authenticationservices/authenticationserver/test/tAuthSvr/src/step_postmarketplugin.cpp
changeset 29 ece3df019add
equal deleted inserted replaced
19:cd501b96611d 29:ece3df019add
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * CTestStep derived implementation
       
    16 *
       
    17 */
       
    18 
       
    19  
       
    20 #include "tAuthSvrStep.h"
       
    21 #include <f32file.h>
       
    22 #include <ecom/ecom.h>
       
    23 #include <e32test.h>
       
    24 
       
    25 #include "authserver/authclient.h"
       
    26 #include "authserver/authmgrclient.h"
       
    27 
       
    28 using namespace AuthServer;
       
    29 
       
    30 const TInt KWaitDuration = 30000000; 
       
    31 #define WAIT_FOR3s User::After(KWaitDuration)
       
    32  
       
    33 
       
    34 _LIT(KSysBinDir, "c:\\sys\\bin\\");
       
    35 _LIT(KRscDir, "c:\\resource\\plugins\\");
       
    36 
       
    37 CTPostMarketPlugin::CTPostMarketPlugin()
       
    38 	{
       
    39 	SetTestStepName(KTPostMarketPlugin);
       
    40 	}
       
    41 
       
    42 TVerdict CTPostMarketPlugin::doTestStepPreambleL()
       
    43 /**
       
    44  * @return - TVerdict code
       
    45  * Override of base class virtual
       
    46  */
       
    47 	{
       
    48 	SetTestStepResult(EFail);
       
    49 	
       
    50 	CTAuthSvrStepBase::doTestStepPreambleL();
       
    51 	
       
    52 	if (!GetStringFromConfig(ConfigSection(), _L("srcPlugin"), iSrcPlugin))
       
    53 		{
       
    54 		INFO_PRINTF1(_L("Source plugin not specified in the ini file"));
       
    55 		return TestStepResult();
       
    56 		}
       
    57 		
       
    58 	if (!GetStringFromConfig(ConfigSection(), _L("destPlugin"), iTargetPlugin))
       
    59 		{
       
    60 		INFO_PRINTF1(_L("Target plugin not specified in the ini file"));
       
    61 		return TestStepResult();
       
    62 		}
       
    63 		
       
    64 	if (!GetStringFromConfig(ConfigSection(), _L("srcRscFile"), iSrcRscFile))
       
    65 		{
       
    66 		INFO_PRINTF1(_L("Source resource file not specified in the ini file"));
       
    67 		return TestStepResult();
       
    68 		}
       
    69 		
       
    70 	if (!GetStringFromConfig(ConfigSection(), _L("destRscFile"), iTargetRscFile))
       
    71 		{
       
    72 		INFO_PRINTF1(_L("Target resource file not specified in the ini file"));
       
    73 		return TestStepResult();
       
    74 		}
       
    75 		
       
    76 	SetTestStepResult(EPass);
       
    77 	return TestStepResult();
       
    78 	}
       
    79 	
       
    80 
       
    81 TBool CTPostMarketPlugin::VerifyObtainedResultsWithExpectedL(AuthServer::RAuthMgrClient& aAuthMgrClient, TInt aExpectedCount, const TDesC& aExpectedPluginName)
       
    82 	{
       
    83 	RPluginDescriptions pluginList;
       
    84 	TCleanupItem cleanup(CleanupEComArray, &pluginList);
       
    85 	CleanupStack::PushL(cleanup);
       
    86 	
       
    87 	//Get a list of all the available plugins.					
       
    88 	aAuthMgrClient.PluginsL(pluginList);	
       
    89 	TInt count = pluginList.Count();
       
    90 	TBool result = ETrue;
       
    91 	if(count != aExpectedCount)
       
    92 		{
       
    93 		INFO_PRINTF3(_L("Expected plugin count %d differs from actual %d..."), &count, &aExpectedCount);
       
    94 		result = EFalse;
       
    95 		}
       
    96 		
       
    97 	if(aExpectedPluginName.Length())
       
    98 		{
       
    99 		TBool found = EFalse;
       
   100 		const TDesC* pluginName = 0;
       
   101 		for(TInt i = 0; i < count; i++)
       
   102 			{
       
   103 			pluginName = pluginList[i]->Name();
       
   104 			if(pluginName->Compare(aExpectedPluginName) == 0)
       
   105 				{
       
   106 				found = ETrue;
       
   107 				break;
       
   108 				}
       
   109 			}
       
   110 		
       
   111 		if(!found)
       
   112 			{
       
   113 			result = EFalse;
       
   114 			}
       
   115 		}
       
   116 	
       
   117 	CleanupStack::PopAndDestroy(&pluginList);	
       
   118 	return result;	
       
   119 	}
       
   120 	
       
   121 
       
   122 TVerdict CTPostMarketPlugin::doTestStepL()
       
   123 	{
       
   124 	SetTestStepResult(EFail);
       
   125 	
       
   126 	//Connect to the AuthServer	
       
   127 	AuthServer::RAuthMgrClient authMgrClient;	
       
   128 	TInt connectVal = authMgrClient.Connect();
       
   129 	if (KErrNotFound == connectVal)
       
   130 		{
       
   131 		//Retry after a delay
       
   132 		TTimeIntervalMicroSeconds32 timeInterval = 2000;	//2 Milliseconds
       
   133 		User::After(timeInterval);
       
   134 		connectVal = authMgrClient.Connect();
       
   135 		}
       
   136 	if (KErrNone != connectVal)
       
   137 		{
       
   138 		ERR_PRINTF2(_L("Unable to start a session or other connection error. Err = %d"), connectVal);
       
   139 		User::LeaveIfError(connectVal);		
       
   140 		}	
       
   141 	
       
   142 	CleanupClosePushL(authMgrClient);
       
   143 	
       
   144 	RTestUtilSession testutil;
       
   145 	User::LeaveIfError(testutil.Connect());
       
   146 	CleanupClosePushL(testutil);
       
   147 	
       
   148 	// test plugin install operation.
       
   149 	INFO_PRINTF1(_L("Test Plugin Install"));
       
   150 	TBool success = TestPluginInstallL(authMgrClient, testutil);
       
   151 	if(!success)
       
   152 		{
       
   153 		INFO_PRINTF1(_L("Test Install failed!"));
       
   154 		CleanupStack::PopAndDestroy(2, &authMgrClient);
       
   155 		return TestStepResult();
       
   156 		}
       
   157 	
       
   158 	// test plugin uninstall operation.
       
   159 	INFO_PRINTF1(_L("Test Plugin Uninstall"));
       
   160 	success = TestPluginUninstallL(authMgrClient, testutil);
       
   161 	if(!success)
       
   162 		{
       
   163 		INFO_PRINTF1(_L("Test Uninstall failed!"));
       
   164 		CleanupStack::PopAndDestroy(2, &authMgrClient);
       
   165 		return TestStepResult();
       
   166 		}
       
   167 	
       
   168 	CleanupStack::PopAndDestroy(2, &authMgrClient);
       
   169 	
       
   170 	SetTestStepResult(EPass);
       
   171 	return TestStepResult();
       
   172 	}
       
   173 
       
   174 
       
   175 TBool CTPostMarketPlugin::TestPluginInstallL(AuthServer::RAuthMgrClient& aAuthMgrClient, RTestUtilSession& aUtilSession)
       
   176 	{
       
   177 	TBool success = EFalse;
       
   178 	
       
   179 	// get the list of available plugin implementations, before an plugin installation/upgrade.
       
   180 	TInt pluginCountPreInstall = 0;
       
   181 	if(GetIntFromConfig(ConfigSection(),_L("initialPluginCount"), pluginCountPreInstall) == EFalse)
       
   182 		{
       
   183 		INFO_PRINTF1(_L("Pre Install Plugin Count not specified in the ini file"));
       
   184 		return success;
       
   185 		}
       
   186 	
       
   187 	TBool result = VerifyObtainedResultsWithExpectedL(aAuthMgrClient, pluginCountPreInstall);
       
   188 	if(!result)
       
   189 		{
       
   190 		return success;
       
   191 		}
       
   192 		
       
   193 	// Install a plugin.
       
   194 	// Incase c:\sys\bin or c:\resource\plugins directory ,doesn't exist, 
       
   195 	// move operation fails with KErrPathNotFound.So create one.
       
   196 		
       
   197 	TInt err = aUtilSession.MkDirAll(KSysBinDir);
       
   198 	if(err != KErrAlreadyExists && err != KErrNone)
       
   199 		{
       
   200 		User::Leave(err);
       
   201 		}
       
   202 		
       
   203 	err = aUtilSession.MkDirAll(KRscDir);
       
   204 	if(err != KErrAlreadyExists && err != KErrNone)
       
   205 		{
       
   206 		User::Leave(err);
       
   207 		}
       
   208 	
       
   209 	INFO_PRINTF3(_L("Moving plugin from %S to %S..."), &iSrcPlugin, &iTargetPlugin);
       
   210 	User::LeaveIfError(aUtilSession.Move(iSrcPlugin, iTargetPlugin));
       
   211 	
       
   212 	INFO_PRINTF3(_L("Moving plugin from %S to %S..."), &iSrcRscFile, &iTargetRscFile);
       
   213 	User::LeaveIfError(aUtilSession.Move(iSrcRscFile, iTargetRscFile));
       
   214 		
       
   215 	WAIT_FOR3s;
       
   216 	
       
   217 	// get the list of available plugin implementations, post installation/upgrade.
       
   218 	TInt pluginCountPostInstall = 0;
       
   219 	if(GetIntFromConfig(ConfigSection(),_L("expectedPluginCount"), pluginCountPostInstall) == EFalse)
       
   220 		{
       
   221 		INFO_PRINTF1(_L("Post Install Plugin Count not specified in the ini file"));
       
   222 		return success;
       
   223 		}
       
   224 		
       
   225 	// get the plugin implementation list post installation.This should load the plugin version based on the ROM_only field.	
       
   226 	TPtrC pluginNamePostInstall;
       
   227 	if ((!GetStringFromConfig(ConfigSection(), _L("pluginNamePostInstall"), pluginNamePostInstall)))
       
   228 		{
       
   229 		INFO_PRINTF1(_L("Post Install Plugin Name not specified in the ini file"));
       
   230 		}
       
   231 	
       
   232 	result = VerifyObtainedResultsWithExpectedL(aAuthMgrClient, pluginCountPostInstall, pluginNamePostInstall);	
       
   233 	if(!result)
       
   234 		{
       
   235 		return success;
       
   236 		}
       
   237 	
       
   238 	success = ETrue;	
       
   239 	return success;
       
   240 	}
       
   241 
       
   242 
       
   243 TBool CTPostMarketPlugin::TestPluginUninstallL(AuthServer::RAuthMgrClient& aAuthMgrClient, RTestUtilSession& aUtilSession)
       
   244 	{
       
   245 	TBool success = EFalse;
       
   246 	
       
   247 	// get the list of available plugin implementations, before an plugin installation/upgrade.
       
   248 	TInt pluginCountPreUninstall = 0;
       
   249 	if(GetIntFromConfig(ConfigSection(),_L("expectedPluginCount"), pluginCountPreUninstall) == EFalse)
       
   250 		{
       
   251 		INFO_PRINTF1(_L("Pre Uninstall Plugin Count not specified in the ini file"));
       
   252 		return success;
       
   253 		}
       
   254 	
       
   255 	TBool result = VerifyObtainedResultsWithExpectedL(aAuthMgrClient, pluginCountPreUninstall);
       
   256 	if(!result)
       
   257 		{
       
   258 		return success;
       
   259 		}
       
   260 		
       
   261 	// Install a plugin.
       
   262 	INFO_PRINTF3(_L("Moving plugin from %S to %S..."), &iTargetPlugin, &iSrcPlugin);
       
   263 	User::LeaveIfError(aUtilSession.Move(iTargetPlugin, iSrcPlugin));
       
   264 	
       
   265 	INFO_PRINTF3(_L("Moving plugin from %S to %S..."), &iTargetRscFile, &iSrcRscFile);
       
   266 	User::LeaveIfError(aUtilSession.Move(iTargetRscFile, iSrcRscFile));
       
   267 		
       
   268 	WAIT_FOR3s;
       
   269 	
       
   270 	// get the list of available plugin implementations, post uninstallation.
       
   271 	TInt pluginCountPostUninstall = 0;
       
   272 	if(GetIntFromConfig(ConfigSection(),_L("initialPluginCount"), pluginCountPostUninstall) == EFalse)
       
   273 		{
       
   274 		INFO_PRINTF1(_L("Post Uninstall Plugin Count not specified in the ini file"));
       
   275 		return success;
       
   276 		}
       
   277 		
       
   278 	// get the plugin name post uninstall.	
       
   279 	TPtrC pluginNamePostUninstall;
       
   280 	if ((!GetStringFromConfig(ConfigSection(), _L("pluginNamePostUninstall"), pluginNamePostUninstall)))
       
   281 		{
       
   282 		INFO_PRINTF1(_L("Post Uninstall Plugin Name not specified in the ini file"));
       
   283 		}
       
   284 	
       
   285 	result = VerifyObtainedResultsWithExpectedL(aAuthMgrClient, pluginCountPostUninstall, pluginNamePostUninstall);	
       
   286 	if(!result)
       
   287 		{
       
   288 		return success;
       
   289 		}
       
   290 	
       
   291 	success = ETrue;	
       
   292 	return success;
       
   293 	}
       
   294 	
       
   295 	
       
   296 CTPostMarketPlugin::~CTPostMarketPlugin()
       
   297 /**
       
   298  Destructor
       
   299 */
       
   300 	{};
       
   301 	
       
   302 CTInstallPluginStep::CTInstallPluginStep()
       
   303 	{
       
   304 	SetTestStepName(KTInstallPluginStep);
       
   305 	}
       
   306 
       
   307 TVerdict CTInstallPluginStep::doTestStepPreambleL()
       
   308 /**
       
   309  * @return - TVerdict code
       
   310  * Override of base class virtual
       
   311  */
       
   312 	{
       
   313 	SetTestStepResult(EFail);
       
   314 	
       
   315 	CTAuthSvrStepBase::doTestStepPreambleL();
       
   316 	
       
   317 	if (!GetStringFromConfig(ConfigSection(), _L("srcPlugin"), iSrcPlugin))
       
   318 		{
       
   319 		INFO_PRINTF1(_L("Source plugin not specified in the ini file"));
       
   320 		return TestStepResult();
       
   321 		}
       
   322 		
       
   323 	if (!GetStringFromConfig(ConfigSection(), _L("destPlugin"), iTargetPlugin))
       
   324 		{
       
   325 		INFO_PRINTF1(_L("Target plugin not specified in the ini file"));
       
   326 		return TestStepResult();
       
   327 		}
       
   328 		
       
   329 	if (!GetStringFromConfig(ConfigSection(), _L("srcRscFile"), iSrcRscFile))
       
   330 		{
       
   331 		INFO_PRINTF1(_L("Source resource file not specified in the ini file"));
       
   332 		return TestStepResult();
       
   333 		}
       
   334 		
       
   335 	if (!GetStringFromConfig(ConfigSection(), _L("destRscFile"), iTargetRscFile))
       
   336 		{
       
   337 		INFO_PRINTF1(_L("Target resource file not specified in the ini file"));
       
   338 		return TestStepResult();
       
   339 		}
       
   340 		
       
   341 	SetTestStepResult(EPass);
       
   342 	return TestStepResult();
       
   343 	}
       
   344 	
       
   345 
       
   346 TVerdict CTInstallPluginStep::doTestStepL()
       
   347 	{
       
   348 	SetTestStepResult(EFail);
       
   349 	
       
   350 	//Connect to the AuthServer	
       
   351 	RTestUtilSession testUtil;
       
   352 	User::LeaveIfError(testUtil.Connect());
       
   353 	CleanupClosePushL(testUtil);
       
   354 	
       
   355 	// simulate plugin install operation via move operation.
       
   356 	INFO_PRINTF1(_L("Install RAM Plugin "));
       
   357 	
       
   358 	// Install a plugin.
       
   359 	// Incase c:\sys\bin or c:\resource\plugins directory ,doesn't exist, 
       
   360 	// move operation fails with KErrPathNotFound.So create one.
       
   361 	
       
   362 	TInt err = testUtil.MkDirAll(KSysBinDir);
       
   363 	if(err != KErrAlreadyExists && err != KErrNone)
       
   364 		{
       
   365 		User::Leave(err);
       
   366 		}
       
   367 		
       
   368 	err = testUtil.MkDirAll(KRscDir);
       
   369 	if(err != KErrAlreadyExists && err != KErrNone)
       
   370 		{
       
   371 		User::Leave(err);
       
   372 		}
       
   373 	
       
   374 	INFO_PRINTF3(_L("Moving plugin from %S to %S..."), &iSrcPlugin, &iTargetPlugin);
       
   375 	User::LeaveIfError(testUtil.Move(iSrcPlugin, iTargetPlugin));
       
   376 	
       
   377 	INFO_PRINTF3(_L("Moving plugin from %S to %S..."), &iSrcRscFile, &iTargetRscFile);
       
   378 	User::LeaveIfError(testUtil.Move(iSrcRscFile, iTargetRscFile));
       
   379 			
       
   380 	CleanupStack::PopAndDestroy(&testUtil);
       
   381 	
       
   382 	SetTestStepResult(EPass);
       
   383 	return TestStepResult();
       
   384 	}
       
   385 
       
   386 
       
   387 CTInstallPluginStep::~CTInstallPluginStep()
       
   388 /**
       
   389  Destructor
       
   390 */
       
   391 	{};
       
   392 	
       
   393 
       
   394 CTUninstallPluginStep::CTUninstallPluginStep()
       
   395 	{
       
   396 	SetTestStepName(KTUninstallPluginStep);
       
   397 	}
       
   398 
       
   399 TVerdict CTUninstallPluginStep::doTestStepPreambleL()
       
   400 /**
       
   401  * @return - TVerdict code
       
   402  * Override of base class virtual
       
   403  */
       
   404 	{
       
   405 	SetTestStepResult(EFail);
       
   406 	
       
   407 	CTAuthSvrStepBase::doTestStepPreambleL();
       
   408 	
       
   409 	if (!GetStringFromConfig(ConfigSection(), _L("srcPlugin"), iSrcPlugin))
       
   410 		{
       
   411 		INFO_PRINTF1(_L("Source plugin not specified in the ini file"));
       
   412 		return TestStepResult();
       
   413 		}
       
   414 		
       
   415 	if (!GetStringFromConfig(ConfigSection(), _L("destPlugin"), iTargetPlugin))
       
   416 		{
       
   417 		INFO_PRINTF1(_L("Target plugin not specified in the ini file"));
       
   418 		return TestStepResult();
       
   419 		}
       
   420 		
       
   421 	if (!GetStringFromConfig(ConfigSection(), _L("srcRscFile"), iSrcRscFile))
       
   422 		{
       
   423 		INFO_PRINTF1(_L("Source resource file not specified in the ini file"));
       
   424 		return TestStepResult();
       
   425 		}
       
   426 		
       
   427 	if (!GetStringFromConfig(ConfigSection(), _L("destRscFile"), iTargetRscFile))
       
   428 		{
       
   429 		INFO_PRINTF1(_L("Target resource file not specified in the ini file"));
       
   430 		return TestStepResult();
       
   431 		}
       
   432 		
       
   433 	SetTestStepResult(EPass);
       
   434 	return TestStepResult();
       
   435 	}
       
   436 	
       
   437 
       
   438 TVerdict CTUninstallPluginStep::doTestStepL()
       
   439 	{
       
   440 	SetTestStepResult(EFail);
       
   441 	
       
   442 	//Connect to the AuthServer	
       
   443 	RTestUtilSession testUtil;
       
   444 	User::LeaveIfError(testUtil.Connect());
       
   445 	CleanupClosePushL(testUtil);
       
   446 	
       
   447 	// simulate plugin uninstall operation via move operation.
       
   448 	INFO_PRINTF1(_L("Unnstall RAM Plugin "));
       
   449 	
       
   450 	INFO_PRINTF3(_L("Moving plugin from %S to %S..."), &iSrcPlugin, &iTargetPlugin);
       
   451 	User::LeaveIfError(testUtil.Move(iSrcPlugin, iTargetPlugin));
       
   452 	
       
   453 	INFO_PRINTF3(_L("Moving plugin from %S to %S..."), &iSrcRscFile, &iTargetRscFile);
       
   454 	User::LeaveIfError(testUtil.Move(iSrcRscFile, iTargetRscFile));
       
   455 	
       
   456 	CleanupStack::PopAndDestroy(&testUtil);
       
   457 	
       
   458 	SetTestStepResult(EPass);
       
   459 	return TestStepResult();
       
   460 	}
       
   461 
       
   462 
       
   463 CTUninstallPluginStep::~CTUninstallPluginStep()
       
   464 /**
       
   465  Destructor
       
   466 */
       
   467 	{};
       
   468