os/ossrv/genericservices/httputils/Test/IpuTestUtils/IpuTestHarness.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "IpuTestUtils.h"
sl@0
    17
#include <e32consf.h>
sl@0
    18
//
sl@0
    19
//	Constants
sl@0
    20
_LIT(KTestPanic, "IpuTestHarness");
sl@0
    21
const TInt KFailedTestsGranularity = 10;
sl@0
    22
const TInt KMaxLogEntrySize = 256;
sl@0
    23
sl@0
    24
//
sl@0
    25
//	CIpuTestHarness
sl@0
    26
//
sl@0
    27
CIpuTestHarness::CIpuTestHarness(const TDesC& aTitle)
sl@0
    28
	: iTest(aTitle)
sl@0
    29
//
sl@0
    30
//	Default c'tor
sl@0
    31
	{
sl@0
    32
    LogRTestToFile(iTest);
sl@0
    33
	iTest.Title();
sl@0
    34
	iCanStartTest = ETrue;
sl@0
    35
	}
sl@0
    36
sl@0
    37
CIpuTestHarness::~CIpuTestHarness()
sl@0
    38
//
sl@0
    39
//	D'tor
sl@0
    40
	{
sl@0
    41
	TTime endtime;
sl@0
    42
	endtime.UniversalTime();
sl@0
    43
sl@0
    44
	// Do resource handle leak test?
sl@0
    45
	if (iDoResourceLeakTest)
sl@0
    46
		ResourceLeakTest();
sl@0
    47
sl@0
    48
	//	End of tests - see if failed or ok
sl@0
    49
	if (iFailedTests->Count())
sl@0
    50
		{
sl@0
    51
		TestHarnessFailed();
sl@0
    52
		}
sl@0
    53
	else
sl@0
    54
		{
sl@0
    55
		TestHarnessComplete();
sl@0
    56
		}
sl@0
    57
sl@0
    58
	iFailedTests->ResetAndDestroy();
sl@0
    59
	delete iFailedTests;
sl@0
    60
sl@0
    61
	//	Log finish time
sl@0
    62
	TDateTime t = endtime.DateTime();
sl@0
    63
	LogIt(_L("Ended @ %d:%d:%d:%d"),t.Hour(),t.Minute(),t.Second(),t.MicroSecond());
sl@0
    64
	TTime difftime(endtime.Int64() - iStartTime.Int64());
sl@0
    65
	t = difftime.DateTime();
sl@0
    66
	LogIt(_L("Execution time %d:%d:%d:%d"),t.Hour(),t.Minute(),t.Second(),t.MicroSecond());
sl@0
    67
sl@0
    68
	//	Close logs and test harness
sl@0
    69
	iFlogger.CloseLog();
sl@0
    70
	
sl@0
    71
	// iTest test harness performs UHEAP MARK/UNMARK check upon creation/destruction
sl@0
    72
	//   therefore, it must be destroyed last since it is created first in 
sl@0
    73
	//   CIpuTestHarness
sl@0
    74
	iTest.Close();
sl@0
    75
	}
sl@0
    76
sl@0
    77
EXPORT_C CIpuTestHarness* CIpuTestHarness::NewLC(const TDesC& aTitle)
sl@0
    78
//
sl@0
    79
//	Static factory c'tor
sl@0
    80
	{
sl@0
    81
	CIpuTestHarness* self = new (ELeave) CIpuTestHarness(aTitle);
sl@0
    82
	CleanupStack::PushL(self);
sl@0
    83
	self->ConstructL(aTitle);
sl@0
    84
	return self;
sl@0
    85
	}
sl@0
    86
sl@0
    87
EXPORT_C CIpuTestHarness* CIpuTestHarness::NewL(const TDesC& aTitle)
sl@0
    88
//
sl@0
    89
//	Static factiry c'tor
sl@0
    90
	{
sl@0
    91
	CIpuTestHarness* self = CIpuTestHarness::NewLC(aTitle);
sl@0
    92
	CleanupStack::Pop();
sl@0
    93
	return self;
sl@0
    94
	}
sl@0
    95
sl@0
    96
void CIpuTestHarness::ConstructL(const TDesC& aTitle)
sl@0
    97
