installationservices/swinstallationfw/test/securitytests/source/scrcomponentspecific.cpp
branchRCL_3
changeset 25 7333d7932ef7
equal deleted inserted replaced
24:5cc91383ab1e 25:7333d7932ef7
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21  @test
       
    22 */
       
    23 
       
    24 #include "scrcomponentspecific.h"
       
    25 
       
    26 #include <usif/scr/scr.h>
       
    27 #include <usif/scr/appregentries.h>
       
    28 #include <scs/cleanuputils.h>
       
    29 #include <e32def.h>
       
    30 
       
    31 _LIT(KScrCompSecName, "SCR Component-specific APIs test");
       
    32 
       
    33 using namespace Usif;
       
    34 
       
    35 CScrComponentSpecificSecTest* CScrComponentSpecificSecTest::NewL()
       
    36 	{
       
    37 	CScrComponentSpecificSecTest* self=new(ELeave) CScrComponentSpecificSecTest();
       
    38 	CleanupStack::PushL(self);
       
    39 	self->ConstructL();
       
    40 	CleanupStack::Pop(self);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 CScrComponentSpecificSecTest::CScrComponentSpecificSecTest()
       
    45 	{
       
    46 	SetSidRequired(TUid::Uid(0x10285BC9)); // Use tscr SID as the one required for modifying dummy components
       
    47 	}
       
    48 	
       
    49 void CScrComponentSpecificSecTest::ConstructL()
       
    50 	{
       
    51 	SetNameL(KScrCompSecName);
       
    52 	}
       
    53 
       
    54 void CScrComponentSpecificSecTest::RunTestL()
       
    55 	{
       
    56 	RSoftwareComponentRegistry scrSession;
       
    57 	User::LeaveIfError(scrSession.Connect());
       
    58 	CleanupClosePushL(scrSession);
       
    59 
       
    60 	// The transaction APIs are tested separately. If this command fails, then we can proceed, as the following operations would fail also, and no transaction management would be required
       
    61 	TRAP_IGNORE(scrSession.CreateTransactionL()); 
       
    62 	_LIT(KStringPropertyName, "StringName");
       
    63 	
       
    64 	TComponentId componentId(0);
       
    65 	TRAPD(err, componentId = scrSession.AddComponentL(_L("TestComponent"), _L("TestVendor"), _L("dummy"))); // "dummy" is a reserved test software type name
       
    66 	CheckFailL(err, _L("AddComponentL"));
       
    67 	
       
    68 	// We rely on the fact that at least one component exists in the DB, created by the script. If we failed
       
    69 	// to create a legitimate component of our own (negative security test), then we attempt doing operations
       
    70 	// on that component (they should fail also)
       
    71 	if (err != KErrNone)
       
    72 		componentId = 1; 
       
    73 	
       
    74 	TRAP(err, scrSession.SetComponentPropertyL(componentId, KStringPropertyName, _L8("PropertyValue")));
       
    75 	CheckFailL(err, _L("SetComponentPropertyL - string"));
       
    76 		
       
    77 	TRAP(err, scrSession.SetComponentPropertyL(componentId, _L("IntName"), 1));
       
    78 	CheckFailL(err, _L("SetComponentPropertyL - int"));	
       
    79 		
       
    80 	TRAP(err, scrSession.SetComponentPropertyL(componentId, _L("LocalName"), _L("PropertyValue"), ELangEnglish));
       
    81 	CheckFailL(err, _L("SetComponentPropertyL - locale"));
       
    82 		
       
    83 	TRAP(err, scrSession.SetComponentNameL(componentId, _L("TestComponentName")));
       
    84 	CheckFailL(err, _L("SetComponentNameL"));	
       
    85 	
       
    86 	TRAP(err, scrSession.SetVendorNameL(componentId, _L("TestComponentVendor")));
       
    87 	CheckFailL(err, _L("SetVendorNameL"));	
       
    88 	
       
    89 	TRAP(err, scrSession.SetComponentVersionL(componentId, _L("1.0")));
       
    90 	CheckFailL(err, _L("SetComponentVersionL"));
       
    91 	
       
    92 	TRAP(err, scrSession.SetComponentSizeL(componentId, 1));
       
    93 	CheckFailL(err, _L("SetComponentSizeL"));	
       
    94 	
       
    95 	TRAP(err, scrSession.DeleteComponentPropertyL(componentId, KStringPropertyName));
       
    96 	CheckFailL(err, _L("DeleteComponentPropertyL"));	
       
    97 		
       
    98 	TRAP(err, scrSession.SetScomoStateL(componentId, Usif::EActivated));
       
    99 	CheckFailL(err, _L("SetScomoStateL"));	
       
   100 
       
   101 	TRAP(err, scrSession.SetIsComponentRemovableL(componentId, EFalse));
       
   102 	CheckFailL(err, _L("SetIsComponentRemovableL"));		
       
   103 	
       
   104 	TRAP(err, scrSession.SetIsComponentDrmProtectedL(componentId, EFalse));
       
   105 	CheckFailL(err, _L("SetIsComponentDrmProtectedL"));
       
   106 	
       
   107 	TRAP(err, scrSession.SetIsComponentHiddenL(componentId, EFalse));
       
   108 	CheckFailL(err, _L("SetIsComponentHiddenL"));
       
   109 	
       
   110 	TRAP(err, scrSession.SetIsComponentKnownRevokedL(componentId, EFalse));
       
   111 	CheckFailL(err, _L("SetIsComponentKnownRevokedL"));
       
   112 	
       
   113 	TRAP(err, scrSession.SetIsComponentOriginVerifiedL(componentId, EFalse));
       
   114 	CheckFailL(err, _L("SetIsComponentOriginVerifiedL"));
       
   115 	
       
   116 	TRAP(err, scrSession.SetIsComponentPresentL(componentId, EFalse));
       
   117 	CheckFailL(err, _L("SetIsComponentPresentL"));
       
   118 	
       
   119 	TRAP(err, scrSession.DeleteComponentL(componentId));
       
   120 	CheckFailL(err, _L("DeleteComponentL"));	
       
   121 		
       
   122 	RPointerArray<CLocalizableComponentInfo> localisableInfoArray;
       
   123 	CleanupResetAndDestroyPushL(localisableInfoArray);
       
   124 	CLocalizableComponentInfo* localisableInfo = CLocalizableComponentInfo::NewLC(_L("TestComponent"), _L("TestVendor"), static_cast<TLanguage>(1)); 
       
   125 	localisableInfoArray.AppendL(localisableInfo);
       
   126 	CleanupStack::Pop(localisableInfo);
       
   127 		
       
   128 	TRAP(err, scrSession.AddComponentL(localisableInfoArray, _L("dummy")));
       
   129 	CheckFailL(err, _L("AddComponentL - localisable"));
       
   130 	CleanupStack::PopAndDestroy(&localisableInfoArray);
       
   131 	
       
   132 	CGlobalComponentId *dependantGlobalId = CGlobalComponentId::NewLC(_L("DependantGlobalId"), _L("dummy"));
       
   133 	CGlobalComponentId *supplierGlobalId = CGlobalComponentId::NewLC(_L("DependantGlobalId"), _L("plain"));
       
   134 	CVersionedComponentId *supplierVerCompId = CVersionedComponentId::NewLC(*supplierGlobalId);
       
   135 	TRAP(err, scrSession.AddComponentDependencyL(*supplierVerCompId, *dependantGlobalId));
       
   136 	CheckFailL(err, _L("AddComponentDependencyL"));
       
   137 	
       
   138 	TRAP(err, scrSession.DeleteComponentDependencyL(*supplierGlobalId, *dependantGlobalId));
       
   139 	CheckFailL(err, _L("DeleteComponentDependencyL"));
       
   140 	CleanupStack::PopAndDestroy(3, dependantGlobalId); // dependantGlobalId, supplierGlobalId, supplierVerCompId
       
   141 	
       
   142 	//TODO: The addition of AppRegInfo needs to be optimized
       
   143 	RPointerArray<HBufC> ownedFileArray;
       
   144     RPointerArray<Usif::CServiceInfo> serviceInfoArray;
       
   145     RPointerArray<Usif::CLocalizableAppInfo> localizableAppInfoArray;
       
   146     RPointerArray<Usif::CPropertyEntry> appPropertyArray;
       
   147 	RPointerArray<Usif::COpaqueData> opaqueDataArray;
       
   148     TUid appUid = TUid::Uid(123454321);
       
   149      
       
   150     TApplicationCharacteristics appCharacteristics;
       
   151     const Usif::CApplicationRegistrationData* appRegData = Usif::CApplicationRegistrationData::NewLC(ownedFileArray, serviceInfoArray, localizableAppInfoArray, appPropertyArray, opaqueDataArray, appUid, _L("SomeFile"), appCharacteristics, 0);
       
   152     TRAP(err, scrSession.AddApplicationEntryL(componentId, *appRegData));
       
   153 	CleanupStack::PopAndDestroy();
       
   154 	CheckFailL(err, _L("AddApplicationEntryL"));
       
   155 	
       
   156 	TRAP(err, scrSession.DeleteApplicationEntriesL(componentId));
       
   157 	CheckFailL(err, _L("DeleteApplicationEntryL"));
       
   158 
       
   159 	// Verify transaction APIs - can be invoked only by an installer
       
   160 	TRAP(err, scrSession.CreateTransactionL());
       
   161 	CheckFailL(err, _L("CreateTransactionL"));
       
   162 	
       
   163 	TRAP(err, scrSession.RollbackTransactionL());
       
   164 	CheckFailL(err, _L("RollbackTransactionL"));	
       
   165 	
       
   166 	TRAP(err, scrSession.CommitTransactionL());
       
   167 	CheckFailL(err, _L("CommitTransactionL"));	
       
   168 		
       
   169 	CleanupStack::PopAndDestroy(&scrSession);
       
   170 	}
       
   171