appfw/apparchitecture/tef/T_RecUpgrade.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 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 // This test case is used to verify that a recognizer plugin can be upgraded and  used 
       
    15 // without reboot.
       
    16 //
       
    17 // t_recupgrade.cpp
       
    18 //
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @file t_recupgrade.cpp
       
    24  @internalComponent - Internal Symbian test code
       
    25 */
       
    26 
       
    27 #include "testableapalssession.h"
       
    28 #include "T_RecUpgrade.h"
       
    29 #include "TRecUpgrade/upgconstants.h"
       
    30 
       
    31 //
       
    32 
       
    33 // Should be enough for CApaEComMonitor to detect new plugin
       
    34 const TInt KOneSecondDelay = 1000000;
       
    35 
       
    36 //
       
    37 
       
    38 CT_RecUpgradeStep::CT_RecUpgradeStep()
       
    39 	{
       
    40 	// Call base class method to set up the human readable name for logging
       
    41 	SetTestStepName(KT_RecUpgradeStep);
       
    42 	}
       
    43 
       
    44 CT_RecUpgradeStep::~CT_RecUpgradeStep()
       
    45 	{
       
    46 	}
       
    47 
       
    48 
       
    49 TInt CT_RecUpgradeStep::DeleteFileL(const TDesC &aFileName, RSmlTestUtils &fs)
       
    50 	{
       
    51 	TInt fileExists = EFalse;
       
    52 	TInt err;
       
    53 	fs.IsFilePresent(aFileName, fileExists);
       
    54 	if (fileExists)
       
    55 		{
       
    56 		fs.ChangeFilePermissionL(aFileName); // clear readonly attribute inherited from z:
       
    57 		err = fs.DeleteFileL(aFileName);
       
    58 		return(err);
       
    59 		}
       
    60 	return(KErrNotFound);
       
    61 	}
       
    62 
       
    63 /**
       
    64 Check that the test plugin file has not been left in the filesystem from a previous run.
       
    65 */
       
    66 TVerdict CT_RecUpgradeStep::doTestStepPreambleL()
       
    67 	{
       
    68 	RSmlTestUtils fs;
       
    69 	CleanupClosePushL(fs);
       
    70 	User::LeaveIfError(fs.Connect());
       
    71 	
       
    72 	INFO_PRINTF1(_L("Verifies that recupgrade.rsc was not present during boot."));
       
    73 	TBool fileExists = ETrue;
       
    74 	TInt err = fs.IsFilePresent(KUpgRscTargetPath, fileExists);
       
    75 	TESTE(fileExists==EFalse, err);
       
    76 	
       
    77 	CleanupStack::PopAndDestroy(&fs);
       
    78 	return TestStepResult();
       
    79 	}
       
    80 
       
    81 /*
       
    82 Delete the plugin file which was installed during the test from c:.
       
    83 */
       
    84 TVerdict CT_RecUpgradeStep::doTestStepPostambleL()
       
    85 	{
       
    86 	RSmlTestUtils fs;
       
    87 	CleanupClosePushL(fs);
       
    88 	User::LeaveIfError(fs.Connect());
       
    89 
       
    90 	TInt err = CT_RecUpgradeStep::DeleteFileL(KUpgRscTargetPath,fs);
       
    91 	if(err == KErrNone || err == KErrNotFound) 
       
    92 		INFO_PRINTF1(_L("Removed temporary file recupgrade.rsc or not found"));
       
    93 	else 
       
    94 		INFO_PRINTF1(_L("Failed to remove temporary file recupgrade.rsc"));	
       
    95 	
       
    96 	err = CT_RecUpgradeStep::DeleteFileL(KUpgDllTargetPath,fs);
       
    97 	if(err == KErrNone || err == KErrNotFound) 
       
    98 		INFO_PRINTF1(_L("Removed temporary file recupgrade.dll or not found"));
       
    99 	else 
       
   100 		INFO_PRINTF1(_L("Failed to remove temporary file recupgrade.dll"));	
       
   101 
       
   102 	CleanupStack::PopAndDestroy(&fs);
       
   103 	return TestStepResult();
       
   104 	}
       
   105 	
       
   106 /*
       
   107 The test entry point
       
   108 */			
       
   109 TVerdict CT_RecUpgradeStep::doTestStepL()
       
   110 	{
       
   111 	RTestableApaLsSession apparcServer;
       
   112 	CleanupClosePushL(apparcServer);
       
   113 	User::LeaveIfError(apparcServer.Connect());
       
   114 	HEAP_TEST_LS_SESSION(apparcServer, 0, 0, TestUpgradeRecognizerL(apparcServer), apparcServer.FlushRecognitionCache());
       
   115 	HEAP_TEST_LS_SESSION(apparcServer, 0, 0, TestUpgradeRecognizer2L(apparcServer), apparcServer.FlushRecognitionCache());	
       
   116 
       
   117 	CleanupStack::PopAndDestroy(&apparcServer);
       
   118 	
       
   119 	return TestStepResult();
       
   120 	}
       
   121 
       
   122 /**
       
   123 @SYMTestCaseID APPFWK-APPARC-0100
       
   124 
       
   125 @SYMDEF INC127312
       
   126 
       
   127 @SYMTestCaseDesc This test verify that apparc can dynamically upgrade and use an Ecom recognizer plugin.
       
   128 
       
   129 @SYMTestPriority High
       
   130 
       
   131 @SYMTestStatus Implemented
       
   132 
       
   133 @SYMTestActions:
       
   134 	
       
   135 	1. Try to recognize .upg file with version 1 of recupgrade ECOM plugin but if shuld not be able to recognize as it is implemented like that
       
   136 	2. Install version 2 of recupgrade plugin (copy recupgrade_armv5_rel.dll and recupgrade.rsc from z:\system\data to c:\sys\bin and c:\resource\plugin respectively)
       
   137 	3. Because of installation Apparc will be notified and it will reload all recognizers plugin
       
   138 	4. Now try to recognize .upg file . it shuld be able to recognize as vertion 2 is implemented like that
       
   139 
       
   140 @SYMTestExpectedResults Test should complete without any leave, panic or error.
       
   141  */
       
   142 void CT_RecUpgradeStep::TestUpgradeRecognizerL(RApaLsSession& aApparcServer)
       
   143 	{
       
   144 	
       
   145 	TDataRecognitionResult recogResult;
       
   146 	TBuf8<255> buffer;
       
   147 	buffer.FillZ(255);
       
   148 	recogResult.Reset();
       
   149 		
       
   150 	// Since recognizer for "mime\upg" mime type is installed but it will return CApaDataRecognizerType::ENotRecognized as implemented : call to RecognizeData()
       
   151 	// returns CApaDataRecognizerType::ENotRecognized.
       
   152 	INFO_PRINTF1(_L("MIME type recognition cache is not used..."));
       
   153 	TEST(aApparcServer.RecognizeData(KUpgDocPath, buffer, recogResult)==KErrNone);
       
   154 
       
   155 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ENotRecognized);
       
   156 
       
   157 	INFO_PRINTF1(_L("Installs upgrade of  mime/upg recognizer plugin file "));
       
   158 	RSmlTestUtils fs;
       
   159 	CleanupClosePushL(fs);
       
   160 	User::LeaveIfError(fs.Connect());
       
   161 	
       
   162 	// Ensure c:\\resource\\plugins is created, otherwise leave from this teststep
       
   163 	TInt err = fs.CreateDirectoryL(KUpgRscTargetDir);
       
   164 	TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
       
   165 	INFO_PRINTF1(_L("c:\\resource\\plugins is created successfully or already exists"));
       
   166 	
       
   167 	// Ensure c:\\sys\\bin is created, otherwise leave from this teststep
       
   168 	err = fs.CreateDirectoryL(KUpgDllTargetDir);
       
   169 	TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
       
   170 	INFO_PRINTF1(_L("c:\\sys\\bin is created successfully or already exists"));
       
   171 
       
   172 	// Copy recupgrade.rsc from z:\\ to c:\\resource\\plugins, to trigger the rescan for plugins.
       
   173 	err = fs.CopyFileL(KUpgRscSourcePath, KUpgRscTargetPath);
       
   174 	TEST(err == KErrNone);
       
   175 	INFO_PRINTF1(_L("Successfully copied recupgrade.rsc from Z:\\system\\data to c\\resource\\plugins"));
       
   176 
       
   177 	// Copy recupgrade_*.dll from z:\\ to c:\\sys\\bin.
       
   178 	err = fs.CopyFileL(KUpgDllSourcePathArmv5, KUpgDllTargetPath);
       
   179 	
       
   180 	TEST(err == KErrNone);
       
   181 	INFO_PRINTF1(_L("Successfully copied recupgrade_*.dll from Z:\\system\\data to c:\\sys\\bin"));
       
   182 
       
   183 	INFO_PRINTF2(_L("Waits %d seconds for new mime/upg recognizer with ECertain confidence to be installed."), (5 * KOneSecondDelay)/1000000);	
       
   184 	User::After(5 * KOneSecondDelay);
       
   185 	
       
   186 	// Test whether newly installed (or copied) plugin to c: drive is loaded by framework and recognizes file with .upg extension.  
       
   187 	INFO_PRINTF1(_L("MIME type recognition cache is flushed when a new recogizer is installed"));
       
   188 	recogResult.Reset();
       
   189 	TEST(aApparcServer.RecognizeData(KUpgDocPath, buffer, recogResult)==KErrNone);
       
   190 	TEST(recogResult.iDataType.Des8().CompareF(KMimeUpgType) == 0);
       
   191 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ECertain);		
       
   192 	
       
   193 	// Delete the plugin resource file of the recognizer with ECertain confidence which was installed during the test from z:.
       
   194 	err=CT_RecUpgradeStep::DeleteFileL(KUpgRscTargetPath,fs);
       
   195 	if(err == KErrNone) 
       
   196 		INFO_PRINTF1(_L("Removed file recupgrade.rsc"));
       
   197 	else 
       
   198 		INFO_PRINTF1(_L("Failed to remove recupgrade.rsc"));	
       
   199 
       
   200 	err=CT_RecUpgradeStep::DeleteFileL(KUpgDllTargetPath,fs);
       
   201 	if(err == KErrNone) 
       
   202 		INFO_PRINTF1(_L("Removed file recupgrade.dll"));
       
   203 	else 
       
   204 		INFO_PRINTF1(_L("Failed to remove recupgrade.dll"));
       
   205 
       
   206 
       
   207 	INFO_PRINTF2(_L("Waits %d seconds for the data recognizer list maintained by EMIME to be updated"), (10 * KOneSecondDelay)/1000000);	
       
   208  	User::After(10 * KOneSecondDelay);
       
   209 	
       
   210 	// Since "mime/upg" recognizer version 2 is uninstalled, mime/upg mime type is not recognized. 
       
   211 	INFO_PRINTF1(_L("MIME type recognition cache is flushed when a existing recogizer is uninstalled"));
       
   212 	recogResult.Reset();
       
   213 	TEST(aApparcServer.RecognizeData(KUpgDocPath, buffer, recogResult)==KErrNone);
       
   214 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ENotRecognized);
       
   215 	
       
   216 	CleanupStack::PopAndDestroy(&fs);
       
   217 	}
       
   218 
       
   219 
       
   220 /**
       
   221 @SYMTestCaseID APPFWK-APPARC-0101
       
   222 
       
   223 @SYMDEF INC127312
       
   224 
       
   225 @SYMTestCaseDesc This test verify that apparc can dynamically upgrade a plugin if the new plugin replaces existing plugin (i.e new plugin is installed to same drive where the old plugin resides).
       
   226 
       
   227 @SYMTestPriority High
       
   228 
       
   229 @SYMTestStatus Implemented
       
   230 
       
   231 @SYMTestActions:
       
   232 	
       
   233 	1. Try to recognize .upg file with version 1 of recupgrade ECOM plugin but if shuld not be able to recognize as it is implemented like that
       
   234 	2. Install version 2 of recupgrade plugin (copy recupgrade_armv5_rel.dll and recupgrade.rsc from z:\system\data to c:\sys\bin and c:\resource\plugin respectively)
       
   235 	3. Because of installation Apparc will be notified and it will reload all recognizers plugin
       
   236 	4. Now try to recognize .upg file . it shuld be able to recognize as vertion 2 is implemented like that
       
   237 	5. Delete the version 2 plugin files and copy version 3 plugin files to c: drive (copy recupgrade2_armv5_rel.dll and recupgrade2.rsc from z:\system\data to c:\sys\bin and c:\resource\plugin respectively)
       
   238 	6. Now try to recognize .upr file . it shuld be able to recognize as vertion 3 is implemented like that
       
   239 
       
   240 @SYMTestExpectedResults Test should complete without any leave, panic or error.
       
   241  */
       
   242 
       
   243 
       
   244 void CT_RecUpgradeStep::TestUpgradeRecognizer2L(RApaLsSession& aApparcServer)
       
   245 	{
       
   246 
       
   247 	TDataRecognitionResult recogResult;
       
   248 	TBuf8<255> buffer;
       
   249 	buffer.FillZ(255);
       
   250 	recogResult.Reset();
       
   251 		
       
   252 	// Since recognizer for "mime\upg" mime type is installed but it will return CApaDataRecognizerType::ENotRecognized as implemented : call to RecognizeData()
       
   253 	// returns CApaDataRecognizerType::ENotRecognized.
       
   254 	INFO_PRINTF1(_L("MIME type recognition cache is not used..."));
       
   255 	TEST(aApparcServer.RecognizeData(KUpgDocPath, buffer, recogResult)==KErrNone);
       
   256 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ENotRecognized);
       
   257 
       
   258 	//Check the loaded plugin recognizes "mime/upr" data. Version 1 of the plugin should not recognize this data.
       
   259 	TEST(aApparcServer.RecognizeData(KUprDocPath, buffer, recogResult)==KErrNone);
       
   260 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ENotRecognized);
       
   261 
       
   262 	INFO_PRINTF1(_L("Installs upgrade of  mime/upg recognizer plugin file "));
       
   263 	RSmlTestUtils fs;
       
   264 	CleanupClosePushL(fs);
       
   265 	User::LeaveIfError(fs.Connect());
       
   266 	
       
   267 	// Ensure c:\\resource\\plugins is created, otherwise leave from this teststep
       
   268 	TInt err = fs.CreateDirectoryL(KUpgRscTargetDir);
       
   269 	TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
       
   270 	INFO_PRINTF1(_L("c:\\resource\\plugins is created successfully or already exists"));
       
   271 	
       
   272 	// Ensure c:\\sys\\bin is created, otherwise leave from this teststep
       
   273 	err = fs.CreateDirectoryL(KUpgDllTargetDir);
       
   274 	TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
       
   275 	INFO_PRINTF1(_L("c:\\sys\\bin is created successfully or already exists"));
       
   276 
       
   277 	// Copy recupgrade.rsc from z:\\ to c:\\resource\\plugins, to trigger the rescan for plugins.
       
   278 	err = fs.CopyFileL(KUpgRscSourcePath, KUpgRscTargetPath);
       
   279 	TEST(err == KErrNone);
       
   280 	INFO_PRINTF1(_L("Successfully copied recupgrade.rsc from Z:\\system\\data to c\\resource\\plugins"));
       
   281 
       
   282 	// Copy recupgrade_*.dll from z:\\ to c:\\sys\\bin.
       
   283 	err = fs.CopyFileL(KUpgDllSourcePathArmv5, KUpgDllTargetPath);
       
   284 	
       
   285 	TEST(err == KErrNone);
       
   286 	INFO_PRINTF1(_L("Successfully copied recupgrade_*.dll from Z:\\system\\data to c:\\sys\\bin"));
       
   287 
       
   288 	INFO_PRINTF2(_L("Waits %d seconds for new mime/upg recognizer with ECertain confidence to be installed."), (5 * KOneSecondDelay)/1000000);	
       
   289 	User::After(5 * KOneSecondDelay);
       
   290 	
       
   291 	// Test whether newly installed (or copied) plugin to c: drive is loaded by framework and recognizes file with .upg extension.	INFO_PRINTF1(_L("MIME type recognition cache is flushed when a new recogizer is installed"));
       
   292 	recogResult.Reset();
       
   293 	TEST(aApparcServer.RecognizeData(KUpgDocPath, buffer, recogResult)==KErrNone);
       
   294 	TEST(recogResult.iDataType.Des8().CompareF(KMimeUpgType) == 0);
       
   295 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ECertain);
       
   296 	
       
   297 	// Test whether newly installed (or copied) plugin does not recognize a file with .upr extension.
       
   298 	recogResult.Reset();
       
   299 	TEST(aApparcServer.RecognizeData(KUprDocPath, buffer, recogResult)==KErrNone);
       
   300 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ENotRecognized);
       
   301 	
       
   302 	// Delete the plugin resource file of the recognizer with ECertain confidence which was installed during the test from z:.
       
   303 	err=CT_RecUpgradeStep::DeleteFileL(KUpgRscTargetPath,fs);
       
   304 	if(err == KErrNone) 
       
   305 		INFO_PRINTF1(_L("Removed file recupgrade.rsc"));
       
   306 	else 
       
   307 		INFO_PRINTF1(_L("Failed to remove recupgrade.rsc"));	
       
   308 
       
   309 	err=CT_RecUpgradeStep::DeleteFileL(KUpgDllTargetPath,fs);
       
   310 	if(err == KErrNone) 
       
   311 		INFO_PRINTF1(_L("Removed file recupgrade.dll"));
       
   312 	else 
       
   313 		INFO_PRINTF1(_L("Failed to remove recupgrade.dll"));
       
   314 
       
   315 	User::After(1 * KOneSecondDelay);	
       
   316 
       
   317 	// Copy recupgrade2.rsc from z:\\ to c:\\resource\\plugins, to trigger the rescan for plugins.
       
   318 	err = fs.CopyFileL(KUprRscSourcePath, KUpgRscTargetPath);
       
   319 	TEST(err == KErrNone);
       
   320 	INFO_PRINTF1(_L("Successfully copied recupgrade2.rsc from Z:\\system\\data to c:\\resource\\plugins"));
       
   321 
       
   322 	
       
   323 	// Copy recupgrade_*.dll from z:\\ to c:\\sys\\bin.
       
   324 	err = fs.CopyFileL(KUprDllSourcePathArmv5, KUpgDllTargetPath);
       
   325 	
       
   326 	TEST(err == KErrNone);
       
   327 	INFO_PRINTF1(_L("Successfully copied recupgrade2_*.dll from Z:\\system\\data to c:\\sys\\bin"));
       
   328 
       
   329 	
       
   330 	INFO_PRINTF2(_L("Waits %d seconds for new mime/upg recognizer with ECertain confidence to be installed."), (5 * KOneSecondDelay)/1000000);	
       
   331 	User::After(5 * KOneSecondDelay);
       
   332 	
       
   333 	// Test whether the plugin which replaces old plugin in c: drive is loaded by framework and recognizes file with .upr extension.
       
   334 	INFO_PRINTF1(_L("MIME type recognition cache is flushed when a new recogizer is installed"));
       
   335 	recogResult.Reset();
       
   336 	TEST(aApparcServer.RecognizeData(KUprDocPath, buffer, recogResult)==KErrNone);
       
   337 	TEST(recogResult.iDataType.Des8().CompareF(KMimeUprType) == 0);
       
   338 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ECertain);
       
   339 
       
   340 	// Test whether the plugin which replaces old plugin in c: drive does not recognize a file with .upg extension.
       
   341 	recogResult.Reset();
       
   342 	TEST(aApparcServer.RecognizeData(KUpgDocPath, buffer, recogResult)==KErrNone);
       
   343 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ENotRecognized);
       
   344 
       
   345 	
       
   346 	// Delete the plugin resource file of the recognizer with ECertain confidence which was installed during the test from z:.
       
   347 	err=CT_RecUpgradeStep::DeleteFileL(KUpgRscTargetPath,fs);
       
   348 	if(err == KErrNone) 
       
   349 		INFO_PRINTF1(_L("Removed file recupgrade.rsc"));
       
   350 	else 
       
   351 		INFO_PRINTF1(_L("Failed to remove recupgrade.rsc"));	
       
   352 
       
   353 	err=CT_RecUpgradeStep::DeleteFileL(KUpgDllTargetPath,fs);
       
   354 	if(err == KErrNone) 
       
   355 		INFO_PRINTF1(_L("Removed file recupgrade.dll"));
       
   356 	else 
       
   357 		INFO_PRINTF1(_L("Failed to remove recupgrade.dll"));
       
   358 
       
   359 	INFO_PRINTF2(_L("Waits %d seconds for the data recognizer list maintained by EMIME to be updated"), (10 * KOneSecondDelay)/1000000);	
       
   360  	User::After(10 * KOneSecondDelay);
       
   361 	
       
   362 	// Since "mime/upr" recognizer version 3 is uninstalled, mime/upr mime type is not recognized. 
       
   363 	INFO_PRINTF1(_L("MIME type recognition cache is flushed when a existing recogizer is uninstalled"));
       
   364 	recogResult.Reset();
       
   365 	TEST(aApparcServer.RecognizeData(KUprDocPath, buffer, recogResult)==KErrNone);
       
   366 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ENotRecognized);
       
   367 
       
   368 	CleanupStack::PopAndDestroy(&fs);
       
   369 	}
       
   370