//
sl@0
    98
//	Non-trivial c'tor
sl@0
    99
	{
sl@0
   100
	//	Create iFailedTests
sl@0
   101
	iFailedTests = new (ELeave) CArrayPtrFlat<CTestInfo> (KFailedTestsGranularity);
sl@0
   102
sl@0
   103
	//	Start up logging server connection
sl@0
   104
	TBuf<64> temp(aTitle);
sl@0
   105
	DefaultLogFileName(temp);
sl@0
   106
	CreateFlogger(temp, EFalse, EFalse);
sl@0
   107
sl@0
   108
	iStartTime.UniversalTime();
sl@0
   109
	TDateTime t = iStartTime.DateTime();
sl@0
   110
	LogIt(_L("Started @ %d:%d:%d:%d"),t.Hour(),t.Minute(),t.Second(),t.MicroSecond());
sl@0
   111
sl@0
   112
	// Find number of open resource handles
sl@0
   113
	TInt processHandleCount=0;
sl@0
   114
	RThread().HandleCount(processHandleCount,iStartHandleCount);
sl@0
   115
	}
sl@0
   116
sl@0
   117
EXPORT_C void CIpuTestHarness::StartTestL(const TDesC& aName)
sl@0
   118
//
sl@0
   119
//	Logs start of test aName
sl@0
   120
	{
sl@0
   121
	if (iCanStartTest)
sl@0
   122
		{
sl@0
   123
		//  - increment test count
sl@0
   124
		++iTestCount;
sl@0
   125
		
sl@0
   126
		if (iTestMode == ETestModeNormal) // don't add this info when we are doing memory leak testing otherwise it
sl@0
   127
										  // would get leaked!
sl@0
   128
			{
sl@0
   129
sl@0
   130
			//	Add this test to failed test list - set errorcode to zero
sl@0
   131
			CTestInfo* temp = CTestInfo::NewLC(aName, iTestCount, 0);
sl@0
   132
			iFailedTests->AppendL(temp);
sl@0
   133
			CleanupStack::Pop();	//	temp
sl@0
   134
sl@0
   135
			//	Stop new test being started until this one has ended
sl@0
   136
			iTest.Start(aName);
sl@0
   137
			iCanStartTest = EFalse;
sl@0
   138
			}
sl@0
   139
sl@0
   140
		
sl@0
   141
		TBuf<KMaxFileName + 4> buf;
sl@0
   142
		buf.Format(KTestStartingWithDesc, iTestCount, &aName);
sl@0
   143
		WriteComment(buf);
sl@0
   144
sl@0
   145
		// Reset iStepNumber - start at 1
sl@0
   146
		iStepNumber = 1;
sl@0
   147
		}
sl@0
   148
	else
sl@0
   149
		{
sl@0
   150
		//	Panic client - bad usage - not allowed to nest tests
sl@0
   151
		Panic(EBadStartTest);
sl@0
   152
		}
sl@0
   153
	}
sl@0
   154
sl@0
   155
EXPORT_C void CIpuTestHarness::NextStep(const TDesC& aStepName)
sl@0
   156
//
sl@0
   157
//	Logs the next step in a test - for informative use.
sl@0
   158
	{
sl@0
   159
	if (!iCanStartTest)
sl@0
   160
		{
sl@0
   161
		TBuf<KMaxFileName + 4> buf;
sl@0
   162
		buf.Format(KNextTestStepWithDesc, iTestCount, iStepNumber, &aStepName);
sl@0
   163
		WriteComment(buf);
sl@0
   164
		iTest.Next(aStepName);
sl@0
   165
		++iStepNumber;
sl@0
   166
		}
sl@0
   167
	else
sl@0
   168
		{
sl@0
   169
		//	Panic client - bad usage - test not started
sl@0
   170
		Panic(EBadStartTest);
sl@0
   171
		}
sl@0
   172
	}
sl@0
   173
sl@0
   174
EXPORT_C void CIpuTestHarness::EndTest(TInt aErrorCode)
sl@0
   175
//
sl@0
   176
