cbsref/csyrefplugins/csy27010/test/unit_test_base/unitTestBase.cpp
changeset 49 f50f4094acd7
equal deleted inserted replaced
48:14460bf2a402 49:f50f4094acd7
       
     1 //
       
     2 // * Copyright 2004 Neusoft America Inc.
       
     3 // * All rights reserved.
       
     4 // * This component and the accompanying materials are made available
       
     5 // * under the terms of the 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 // * Contributors:
       
    10 // * Keith Collins (Neusoft America Inc.)  original software development and additional code and modifications.
       
    11 // * Thomas Gahagen (Neusoft America Inc.)  additional code and modifications.
       
    12 // * Zhen Yuan (Neusoft America Inc.)  additional code and modifications.
       
    13 // *
       
    14 // * Description:  This file contains the implementation for the base class from 
       
    15 // *               which all unit test classes are derived.
       
    16 //
       
    17 
       
    18 // UnitTestBase.cpp
       
    19 
       
    20 /** @file UnitTestBase.cpp
       
    21  *
       
    22  */
       
    23 
       
    24 #include "unitTestBase.h"
       
    25 
       
    26 // This indicates that the CSY is loaded by the TSY
       
    27 #define LOADED_BY_TSY	1
       
    28 
       
    29 //
       
    30 // CUnitTestBase
       
    31 //
       
    32 
       
    33 // These methods can be overwritten
       
    34 
       
    35 TBool CUnitTestBase::HasTestRangesDefined()
       
    36 	{
       
    37 	return EFalse;
       
    38 	}
       
    39 
       
    40 
       
    41 void CUnitTestBase::ConstructL()
       
    42 /**
       
    43  *
       
    44  *
       
    45  */
       
    46 	{
       
    47 	//LOGTEXT(">>ConstructL");
       
    48 
       
    49 	User::LeaveIfError(iFs.Connect());
       
    50 	User::LeaveIfError(iFs.SetSessionPath(KTestSessionPath));
       
    51 
       
    52 	TInt err=iLogFile.Open(iFs,iLogFileName, EFileWrite);
       
    53 
       
    54 	if (err==KErrNotFound) // file does not exist - create it
       
    55 		{
       
    56 		err = iLogFile.Create(iFs, iLogFileName, EFileWrite);
       
    57 		}
       
    58 	// In simultaneous tests, someone else may have created it between our
       
    59 	// calls to Open and Create, so no 'else' here.
       
    60 	if ( err == KErrInUse || err == KErrAlreadyExists )
       
    61 		{
       
    62 		//LOGTEXT("Distinct logging required");
       
    63 
       
    64 		// Same filename already open by someone else. In order to run more
       
    65 		// than one test in, say, BasicCall at once AND have logging that
       
    66 		// works, create distinct log files when required.
       
    67 		TInt n = 0;
       
    68 		while ( err == KErrInUse || err == KErrAlreadyExists )
       
    69 			{
       
    70 			TName newLogFileName(iLogFileName);
       
    71 			n++;
       
    72 			newLogFileName.AppendFormat(_L("%d"),n);
       
    73 			err = iLogFile.Open(iFs, newLogFileName, EFileWrite);
       
    74 			if (! err)
       
    75 				{
       
    76 				TInt pos = 0;
       
    77 				iLogFile.Seek(ESeekEnd, pos);
       
    78 				}
       
    79 			if ( err == KErrNotFound )
       
    80 				{
       
    81 				err = iLogFile.Create(iFs, newLogFileName, EFileWrite);
       
    82 				break;
       
    83 				}
       
    84 			}
       
    85 		}
       
    86 
       
    87 	if (err)
       
    88 		{
       
    89 		iTest.Printf(_L("Couldn't open log file (%d). Does the %S path exist?\n"), err, &KTestSessionPath);
       
    90 		User::After(4000000);
       
    91 		User::Leave(err);
       
    92 		}
       
    93 	TInt pos = 0;
       
    94 	iLogFile.Seek(ESeekEnd, pos);
       
    95 
       
    96 	err = iLogFile.Write(_L8("#------------------------Test Run Start-------------------------\r\n"));
       
    97 	iLogFile.Flush();
       
    98 
       
    99 	}
       
   100 
       
   101 CUnitTestBase::CUnitTestBase(const TDesC& aUnitTestName,
       
   102 							 const TDesC& aLogFileName,
       
   103 							 const TDesC& aTestSpecName,
       
   104 							 const TDesC& aTestScriptName)
       
   105 /**
       
   106  *
       
   107  *
       
   108  */
       
   109 	:iTest(aUnitTestName),
       
   110 	 iUnitTestName(aUnitTestName),
       
   111 	 iLogFileName(aLogFileName),
       
   112 	 iTestScriptName(aTestScriptName),
       
   113 	 iTestSpecName(aTestSpecName)
       
   114 	{
       
   115 #ifndef __WINS__
       
   116 	iTest.SetLogged(EFalse);
       
   117 #endif // __WINS__
       
   118 	}
       
   119 
       
   120 CUnitTestBase::~CUnitTestBase()
       
   121 /**
       
   122  *
       
   123  *
       
   124  */
       
   125 	{
       
   126 	iFailedTests.Close();
       
   127 
       
   128 	if (iLogFile.SubSessionHandle())
       
   129 		{
       
   130 		iLogFile.Write(_L8("#------------------------Test Run End-------------------------\r\n"));
       
   131 		iLogFile.Flush();
       
   132 		}
       
   133 	iLogFile.Close();
       
   134 	iFs.Close();
       
   135 	iTest.Close();
       
   136 	}
       
   137 
       
   138 void CUnitTestBase::ResizeConsoleL(const TDesC& aName, TInt aXOrg, TInt aYOrg, TInt aXSize, TInt aYSize)
       
   139 	{
       
   140 #if defined (__WINS__)
       
   141 	CConsoleBase* cons = iTest.Console();
       
   142 	CConsoleBase* newCon = NULL;
       
   143 
       
   144 	TRAPD(err,newCon = Console::NewL(aName,TSize(aXSize,aYSize)));
       
   145 	if (!err)
       
   146 		{
       
   147 		(void)aXOrg; (void)aYOrg; //unable to use these without a dirty hack!
       
   148 		delete cons;
       
   149 		iTest.SetConsole(newCon);
       
   150 		}
       
   151 #else //__WINS__
       
   152 	(void)aName; (void)aXOrg; (void)aYOrg; (void)aXSize; (void)aYSize;
       
   153 #endif //__WINS__
       
   154 	}
       
   155 
       
   156 TBool CUnitTestBase::DoSingleTestL(TInt aMethodNum, TInt aTestNum, TTestMode aTestMode)
       
   157 	{
       
   158 	//LOGTEXT3(">>DoSingleTestL [aMethodNum=%d, aTestNum=%d]",aMethodNum,aTestNum);
       
   159 
       
   160 	TInt numMethods;
       
   161 	TInt numTests;
       
   162 	TInt errorCode;
       
   163 	TInt leaveCode;
       
   164 
       
   165 	// Check if the specified test is in a valid range - if we can
       
   166 	if (HasTestRangesDefined())
       
   167 		{
       
   168 		RunTestsL(EFalse, EBatch, numMethods, leaveCode, 0, 0);
       
   169 
       
   170 		// Check that the method number is correct
       
   171 		if (aMethodNum == 0 || aMethodNum > numMethods)
       
   172 			{
       
   173 			iTest.Printf(_L("Bad method number: %d - Needs to be in range 1 to %d\n"),
       
   174 						aMethodNum, numMethods);
       
   175 			iTest.Printf(_L("Press a key when ready\n"));
       
   176 			iTest.Console()->Getch();
       
   177 			//LOGTEXT("<<DoSingleTestL bad method number");
       
   178 			return ETrue;
       
   179 			}
       
   180 
       
   181 
       
   182 		TInt testRange = 0;
       
   183 		if (aTestNum > 100) testRange = 100;
       
   184 
       
   185 		// Get the number of tests for this method and test if aTestNum is in range
       
   186 		RunTestsL(EFalse, EBatch, numTests, leaveCode, aMethodNum, testRange);
       
   187 		numTests += testRange;
       
   188 
       
   189 		if (aTestNum <= testRange || aTestNum > numTests)
       
   190 			{
       
   191 			iTest.Printf(_L("Bad test number (%d) for method %d - Needs to be in range %d to %d\n"),
       
   192 						aTestNum, aMethodNum, testRange+1, numTests);
       
   193 			iTest.Printf(_L("Press a key when ready\n"));
       
   194 			iTest.Console()->Getch();
       
   195 			//LOGTEXT("<<DoSingleTestL bad test number");
       
   196 			return ETrue;
       
   197 			}
       
   198 		}
       
   199 
       
   200 	errorCode = KErrNone;
       
   201 	leaveCode = KErrNone;
       
   202 
       
   203 	RunTestsL(EFalse, aTestMode, errorCode, leaveCode, aMethodNum,aTestNum);
       
   204 
       
   205 	LogTestResult(errorCode, leaveCode, EFalse, aMethodNum, aTestNum, aTestMode);
       
   206 
       
   207 	//LOGTEXT("<<DoSingleTestL ETrue");
       
   208 	return ETrue;
       
   209 	}
       
   210 
       
   211 TBool CUnitTestBase::DoAutoMethodTestsL(TInt aMethodNum)
       
   212 	{
       
   213 	//LOGTEXT2(">>DoAutoMethodTestsL [aMethodNum=%d]",aMethodNum);
       
   214 
       
   215 	TInt numMethods;
       
   216 	TInt numTests;
       
   217 	TInt errorCode;
       
   218 	TInt leaveCode;
       
   219 
       
   220 	if (! HasTestRangesDefined())
       
   221 		{
       
   222 		iTest.Printf(_L("Cannot auto run tests as test ranges not implemented\n"));
       
   223 		iTest.Printf(_L("Press a key when ready\n"));
       
   224 		iTest.Console()->Getch();
       
   225 		return ETrue;
       
   226 		}
       
   227 
       
   228 	// Check that the method number is correct
       
   229 	RunTestsL(EFalse, EBatch, numMethods, leaveCode, 0, 0);
       
   230 
       
   231 	if (aMethodNum == 0 || aMethodNum > numMethods)
       
   232 		{
       
   233 		iTest.Printf(_L("Bad method number: %d - Needs to be in range 1 to %d\n"),
       
   234 					aMethodNum, numMethods);
       
   235 		iTest.Printf(_L("Press a key when ready\n"));
       
   236 		iTest.Console()->Getch();
       
   237 		return ETrue;
       
   238 		}
       
   239 
       
   240 
       
   241 	// Get the number of automated tests for this method
       
   242 	RunTestsL(EFalse, EBatch, numTests, leaveCode, aMethodNum, 0);
       
   243 
       
   244 	for (TInt testIndex = 1; testIndex <= numTests; testIndex++)
       
   245 		{
       
   246 		errorCode = KErrNone;
       
   247 		leaveCode = KErrNone;
       
   248 
       
   249 		RunTestsL(EFalse, EBatch, errorCode, leaveCode, aMethodNum, testIndex);
       
   250 		LogTestResult(errorCode, leaveCode, EFalse, aMethodNum, testIndex, EBatch);
       
   251 
       
   252 		if (errorCode || leaveCode)
       
   253 			{
       
   254 			TTestFailure theFailedTest(aMethodNum, testIndex);
       
   255 			(void) iFailedTests.Append(theFailedTest);
       
   256 			}
       
   257 		}
       
   258 
       
   259 	//LOGTEXT("<<DoAutoMethodTestsL");
       
   260 	return ETrue;
       
   261 	}
       
   262 
       
   263 TBool CUnitTestBase::DoTestsInSpecifiedRangeL(TInt aStartMethodNum,
       
   264 											  TInt aStartTestNum,
       
   265 											  TInt aEndMethodNum,
       
   266 											  TInt aEndTestNum)
       
   267 	{
       
   268 	//LOGTEXT3(">>DoTestsInSpecifiedRangeL [aStartMethodNum=%d, aEndMethodNum=%d]",
       
   269 	//	aStartMethodNum,aEndMethodNum);
       
   270 
       
   271 	TInt numMethods;
       
   272 	TInt numTests;
       
   273 	TInt errorCode;
       
   274 	TInt leaveCode;
       
   275 
       
   276 	if (! HasTestRangesDefined())
       
   277 		{
       
   278 		iTest.Printf(_L("Cannot auto run tests as test ranges not implemented\n"));
       
   279 		iTest.Printf(_L("Press a key when ready\n"));
       
   280 		iTest.Console()->Getch();
       
   281 		return ETrue;
       
   282 		}
       
   283 
       
   284 	// Check that the method number is correct
       
   285 	RunTestsL(EFalse, EBatch, numMethods, leaveCode, 0, 0);
       
   286 
       
   287 	if (aStartMethodNum == 0 || aStartMethodNum > numMethods)
       
   288 		{
       
   289 		iTest.Printf(_L("Bad method number: %d - Needs to be in range 1 to %d\n"),
       
   290 					aStartMethodNum, numMethods);
       
   291 		iTest.Printf(_L("Press a key when ready\n"));
       
   292 		iTest.Console()->Getch();
       
   293 		return ETrue;
       
   294 		}
       
   295 	if (aEndMethodNum == 0 || aEndMethodNum > numMethods)
       
   296 		{
       
   297 		iTest.Printf(_L("Bad method number: %d - Needs to be in range 1 to %d\n"),
       
   298 					aEndMethodNum, numMethods);
       
   299 		iTest.Printf(_L("Press a key when ready\n"));
       
   300 		iTest.Console()->Getch();
       
   301 		return ETrue;
       
   302 		}
       
   303 	if (aEndMethodNum == -1)
       
   304 		aEndMethodNum = numMethods;
       
   305 
       
   306 	for (TInt methodIndex = aStartMethodNum; methodIndex <= aEndMethodNum; methodIndex++)
       
   307 		{
       
   308 		TInt testIndex;
       
   309 
       
   310 		if ((methodIndex < aEndMethodNum) || (aEndTestNum == -1))
       
   311 			{
       
   312 			// Get the number of automated tests for the current method
       
   313 			RunTestsL(EFalse, EBatch, numTests, leaveCode, methodIndex, 0);
       
   314 			}
       
   315 		else
       
   316 			{
       
   317 			// Finish on a specified test.
       
   318 			numTests = aEndTestNum;
       
   319 			}
       
   320 
       
   321 		if (methodIndex == aStartMethodNum)
       
   322 			testIndex = aStartTestNum;
       
   323 		else
       
   324 			testIndex = 1;
       
   325 
       
   326 		iTest.Printf(_L("Running tests %d to %d in method %d\n"),
       
   327 			testIndex, numTests, methodIndex);
       
   328 		for (; testIndex <= numTests; testIndex++)
       
   329 			{
       
   330 			errorCode = KErrNone;
       
   331 			leaveCode = KErrNone;
       
   332 
       
   333 			RunTestsL(EFalse, EBatch, errorCode, leaveCode, methodIndex, testIndex);
       
   334 
       
   335 			LogTestResult(errorCode, leaveCode, EFalse, methodIndex, testIndex, EBatch);
       
   336 			}
       
   337 		}
       
   338 
       
   339 	//LOGTEXT("<<DoTestsInSpecifiedRangeL");
       
   340 	return ETrue;
       
   341 	}
       
   342 
       
   343 TBool CUnitTestBase::DoAutoMethodsL()
       
   344 	{
       
   345 	//LOGTEXT(">>DoAutoMethodsL");
       
   346 
       
   347 	TInt numMethods;
       
   348 	TInt leaveCode;
       
   349 
       
   350 	if (! HasTestRangesDefined())
       
   351 		{
       
   352 		iTest.Printf(_L("Cannot auto run tests as test ranges not implemented\n"));
       
   353 		iTest.Printf(_L("Press a key when ready\n"));
       
   354 		iTest.Console()->Getch();
       
   355 		return ETrue;
       
   356 		}
       
   357 
       
   358 	// Get the number of automated tests for this method
       
   359 	RunTestsL(EFalse, EBatch, numMethods, leaveCode, 0, 0);
       
   360 
       
   361 	iFailedTests.Reset();
       
   362 	for (TInt methodIndex = 1; methodIndex <= numMethods; methodIndex++)
       
   363 		{
       
   364 		DoAutoMethodTestsL(methodIndex);
       
   365 		}
       
   366 
       
   367 	TInt failedCount = iFailedTests.Count();
       
   368 	if (   iRepeatFailedTests
       
   369 		&& failedCount > 0)
       
   370 		{
       
   371 		iTest.Printf(_L("%d tests failed. Will retry them now.\n"), failedCount);
       
   372 		iLogFile.Write(_L8("#--- Retrying the tests that failed ---\r\n"));
       
   373 		for (TInt i = 0; i < failedCount; i++)
       
   374 			{
       
   375 			TTestFailure theFailedTest = iFailedTests[i];
       
   376 			DoSingleTestL(theFailedTest.iMethodNum, theFailedTest.iTestIndex, EBatch);
       
   377 			}
       
   378 		}
       
   379 	iFailedTests.Reset();
       
   380 
       
   381 	//LOGTEXT("<<DoAutoMethodsL");
       
   382 	return ETrue;
       
   383 	}
       
   384 
       
   385 TBool CUnitTestBase::DoTestsL()
       
   386 /**
       
   387  * This function selects a unit test, runs it and then logs the result
       
   388  *
       
   389  * @return return a TBool
       
   390  * @retval ETrue if another test to run in interactive mode
       
   391  * @retval EFalse if the test is in batch mode or there is not another
       
   392  *         test to run in interactive mode
       
   393  */
       
   394 	{
       
   395 	TInt methodNum;
       
   396 	TInt testNum;
       
   397 	TInt endMethodNum;
       
   398 	TInt endTestNum;
       
   399 	TTestMode testMode = EBatch;
       
   400 	TBool exitTests;
       
   401 
       
   402 	TBool numOK = SelectTestL(methodNum, testNum,
       
   403 		endMethodNum, endTestNum, testMode, exitTests);
       
   404 
       
   405 	if (! numOK)
       
   406 		{
       
   407 		iTest.Printf(_L("Bad number entered\n"));
       
   408 		iTest.Printf(_L("Press a key when ready\n"));
       
   409 		iTest.Console()->Getch();
       
   410 		return ETrue;
       
   411 		}
       
   412 
       
   413 	if (exitTests)
       
   414 		{
       
   415 		return EFalse;
       
   416 		}
       
   417 
       
   418 	// Is this a manual test?
       
   419 	if ((testNum != -1) && ((endTestNum == -1) || (testMode == EInteractive)))
       
   420 		{
       
   421 		iTest.Printf(_L("Running single test %d-%d\n"), methodNum, testNum);
       
   422 		DoSingleTestL(methodNum, testNum, testMode);
       
   423 		return ETrue;
       
   424 		}
       
   425 
       
   426 	// Do we want to auto run all the tests for a specified method
       
   427 	if ((methodNum != -1) && (testNum == -1))
       
   428 		{
       
   429 		iTest.Printf(_L("Running all tests in method %d\n"), methodNum);
       
   430 		DoAutoMethodTestsL(methodNum);
       
   431 		return ETrue;
       
   432 		}
       
   433 
       
   434 	// Do we want to run tests from one index to another?
       
   435 	if (methodNum != -1)
       
   436 		{
       
   437 		iTest.Printf(_L("Running tests %d-%d to %d-%d\n"), methodNum, testNum, endMethodNum, endTestNum);
       
   438 		DoTestsInSpecifiedRangeL(methodNum, testNum, endMethodNum, endTestNum);
       
   439 		return ETrue;
       
   440 		}
       
   441 
       
   442 	// methodNum == -1 && testNum == -1 =>
       
   443 	// We want to all the tests for every method automatically
       
   444 	iTest.Printf(_L("Running all tests\n"));
       
   445 	return DoAutoMethodsL();
       
   446   	}
       
   447 
       
   448 TInt CUnitTestBase::PostTestDelayTime()
       
   449 /**
       
   450  * This virtual function can be overridden by derived tests to
       
   451  * configure the length of delay between running tests in
       
   452  * automated mode. This used to be hard coded to KTsyTestCompleteTime,
       
   453  * which was 3 seconds.
       
   454  *
       
   455  * With 100 tests, that adds up to 5 minutes of wasted time per run!
       
   456  */
       
   457 	{
       
   458 	return KTsyTestCompleteTime;
       
   459 	}
       
   460 
       
   461 void  CUnitTestBase::ActionNoMatch(TBool aEndInd,TTestMode aTestMode,
       
   462 								   TInt aApiNumber,TInt aTestNumber)
       
   463 /**
       
   464  * This function provides the default action for the case
       
   465  * when the test identified by the API and test number is
       
   466  * not implemented. It is to be called within RunTestsL()
       
   467  * in the default case of its switch statement
       
   468  */
       
   469 	{
       
   470 	if(!aEndInd)
       
   471 		{
       
   472 		iTest.Printf(_L("** Not implemented CSY%S-%d-%d yet **\n"),
       
   473 			         &iUnitTestName,aApiNumber,aTestNumber);
       
   474 		if(aTestMode==EInteractive)
       
   475 			{
       
   476 			iTest.Printf(_L("press any key to continue\n"));
       
   477 			iTest.Console()->Getch();
       
   478 			}
       
   479 		}
       
   480 	}
       
   481 
       
   482 TInt CUnitTestBase::CompareTestResult
       
   483 (TInt aExpectedResult,TRequestStatus aStatus)
       
   484 /**
       
   485  * This function compare the test result with the expected one
       
   486  *
       
   487  * @param aStatus stores the result of a client API request
       
   488  *
       
   489  */
       
   490 	{
       
   491 	TInt ret=KErrNone;
       
   492 	if (aStatus.Int() != aExpectedResult)
       
   493 		{
       
   494 		if(aStatus==KErrNone)
       
   495 			ret=__LINE__;
       
   496 		else
       
   497 			ret=aStatus.Int();
       
   498 		}
       
   499 	return ret;
       
   500 	}
       
   501 
       
   502 void  CUnitTestBase::LogTestResult(TInt aErrCode, TInt aLeaveCode,
       
   503 								   TBool aEndInd,TInt aApiNumber,
       
   504 								   TInt aTestNumber,TTestMode aTestMode)
       
   505 /**
       
   506  * This function logs the test result
       
   507  */
       
   508 	{
       
   509 	TInt err=KErrNone;
       
   510 	if ((aErrCode)||(aLeaveCode))
       
   511 		{
       
   512 		if (aLeaveCode)
       
   513 			{
       
   514 			iTest.Printf(_L("Test failed with a LEAVE: CSY%S-%d-%d\n"),
       
   515 				         &iUnitTestName,aApiNumber,aTestNumber);
       
   516 			err=aLeaveCode;
       
   517 			}
       
   518 		else
       
   519 			{
       
   520 			iTest.Printf(_L("FAILURE: CSY%S-%d-%d failed with %d\n"),
       
   521 				         &iUnitTestName,aApiNumber,aTestNumber,aErrCode);
       
   522 			err=aErrCode;
       
   523 			}
       
   524 
       
   525 		//Print out test results in Symbian's requested format
       
   526 		TUint count=iFunIndices.Count();
       
   527 		for(TUint i = 0; i < count; i++)
       
   528 			WriteLog(EFalse,iFunIndices[i],aApiNumber,aTestNumber,err);
       
   529 		iFunIndices.Reset();
       
   530 
       
   531 		if (aTestMode==EInteractive)
       
   532 			{
       
   533 			iTest.Printf(_L("press any key to continue\n"));
       
   534 			iTest.Console()->Getch();
       
   535 			}
       
   536 		}
       
   537 	else
       
   538 		{
       
   539 		//these code will not be run if a user type E or e
       
   540 		//to end running the tests in interactive mode
       
   541 		if (!aEndInd)
       
   542 			{
       
   543 			iTest.Printf(_L("CSY%S-%d-%d finished successfully\n"),
       
   544 				         &iUnitTestName,aApiNumber,aTestNumber);
       
   545 
       
   546 #ifndef LOG_FAILED_TESTS_ONLY
       
   547 			//Print out test results in Symbian's requested format
       
   548 			TUint count=iFunIndices.Count();
       
   549 			for(TUint i = 0; i < count; i++)
       
   550 				WriteLog(ETrue,iFunIndices[i],aApiNumber,aTestNumber,err);
       
   551 			iFunIndices.Reset();
       
   552 #endif
       
   553 			iTest.Printf(_L("Waiting briefly for system to close\n"));
       
   554 
       
   555 			// give some time for test to complete
       
   556 //			User::After(this->PostTestDelayTime());
       
   557 			}
       
   558 		}
       
   559 	}
       
   560 
       
   561 
       
   562 TBool CUnitTestBase::UserSelectionL(TChar aMainNumber,
       
   563 									TInt aNumMethods,
       
   564 									TBool aRangeSpecified,
       
   565 									TInt& aApiNum, TInt& aTestNum,
       
   566 								    TTestMode& aTestMode)
       
   567 	{
       
   568 	TInt leaveCode  = 0;
       
   569 	aApiNum = UserChoice(aMainNumber);
       
   570 
       
   571 	if (aApiNum == -1) return EFalse;
       
   572 
       
   573 	if (aNumMethods != -1 && (aApiNum < 1 || aApiNum > aNumMethods))
       
   574 		{
       
   575 		aApiNum = -1;
       
   576 		aTestNum  = -1;
       
   577 		return EFalse;
       
   578 		}
       
   579 
       
   580 	PrintTestDetails(aApiNum);
       
   581 
       
   582 	TInt numAutoTests   = -1;
       
   583 	TInt numManualTests = -1;
       
   584 
       
   585 	if (! HasTestRangesDefined())
       
   586 		iTest.Printf(_L("Test number:"));
       
   587 	else
       
   588 		{
       
   589 		RunTestsL(EFalse, EBatch, numAutoTests, leaveCode, aApiNum, 0);
       
   590 		RunTestsL(EFalse, EBatch, numManualTests, leaveCode, aApiNum, 100);
       
   591 
       
   592 		iTest.Printf(_L("There are %d auto and %d manual tests\n"),
       
   593 											numAutoTests, numManualTests);
       
   594 		if (aRangeSpecified)
       
   595 			iTest.Printf(_L("Range test number:"));
       
   596 		else
       
   597 			iTest.Printf(_L("Test number or 'A' for all tests:"));
       
   598 		}
       
   599 
       
   600 	TChar numberKey = iTest.Console()->Getch();
       
   601 	iTest.Printf(_L("\n"));
       
   602 
       
   603 	if ((!aRangeSpecified) && HasTestRangesDefined() && ((numberKey == 'A')||(numberKey == 'a')))
       
   604 		{
       
   605 		aTestMode = EBatch;
       
   606 		aTestNum  = -1;
       
   607 		return ETrue;
       
   608 		}
       
   609 
       
   610 	aTestNum = UserChoice(numberKey);
       
   611 
       
   612 	if (aTestNum == -1) return EFalse;
       
   613 
       
   614 	TBool ret = EFalse;
       
   615 
       
   616 	if (! HasTestRangesDefined())
       
   617 		ret = ETrue;
       
   618 
       
   619 	if (aTestNum > 0 && aTestNum <= numAutoTests)
       
   620 		ret = ETrue;
       
   621 
       
   622 	if (aTestNum > 100 && aTestNum <= (100+numManualTests))
       
   623 		ret = ETrue;
       
   624 
       
   625 	return ret;
       
   626 	}
       
   627 
       
   628 TBool CUnitTestBase::SelectTestL(TInt& aApiNum, TInt& aTestNum,
       
   629 								 TInt& aEndApiNum, TInt& aEndTestNum,
       
   630 								 TTestMode& aTestMode, TBool& aExit)
       
   631 /**
       
   632  * This function selects a unit test which is identified by its API &
       
   633  * test numbers to be run either in batch or interactive mode
       
   634  *
       
   635  * @return return a TBool to indicate whether or not to end the test in
       
   636  *         interactive mode
       
   637  */
       
   638 	{
       
   639 	aTestMode = EBatch;
       
   640 	aExit     = EFalse;
       
   641 
       
   642 	iTest.Console()->ClearScreen();
       
   643 
       
   644 	if (CommandLineL(aApiNum, aTestNum, aEndApiNum, aEndTestNum))
       
   645 		{
       
   646 		aTestMode = EBatch;
       
   647 		iExitAfterTestsComplete = ETrue;
       
   648 
       
   649 		// we have got the numbers from the command line
       
   650 		iTest.Printf(_L("Running %S automated API tests\n"),&iUnitTestName);
       
   651 
       
   652 		// give tester time to get up and running
       
   653 		User::After(KTsyTesterSetupTime);
       
   654 		return ETrue;
       
   655 		}
       
   656 
       
   657 	// need to get numbers from the user
       
   658 	iTest.Printf(_L("Running %S API Tests - interactively\n"), &iUnitTestName);
       
   659 
       
   660 	aTestMode = EInteractive;
       
   661 
       
   662 	// helper to aid user - which identifier relates to which number
       
   663 	PrintTestSpecIdentifiers();
       
   664 
       
   665 	TInt numMethods = -1;
       
   666 	TInt leaveCode  = 0;
       
   667 	TBool rangeSpecified = EFalse;
       
   668 
       
   669 	// Get the numbers
       
   670 	if (! HasTestRangesDefined())
       
   671 		iTest.Printf(_L("\nNumber or 'S' for specific test or 'E' to end:"));
       
   672 	else
       
   673 		{
       
   674 		RunTestsL(EFalse, EBatch, numMethods, leaveCode, 0, 0);
       
   675 		iTest.Printf(_L("\nNumber or 'S' for specific test, 'R' for range, 'A' for all or 'E' to end:"), numMethods);
       
   676 		}
       
   677 
       
   678 	TChar numberKey = iTest.Console()->Getch();
       
   679 	iTest.Printf(_L("\n"));
       
   680 
       
   681 	if (!numberKey.IsDigit())
       
   682 		{
       
   683 		switch (numberKey)
       
   684 			{
       
   685 		case 'E':
       
   686 		case 'e':
       
   687 			aExit = ETrue;
       
   688 			return ETrue;
       
   689 		case 'A':
       
   690 		case 'a':
       
   691 			{
       
   692 			if (HasTestRangesDefined())
       
   693 				{
       
   694 				aTestMode = EBatch;
       
   695 				aApiNum   = -1;
       
   696 				aTestNum  = -1;
       
   697 				return ETrue;
       
   698 				}
       
   699 			}
       
   700 			return EFalse;
       
   701 		case 'R':
       
   702 		case 'r':
       
   703 			{
       
   704 			if (HasTestRangesDefined())
       
   705 				{
       
   706 				aTestMode = EBatch;
       
   707 				iTest.Printf(_L("Enter Start Method of range (1 -> %d):"), numMethods);
       
   708 				numberKey = iTest.Console()->Getch();
       
   709 				rangeSpecified = ETrue;
       
   710 				}
       
   711 			else
       
   712 				return EFalse;
       
   713 			}
       
   714 			break;
       
   715 		case 'S':
       
   716 		case 's':
       
   717 			{
       
   718 			iTest.Printf(_L("Method to test (1 -> %d):"), numMethods);
       
   719 			numberKey = iTest.Console()->Getch();
       
   720 			}
       
   721 			break;
       
   722 		default:
       
   723 			iTest.Printf(_L("Incorrect value\n"));
       
   724 			return EFalse;
       
   725 			}
       
   726 		}
       
   727 
       
   728 	// User to select test case or start of range
       
   729 	TBool ret = UserSelectionL(numberKey, numMethods, rangeSpecified,
       
   730 		aApiNum, aTestNum, aTestMode);
       
   731 
       
   732 	if (ret && rangeSpecified)
       
   733 		{
       
   734 		PrintTestSpecIdentifiers();
       
   735 
       
   736 		iTest.Printf(_L("Enter end method of range (1 -> %d) or 'L' last"), numMethods);
       
   737 		numberKey = iTest.Console()->Getch();
       
   738 		iTest.Printf(_L("\n"));
       
   739 
       
   740 		if ((numberKey == 'L')||(numberKey == 'l'))
       
   741 			{
       
   742 			aTestMode = EBatch;
       
   743 			aEndApiNum   = -1;
       
   744 			aEndTestNum  = -1;
       
   745 			return ETrue;
       
   746 			}
       
   747 
       
   748 		// User to select end of range
       
   749 		ret = UserSelectionL(numberKey, numMethods, ETrue,
       
   750 			aEndApiNum, aEndTestNum, aTestMode);
       
   751 		}
       
   752 
       
   753 	return ret;
       
   754 	}
       
   755 
       
   756 TInt  CUnitTestBase::UserChoice(TChar aNumberKey)
       
   757 /**
       
   758  * This function gets the number equivalent to the user's keyboard input
       
   759  * and will return once the enter key is pressed
       
   760  *
       
   761  * @param  aNumberKey is a key pressed by the user
       
   762  * @return return the number equivalent to the user's keyboard input
       
   763  */
       
   764 	{
       
   765 	TInt choice=0;
       
   766 	TInt mult=1;
       
   767 
       
   768 	while ( STATIC_CAST(TInt,aNumberKey) != EKeyEnter )
       
   769 		{
       
   770 		// If the user pressed Backspace, delete the previous number.
       
   771 		if (aNumberKey == 0x8)
       
   772 			{
       
   773 			if (choice > 0)
       
   774 				{
       
   775 				iTest.Printf(_L("%c %c"), aNumberKey, aNumberKey);
       
   776 				choice /= 10;
       
   777 				if (choice == 0)
       
   778 					mult = 1;
       
   779 				}
       
   780 			}
       
   781 
       
   782 		if (!aNumberKey.IsDigit())
       
   783 			{
       
   784 			aNumberKey = iTest.Console()->Getch();
       
   785 			continue;
       
   786 			}
       
   787 
       
   788 		TInt val = aNumberKey.GetNumericValue();
       
   789 		iTest.Printf(_L("%d"),val) ;
       
   790 		choice = (choice * mult) + val;
       
   791 		if(mult==1)
       
   792 			mult *=  10;
       
   793 		aNumberKey = iTest.Console()->Getch() ;
       
   794 		}
       
   795 
       
   796 	iTest.Printf(_L("\n")) ;
       
   797 	return choice;
       
   798 	}
       
   799 
       
   800 TBool CUnitTestBase::CommandLineL(TInt& aApiNum, TInt& aTestNum,
       
   801 								  TInt& aEndApiNum, TInt& aEndTestNum)
       
   802 /**
       
   803  * This function takes inputs from command lines in the batch file run_me.bat
       
   804  */
       
   805 	{
       
   806 	aApiNum = 0;
       
   807 	aTestNum = 0;
       
   808 
       
   809 	TInt commandLineLength;
       
   810 #ifndef BUILD_FOR_JETSTREAM
       
   811 	commandLineLength = User::CommandLineLength();
       
   812 #else
       
   813 	RProcess eteltest;
       
   814 	commandLineLength = eteltest.CommandLineLength();
       
   815 #endif // BUILD_FOR_JETSTREAM
       
   816 
       
   817 	if (commandLineLength > 0)
       
   818 		{
       
   819 		HBufC* argv = HBufC::NewLC(commandLineLength);
       
   820 		TPtr cmd(argv->Des());
       
   821 
       
   822 #ifndef BUILD_FOR_JETSTREAM
       
   823 		User::CommandLine(cmd);
       
   824 #else
       
   825 		eteltest.CommandLine(cmd);
       
   826 #endif // BUILD_FOR_JETSTREAM
       
   827 
       
   828 		TLex argParser(*argv);
       
   829 
       
   830 		TInt argc = 0;
       
   831 		while (argParser.NextToken().Length()) argc++;
       
   832 		if ((argc < 2) || (argc > 4))
       
   833 			{
       
   834 			iTest.Console()->Printf(_L("Usage: <app> <api num> <test num> [<end api> <end test>]\n"));
       
   835 			return EFalse;
       
   836 			}
       
   837 
       
   838 		argParser.UnGetToMark(); //Returns to the beginning of argv.
       
   839 		argParser.SkipSpace();
       
   840 
       
   841 		argParser.Val(aApiNum);
       
   842 		argParser.SkipSpace();
       
   843 		argParser.Val(aTestNum);
       
   844 
       
   845 		if (argc == 4)
       
   846 			{
       
   847 			argParser.SkipSpace();
       
   848 			argParser.Val(aEndApiNum);
       
   849 			argParser.SkipSpace();
       
   850 			argParser.Val(aEndTestNum);
       
   851 			}
       
   852 		else
       
   853 			{
       
   854 			aEndApiNum = aApiNum;
       
   855 			aEndTestNum = aTestNum;
       
   856 			}
       
   857 
       
   858 		delete argv;
       
   859 		CleanupStack::Pop();//argv
       
   860 
       
   861 		// we did find some command line params
       
   862 		return ETrue;
       
   863 		}
       
   864 	return EFalse;
       
   865 	}
       
   866 
       
   867 TInt CUnitTestBase::WriteLog(TBool aIsPassed,TUint aFunIndex,TUint aApiNum,
       
   868 		                     TUint aTstNum, TInt aErrorCode)
       
   869 /**
       
   870  * This function write test result to log in the folowing formats:
       
   871  * AUTO;<DATE>;<TIME>;UTS;<TS-Identifier>;<Functionality-Index>;
       
   872  * PASSED;<Test-Script>;<Method-In-Test-Script>;
       
   873  * or
       
   874  * AUTO;<DATE>;<TIME>;UTS;<TS-Identifier>;<Functionality-Index>;
       
   875  * FAILED;<Test-Script>;<Method-In-Test-Script>;<ErrorCode>
       
   876  */
       
   877 	{
       
   878 	//Get date & time
       
   879 	TTime time;
       
   880 	TDateTime dateTime;
       
   881 	time.HomeTime();
       
   882 	dateTime=time.DateTime();
       
   883 	TUint year = dateTime.Year();
       
   884 	TUint day = dateTime.Day() + 1;//Day() & Month() starts from 0
       
   885 	TUint month = dateTime.Month() + 1;
       
   886 	TUint hour = dateTime.Hour();
       
   887 	TUint minute = dateTime.Minute();
       
   888 	TUint second = dateTime.Second();
       
   889 
       
   890 	//Prepared the PASSED/FAILED field
       
   891 	TBuf8<KBufSize10> passedOrFailed;
       
   892 	if(aIsPassed)
       
   893 		passedOrFailed.Copy(KPassed);
       
   894 	else
       
   895 		passedOrFailed.Copy(KFailed);
       
   896 
       
   897 	TBuf8<KMaxName> testResult;
       
   898 
       
   899 	testResult.Copy(KAutoTestMarker);//AUTO;
       
   900 
       
   901 	//<DATE>;<TIME>;
       
   902 	TBuf8<KBufSize25> dateTimeField;
       
   903 	FormDateTimeBit(dateTimeField,day,ETrue,ETrue);
       
   904 	FormDateTimeBit(dateTimeField,month,ETrue,ETrue);
       
   905 	FormDateTimeBit(dateTimeField,year,ETrue,EFalse);
       
   906 	FormDateTimeBit(dateTimeField,hour,EFalse,ETrue);
       
   907 	FormDateTimeBit(dateTimeField,minute,EFalse,ETrue);
       
   908 	FormDateTimeBit(dateTimeField,second,EFalse,EFalse);
       
   909 	testResult.Append(dateTimeField);
       
   910 
       
   911 	testResult.Append(iTestSpecName);//UTS;
       
   912 
       
   913 	//<TS-Identifier>;
       
   914 	testResult.Append(iTsIdentifier);
       
   915 	testResult.Append(KSemiColon);
       
   916 
       
   917 	//<Functionality-Index>;
       
   918 	TBuf8<KBufSize25> buf;
       
   919 	buf.Num(aFunIndex);
       
   920 	buf.Append(KSemiColon);
       
   921 	testResult.Append(buf);
       
   922 
       
   923 	//PASSED/FAILED;
       
   924 	testResult.Append(passedOrFailed);
       
   925 
       
   926 	//<Test-Script>;
       
   927 	testResult.Append(iTestScriptName);
       
   928 
       
   929 	//<Method-In-Test-Script>
       
   930 	TBuf8<KBufSize100> bufMethodWithId;
       
   931 	bufMethodWithId.Copy(iMethodName);
       
   932 	bufMethodWithId.Append(KHyphen);
       
   933 	buf.Num(aApiNum);
       
   934 	buf.Append(KHyphen);
       
   935 	bufMethodWithId.Append(buf);
       
   936 	buf.Num(aTstNum);
       
   937 	buf.Append(KSemiColon);
       
   938 	bufMethodWithId.Append(buf);
       
   939 	testResult.Append(bufMethodWithId);
       
   940 
       
   941 	if(!aIsPassed)
       
   942 		{
       
   943 		buf.Num(aErrorCode);
       
   944 		testResult.Append(buf);
       
   945 		}
       
   946 	testResult.Append(KNewLine);
       
   947 
       
   948 	TInt err = iLogFile.Write(testResult);
       
   949 	iLogFile.Flush();
       
   950 
       
   951 	return err;
       
   952 	}
       
   953 
       
   954 void CUnitTestBase::FormDateTimeBit(TDes8& aDateTimeField,TUint aDateTimeBit,
       
   955 		                            TBool aIsDateSepa,TBool aAddSepa)
       
   956 /**
       
   957  * Append a date/time bit(month & hour etc.) and separator or delimiter
       
   958  * into the dateTimeField descriptor
       
   959  */
       
   960 	{
       
   961 	TBuf8<KBufSize1> separator;//- or :
       
   962 	TBuf8<KBufSize4> buf;//year takes 4 digits, the rest takes two digits
       
   963 	if(aIsDateSepa)
       
   964 		separator.Copy(KHyphen);
       
   965 	else
       
   966 		separator.Copy(KColon);
       
   967 	if(aDateTimeBit < KZeroPadValue)
       
   968 		aDateTimeField.Append(KZeroPadding);
       
   969 	buf.Num(aDateTimeBit);
       
   970 	aDateTimeField.Append(buf);
       
   971 	if(aAddSepa)
       
   972 		aDateTimeField.Append(separator);
       
   973 	else
       
   974 		aDateTimeField.Append(KSemiColon);
       
   975 	}
       
   976 
       
   977 
       
   978 TInt CUnitTestBase::LoadComms()
       
   979 /**
       
   980  *
       
   981  */
       
   982 	{
       
   983 	// connect to C32
       
   984 	TInt ret = iCommServer.Connect();
       
   985 	if (ret)
       
   986 		{
       
   987 		return ret;
       
   988 		}
       
   989 	return ret;
       
   990 	}
       
   991 
       
   992 TInt CUnitTestBase::UnloadComms()
       
   993 /**
       
   994  *
       
   995  */
       
   996 	{
       
   997 	iCommServer.Close();
       
   998 	
       
   999 	return (KErrNone);
       
  1000 	}
       
  1001 
       
  1002 void CUnitTestBase::ReadStr(TDes& aDes)
       
  1003 	{
       
  1004 	TChar inputKey;
       
  1005 	TInt count = 0;
       
  1006 	const TInt KMaxLength = aDes.MaxLength();
       
  1007 
       
  1008 	aDes.Zero();
       
  1009 	for (;;)
       
  1010 		{
       
  1011 		inputKey = (TInt) iTest.Getch();
       
  1012 
       
  1013 		if ((TInt)inputKey == EKeyEnter)
       
  1014 			{
       
  1015 			iTest.Printf(_L("\n"));
       
  1016 			break;
       
  1017 			}
       
  1018 
       
  1019 		if (inputKey == EKeyBackspace)
       
  1020 			{
       
  1021 			if (count > 0)
       
  1022 				{
       
  1023 				iTest.Printf(_L("%c"), inputKey);
       
  1024 				aDes.Delete(--count,1);
       
  1025 				}
       
  1026 			}
       
  1027 		else if (inputKey.IsPrint() && count < KMaxLength)
       
  1028 			{
       
  1029 			iTest.Printf(_L("%c"), inputKey);
       
  1030 			aDes.Append(inputKey);
       
  1031 			count++;
       
  1032 			}
       
  1033 		}
       
  1034 	}
       
  1035 
       
  1036 void CUnitTestBase::GetCompilationDate(TInt& aDay, TInt& aMonth, TInt& /*aYear*/)
       
  1037 	{
       
  1038 	// The __DATE__ string is guaranteed to be of the form "Mmm dd yyyy"
       
  1039 	// eg. Sep  9 2002
       
  1040 
       
  1041 	const TUint8* KMonthNames[] = {
       
  1042 		_S8("Jan"), _S8("Feb"), _S8("Mar"), _S8("Apr"), _S8("May"), _S8("Jun"),
       
  1043 		_S8("Jul"), _S8("Aug"), _S8("Sep"), _S8("Oct"), _S8("Nov"), _S8("Dec") };
       
  1044 	const TUint8 KDateString[] = __DATE__;
       
  1045 	const TPtrC8 KMonth(KDateString, 3);
       
  1046 	const TPtrC8 KDay(KDateString + 4, 2);
       
  1047 	const TPtrC8 KYear(KDateString + 7, 4);
       
  1048 
       
  1049 	TLex8 lex(KDay);
       
  1050 	lex.SkipSpaceAndMark();
       
  1051 	//kmif (lex.Val(aDay)) PANIC(10000);
       
  1052 	aDay--;               // get a zero based day for compatibility with TDateTime
       
  1053 	lex.Assign(KYear);
       
  1054 	//kmif (lex.Val(aYear)) PANIC(10000);
       
  1055 
       
  1056 	aMonth = KErrNotFound;
       
  1057 	for (TInt i = 0; i < 12; i++)
       
  1058 		{
       
  1059 		TPtrC8 month(KMonthNames[i], 3);
       
  1060 		if (month == KMonth) aMonth = i;
       
  1061 		}
       
  1062 
       
  1063 	//kmif (aMonth < 0) PANIC(10000);
       
  1064 	//kmif (aMonth > 11) PANIC(10000);
       
  1065 	}
       
  1066 
       
  1067 void CUnitTestBase::EnsureTargetDeviceClockIsSet()
       
  1068 	{
       
  1069 	TTime now;
       
  1070 	now.HomeTime();
       
  1071 	TDateTime date = now.DateTime();
       
  1072 
       
  1073 	TInt month, dayInMonth, year;
       
  1074 	GetCompilationDate(dayInMonth, month, year);
       
  1075 
       
  1076 	//LOGTEXT4("day %d  month %d  year %d", dayInMonth, month, year);
       
  1077 
       
  1078 	// If boards current date is later than our compilation year, just return
       
  1079 	if (   date.Year() >= year
       
  1080 		&& date.Month() >= month
       
  1081 		&& date.Day() >= dayInMonth)
       
  1082 		{
       
  1083 		return;
       
  1084 		}
       
  1085 
       
  1086 	const TInt KCompiledYear = year;
       
  1087 	for (;;)
       
  1088 		{
       
  1089 		iTest.Printf(_L("Enter date as DD MM YYYY (year is optional, defaults to %d) "), year);
       
  1090 
       
  1091 		TBuf<12> input;
       
  1092 		TBuf8<12> input8;
       
  1093 		ReadStr(input);
       
  1094 		input.TrimAll();
       
  1095 		input8.Copy(input);
       
  1096 
       
  1097 		TLex8 lex(input8);
       
  1098 
       
  1099 		lex.Val(dayInMonth);
       
  1100 		lex.SkipSpaceAndMark();
       
  1101 		lex.Val(month);
       
  1102 		lex.SkipSpaceAndMark();
       
  1103 		lex.Val(year); // if no year entered, this just returns error - year is unchanged
       
  1104 
       
  1105 		TInt err;
       
  1106 		err = date.SetYear(year);
       
  1107 		if (!err) err = date.SetMonth(static_cast<TMonth>(month-1));
       
  1108 		if (!err) err = date.SetDay(dayInMonth-1);
       
  1109 		if (!err && year < KCompiledYear) err = KErrNotReady;
       
  1110 
       
  1111 		if (err == KErrNone)
       
  1112 			{
       
  1113 			break; // loop termination condition
       
  1114 			}
       
  1115 		else
       
  1116 			{
       
  1117 			iTest.Printf(_L("Does not appear to be a correctly formatted date, try again.\n"));
       
  1118 			month = 0;
       
  1119 			dayInMonth = 0;
       
  1120 			year = KCompiledYear;
       
  1121 			}
       
  1122 		}
       
  1123 
       
  1124 	// Refresh the other time values
       
  1125 	now.HomeTime();
       
  1126 	date = now.DateTime();
       
  1127 	// Now restore the user-entered values
       
  1128 	date.SetYear(year);
       
  1129 	date.SetMonth(static_cast<TMonth>(month-1));
       
  1130 	date.SetDay(dayInMonth-1);
       
  1131 	User::SetHomeTime(date);
       
  1132 	}
       
  1133 
       
  1134 void CUnitTestBase::RunUnitTestsL()
       
  1135 /**
       
  1136  * This function is called within CreateTestL(), which is a
       
  1137  * static member function of CUnitTestBase derived classes,  to run
       
  1138  * the unit tests for the appropriate module
       
  1139  */
       
  1140 	{
       
  1141 	// load the CSY
       
  1142 	iTest(LoadComms() == KErrNone);
       
  1143 
       
  1144 #ifdef __EPOC32__
       
  1145 //	EnsureTargetDeviceClockIsSet();
       
  1146 #endif
       
  1147 
       
  1148 	// do test sequence
       
  1149 	TBool noEnd = ETrue;
       
  1150 	while(noEnd)
       
  1151 		{
       
  1152 		noEnd = DoTestsL();
       
  1153 		if (iExitAfterTestsComplete)
       
  1154 			noEnd = EFalse;
       
  1155 		}
       
  1156 
       
  1157 	// unload the CSY
       
  1158 	iTest(UnloadComms() == KErrNone);
       
  1159 	}
       
  1160 
       
  1161 TInt CUnitTestBase::SetUpTest()
       
  1162 /**
       
  1163  * This function is called within CreateTestL(), which is a
       
  1164  * static member function of CUnitTestBase derived classes,
       
  1165  * to load drivers & start C32
       
  1166  *
       
  1167  * If you want to give an 'opening page' of instructions for your unit test,
       
  1168  * override this and do so. Remember to base call! See DataUnitTest for an
       
  1169  * example.
       
  1170  *
       
  1171  * @return return an error code if set up fails
       
  1172  */
       
  1173 	{
       
  1174 	iTest.Title();
       
  1175 
       
  1176 	iTest.Start(_L("Loading Serial drivers\n"));
       
  1177 
       
  1178 	TInt r;
       
  1179 
       
  1180 #if defined (__WINS__)
       
  1181 	r = User::LoadPhysicalDevice(PDD_NAME);
       
  1182     r = User::LoadLogicalDevice(LDD_NAME);
       
  1183 
       
  1184 //taproot: tushar commented for OMAP
       
  1185 //#else  // __GCC32__ 
       
  1186 //	r = User::LoadPhysicalDevice(PDD_SIR_NAME);
       
  1187 //	r = User::LoadPhysicalDevice(PDD_UART_NAME);
       
  1188 //  r = User::LoadLogicalDevice(LDD_NAME);
       
  1189 #endif
       
  1190 
       
  1191 	r = StartC32();
       
  1192 	if ((r != KErrNone) && (r != KErrAlreadyExists))
       
  1193 		iTest.Printf(_L("Failed to start C32 %d\n"), r);
       
  1194 
       
  1195 	return KErrNone;
       
  1196 	}
       
  1197 
       
  1198 void CUnitTestBase::PrintTestSpecIdentifiers()
       
  1199 	{
       
  1200 	// This version prints no helpful info on the screen. Overload this in
       
  1201 	// your own test class to put out test identifier and number of API test
       
  1202 	}
       
  1203 
       
  1204 void CUnitTestBase::PrintTestDetails(TInt /*aTstSpecNumber*/)
       
  1205 	{
       
  1206 	// This version prints no helpful info on the screen. Overload this in
       
  1207 	// your own test class to put out test details for the test spec idenifier
       
  1208 	// selected
       
  1209 	}
       
  1210 
       
  1211 void CUnitTestBase::SetFunIndex2(TUint aFunIndex1,TUint aFunIndex2)
       
  1212 	{
       
  1213 	iFunIndices.Insert(aFunIndex1,0);
       
  1214 	iFunIndices.Insert(aFunIndex2,1);
       
  1215 	}
       
  1216 
       
  1217 void CUnitTestBase::SetFunIndex3(TUint aFunIndex1,TUint aFunIndex2,
       
  1218 		                         TUint aFunIndex3)
       
  1219 	{
       
  1220 	iFunIndices.Insert(aFunIndex1,0);
       
  1221 	iFunIndices.Insert(aFunIndex2,1);
       
  1222 	iFunIndices.Insert(aFunIndex3,2);
       
  1223 	}
       
  1224 
       
  1225 void CUnitTestBase::SetFunIndex4(TUint aFunIndex1,TUint aFunIndex2,
       
  1226 		                         TUint aFunIndex3,TUint aFunIndex4)
       
  1227 	{
       
  1228 	iFunIndices.Insert(aFunIndex1,0);
       
  1229 	iFunIndices.Insert(aFunIndex2,1);
       
  1230 	iFunIndices.Insert(aFunIndex3,2);
       
  1231 	iFunIndices.Insert(aFunIndex4,3);
       
  1232 	}
       
  1233 
       
  1234 TInt CUnitTestBase::GetRequestOrTimeOut(TRequestStatus& aRequestStatus,
       
  1235 										TTimeIntervalMicroSeconds32 aTimeOut)
       
  1236 /**
       
  1237  * Acts exactly like User::WaitForRequest, except aTimeOut is a timeout period
       
  1238  * to give up waiting after.
       
  1239  * If the request times out, returns KErrTimedOut, otherwise returns KErrNone
       
  1240  * and aRequestStatus is completed as usual.
       
  1241  */
       
  1242 	{
       
  1243 	//LOGTEXT(">>GetRequestOrTimeOut");
       
  1244 
       
  1245 	RTimer timer;
       
  1246 	TRequestStatus timerRequest;
       
  1247 	timer.CreateLocal();
       
  1248 	timer.After(timerRequest, aTimeOut);
       
  1249 
       
  1250 	// Wait for the requestto complete or until we time out
       
  1251 	User::WaitForRequest(timerRequest, aRequestStatus);
       
  1252 
       
  1253 	// If timer is no longer pending => we have timed out
       
  1254 	if (timerRequest != KRequestPending)
       
  1255 		{
       
  1256 		//LOGTEXT("<<GetRequestOrTimeOut **** Timed out ****");
       
  1257 		return KErrTimedOut;
       
  1258 		}
       
  1259 
       
  1260 	timer.Cancel();
       
  1261 
       
  1262 	User::WaitForRequest(timerRequest);
       
  1263 
       
  1264 	//LOGTEXT2("<<GetRequestOrTimeOut [aRequestStatus=%d]",aRequestStatus);
       
  1265 	return KErrNone;
       
  1266 	}