os/ossrv/genericservices/httputils/Test/IpuTestUtils/IpuTestHarness.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/httputils/Test/IpuTestUtils/IpuTestHarness.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,657 @@
     1.4 +// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "IpuTestUtils.h"
    1.20 +#include <e32consf.h>
    1.21 +//
    1.22 +//	Constants
    1.23 +_LIT(KTestPanic, "IpuTestHarness");
    1.24 +const TInt KFailedTestsGranularity = 10;
    1.25 +const TInt KMaxLogEntrySize = 256;
    1.26 +
    1.27 +//
    1.28 +//	CIpuTestHarness
    1.29 +//
    1.30 +CIpuTestHarness::CIpuTestHarness(const TDesC& aTitle)
    1.31 +	: iTest(aTitle)
    1.32 +//
    1.33 +//	Default c'tor
    1.34 +	{
    1.35 +    LogRTestToFile(iTest);
    1.36 +	iTest.Title();
    1.37 +	iCanStartTest = ETrue;
    1.38 +	}
    1.39 +
    1.40 +CIpuTestHarness::~CIpuTestHarness()
    1.41 +//
    1.42 +//	D'tor
    1.43 +	{
    1.44 +	TTime endtime;
    1.45 +	endtime.UniversalTime();
    1.46 +
    1.47 +	// Do resource handle leak test?
    1.48 +	if (iDoResourceLeakTest)
    1.49 +		ResourceLeakTest();
    1.50 +
    1.51 +	//	End of tests - see if failed or ok
    1.52 +	if (iFailedTests->Count())
    1.53 +		{
    1.54 +		TestHarnessFailed();
    1.55 +		}
    1.56 +	else
    1.57 +		{
    1.58 +		TestHarnessComplete();
    1.59 +		}
    1.60 +
    1.61 +	iFailedTests->ResetAndDestroy();
    1.62 +	delete iFailedTests;
    1.63 +
    1.64 +	//	Log finish time
    1.65 +	TDateTime t = endtime.DateTime();
    1.66 +	LogIt(_L("Ended @ %d:%d:%d:%d"),t.Hour(),t.Minute(),t.Second(),t.MicroSecond());
    1.67 +	TTime difftime(endtime.Int64() - iStartTime.Int64());
    1.68 +	t = difftime.DateTime();
    1.69 +	LogIt(_L("Execution time %d:%d:%d:%d"),t.Hour(),t.Minute(),t.Second(),t.MicroSecond());
    1.70 +
    1.71 +	//	Close logs and test harness
    1.72 +	iFlogger.CloseLog();
    1.73 +	
    1.74 +	// iTest test harness performs UHEAP MARK/UNMARK check upon creation/destruction
    1.75 +	//   therefore, it must be destroyed last since it is created first in 
    1.76 +	//   CIpuTestHarness
    1.77 +	iTest.Close();
    1.78 +	}
    1.79 +
    1.80 +EXPORT_C CIpuTestHarness* CIpuTestHarness::NewLC(const TDesC& aTitle)
    1.81 +//
    1.82 +//	Static factory c'tor
    1.83 +	{
    1.84 +	CIpuTestHarness* self = new (ELeave) CIpuTestHarness(aTitle);
    1.85 +	CleanupStack::PushL(self);
    1.86 +	self->ConstructL(aTitle);
    1.87 +	return self;
    1.88 +	}
    1.89 +
    1.90 +EXPORT_C CIpuTestHarness* CIpuTestHarness::NewL(const TDesC& aTitle)
    1.91 +//
    1.92 +//	Static factiry c'tor
    1.93 +	{
    1.94 +	CIpuTestHarness* self = CIpuTestHarness::NewLC(aTitle);
    1.95 +	CleanupStack::Pop();
    1.96 +	return self;
    1.97 +	}
    1.98 +
    1.99 +void CIpuTestHarness::ConstructL(const TDesC& aTitle)
   1.100 +//
   1.101 +//	Non-trivial c'tor
   1.102 +	{
   1.103 +	//	Create iFailedTests
   1.104 +	iFailedTests = new (ELeave) CArrayPtrFlat<CTestInfo> (KFailedTestsGranularity);
   1.105 +
   1.106 +	//	Start up logging server connection
   1.107 +	TBuf<64> temp(aTitle);
   1.108 +	DefaultLogFileName(temp);
   1.109 +	CreateFlogger(temp, EFalse, EFalse);
   1.110 +
   1.111 +	iStartTime.UniversalTime();
   1.112 +	TDateTime t = iStartTime.DateTime();
   1.113 +	LogIt(_L("Started @ %d:%d:%d:%d"),t.Hour(),t.Minute(),t.Second(),t.MicroSecond());
   1.114 +
   1.115 +	// Find number of open resource handles
   1.116 +	TInt processHandleCount=0;
   1.117 +	RThread().HandleCount(processHandleCount,iStartHandleCount);
   1.118 +	}
   1.119 +
   1.120 +EXPORT_C void CIpuTestHarness::StartTestL(const TDesC& aName)
   1.121 +//
   1.122 +//	Logs start of test aName
   1.123 +	{
   1.124 +	if (iCanStartTest)
   1.125 +		{
   1.126 +		//  - increment test count
   1.127 +		++iTestCount;
   1.128 +		
   1.129 +		if (iTestMode == ETestModeNormal) // don't add this info when we are doing memory leak testing otherwise it
   1.130 +										  // would get leaked!
   1.131 +			{
   1.132 +
   1.133 +			//	Add this test to failed test list - set errorcode to zero
   1.134 +			CTestInfo* temp = CTestInfo::NewLC(aName, iTestCount, 0);
   1.135 +			iFailedTests->AppendL(temp);
   1.136 +			CleanupStack::Pop();	//	temp
   1.137 +
   1.138 +			//	Stop new test being started until this one has ended
   1.139 +			iTest.Start(aName);
   1.140 +			iCanStartTest = EFalse;
   1.141 +			}
   1.142 +
   1.143 +		
   1.144 +		TBuf<KMaxFileName + 4> buf;
   1.145 +		buf.Format(KTestStartingWithDesc, iTestCount, &aName);
   1.146 +		WriteComment(buf);
   1.147 +
   1.148 +		// Reset iStepNumber - start at 1
   1.149 +		iStepNumber = 1;
   1.150 +		}
   1.151 +	else
   1.152 +		{
   1.153 +		//	Panic client - bad usage - not allowed to nest tests
   1.154 +		Panic(EBadStartTest);
   1.155 +		}
   1.156 +	}
   1.157 +
   1.158 +EXPORT_C void CIpuTestHarness::NextStep(const TDesC& aStepName)
   1.159 +//
   1.160 +//	Logs the next step in a test - for informative use.
   1.161 +	{
   1.162 +	if (!iCanStartTest)
   1.163 +		{
   1.164 +		TBuf<KMaxFileName + 4> buf;
   1.165 +		buf.Format(KNextTestStepWithDesc, iTestCount, iStepNumber, &aStepName);
   1.166 +		WriteComment(buf);
   1.167 +		iTest.Next(aStepName);
   1.168 +		++iStepNumber;
   1.169 +		}
   1.170 +	else
   1.171 +		{
   1.172 +		//	Panic client - bad usage - test not started
   1.173 +		Panic(EBadStartTest);
   1.174 +		}
   1.175 +	}
   1.176 +
   1.177 +EXPORT_C void CIpuTestHarness::EndTest(TInt aErrorCode)
   1.178 +//
   1.179 +//	Logs end of test
   1.180 +	{
   1.181 +	if (!iCanStartTest)
   1.182 +		{
   1.183 +		if (iTestMode == ETestModeNormal)
   1.184 +			{
   1.185 +			//	Get ptr to this test's entry in failed list - will be the last entry
   1.186 +			TBuf<KMaxFileName + 4> buf;
   1.187 +			TInt index = iFailedTests->Count();
   1.188 +			CTestInfo* ptr = iFailedTests->At(--index);
   1.189 +			if (aErrorCode)
   1.190 +				{
   1.191 +				//	Set the error code
   1.192 +				ptr->SetErrorCode(aErrorCode);
   1.193 +				buf.Format(KTestFailed, iTestCount, aErrorCode);
   1.194 +				WriteComment(buf);
   1.195 +				}
   1.196 +			else
   1.197 +				{
   1.198 +				//	Remove entry from list of failed tests
   1.199 +				delete ptr;
   1.200 +				iFailedTests->Delete(index);
   1.201 +				}
   1.202 +			
   1.203 +			}
   1.204 +		//	Allow new test to start
   1.205 +		iTest.End();
   1.206 +		iCanStartTest = ETrue;
   1.207 +		}
   1.208 +	else
   1.209 +		{
   1.210 +		if (iTestMode == ETestModeNormal)
   1.211 +			//	Panic client - bad usage - test not started
   1.212 +			Panic(EBadEndTest);
   1.213 +		// don't panic when we are memory leak testing as EndTestL will never get called to reset the test properly
   1.214 +		}
   1.215 +	}
   1.216 +
   1.217 +EXPORT_C void CIpuTestHarness::LogIt(TRefByValue<const TDesC> aFmt, ...)
   1.218 +//
   1.219 +//	Messages to the front end emulator and to the Inu log
   1.220 +	{
   1.221 +	VA_LIST list;
   1.222 +	VA_START(list,aFmt);
   1.223 +
   1.224 +	TBuf<KMaxFileName + 4> buf;
   1.225 +	buf.Append(KTestCommentPrepend);
   1.226 +	buf.AppendFormatList(aFmt,list);
   1.227 +	VA_END(list);
   1.228 +
   1.229 +	WriteComment(buf);
   1.230 +	}
   1.231 +
   1.232 +EXPORT_C void CIpuTestHarness::operator()(TInt aResult,TInt aLineNum)
   1.233 +//
   1.234 +//	Overload operator ()
   1.235 +	{
   1.236 +	iTest(aResult, aLineNum);
   1.237 +	}
   1.238 +
   1.239 +EXPORT_C void CIpuTestHarness::operator()(TInt aResult)
   1.240 +//
   1.241 +//	Overload operator ()
   1.242 +	{
   1.243 +	iTest(aResult);
   1.244 +	}
   1.245 +
   1.246 +EXPORT_C void CIpuTestHarness::PressAnyKey()
   1.247 +//
   1.248 +//	Request a key press from user and wait - unless we are running a script
   1.249 +	{
   1.250 +	if (!iScriptRunning)
   1.251 +		{
   1.252 +		iTest.Printf(TRefByValue<const TDesC>_L("\nPress a key"));	
   1.253 +		iTest.Getch();
   1.254 +		}
   1.255 +	}
   1.256 +
   1.257 +EXPORT_C void CIpuTestHarness::DumpData(HBufC8& aData, TBool logIt)
   1.258 +//
   1.259 +//	Do a formatted dump of binary data, optionally logging it
   1.260 +	{
   1.261 +	// Iterate the supplied block of data in blocks of 16 bytes
   1.262 +	TInt pos = 0;
   1.263 +	TBuf<KMaxLogEntrySize> logLine;
   1.264 +	TBuf<KMaxLogEntrySize> anEntry;
   1.265 +	while (pos < aData.Length())
   1.266 +		{
   1.267 +		anEntry.Format(TRefByValue<const TDesC>_L("%04x : "), pos);
   1.268 +		logLine.Append(anEntry);
   1.269 +
   1.270 +		// Hex output
   1.271 +		TInt offset = 0;
   1.272 +		for (offset = 0; offset < 16; offset++)
   1.273 +			{
   1.274 +			if (pos + offset < aData.Length())
   1.275 +				{
   1.276 +				TInt nextByte = aData[pos + offset];
   1.277 +				anEntry.Format(TRefByValue<const TDesC>_L("%02x "), nextByte);
   1.278 +				logLine.Append(anEntry);
   1.279 +				}
   1.280 +			else
   1.281 +				{
   1.282 +				anEntry.Format(TRefByValue<const TDesC>_L("   "));
   1.283 +				logLine.Append(anEntry);
   1.284 +				}
   1.285 +			}
   1.286 +			anEntry.Format(TRefByValue<const TDesC>_L(": "));
   1.287 +			logLine.Append(anEntry);
   1.288 +
   1.289 +		// Char output
   1.290 +		for (offset = 0; offset < 16; offset++)
   1.291 +			{
   1.292 +			if (pos + offset < aData.Length())
   1.293 +				{
   1.294 +				TInt nextByte = aData[pos + offset];
   1.295 +				if ((nextByte >= 32) && (nextByte <= 127))
   1.296 +					{
   1.297 +					anEntry.Format(TRefByValue<const TDesC>_L("%c"), nextByte);
   1.298 +					logLine.Append(anEntry);
   1.299 +					}
   1.300 +				else
   1.301 +					{
   1.302 +					anEntry.Format(TRefByValue<const TDesC>_L("."));
   1.303 +					logLine.Append(anEntry);
   1.304 +					}
   1.305 +				}
   1.306 +			else
   1.307 +				{
   1.308 +				anEntry.Format(TRefByValue<const TDesC>_L(" "));
   1.309 +				logLine.Append(anEntry);
   1.310 +				}
   1.311 +			}
   1.312 +			if (logIt)
   1.313 +				{
   1.314 +				LogIt(TRefByValue<const TDesC>_L("%S"), &logLine);
   1.315 +				}
   1.316 +			else
   1.317 +				{
   1.318 +				iTest.Printf(TRefByValue<const TDesC>_L("%S\n"), &logLine);	
   1.319 +				}
   1.320 +			logLine.Zero();
   1.321 +
   1.322 +		// Advance to next 16 byte segment
   1.323 +		pos += 16;
   1.324 +		}
   1.325 +	}
   1.326 +
   1.327 +EXPORT_C void CIpuTestHarness::GetAnEntry(const TDesC& ourPrompt, TDes& currentstring)
   1.328 +//
   1.329 +//	Get an input string from the user, displaying a supplied prompt and default string value
   1.330 +	{
   1.331 +	// If we're scripting, try reading from script first
   1.332 +	TInt readScriptErr = KErrNotFound;
   1.333 +	if (iScriptRunning)
   1.334 +		{
   1.335 +		readScriptErr = ReadLineFromScript(currentstring);
   1.336 +		}
   1.337 +	if (!readScriptErr)
   1.338 +		return;
   1.339 +
   1.340 +	// Either not scripting, or hit end of script - continue with user input
   1.341 +	TBuf16<KMaxUserEntrySize> ourLine;
   1.342 +	TBuf<KMaxUserEntrySize> tempstring;				//tempstring is a unicode descriptor
   1.343 +										//create a temporary buffer where the
   1.344 +										//unicode strings are stored in order to 
   1.345 +										//be displayed
   1.346 +	ourLine.Zero ();
   1.347 +	tempstring.Copy(currentstring);		//Copy current string to Unicode buffer
   1.348 +	TKeyCode key = EKeyNull;						//current string buffer is 8 bits wide.
   1.349 +										//Unicode string bufffer (tempstring) is 16 bits wide.
   1.350 +	for (;;)
   1.351 +		{
   1.352 +		if (ourLine.Length () == 0)
   1.353 +			{
   1.354 +			iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
   1.355 +			iTest.Console()->Printf (_L ("%S"), &ourPrompt);
   1.356 +			if (tempstring.Length () != 0)						//get tempstring's number of items
   1.357 +				iTest.Console()->Printf (_L (" = %S"), &tempstring);	//if not zero print them to iTest.Console()
   1.358 +			iTest.Console()->Printf (_L (" : "));
   1.359 +			iTest.Console()->ClearToEndOfLine ();
   1.360 +			}
   1.361 +		key = iTest.Getch();
   1.362 +		
   1.363 +		  if (key == EKeyBackspace)
   1.364 +				{
   1.365 +					if (ourLine.Length() !=0)
   1.366 +					{
   1.367 +						ourLine.SetLength(ourLine.Length()-1);
   1.368 +						iTest.Console()->Printf (_L ("%c"), key);
   1.369 +						iTest.Console()->SetPos(iTest.Console()->WhereX(),iTest.Console()->WhereY());
   1.370 +						iTest.Console()->ClearToEndOfLine();
   1.371 +					}	// end if (ourLine.Length() !=0)
   1.372 +				}	// end if (key == KeyBackSpace)
   1.373 +		  
   1.374 +		  		  
   1.375 +		  if (key == EKeyDelete) 			
   1.376 +				{
   1.377 +					ourLine.Zero();
   1.378 +					iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
   1.379 +					iTest.Console()->ClearToEndOfLine ();
   1.380 +					tempstring.Copy(ourLine);
   1.381 +					break;
   1.382 +				}
   1.383 +		  
   1.384 +		  if (key == EKeyEnter)
   1.385 +			break;
   1.386 +		
   1.387 +		  if (key < 32)
   1.388 +			{
   1.389 +			continue;
   1.390 +			}
   1.391 +		
   1.392 +		ourLine.Append (key);
   1.393 +		iTest.Console()->Printf (_L ("%c"), key);
   1.394 +		iTest.Console()->SetPos(iTest.Console()->WhereX(),iTest.Console()->WhereY());
   1.395 +		iTest.Console()->ClearToEndOfLine();
   1.396 +		if (ourLine.Length () == ourLine.MaxLength ())
   1.397 +			break;
   1.398 +		}	// end of for statement
   1.399 +
   1.400 +	if ((key == EKeyEnter) && (ourLine.Length () == 0))
   1.401 +		tempstring.Copy (currentstring);				//copy contents of 8 bit "ourLine" descriptor
   1.402 +	
   1.403 +	iTest.Console()->SetPos (0, iTest.Console()->WhereY ());		
   1.404 +	iTest.Console()->ClearToEndOfLine ();
   1.405 +	iTest.Console()->Printf (_L ("%S"), &ourPrompt);
   1.406 +	
   1.407 +	if ((key == EKeyEnter) && (ourLine.Length() !=0))
   1.408 +		tempstring.Copy(ourLine);
   1.409 +	if (tempstring.Length () != 0)						//if temstring length is not zero
   1.410 +		{
   1.411 +		iTest.Console()->Printf (_L (" = %S\n"), &tempstring);	//print the contents to iTest.Console()
   1.412 +		LogIt(_L ("%S = %S\n"), &ourPrompt, &tempstring);
   1.413 +		}
   1.414 +
   1.415 +	else
   1.416 +		//iTest.Console()->Printf (_L (" is empty"));
   1.417 +	iTest.Console()->Printf (_L ("\n"));
   1.418 +	currentstring.Copy(tempstring);						//copy 16 bit tempstring descriptor back 
   1.419 +	}
   1.420 +
   1.421 +
   1.422 +EXPORT_C TInt CIpuTestHarness::GetSelection(const TDesC& ourPrompt, const TDesC& validChoices)
   1.423 +//
   1.424 +//	Present the user with a list of options, and get their selection
   1.425 +	{
   1.426 +	// If we're scripting, try reading from script first
   1.427 +	TInt readScriptErr = KErrNotFound;
   1.428 +	if (iScriptRunning)
   1.429 +		{
   1.430 +		TBuf<1> oneCharBuf;
   1.431 +		readScriptErr = ReadLineFromScript(oneCharBuf);
   1.432 +		if (!readScriptErr)
   1.433 +			{
   1.434 +			return validChoices.Locate((TChar)oneCharBuf[0]);
   1.435 +			}
   1.436 +		}
   1.437 +
   1.438 +	// Either not scripting, or hit end of script - continue with user input
   1.439 +	TKeyCode key = EKeyNull;
   1.440 +	iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
   1.441 +	iTest.Console()->Printf(_L("%S "), &ourPrompt);
   1.442 +	iTest.Console()->Printf(_L("[%S] :"), &validChoices);
   1.443 +	TInt retVal = KErrNotFound;
   1.444 +	while (retVal == KErrNotFound)
   1.445 +		{
   1.446 +		key = iTest.Getch();
   1.447 +
   1.448 +		// Check that key is in the list of valid choices
   1.449 +		retVal = validChoices.Locate((TChar)key);
   1.450 +		}
   1.451 +	iTest.Console()->Printf(_L("%c\n\n"), key);
   1.452 +	return retVal;
   1.453 +	}
   1.454 +
   1.455 +
   1.456 +EXPORT_C void CIpuTestHarness::SetScript(RFile& scriptFile)
   1.457 +//
   1.458 +//	Sets the file to be used for a test script - ie. a file that contains commands used by
   1.459 +//  GetEntry() and GetSelection()
   1.460 +	{
   1.461 +	iScriptFile = &scriptFile;
   1.462 +	iScriptRunning = ETrue;
   1.463 +	LogIt(_L("***SCRIPT STARTING***\n"));
   1.464 +	}
   1.465 +
   1.466 +TInt CIpuTestHarness::ReadLineFromScript(TDes& aBuffer)
   1.467 +//
   1.468 +// Reads the next line from the script file, and sets the passed-in descriptor with its contents.
   1.469 +// Returns KErrNone if reading succeeded; KErrNotFound if the EOF was reached. When EOF is reached,
   1.470 +// the file is closed.
   1.471 +	{
   1.472 +	// *********************************
   1.473 +	// Assume script is 8-bit text file
   1.474 +	// *********************************
   1.475 +	TBool isAComment = ETrue;
   1.476 +	TInt err = KErrNone;
   1.477 +	TBuf<512> line;
   1.478 +	while (isAComment && !err)
   1.479 +		{
   1.480 +		TFileText text;
   1.481 +		text.Set(*iScriptFile);
   1.482 +		line.SetLength(0);
   1.483 +		for(;;)
   1.484 +			{
   1.485 +			TBuf8<2> c;
   1.486 +			err = iScriptFile->Read(c,1);
   1.487 +			if (err && err != KErrEof)
   1.488 +				{
   1.489 +				iTest.Printf(_L("Error reading file: %d\n"), err);
   1.490 +				break;
   1.491 +				}
   1.492 +			if (c.Length() == 0)
   1.493 +				{
   1.494 +				err = KErrEof;
   1.495 +				break;
   1.496 +				}
   1.497 +			else
   1.498 +				{
   1.499 +				if (c[0] == '\n') // break out if it is CR
   1.500 +					break;
   1.501 +				else if (c[0] != (TUint8)(0x0d)) // otherwise append the char, _unless_ it is a LF
   1.502 +					line.Append(c[0]);
   1.503 +				}
   1.504 +			}
   1.505 +		if (err == KErrNone && line.Locate('/') != 0) // comment (only works if it's the first character)
   1.506 +			{
   1.507 +			isAComment = EFalse;
   1.508 +			}
   1.509 +		}
   1.510 +
   1.511 +	// The line read is not a comment, or have hit end of file
   1.512 +	if (!err)
   1.513 +		{
   1.514 +		// copy to passed in descriptor, but do not allow an overflow
   1.515 +		aBuffer.Copy(line.Left(aBuffer.MaxLength()));
   1.516 +		LogIt(_L("***SCRIPT : read command '%S' ***\n"), &aBuffer);
   1.517 +		}
   1.518 +	else
   1.519 +		{
   1.520 +		iScriptFile->Close();
   1.521 +		err = KErrNotFound;
   1.522 +		iScriptRunning = EFalse;
   1.523 +		LogIt(_L("***SCRIPT ENDED***\n"));
   1.524 +		}
   1.525 +	return err;
   1.526 +	}
   1.527 +
   1.528 +void CIpuTestHarness::Panic(TInt aPanic)
   1.529 +//
   1.530 +//	Panic the client program.
   1.531 +	{
   1.532 +	User::Panic(KTestPanic,aPanic);
   1.533 +	}
   1.534 +
   1.535 +void CIpuTestHarness::TestHarnessComplete()
   1.536 +//
   1.537 +//	Test harness completed without failures
   1.538 +	{
   1.539 +	_LIT(KTestCompleteFormat, "Total Tests %d, Failed Tests %d");
   1.540 +	TBuf<50> text;
   1.541 +	text.AppendFormat(KTestCompleteFormat, iTestCount, iFailedTests->Count()); 
   1.542 +	WriteComment(text);
   1.543 +	WriteComment(KTestHarnessCompleted);
   1.544 +	}
   1.545 +
   1.546 +void CIpuTestHarness::TestHarnessFailed()
   1.547 +//
   1.548 +//	Test harness has a failure - log information
   1.549 +	{
   1.550 +	TBuf<KMaxFileName + 4> buf;
   1.551 +	buf.Format(KTestHarnessFailed, iFailedTests->Count());
   1.552 +	WriteComment(buf);
   1.553 +	//	Log fialed tests' information
   1.554 +	for (TInt ii=0; ii<iFailedTests->Count(); ++ii)
   1.555 +		{
   1.556 +		CTestInfo* failed = iFailedTests->At(ii);
   1.557 +		TPtrC name = failed->Name();
   1.558 +		LogIt(KTestFailInfo, failed->Number(), &name, failed->ErrorCode());
   1.559 +		}
   1.560 +	}
   1.561 +
   1.562 +void CIpuTestHarness::ResourceLeakTest()
   1.563 +//
   1.564 +// Creates a new test that fails if any there are any leaked resource handles
   1.565 +	{
   1.566 +	// Start new test
   1.567 +	_LIT(KResourceTestName, "Resource Handle Leak Test");
   1.568 +	TRAPD(testError, StartTestL(KResourceTestName));
   1.569 +	if(testError==KErrNone)
   1.570 +		{
   1.571 +		//	Find number of opened handles
   1.572 +		TInt processHandleCount=0;
   1.573 +		TInt threadHandleCount=0;
   1.574 +		RThread().HandleCount(processHandleCount,threadHandleCount);
   1.575 +		TInt openHandleCount = iStartHandleCount-threadHandleCount;
   1.576 +		TInt err = KErrNone;
   1.577 +		if ( openHandleCount !=0 )
   1.578 +			{
   1.579 +			err = KErrGeneral;
   1.580 +			LogIt(_L("Number leaked handles is %D"), openHandleCount);
   1.581 +			}
   1.582 +		EndTest(err);
   1.583 +		}
   1.584 +	else
   1.585 +		{
   1.586 +		_LIT(KTxtResourceTestRunError, "Unable to complete Resource Leak Test, error: %d");
   1.587 +		LogIt(KTxtResourceTestRunError, testError);
   1.588 +		EndTest(testError);
   1.589 +		}
   1.590 +	}
   1.591 +
   1.592 +//
   1.593 +//	CTestInfo
   1.594 +//
   1.595 +CIpuTestHarness::CTestInfo::CTestInfo()
   1.596 +//
   1.597 +//	Default c'tor
   1.598 +	{
   1.599 +	}
   1.600 +
   1.601 +CIpuTestHarness::CTestInfo::~CTestInfo()
   1.602 +//
   1.603 +//	D'tor
   1.604 +	{
   1.605 +	delete iName;
   1.606 +	}
   1.607 +
   1.608 +CIpuTestHarness::CTestInfo* CIpuTestHarness::CTestInfo::NewLC(const TDesC& aName, TInt aNumber, TInt aErrorCode)
   1.609 +//
   1.610 +//	Static factory c'tor
   1.611 +	{
   1.612 +	CTestInfo* self = new (ELeave) CTestInfo();
   1.613 +	CleanupStack::PushL(self);
   1.614 +	self->ConstructL(aName, aNumber, aErrorCode);
   1.615 +	return self;
   1.616 +	}
   1.617 +
   1.618 +CIpuTestHarness::CTestInfo* CIpuTestHarness::CTestInfo::NewL(const TDesC& aName, TInt aNumber, TInt aErrorCode)
   1.619 +//
   1.620 +//	Static factory c'tor
   1.621 +	{
   1.622 +	CTestInfo* self = NewLC(aName, aNumber, aErrorCode);
   1.623 +	CleanupStack::Pop();	//	self
   1.624 +	return self;
   1.625 +	}
   1.626 +
   1.627 +void CIpuTestHarness::CTestInfo::ConstructL(const TDesC& aName, TInt aNumber, TInt aErrorCode)
   1.628 +//
   1.629 +//	Non-trivial c'tor
   1.630 +	{
   1.631 +	iName = aName.AllocLC();
   1.632 +	CleanupStack::Pop();	//	iName
   1.633 +
   1.634 +	iNumber = aNumber;
   1.635 +	iErrorCode = aErrorCode;
   1.636 +	}
   1.637 +
   1.638 +void CIpuTestHarness::CTestInfo::SetNameL(const TDesC& aName)
   1.639 +//
   1.640 +//	Sets iName
   1.641 +	{
   1.642 +	HBufC* temp = aName.AllocLC();
   1.643 +	CleanupStack::Pop();	//	temp
   1.644 +	delete iName;
   1.645 +	iName = temp;
   1.646 +	}
   1.647 +
   1.648 +void CIpuTestHarness::CTestInfo::SetNumber(TInt aNumber)
   1.649 +//
   1.650 +//	Sets iNumber
   1.651 +	{
   1.652 +	iNumber = aNumber;
   1.653 +	}
   1.654 +
   1.655 +void CIpuTestHarness::CTestInfo::SetErrorCode(TInt aErrorCode)
   1.656 +//
   1.657 +//	Sets iErrorCode
   1.658 +	{
   1.659 +	iErrorCode = aErrorCode;
   1.660 +	}