//	Logs end of test
sl@0
   177
	{
sl@0
   178
	if (!iCanStartTest)
sl@0
   179
		{
sl@0
   180
		if (iTestMode == ETestModeNormal)
sl@0
   181
			{
sl@0
   182
			//	Get ptr to this test's entry in failed list - will be the last entry
sl@0
   183
			TBuf<KMaxFileName + 4> buf;
sl@0
   184
			TInt index = iFailedTests->Count();
sl@0
   185
			CTestInfo* ptr = iFailedTests->At(--index);
sl@0
   186
			if (aErrorCode)
sl@0
   187
				{
sl@0
   188
				//	Set the error code
sl@0
   189
				ptr->SetErrorCode(aErrorCode);
sl@0
   190
				buf.Format(KTestFailed, iTestCount, aErrorCode);
sl@0
   191
				WriteComment(buf);
sl@0
   192
				}
sl@0
   193
			else
sl@0
   194
				{
sl@0
   195
				//	Remove entry from list of failed tests
sl@0
   196
				delete ptr;
sl@0
   197
				iFailedTests->Delete(index);
sl@0
   198
				}
sl@0
   199
			
sl@0
   200
			}
sl@0
   201
		//	Allow new test to start
sl@0
   202
		iTest.End();
sl@0
   203
		iCanStartTest = ETrue;
sl@0
   204
		}
sl@0
   205
	else
sl@0
   206
		{
sl@0
   207
		if (iTestMode == ETestModeNormal)
sl@0
   208
			//	Panic client - bad usage - test not started
sl@0
   209
			Panic(EBadEndTest);
sl@0
   210
		// don't panic when we are memory leak testing as EndTestL will never get called to reset the test properly
sl@0
   211
		}
sl@0
   212
	}
sl@0
   213
sl@0
   214
EXPORT_C void CIpuTestHarness::LogIt(TRefByValue<const TDesC> aFmt, ...)
sl@0
   215
//
sl@0
   216
//	Messages to the front end emulator and to the Inu log
sl@0
   217
	{
sl@0
   218
	VA_LIST list;
sl@0
   219
	VA_START(list,aFmt);
sl@0
   220
sl@0
   221
	TBuf<KMaxFileName + 4> buf;
sl@0
   222
	buf.Append(KTestCommentPrepend);
sl@0
   223
	buf.AppendFormatList(aFmt,list);
sl@0
   224
	VA_END(list);
sl@0
   225
sl@0
   226
	WriteComment(buf);
sl@0
   227
	}
sl@0
   228
sl@0
   229
EXPORT_C void CIpuTestHarness::operator()(TInt aResult,TInt aLineNum)
sl@0
   230
//
sl@0
   231
//	Overload operator ()
sl@0
   232
	{
sl@0
   233
	iTest(aResult, aLineNum);
sl@0
   234
	}
sl@0
   235
sl@0
   236
EXPORT_C void CIpuTestHarness::operator()(TInt aResult)
sl@0
   237
//
sl@0
   238
//	Overload operator ()
sl@0
   239
	{
sl@0
   240
	iTest(aResult);
sl@0
   241
	}
sl@0
   242
sl@0
   243
EXPORT_C void CIpuTestHarness::PressAnyKey()
sl@0
   244
//
sl@0
   245
//	Request a key press from user and wait - unless we are running a script
sl@0
   246
	{
sl@0
   247
	if (!iScriptRunning)
sl@0
   248
		{
sl@0
   249
		iTest.Printf(TRefByValue<const TDesC>_L("\nPress a key"));	
sl@0
   250
		iTest.Getch();
sl@0
   251
		}
sl@0
   252
	}
sl@0
   253
sl@0
   254
EXPORT_C void CIpuTestHarness::DumpData(HBufC8& aData, TBool logIt)
sl@0
   255
//
sl@0
   256
