sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // testengine.cpp sl@0: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include // unicode builds sl@0: #include sl@0: #include sl@0: #include sl@0: #include // RTest headder sl@0: #include sl@0: #include sl@0: #include "testcaseroot.h" sl@0: #include "testcasecontroller.h" sl@0: #include "testengine.h" sl@0: sl@0: sl@0: sl@0: sl@0: CTestCaseController* CTestCaseController::NewL(CTestEngine& aTestEngine,TBool aHostRole) sl@0: { sl@0: CTestCaseController* self = new (ELeave) CTestCaseController(aTestEngine,aHostRole); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CTestCaseController::CTestCaseController(CTestEngine& aTestEngine,TBool aHostRole) sl@0: : CActive(EPriorityStandard), sl@0: iTestEngine(aTestEngine), sl@0: iHostRole(aHostRole) sl@0: { sl@0: // Add to current threads active scheduler sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: sl@0: CTestCaseController::~CTestCaseController() sl@0: { sl@0: // Cancel any outstanding test cases sl@0: Cancel(); sl@0: delete iTestPolicy; sl@0: } sl@0: sl@0: sl@0: void CTestCaseController::ConstructL() sl@0: { sl@0: TInt err(KErrNone); sl@0: sl@0: iTestPolicy = CBasicTestPolicy::NewL(); sl@0: sl@0: err = iTestEngine.NextTestCaseId(iTestCaseId); sl@0: if (err != KErrNone) sl@0: User::Leave(-2); sl@0: sl@0: test.Next(iTestCaseId); sl@0: // pass control to the test-policy (which merely instantiates and runs the test) sl@0: iTestPolicy->RunTestCaseL(iTestCaseId, &iStatus); sl@0: SetActive(); // when the 1st test finnishes, we drop into our own RunL active processing loop sl@0: } sl@0: sl@0: sl@0: void CTestCaseController::DoCancel() sl@0: { sl@0: // Cancel the outstanding test case running sl@0: iTestPolicy->Cancel(); sl@0: } sl@0: sl@0: sl@0: void CTestCaseController::RunL() sl@0: { sl@0: // Retrieve the completion code of the last test case run sl@0: TInt err(iStatus.Int()); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: test.Printf(_L(" Test case %lS failed\n"),&iTestCaseId); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("Test case %lS passed\n"),&iTestCaseId); sl@0: } sl@0: sl@0: // Find next test to run sl@0: err = iTestEngine.NextTestCaseId(iTestCaseId); sl@0: if (err == KErrNone) sl@0: { sl@0: test.Printf(_L("\n")); // ensures blank line between tests sl@0: test.Printf(_L("\n")); sl@0: test.Next(iTestCaseId); sl@0: sl@0: // run the next test here sl@0: iTestPolicy->RunTestCaseL(iTestCaseId, &iStatus); sl@0: SetActive(); sl@0: } sl@0: else if (err == KErrNotFound) sl@0: { sl@0: RDebug::Printf("All specified test cases performed"); sl@0: CActiveScheduler::Stop(); sl@0: } sl@0: else sl@0: { sl@0: RDebug::Printf(" Unknown error from CTestEngine::NextTestCaseId",err); sl@0: User::Leave(err); sl@0: } sl@0: } sl@0: sl@0: sl@0: TInt CTestCaseController::RunError(TInt aError) sl@0: { sl@0: LOG_FUNC sl@0: switch (aError) sl@0: { sl@0: case KErrNoMemory: sl@0: default: sl@0: // Panic the test module sl@0: test(EFalse); sl@0: break; sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: