Update contrib.
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
 
     2 // All rights reserved.
 
     3 // This component and the accompanying materials are made available
 
     4 // under the terms of the License "Eclipse Public License v1.0"
 
     5 // which accompanies this distribution, and is available
 
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
 
     8 // Initial Contributors:
 
     9 // Nokia Corporation - initial contribution.
 
    17 #include "t_framework.h"
 
    19 RTest test(RProcess().FileName());
 
    21 CTestProgram::CTestProgram(const TDesC& aName) : iName(aName) 
 
    23 	iThreadId = RThread().Id();
 
    26 void CTestProgram::Panic()
 
    28 	TPtrC8 fd((TUint8*)iFile);
 
    29 	TPtrC8 cd((TUint8*)iCond);
 
    31 	HBufC* fhb = HBufC::NewMax(fd.Length());
 
    33 	HBufC* chb = HBufC::NewMax(cd.Length());
 
    39 	test.Panic(iError, _L("Test '%S' Fails;\nCond: '%S'; File: '%S'; Line %d;\n"), &iName, chb, fhb, iLine);
 
    42 void CTestProgram::Panic(TInt aError, char* aCond, char* aFile, TInt aLine)
 
    48 	if (iThreadId != RThread().Id())
 
    51 		thr.Panic(_L("FAIL"), aError);
 
    56 void CTestProgram::Launch(TUint aCount)
 
    58 	// Remember the number of open handles. Just for a sanity check ....
 
    59 	TInt start_thc, start_phc;
 
    60 	RThread().HandleCount(start_phc, start_thc);
 
    61 	TF_ERROR(RThread().RequestCount(), RThread().RequestCount() == 0);
 
    66 	// Sanity check for open handles
 
    67 	TInt end_thc, end_phc;
 
    68 	RThread().HandleCount(end_phc, end_thc);
 
    69 	TF_ERROR(end_thc - start_thc, start_thc == end_thc);
 
    70 	TF_ERROR(end_phc - start_phc, start_phc == end_phc);
 
    71 		// and also for pending requests ...
 
    72 	TF_ERROR(RThread().RequestCount(), RThread().RequestCount() == 0);
 
    75 void CTestProgram::LaunchGroup(CTestProgram** aGroup, TUint aCount)
 
    77 	for (CTestProgram** progP = aGroup; *progP; ++progP)
 
    79 		CTestProgram* prog = *progP;
 
    84 TInt CTestProgram::ThreadEntry(TAny* a)
 
    86 	CTestProgram* prog = (CTestProgram*) a;
 
    87 	prog->Run(prog->iCount);
 
    91 void CTestProgram::Spawn(TUint aCount)
 
    95 	iStatus = KRequestPending;
 
    97 	TInt r = thr.Create(KNullDesC, ThreadEntry, 0x2000, NULL, this);
 
    98 	TF_ERROR(r, r == KErrNone);
 
    99 	thr.NotifyDestruction(iDestroyStatus);
 
   105 void CTestProgram::Wait()
 
   107 	User::WaitForRequest(iStatus);
 
   108 	if (iStatus.Int() != KErrNone)
 
   112 	User::WaitForRequest(iDestroyStatus);
 
   113 	if (iDestroyStatus.Int() != KErrNone)
 
   119 void CTestProgram::SpawnGroup(CTestProgram** aGroup, TUint aCount)
 
   121 	test.Start(_L("=== Start Parallel Testing ==="));
 
   122 	CTestProgram** progP;
 
   123 	for (progP = aGroup; *progP; ++progP)
 
   125 		CTestProgram* prog = *progP;
 
   128 	for (progP = aGroup; *progP; ++progP)
 
   130 		CTestProgram* prog = *progP;
 
   133 	test.Next(_L("=== End Parallel Testing ==="));
 
   137 void CTestProgram::Exec(const TDesC& aFile, TAny* args, TInt size)
 
   140 	// Create the child process and pass args as a UNICODE command line.
 
   141 	// (we suppose that the args size is multiple of sizeof(TUint16))
 
   144 	TInt r = proc.Create(aFile, TPtrC((TUint16*) args, size/sizeof(TUint16)));
 
   145 	TF_ERROR(r, r == KErrNone);
 
   146 	TRequestStatus status;
 
   149 	User::WaitForRequest(status);
 
   150 	TF_ERROR(status.Int(), status.Int() == KErrNone);
 
   154 void CTestProgram::Start()
 
   157 	test.Start(_L("GO!"));
 
   160 void CTestProgram::End()