//	Do a formatted dump of binary data, optionally logging it
sl@0
   257
	{
sl@0
   258
	// Iterate the supplied block of data in blocks of 16 bytes
sl@0
   259
	TInt pos = 0;
sl@0
   260
	TBuf<KMaxLogEntrySize> logLine;
sl@0
   261
	TBuf<KMaxLogEntrySize> anEntry;
sl@0
   262
	while (pos < aData.Length())
sl@0
   263
		{
sl@0
   264
		anEntry.Format(TRefByValue<const TDesC>_L("%04x : "), pos);
sl@0
   265
		logLine.Append(anEntry);
sl@0
   266
sl@0
   267
		// Hex output
sl@0
   268
		TInt offset = 0;
sl@0
   269
		for (offset = 0; offset < 16; offset++)
sl@0
   270
			{
sl@0
   271
			if (pos + offset < aData.Length())
sl@0
   272
				{
sl@0
   273
				TInt nextByte = aData[pos + offset];
sl@0
   274
				anEntry.Format(TRefByValue<const TDesC>_L("%02x "), nextByte);
sl@0
   275
				logLine.Append(anEntry);
sl@0
   276
				}
sl@0
   277
			else
sl@0
   278
				{
sl@0
   279
				anEntry.Format(TRefByValue<const TDesC>_L("   "));
sl@0
   280
				logLine.Append(anEntry);
sl@0
   281
				}
sl@0
   282
			}
sl@0
   283
			anEntry.Format(TRefByValue<const TDesC>_L(": "));
sl@0
   284
			logLine.Append(anEntry);
sl@0
   285
sl@0
   286
		// Char output
sl@0
   287
		for (offset = 0; offset < 16; offset++)
sl@0
   288
			{
sl@0
   289
			if (pos + offset < aData.Length())
sl@0
   290
				{
sl@0
   291
				TInt nextByte = aData[pos + offset];
sl@0
   292
				if ((nextByte >= 32) && (nextByte <= 127))
sl@0
   293
					{
sl@0
   294
					anEntry.Format(TRefByValue<const TDesC>_L("%c"), nextByte);
sl@0
   295
					logLine.Append(anEntry);
sl@0
   296
					}
sl@0
   297
				else
sl@0
   298
					{
sl@0
   299
					anEntry.Format(TRefByValue<const TDesC>_L("."));
sl@0
   300
					logLine.Append(anEntry);
sl@0
   301
					}
sl@0
   302
				}
sl@0
   303
			else
sl@0
   304
				{
sl@0
   305
				anEntry.Format(TRefByValue<const TDesC>_L(" "));
sl@0
   306
				logLine.Append(anEntry);
sl@0
   307
				}
sl@0
   308
			}
sl@0
   309
			if (logIt)
sl@0
   310
				{
sl@0
   311
				LogIt(TRefByValue<const TDesC>_L("%S"), &logLine);
sl@0
   312
				}
sl@0
   313
			else
sl@0
   314
				{
sl@0
   315
				iTest.Printf(TRefByValue<const TDesC>_L("%S\n"), &logLine);	
sl@0
   316
				}
sl@0
   317
			logLine.Zero();
sl@0
   318
sl@0
   319
		// Advance to next 16 byte segment
sl@0
   320
		pos += 16;
sl@0
   321
		}
sl@0
   322
	}
sl@0
   323
sl@0
   324
EXPORT_C void CIpuTestHarness::GetAnEntry(const TDesC& ourPrompt, TDes& currentstring)
sl@0
   325
//
sl@0
   326
