os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/exampletestcase.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
// @internalComponent
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
sl@0
    19
#include <e32std.h>
sl@0
    20
#include <e32std_private.h>
sl@0
    21
#include <u32std.h> 	// unicode builds
sl@0
    22
#include <e32base.h>
sl@0
    23
#include <e32base_private.h>
sl@0
    24
#include <e32cons.h>
sl@0
    25
#include <e32Test.h>	// RTest headder
sl@0
    26
#include "testcaseroot.h"
sl@0
    27
#include "testcasewd.h"
sl@0
    28
#include "testcasefactory.h"
sl@0
    29
#include "exampletestcase.h"
sl@0
    30
sl@0
    31
sl@0
    32
sl@0
    33
// the name below is used to add a pointer to our construction method to a pointer MAP in 
sl@0
    34
// the class factory
sl@0
    35
_LIT(KTestCaseId,"EXAMPLETESTCASE");
sl@0
    36
sl@0
    37
// UNcomment the next line to add the test to the catalog(factory)
sl@0
    38
const TTestCaseFactoryReceipt<CExampleTestCase> CExampleTestCase::iFactoryReceipt(KTestCaseId);	
sl@0
    39
sl@0
    40
CExampleTestCase* CExampleTestCase::NewL(TBool aHost)
sl@0
    41
	{
sl@0
    42
	LOG_FUNC
sl@0
    43
	CExampleTestCase* self = new (ELeave) CExampleTestCase(aHost);
sl@0
    44
	CleanupStack::PushL(self);
sl@0
    45
	self->ConstructL();
sl@0
    46
	CleanupStack::Pop(self);
sl@0
    47
	return self;
sl@0
    48
	}
sl@0
    49
	
sl@0
    50
sl@0
    51
CExampleTestCase::CExampleTestCase(TBool aHost)
sl@0
    52
:	CTestCaseRoot(KTestCaseId, aHost)
sl@0
    53
	{
sl@0
    54
	LOG_FUNC
sl@0
    55
	} 
sl@0
    56
sl@0
    57
sl@0
    58
void CExampleTestCase::ConstructL()
sl@0
    59
	{
sl@0
    60
	LOG_FUNC
sl@0
    61
	BaseConstructL();
sl@0
    62
	iWDTimer = CTestCaseWatchdog::NewL();
sl@0
    63
	}
sl@0
    64
sl@0
    65
sl@0
    66
CExampleTestCase::~CExampleTestCase()
sl@0
    67
	{
sl@0
    68
	LOG_FUNC
sl@0
    69
sl@0
    70
	delete iWDTimer;
sl@0
    71
	Cancel();
sl@0
    72
	}
sl@0
    73
sl@0
    74
sl@0
    75
void CExampleTestCase::ExecuteTestCaseL()
sl@0
    76
	{
sl@0
    77
	LOG_FUNC
sl@0
    78
	iCaseStep = EFirstStep;
sl@0
    79
sl@0
    80
	//	
sl@0
    81
	CActiveScheduler::Add(this);
sl@0
    82
	// run our root RunL()
sl@0
    83
	SelfComplete();
sl@0
    84
sl@0
    85
	}
sl@0
    86
sl@0
    87
void CExampleTestCase::DescribePreconditions()
sl@0
    88
	{
sl@0
    89
	test.Printf(_L("This is an example test, there is nothing to do beforehand.\n"));
sl@0
    90
	}
sl@0
    91
	
sl@0
    92
void CExampleTestCase::DoCancel()
sl@0
    93
	{
sl@0
    94
	LOG_FUNC
sl@0
    95
sl@0
    96
	}
sl@0
    97
sl@0
    98
sl@0
    99
void CExampleTestCase::ProcessKey(TKeyCode &aKey)
sl@0
   100
	{	// the default implementation does this already, but we will store the key here again anyway
sl@0
   101
	iKeyCodeInput = aKey;
sl@0
   102
sl@0
   103
	}
sl@0
   104
sl@0
   105
void CExampleTestCase::FuncA(CTestCaseRoot *pThis)
sl@0
   106
	{
sl@0
   107
	CExampleTestCase * p = REINTERPRET_CAST(CExampleTestCase *,pThis);
sl@0
   108
	// cancel any pending call, and then complete our active obj with a timeout value
sl@0
   109
	test.Printf(_L("@@@ FuncA cancel a keyboard Read() @@@\n"));
sl@0
   110
sl@0
   111
	p->iConsole->ReadCancel();
sl@0
   112
sl@0
   113
	}
sl@0
   114
sl@0
   115
