appfw/apparchitecture/tef/T_File3Step.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Tests CApaAppRegFinder APIs.
       
    15 // 
       
    16 // t_file3step.cpp
       
    17 //
       
    18 
       
    19 /**
       
    20  @file t_file3step.cpp
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 
       
    24 #include <apgicnfl.h>
       
    25 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    26 #include <apgicnflpartner.h>
       
    27 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
       
    28 #include <e32property.h>
       
    29 #include "T_File3Step.h"
       
    30 #include "../aplist/aplappregfinder.h"	// class CApaAppRegFinder
       
    31 #include "../aplist/aplapplistitem.h"	// class TApaAppEntry 
       
    32 #include "TSidChecker/TestSidChecker.h"
       
    33 
       
    34 #include <e32test.h>
       
    35 #include <f32file.h>
       
    36 
       
    37 _LIT(KCallBackAppRsc,"\\private\\10003a3f\\import\\apps\\NonNative\\Resource\\10281fe0_reg.rsc");
       
    38 _LIT(KCallBackAppIst,"\\TestSidCheckerCallBackApp.ist");
       
    39 _LIT(KBadAppRsc,"\\private\\10003a3f\\import\\apps\\NonNative\\Resource\\10281fdc_reg.rsc");
       
    40 _LIT(KBadAppIst,"\\TestSidCheckerBadApp.ist");
       
    41 _LIT(KGoodAppRsc,"\\private\\10003a3f\\import\\apps\\NonNative\\Resource\\10281fdd_reg.rsc");
       
    42 _LIT(KGoodAppIst,"\\TestSidCheckerGoodApp.ist");
       
    43 _LIT(KForcedAppRsc, "\\private\\10003a3f\\import\\apps\\NonNative\\Resource\\102825b5_reg.rsc");
       
    44 _LIT(KForcedAppIst, "\\TestSidCheckerForcedApp.ist");
       
    45 _LIT(KTriggerRescanRsc,"\\private\\10003a3f\\import\\apps\\NonNative\\Resource\\102825b6_reg.rsc");
       
    46 _LIT(KTriggerRescanIst,"\\TestSidCheckerTriggerRescan.ist");
       
    47 _LIT(KMmcPrivateDir,"\\private\\10003a3f\\");
       
    48 _LIT(KAppRsc1,"\\private\\10003a3f\\import\\apps\\NonNative\\Resource\\A000D107_reg.rsc");
       
    49 _LIT(KAppRsc2,"\\private\\10003a3f\\import\\apps\\NonNative\\Resource\\A000D107_r02.rsc");
       
    50 _LIT(KAppRsc3,"\\private\\10003a3f\\import\\apps\\NonNative\\Resource\\A000D107_r03.rsc");
       
    51 _LIT(KAppIst, "\\TestSidCheckerMultipleRegistrationFilesApp.ist");
       
    52 
       
    53 CT_File3Step::CT_File3Step()
       
    54 /**
       
    55    Constructor
       
    56  */
       
    57 	{
       
    58 	// Call base class method to set up the human readable name for logging
       
    59 	SetTestStepName(KT_File3Step);
       
    60 	}
       
    61 
       
    62 _LIT(KLitNativeExecutable, "z:\\sys\\bin\\SidCheckerTestDummy.exe");
       
    63 
       
    64 /**
       
    65    @return - TVerdict code
       
    66    Override of base class virtual
       
    67  */
       
    68 TVerdict CT_File3Step::doTestStepPreambleL()
       
    69 	{
       
    70 	SetTestStepResult(EPass);
       
    71 	TInt err = iSession.Connect();
       
    72 	TEST(err==KErrNone);
       
    73 	err = iUtils.Connect();
       
    74 	TEST(err==KErrNone);
       
    75 	return TestStepResult();
       
    76 	}
       
    77 
       
    78 TVerdict CT_File3Step::doTestStepL()
       
    79 /**
       
    80   @return - TVerdict code
       
    81   Override of base class virtual
       
    82 */
       
    83 	{
       
    84 	INFO_PRINTF1(_L("Testing the CAppSidChecker api"));
       
    85 	FindRemovableDriveAndSetPathL();
       
    86 	// Must be first, since the plugin must not be loaded when this is started.
       
    87 	//DONT_CHECK since changes on file system changes the heap
       
    88  	HEAP_TEST_LS_SESSION(iSession, 0, DONT_CHECK, TestRescanCallBackL(), REComSession::FinalClose() );
       
    89 	HEAP_TEST_LS_SESSION(iSession, 0, DONT_CHECK, TestAppPresenceL(), REComSession::FinalClose() );
       
    90 	HEAP_TEST_LS_SESSION(iSession, 0, DONT_CHECK, TestForceRegistrationL(), REComSession::FinalClose() );
       
    91 	HEAP_TEST_LS_SESSION(iSession, 0, DONT_CHECK, TestCorruptedRegFileL(), NO_CLEANUP );
       
    92 	HEAP_TEST_LS_SESSION(iSession, 0, DONT_CHECK, TestMultipleRegistrationFilesForSameAppL(), REComSession::FinalClose() );
       
    93 	
       
    94 	INFO_PRINTF1(_L("Test completed!"));
       
    95 	return TestStepResult();
       
    96 	}
       
    97 
       
    98 
       
    99 /**
       
   100    @SYMTestCaseID UIFRAMEWORKS-APPARC-0047
       
   101   
       
   102    @SYMDEF INC069526
       
   103   
       
   104    @SYMTestCaseDesc When an implementation of the ApSidChecker interface invokes the rescan callback that was passed to it,
       
   105                     the App list server should scan for application registration files. This tests that it does so.
       
   106    
       
   107    @SYMTestPriority High
       
   108   
       
   109    @SYMTestStatus Implemented
       
   110    
       
   111    @SYMTestActions Trigger the loading of a special plugin implementing the ApSidChecker interface
       
   112                    Tell the loaded instance of the aforementioned implementation to trigger a rescan via pub&sub
       
   113 		    -> The plugin will invoke its callback
       
   114 		    -> The plugin will start a timer
       
   115 		    -> The timer will publish a result when either:
       
   116 		       a) it recieves an AppRegisteredAt() call -- this is part of the scan we tried to trigger. (success)
       
   117 		       b) the timer completes (failure)
       
   118 		   Retrieve the results from the plugin, again via pub & sub
       
   119   
       
   120    @SYMTestExpectedResults The Apparc App list server scans for new/removed apps when a plugins requests it
       
   121  */
       
   122 void CT_File3Step::TestRescanCallBackL()
       
   123 	{
       
   124 	INFO_PRINTF1(_L("Testing CApaAppRegFinder::TestRescanCallBackL()"));
       
   125 
       
   126 	CleanupRegFilesL();
       
   127 
       
   128 	User::LeaveIfError(RProperty::Define(KApFileTestPubSubCategory, KApFileTestPubSubCallBackKey, RProperty::EInt));	
       
   129 	User::LeaveIfError(RProperty::Set(KApFileTestPubSubCategory, KApFileTestPubSubCallBackKey, CTestSidChecker::EPluginLoad));
       
   130 	
       
   131 	TProcessPriority oldPriority = RProcess().Priority();
       
   132 	RProcess().SetPriority(EPriorityLow); // so that we're pre-empted by the Apparc server when it does its scan
       
   133 
       
   134 	iSession.RegisterNonNativeApplicationTypeL(KApFileTestAppType, KLitNativeExecutable);
       
   135 	TRAPD(err, PrepareRegFileL(KApFileTestCallBackApp, iCallBackAppRsc, iCallBackAppIst));
       
   136 	TEST(err==KErrNone);
       
   137 	User::After(20 * 1000000);
       
   138 
       
   139 	TRequestStatus status;
       
   140 	RProperty property;
       
   141 	CleanupClosePushL(property);
       
   142 	User::LeaveIfError(RProperty::Set(KApFileTestPubSubCategory, KApFileTestPubSubCallBackKey, CTestSidChecker::ETriggerScan));
       
   143 	User::LeaveIfError(property.Attach(KApFileTestPubSubCategory, KApFileTestPubSubCallBackKey));
       
   144 	property.Subscribe(status);
       
   145 
       
   146 	RTimer timer;
       
   147 	CleanupClosePushL(timer);
       
   148 	User::LeaveIfError(timer.CreateLocal());
       
   149 	TRequestStatus timerStatus;
       
   150 	timer.After(timerStatus,30 * 1000000);
       
   151 	
       
   152 	User::WaitForRequest(status,timerStatus);
       
   153 	TEST(status != KRequestPending);
       
   154 	if(status != KRequestPending)
       
   155 		{
       
   156 		timer.Cancel();
       
   157 		User::WaitForRequest(timerStatus);
       
   158 		TInt result;	
       
   159 		User::LeaveIfError(RProperty::Get(KApFileTestPubSubCategory, KApFileTestPubSubCallBackKey, result));
       
   160 		TEST(result == CTestSidChecker::EScanOccurred);
       
   161 		}
       
   162 	else
       
   163 		{
       
   164 		property.Cancel();
       
   165 		User::WaitForRequest(status);
       
   166 		ASSERT(timerStatus != KRequestPending);
       
   167 		INFO_PRINTF1(_L("Timeout exceeded"));
       
   168 		}
       
   169 	
       
   170 	CleanupStack::PopAndDestroy(2,&property);
       
   171 	
       
   172 	RProcess().SetPriority(oldPriority);
       
   173 	
       
   174 	CleanupRegFilesL();
       
   175 	}
       
   176 
       
   177 /**
       
   178    @SYMTestCaseID UIFRAMEWORKS-APPARC-0048
       
   179   
       
   180    @SYMDEF INC069526
       
   181   
       
   182    @SYMTestCaseDesc Test that the results of the AppRegisteredAt() function in the ApSidChecker ECOM interface are handled correctly
       
   183    
       
   184    @SYMTestPriority High
       
   185   
       
   186    @SYMTestStatus Implemented
       
   187    
       
   188    @SYMTestActions Create application registration files on a removable drive
       
   189                    Iterate over all registration files with an instance of CApaAppRegFinder
       
   190   
       
   191    @SYMTestExpectedResults CApaAppRegFinder's list of entries contains KApFileTestGoodApp but not KApFileTestBadApp
       
   192  */
       
   193 void CT_File3Step::TestAppPresenceL()
       
   194 	{
       
   195 	INFO_PRINTF1(_L("Testing CApaAppRegFinder::TestAppPresenceL()"));
       
   196 	
       
   197 	/*
       
   198 	 * Prepare registration files
       
   199 	 */
       
   200 	
       
   201 	CleanupRegFilesL();
       
   202 
       
   203 	iSession.RegisterNonNativeApplicationTypeL(KApFileTestAppType, KLitNativeExecutable);
       
   204 	TRAPD(err, PrepareRegFileL(KApFileTestBadApp, iBadAppRsc, iBadAppIst));
       
   205 	TEST(err==KErrNone);
       
   206 	TRAP(err, PrepareRegFileL(KApFileTestGoodApp, iGoodAppRsc, iGoodAppIst));
       
   207 	TEST(err==KErrNone);
       
   208 
       
   209 	/*
       
   210 	 * Manually scan files
       
   211 	 */
       
   212 	RFs fSession;
       
   213 	User::LeaveIfError(fSession.Connect());
       
   214 	CleanupClosePushL(fSession);
       
   215 	CApaAppRegFinder* regFinder=CApaAppRegFinder::NewLC(fSession);
       
   216 
       
   217 	TRAPD(ret, regFinder->FindAllAppsL(CApaAppRegFinder::EScanAllDrives) );
       
   218 	TEST(ret==KErrNone);
       
   219 
       
   220 	CDesCArray* dummyArray = new (ELeave) CDesCArraySeg(1);
       
   221 	CleanupStack::PushL(dummyArray);
       
   222 	TApaAppEntry entry;
       
   223 	TBool more = ETrue;
       
   224 	TBool foundGoodApp = EFalse;
       
   225 	TBool foundBadApp = EFalse;
       
   226 	while (more)
       
   227 		{
       
   228 		TRAPD(ret, more=regFinder->NextL(entry, *dummyArray) );
       
   229 		TEST(ret==KErrNone);
       
   230 		if(entry.iUidType[2] == KApFileTestBadApp)
       
   231 			foundBadApp = ETrue;
       
   232 		if(entry.iUidType[2] == KApFileTestGoodApp)
       
   233 			foundGoodApp = ETrue;
       
   234 		}
       
   235 	TEST(foundGoodApp);
       
   236 	TEST(!foundBadApp);
       
   237 
       
   238 	CleanupStack::PopAndDestroy(dummyArray);
       
   239 	CleanupStack::PopAndDestroy(2,&fSession);	
       
   240 
       
   241 	/*
       
   242 	 * Cleanup
       
   243 	 */	
       
   244 	CleanupRegFilesL();
       
   245 	}
       
   246 
       
   247 /**
       
   248    @SYMTestCaseID UIFRAMEWORKS-APPARC-0051
       
   249   
       
   250    @SYMDEF INC084770
       
   251   
       
   252    @SYMTestCaseDesc Test that the AppRegisteredAt check can be overridden
       
   253    
       
   254    @SYMTestPriority High
       
   255   
       
   256    @SYMTestStatus Implemented
       
   257    
       
   258    @SYMTestActions Installs an application for which AppRegisteredAt returns EFalse. Then adds this
       
   259    application to a list of applications for which the results of AppRegisteredAt will be ignored and
       
   260    tests that the application appears in the list of apps.
       
   261   
       
   262    @SYMTestExpectedResults CApaAppList contains the application.
       
   263  */	
       
   264 void CT_File3Step::TestForceRegistrationL()
       
   265 	{
       
   266 	INFO_PRINTF1(_L("Testing RApaLsSession::ForceRegistrationL()"));
       
   267 	
       
   268 	/*
       
   269 	 * Prepare registration files
       
   270 	 */
       
   271 	CleanupRegFilesL();
       
   272 	
       
   273 	// Install the test application
       
   274 	iSession.RegisterNonNativeApplicationTypeL(KApFileTestAppType, KLitNativeExecutable);
       
   275 	TRAPD(err, PrepareRegFileL(KApFileTestForcedRegistration, iForcedAppRsc, iForcedAppIst));
       
   276 	TEST(err==KErrNone);
       
   277 	
       
   278 	// Wait for a rescan and check that the application is not in the list
       
   279 	RPointerArray<TDesC> dummy;
       
   280 	err = iSession.ForceRegistration(dummy);
       
   281 	TApaAppInfo info;
       
   282 	err = iSession.GetAppInfo(info,KApFileTestForcedRegistration);
       
   283 	TEST(err==KErrNotFound);
       
   284 	
       
   285 	// Add the application to the list of applications that ignore the AppRegisteredAt test
       
   286 	RPointerArray<TDesC> regFiles;
       
   287 	_LIT(KRegFile2, "test2");	// Add a second dummy registration file just to check that this works
       
   288 	regFiles.Append(iForcedAppRsc.AllocL());
       
   289 	regFiles.Append(KRegFile2().AllocL());
       
   290 	err = iSession.ForceRegistration(regFiles);
       
   291 	TEST(err==KErrNone);
       
   292 	regFiles.ResetAndDestroy();
       
   293 	err = iSession.GetAppInfo(info,KApFileTestForcedRegistration);
       
   294 	TEST(err==KErrNone);
       
   295 	
       
   296 	// triggers a rescan from the sid checker, this will cause the 
       
   297 	// list to be emptied
       
   298 	TRAP(err, PrepareRegFileL(KApTriggerRescan, iTriggerRescanRsc, iTriggerRescanIst));
       
   299 	TEST(err==KErrNone);
       
   300 	
       
   301 	// Now the app should not be listed anymore as we have removed it from the "force" list
       
   302 	err = iSession.ForceRegistration(dummy);			
       
   303 	err = iSession.GetAppInfo(info,KApFileTestForcedRegistration);
       
   304 	TEST(err==KErrNotFound);
       
   305 	
       
   306 	/*
       
   307 	 * Cleanup
       
   308 	 */	
       
   309 	CleanupRegFilesL();
       
   310 	}
       
   311 
       
   312 void CT_File3Step::PrepareRegFileL(const TUid& aUid, const TDesC& aRscFile, const TDesC& aLogicalExecutable)
       
   313 	{
       
   314 	CApaRegistrationResourceFileWriter* const registrationResourceFileWriter =
       
   315 			CApaRegistrationResourceFileWriter::NewL(aUid,
       
   316 				                                         aLogicalExecutable,
       
   317 		    	                                     TApaAppCapability::ENonNative);
       
   318 	CleanupStack::PushL(registrationResourceFileWriter);
       
   319 
       
   320 	iSession.PrepareNonNativeApplicationsUpdatesL();
       
   321 	iSession.RegisterNonNativeApplicationL(KApFileTestAppType, iDrive, *registrationResourceFileWriter, NULL, NULL);
       
   322 	iSession.CommitNonNativeApplicationsUpdatesL();
       
   323 	TBool present = EFalse;
       
   324 	User::LeaveIfError(iUtils.IsFilePresent(aRscFile, present));
       
   325 	TEST(present);
       
   326 	
       
   327 	CleanupStack::PopAndDestroy(registrationResourceFileWriter);
       
   328 	}
       
   329 
       
   330 void CT_File3Step::CleanupRegFilesL()
       
   331 	{
       
   332 	iSession.PrepareNonNativeApplicationsUpdatesL();
       
   333 	iSession.DeregisterNonNativeApplicationL(KApFileTestBadApp);
       
   334 	iSession.DeregisterNonNativeApplicationL(KApFileTestGoodApp);
       
   335 	iSession.DeregisterNonNativeApplicationL(KApFileTestCallBackApp);
       
   336 	iSession.DeregisterNonNativeApplicationL(KApFileTestForcedRegistration);
       
   337 	iSession.DeregisterNonNativeApplicationL(KApTriggerRescan);
       
   338 	iSession.DeregisterNonNativeApplicationL(KApFileTestAppWithMultipleRegistrationFiles);
       
   339 	iSession.CommitNonNativeApplicationsUpdatesL();
       
   340 	iSession.DeregisterNonNativeApplicationTypeL(KApFileTestAppType);
       
   341 	RFs fSession;
       
   342 	User::LeaveIfError(fSession.Connect());
       
   343 	CleanupClosePushL(fSession);
       
   344 	CFileMan* fMan = CFileMan::NewL(fSession);
       
   345 	CleanupStack::PushL(fMan);
       
   346 	TInt err = fMan->Delete(iMmcPrivateDir, CFileMan::ERecurse);
       
   347 	if(err != KErrNone && err != KErrNotFound && err != KErrPathNotFound)
       
   348 		{
       
   349 		User::Leave(err);
       
   350 		}
       
   351 	CleanupStack::PopAndDestroy(2,&fSession);
       
   352 	}
       
   353 	
       
   354 /**
       
   355    @SYMTestCaseID UIFRAMEWORKS-APPARC-0052
       
   356   
       
   357    @SYMDEF INC87806
       
   358   
       
   359    @SYMTestCaseDesc Test that apparc does not stop scanning its list of registration files after scanning a corrupted registration file.
       
   360    
       
   361    @SYMTestPriority High
       
   362   
       
   363    @SYMTestStatus Implemented
       
   364    
       
   365    @SYMTestActions Copy a corrupted registration file into C:\\Private\\10003a3f\\import\\apps\\. Register a non-native application. Force apparc to rescan. Since non-native applications
       
   366    					are scanned after native ones, we eliminate the risk that the corrupted registration file is scanned after the non-native one. Call GetAppInfo on non-native application.
       
   367   
       
   368    @SYMTestExpectedResults Apparc successfully scans the non-native app. Calling GetAppInfo on the non-native app returns KErrNone. 
       
   369  */	
       
   370 void CT_File3Step::TestCorruptedRegFileL()
       
   371 	{
       
   372 	INFO_PRINTF1(_L("TestCorruptedRegFileL about to start..."));	
       
   373 	_LIT(KCorruptedSourceFileName, "Z:\\ApparcTest\\Corrupted_reg.RSC"); // corrupted_reg.rsc file is pre-built.
       
   374 	_LIT(KCorruptedTargetFileName, "C:\\Private\\10003a3f\\import\\apps\\Corrupted_reg.RSC");
       
   375 	_LIT(KDir, "C:\\private\\10003a3f\\import\\apps\\");
       
   376 	_LIT(KNonNativeFileName,"C:\\private\\10003a3f\\import\\apps\\NonNative\\Resource\\NonCorrupted_reg.rsc");
       
   377 	_LIT(KLitNoncorruptedExe, "z:\\sys\\bin\\NonCorrupted.exe");
       
   378 	const TUid KNonCorruptedAppUid = {0x102826DE};
       
   379 
       
   380 	RFs	fs;
       
   381  	User::LeaveIfError(fs.Connect());
       
   382  	CleanupClosePushL(fs);
       
   383   	TInt ret = fs.MkDirAll(KDir);
       
   384 	if (ret != KErrAlreadyExists)
       
   385 		{
       
   386 		User::LeaveIfError(ret);			
       
   387 		}
       
   388   	CFileMan* fileManager = CFileMan::NewL(fs);
       
   389  	CleanupStack::PushL(fileManager);
       
   390 	ret = fileManager->Copy(KCorruptedSourceFileName, KCorruptedTargetFileName, CFileMan::EOverWrite);
       
   391 	TEST(ret==KErrNone);
       
   392 
       
   393 	CApaRegistrationResourceFileWriter* const registrationResourceFileWriter=CApaRegistrationResourceFileWriter::NewL(KNonCorruptedAppUid,KNonNativeFileName,TApaAppCapability::ENonNative);
       
   394 	CleanupStack::PushL(registrationResourceFileWriter);
       
   395 	iSession.PrepareNonNativeApplicationsUpdatesL();
       
   396 	iSession.RegisterNonNativeApplicationTypeL(KApFileTestAppType,KLitNoncorruptedExe);
       
   397 	iSession.RegisterNonNativeApplicationL(KApFileTestAppType, EDriveC, *registrationResourceFileWriter, NULL, NULL);
       
   398 	iSession.CommitNonNativeApplicationsUpdatesL();
       
   399 	
       
   400 	RPointerArray<TDesC> empty;
       
   401 	ret = iSession.ForceRegistration(empty);
       
   402 	TEST(ret==KErrNone);
       
   403 	TApaAppInfo appInfo;
       
   404 	ret = iSession.GetAppInfo(appInfo,KNonCorruptedAppUid);
       
   405 	TEST(ret==KErrNone);
       
   406 	
       
   407 	iSession.PrepareNonNativeApplicationsUpdatesL();
       
   408 	iSession.DeregisterNonNativeApplicationL(KNonCorruptedAppUid);
       
   409 	iSession.DeregisterNonNativeApplicationTypeL(KApFileTestAppType);
       
   410 	iSession.CommitNonNativeApplicationsUpdatesL();
       
   411 	fileManager->RmDir(KDir);
       
   412 
       
   413 	CleanupStack::PopAndDestroy(registrationResourceFileWriter);
       
   414 	CleanupStack::PopAndDestroy(fileManager);
       
   415 	CleanupStack::PopAndDestroy(&fs);
       
   416 	}
       
   417 
       
   418 /**
       
   419    @SYMTestCaseID UIFRAMEWORKS-APPARC-0102
       
   420   
       
   421    @SYMDEF PDEF139145
       
   422   
       
   423    @SYMTestCaseDesc Test that apparc calls sid checker only once for multiple registration resource file for same application.
       
   424    
       
   425    @SYMTestPriority High
       
   426   
       
   427    @SYMTestStatus Implemented
       
   428    
       
   429    @SYMTestActions Make copies of a registration resource file in the removable drive. Plugin implementing the ApSidChecker 
       
   430    					interface will set a Pub&Sub value everytime it is called. Check that it has been called only once.
       
   431   
       
   432    @SYMTestExpectedResults Pub&Sub value has been set only once by the SidChecker plugin. 
       
   433  */	
       
   434 void CT_File3Step::TestMultipleRegistrationFilesForSameAppL()
       
   435 	{
       
   436 	INFO_PRINTF1(_L("Testing Multiple registration files for same application"));
       
   437 	
       
   438 	//Cleanup registration files
       
   439 	CleanupRegFilesL();
       
   440 	
       
   441  	// Install the test application
       
   442 	iSession.RegisterNonNativeApplicationTypeL(KApFileTestAppType, KLitNativeExecutable);
       
   443 	TRAPD(err, PrepareRegFileL(KApFileTestAppWithMultipleRegistrationFiles, iAppRsc1, iAppIst));
       
   444 	TEST(err==KErrNone);
       
   445 	INFO_PRINTF1(_L("Reg File 1 commited"));
       
   446  	
       
   447 	RFs	fs;
       
   448  	User::LeaveIfError(fs.Connect());
       
   449  	CleanupClosePushL(fs);
       
   450   	TInt ret = fs.MkDirAll(KMmcPrivateDir);
       
   451 	if (ret != KErrAlreadyExists)
       
   452 		{
       
   453 		User::LeaveIfError(ret);			
       
   454 		}
       
   455 	CFileMan* fileManager = CFileMan::NewL(fs);
       
   456  	CleanupStack::PushL(fileManager);
       
   457  	//Make copies of the registration resource files.
       
   458 	ret = fileManager->Copy(iAppRsc1, iAppRsc2, CFileMan::EOverWrite);
       
   459 	TEST(ret==KErrNone);
       
   460 	TBool present = EFalse;
       
   461 	User::LeaveIfError(iUtils.IsFilePresent(iAppRsc2, present));
       
   462 	TEST(present);
       
   463 	INFO_PRINTF1(_L("Reg File 2 created"));
       
   464 	
       
   465 	ret = fileManager->Copy(iAppRsc1, iAppRsc3, CFileMan::EOverWrite);
       
   466 	TEST(ret==KErrNone);
       
   467 	present = EFalse;
       
   468 	User::LeaveIfError(iUtils.IsFilePresent(iAppRsc3, present));
       
   469 	TEST(present);
       
   470 	INFO_PRINTF1(_L("Reg File 3 created"));
       
   471 	
       
   472 	TProcessPriority oldPriority = RProcess().Priority();
       
   473 	RProcess().SetPriority(EPriorityLow); // so that we're pre-empted by the Apparc server when it does its scan
       
   474 	
       
   475 	TRequestStatus status;
       
   476 	RProperty property;
       
   477 	CleanupClosePushL(property);
       
   478 	User::LeaveIfError(RProperty::Set(KApFileTestPubSubCategory, KApFileTestPubSubCallBackKey, CTestSidChecker::EPropertyDefault));
       
   479 	User::LeaveIfError(property.Attach(KApFileTestPubSubCategory, KApFileTestPubSubCallBackKey));
       
   480 	property.Subscribe(status);
       
   481 
       
   482 	RTimer timer;
       
   483 	CleanupClosePushL(timer);
       
   484 	User::LeaveIfError(timer.CreateLocal());
       
   485 	TRequestStatus timerStatus;
       
   486 	timer.After(timerStatus,30 * 1000000);
       
   487 	
       
   488 	RPointerArray<TDesC> empty;
       
   489 	ret = iSession.ForceRegistration(empty);
       
   490 	TEST(ret==KErrNone);
       
   491 	
       
   492 	// Wait for a rescan
       
   493 	User::WaitForRequest(status,timerStatus);
       
   494 	TEST(status != KRequestPending);
       
   495 	if(status != KRequestPending)
       
   496 		{
       
   497 		timer.Cancel();
       
   498 		User::WaitForRequest(timerStatus);
       
   499 		TInt result;	
       
   500 		User::LeaveIfError(RProperty::Get(KApFileTestPubSubCategory, KApFileTestPubSubCallBackKey, result));
       
   501 		TEST(result == CTestSidChecker::ECheckedOnce);
       
   502 		}
       
   503 	else
       
   504 		{
       
   505 		property.Cancel();
       
   506 		User::WaitForRequest(status);
       
   507 		TEST(timerStatus != KRequestPending);
       
   508 		INFO_PRINTF1(_L("Timeout exceeded"));
       
   509 		}
       
   510 		
       
   511 	RProcess().SetPriority(oldPriority);
       
   512 	
       
   513 	INFO_PRINTF1(_L("Removing duplicate reg files"));
       
   514 	TTime tempTime(0); // added tempTime to avoid asynch CFileMan::Attribs request completing with KErrArgument
       
   515 	
       
   516 	TEST(fileManager->Attribs(iAppRsc2,0,KEntryAttReadOnly,tempTime,CFileMan::ERecurse,status)==KErrNone);
       
   517 	User::WaitForRequest(status);
       
   518 	TEST(status.Int()==KErrNone);
       
   519  	TEST(KErrNone==fileManager->Delete(iAppRsc2,CFileMan::ERecurse));
       
   520  	
       
   521  	TEST(fileManager->Attribs(iAppRsc3,0,KEntryAttReadOnly,tempTime,CFileMan::ERecurse,status)==KErrNone);
       
   522 	User::WaitForRequest(status);
       
   523 	TEST(status.Int()==KErrNone);
       
   524  	TEST(KErrNone==fileManager->Delete(iAppRsc3,CFileMan::ERecurse));
       
   525  
       
   526  	CleanupStack::PopAndDestroy(4,&fs);
       
   527 	CleanupRegFilesL();
       
   528 	}
       
   529 	
       
   530 void CT_File3Step::FindRemovableDriveAndSetPathL()
       
   531 {
       
   532 #if defined(__WINS__)
       
   533 	// The removable media is expected at X: on emulator.
       
   534 	iDrive = EDriveX;
       
   535 #else
       
   536 
       
   537 	RFs	fs;
       
   538  	User::LeaveIfError(fs.Connect());
       
   539 
       
   540 	// The removable media is expected at D: on NAND ROM and at E: on normal ROMs.
       
   541 	//The following code works on techview but not guaranteed to work on all platforms. 
       
   542 	TDriveInfo driveInfo;
       
   543 	TInt err = fs.Drive(driveInfo, EDriveD);
       
   544 	if(err == KErrNone && ((driveInfo.iDriveAtt & KDriveAttRemovable) != 0))
       
   545 		{
       
   546 	 	 // Use drive D
       
   547 	 	 iDrive = EDriveD;
       
   548 	 	}
       
   549 	 else
       
   550 	 	{
       
   551 		err = fs.Drive(driveInfo, EDriveE);
       
   552 		if(err == KErrNone && ((driveInfo.iDriveAtt & KDriveAttRemovable) != 0))
       
   553 			{
       
   554 		 	// Use drive E
       
   555 		 	iDrive = EDriveE;
       
   556 		 	}
       
   557 		}
       
   558 	fs.Close();
       
   559 #endif
       
   560 	iCallBackAppRsc = iDrive.Name();
       
   561 	iCallBackAppIst = iDrive.Name();
       
   562 	iBadAppRsc = iDrive.Name();
       
   563 	iBadAppIst = iDrive.Name();
       
   564 	iGoodAppRsc = iDrive.Name();
       
   565 	iGoodAppIst = iDrive.Name();
       
   566 	iForcedAppRsc = iDrive.Name();
       
   567 	iForcedAppIst = iDrive.Name();
       
   568 	iTriggerRescanRsc = iDrive.Name();
       
   569 	iTriggerRescanIst = iDrive.Name();
       
   570 	iMmcPrivateDir = iDrive.Name();
       
   571 	iAppRsc1 = iDrive.Name();
       
   572 	iAppRsc2 = iDrive.Name();
       
   573 	iAppRsc3 = iDrive.Name();
       
   574 	iAppIst = iDrive.Name();
       
   575 	
       
   576 	iCallBackAppRsc.Append(KCallBackAppRsc);
       
   577 	iCallBackAppIst.Append(KCallBackAppIst);
       
   578 	iBadAppRsc.Append(KBadAppRsc);
       
   579 	iBadAppIst.Append(KBadAppIst);
       
   580 	iGoodAppRsc.Append(KGoodAppRsc);
       
   581 	iGoodAppIst.Append(KGoodAppIst);
       
   582 	iForcedAppRsc.Append(KForcedAppRsc);
       
   583 	iForcedAppIst.Append(KForcedAppIst);
       
   584 	iTriggerRescanRsc.Append(KTriggerRescanRsc);
       
   585 	iTriggerRescanIst.Append(KTriggerRescanIst);
       
   586 	iMmcPrivateDir.Append(KMmcPrivateDir);
       
   587 	iAppRsc1.Append(KAppRsc1);
       
   588 	iAppRsc2.Append(KAppRsc2);
       
   589 	iAppRsc3.Append(KAppRsc3);
       
   590 	iAppIst.Append(KAppIst);
       
   591 }
       
   592 
       
   593 TVerdict CT_File3Step::doTestStepPostambleL()
       
   594 /**
       
   595    @return - TVerdict code
       
   596    Override of base class virtual
       
   597  */
       
   598 	{
       
   599 	iSession.Close();
       
   600 	iUtils.Close();
       
   601 	return TestStepResult();
       
   602 	}
       
   603 
       
   604 CT_File3Step::~CT_File3Step()
       
   605 /**
       
   606    Destructor
       
   607  */
       
   608 	{
       
   609 	}
       
   610