//	Get an input string from the user, displaying a supplied prompt and default string value
sl@0
   327
	{
sl@0
   328
	// If we're scripting, try reading from script first
sl@0
   329
	TInt readScriptErr = KErrNotFound;
sl@0
   330
	if (iScriptRunning)
sl@0
   331
		{
sl@0
   332
		readScriptErr = ReadLineFromScript(currentstring);
sl@0
   333
		}
sl@0
   334
	if (!readScriptErr)
sl@0
   335
		return;
sl@0
   336
sl@0
   337
	// Either not scripting, or hit end of script - continue with user input
sl@0
   338
	TBuf16<KMaxUserEntrySize> ourLine;
sl@0
   339
	TBuf<KMaxUserEntrySize> tempstring;				//tempstring is a unicode descriptor
sl@0
   340
										//create a temporary buffer where the
sl@0
   341
										//unicode strings are stored in order to 
sl@0
   342
										//be displayed
sl@0
   343
	ourLine.Zero ();
sl@0
   344
	tempstring.Copy(currentstring);		//Copy current string to Unicode buffer
sl@0
   345
	TKeyCode key = EKeyNull;						//current string buffer is 8 bits wide.
sl@0
   346
										//Unicode string bufffer (tempstring) is 16 bits wide.
sl@0
   347
	for (;;)
sl@0
   348
		{
sl@0
   349
		if (ourLine.Length () == 0)
sl@0
   350
			{
sl@0
   351
			iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
sl@0
   352
			iTest.Console()->Printf (_L ("%S"), &ourPrompt);
sl@0
   353
			if (tempstring.Length () != 0)						//get tempstring's number of items
sl@0
   354
				iTest.Console()->Printf (_L (" = %S"), &tempstring);	//if not zero print them to iTest.Console()
sl@0
   355
			iTest.Console()->Printf (_L (" : "));
sl@0
   356
			iTest.Console()->ClearToEndOfLine ();
sl@0
   357
			}
sl@0
   358
		key = iTest.Getch();
sl@0
   359
		
sl@0
   360
		  if (key == EKeyBackspace)
sl@0
   361
				{
sl@0
   362
					if (ourLine.Length() !=0)
sl@0
   363
					{
sl@0
   364
						ourLine.SetLength(ourLine.Length()-1);
sl@0
   365
						iTest.Console()->Printf (_L ("%c"), key);
sl@0
   366
						iTest.Console()->SetPos(iTest.Console()->WhereX(),iTest.Console()->WhereY());
sl@0
   367
						iTest.Console()->ClearToEndOfLine();
sl@0
   368
					}	// end if (ourLine.Length() !=0)
sl@0
   369
				}	// end if (key == KeyBackSpace)
sl@0
   370
		  
sl@0
   371
		  		  
sl@0
   372
		  if (key == EKeyDelete) 			
sl@0
   373
				{
sl@0
   374
					ourLine.Zero();
sl@0
   375
					iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
sl@0
   376
					iTest.Console()->ClearToEndOfLine ();
sl@0
   377
					tempstring.Copy(ourLine);
sl@0
   378
					break;
sl@0
   379
				}
sl@0
   380
		  
sl@0
   381
		  if (key == EKeyEnter)
sl@0
   382
			break;
sl@0
   383
		
sl@0
   384
		  if (key < 32)
sl@0
   385
			{
sl@0
   386
			continue;
sl@0
   387
			}
sl@0
   388
		
sl@0
   389
		ourLine.Append (key);
sl@0
   390
		iTest.Console()->Printf (_L ("%c"), key);
sl@0
   391
		iTest.Console()->SetPos(iTest.Console()->WhereX(),iTest.Console()->WhereY());
sl@0
   392
		iTest.Console()->ClearToEndOfLine();
sl@0
   393
		if (ourLine.Length () == ourLine.MaxLength ())
sl@0
   394
			break;
sl@0
   395
		}	// end of for statement
sl@0
   396
sl@0
   397
	if ((key == EKeyEnter) && (ourLine.Length () == 0))
sl@0
   398
		tempstring.Copy (currentstring);				//copy contents of 8 bit "ourLine" descriptor
sl@0
   399
	
sl@0
   400
	iTest.Console()->SetPos (0, iTest.Console()->WhereY ());		
sl@0
   401
	iTest.Console()->ClearToEndOfLine ();
sl@0
   402
	iTest.Console()->Printf (_L ("%S"), &ourPrompt);
sl@0
   403
	
sl@0
   404
	if ((key == EKeyEnter) && (ourLine.Length() !=0))
sl@0
   405
		tempstring.Copy(ourLine);
sl@0
   406
	if (tempstring.Length () != 0)						//if temstring length is not zero
sl@0
   407
		{
sl@0
   408
		iTest.Console()->Printf (_L (" = %S\n"), &tempstring);	//print the contents to iTest.Console()
sl@0
   409
		LogIt(_L ("%S = %S\n"), &ourPrompt, &tempstring);
sl@0
   410
		}
sl@0
   411
sl@0
   412
	else
sl@0
   413
		//iTest.Console()->Printf (_L (" is empty"));
sl@0
   414
	iTest.Console()->Printf (_L ("\n"));
sl@0
   415
	currentstring.Copy(tempstring);						//copy 16 bit tempstring descriptor back 
sl@0
   416
	}