void CExampleTestCase::FuncB(CTestCaseRoot *pThis)
sl@0
   116
	{
sl@0
   117
	CExampleTestCase * p = REINTERPRET_CAST(CExampleTestCase *,pThis);
sl@0
   118
	// cancel any pending call, and then complete our active obj with a timeout value
sl@0
   119
	test.Printf(_L("@@@ FuncB cancel a 'B' keyboard Read() @@@\n"));
sl@0
   120
sl@0
   121
	p->Cancel();
sl@0
   122
	p->iConsole->ReadCancel();
sl@0
   123
sl@0
   124
	TRequestStatus* s = &p->iStatus;
sl@0
   125
	p->iStatus = KRequestPending;
sl@0
   126
sl@0
   127
	p->SetActive();
sl@0
   128
	User::RequestComplete(s, KTestCaseWatchdogTO);
sl@0
   129
sl@0
   130
	}
sl@0
   131
sl@0
   132
sl@0
   133
// handle event completion	
sl@0
   134
void CExampleTestCase::RunStepL()
sl@0
   135
	{
sl@0
   136
	LOG_FUNC
sl@0
   137
sl@0
   138
	// Obtain the completion code for this CActive obj.
sl@0
   139
	TInt completionCode(iStatus.Int()); 
sl@0
   140
	RDebug::Printf("Example test iStatus compl.=%d\n", completionCode);
sl@0
   141
	//test.Printf(_L("Example test iStatus compl.=%d\n"), completionCode);
sl@0
   142
sl@0
   143
	switch(iCaseStep)
sl@0
   144
		{
sl@0
   145
		case EFirstStep:
sl@0
   146
			iCaseStep=ESecondStep;
sl@0
   147
			test.Printf(_L("Test step 1\n"));
sl@0
   148
sl@0
   149
			SelfComplete();
sl@0
   150
			break;
sl@0
   151
		case ESecondStep:
sl@0
   152
			iCaseStep=EThirdStep;
sl@0
   153
			test.Printf(_L("Test step 2\n"));
sl@0
   154
			test.Printf(_L("(this test step uses Keyboard)\n"));
sl@0
   155
			test.Printf(_L("Press ANY key once you have removed the 'A' connector...\n"));
sl@0
   156
			RequestCharacter();
sl@0
   157
			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &FuncA);
sl@0
   158
			break;
sl@0
   159
		case EThirdStep:
sl@0
   160
			test.Printf(_L("key was a '%c'\n"), iKeyCodeInput);
sl@0
   161
			iWDTimer->Cancel();
sl@0
   162
			iCaseStep=EFourthStep;
sl@0
   163
			test.Printf(_L("Test step 3\n"));
sl@0
   164
			test.Printf(_L("(this test step uses Keyboard)\n"));
sl@0
   165
			test.Printf(_L("Press <SPACE> key once you have removed the 'A' connector...\n"));
sl@0
   166
			RequestCharacter();
sl@0
   167
			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &FuncB);
sl@0
   168
			
sl@0
   169
			break;
sl@0
   170
		case EFourthStep:
sl@0
   171
			test.Printf(_L("key was a '%c'\n"), iKeyCodeInput);
sl@0
   172
			test.Printf(_L("Test step 4\n"));
sl@0
   173
			iWDTimer->Cancel();
sl@0
   174
sl@0
   175
			iCaseStep=EFifthStep;
sl@0
   176
			if (' ' != iKeyCodeInput)
sl@0
   177
				{
sl@0
   178
				
sl@0
   179
				iCaseStep=EThirdStep;
sl@0
   180
				}
sl@0
   181
			SelfComplete();
sl@0
   182
			break;
sl@0
   183
		case EFifthStep:
sl@0
   184
			iCaseStep=ESixthStep;
sl@0
   185
			test.Printf(_L("Test step 5\n"));
sl@0
   186
			test.Printf(_L("(this test uses a delay)\n"));
sl@0
   187
			iTimer.After(iStatus, 500000);
sl@0
   188
			SetActive();
sl@0
   189
			break;
sl@0
   190
		case ESixthStep:
sl@0
   191
			iCaseStep=ELastStep;
sl@0
   192
			test.Printf(_L("Test step 6(%d)\n"), completionCode);
sl@0
   193
			RequestCharacter();
sl@0
   194
			iConsole->ReadCancel();
sl@0
   195
			Cancel();
sl@0
   196
			RequestCharacter();
sl@0
   197
			
sl@0
   198
			//SelfComplete();
sl@0
   199
			break;
sl@0
   200
		case ELastStep:
sl@0
   201
			iCaseStep=ESecondStep;
sl@0
   202
			test.Printf(_L("LAST step7 code (%d)\n"), completionCode);
sl@0
   203
			TestPolicy().SignalTestComplete(KErrNone);
sl@0
   204
			return TestPassed();
sl@0
   205
			//break;
sl@0
   206
sl@0
   207
		default:
sl@0
   208
			//test.Printf(_L("<Error> unknown test step"));
sl@0
   209
			Cancel();
sl@0
   210
			TestFailed(KErrCorrupt, _L("unknown test step"));
sl@0
   211
			break;
sl@0
   212
		}
sl@0
   213
	
sl@0
   214
	}
sl@0
   215
sl@0
   216