os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcasecontroller.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcasecontroller.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,142 @@
     1.4 +// Copyright (c) 2007-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 the License "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 +// testengine.cpp
    1.18 +// @internalComponent
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +
    1.23 +#include <e32std.h>
    1.24 +#include <e32std_private.h>
    1.25 +#include <u32std.h> 	// unicode builds
    1.26 +#include <e32base.h>
    1.27 +#include <e32base_private.h>
    1.28 +#include <e32cons.h>
    1.29 +#include <e32Test.h>	// RTest headder
    1.30 +#include <e32def.h>
    1.31 +#include <e32def_private.h>
    1.32 +#include "testcaseroot.h"
    1.33 +#include "testcasecontroller.h"
    1.34 +#include "testengine.h"
    1.35 +
    1.36 +
    1.37 +
    1.38 +	
    1.39 +CTestCaseController* CTestCaseController::NewL(CTestEngine& aTestEngine,TBool aHostRole)
    1.40 +	{
    1.41 +	CTestCaseController* self = new (ELeave) CTestCaseController(aTestEngine,aHostRole);
    1.42 +	CleanupStack::PushL(self);
    1.43 +	self->ConstructL();
    1.44 +	CleanupStack::Pop(self);
    1.45 +	return self;
    1.46 +	}
    1.47 +	
    1.48 +	
    1.49 +CTestCaseController::CTestCaseController(CTestEngine& aTestEngine,TBool aHostRole)
    1.50 +:	CActive(EPriorityStandard),
    1.51 +	iTestEngine(aTestEngine),
    1.52 +	iHostRole(aHostRole)
    1.53 +	{
    1.54 +	// Add to current threads active scheduler
    1.55 +	CActiveScheduler::Add(this);
    1.56 +	}
    1.57 +	
    1.58 +	
    1.59 +CTestCaseController::~CTestCaseController()
    1.60 +	{
    1.61 +	// Cancel any outstanding test cases
    1.62 +	Cancel();
    1.63 +	delete iTestPolicy;	
    1.64 +	}
    1.65 +
    1.66 +
    1.67 +void CTestCaseController::ConstructL()
    1.68 +	{
    1.69 +	TInt err(KErrNone);
    1.70 +	
    1.71 +	iTestPolicy = CBasicTestPolicy::NewL();
    1.72 +	
    1.73 +	err = iTestEngine.NextTestCaseId(iTestCaseId);
    1.74 +	if (err != KErrNone)
    1.75 +		User::Leave(-2);
    1.76 +	
    1.77 +	test.Next(iTestCaseId);
    1.78 +	// pass control to the test-policy (which merely instantiates and runs the test)
    1.79 +	iTestPolicy->RunTestCaseL(iTestCaseId, &iStatus);
    1.80 +	SetActive(); // when the 1st test finnishes, we drop into our own RunL active processing loop
    1.81 +	}
    1.82 +	
    1.83 +
    1.84 +void CTestCaseController::DoCancel()
    1.85 +	{
    1.86 +	// Cancel the outstanding test case running
    1.87 +	iTestPolicy->Cancel();
    1.88 +	}
    1.89 +	
    1.90 +	
    1.91 +void CTestCaseController::RunL()
    1.92 +	{
    1.93 +	// Retrieve the completion code of the last test case run
    1.94 +	TInt err(iStatus.Int());
    1.95 +	
    1.96 +	if (err != KErrNone)
    1.97 +		{
    1.98 +		test.Printf(_L("<Error> Test case %lS failed\n"),&iTestCaseId);
    1.99 +		}
   1.100 +	else
   1.101 +		{
   1.102 +		test.Printf(_L("Test case %lS passed\n"),&iTestCaseId);
   1.103 +		}
   1.104 +		
   1.105 +	// Find next test to run	
   1.106 +	err = iTestEngine.NextTestCaseId(iTestCaseId);
   1.107 +	if (err == KErrNone)
   1.108 +		{
   1.109 +		test.Printf(_L("\n"));	// ensures blank line between tests
   1.110 +		test.Printf(_L("\n"));
   1.111 +		test.Next(iTestCaseId);
   1.112 +		
   1.113 +		// run the next test here
   1.114 +		iTestPolicy->RunTestCaseL(iTestCaseId, &iStatus);
   1.115 +		SetActive();
   1.116 +		}
   1.117 +	else if (err == KErrNotFound)
   1.118 +		{
   1.119 +		RDebug::Printf("All specified test cases performed");
   1.120 +		CActiveScheduler::Stop();
   1.121 +		}
   1.122 +	else
   1.123 +		{
   1.124 +		RDebug::Printf("<Error %d> Unknown error from CTestEngine::NextTestCaseId",err);
   1.125 +		User::Leave(err);
   1.126 +		}
   1.127 +	}
   1.128 +	
   1.129 +	
   1.130 +TInt CTestCaseController::RunError(TInt aError)
   1.131 +	{
   1.132 +	LOG_FUNC
   1.133 +	switch (aError)
   1.134 +		{
   1.135 +		case KErrNoMemory:
   1.136 +		default:
   1.137 +			// Panic the test module
   1.138 +			test(EFalse);
   1.139 +			break;
   1.140 +		}
   1.141 +	return KErrNone;
   1.142 +	}
   1.143 +
   1.144 +
   1.145 +