sl@0
   417
sl@0
   418
sl@0
   419
EXPORT_C TInt CIpuTestHarness::GetSelection(const TDesC& ourPrompt, const TDesC& validChoices)
sl@0
   420
//
sl@0
   421
//	Present the user with a list of options, and get their selection
sl@0
   422
	{
sl@0
   423
	// If we're scripting, try reading from script first
sl@0
   424
	TInt readScriptErr = KErrNotFound;
sl@0
   425
	if (iScriptRunning)
sl@0
   426
		{
sl@0
   427
		TBuf<1> oneCharBuf;
sl@0
   428
		readScriptErr = ReadLineFromScript(oneCharBuf);
sl@0
   429
		if (!readScriptErr)
sl@0
   430
			{
sl@0
   431
			return validChoices.Locate((TChar)oneCharBuf[0]);
sl@0
   432
			}
sl@0
   433
		}
sl@0
   434
sl@0
   435
	// Either not scripting, or hit end of script - continue with user input
sl@0
   436
	TKeyCode key = EKeyNull;
sl@0
   437
	iTest.Console()->SetPos (0, iTest.Console()->WhereY ());
sl@0
   438
	iTest.Console()->Printf(_L("%S "), &ourPrompt);
sl@0
   439
	iTest.Console()->Printf(_L("[%S] :"), &validChoices);
sl@0
   440
	TInt retVal = KErrNotFound;
sl@0
   441
	while (retVal == KErrNotFound)
sl@0
   442
		{
sl@0
   443
		key = iTest.Getch();
sl@0
   444
sl@0
   445
		// Check that key is in the list of valid choices
sl@0
   446
		retVal = validChoices.Locate((TChar)key);
sl@0
   447
		}
sl@0
   448
	iTest.Console()->Printf(_L("%c\n\n"), key);
sl@0
   449
	return retVal;
sl@0
   450
	}
sl@0
   451
sl@0
   452
sl@0
   453
EXPORT_C void CIpuTestHarness::SetScript(RFile& scriptFile)
sl@0
   454
//
sl@0
   455
//	Sets the file to be used for a test script - ie. a file that contains commands used by
sl@0
   456
//  GetEntry() and GetSelection()
sl@0
   457
	{
sl@0
   458
	iScriptFile = &scriptFile;
sl@0
   459
	iScriptRunning = ETrue;
sl@0
   460
	LogIt(_L("***SCRIPT STARTING***\n"));
sl@0
   461
	}
sl@0
   462
sl@0
   463
TInt CIpuTestHarness::ReadLineFromScript(TDes& aBuffer)
sl@0
   464
//
sl@0
   465
// Reads the next line from the script file, and sets the passed-in descriptor with its contents.
sl@0
   466
// Returns KErrNone if reading succeeded; KErrNotFound if the EOF was reached. When EOF is reached,
sl@0
   467
