os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcasecontroller.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-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 the License "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
// testengine.cpp
sl@0
    15
// @internalComponent
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
sl@0
    20
#include <e32std.h>
sl@0
    21
#include <e32std_private.h>
sl@0
    22
#include <u32std.h> 	// unicode builds
sl@0
    23
#include <e32base.h>
sl@0
    24
#include <e32base_private.h>
sl@0
    25
#include <e32cons.h>
sl@0
    26
#include <e32Test.h>	// RTest headder
sl@0
    27
#include <e32def.h>
sl@0
    28
#include <e32def_private.h>
sl@0
    29
#include "testcaseroot.h"
sl@0
    30
#include "testcasecontroller.h"
sl@0
    31
#include "testengine.h"
sl@0
    32
sl@0
    33
sl@0
    34
sl@0
    35
	
sl@0
    36
CTestCaseController* CTestCaseController::NewL(CTestEngine& aTestEngine,TBool aHostRole)
sl@0
    37
	{
sl@0
    38
	CTestCaseController* self = new (ELeave) CTestCaseController(aTestEngine,aHostRole);
sl@0
    39
	CleanupStack::PushL(self);
sl@0
    40
	self->ConstructL();
sl@0
    41
	CleanupStack::Pop(self);
sl@0
    42
	return self;
sl@0
    43
	}
sl@0
    44
	
sl@0
    45
	
sl@0
    46
CTestCaseController::CTestCaseController(CTestEngine& aTestEngine,TBool aHostRole)
sl@0
    47
:	CActive(EPriorityStandard),
sl@0
    48
	iTestEngine(aTestEngine),
sl@0
    49
	iHostRole(aHostRole)
sl@0
    50
	{
sl@0
    51
	// Add to current threads active scheduler
sl@0
    52
	CActiveScheduler::Add(this);
sl@0
    53
	}
sl@0
    54
	
sl@0
    55
	
sl@0
    56
CTestCaseController::~CTestCaseController()
sl@0
    57
	{
sl@0
    58
	// Cancel any outstanding test cases
sl@0
    59
	Cancel();
sl@0
    60
	delete iTestPolicy;	
sl@0
    61
	}
sl@0
    62
sl@0
    63
sl@0
    64
void CTestCaseController::ConstructL()
sl@0
    65
	{
sl@0
    66
	TInt err(KErrNone);
sl@0
    67
	
sl@0
    68
	iTestPolicy = CBasicTestPolicy::NewL();
sl@0
    69
	
sl@0
    70
	err = iTestEngine.NextTestCaseId(iTestCaseId);
sl@0
    71
	if (err != KErrNone)
sl@0
    72
		User::Leave(-2);
sl@0
    73
	
sl@0
    74
	test.Next(iTestCaseId);
sl@0
    75
	// pass control to the test-policy (which merely instantiates and runs the test)
sl@0
    76
	iTestPolicy->RunTestCaseL(iTestCaseId, &iStatus);
sl@0
    77
	SetActive(); // when the 1st test finnishes, we drop into our own RunL active processing loop
sl@0
    78
	}
sl@0
    79
	
sl@0
    80
sl@0
    81
void CTestCaseController::DoCancel()
sl@0
    82
	{
sl@0
    83
	// Cancel the outstanding test case running
sl@0
    84
	iTestPolicy->Cancel();
sl@0
    85
	}
sl@0
    86
	
sl@0
    87
	
sl@0
    88
void CTestCaseController::RunL()
sl@0
    89
	{
sl@0
    90
	// Retrieve the completion code of the last test case run
sl@0
    91
	TInt err(iStatus.Int());
sl@0
    92
	
sl@0
    93
	if (err != KErrNone)
sl@0
    94
		{
sl@0
    95
		test.Printf(_L("<Error> Test case %lS failed\n"),&iTestCaseId);
sl@0
    96
		}
sl@0
    97
	else
sl@0
    98
		{
sl@0
    99
		test.Printf(_L("Test case %lS passed\n"),&iTestCaseId);
sl@0
   100
		}
sl@0
   101
		
sl@0
   102
	// Find next test to run	
sl@0
   103
	err = iTestEngine.NextTestCaseId(iTestCaseId);
sl@0
   104
	if (err == KErrNone)
sl@0
   105
		{
sl@0
   106
		test.Printf(_L("\n"));	// ensures blank line between tests
sl@0
   107
		test.Printf(_L("\n"));
sl@0
   108
		test.Next(iTestCaseId);
sl@0
   109
		
sl@0
   110
		// run the next test here
sl@0
   111
		iTestPolicy->RunTestCaseL(iTestCaseId, &iStatus);
sl@0
   112
		SetActive();
sl@0
   113
		}
sl@0
   114
	else if (err == KErrNotFound)
sl@0
   115
		{
sl@0
   116
		RDebug::Printf("All specified test cases performed");
sl@0
   117
		CActiveScheduler::Stop();
sl@0
   118
		}
sl@0
   119
	else
sl@0
   120
		{
sl@0
   121
		RDebug::Printf("<Error %d> Unknown error from CTestEngine::NextTestCaseId",err);
sl@0
   122
		User::Leave(err);
sl@0
   123
		}
sl@0
   124
	}
sl@0
   125
	
sl@0
   126
	
sl@0
   127
TInt CTestCaseController::RunError(TInt aError)
sl@0
   128
	{
sl@0
   129
	LOG_FUNC
sl@0
   130
	switch (aError)
sl@0
   131
		{
sl@0
   132
		case KErrNoMemory:
sl@0
   133
		default:
sl@0
   134
			// Panic the test module
sl@0
   135
			test(EFalse);
sl@0
   136
			break;
sl@0
   137
		}
sl@0
   138
	return KErrNone;
sl@0
   139
	}
sl@0
   140
sl@0
   141
sl@0
   142