installationservices/swi/test/tsisregistrytest/tsisregistryteststep.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2004-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 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file 
       
    21  @test
       
    22  @internalTechnology
       
    23 */
       
    24  
       
    25 #include <test/testexecutelog.h>
       
    26 #include "tsisregistryteststep.h"
       
    27 #include "testutilclientswi.h"
       
    28 #include "filesisdataprovider.h"
       
    29 #include "siscontents.h"
       
    30 #include "sisparser.h"
       
    31 
       
    32 /////////////////////////////////////////////////////////////////////
       
    33 // defs, Constants used by test steps
       
    34 /////////////////////////////////////////////////////////////////////
       
    35 
       
    36 _LIT(KSisRegistryPath, "\\sys\\install\\sisregistry\\");
       
    37 _LIT(KBackupPath, "\\sys\\install\\backup\\");
       
    38 _LIT(KTestRegistryPath, "z:\\tswi\\tsisregistrytest\\data\\");
       
    39 _LIT(KSaveRegistryPath, "\\tswi\\tsisregistrytest\\generated\\");
       
    40 
       
    41 _LIT(KScrDbFileName, "scr.db");
       
    42 _LIT(KScrDbFilePath, "\\sys\\install\\scr\\");
       
    43 
       
    44 _LIT(KKeyFormat, "-%02d");
       
    45 
       
    46 /////////////////////////////////////////////////////////////////////
       
    47 // Tags used by test steps
       
    48 /////////////////////////////////////////////////////////////////////
       
    49 
       
    50 void CSisRegistryTestStepBase:: MarkAsPerformanceStep()
       
    51 	{
       
    52 	iIsPerformanceTest = ETrue;
       
    53 	}
       
    54 
       
    55 void CSisRegistryTestStepBase::PrintPerformanceLog(TTime aTime)
       
    56 	{
       
    57 	_LIT(KPerformanceTestInfo, "PERFORMANCE_LOG_INFORMATION");
       
    58 	TDateTime timer = aTime.DateTime();
       
    59 	INFO_PRINTF6(_L("%S,%d:%d:%d:%d"), &KPerformanceTestInfo(), timer.Hour(), timer.Minute(), timer.Second(), timer.MicroSecond());
       
    60 	}
       
    61 
       
    62 TVerdict CSisRegistryTestStepBase::PrintErrorAndReturnFailL(const TDesC& aMsg)
       
    63 	{
       
    64 	ERR_PRINTF1(aMsg);
       
    65 	SetTestStepResult(EFail);
       
    66 	return TestStepResult();
       
    67 	}
       
    68 
       
    69 void CSisRegistryTestStepBase::StartTimer()
       
    70 	{
       
    71 	if(!iIsPerformanceTest)
       
    72 		return; // Do nothing if not performance test
       
    73 	iStartTime.HomeTime();
       
    74 	PrintPerformanceLog(iStartTime);
       
    75 	}
       
    76 
       
    77 void CSisRegistryTestStepBase::StopTimerAndPrintResultL()
       
    78 	{
       
    79 	if(!iIsPerformanceTest)
       
    80 		return; // Do nothing if not performance test
       
    81 	
       
    82 	TTime endTime;
       
    83 	endTime.HomeTime();
       
    84 	PrintPerformanceLog(endTime);
       
    85 	
       
    86 	TTimeIntervalMicroSeconds duration = endTime.MicroSecondsFrom(iStartTime);
       
    87 	TInt actualDuration = I64INT(duration.Int64())/1000; // in millisecond
       
    88 	
       
    89 	if(iTimeMeasuredExternally)
       
    90 		{ // if the time has been measured externally, update the actual duration value with that.
       
    91 		actualDuration = iTimeMeasuredExternally;
       
    92 		}
       
    93 	
       
    94 	// Performance related names
       
    95 	_LIT(KMaxDurationName, "MaxDuration");
       
    96 	_LIT(KMaxTestCaseDuration, "TEST_CASE_MAXIMUM_ALLOWED_DURATION");
       
    97 	_LIT(KActualTestCaseDuration, "TEST_CASE_ACTUAL_DURATION");
       
    98 	
       
    99 	TInt maxDuration = 0;
       
   100 	if(!GetIntFromConfig(ConfigSection(), KMaxDurationName, maxDuration))
       
   101 		{
       
   102 		ERR_PRINTF2(_L("%S could not be found in configuration."), &KMaxDurationName());
       
   103 		User::Leave(KErrNotFound);
       
   104 		}
       
   105 	else
       
   106 		{
       
   107 		INFO_PRINTF3(_L("%S,%d"), &KMaxTestCaseDuration(), maxDuration);
       
   108 		INFO_PRINTF3(_L("%S,%d"), &KActualTestCaseDuration(), actualDuration);
       
   109 		}
       
   110 	
       
   111 	if(actualDuration <= maxDuration)
       
   112 		{
       
   113 		INFO_PRINTF2(_L("This test meets performance requirement (Duration=%d)."), actualDuration);
       
   114 		}
       
   115 	else
       
   116 		{
       
   117 		ERR_PRINTF2(_L("This test does not meet performance requirement (Duration=%d)."), actualDuration);
       
   118 		SetTestStepResult(EFail);
       
   119 		}
       
   120 	}
       
   121 
       
   122 void CSisRegistryTestStepBase::GetStringArrayFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, RArray<TPtrC>& aArray)
       
   123 	{
       
   124 	HBufC* buf = HBufC::NewLC(aKeyName.Length() + KKeyFormat().Length());
       
   125 	TPtr ptr(buf->Des());
       
   126 	INFO_PRINTF2(_L("Parsing attribute: %S"), &aKeyName);
       
   127 
       
   128 	TInt i = 0;
       
   129 	TBool cont = ETrue;
       
   130 	do
       
   131 		{
       
   132 		++i;
       
   133 		ptr = aKeyName;
       
   134 		ptr.AppendFormat(KKeyFormat(), i);
       
   135 		TPtrC val;
       
   136 
       
   137 		cont = GetStringFromConfig(aSectName, ptr, val);
       
   138 		if (cont)
       
   139 			{
       
   140 			TInt error = aArray.Append(val);
       
   141 
       
   142 			INFO_PRINTF2(_L("String name: %S"), &val);
       
   143 
       
   144 			User::LeaveIfError(error);
       
   145 			}
       
   146 		} while (cont);
       
   147 
       
   148 	INFO_PRINTF2(_L("Element count: %d"), i-1);
       
   149 	CleanupStack::PopAndDestroy(buf);
       
   150 	}
       
   151 
       
   152 TBool CSisRegistryTestStepBase::GetUidFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TUid& aUid)
       
   153 	{
       
   154 	TInt val;
       
   155 	if(GetHexFromConfig(aSectName, aKeyName, val))
       
   156 		{
       
   157 		aUid = TUid::Uid(val);
       
   158 		return ETrue;
       
   159 		}
       
   160 	else
       
   161 		{
       
   162 		return EFalse;
       
   163 		}
       
   164 	}
       
   165 
       
   166 void CSisRegistryTestStepBase::GetUidArrayFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, RArray<TUid>& aArray)
       
   167 	{
       
   168 	HBufC* buf = HBufC::NewLC(aKeyName.Length() + KKeyFormat().Length());
       
   169 	TPtr ptr(buf->Des());
       
   170 	INFO_PRINTF2(_L("Parsing attribute: %S"), &aKeyName);
       
   171 
       
   172 	TInt i = 0;
       
   173 	TBool cont = ETrue;
       
   174 	do
       
   175 		{
       
   176 		++i;
       
   177 		ptr = aKeyName;
       
   178 		ptr.AppendFormat(KKeyFormat(), i);
       
   179 		TUid uid;
       
   180 
       
   181 		cont = GetUidFromConfig(aSectName, ptr, uid);
       
   182 		if (cont)
       
   183 			{
       
   184 			User::LeaveIfError(aArray.Append(uid));
       
   185 			}
       
   186 		} while (cont);
       
   187 
       
   188 	INFO_PRINTF2(_L("Element count: %d"), i-1);
       
   189 	CleanupStack::PopAndDestroy(buf);
       
   190 	}
       
   191 
       
   192 void CSisRegistryTestStepBase::GetIntArrayFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, RArray<TInt>& aArray)
       
   193 	{
       
   194 	HBufC* buf = HBufC::NewLC(aKeyName.Length() + KKeyFormat().Length());
       
   195 	TPtr ptr(buf->Des());
       
   196 	INFO_PRINTF2(_L("Parsing attribute: %S"), &aKeyName);
       
   197 
       
   198 	TInt i = 0;
       
   199 	TBool cont = ETrue;
       
   200 	do
       
   201 		{
       
   202 		++i;
       
   203 		ptr = aKeyName;
       
   204 		ptr.AppendFormat(KKeyFormat(), i);
       
   205 		TInt val;
       
   206 
       
   207 		cont = GetIntFromConfig(aSectName, ptr, val);
       
   208 		if (cont)
       
   209 			{
       
   210 			User::LeaveIfError(aArray.Append(val));
       
   211 			}
       
   212 		} while (cont);
       
   213 
       
   214 	INFO_PRINTF2(_L("Element count: %d"), i-1);
       
   215 	CleanupStack::PopAndDestroy(buf);
       
   216 	}
       
   217 
       
   218 HBufC8* CSisRegistryTestStepBase::GetControllerFromSisLC(const TDesC& aSisFileName)
       
   219 	{
       
   220 	RFs fs;
       
   221 	User::LeaveIfError(fs.Connect());
       
   222 	CleanupClosePushL(fs);
       
   223 	RFile file;
       
   224 	User::LeaveIfError(file.Open(fs, aSisFileName, EFileRead));
       
   225 	CleanupClosePushL(file);
       
   226 
       
   227 	// Create a file data provider
       
   228 	MSisDataProvider* dataProvider = CFileSisDataProvider::NewLC(file);
       
   229 
       
   230 	// Extract raw controller data into a buffer
       
   231 	TInt64 pos(0);
       
   232 	User::LeaveIfError(dataProvider->Seek(ESeekStart, pos));
       
   233 	Sis::CContents *contents = Sis::Parser::ContentsL(*dataProvider);
       
   234 	CleanupStack::PushL(contents);
       
   235 	HBufC8* ret = contents->ReadControllerL();
       
   236 	CleanupStack::PopAndDestroy(4, &fs); //contents, dataProvier, file
       
   237 	CleanupStack::PushL(ret);
       
   238 	return ret;
       
   239 	}
       
   240 /////////////////////////////////////////////////////////////////////
       
   241 // CBackupRegistryStep
       
   242 /////////////////////////////////////////////////////////////////////
       
   243 CBackupRegistryStep::CBackupRegistryStep()
       
   244 	{
       
   245 	SetTestStepName(KBackupRegistry);
       
   246 	}
       
   247 
       
   248 TVerdict CBackupRegistryStep::doTestStepL()
       
   249 	{
       
   250 	RTestUtilSessionSwi util;
       
   251 	User::LeaveIfError(util.Connect());
       
   252 	CleanupClosePushL(util);
       
   253 	
       
   254 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   255 	TDriveName sysDriveName (sysDrive.Name());
       
   256 		
       
   257 	TBuf<128> backUpPath (sysDriveName);
       
   258 	backUpPath.Append(KBackupPath);
       
   259 
       
   260 	(void) util.RmDir(backUpPath);
       
   261 
       
   262 	TBuf<128> sisRegistryPath (sysDriveName);
       
   263 	sisRegistryPath.Append(KSisRegistryPath);
       
   264 	TInt err = util.Move(sisRegistryPath, backUpPath);
       
   265 	if(err != KErrNone && err != KErrPathNotFound && err != KErrNotFound)
       
   266 		{
       
   267 		User::Leave(err);
       
   268 		}
       
   269 		
       
   270 	TBuf<128> backupDbPath(sysDriveName);
       
   271 	backupDbPath.Append(KBackupPath);
       
   272 	backupDbPath.Append(KScrDbFileName);
       
   273 	
       
   274 	TBuf<128> scrDbPath(sysDriveName);
       
   275 	scrDbPath.Append(KScrDbFilePath);
       
   276 	scrDbPath.Append(KScrDbFileName);
       
   277 			
       
   278 	// Copy the current SCR in to backup location
       
   279 	err = util.Move(scrDbPath, backupDbPath);
       
   280 	if(err != KErrNone && err != KErrPathNotFound && err != KErrNotFound)
       
   281 		{
       
   282 		User::Leave(err);
       
   283 		}	
       
   284 
       
   285 	CleanupStack::PopAndDestroy(&util);
       
   286 	
       
   287 	SetTestStepResult(EPass);
       
   288 	return TestStepResult();
       
   289 	}
       
   290 
       
   291 /////////////////////////////////////////////////////////////////////
       
   292 // CCreateTestRegistryStep
       
   293 /////////////////////////////////////////////////////////////////////
       
   294 CCreateTestRegistryStep::CCreateTestRegistryStep()
       
   295 	{
       
   296 	SetTestStepName(KCreateTestRegistry);
       
   297 	}
       
   298 
       
   299 TVerdict CCreateTestRegistryStep::doTestStepL()
       
   300 	{
       
   301 	RTestUtilSessionSwi util;
       
   302 	User::LeaveIfError(util.Connect());
       
   303 	CleanupClosePushL(util);
       
   304 	
       
   305 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   306 	TBuf<128> sisRegistryPath (sysDrive.Name());
       
   307 	sisRegistryPath.Append(KSisRegistryPath);
       
   308 
       
   309 	User::LeaveIfError(util.Copy(KTestRegistryPath, sisRegistryPath));
       
   310 		
       
   311 	TBuf<128> emptyDbPath(KTestRegistryPath);
       
   312 	emptyDbPath.Append(KScrDbFileName);
       
   313 	
       
   314 	TBuf<128> scrDbPath(sysDrive.Name());
       
   315 	scrDbPath.Append(KScrDbFilePath);
       
   316 	scrDbPath.Append(KScrDbFileName);
       
   317 	
       
   318 	TBuf<128> exesDbFile(sysDrive.Name());
       
   319 	exesDbFile.Append(KSisRegistryPath);
       
   320 	exesDbFile.Append(KScrDbFileName);
       
   321 	
       
   322 	// Remove the extra SCR DB file copied from KTestRegistryPath to sisRegistryPath
       
   323 	util.Delete(exesDbFile);
       
   324 			
       
   325 	// Copy the empty SCR DB in place
       
   326 	User::LeaveIfError(util.Copy(emptyDbPath, scrDbPath));
       
   327 	
       
   328 	CleanupStack::PopAndDestroy(&util);
       
   329 	
       
   330 	SetTestStepResult(EPass);
       
   331 	return TestStepResult();
       
   332 	}
       
   333 
       
   334 /////////////////////////////////////////////////////////////////////
       
   335 // CDeleteRegistryStep
       
   336 /////////////////////////////////////////////////////////////////////
       
   337 CDeleteRegistryStep::CDeleteRegistryStep()
       
   338 	{
       
   339 	SetTestStepName(KDeleteRegistry);
       
   340 	}
       
   341 
       
   342 TVerdict CDeleteRegistryStep::doTestStepL()
       
   343 	{
       
   344 	// Wait up to 30 seconds to ensure both the sisregistry server and SCRServer
       
   345 	// have shut down
       
   346 	_LIT(KSisRegistryServerName, "!SisRegistryServer");
       
   347 	_LIT(KScrServerName, "!ScrServer");
       
   348 	TInt delaytime = 30; 
       
   349 
       
   350 	while (delaytime-- > 0)
       
   351 		{
       
   352 		TFullName serverName;
       
   353 		TFindServer find(KSisRegistryServerName);
       
   354 		if (KErrNotFound == find.Next(serverName))
       
   355 			{
       
   356 			find.Find(KScrServerName);
       
   357 			if (KErrNotFound == find.Next(serverName))
       
   358 				{
       
   359 				break;
       
   360 				}
       
   361 			}
       
   362 		User::After(1000000); // wait a second until the next test
       
   363 		}
       
   364 		
       
   365 	RTestUtilSessionSwi util;
       
   366 	User::LeaveIfError(util.Connect());
       
   367 	CleanupClosePushL(util);
       
   368 	
       
   369 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   370 	TBuf<128> sisRegistryPath (sysDrive.Name());
       
   371 	sisRegistryPath.Append(KSisRegistryPath);
       
   372 	
       
   373 	TInt err = util.RmDir(sisRegistryPath);
       
   374 	if(err != KErrNone && err != KErrPathNotFound && err != KErrNotFound)
       
   375 		{
       
   376 		User::Leave(err);
       
   377 		}
       
   378 			
       
   379 	TBuf<128> scrDbPath(sysDrive.Name());
       
   380 	scrDbPath.Append(KScrDbFilePath);
       
   381 	scrDbPath.Append(KScrDbFileName);
       
   382 			
       
   383 	// Delete the current SCR DB
       
   384 	err = util.Delete(scrDbPath);
       
   385 	if(err != KErrNone && err != KErrPathNotFound && err != KErrNotFound)
       
   386 		{
       
   387 		User::Leave(err);
       
   388 		}	
       
   389 	
       
   390 	CleanupStack::PopAndDestroy(&util);
       
   391 	
       
   392 	SetTestStepResult(EPass);
       
   393 	return TestStepResult();
       
   394 	}
       
   395 
       
   396 /////////////////////////////////////////////////////////////////////
       
   397 // CRestoreRegistryStep
       
   398 /////////////////////////////////////////////////////////////////////
       
   399 CRestoreRegistryStep::CRestoreRegistryStep()
       
   400 	{
       
   401 	SetTestStepName(KRestoreRegistry);
       
   402 	}
       
   403 
       
   404 TVerdict CRestoreRegistryStep::doTestStepL()
       
   405 	{
       
   406 	RTestUtilSessionSwi util;
       
   407 	User::LeaveIfError(util.Connect());
       
   408 	CleanupClosePushL(util);
       
   409 	
       
   410 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   411 	TDriveName sysDriveName (sysDrive.Name());
       
   412 
       
   413 	TBuf<128> backUpPath (sysDriveName);
       
   414 	backUpPath.Append(KBackupPath);
       
   415 	
       
   416 	TBuf<128> sisRegistryPath (sysDriveName);
       
   417 	sisRegistryPath.Append(KSisRegistryPath);
       
   418 	
       
   419 	TInt err = util.Move(backUpPath, sisRegistryPath);
       
   420 	if(err != KErrNone && err != KErrPathNotFound && err != KErrNotFound)
       
   421 		{
       
   422 		User::Leave(err);
       
   423 		}
       
   424 		
       
   425 	TBuf<128> backupDbPath(sysDriveName);
       
   426 	backupDbPath.Append(KSisRegistryPath);
       
   427 	backupDbPath.Append(KScrDbFileName);
       
   428 	
       
   429 	TBuf<128> scrDbPath(sysDriveName);
       
   430 	scrDbPath.Append(KScrDbFilePath);
       
   431 	scrDbPath.Append(KScrDbFileName);
       
   432 
       
   433 	// SCR DB already copied from backup path to sisregistrypath,
       
   434 	// so, copy the file from there to SCR path.
       
   435 	err = util.Move(backupDbPath, scrDbPath);
       
   436 	if(err != KErrNone && err != KErrPathNotFound && err != KErrNotFound)
       
   437 		{
       
   438 		User::Leave(err);
       
   439 		}	
       
   440 	CleanupStack::PopAndDestroy(&util);
       
   441 	
       
   442 	SetTestStepResult(EPass);
       
   443 	return TestStepResult();
       
   444 	}
       
   445 
       
   446 /////////////////////////////////////////////////////////////////////
       
   447 // CSaveRegistryStep
       
   448 /////////////////////////////////////////////////////////////////////
       
   449 CSaveRegistryStep::CSaveRegistryStep()
       
   450 	{
       
   451 	SetTestStepName(KSaveGeneratedRegistry);
       
   452 	}
       
   453 
       
   454 TVerdict CSaveRegistryStep::doTestStepL()
       
   455 	{
       
   456 	// Wait up to 30 seconds to ensure both the sisregistry server and SCRServer
       
   457 	// have shut down
       
   458 	_LIT(KSisRegistryServerName, "!SisRegistryServer");
       
   459 	_LIT(KScrServerName, "!ScrServer");
       
   460 	TInt delaytime = 30; 
       
   461 
       
   462 	while (delaytime-- > 0)
       
   463 		{
       
   464 		TFullName serverName;
       
   465 		TFindServer find(KSisRegistryServerName);
       
   466 		if (KErrNotFound == find.Next(serverName))
       
   467 			{
       
   468 			find.Find(KScrServerName);
       
   469 			if (KErrNotFound == find.Next(serverName))
       
   470 				{
       
   471 				break;
       
   472 				}
       
   473 			}
       
   474 		User::After(1000000); // wait a second until the next test
       
   475 		}
       
   476 	
       
   477 	RTestUtilSessionSwi util;
       
   478 	User::LeaveIfError(util.Connect());
       
   479 	CleanupClosePushL(util);
       
   480 	
       
   481 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   482 	TDriveName sysDriveName(sysDrive.Name());
       
   483 	
       
   484 	TFileName saveRegistryPath (sysDriveName);
       
   485 	saveRegistryPath.Append(KSaveRegistryPath);
       
   486 
       
   487 	TInt err = util.RmDir(saveRegistryPath);
       
   488 	TFileName sisRegistryPath (sysDriveName);
       
   489 	sisRegistryPath.Append(KSisRegistryPath);
       
   490 	
       
   491 	User::LeaveIfError(util.Copy(sisRegistryPath, saveRegistryPath));
       
   492 		
       
   493 	TBuf<128> dbSavePath(sysDriveName);
       
   494 	dbSavePath.Append(KSaveRegistryPath);
       
   495 	dbSavePath.Append(KScrDbFileName);
       
   496 	
       
   497 	TBuf<128> scrDbPath(sysDriveName);
       
   498 	scrDbPath.Append(KScrDbFilePath);
       
   499 	scrDbPath.Append(KScrDbFileName);
       
   500 
       
   501 	// Save the SCR DB to the saving location
       
   502 	User::LeaveIfError(util.Copy(scrDbPath, dbSavePath));
       
   503 	
       
   504 	CleanupStack::PopAndDestroy(&util);
       
   505 	
       
   506 	SetTestStepResult(EPass);
       
   507 	return TestStepResult();
       
   508 	}