// the file is closed.
sl@0
   468
	{
sl@0
   469
	// *********************************
sl@0
   470
	// Assume script is 8-bit text file
sl@0
   471
	// *********************************
sl@0
   472
	TBool isAComment = ETrue;
sl@0
   473
	TInt err = KErrNone;
sl@0
   474
	TBuf<512> line;
sl@0
   475
	while (isAComment && !err)
sl@0
   476
		{
sl@0
   477
		TFileText text;
sl@0
   478
		text.Set(*iScriptFile);
sl@0
   479
		line.SetLength(0);
sl@0
   480
		for(;;)
sl@0
   481
			{
sl@0
   482
			TBuf8<2> c;
sl@0
   483
			err = iScriptFile->Read(c,1);
sl@0
   484
			if (err && err != KErrEof)
sl@0
   485
				{
sl@0
   486
				iTest.Printf(_L("Error reading file: %d\n"), err);
sl@0
   487
				break;
sl@0
   488
				}
sl@0
   489
			if (c.Length() == 0)
sl@0
   490
				{
sl@0
   491
				err = KErrEof;
sl@0
   492
				break;
sl@0
   493
				}
sl@0
   494
			else
sl@0
   495
				{
sl@0
   496
				if (c[0] == '\n') // break out if it is CR
sl@0
   497
					break;
sl@0
   498
				else if (c[0] != (TUint8)(0x0d)) // otherwise append the char, _unless_ it is a LF
sl@0
   499
					line.Append(c[0]);
sl@0
   500
				}
sl@0
   501
			}
sl@0
   502
		if (err == KErrNone && line.Locate('/') != 0) // comment (only works if it's the first character)
sl@0
   503
			{
sl@0
   504
			isAComment = EFalse;
sl@0
   505
			}
sl@0
   506
		}
sl@0
   507
sl@0
   508
	// The line read is not a comment, or have hit end of file
sl@0
   509
	if (!err)
sl@0
   510
		{
sl@0
   511
		// copy to passed in descriptor, but do not allow an overflow
sl@0
   512
		aBuffer.Copy(line.Left(aBuffer.MaxLength()));
sl@0
   513
		LogIt(_L("***SCRIPT : read command '%S' ***\n"), &aBuffer);
sl@0
   514
		}
sl@0
   515
	else
sl@0
   516
		{
sl@0
   517
		iScriptFile->Close();
sl@0
   518
		err = KErrNotFound;
sl@0
   519
		iScriptRunning = EFalse;
sl@0
   520
		LogIt(_L("***SCRIPT ENDED***\n"));
sl@0
   521
		}
sl@0
   522
	return err;
sl@0
   523
	}
sl@0
   524
sl@0
   525
void CIpuTestHarness::Panic(TInt aPanic)
sl@0
   526
//
sl@0
   527
//	Panic the client program.
sl@0
   528
	{
sl@0
   529
	User::Panic(KTestPanic,aPanic);
sl@0
   530
	}
sl@0
   531
sl@0
   532
void CIpuTestHarness::TestHarnessComplete()
sl@0
   533
//
sl@0
   534
//	Test harness completed without failures
sl@0
   535
	{
sl@0
   536
	_LIT(KTestCompleteFormat, "Total Tests %d, Failed Tests %d");
sl@0
   537
	TBuf<50> text;
sl@0
   538
	text.AppendFormat(KTestCompleteFormat, iTestCount, iFailedTests->Count()); 
sl@0
   539
	WriteComment(text);
sl@0
   540
	WriteComment(KTestHarnessCompleted);
sl@0
   541
	}
sl@0
   542
sl@0
   543
void CIpuTestHarness::TestHarnessFailed()
sl@0
   544
//
sl@0
   545
//	Test harness has a failure - log information
sl@0
   546
	{
sl@0
   547
	TBuf<KMaxFileName + 4> buf;
sl@0
   548
	buf.Format(KTestHarnessFailed, iFailedTests->Count());
sl@0
   549
	WriteComment(buf);
sl@0
   550
	//	Log fialed tests' information
sl@0
   551
	for (TInt ii=0; ii<iFailedTests->Count(); ++ii)
sl@0
   552
		{
sl@0
   553
		CTestInfo* failed = iFailedTests->At(ii);
sl@0
   554
		TPtrC name = failed->Name();
sl@0
   555
		LogIt(KTestFailInfo, failed->Number(), &name, failed->ErrorCode());
sl@0
   556
		}
sl@0
   557
	}
sl@0
   558
sl@0
   559
void CIpuTestHarness::ResourceLeakTest()
sl@0
   560
//
sl@0
   561
