common/tools/ats/smoketest/localisation/apparchitecture/tef/T_NonNativeAppsStep.cpp
changeset 793 0c32c669a39d
child 872 17498133d9ad
equal deleted inserted replaced
792:893b85cda81b 793:0c32c669a39d
       
     1 // Copyright (c) 2005-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 /**
       
    19  @file
       
    20  @test
       
    21  @internalComponent - Internal Symbian test code  
       
    22 */
       
    23 
       
    24 #include <E32STD.H>
       
    25 #include <E32BASE.H>
       
    26 #include <F32FILE.H>
       
    27 #include <APGCLI.H>
       
    28 #include <APMREC.H>
       
    29 #include <APAID.H>
       
    30 #include "testableapalssession.h"
       
    31 #include <APGICNFL.H>
       
    32 #include <APMSTD.H>
       
    33 #include <APACMDLN.H>
       
    34 #include <E32PROPERTY.H>
       
    35 #include <apgnotif.h>
       
    36 
       
    37 #include "..\tef\TNonNative\tnnapp1.h"
       
    38 #include "T_NonNativeAppsStep.h"
       
    39 #include <appfwk_test.h>
       
    40 
       
    41 
       
    42 const TUint KApplicationType=0x10207f90;
       
    43 const TUint KApplicationA=0x10207f91;
       
    44 TUint KApplicationB = 0x2002237C;
       
    45 const TUint KMySID=0x101F289C;				// apparctestserver UID
       
    46 const TUint KPropertyCategory=KMySID;
       
    47 const TUint KPropertyKey=0;
       
    48 const TUint KBytesToRead=100;
       
    49 
       
    50 _LIT8(KLit8_DataType_Gif, "x-epoc/nna-gif");
       
    51 _LIT8(KLit8_DataType_Html, "x-epoc/nna-html");
       
    52 _LIT8(KLit8_DataType_Vcard, "x-epoc/nna-vcf");
       
    53 _LIT8(KLit8_DataType_plainText, "x-epoc/nna-txt");
       
    54 
       
    55 _LIT(KLitLogicalExecutableA, "c:\\A.NNAPP2"); // this file never actually needs to exist
       
    56 _LIT(KLitApplicationCaptionA, "Caption NNA A");
       
    57 _LIT(KLitDocumentName1, "nnapp2:1");
       
    58 _LIT(KLitDocumentName2, "nnapp2:2");
       
    59 _LIT(KLitDocumentName3, "nnapp2:3");
       
    60 _LIT(KLitNativeExecutable, "z:\\sys\\bin\\TNNAPP2.EXE");
       
    61 _LIT8(KLitMimeTypeA, "x-epoc/a-nnapp2");
       
    62 _LIT8(KLitMimeTypeB, "x-epoc/dummy");
       
    63 
       
    64 enum TOption 
       
    65 	{
       
    66 	EAppA,
       
    67 	EAppB
       
    68 	};
       
    69 
       
    70 
       
    71 LOCAL_C void DeregisterNonNativeL(TAny* aApparcServer)
       
    72 	{
       
    73 	RApaLsSession& apparcServer=*STATIC_CAST(RApaLsSession*, aApparcServer);
       
    74 	apparcServer.PrepareNonNativeApplicationsUpdatesL();
       
    75 	apparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
    76 	apparcServer.CommitNonNativeApplicationsUpdatesL();
       
    77 	apparcServer.DeregisterNonNativeApplicationTypeL(TUid::Uid(KApplicationType));
       
    78 	}
       
    79 
       
    80 
       
    81 // RTstFileArray
       
    82 
       
    83 RTstFileArray::RTstFileArray(TInt aGranularity)
       
    84 	:iFileArray(aGranularity)
       
    85 	{
       
    86 	}
       
    87 
       
    88 void RTstFileArray::Close()
       
    89 	{
       
    90 	for (TInt i=iFileArray.Count()-1; i>=0; --i)
       
    91 		{
       
    92 		const SFile& file=iFileArray[i];
       
    93 		delete file.iFullFileName;
       
    94 		delete file.iExpectedDataType;
       
    95 		}
       
    96 	iFileArray.Close();
       
    97 	}
       
    98 
       
    99 void RTstFileArray::AppendL(const TDesC& aFullFileName, const TDesC8& aExpectedDataType)
       
   100 	{
       
   101 	SFile file;
       
   102 	file.iFullFileName=aFullFileName.AllocLC();
       
   103 	file.iExpectedDataType=aExpectedDataType.AllocLC();
       
   104 	iFileArray.AppendL(file);
       
   105 	CleanupStack::Pop(2, file.iFullFileName);
       
   106 	}
       
   107 
       
   108 void RTstFileArray::Get(TPtrC& aFullFileName, TPtrC8& aExpectedDataType, TInt aIndex) const
       
   109 	{
       
   110 	const SFile& file=iFileArray[aIndex];
       
   111 	aFullFileName.Set(*file.iFullFileName);
       
   112 	aExpectedDataType.Set(*file.iExpectedDataType);
       
   113 	}
       
   114 
       
   115 
       
   116 // RTstAppService
       
   117 
       
   118 TInt RTstAppService::DoTestL(TUid aServiceUid, TBool aPassingFileByHandle, const TDesC& aFileNameWithoutDriveOrPath)
       
   119 	{ // static
       
   120 	RTstAppService appService(aServiceUid);
       
   121 	CleanupClosePushL(appService);
       
   122 	appService.ConnectL();
       
   123 	TRequestStatus requestStatus;
       
   124 	appService.ReceiveTestResult(requestStatus, aPassingFileByHandle, aFileNameWithoutDriveOrPath);
       
   125 	User::WaitForRequest(requestStatus);
       
   126 	const TInt result=User::LeaveIfError(requestStatus.Int());
       
   127 	CleanupStack::PopAndDestroy(&appService);
       
   128 	User::After(5 * 1000000); //Wait 5sec for Apparc update due to paging
       
   129 	return result;
       
   130 	}
       
   131 
       
   132 RTstAppService::RTstAppService(TUid aServiceUid)
       
   133 	:iServiceUid(aServiceUid)
       
   134 	{
       
   135 	}
       
   136 
       
   137 void RTstAppService::ConnectL()
       
   138 	{
       
   139 	ConnectExistingByNameL(KLitServerName);
       
   140 	}
       
   141 
       
   142 void RTstAppService::ReceiveTestResult(TRequestStatus& aRequestStatus, TBool aPassingFileByHandle, const TDesC& aFileNameWithoutDriveOrPath)
       
   143 	{
       
   144 	SendReceive(EOpcode_receiveTestResult, TIpcArgs(aPassingFileByHandle, &aFileNameWithoutDriveOrPath), aRequestStatus);
       
   145 	}
       
   146 
       
   147 TUid RTstAppService::ServiceUid() const
       
   148 	{
       
   149 	return iServiceUid;
       
   150 	}
       
   151 
       
   152 
       
   153 // top-level functions
       
   154 
       
   155 HBufC8* CT_NonNativeAppsStep::OpenFileAndReadBufferLC(RApaLsSession& aApparcServer, RFs& aFileServer, const TDesC& aFullFileName)
       
   156 	{
       
   157 	TInt preferredBufSize=0;
       
   158 	User::LeaveIfError(aApparcServer.GetPreferredBufSize(preferredBufSize));
       
   159 	HBufC8* const buffer=HBufC8::NewLC(preferredBufSize);
       
   160 	RFile file;
       
   161 	CleanupClosePushL(file);
       
   162 	User::LeaveIfError(file.Open(aFileServer, aFullFileName, EFileShareReadersOnly|EFileStream|EFileRead));
       
   163 	{TPtr8 buffer_asWritable(buffer->Des());
       
   164 	User::LeaveIfError(file.Read(buffer_asWritable));}
       
   165 	CleanupStack::PopAndDestroy(&file);
       
   166 	return buffer;
       
   167 	}
       
   168 
       
   169 void CT_NonNativeAppsStep::OpenFileAndSetFilePositionToSomewhereUnusualLC(RFile& aFile, TInt& aFilePosition, RFs& aFileServer, const TDesC& aFullFileName)
       
   170 	{
       
   171 	CleanupClosePushL(aFile);
       
   172 	User::LeaveIfError(aFile.Open(aFileServer, aFullFileName, EFileShareReadersOnly|EFileStream|EFileRead));
       
   173 	aFilePosition=0;
       
   174 	User::LeaveIfError(aFile.Seek(ESeekEnd, aFilePosition));
       
   175 	aFilePosition=(aFilePosition*83)/100; // set it to somewhere "random" in the middle of the file (83% of the way through)
       
   176 	User::LeaveIfError(aFile.Seek(ESeekStart, aFilePosition));
       
   177 	}
       
   178 
       
   179 void CT_NonNativeAppsStep::TestFilePosition(RFile& aFile, TInt aFilePosition)
       
   180 	{
       
   181 	TInt filePosition=0;
       
   182 	TEST(aFile.Seek(ESeekCurrent, filePosition) == KErrNone);
       
   183 	TEST(filePosition==aFilePosition);
       
   184 	}
       
   185 
       
   186 /**
       
   187    @SYMTestCaseID T_NonNativeAppsStep-TestAppForDocument
       
   188   
       
   189    @SYMDEF	DEF065742
       
   190   
       
   191    @SYMTestCaseDesc Tests AppForDocument API for non native applications.
       
   192   
       
   193    @SYMTestPriority High
       
   194   
       
   195    @SYMTestStatus Implemented
       
   196    
       
   197    @SYMTestActions	Call AppForDocument, first with the file name, and then with the file data, with a series of different known files.
       
   198    		API Calls:\n	
       
   199    		RApaLsSession::AppForDocument(const TDesC &aFileName, TUid &aAppUid, TDataType &aDataType) const;\n
       
   200    		RApaLsSession::AppForDocument(RFile &aFile, TUid &aAppUid, TDataType &aDataType) const;\n
       
   201    
       
   202    @SYMTestExpectedResults Test checks MIME type and UIDs obtained match the expected ones.
       
   203  */
       
   204 void CT_NonNativeAppsStep::TestAppForDocumentL(RApaLsSession& aApparcServer, RFs& aFileServer, const RTstFileArray& aFileArray)
       
   205 	{
       
   206 	INFO_PRINTF1(_L("Testing AppForDocumentL()..."));
       
   207 	for (TInt i=aFileArray.Count()-1; i>=0; --i)
       
   208 		{
       
   209 		TPtrC fullFileName;
       
   210 		TPtrC8 expectedDataType;
       
   211 		aFileArray.Get(fullFileName, expectedDataType, i);
       
   212  
       
   213 		TPtrC fileNameWithoutDriveOrPath(TParsePtrC(fullFileName).NameAndExt());
       
   214 		INFO_PRINTF2(_L("..using following file: '%S'"), &fileNameWithoutDriveOrPath);
       
   215 
       
   216 		{
       
   217 		TDataType dataType;
       
   218 		TUid appUid;
       
   219 		//due to access of file in private folder
       
   220 		APPFWK_EXPECTED_PLATSEC_START;
       
   221 		User::LeaveIfError(aApparcServer.AppForDocument(fullFileName, appUid, dataType));
       
   222 		RDebug::Print(_L("The Full FileName is '%S' "),&fullFileName);
       
   223 		APPFWK_EXPECTED_PLATSEC_FINISH;
       
   224 		TEST(dataType.Des8().CompareF(expectedDataType)==0);
       
   225 		TEST(appUid.iUid==0x10207f92);
       
   226 		}
       
   227 
       
   228 		RFile file;
       
   229 		TInt originalFilePosition=0;
       
   230 		OpenFileAndSetFilePositionToSomewhereUnusualLC(file, originalFilePosition, aFileServer, fullFileName);
       
   231 
       
   232 		{
       
   233 		TDataType dataType;
       
   234 		TUid appUid;
       
   235 		User::LeaveIfError(aApparcServer.AppForDocument(file, appUid, dataType));
       
   236 		TEST(dataType.Des8().CompareF(expectedDataType)==0);
       
   237 		TEST(appUid.iUid==0x10207f92);
       
   238 
       
   239 		TestFilePosition(file, originalFilePosition);
       
   240 		CleanupStack::PopAndDestroy(&file);
       
   241 		}
       
   242 		}
       
   243 	}
       
   244 
       
   245 void CT_NonNativeAppsStep::TestResultsOfAppForDocumentAndServiceL(TUid aServiceUid, TInt aError,
       
   246 						const TUid& aAppUid, // aAppUid needs to be passed by reference (rather than by value) because of the way that this function is called, namely the aAppUid parameter seems to be put into the stack before the expression passed to the aError parameter has executed, the latter having the side-effect of changing the app-UID
       
   247 						const TDataType& aDataType, const TDesC8& aExpectedDataType)
       
   248 	{
       
   249 	if (aServiceUid.iUid==0x10207f99)
       
   250 		{
       
   251 		User::LeaveIfError(aError);
       
   252 		TEST(aDataType.Des8().CompareF(aExpectedDataType)==0);
       
   253 		(aDataType.Des8().CompareF(KLit8_DataType_Gif)==0) ? TEST(aAppUid.iUid==0x10207f94) : TEST(aAppUid.iUid==0);
       
   254 		}
       
   255 	else
       
   256 		{
       
   257 		User::LeaveIfError(aError);
       
   258 		TEST(aDataType.Des8().CompareF(aExpectedDataType)==0);
       
   259 		TEST(aAppUid.iUid==0x10207f92);
       
   260 		}
       
   261 	}
       
   262 
       
   263 /**
       
   264    @SYMTestCaseID T_NonNativeAppsStep-TestAppForDocumentAndServiceL
       
   265   
       
   266    @SYMDEF	DEF065742
       
   267   
       
   268    @SYMTestCaseDesc Tests AppForDocumentAndService API for non native applications.
       
   269   
       
   270    @SYMTestPriority High
       
   271   
       
   272    @SYMTestStatus Implemented
       
   273    
       
   274    @SYMTestActions	Call AppForDocumentAndService, first with the file name, and then with the file data, with a series of different known files and serviceUIDs.
       
   275    		Note the following:
       
   276    			- TNNAPP1 defines in the datatype_list the 4 datatypes, while in the service_list, only 1 datatype is defined.
       
   277    			- TNNAPP2 defines no datatype_list, while it just contains 1 datatype in the service_list.
       
   278    			- The datatype of the file to be opened is searched in the service_list corresponding to the serviceUID. If not found,
       
   279    				the datatype_list of the same reg file is searched. If not found there, it returns a KNullUid as the app.
       
   280    			- It means that the service_list has 'priority' over the datatype_list in the same reg file.
       
   281    		API Calls:\n	
       
   282    		RApaLsSession::AppForDocumentAndService(const TDesC &aFileName, TUid aServiceUid, TUid &aAppUid, TDataType &aDataType) const;\n
       
   283    		RApaLsSession::AppForDocumentAndService(RFile &aFile, TUid aServiceUid, TUid &aAppUid, TDataType &aDataType) const;\n
       
   284    
       
   285    @SYMTestExpectedResults Test checks MIME type and UIDs obtained match the expected ones.
       
   286  */
       
   287 void CT_NonNativeAppsStep::TestAppForDocumentAndServiceL(RApaLsSession& aApparcServer, RFs& aFileServer, const RTstFileArray& aFileArray)
       
   288 	{
       
   289 	INFO_PRINTF1(_L("Testing AppForDocumentAndServiceL()..."));
       
   290 	for (TInt i=aFileArray.Count()-1; i>=0; --i)
       
   291 		{
       
   292 		TPtrC fullFileName;
       
   293 		TPtrC8 expectedDataType;
       
   294 		aFileArray.Get(fullFileName, expectedDataType, i);
       
   295 
       
   296 		TPtrC fileNameWithoutDriveOrPath(TParsePtrC(fullFileName).NameAndExt());
       
   297 		INFO_PRINTF2(_L("..using following file: '%S'"), &fileNameWithoutDriveOrPath);
       
   298 
       
   299 		{
       
   300 		TDataType dataType;
       
   301 		TUid appUid;
       
   302 		TUid serviceUid(TUid::Uid(0x10207f99));
       
   303 		//due to access of file in private folder
       
   304 		APPFWK_EXPECTED_PLATSEC_START;
       
   305 		TestResultsOfAppForDocumentAndServiceL(serviceUid, aApparcServer.AppForDocumentAndService(fullFileName, serviceUid, appUid, dataType), appUid, dataType, expectedDataType);
       
   306 		APPFWK_EXPECTED_PLATSEC_FINISH;
       
   307 		serviceUid.iUid=0x10207f93;
       
   308 		//due to access of file in private folder
       
   309 		APPFWK_EXPECTED_PLATSEC_START;
       
   310 		TestResultsOfAppForDocumentAndServiceL(serviceUid, aApparcServer.AppForDocumentAndService(fullFileName, serviceUid, appUid, dataType), appUid, dataType, expectedDataType);
       
   311 		APPFWK_EXPECTED_PLATSEC_FINISH;
       
   312 		}
       
   313 
       
   314 		{
       
   315 		RFile file;
       
   316 		TInt originalFilePosition=0;
       
   317 		OpenFileAndSetFilePositionToSomewhereUnusualLC(file, originalFilePosition, aFileServer, fullFileName);
       
   318 
       
   319 		TDataType dataType;
       
   320 		TUid appUid;
       
   321 		TUid serviceUid(TUid::Uid(0x10207f99));
       
   322 		TestResultsOfAppForDocumentAndServiceL(serviceUid, aApparcServer.AppForDocumentAndService(file, serviceUid, appUid, dataType), appUid, dataType, expectedDataType);
       
   323 		serviceUid.iUid=0x10207f93;
       
   324 		TestResultsOfAppForDocumentAndServiceL(serviceUid, aApparcServer.AppForDocumentAndService(file, serviceUid, appUid, dataType), appUid, dataType, expectedDataType);
       
   325 
       
   326 		TestFilePosition(file, originalFilePosition);
       
   327 		CleanupStack::PopAndDestroy(&file);
       
   328 		}
       
   329 		}
       
   330 	}
       
   331 
       
   332 /**
       
   333    @SYMTestCaseID T_NonNativeAppsStep-TestRecognizingL
       
   334   
       
   335    @SYMDEF	DEF065742
       
   336   
       
   337    @SYMTestCaseDesc Tests RecognizeData API for non native applications.
       
   338   
       
   339    @SYMTestPriority High
       
   340   
       
   341    @SYMTestStatus Implemented
       
   342    
       
   343    @SYMTestActions	Call RecognizeData, first with the file name, and then with the file data, with a series of different known files.
       
   344    		API Calls:\n	
       
   345    		RApaLsSession::RecognizeData(const TDesC &aName, const TDesC8 &aBuffer, TDataRecognitionResult &aDataType) const;\n
       
   346    		RApaLsSession::RecognizeData(RFile &aFile, TDataRecognitionResult &aDataType) const;\n
       
   347    
       
   348    @SYMTestExpectedResults Test checks MIME type and conficence obtained match the expected ones.
       
   349  */
       
   350 void CT_NonNativeAppsStep::TestRecognizingL(RApaLsSession& aApparcServer, RFs& aFileServer, const RTstFileArray& aFileArray)
       
   351 	{
       
   352 	INFO_PRINTF1(_L("Testing RecognizingL()..."));
       
   353 	for (TInt i=aFileArray.Count()-1; i>=0; --i)
       
   354 		{
       
   355 		TPtrC fullFileName;
       
   356 		TPtrC8 expectedDataType;
       
   357 		aFileArray.Get(fullFileName, expectedDataType, i);
       
   358 
       
   359 		TPtrC fileNameWithoutDriveOrPath(TParsePtrC(fullFileName).NameAndExt());
       
   360 		INFO_PRINTF2(_L("..using following file: '%S'"), &fileNameWithoutDriveOrPath);
       
   361 
       
   362 		{
       
   363 		RFile file;
       
   364 		TInt originalFilePosition=0;
       
   365 		OpenFileAndSetFilePositionToSomewhereUnusualLC(file, originalFilePosition, aFileServer, fullFileName);
       
   366 
       
   367 		TDataRecognitionResult dataRecognitionResult;
       
   368 		dataRecognitionResult.Reset();
       
   369 		User::LeaveIfError(aApparcServer.RecognizeData(file, dataRecognitionResult));
       
   370 		TEST(dataRecognitionResult.iConfidence>=CApaDataRecognizerType::EProbable);
       
   371 		TEST(dataRecognitionResult.iDataType.Des8().CompareF(expectedDataType)==0);
       
   372 
       
   373 		TestFilePosition(file, originalFilePosition);
       
   374 		CleanupStack::PopAndDestroy(&file);
       
   375 		}
       
   376 
       
   377 		{
       
   378 		RFile file;
       
   379 		TInt originalFilePosition=0;
       
   380 		OpenFileAndSetFilePositionToSomewhereUnusualLC(file, originalFilePosition, aFileServer, fullFileName);
       
   381 
       
   382 		TBool result=EFalse;
       
   383 		User::LeaveIfError(aApparcServer.RecognizeSpecificData(file, TDataType(expectedDataType), result));
       
   384 		TEST(result);
       
   385 
       
   386 		TestFilePosition(file, originalFilePosition);
       
   387 		CleanupStack::PopAndDestroy(&file);
       
   388 		}
       
   389 
       
   390 		{
       
   391 		HBufC8* const buffer=OpenFileAndReadBufferLC(aApparcServer, aFileServer, fullFileName);
       
   392 
       
   393 		TDataRecognitionResult dataRecognitionResult;
       
   394 		dataRecognitionResult.Reset();
       
   395 		APPFWK_EXPECTED_PLATSEC_START;
       
   396 		User::LeaveIfError(aApparcServer.RecognizeData(fullFileName, *buffer, dataRecognitionResult));
       
   397 		APPFWK_EXPECTED_PLATSEC_FINISH;
       
   398 		TEST(dataRecognitionResult.iConfidence>=CApaDataRecognizerType::EProbable);
       
   399 		TEST(dataRecognitionResult.iDataType.Des8().CompareF(expectedDataType)==0);
       
   400 
       
   401 		CleanupStack::PopAndDestroy(buffer);
       
   402 		}
       
   403 
       
   404 		{
       
   405 		HBufC8* const buffer=OpenFileAndReadBufferLC(aApparcServer, aFileServer, fullFileName);
       
   406 
       
   407 		TBool result=EFalse;
       
   408 		User::LeaveIfError(aApparcServer.RecognizeSpecificData(fullFileName, *buffer, TDataType(expectedDataType), result));
       
   409 		TEST(result);
       
   410 
       
   411 		CleanupStack::PopAndDestroy(buffer);
       
   412 		}
       
   413 		}
       
   414 	}
       
   415 
       
   416 /**
       
   417    @SYMTestCaseID T_NonNativeAppsStep-TestStartDocumentL
       
   418   
       
   419    @SYMDEF	DEF065742
       
   420   
       
   421    @SYMTestCaseDesc Tests StartDocument API for non native applications.
       
   422   
       
   423    @SYMTestPriority High
       
   424   
       
   425    @SYMTestStatus Implemented
       
   426    
       
   427    @SYMTestActions	Call StartDocument, either with the file name as a parameter or a file handle. The test presupposes that when
       
   428    		the file is passed by name, it can't be oppened as it's in a private folder (since the app doesn't have AllFiles capability).
       
   429    		These provokes few negative platsec errors in the epocwind.out file.
       
   430    		On the other hand, when the file is passed by handle, there are no problems opening the file. No platsec errors should be reported.
       
   431    		API Calls:\n	
       
   432    		RApaLsSession::StartDocument(const TDesC &aFileName, TThreadId &aThreadId, TLaunchType aLaunchType=ELaunchNewApp);\n
       
   433    		RApaLsSession::StartDocument(RFile &aFile, TThreadId &aThreadId, TRequestStatus *aRequestStatusForRendezvous=0);\n
       
   434    		RApaLsSession::StartDocument(const TDesC &aFileName, const TDataType &aDataType, TThreadId &aThreadId, TLaunchType aLaunchType=ELaunchNewApp);\n
       
   435    		RApaLsSession::StartDocument(RFile &aFile, const TDataType &aDataType, TThreadId &aThreadId, TRequestStatus *aRequestStatusForRendezvous=0);\n
       
   436    
       
   437    @SYMTestExpectedResults Test the requeststatus obtained match the expected one.
       
   438  */
       
   439 void CT_NonNativeAppsStep::TestStartDocumentL(RApaLsSession& aApparcServer, RFs& aFileServer, const RTstFileArray& aFileArray)
       
   440 	{
       
   441 	INFO_PRINTF1(_L("Testing StartDocumentL()..."));
       
   442 	for (TInt i=aFileArray.Count()-1; i>=0; --i)
       
   443 		{
       
   444 		TPtrC fullFileName;
       
   445 		TPtrC8 expectedDataType;
       
   446 		aFileArray.Get(fullFileName, expectedDataType, i);
       
   447 
       
   448 		TPtrC fileNameWithoutDriveOrPath(TParsePtrC(fullFileName).NameAndExt());
       
   449 		INFO_PRINTF2(_L("..using following file: '%S'"), &fileNameWithoutDriveOrPath);
       
   450 
       
   451 		for (TInt j=0; j<2; ++j)
       
   452 			{
       
   453 			const TUid serviceUid=(j==0)? KTstServiceUid_nonSecure: KTstServiceUid_secure;
       
   454 			{
       
   455 			RFile file;
       
   456 			TInt originalFilePosition=0;
       
   457 			OpenFileAndSetFilePositionToSomewhereUnusualLC(file, originalFilePosition, aFileServer, fullFileName);
       
   458 
       
   459 			TThreadId threadId;
       
   460 			TRequestStatus requestStatusForRendezvous;
       
   461 			User::LeaveIfError(aApparcServer.StartDocument(file, threadId, &requestStatusForRendezvous));
       
   462 			User::WaitForRequest(requestStatusForRendezvous);
       
   463 			TEST(RTstAppService::DoTestL(serviceUid, ETrue, fileNameWithoutDriveOrPath) == KCheckPass);
       
   464 
       
   465 			TestFilePosition(file, originalFilePosition);
       
   466 			CleanupStack::PopAndDestroy(&file);
       
   467 			}
       
   468 
       
   469 			{
       
   470 			RFile file;
       
   471 			TInt originalFilePosition=0;
       
   472 			OpenFileAndSetFilePositionToSomewhereUnusualLC(file, originalFilePosition, aFileServer, fullFileName);
       
   473 
       
   474 			TThreadId threadId;
       
   475 			TRequestStatus requestStatusForRendezvous;
       
   476 			User::LeaveIfError(aApparcServer.StartDocument(file, TDataType(expectedDataType), threadId, &requestStatusForRendezvous));
       
   477 			User::WaitForRequest(requestStatusForRendezvous);
       
   478 			TEST(RTstAppService::DoTestL(serviceUid, ETrue, fileNameWithoutDriveOrPath) == KCheckPass);
       
   479 
       
   480 			TestFilePosition(file, originalFilePosition);
       
   481 			CleanupStack::PopAndDestroy(&file);
       
   482 			}
       
   483 
       
   484 			{
       
   485 			RFile file;
       
   486 			TInt originalFilePosition=0;
       
   487 			OpenFileAndSetFilePositionToSomewhereUnusualLC(file, originalFilePosition, aFileServer, fullFileName);
       
   488 
       
   489 			TThreadId threadId;
       
   490 			TRequestStatus requestStatusForRendezvous;
       
   491 			User::LeaveIfError(aApparcServer.StartDocument(file, TUid::Uid(0x10207f92), threadId, &requestStatusForRendezvous));
       
   492 			User::WaitForRequest(requestStatusForRendezvous);
       
   493 			TEST(RTstAppService::DoTestL(serviceUid, ETrue, fileNameWithoutDriveOrPath) == KCheckPass);
       
   494 
       
   495 			TestFilePosition(file, originalFilePosition);
       
   496 			CleanupStack::PopAndDestroy(&file);
       
   497 			}
       
   498 
       
   499 			{
       
   500 			TThreadId threadId;
       
   501 			//due to access of file in private folder
       
   502 			APPFWK_EXPECTED_PLATSEC_START;
       
   503 			User::LeaveIfError(aApparcServer.StartDocument(fullFileName, threadId));
       
   504 			APPFWK_EXPECTED_PLATSEC_FINISH;
       
   505 			User::After(1500000);
       
   506 			TEST(RTstAppService::DoTestL(serviceUid, EFalse, fileNameWithoutDriveOrPath) == KCheckPass);
       
   507 			}
       
   508 
       
   509 			{
       
   510 			TThreadId threadId;
       
   511 			User::LeaveIfError(aApparcServer.StartDocument(fullFileName, TDataType(expectedDataType), threadId));
       
   512 			User::After(1500000);
       
   513 			TEST(RTstAppService::DoTestL(serviceUid, EFalse, fileNameWithoutDriveOrPath) == KCheckPass);
       
   514 			}
       
   515 
       
   516 			{
       
   517 			TThreadId threadId;
       
   518 			User::LeaveIfError(aApparcServer.StartDocument(fullFileName, TUid::Uid(0x10207f92), threadId));
       
   519 			User::After(1500000);
       
   520 			TEST(RTstAppService::DoTestL(serviceUid, EFalse, fileNameWithoutDriveOrPath) == KCheckPass);
       
   521 			}
       
   522 			}
       
   523 		}
       
   524 	//avoid race conditions
       
   525 	User::After(1500000);
       
   526 	}
       
   527 	
       
   528 void CT_NonNativeAppsStep::CheckPropertyUpdateAndResetL(const TDesC& aExpectedNewValue)
       
   529 	{
       
   530 	__ASSERT_ALWAYS(aExpectedNewValue.Length()>0, User::Invariant());
       
   531 	RProperty property;
       
   532 	CleanupClosePushL(property);
       
   533 	User::LeaveIfError(property.Attach(TUid::Uid(KPropertyCategory), KPropertyKey));
       
   534 	TRequestStatus requestStatus;
       
   535 	property.Subscribe(requestStatus);
       
   536 	TBuf<50> propertyValue;
       
   537 	User::LeaveIfError(property.Get(propertyValue));
       
   538 	if (propertyValue.Length()>0)
       
   539 		{
       
   540 		property.Cancel();
       
   541 		}
       
   542 	User::WaitForRequest(requestStatus);
       
   543 	if (propertyValue.Length()==0)
       
   544 		{
       
   545 		User::LeaveIfError(property.Get(propertyValue));
       
   546 		}
       
   547 	TEST(propertyValue.CompareF(aExpectedNewValue)==0);
       
   548 	User::LeaveIfError(property.Set(KNullDesC)); // reset it to an empty descriptor
       
   549 	CleanupStack::PopAndDestroy(&property);
       
   550 	}
       
   551 
       
   552 void CT_NonNativeAppsStep::CheckApplicationLaunchesOkayL(RApaLsSession& aApparcServer, const CApaCommandLine& aCommandLine, TAny* aOption)
       
   553 	{
       
   554 	TThreadId notUsed;
       
   555 	const TInt option = TInt(aOption);
       
   556 	switch(option)
       
   557 		{
       
   558 			case EAppA:
       
   559 				INFO_PRINTF1(_L("..Checking ApplicationLaunchesOkayL for app 'A'.."));
       
   560 				User::LeaveIfError(aApparcServer.StartDocument(KLitDocumentName1, TDataType(KLitMimeTypeA), notUsed));
       
   561 				CheckPropertyUpdateAndResetL(KLitDocumentName1);
       
   562 				User::LeaveIfError(aApparcServer.StartApp(aCommandLine));
       
   563 				CheckPropertyUpdateAndResetL(KLitDocumentName2);
       
   564 				break;
       
   565 			case EAppB:
       
   566 				INFO_PRINTF1(_L("..Checking ApplicationLaunchesOkayL for app 'B'.."));
       
   567 				TEST( aApparcServer.StartDocument(KLitDocumentName3, TDataType(KLitMimeTypeB), notUsed) == KErrNone);
       
   568 				break;
       
   569 			default:
       
   570 				break;
       
   571 		}
       
   572 	}
       
   573 
       
   574 void CT_NonNativeAppsStep::CheckApplicationFailsToLaunchL(RApaLsSession& aApparcServer, const CApaCommandLine& aCommandLine, TAny* aOption)
       
   575 	{
       
   576 	TThreadId notUsed;
       
   577 	const TInt option = TInt(aOption);
       
   578 	switch(option)
       
   579 		{
       
   580 			case EAppA:
       
   581 				INFO_PRINTF1(_L("..Checking ApplicationFailsToLaunchL for app 'A'.."));
       
   582 				TEST(aApparcServer.StartDocument(KLitDocumentName1, TDataType(KLitMimeTypeA), notUsed) != KErrNone);
       
   583 				TEST(aApparcServer.StartApp(aCommandLine)!=KErrNone);
       
   584 				break;
       
   585 			case EAppB:
       
   586 				INFO_PRINTF1(_L("..Checking ApplicationFailsToLaunchL for app 'B'.."));
       
   587 				TEST( aApparcServer.StartDocument(KLitDocumentName3, TDataType(KLitMimeTypeB), notUsed) != KErrNone);
       
   588 				break;
       
   589 			default:
       
   590 				break;
       
   591 		}
       
   592 	}
       
   593 	
       
   594 /**
       
   595    @SYMTestCaseID T_NonNativeAppsStep-TestRegisterNonNativeApplicationL
       
   596   
       
   597    @SYMDEF	DEF065742
       
   598   
       
   599    @SYMTestCaseDesc Tests RegisterNonNativeApplicationL and DeregisterNonNativeApplicationL API for non native applications.
       
   600   
       
   601    @SYMTestPriority High
       
   602   
       
   603    @SYMTestStatus Implemented
       
   604    
       
   605    @SYMTestActions Call RegisterNonNativeApplicationL and try to launch the app. Then call 
       
   606    DeregisterNonNativeApplicationL and try to launch the app again. This is repeated with 
       
   607    localisable resource files, etc., etc.. 
       
   608    		API Calls:\n	
       
   609    		RApaLsSession::RegisterNonNativeApplicationL(TUid aApplicationType, const TDriveUnit& aDrive, CApaRegistrationResourceFileWriter& aRegistrationResourceFile, CApaLocalisableResourceFileWriter* aLocalisableResourceFile, RFile* aIconFile); \n
       
   610    		RApaLsSession::DeregisterNonNativeApplicationL(TUid aApplication);\n
       
   611    		RApaLsSession::GetAppIcon(TUid aAppUid, RFile& aFile) const; \n
       
   612    
       
   613    @SYMTestExpectedResults Test checks if app is registered (and launches ok) and deregistered (and fails to launch).
       
   614  */
       
   615 void CT_NonNativeAppsStep::TestRegisterNonNativeApplicationL(RApaLsSession& aApparcServer, RFs& aFileServer )
       
   616 	{
       
   617 	INFO_PRINTF1(_L("Testing RegisterNonNativeApplicationL()..."));
       
   618 
       
   619 	RProcess().SetPriority(EPriorityLow); // so that we're pre-empted by the Apparc server when it does its scan
       
   620 
       
   621 	CApaCommandLine* commandLine=NULL;
       
   622 	User::LeaveIfError(CApaCommandLine::GetCommandLineFromProcessEnvironment(commandLine));
       
   623 	CleanupStack::PushL(commandLine);
       
   624 	const TPtrC executableName(commandLine->ExecutableName());
       
   625 
       
   626 	_LIT_SECURITY_POLICY_S0(readSecurityPolicy, KMySID);
       
   627 	_LIT_SECURITY_POLICY_PASS(writeSecurityPolicy);
       
   628 	const TInt error=RProperty::Define(KPropertyKey, RProperty::EText, readSecurityPolicy, writeSecurityPolicy);
       
   629 	if (error!=KErrAlreadyExists)
       
   630 		{
       
   631 		User::LeaveIfError(error);
       
   632 		}
       
   633 	User::LeaveIfError(RProperty::Set(TUid::Uid(KPropertyCategory), KPropertyKey, KNullDesC));
       
   634 
       
   635 	// make sure we're starting from a clean sheet
       
   636 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   637 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
   638 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   639 	aApparcServer.DeregisterNonNativeApplicationTypeL(TUid::Uid(KApplicationType));
       
   640 	CleanupStack::PushL(TCleanupItem(DeregisterNonNativeL, &aApparcServer));
       
   641 
       
   642 	aApparcServer.RegisterNonNativeApplicationTypeL(TUid::Uid(KApplicationType), KLitNativeExecutable);
       
   643 
       
   644 	CApaRegistrationResourceFileWriter* const registrationResourceFileWriter=CApaRegistrationResourceFileWriter::NewL(TUid::Uid(KApplicationA), KLitLogicalExecutableA, TApaAppCapability::ENonNative);
       
   645 	CleanupStack::PushL(registrationResourceFileWriter);
       
   646 	registrationResourceFileWriter->AddDataTypeL(KDataTypePriorityNormal, KLitMimeTypeA);
       
   647 
       
   648 	CApaCommandLine* const nextCommandLine=CApaCommandLine::NewLC();
       
   649 	nextCommandLine->SetDocumentNameL(KLitDocumentName2);
       
   650 	nextCommandLine->SetExecutableNameL(KLitLogicalExecutableA);
       
   651 	
       
   652 	INFO_PRINTF1(_L("..registering app using RegisterNonNativeApplicationL() "));
       
   653 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   654 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, *registrationResourceFileWriter, NULL, NULL);
       
   655 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   656 	CheckApplicationLaunchesOkayL(aApparcServer, *nextCommandLine, (TAny*)EAppA);
       
   657 	//Check if there is no problem in registering same app again(basically simulating an upgrade)
       
   658 	INFO_PRINTF1(_L("..registering same app again using RegisterNonNativeApplicationL() "));
       
   659 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   660 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, *registrationResourceFileWriter, NULL, NULL);
       
   661 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   662 	CheckApplicationLaunchesOkayL(aApparcServer, *nextCommandLine, (TAny*)EAppA);
       
   663 	
       
   664 	INFO_PRINTF1(_L("..deregistering app using DeregisterNonNativeApplicationL() "));
       
   665 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   666 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
   667 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   668 	CheckApplicationFailsToLaunchL(aApparcServer, *nextCommandLine, (TAny*)EAppA);
       
   669 	
       
   670 	_LIT8(KLitOpData, "opaquedata");
       
   671 	registrationResourceFileWriter->SetOpaqueDataL(KLitOpData);
       
   672 
       
   673 	CApaLocalisableResourceFileWriter* const localisableResourceFileWriter_noIcons=CApaLocalisableResourceFileWriter::NewL(KNullDesC, KLitApplicationCaptionA, 0, KNullDesC);
       
   674 	CleanupStack::PushL(localisableResourceFileWriter_noIcons);
       
   675 	INFO_PRINTF1(_L("..registering app using RegisterNonNativeApplicationL() with localisableResourceFileWriter_noIcons"));
       
   676 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   677 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, *registrationResourceFileWriter, localisableResourceFileWriter_noIcons, NULL);
       
   678 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   679 	CleanupStack::PopAndDestroy(localisableResourceFileWriter_noIcons);
       
   680 	CheckApplicationLaunchesOkayL(aApparcServer, *nextCommandLine, (TAny*)EAppA);
       
   681 
       
   682 	//Testing with OpaqueData
       
   683 	TPtrC8 opData =nextCommandLine->OpaqueData();
       
   684 	TInt tst=opData.CompareF(KLitOpData);
       
   685 	TEST(opData.CompareF(KLitOpData)==0);
       
   686 		
       
   687 	INFO_PRINTF1(_L("..deregistering app using DeregisterNonNativeApplicationL() with localisableResourceFileWriter_noIcons"));
       
   688 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   689 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
   690 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   691 	CheckApplicationFailsToLaunchL(aApparcServer, *nextCommandLine, (TAny*)EAppA);
       
   692 
       
   693 	//Testing with IconFile
       
   694 	CApaLocalisableResourceFileWriter* const localisableResourceFileWriter_withIcons=CApaLocalisableResourceFileWriter::NewL(KNullDesC, KLitApplicationCaptionA, 2, KNullDesC);
       
   695 	CleanupStack::PushL(localisableResourceFileWriter_withIcons);
       
   696 	INFO_PRINTF1(_L("..registering app using RegisterNonNativeApplicationL() with localisableResourceFileWriter_withIcons"));
       
   697 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   698 
       
   699 	RFile iconFile;
       
   700 	CleanupClosePushL(iconFile);
       
   701 	_LIT(KIconFullFileName, "z:\\resource\\apps\\tstapp.mbm");
       
   702 	User::LeaveIfError(iconFile.Open(aFileServer, KIconFullFileName, EFileRead));
       
   703 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, *registrationResourceFileWriter, localisableResourceFileWriter_withIcons, &iconFile);
       
   704 	iconFile.Close();
       
   705 	CleanupStack::PopAndDestroy(&iconFile);
       
   706 	
       
   707 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   708 	CheckApplicationLaunchesOkayL(aApparcServer, *nextCommandLine, (TAny*)EAppA);
       
   709 
       
   710 	HBufC* iconFileName = NULL;
       
   711 	TInt err = aApparcServer.GetAppIcon(TUid::Uid(KApplicationA),iconFileName);
       
   712 	TEST(err == KErrNone);
       
   713 	_LIT(KIconFileName, "tstapp.mbm");
       
   714 	TEST(iconFileName != NULL);
       
   715 	if(iconFileName != NULL)
       
   716 		{
       
   717 		TEST(iconFileName->Des().Find(KIconFileName) >= 0);
       
   718 		delete iconFileName;
       
   719 		}
       
   720 	
       
   721 	//Test other overload of GetAppIcon for MBM icon file.
       
   722 	RFile mbmIconFile;
       
   723 	CleanupClosePushL(mbmIconFile);
       
   724 	INFO_PRINTF1(_L("..testing GetAppIcon for non-native app to retrieve an open file handle to an MBM icon file"));
       
   725 	err = aApparcServer.GetAppIcon(TUid::Uid(KApplicationA), mbmIconFile);
       
   726 	TEST(err == KErrNone);
       
   727 	
       
   728 	TBuf<KMaxFileName> mbmIconFileName;
       
   729 	mbmIconFile.FullName(mbmIconFileName);
       
   730 	TEST(mbmIconFileName.Length() != 0);	
       
   731 	
       
   732 	//Try to write into the MBM icon file whose handle was returned.
       
   733 	INFO_PRINTF1(_L("..writing into the MBM icon file whose handle was returned."));
       
   734 	_LIT8(KSomeText, "It would not be written into the file");
       
   735 	err = mbmIconFile.Write(KSomeText);
       
   736 	TEST(err == KErrAccessDenied);
       
   737 	
       
   738 	//Try to read from the MBM icon file whose handle was returned.
       
   739 	INFO_PRINTF1(_L("..reading from the MBM icon file whose handle was returned."));
       
   740 	TBuf8<KBytesToRead> buffer; //buffer to read first KBytesToRead bytes of the mbm icon file. 
       
   741 	err = mbmIconFile.Read(buffer);
       
   742 	TEST(err == KErrNone);
       
   743 	
       
   744 	//First KBytesToRead bytes of the icon file, this should be same as in mbm file.
       
   745 	RFile tempFile;
       
   746 	CleanupClosePushL(tempFile);
       
   747 	err = tempFile.Open(aFileServer, KIconFullFileName, EFileRead);
       
   748 	TEST(err == KErrNone);
       
   749 	TBuf8<KBytesToRead> buffer1;
       
   750 	err = tempFile.Read(buffer1);
       
   751 	TEST(err == KErrNone);	
       
   752 	TEST(buffer == buffer1);
       
   753 	
       
   754 	//Close icon files.
       
   755 	CleanupStack::PopAndDestroy(2, &mbmIconFile);
       
   756 	
       
   757 	INFO_PRINTF1(_L("..deregistering app using DeregisterNonNativeApplicationL() with localisableResourceFileWriter_withIcons"));
       
   758 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   759 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
   760 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   761 	CheckApplicationFailsToLaunchL(aApparcServer, *nextCommandLine, (TAny*)EAppA);
       
   762 	
       
   763 	//Testing GetAppIcon API for non-native application with SVG icon.
       
   764 	TestGetAppIconForNonNativeL(aApparcServer,aFileServer, registrationResourceFileWriter, localisableResourceFileWriter_withIcons);
       
   765 	
       
   766  	// clean-up
       
   767 	CleanupStack::PopAndDestroy(5, commandLine);
       
   768 	}
       
   769 
       
   770 /**
       
   771    @SYMTestCaseID APPFWK-APPARC-0072
       
   772   
       
   773    @SYMDEF INC098717: support for scalable midlet icons is missing 
       
   774   
       
   775    @SYMTestCaseDesc Tests GetAppIcon API for non native applications with SVG icon file.
       
   776   
       
   777    @SYMTestPriority High
       
   778   
       
   779    @SYMTestStatus Implemented
       
   780    
       
   781    @SYMTestActions Register a non-native app with a SVG icon file, Call GetAppIcon API, 
       
   782    deregister the app. Again register the same app without the icon file, call GetAppIcon 
       
   783    API, deregister the app. Call GetAppIcon with an invalid app uid.
       
   784    
       
   785    @SYMTestExpectedResults RApaLsSession::GetAppIcon should return KErrNotFound when 
       
   786    an invalid app uid is passed, KErrNotFound when application does not have an icon 
       
   787    file, KErrNone and an open file handle to the application's icon file if app has icon file.
       
   788  */
       
   789 void CT_NonNativeAppsStep::TestGetAppIconForNonNativeL(RApaLsSession& aApparcServer,
       
   790                                                        RFs& aFileServer, 
       
   791                                                        CApaRegistrationResourceFileWriter* const aRegistrationResourceFileWriter, 
       
   792                                                        CApaLocalisableResourceFileWriter* const aLocalisableResourceFileWriter)
       
   793 	{
       
   794 	//Testing GetAppIcon for non-native app having SVG icon file
       
   795 	INFO_PRINTF1(_L("..registering app using RegisterNonNativeApplicationL() with localisableResourceFileWriter_withIcons"));
       
   796 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   797 
       
   798 	RFile iconFile;
       
   799 	CleanupClosePushL(iconFile);
       
   800 	_LIT(KSVGIconSourceFile, "z:\\resource\\apps\\svg_icon.svg");
       
   801 	User::LeaveIfError(iconFile.Open(aFileServer, KSVGIconSourceFile, EFileRead));
       
   802 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, *aRegistrationResourceFileWriter, aLocalisableResourceFileWriter, &iconFile);
       
   803 	CleanupStack::PopAndDestroy(&iconFile);
       
   804 	
       
   805 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   806 	
       
   807 	RFile svgIconFile;
       
   808 	CleanupClosePushL(svgIconFile);
       
   809 	INFO_PRINTF1(_L("..testing GetAppIcon for non-native app to retrieve an open file handle to an SVG icon file"));
       
   810 	TInt err = aApparcServer.GetAppIcon(TUid::Uid(KApplicationA),svgIconFile);
       
   811 	TEST(err == KErrNone);
       
   812 	
       
   813 	_LIT(KSVGIconFileName, "c:\\private\\10003a3f\\import\\apps\\nonnative\\resource\\svg_icon.svg");
       
   814 	TBuf<KMaxFileName> iconFileName;
       
   815 	//Get the name of the icon file 
       
   816 	svgIconFile.FullName(iconFileName);
       
   817 	TEST(iconFileName.Length() != 0);
       
   818 	if (iconFileName.Length() != 0)
       
   819 		{
       
   820 		INFO_PRINTF1(_L("..testing if the SVG icon file for non-native app gets installed in apparc's data cage"));
       
   821 		iconFileName.LowerCase();
       
   822 		TEST(iconFileName.Compare(KSVGIconFileName) == 0);
       
   823 		}	
       
   824 		
       
   825 	//Try to write into the icon file whose handle was returned.
       
   826 	INFO_PRINTF1(_L("..writing into the SVG icon file whose handle was returned."));
       
   827 	_LIT8(KSomeText, "It would not be written into the file");
       
   828 	err = svgIconFile.Write(KSomeText);
       
   829 	TEST(err == KErrAccessDenied);
       
   830 	
       
   831 	//Try to read from the icon file whose handle was returned.
       
   832 	INFO_PRINTF1(_L("..reading from the SVG icon file whose handle was returned."));
       
   833 	TBuf8<KBytesToRead> buffer; //buffer to read first KBytesToRead bytes of the icon file. 
       
   834 	err = svgIconFile.Read(buffer);
       
   835 	TEST(err == KErrNone);
       
   836 	
       
   837 	//First KBytesToRead bytes of the icon file, this should be same as in svg file.
       
   838 	RFile tempFile;
       
   839 	CleanupClosePushL(tempFile);
       
   840 	err = tempFile.Open(aFileServer, KSVGIconSourceFile, EFileRead);
       
   841 	TEST(err == KErrNone);
       
   842 	TBuf8<KBytesToRead> buffer1;
       
   843 	err = tempFile.Read(buffer1);
       
   844 	TEST(err == KErrNone);
       
   845 	TEST(buffer == buffer1);
       
   846 	
       
   847 	//Close icon files
       
   848 	CleanupStack::PopAndDestroy(2, &svgIconFile);
       
   849 		
       
   850 	INFO_PRINTF1(_L("..deregistering app using DeregisterNonNativeApplicationL() with localisableResourceFileWriter_withIcons"));
       
   851 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   852 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
   853 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   854 	
       
   855 	//Testing GetAppIcon for non-native app without SVG Icon file.
       
   856 	INFO_PRINTF1(_L("..registering app using RegisterNonNativeApplicationL() with localisableResourceFileWriter_withIcons"));
       
   857 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   858 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, *aRegistrationResourceFileWriter, aLocalisableResourceFileWriter, NULL);		
       
   859 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   860 	
       
   861 	INFO_PRINTF1(_L("..testing GetAppIcon for non-native app that does not have an icon file"));
       
   862 	RFile iconFile1;
       
   863 	CleanupClosePushL(iconFile1);
       
   864 	err = aApparcServer.GetAppIcon(TUid::Uid(KApplicationA),iconFile1);
       
   865 	TEST(err == KErrNotFound);
       
   866 			
       
   867 	INFO_PRINTF1(_L("..deregistering app using DeregisterNonNativeApplicationL() with localisableResourceFileWriter_withIcons"));
       
   868 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   869 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
   870 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   871 	
       
   872 	//Testing GetAppIcon with an invalid app UID.
       
   873 	INFO_PRINTF1(_L("..testing GetAppIcon, if an invalid app UID is passed"));
       
   874 	err = aApparcServer.GetAppIcon(TUid::Uid(KApplicationA),iconFile1);
       
   875 	TEST(err == KErrNotFound);
       
   876 	
       
   877 	//Close icon file
       
   878 	CleanupStack::PopAndDestroy(&iconFile1);
       
   879 	}
       
   880 
       
   881 
       
   882 /**
       
   883    @SYMTestCaseID APPFWK-APPARC-0099
       
   884   
       
   885    @SYMDEF	PDEF129466
       
   886   
       
   887    @SYMTestCaseDesc Tests ForceCommitNonNativeApplicationsUpdatesL() API.
       
   888   
       
   889    @SYMTestPriority High
       
   890   
       
   891    @SYMTestStatus Implemented
       
   892    
       
   893    @SYMTestActions Call RegisterNonNativeApplicationL and try to launch the app. Then call 
       
   894    DeregisterNonNativeApplicationL and try to launch the app again. ForceCommitNonNativeApplicationsUpdatesL
       
   895    API is used to commit the non-native application updates.
       
   896    
       
   897    @SYMTestExpectedResults Test checks ForceCommitNonNativeApplicationsUpdatesL behaviour and completed with success.
       
   898  */
       
   899 void CT_NonNativeAppsStep::TestCommitNNAppUpdatesL(RApaLsSession& aApparcServer)
       
   900 	{
       
   901 	INFO_PRINTF1(_L("Testing ForceCommitNonNativeApplicationsUpdatesL API..."));
       
   902 
       
   903 	RProcess().SetPriority(EPriorityLow); // so that we're pre-empted by the Apparc server when it does its scan
       
   904 
       
   905 	CApaCommandLine* commandLine=NULL;
       
   906 	User::LeaveIfError(CApaCommandLine::GetCommandLineFromProcessEnvironment(commandLine));
       
   907 	CleanupStack::PushL(commandLine);
       
   908 	const TPtrC executableName(commandLine->ExecutableName());
       
   909 
       
   910 
       
   911 	_LIT_SECURITY_POLICY_S0(readSecurityPolicy, KMySID);
       
   912 	_LIT_SECURITY_POLICY_PASS(writeSecurityPolicy);
       
   913 	
       
   914 	//TNNAPP2.exe sets the document name passed as part of the command line to this property.
       
   915 	const TInt error=RProperty::Define(KPropertyKey, RProperty::EText, readSecurityPolicy, writeSecurityPolicy);
       
   916 	if (error!=KErrAlreadyExists)
       
   917 		{
       
   918 		User::LeaveIfError(error);
       
   919 		}
       
   920 	User::LeaveIfError(RProperty::Set(TUid::Uid(KPropertyCategory), KPropertyKey, KNullDesC));
       
   921 
       
   922 	// make sure we're starting from a clean sheet
       
   923 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   924 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
   925 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   926 	aApparcServer.DeregisterNonNativeApplicationTypeL(TUid::Uid(KApplicationType));
       
   927 	CleanupStack::PushL(TCleanupItem(DeregisterNonNativeL, &aApparcServer));
       
   928 
       
   929 	aApparcServer.RegisterNonNativeApplicationTypeL(TUid::Uid(KApplicationType), KLitNativeExecutable);
       
   930 
       
   931 	CApaRegistrationResourceFileWriter* const registrationResourceFileWriter=CApaRegistrationResourceFileWriter::NewL(TUid::Uid(KApplicationA), KLitLogicalExecutableA, TApaAppCapability::ENonNative);
       
   932 	CleanupStack::PushL(registrationResourceFileWriter);
       
   933 	registrationResourceFileWriter->AddDataTypeL(KDataTypePriorityNormal, KLitMimeTypeA);
       
   934 
       
   935 	CApaCommandLine* const nextCommandLine=CApaCommandLine::NewLC();
       
   936 	nextCommandLine->SetDocumentNameL(KLitDocumentName2);
       
   937 	nextCommandLine->SetExecutableNameL(KLitLogicalExecutableA);
       
   938 	
       
   939 	
       
   940 	INFO_PRINTF1(_L("..registering app using RegisterNonNativeApplicationL() "));
       
   941 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   942 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, *registrationResourceFileWriter, NULL, NULL);
       
   943 	TTime startTime,endTime;
       
   944 	TTimeIntervalMicroSeconds timeTakenToCommitRegistration;
       
   945 	INFO_PRINTF1(_L("..start commiting the registration with CommitNonNativeApplicationsUpdatesL"));
       
   946 	startTime.HomeTime();
       
   947 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   948 	endTime.HomeTime();
       
   949 	INFO_PRINTF1(_L("..commiting the registration is done"));	
       
   950 	timeTakenToCommitRegistration=endTime.MicroSecondsFrom(startTime);
       
   951 
       
   952 	TInt64 value = timeTakenToCommitRegistration.Int64();
       
   953 	INFO_PRINTF2(_L("..Time taken for registration of application by CommitNonNativeApplicationsUpdatesL is %d micro seconds"), value);	
       
   954 	CheckApplicationLaunchesOkayL(aApparcServer, *nextCommandLine, (TAny*)EAppA);
       
   955 	
       
   956 	INFO_PRINTF1(_L("..deregistering app using DeregisterNonNativeApplicationL() "));
       
   957 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   958 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
   959 	TTimeIntervalMicroSeconds timeTakenToCommitDeregistration;
       
   960 	INFO_PRINTF1(_L("..start commiting the deregistration with CommitNonNativeApplicationsUpdatesL"));
       
   961 	startTime.HomeTime();	
       
   962 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
   963 	endTime.HomeTime();	
       
   964 	INFO_PRINTF1(_L("..commiting the deregistration is done"));
       
   965 	timeTakenToCommitDeregistration=endTime.MicroSecondsFrom(startTime);
       
   966 	value = timeTakenToCommitDeregistration.Int64();
       
   967 	INFO_PRINTF2(_L("..Time taken for deregistration of application by CommitNonNativeApplicationsUpdatesL is %d micro seconds"), value);	
       
   968 	CheckApplicationFailsToLaunchL(aApparcServer, *nextCommandLine, (TAny*)EAppA);
       
   969 
       
   970 	
       
   971 	INFO_PRINTF1(_L("..registering app using RegisterNonNativeApplicationL() "));
       
   972 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   973 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, *registrationResourceFileWriter, NULL, NULL);
       
   974 	TTimeIntervalMicroSeconds timeTakenToForceCommitRegistration;
       
   975 	INFO_PRINTF1(_L("..start commiting the registration with ForceCommitNonNativeApplicationsUpdatesL"));
       
   976 	startTime.HomeTime();
       
   977 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
   978 	endTime.HomeTime();
       
   979 	INFO_PRINTF1(_L("..commiting the registration is done"));
       
   980 	timeTakenToForceCommitRegistration=endTime.MicroSecondsFrom(startTime);
       
   981 	value = timeTakenToForceCommitRegistration.Int64();
       
   982 	INFO_PRINTF2(_L("..Time taken for registration of application by ForceCommitNonNativeApplicationsUpdatesL is %d micro seconds"), value);
       
   983 	TRequestStatus appScanCompleted=KRequestPending; 
       
   984 	aApparcServer.SetNotify(EFalse,appScanCompleted);    
       
   985 	User::WaitForRequest(appScanCompleted); 
       
   986 	TEST(appScanCompleted.Int()==MApaAppListServObserver::EAppListChanged);
       
   987 	CheckApplicationLaunchesOkayL(aApparcServer, *nextCommandLine, (TAny*)EAppA);
       
   988 	
       
   989 	INFO_PRINTF1(_L("..deregistering app using DeregisterNonNativeApplicationL() "));
       
   990 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
   991 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
   992 	TTimeIntervalMicroSeconds timeTakenToForceCommitDeregistration;
       
   993 	INFO_PRINTF1(_L("..start commiting the deregistration with ForceCommitNonNativeApplicationsUpdatesL"));
       
   994 	startTime.HomeTime();	
       
   995 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
   996 	endTime.HomeTime();	
       
   997 	INFO_PRINTF1(_L("..commiting the deregistration is done"));
       
   998 	timeTakenToForceCommitDeregistration=endTime.MicroSecondsFrom(startTime);
       
   999 	value = timeTakenToForceCommitDeregistration.Int64();
       
  1000 	INFO_PRINTF2(_L("..Time taken for deregistration of application by ForceCommitNonNativeApplicationsUpdatesL is %d micro seconds"), value);
       
  1001 	appScanCompleted=KRequestPending; 
       
  1002 	aApparcServer.SetNotify(EFalse,appScanCompleted);    
       
  1003 	User::WaitForRequest(appScanCompleted);
       
  1004 	TEST(appScanCompleted.Int()==MApaAppListServObserver::EAppListChanged);
       
  1005 	CheckApplicationFailsToLaunchL(aApparcServer, *nextCommandLine, (TAny*)EAppA);
       
  1006 	TEST(timeTakenToForceCommitRegistration<timeTakenToCommitRegistration);	
       
  1007 	TEST(timeTakenToForceCommitDeregistration<timeTakenToCommitDeregistration);
       
  1008 	
       
  1009 	CleanupStack::PopAndDestroy(4, commandLine);
       
  1010 	}
       
  1011 	
       
  1012 /**
       
  1013    @SYMTestCaseID 			APPFWK-APPARC-0103
       
  1014   
       
  1015    @SYMDEF					PDEF134174
       
  1016   
       
  1017    @SYMTestCaseDesc 		Tests ForceCommitNonNativeApplicationsUpdatesL() API.
       
  1018   
       
  1019    @SYMTestPriority 		High
       
  1020   
       
  1021    @SYMTestStatus 			Implemented
       
  1022    
       
  1023    @SYMTestActions 			Make back to back installations of apps and notice that the app in not updated to the applist
       
  1024    							immediately. All apps are updated only after the last ForceCommitNonNativeApplicationsUpdatesL.
       
  1025    				   			Note that previous ForceCommitNonNativeApplicationsUpdatesL actions are updates in applist 
       
  1026    							when RollbackNonNativeApplicationsUpdates is called.
       
  1027    
       
  1028    @SYMTestExpectedResults 	Test checks ForceCommitNonNativeApplicationsUpdatesL and RollbackNonNativeApplicationsUpdates behaviour and completed with success.
       
  1029  */
       
  1030  void CT_NonNativeAppsStep::TestForceCommitNNAppUpdatesL(RApaLsSession& aApparcServer)
       
  1031  	{
       
  1032  	INFO_PRINTF1(_L("Testing ForceCommitNonNativeApplicationsUpdatesL API..."));
       
  1033 
       
  1034 	RProcess().SetPriority(EPriorityLow); // so that we're pre-empted by the Apparc server when it does its scan
       
  1035 
       
  1036 	CApaCommandLine* commandLine=NULL;
       
  1037 	User::LeaveIfError(CApaCommandLine::GetCommandLineFromProcessEnvironment(commandLine));
       
  1038 	CleanupStack::PushL(commandLine);
       
  1039 	const TPtrC executableName(commandLine->ExecutableName());
       
  1040 
       
  1041 
       
  1042 	_LIT_SECURITY_POLICY_S0(readSecurityPolicy, KMySID);
       
  1043 	_LIT_SECURITY_POLICY_PASS(writeSecurityPolicy);
       
  1044 	
       
  1045 	//TNNAPP2.exe sets the document name passed as part of the command line to this property.
       
  1046 	const TInt error=RProperty::Define(KPropertyKey, RProperty::EText, readSecurityPolicy, writeSecurityPolicy);
       
  1047 	if (error!=KErrAlreadyExists)
       
  1048 		{
       
  1049 		User::LeaveIfError(error);
       
  1050 		}
       
  1051 	User::LeaveIfError(RProperty::Set(TUid::Uid(KPropertyCategory), KPropertyKey, KNullDesC));
       
  1052 
       
  1053 	// make sure we're starting from a clean sheet
       
  1054 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1055 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
  1056 	aApparcServer.CommitNonNativeApplicationsUpdatesL();
       
  1057 	aApparcServer.DeregisterNonNativeApplicationTypeL(TUid::Uid(KApplicationType));
       
  1058 	CleanupStack::PushL(TCleanupItem(DeregisterNonNativeL, &aApparcServer));
       
  1059 
       
  1060 	INFO_PRINTF1(_L("..Registering type KApplicationType using RegisterNonNativeApplicationTypeL() "));
       
  1061 	aApparcServer.RegisterNonNativeApplicationTypeL(TUid::Uid(KApplicationType), KLitNativeExecutable);
       
  1062 
       
  1063 	CApaRegistrationResourceFileWriter* const registrationResourceFileWriter=CApaRegistrationResourceFileWriter::NewL(TUid::Uid(KApplicationA), KLitLogicalExecutableA, TApaAppCapability::ENonNative);
       
  1064 	CleanupStack::PushL(registrationResourceFileWriter);
       
  1065 	INFO_PRINTF1(_L("..Add datatype to app 'A'"));
       
  1066 	registrationResourceFileWriter->AddDataTypeL(KDataTypePriorityNormal, KLitMimeTypeA);
       
  1067 
       
  1068 	CApaCommandLine* const nextCommandLine=CApaCommandLine::NewLC();
       
  1069 	nextCommandLine->SetDocumentNameL(KLitDocumentName2);
       
  1070 	nextCommandLine->SetExecutableNameL(KLitLogicalExecutableA);
       
  1071 	
       
  1072 	TApaAppInfo info;
       
  1073 	CApaRegistrationResourceFileWriter* const registrationResourceFileWriterB=CApaRegistrationResourceFileWriter::NewL(TUid::Uid(KApplicationB), KLitLogicalExecutableA, TApaAppCapability::ENonNative);
       
  1074 	CleanupStack::PushL(registrationResourceFileWriterB);
       
  1075 	registrationResourceFileWriterB->AddDataTypeL(KDataTypePriorityNormal, KLitMimeTypeB);
       
  1076 	
       
  1077 	TestForceCommitL(aApparcServer, *registrationResourceFileWriter, *registrationResourceFileWriterB, *nextCommandLine);
       
  1078 	TestRollbackRegistrationL(aApparcServer, *registrationResourceFileWriter, *registrationResourceFileWriterB, *nextCommandLine);
       
  1079 	TestRollbackDeregistrationL(aApparcServer, *registrationResourceFileWriter, *registrationResourceFileWriterB, *nextCommandLine);
       
  1080 	
       
  1081 	CleanupStack::PopAndDestroy(5, commandLine);
       
  1082  	}
       
  1083  	
       
  1084  void CT_NonNativeAppsStep::WaitForApplistUpdate(RApaLsSession& aApparcServer)
       
  1085  	{
       
  1086  	INFO_PRINTF1(_L("..waiting for applist to be updated "));
       
  1087  	TRequestStatus appScanCompleted=KRequestPending; 
       
  1088 	aApparcServer.SetNotify(EFalse,appScanCompleted);    
       
  1089 	User::WaitForRequest(appScanCompleted);
       
  1090 	TEST(appScanCompleted.Int()==MApaAppListServObserver::EAppListChanged);
       
  1091  	}
       
  1092  	
       
  1093  void CT_NonNativeAppsStep::TestForceCommitL(RApaLsSession& aApparcServer, CApaRegistrationResourceFileWriter& aRegistrationResourceFileWriter, CApaRegistrationResourceFileWriter& aRegistrationResourceFileWriterB, CApaCommandLine& aNextCommandLine)
       
  1094  	{
       
  1095  	INFO_PRINTF1(_L("..Start Testing TestForceCommitL API..."));
       
  1096  	
       
  1097  	//Register app A and ForceCommitNNAUpdate
       
  1098 	INFO_PRINTF1(_L("..registering app 'A' using RegisterNonNativeApplicationL() "));
       
  1099 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1100 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, aRegistrationResourceFileWriter, NULL, NULL);
       
  1101 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
  1102 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppA);//Since applist update has not yet completed
       
  1103 	
       
  1104 	//Register app B and ForceCommitNNAUpdate
       
  1105 	INFO_PRINTF1(_L("..registering app 'B' using RegisterNonNativeApplicationL() "));
       
  1106 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1107 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, aRegistrationResourceFileWriterB, NULL, NULL);
       
  1108 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
  1109 	TThreadId notUsed2;
       
  1110 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppB);
       
  1111 	
       
  1112 	//Wait for applist to be updated
       
  1113 	WaitForApplistUpdate(aApparcServer);
       
  1114 	CheckApplicationLaunchesOkayL(aApparcServer, aNextCommandLine, (TAny*)EAppA);//Check if app A launches since applist update is complete now
       
  1115 	CheckApplicationLaunchesOkayL(aApparcServer, aNextCommandLine, (TAny*)EAppB);//Similarly check if app B launches
       
  1116 	
       
  1117 	//DeRegister app B and ForceCommitNNAUpdate
       
  1118 	INFO_PRINTF1(_L("..deregistering app 'B' using DeregisterNonNativeApplicationL() "));
       
  1119 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1120 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationB));
       
  1121 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
  1122 	//Since applist update has not yet completed, both apps should launch
       
  1123 	CheckApplicationLaunchesOkayL(aApparcServer, aNextCommandLine, (TAny*)EAppA); 
       
  1124 	CheckApplicationLaunchesOkayL(aApparcServer, aNextCommandLine, (TAny*)EAppB);
       
  1125 	
       
  1126 	//Wait for applist to be updated
       
  1127 	WaitForApplistUpdate(aApparcServer);
       
  1128 	CheckApplicationLaunchesOkayL(aApparcServer, aNextCommandLine, (TAny*)EAppA);
       
  1129 	//Check if app B fails to launches Since applist update is complete now
       
  1130 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppB);
       
  1131 	
       
  1132 	//Deregister app A and ForceCommitNNAUpdate
       
  1133 	INFO_PRINTF1(_L("..deregistering app 'A' using RegisterNonNativeApplicationL() "));
       
  1134 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1135 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
  1136 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
  1137 	WaitForApplistUpdate(aApparcServer);
       
  1138 	//Both apps fail to launch since they are deregistered
       
  1139 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppA);
       
  1140 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppB);
       
  1141 	
       
  1142 	INFO_PRINTF1(_L("..End Testing TestForceCommitL API..."));
       
  1143  	}
       
  1144  
       
  1145   void CT_NonNativeAppsStep::TestRollbackRegistrationL(RApaLsSession& aApparcServer, CApaRegistrationResourceFileWriter& aRegistrationResourceFileWriter, CApaRegistrationResourceFileWriter& aRegistrationResourceFileWriterB, CApaCommandLine& aNextCommandLine)
       
  1146  	{
       
  1147  	INFO_PRINTF1(_L("..Start Testing TestRollbackRegistrationL API..."));
       
  1148  	
       
  1149  	//Register app A and ForceCommitNNAUpdate
       
  1150 	INFO_PRINTF1(_L("..registering app 'A' using RegisterNonNativeApplicationL() "));
       
  1151 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1152 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, aRegistrationResourceFileWriter, NULL, NULL);
       
  1153 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
  1154 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppA);//Since applist update has not yet completed
       
  1155 	
       
  1156 	//Register app B and RollbackNNAUpdates
       
  1157 	INFO_PRINTF1(_L("..registering app 'B' using RegisterNonNativeApplicationL() "));
       
  1158 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1159 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, aRegistrationResourceFileWriterB, NULL, NULL);
       
  1160 	aApparcServer.RollbackNonNativeApplicationsUpdates();
       
  1161 	
       
  1162 	//Wait for applist to be updated
       
  1163 	WaitForApplistUpdate(aApparcServer);
       
  1164 	CheckApplicationLaunchesOkayL(aApparcServer, aNextCommandLine, (TAny*)EAppA);//Check if app A launches
       
  1165 	//App B's registration was rolled back, so cannot launch it
       
  1166 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppB);
       
  1167 	
       
  1168 	//DeRegister app A and ForceCommitNNAUpdate
       
  1169 	INFO_PRINTF1(_L("..deregistering app 'A' using DeregisterNonNativeApplicationL() "));
       
  1170 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1171 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
  1172 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
  1173 	//Since applist update has not yet completed, app A should launch
       
  1174 	CheckApplicationLaunchesOkayL(aApparcServer, aNextCommandLine, (TAny*)EAppA); 
       
  1175 	
       
  1176 	//Wait for applist to be updated
       
  1177 	WaitForApplistUpdate(aApparcServer);
       
  1178 	//Both apps fail to launch
       
  1179 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppA);
       
  1180 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppB);
       
  1181 	
       
  1182 	INFO_PRINTF1(_L("..End Testing TestRollbackRegistrationL API..."));
       
  1183 	}
       
  1184  	
       
  1185   void CT_NonNativeAppsStep::TestRollbackDeregistrationL(RApaLsSession& aApparcServer, CApaRegistrationResourceFileWriter& aRegistrationResourceFileWriter, CApaRegistrationResourceFileWriter& aRegistrationResourceFileWriterB, CApaCommandLine& aNextCommandLine)
       
  1186  	{
       
  1187  	INFO_PRINTF1(_L("..Start Testing TestRollbackDeregistrationL API..."));
       
  1188  	
       
  1189  	//Register app A and ForceCommitNNAUpdate
       
  1190 	INFO_PRINTF1(_L("..registering app 'A' using RegisterNonNativeApplicationL() "));
       
  1191 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1192 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, aRegistrationResourceFileWriter, NULL, NULL);
       
  1193 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
  1194 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppA);//Since applist update has not yet completed
       
  1195 	
       
  1196 	//Register app B and ForceCommitNNAUpdate
       
  1197 	INFO_PRINTF1(_L("..registering app 'B' using RegisterNonNativeApplicationL() "));
       
  1198 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1199 	aApparcServer.RegisterNonNativeApplicationL(TUid::Uid(KApplicationType), EDriveC, aRegistrationResourceFileWriterB, NULL, NULL);
       
  1200 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
  1201 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppB);
       
  1202 	
       
  1203 	//Wait for applist to be updated
       
  1204 	WaitForApplistUpdate(aApparcServer);
       
  1205 	//Check if both apps launches since applist update is complete now
       
  1206 	CheckApplicationLaunchesOkayL(aApparcServer, aNextCommandLine, (TAny*)EAppA);
       
  1207 	CheckApplicationLaunchesOkayL(aApparcServer, aNextCommandLine, (TAny*)EAppB);
       
  1208 	
       
  1209 	//DeRegister app B and ForceCommitNNAUpdate
       
  1210 	INFO_PRINTF1(_L("..deregistering app 'B' using DeregisterNonNativeApplicationL() "));
       
  1211 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1212 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationB));
       
  1213 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
  1214 	
       
  1215 	//DeRegister app A and ForceCommitNNAUpdate
       
  1216 	INFO_PRINTF1(_L("..deregistering app 'A' using DeregisterNonNativeApplicationL() "));
       
  1217 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1218 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
  1219 	aApparcServer.RollbackNonNativeApplicationsUpdates();
       
  1220 	
       
  1221 	//Wait for applist to be updated
       
  1222 	WaitForApplistUpdate(aApparcServer);
       
  1223 	//Since deregistration of app A was rolled back it still launches
       
  1224 	CheckApplicationLaunchesOkayL(aApparcServer, aNextCommandLine, (TAny*)EAppA); 
       
  1225 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppB);
       
  1226 
       
  1227 	INFO_PRINTF1(_L("..deregistering app 'A' using DeregisterNonNativeApplicationL() "));
       
  1228 	aApparcServer.PrepareNonNativeApplicationsUpdatesL();
       
  1229 	aApparcServer.DeregisterNonNativeApplicationL(TUid::Uid(KApplicationA));
       
  1230 	aApparcServer.ForceCommitNonNativeApplicationsUpdatesL();
       
  1231 
       
  1232 	//Wait for applist to be updated
       
  1233 	WaitForApplistUpdate(aApparcServer);
       
  1234 	//Both apps fail to launch
       
  1235 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppA);
       
  1236 	CheckApplicationFailsToLaunchL(aApparcServer, aNextCommandLine, (TAny*)EAppB);
       
  1237 	
       
  1238 	INFO_PRINTF1(_L("..End Testing TestRollbackDeregistrationL API..."));
       
  1239  	}
       
  1240  
       
  1241 // CTestStep derived functions
       
  1242 	
       
  1243 CT_NonNativeAppsStep::~CT_NonNativeAppsStep()
       
  1244 	{
       
  1245 	}
       
  1246 
       
  1247 CT_NonNativeAppsStep::CT_NonNativeAppsStep()
       
  1248 	{
       
  1249 	SetTestStepName(KT_NonNativeAppsStep);
       
  1250 	}
       
  1251 
       
  1252 TVerdict CT_NonNativeAppsStep::doTestStepPreambleL()
       
  1253 	{
       
  1254 	SetTestStepResult(EPass);
       
  1255 	return TestStepResult();
       
  1256 	}
       
  1257 
       
  1258 TVerdict CT_NonNativeAppsStep::doTestStepPostambleL()
       
  1259 	{
       
  1260 	return TestStepResult();
       
  1261 	}
       
  1262 
       
  1263 TVerdict CT_NonNativeAppsStep::doTestStepL()
       
  1264 	{
       
  1265 	INFO_PRINTF1(_L("Test NonNativeApps starting....\n"));
       
  1266 
       
  1267 	RTstFileArray fileArray(2);
       
  1268 	CleanupClosePushL(fileArray);
       
  1269 	fileArray.AppendL(_L("z:\\private\\101F289C\\GIF.NNA1"), KLit8_DataType_Gif);
       
  1270 	fileArray.AppendL(_L("z:\\private\\101F289C\\HTML.NNA2"), KLit8_DataType_Html);
       
  1271 	fileArray.AppendL(_L("z:\\private\\101F289C\\CONTACT.NNA3"), KLit8_DataType_Vcard);
       
  1272 	fileArray.AppendL(_L("z:\\private\\101F289C\\TXT.NNA4"), KLit8_DataType_plainText);
       
  1273 
       
  1274 	RTestableApaLsSession apparcServer;
       
  1275 	CleanupClosePushL(apparcServer);
       
  1276 	User::LeaveIfError(apparcServer.Connect());
       
  1277 
       
  1278 	RFs fileServer;
       
  1279 	CleanupClosePushL(fileServer);
       
  1280 	User::LeaveIfError(fileServer.Connect());
       
  1281 	User::LeaveIfError(fileServer.ShareProtected());
       
  1282 
       
  1283 	apparcServer.FlushRecognitionCache();
       
  1284 	HEAP_TEST_LS_SESSION(apparcServer, 0, 0, TestAppForDocumentL(apparcServer, fileServer, fileArray), apparcServer.FlushRecognitionCache());
       
  1285 	HEAP_TEST_LS_SESSION(apparcServer, 0, 0, TestAppForDocumentAndServiceL(apparcServer, fileServer, fileArray), apparcServer.FlushRecognitionCache());
       
  1286 	HEAP_TEST_LS_SESSION(apparcServer, 0, 0, TestRecognizingL(apparcServer, fileServer, fileArray), apparcServer.FlushRecognitionCache());
       
  1287 	
       
  1288 	//avoid race conditions
       
  1289 	User::After(1500000);
       
  1290 	//DONT_CHECK Skips the heap check at server side. This heap imbalance happens intermittently,with no known reason (See PDEF111975).
       
  1291 	HEAP_TEST_LS_SESSION(apparcServer, 0, DONT_CHECK, TestStartDocumentL(apparcServer, fileServer, fileArray), apparcServer.FlushRecognitionCache());
       
  1292 	//DONT_CHECK due to file system changes
       
  1293 	HEAP_TEST_LS_SESSION(apparcServer, 0, DONT_CHECK, TestRegisterNonNativeApplicationL(apparcServer,fileServer), NO_CLEANUP);
       
  1294 
       
  1295 	//INC127734: Test case is added to test ForceCommitNonNativeApplicationsUpdatesL API
       
  1296 	//DONT_CHECK due to file system changes
       
  1297 	HEAP_TEST_LS_SESSION(apparcServer, 0, DONT_CHECK, TestCommitNNAppUpdatesL(apparcServer), NO_CLEANUP);
       
  1298 	//DONT_CHECK due to file system changes
       
  1299 	HEAP_TEST_LS_SESSION(apparcServer, 0, DONT_CHECK, TestForceCommitNNAppUpdatesL(apparcServer), NO_CLEANUP);
       
  1300 	
       
  1301 	CleanupStack::PopAndDestroy(3, &fileArray);
       
  1302 
       
  1303 	INFO_PRINTF1(_L("....Test NonNativeApps completed!"));
       
  1304 	return TestStepResult();
       
  1305 	}