appfw/apparchitecture/tef/T_AppListFileUpdateStep.cpp
changeset 0 2e3d3ce01487
child 29 6a787171e1de
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 // Note: With PREQ1228, we introduced "REQ5896:Load application information from a single file".
       
    15 // This PREQ is tested with the following two test steps:
       
    16 // T_AppListBootStep (only run for emulator, as it requires epoc restart)
       
    17 // |___ (APPFWK-APPARC-0033) Tests that the application information file (AppsList.bin) is created 
       
    18 // |		if it does not exists, and we reboot the phone.
       
    19 // |___ (APPFWK-APPARC-0034) Tests that the Short Caption associated with an app
       
    20 // T_AppListUpdateStep
       
    21 // |___ (APPFWK-APPARC-0035) Tests that the application information file (AppsList.bin) is created 
       
    22 // |		if it does not exists, and we force a registration.
       
    23 // |___ (APPFWK-APPARC-0032) Tests that the application information file (AppsList.bin) is updated 
       
    24 // whenever a new application is installed.
       
    25 // 
       
    26 //
       
    27 
       
    28 /**
       
    29  @file
       
    30  @test
       
    31  @internalComponent - Internal Symbian test code
       
    32 */
       
    33 
       
    34 
       
    35 #include <apgcli.h>
       
    36 #include "T_AppListFileUpdateStep.h"
       
    37 
       
    38 _LIT(KTestAppZPath,"Z:\\ApparcTest\\TestAppInstall_reg.RSC");
       
    39 _LIT(KAppListFileName,"C:\\private\\10003a3f\\AppsListCache\\AppsList.bin");
       
    40 _LIT(KAppTimeFormat,"%:0%H%:1%T%:2%S%:3");
       
    41 _LIT(KAppDirectory,"C:\\Private\\10003a3f\\Import\\apps\\");
       
    42 _LIT(KTestAppObsolutePath1,"C:\\Private\\10003a3f\\Import\\apps\\TestAppInstall_reg.RSC");
       
    43 
       
    44 const TInt KMaxTimeCount = 18;			// 18 * 10 is 180 Seconds
       
    45 
       
    46 
       
    47 CT_AppListFileUpdateStep::CT_AppListFileUpdateStep()
       
    48 	{
       
    49 	// Call base class method to set up the human readable name for logging
       
    50 	SetTestStepName(KT_AppListFileUpdate);
       
    51 	}
       
    52 
       
    53 
       
    54 CT_AppListFileUpdateStep::~CT_AppListFileUpdateStep()
       
    55 	{
       
    56 	}
       
    57 
       
    58 TVerdict CT_AppListFileUpdateStep::doTestStepPreambleL()
       
    59 	{
       
    60  	User::LeaveIfError(iSession.Connect());
       
    61  	User::LeaveIfError(iUtils.Connect());
       
    62  	User::LeaveIfError(iFs.Connect());
       
    63 	
       
    64 	SetTestStepResult(EPass);
       
    65 	return TestStepResult();
       
    66 	}
       
    67 
       
    68 TVerdict CT_AppListFileUpdateStep::doTestStepPostambleL()
       
    69 	{
       
    70 	iFs.Close();
       
    71 	iUtils.Close();
       
    72 	iSession.Close();
       
    73 	return TestStepResult();
       
    74 	}
       
    75 
       
    76 
       
    77 TVerdict CT_AppListFileUpdateStep::doTestStepL()
       
    78 	{
       
    79 	INFO_PRINTF1(_L("AppListFileUpdateStep test step started..."));
       
    80 
       
    81  	__UHEAP_MARK;
       
    82 	INFO_PRINTF1(_L("APPFWK-APPARC-0035 Test Started"));
       
    83 	TRAPD(ret, TestDeleteAppListFileL());
       
    84 	TEST(ret == KErrNone);
       
    85  	INFO_PRINTF2(_L("TestDeleteAppListFileL() finished with return code '%d'\n"), ret);
       
    86 	INFO_PRINTF1(_L("APPFWK-APPARC-0035 Test Finished\n"));
       
    87   	__UHEAP_MARKEND;
       
    88 
       
    89  	__UHEAP_MARK;
       
    90 	INFO_PRINTF1(_L("APPFWK-APPARC-0032 Test Started"));
       
    91 	TRAP(ret, TestTimeStampL());
       
    92 	TEST(ret == KErrNone);
       
    93  	INFO_PRINTF2(_L("TestTimeStampL() finished with return code '%d'"), ret);
       
    94 	INFO_PRINTF1(_L("APPFWK-APPARC-0032 Test Finished\n"));
       
    95   	__UHEAP_MARKEND;
       
    96 
       
    97 	INFO_PRINTF1(_L("...AppListFileUpdateStep test step finished!"));
       
    98 	return TestStepResult();
       
    99 	}
       
   100 
       
   101 
       
   102 /**
       
   103    @SYMTestCaseID 	APPFWK-APPARC-0032
       
   104   
       
   105    @SYMPREQ 		PREQ1228 (CR0831)
       
   106    
       
   107    @SYMREQ			REQ5896
       
   108   
       
   109    @SYMTestCaseDesc Tests that the application information file (AppsList.bin) is updated 
       
   110 					whenever a new application is installed.
       
   111 
       
   112    @SYMTestType		CIT
       
   113    
       
   114    @SYMTestPriority High 
       
   115   
       
   116    @SYMTestStatus 	Implemented
       
   117    
       
   118    @SYMTestActions 	This tests the update of the applist file in \\private\\10003a3f\\import\\\apps\\.
       
   119    			The sequence is as follows:
       
   120    			1.- Check the file exists. It must exists.
       
   121    			2.- Record timestamp for applist file.
       
   122    			3.- Install a new test application.
       
   123    			4.- Record timestamp for applist file, allowing some time for the file to be updated
       
   124    			4.- Compare timestamps before and after test app installation.
       
   125 	   
       
   126    @SYMTestExpectedResults	Modified time of AppsList.bin after installation must be greater than before installation. 
       
   127  */
       
   128  
       
   129  void CT_AppListFileUpdateStep::TestTimeStampL()
       
   130  	{
       
   131 	// Create KAppDirectory
       
   132 	TInt err = iUtils.CreateDirectoryL(KAppDirectory);
       
   133 	TEST(err == KErrNone || err == KErrAlreadyExists);
       
   134 	
       
   135 	// Wait until KAppListFileName is present and check that the file has been created indeed
       
   136 	TBool present = CheckForFilePresent();
       
   137 	TEST(present);
       
   138 
       
   139 	// Record time before app list was modified	
       
   140 	INFO_PRINTF1(_L("Record time before app list was modified..."));
       
   141 	TTime timeBeforeAppListModification;
       
   142 	AppsListModifiedTimeL(timeBeforeAppListModification);
       
   143 		
       
   144 	// Install an application
       
   145 	INFO_PRINTF1(_L("Install application..."));
       
   146 	InstallApplicationL(KTestAppObsolutePath1);
       
   147 
       
   148 	// wait 5 seconds for the app to be properly installed
       
   149 	User::After(5 * 1000000);
       
   150 	
       
   151 	// Wait until KAppListFileName is present and check that the file has been created indeed.
       
   152 	present = CheckForFilePresent();
       
   153 	TEST(present);
       
   154 
       
   155 	// Record time after app list was modified	
       
   156 	INFO_PRINTF1(_L("Record time after app list was modified..."));
       
   157 	TTime timeAfterAppListModification;
       
   158 	AppsListModifiedTimeL(timeAfterAppListModification);
       
   159     
       
   160     // Check that the modification time "after" is after the modification time "before"
       
   161     TEST(timeAfterAppListModification > timeBeforeAppListModification);
       
   162 
       
   163 	// Uninstall & delete...
       
   164 	INFO_PRINTF1(_L("Uninstalling application..."));
       
   165 	DeleteApplicationL(KTestAppObsolutePath1);
       
   166  	}
       
   167  
       
   168  
       
   169 /*
       
   170 Delete a registration resource file (TestAppInstall.rsc) in the path  "C:\private\10003a3f\import\apps" .
       
   171 */
       
   172 void CT_AppListFileUpdateStep::DeleteApplicationL(const TDesC& aAppName)
       
   173 	{
       
   174 	INFO_PRINTF2(_L("Deleting file '%S'"), &aAppName);
       
   175 
       
   176 	TInt ret = iUtils.SetReadOnly(aAppName, 0);
       
   177 	TEST(ret == KErrNone);
       
   178 	ret = iUtils.DeleteFileL(aAppName);
       
   179 	TEST(ret == KErrNone);
       
   180 	}
       
   181 
       
   182 
       
   183 /*
       
   184 Copy a registration resource file (TestAppInstall.rsc) in the path  "c:\private\10003a3f\import\apps" .
       
   185 */
       
   186 void CT_AppListFileUpdateStep::InstallApplicationL(const TDesC& aAppName)
       
   187 	{
       
   188 	INFO_PRINTF3(_L("Copying file '%S' to folder '%S'"), &aAppName, &KTestAppZPath);
       
   189 
       
   190 	TInt ret = iUtils.CopyFileL(KTestAppZPath, aAppName);
       
   191 	TEST(ret == KErrNone);
       
   192 	}
       
   193 
       
   194 
       
   195 /*
       
   196 Gets the modified time for AppsList.bin
       
   197 */
       
   198 void CT_AppListFileUpdateStep::AppsListModifiedTimeL(TTime& aTime)
       
   199 	{
       
   200 	INFO_PRINTF2(_L("Retrieving modification time of file '%S'"), &KAppListFileName);
       
   201 	TInt ret = iFs.Modified(KAppListFileName, aTime);
       
   202 	TEST(ret == KErrNone);
       
   203 	
       
   204 	TBuf<40> timeString; // Holds the formatted date and time
       
   205     aTime.FormatL(timeString,KAppTimeFormat);
       
   206 	INFO_PRINTF2(_L("Recorded modified time is '%S'"), &timeString);
       
   207 	}
       
   208 
       
   209 
       
   210 /**
       
   211    @SYMTestCaseID 	APPFWK-APPARC-0035
       
   212   
       
   213    @SYMPREQ 		PREQ1228 (CR0831)
       
   214    
       
   215    @SYMREQ			REQ5896
       
   216   
       
   217    @SYMTestCaseDesc Apparc component repopulates the file list if it has been deleted and a registration is forced.
       
   218 
       
   219    @SYMTestType		CIT
       
   220    
       
   221    @SYMTestPriority High 
       
   222   
       
   223    @SYMTestStatus 	Implemented
       
   224    
       
   225    @SYMTestActions 	This tests the update of the applist file in \\private\\10003a3f\\import\\\apps\\.
       
   226    			The sequence is as follows:
       
   227    			1.- Check the file exists. It must exists.
       
   228    			2.- Delete the file and check it does not exist, and that is not created either.
       
   229    			3.- Force Registration, which means that the applist file needs to be created again.
       
   230    			4.- Check that the above mentioned file exists again after waiting for a short period of time.
       
   231 	   
       
   232    @SYMTestExpectedResults	AppsList.bin is deleted and created according to the test actions.
       
   233  */
       
   234  
       
   235  void CT_AppListFileUpdateStep::TestDeleteAppListFileL()
       
   236  	{
       
   237 	// Check the file IS present
       
   238 	TBool present = CheckForFilePresent();			
       
   239 	TEST(present);
       
   240 
       
   241 	// Delete applist file
       
   242 	DeleteAppListFileL(KAppListFileName);
       
   243 
       
   244 	// Check the file is NOT present
       
   245 	present = CheckForFilePresent();			
       
   246 	TEST(!present);
       
   247 	
       
   248 	// Do a rescan and check that the file exists again.
       
   249 	INFO_PRINTF1(_L("Do a rescan and check that the file exists again...."));
       
   250 	RPointerArray<TDesC> dummy;
       
   251 	TEST(iSession.ForceRegistration(dummy) == KErrNone);
       
   252 	present = CheckForFilePresent();			
       
   253 	TEST(present);
       
   254  	}
       
   255 
       
   256 
       
   257 /*
       
   258 Checks whether the "AppList.Bin" exists, if not waits for a maximum time of (KMaxTimeCount * 10) seconds for the file to create. 
       
   259 Else the test fails.
       
   260 */
       
   261 TBool CT_AppListFileUpdateStep::CheckForFilePresent()
       
   262 	{
       
   263 	INFO_PRINTF2(_L("Wait for a maximum time of '%d' secs for the file to be created"), KMaxTimeCount * 10);
       
   264 
       
   265 	TBool present = EFalse;
       
   266 	for (TInt index = 0; present == EFalse && index < KMaxTimeCount; index++)
       
   267 		{
       
   268 		TEST(iUtils.IsFilePresent(KAppListFileName, present) == KErrNone);
       
   269 		if (present)
       
   270 			{
       
   271 			INFO_PRINTF2(_L("AppList file is successfully created after '%d' seconds!"), index * 10);
       
   272 			break;
       
   273 			}
       
   274 		// wait 10 secs before trying again in the next loop
       
   275 		User::After(10 * 1000000);	
       
   276 		}
       
   277 
       
   278 	if (!present)
       
   279 		{
       
   280 		INFO_PRINTF2(_L("AppList file was NOT created after '%d' seconds"), KMaxTimeCount * 10);
       
   281 		}
       
   282 
       
   283 	return present;
       
   284 	}
       
   285 
       
   286 
       
   287 /*
       
   288 It will delete the applistfile created by apparc component
       
   289 */
       
   290 void CT_AppListFileUpdateStep::DeleteAppListFileL(const TDesC& aFileName)
       
   291 	{
       
   292 	INFO_PRINTF2(_L("Delete AppList file '%S'..."), &aFileName);
       
   293 
       
   294 	TInt ret = iUtils.SetReadOnly(aFileName, 0);
       
   295 	TEST(ret == KErrNone);
       
   296 	ret = iUtils.DeleteFileL(aFileName);
       
   297 	TEST(ret == KErrNone);
       
   298 	}