// Creates a new test that fails if any there are any leaked resource handles
sl@0
   562
	{
sl@0
   563
	// Start new test
sl@0
   564
	_LIT(KResourceTestName, "Resource Handle Leak Test");
sl@0
   565
	TRAPD(testError, StartTestL(KResourceTestName));
sl@0
   566
	if(testError==KErrNone)
sl@0
   567
		{
sl@0
   568
		//	Find number of opened handles
sl@0
   569
		TInt processHandleCount=0;
sl@0
   570
		TInt threadHandleCount=0;
sl@0
   571
		RThread().HandleCount(processHandleCount,threadHandleCount);
sl@0
   572
		TInt openHandleCount = iStartHandleCount-threadHandleCount;
sl@0
   573
		TInt err = KErrNone;
sl@0
   574
		if ( openHandleCount !=0 )
sl@0
   575
			{
sl@0
   576
			err = KErrGeneral;
sl@0
   577
			LogIt(_L("Number leaked handles is %D"), openHandleCount);
sl@0
   578
			}
sl@0
   579
		EndTest(err);
sl@0
   580
		}
sl@0
   581
	else
sl@0
   582
		{
sl@0
   583
		_LIT(KTxtResourceTestRunError, "Unable to complete Resource Leak Test, error: %d");
sl@0
   584
		LogIt(KTxtResourceTestRunError, testError);
sl@0
   585
		EndTest(testError);
sl@0
   586
		}
sl@0
   587
	}
sl@0
   588
sl@0
   589
//
sl@0
   590
//	CTestInfo
sl@0
   591
//
sl@0
   592
CIpuTestHarness::CTestInfo::CTestInfo()
sl@0
   593
//
sl@0
   594
//	Default c'tor
sl@0
   595
	{
sl@0
   596
	}
sl@0
   597
sl@0
   598
CIpuTestHarness::CTestInfo::~CTestInfo()
sl@0
   599
//
sl@0
   600
//	D'tor
sl@0
   601
	{
sl@0
   602
	delete iName;
sl@0
   603
	}
sl@0
   604
sl@0
   605
CIpuTestHarness::CTestInfo* CIpuTestHarness::CTestInfo::NewLC(const TDesC& aName, TInt aNumber, TInt aErrorCode)
sl@0
   606
//
sl@0
   607
//	Static factory c'tor
sl@0
   608
	{
sl@0
   609
	CTestInfo* self = new (ELeave) CTestInfo();
sl@0
   610
	CleanupStack::PushL(self);
sl@0
   611
	self->ConstructL(aName, aNumber, aErrorCode);
sl@0
   612
	return self;
sl@0
   613
	}
sl@0
   614
sl@0
   615
CIpuTestHarness::CTestInfo* CIpuTestHarness::CTestInfo::NewL(const TDesC& aName, TInt aNumber, TInt aErrorCode)
sl@0
   616
//
sl@0
   617
//	Static factory c'tor
sl@0
   618
	{
sl@0
   619
	CTestInfo* self = NewLC(aName, aNumber, aErrorCode);
sl@0
   620
	CleanupStack::Pop();	//	self
sl@0
   621
	return self;
sl@0
   622
	}
sl@0
   623
sl@0
   624
void CIpuTestHarness::CTestInfo::ConstructL(const TDesC& aName, TInt aNumber, TInt aErrorCode)
sl@0
   625
//
sl@0
   626
//	Non-trivial c'tor
sl@0
   627
	{
sl@0
   628
	iName = aName.AllocLC();
sl@0
   629
	CleanupStack::Pop();	//	iName
sl@0
   630
sl@0
   631
	iNumber = aNumber;
sl@0
   632
	iErrorCode = aErrorCode;
sl@0
   633
	}
sl@0
   634
sl@0
   635
void CIpuTestHarness::CTestInfo::SetNameL(const TDesC& aName)
sl@0
   636
//
sl@0
   637
//	Sets iName
sl@0
   638
	{
sl@0
   639
	HBufC* temp = aName.AllocLC();
sl@0
   640
	CleanupStack::Pop();	//	temp
sl@0
   641
	delete iName;
sl@0
   642
	iName = temp;
sl@0
   643
	}
sl@0
   644
sl@0
   645
void CIpuTestHarness::CTestInfo::SetNumber(TInt aNumber)
sl@0
   646
//
sl@0
   647
//	Sets iNumber
sl@0
   648
	{
sl@0
   649
	iNumber = aNumber;
sl@0
   650
	}
sl@0
   651
sl@0
   652
void CIpuTestHarness::CTestInfo::SetErrorCode(TInt aErrorCode)
sl@0
   653
//
sl@0
   654
//	Sets iErrorCode
sl@0
   655
	{
sl@0
   656
	iErrorCode = aErrorCode;
sl@0
   657
	}