installationservices/swinstallationfw/test/securitytests/source/scrpluginmanagement.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
       
     2 * Copyright (c) 2008-2010 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 "scrpluginmanagement.h"
       
    25 
       
    26 #include <usif/scr/scr.h>
       
    27 #include <scs/cleanuputils.h>
       
    28 #include <e32def.h>
       
    29 
       
    30 _LIT_SECURE_ID(KSisRegistryServerSid, 0x10202DCA);
       
    31 _LIT(KScrPluginManagementSecName, "SCR Plugin Management APIs test");
       
    32 
       
    33 using namespace Usif;
       
    34 
       
    35 CScrPluginManagementSecTest* CScrPluginManagementSecTest::NewL()
       
    36 	{
       
    37 	CScrPluginManagementSecTest* self=new(ELeave) CScrPluginManagementSecTest();
       
    38 	CleanupStack::PushL(self);
       
    39 	self->ConstructL();
       
    40 	CleanupStack::Pop(self);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 CScrPluginManagementSecTest::CScrPluginManagementSecTest()
       
    45 	{
       
    46 	SetSidRequired(KSisRegistryServerSid);
       
    47 	}
       
    48 	
       
    49 void CScrPluginManagementSecTest::ConstructL()
       
    50 	{
       
    51 	SetNameL(KScrPluginManagementSecName);
       
    52 	}
       
    53 
       
    54 void CScrPluginManagementSecTest::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 	
       
    63 	TInt err(0);
       
    64 	
       
    65 	// First, add a new sofwtare type
       
    66 	_LIT(KSwTypeName, "usifsecuritytestsoftwaretype");
       
    67 	TUid sifPluginUid = {0xA01B7211};
       
    68 	
       
    69 	RArray<TCustomAccessInfo> sidArray;
       
    70 	CleanupClosePushL(sidArray);
       
    71 	
       
    72 	TCustomAccessInfo id1(TSecureId(0xAAFFEE11), static_cast<TAccessMode>(1));
       
    73 	TCustomAccessInfo id2(TSecureId(0xAAEEDD11), static_cast<TAccessMode>(1));
       
    74 
       
    75 	sidArray.AppendL(id1);
       
    76 	sidArray.AppendL(id2);
       
    77 	
       
    78 	_LIT(KMimeType, "usifsecuritytestmimetype");
       
    79 	RPointerArray<HBufC> mimeTypes;
       
    80 	CleanupResetAndDestroyPushL(mimeTypes);
       
    81 	mimeTypes.Append(KMimeType().AllocL());
       
    82 	
       
    83 	_LIT(KLauncherExecutable, "usifsecuritytestLauncherExec");
       
    84 	
       
    85 	Usif::CSoftwareTypeRegInfo* swType = Usif::CSoftwareTypeRegInfo::NewL(KSwTypeName);
       
    86 	CleanupStack::PushL(swType);
       
    87 	swType->SetSifPluginUid(sifPluginUid);
       
    88 	for(TInt i=0;i<sidArray.Count(); ++i)
       
    89 		{
       
    90 		swType->SetCustomAccessL(sidArray[i]);
       
    91 		}
       
    92 	for(TInt i=0;i<mimeTypes.Count(); ++i)
       
    93 		{
       
    94 		swType->SetMimeTypeL(mimeTypes[i]->Des());
       
    95 		}
       
    96 
       
    97 	swType->SetLauncherExecutableL(KLauncherExecutable);
       
    98 	
       
    99 	TRAP(err, scrSession.AddSoftwareTypeL(*swType));
       
   100 	CheckFailL(err, _L("AddSoftwareTypeL"));
       
   101 	CleanupStack::PopAndDestroy(3, &sidArray);
       
   102 	
       
   103 	// Then, delete the newly added sofwtare type. 
       
   104 	RPointerArray<HBufC> deletedMimeTypes;
       
   105 	CleanupResetAndDestroyPushL(deletedMimeTypes);
       
   106 	TRAP(err, scrSession.DeleteSoftwareTypeL(KSwTypeName,deletedMimeTypes));
       
   107 	CheckFailL(err, _L("DeleteSoftwareTypeL"));
       
   108 	CleanupStack::PopAndDestroy(&deletedMimeTypes); 
       
   109 		
       
   110 	TRAP_IGNORE(scrSession.CommitTransactionL());
       
   111 	CleanupStack::PopAndDestroy(&scrSession);
       
   112 	}