installationservices/swinstallationfw/test/securitytests/source/scrcomponentspecific.cpp
changeset 24 84a16765cd86
child 25 98b66e4fb0be
equal deleted inserted replaced
6:aba6b8104af3 24:84a16765cd86
       
     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 <scs/cleanuputils.h>
       
    28 #include <e32def.h>
       
    29 
       
    30 _LIT(KScrCompSecName, "SCR Component-specific APIs test");
       
    31 
       
    32 using namespace Usif;
       
    33 
       
    34 CScrComponentSpecificSecTest* CScrComponentSpecificSecTest::NewL()
       
    35 	{
       
    36 	CScrComponentSpecificSecTest* self=new(ELeave) CScrComponentSpecificSecTest();
       
    37 	CleanupStack::PushL(self);
       
    38 	self->ConstructL();
       
    39 	CleanupStack::Pop(self);
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 CScrComponentSpecificSecTest::CScrComponentSpecificSecTest()
       
    44 	{
       
    45 	SetSidRequired(TUid::Uid(0x10285BC9)); // Use tscr SID as the one required for modifying dummy components
       
    46 	}
       
    47 	
       
    48 void CScrComponentSpecificSecTest::ConstructL()
       
    49 	{
       
    50 	SetNameL(KScrCompSecName);
       
    51 	}
       
    52 
       
    53 void CScrComponentSpecificSecTest::RunTestL()
       
    54 	{
       
    55 	RSoftwareComponentRegistry scrSession;
       
    56 	User::LeaveIfError(scrSession.Connect());
       
    57 	CleanupClosePushL(scrSession);
       
    58 
       
    59 	// 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
       
    60 	TRAP_IGNORE(scrSession.CreateTransactionL()); 
       
    61 	_LIT(KStringPropertyName, "StringName");
       
    62 	
       
    63 	TComponentId componentId(0);
       
    64 	TRAPD(err, componentId = scrSession.AddComponentL(_L("TestComponent"), _L("TestVendor"), _L("dummy"))); // "dummy" is a reserved test software type name
       
    65 	CheckFailL(err, _L("AddComponentL"));
       
    66 	
       
    67 	// We rely on the fact that at least one component exists in the DB, created by the script. If we failed
       
    68 	// to create a legitimate component of our own (negative security test), then we attempt doing operations
       
    69 	// on that component (they should fail also)
       
    70 	if (err != KErrNone)
       
    71 		componentId = 1; 
       
    72 	
       
    73 	TRAP(err, scrSession.SetComponentPropertyL(componentId, KStringPropertyName, _L8("PropertyValue")));
       
    74 	CheckFailL(err, _L("SetComponentPropertyL - string"));
       
    75 		
       
    76 	TRAP(err, scrSession.SetComponentPropertyL(componentId, _L("IntName"), 1));
       
    77 	CheckFailL(err, _L("SetComponentPropertyL - int"));	
       
    78 		
       
    79 	TRAP(err, scrSession.SetComponentPropertyL(componentId, _L("LocalName"), _L("PropertyValue"), ELangEnglish));
       
    80 	CheckFailL(err, _L("SetComponentPropertyL - locale"));
       
    81 		
       
    82 	TRAP(err, scrSession.SetComponentNameL(componentId, _L("TestComponentName")));
       
    83 	CheckFailL(err, _L("SetComponentNameL"));	
       
    84 	
       
    85 	TRAP(err, scrSession.SetVendorNameL(componentId, _L("TestComponentVendor")));
       
    86 	CheckFailL(err, _L("SetVendorNameL"));	
       
    87 	
       
    88 	TRAP(err, scrSession.SetComponentVersionL(componentId, _L("1.0")));
       
    89 	CheckFailL(err, _L("SetComponentVersionL"));
       
    90 	
       
    91 	TRAP(err, scrSession.SetComponentSizeL(componentId, 1));
       
    92 	CheckFailL(err, _L("SetComponentSizeL"));	
       
    93 	
       
    94 	TRAP(err, scrSession.DeleteComponentPropertyL(componentId, KStringPropertyName));
       
    95 	CheckFailL(err, _L("DeleteComponentPropertyL"));	
       
    96 		
       
    97 	TRAP(err, scrSession.SetScomoStateL(componentId, Usif::EActivated));
       
    98 	CheckFailL(err, _L("SetScomoStateL"));	
       
    99 
       
   100 	TRAP(err, scrSession.SetIsComponentRemovableL(componentId, EFalse));
       
   101 	CheckFailL(err, _L("SetIsComponentRemovableL"));		
       
   102 	
       
   103 	TRAP(err, scrSession.SetIsComponentDrmProtectedL(componentId, EFalse));
       
   104 	CheckFailL(err, _L("SetIsComponentDrmProtectedL"));
       
   105 	
       
   106 	TRAP(err, scrSession.SetIsComponentHiddenL(componentId, EFalse));
       
   107 	CheckFailL(err, _L("SetIsComponentHiddenL"));
       
   108 	
       
   109 	TRAP(err, scrSession.SetIsComponentKnownRevokedL(componentId, EFalse));
       
   110 	CheckFailL(err, _L("SetIsComponentKnownRevokedL"));
       
   111 	
       
   112 	TRAP(err, scrSession.SetIsComponentOriginVerifiedL(componentId, EFalse));
       
   113 	CheckFailL(err, _L("SetIsComponentOriginVerifiedL"));
       
   114 	
       
   115 	TRAP(err, scrSession.SetIsComponentPresentL(componentId, EFalse));
       
   116 	CheckFailL(err, _L("SetIsComponentPresentL"));
       
   117 	
       
   118 	TRAP(err, scrSession.DeleteComponentL(componentId));
       
   119 	CheckFailL(err, _L("DeleteComponentL"));	
       
   120 		
       
   121 	RPointerArray<CLocalizableComponentInfo> localisableInfoArray;
       
   122 	CleanupResetAndDestroyPushL(localisableInfoArray);
       
   123 	CLocalizableComponentInfo* localisableInfo = CLocalizableComponentInfo::NewLC(_L("TestComponent"), _L("TestVendor"), static_cast<TLanguage>(1)); 
       
   124 	localisableInfoArray.AppendL(localisableInfo);
       
   125 	CleanupStack::Pop(localisableInfo);
       
   126 		
       
   127 	TRAP(err, scrSession.AddComponentL(localisableInfoArray, _L("dummy")));
       
   128 	CheckFailL(err, _L("AddComponentL - localisable"));
       
   129 	CleanupStack::PopAndDestroy(&localisableInfoArray);
       
   130 	
       
   131 	CGlobalComponentId *dependantGlobalId = CGlobalComponentId::NewLC(_L("DependantGlobalId"), _L("dummy"));
       
   132 	CGlobalComponentId *supplierGlobalId = CGlobalComponentId::NewLC(_L("DependantGlobalId"), _L("plain"));
       
   133 	CVersionedComponentId *supplierVerCompId = CVersionedComponentId::NewLC(*supplierGlobalId);
       
   134 	TRAP(err, scrSession.AddComponentDependencyL(*supplierVerCompId, *dependantGlobalId));
       
   135 	CheckFailL(err, _L("AddComponentDependencyL"));
       
   136 	
       
   137 	TRAP(err, scrSession.DeleteComponentDependencyL(*supplierGlobalId, *dependantGlobalId));
       
   138 	CheckFailL(err, _L("DeleteComponentDependencyL"));
       
   139 	CleanupStack::PopAndDestroy(3, dependantGlobalId); // dependantGlobalId, supplierGlobalId, supplierVerCompId
       
   140 	
       
   141 	// Verify transaction APIs - can be invoked only by an installer
       
   142 	TRAP(err, scrSession.CreateTransactionL());
       
   143 	CheckFailL(err, _L("CreateTransactionL"));
       
   144 	
       
   145 	TRAP(err, scrSession.RollbackTransactionL());
       
   146 	CheckFailL(err, _L("RollbackTransactionL"));	
       
   147 	
       
   148 	TRAP(err, scrSession.CommitTransactionL());
       
   149 	CheckFailL(err, _L("CommitTransactionL"));	
       
   150 		
       
   151 	CleanupStack::PopAndDestroy(&scrSession);
       
   152 	}
       
   153