localisation/apparchitecture/tef/T_RecUpgrade.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2008-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 // This test case is used to verify that a recognizer plugin can be upgraded and  used 
       
    15 // without reboot.
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23  @internalComponent - Internal Symbian test code
       
    24 */
       
    25 
       
    26 #include "testableapalssession.h"
       
    27 #include "T_RecUpgrade.h"
       
    28 #include "appfwk_test_utils.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 Check that the test plugin file has not been left in the filesystem from a previous run.
       
    50 */
       
    51 TVerdict CT_RecUpgradeStep::doTestStepPreambleL()
       
    52 	{
       
    53 	RSmlTestUtils fs;
       
    54 	CleanupClosePushL(fs);
       
    55 	User::LeaveIfError(fs.Connect());
       
    56 	
       
    57 	INFO_PRINTF1(_L("Verifies that recupgrade.rsc was not present during boot."));
       
    58 	TBool fileExists = ETrue;
       
    59 	TInt err = fs.IsFilePresent(KUpgRscTargetPath, fileExists);
       
    60 	TESTE(fileExists==EFalse, err);
       
    61 	
       
    62 	CleanupStack::PopAndDestroy(&fs);
       
    63 	return TestStepResult();
       
    64 	}
       
    65 
       
    66 /*
       
    67 Delete the plugin file which was installed during the test from c:.
       
    68 */
       
    69 TVerdict CT_RecUpgradeStep::doTestStepPostambleL()
       
    70 	{
       
    71 	RSmlTestUtils fs;
       
    72 	CleanupClosePushL(fs);
       
    73 	User::LeaveIfError(fs.Connect());
       
    74 
       
    75 	TBool fileExists = EFalse;
       
    76 	fs.IsFilePresent(KUpgRscTargetPath, fileExists);
       
    77 	if(fileExists)
       
    78 		{
       
    79 		fs.ChangeFilePermissionL(KUpgRscTargetPath); // clear readonly attribute inherited from z:
       
    80 		const TInt err = fs.DeleteFileL(KUpgRscTargetPath);
       
    81 		if(err == KErrNone) 
       
    82 			INFO_PRINTF1(_L("Removed temporary file recupgrade.rsc"));
       
    83 		else 
       
    84 			INFO_PRINTF1(_L("Failed to remove temporary file recupgrade.rsc"));	
       
    85 		}
       
    86 		
       
    87 	CleanupStack::PopAndDestroy(&fs);
       
    88 	return TestStepResult();
       
    89 	}
       
    90 	
       
    91 /*
       
    92 The test entry point
       
    93 */			
       
    94 TVerdict CT_RecUpgradeStep::doTestStepL()
       
    95 	{
       
    96 	RTestableApaLsSession apparcServer;
       
    97 	CleanupClosePushL(apparcServer);
       
    98 	User::LeaveIfError(apparcServer.Connect());
       
    99 	//DONT_CHECK skips the heap check at server side. This heap imbalance happens due to copying recupgrade.dll to c:\sys\bin
       
   100 	//and failed to delete it in cleanup (Windows OS don’t allow to delete any file which are in use).
       
   101  	HEAP_TEST_LS_SESSION(apparcServer, 0, DONT_CHECK, TestUpgradeRecognizerL(apparcServer), NO_CLEANUP);
       
   102 
       
   103 	CleanupStack::PopAndDestroy(&apparcServer);
       
   104 	
       
   105 	return TestStepResult();
       
   106 	}
       
   107 
       
   108 /**
       
   109 @SYMTestCaseID APPFWK-APPARC-0100
       
   110 
       
   111 @SYMDEF INC127312
       
   112 
       
   113 @SYMTestCaseDesc This test verify that apparc can dynamically upgrade and use an Ecom recognizer plugin.
       
   114 
       
   115 @SYMTestPriority High
       
   116 
       
   117 @SYMTestStatus Implemented
       
   118 
       
   119 @SYMTestActions:
       
   120 	
       
   121 	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
       
   122 	2. Install version 2 of recupgrade plugin (copy recupgrade_winscw/armv5_rec.dll and recupgrade_1.rsc from z:\system\data to c:\sys\bin and c:\resource\plugin respectively)
       
   123 
       
   124 	3. Because of installation Apparc will be notified and it will reload all recognizers plugin
       
   125 	4. Now try to recognize .upg file . it shuld be able to recognize as vertion 2 is implemented like that
       
   126 
       
   127 @SYMTestExpectedResults Test should complete without any leave, panic or error.
       
   128  */
       
   129 void CT_RecUpgradeStep::TestUpgradeRecognizerL(RApaLsSession& aApparcServer)
       
   130 	{
       
   131 	
       
   132 	TDataRecognitionResult recogResult;
       
   133 	TBuf8<255> buffer;
       
   134 	buffer.FillZ(255);
       
   135 	recogResult.Reset();
       
   136 		
       
   137 	// Since recognizer for "mime\upg" mime type is installed but it will return CApaDataRecognizerType::ENotRecognized as implemented : call to RecognizeData()
       
   138 	// returns CApaDataRecognizerType::ENotRecognized.
       
   139 	INFO_PRINTF1(_L("MIME type recognition cache is not used..."));
       
   140 	TEST(aApparcServer.RecognizeData(KUpgDocPath, buffer, recogResult)==KErrNone);
       
   141 
       
   142 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ENotRecognized);
       
   143 
       
   144 	INFO_PRINTF1(_L("Installs upgrade of  mime/upg recognizer plugin file "));
       
   145 	RSmlTestUtils fs;
       
   146 	CleanupClosePushL(fs);
       
   147 	User::LeaveIfError(fs.Connect());
       
   148 	
       
   149 	// Ensure c:\\resource\\plugins is created, otherwise leave from this teststep
       
   150 	
       
   151 	TInt err = fs.CreateDirectoryL(KUpgRscTargetDir);
       
   152 	TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
       
   153 	INFO_PRINTF1(_L("c:\\resource\\plugins is created successfully or already exists"));
       
   154 	
       
   155 	// Ensure c:\\sys\\bin is created, otherwise leave from this teststep
       
   156 	
       
   157 	err = fs.CreateDirectoryL(KUpgDllTargetDir);
       
   158 	TESTEL((err == KErrNone || err == KErrAlreadyExists), err);
       
   159 	INFO_PRINTF1(_L("c:\\sys\\bin is created successfully or already exists"));
       
   160 
       
   161 	// Copy recupgrade.rsc from z:\\ to c:\\resource\\plugins, to trigger the rescan for plugins.
       
   162 	
       
   163 	err = fs.CopyFileL(KUpgRscSourcePath, KUpgRscTargetPath);
       
   164 	TEST(err == KErrNone);
       
   165 	INFO_PRINTF1(_L("Successfully copied recupgrade.rsc from Z:\\system\\data to c\\resource\\plugins"));
       
   166 	// Copy recupgrade_*.dll from z:\\ to c:\\sys\\bin.
       
   167 	#ifdef __WINS__ 
       
   168 		err = fs.CopyFileL(KUpgDllSourcePathWinscw, KUpgDllTargetPath);
       
   169 	#else
       
   170 		err = fs.CopyFileL(KUpgDllSourcePathArmv5, KUpgDllTargetPath);
       
   171 	#endif
       
   172 	TEST(err == KErrNone);
       
   173 	INFO_PRINTF1(_L("Successfully copied recupgrade_*.dll from Z:\\system\\data to c:\\sys\\bin"));
       
   174 
       
   175 	INFO_PRINTF2(_L("Waits %d seconds for new mime/upg recognizer with EPossible confidence to be installed."), (4 * KOneSecondDelay)/1000000);	
       
   176 	User::After(4 * KOneSecondDelay);
       
   177 	
       
   178 	// Without fix for INC127312: Apparc server will not reload all upgraded MIME type recognition hence new version of existing will not used for recognization 
       
   179 	INFO_PRINTF1(_L("MIME type recognition cache is flushed when a new recogizer is installed"));
       
   180 	recogResult.Reset();
       
   181 	TEST(aApparcServer.RecognizeData(KUpgDocPath, buffer, recogResult)==KErrNone);
       
   182 	TEST(recogResult.iDataType.Des8().CompareF(KMimeUpgType) == 0);
       
   183 	TEST(recogResult.iConfidence == CApaDataRecognizerType::EPossible);
       
   184 		
       
   185 	
       
   186 // Delete the plugin resource file of the recognizer with EPossible confidence which was installed during the test from z:.
       
   187 	
       
   188 	TInt fileExists = EFalse;
       
   189 	fs.IsFilePresent(KUpgRscTargetPath, fileExists);
       
   190 	if (fileExists)
       
   191 		{
       
   192 		fs.ChangeFilePermissionL(KUpgRscTargetPath); // clear readonly attribute inherited from z:
       
   193 		err = fs.DeleteFileL(KUpgRscTargetPath);
       
   194 		if(err == KErrNone) 
       
   195 			INFO_PRINTF1(_L("Removed file recupgrade.rsc"));
       
   196 		else 
       
   197 			INFO_PRINTF1(_L("Failed to remove recupgrade.rsc"));	
       
   198 		}
       
   199 
       
   200 	fileExists = EFalse;
       
   201 	fs.IsFilePresent(KUpgDllTargetPath, fileExists);
       
   202 	if (fileExists)
       
   203 		{
       
   204 		fs.ChangeFilePermissionL(KUpgDllTargetPath); // clear readonly attribute inherited from z:
       
   205 		err = fs.DeleteFileL(KUpgDllTargetPath);
       
   206 		if(err == KErrNone) 
       
   207 			INFO_PRINTF1(_L("Removed recupgrade.dll"));
       
   208 		else 
       
   209 			INFO_PRINTF1(_L("Failed to remove recupgrade.dll"));	
       
   210 		}
       
   211 
       
   212 	INFO_PRINTF2(_L("Waits %d seconds for the data recognizer list maintained by EMIME to be updated"), (10 * KOneSecondDelay)/1000000);	
       
   213  	User::After(10 * KOneSecondDelay);
       
   214 	
       
   215 	// Since "mime/upg" recognizer version 2 is uninstalled, mime/upg mime type is not recognized. 
       
   216 	INFO_PRINTF1(_L("MIME type recognition cache is flushed when a existing recogizer is uninstalled"));
       
   217 	recogResult.Reset();
       
   218 	TEST(aApparcServer.RecognizeData(KUpgDocPath, buffer, recogResult)==KErrNone);
       
   219 	TEST(recogResult.iConfidence == CApaDataRecognizerType::ENotRecognized);
       
   220 	
       
   221 	CleanupStack::PopAndDestroy(&fs);
       
   222 	
       
   223 	}