kerneltest/e32test/usbho/t_otgdi/src/exampletestcase.cpp
changeset 253 d37db4dcc88d
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
252:0a40b8675b23 253:d37db4dcc88d
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    25 #include <e32Test.h>	// RTest headder
    25 #include <e32Test.h>	// RTest headder
    26 #include "testcaseroot.h"
    26 #include "testcaseroot.h"
    27 #include "testcasewd.h"
    27 #include "testcasewd.h"
    28 #include "testcasefactory.h"
    28 #include "testcasefactory.h"
    29 #include "exampletestcase.h"
    29 #include "exampletestcase.h"
       
    30 #include "OstTraceDefinitions.h"
       
    31 #ifdef OST_TRACE_COMPILER_IN_USE
       
    32 #include "exampletestcaseTraces.h"
       
    33 #endif
    30 
    34 
    31 
    35 
    32 
    36 
    33 // the name below is used to add a pointer to our construction method to a pointer MAP in 
    37 // the name below is used to add a pointer to our construction method to a pointer MAP in 
    34 // the class factory
    38 // the class factory
    37 // UNcomment the next line to add the test to the catalog(factory)
    41 // UNcomment the next line to add the test to the catalog(factory)
    38 const TTestCaseFactoryReceipt<CExampleTestCase> CExampleTestCase::iFactoryReceipt(KTestCaseId);	
    42 const TTestCaseFactoryReceipt<CExampleTestCase> CExampleTestCase::iFactoryReceipt(KTestCaseId);	
    39 
    43 
    40 CExampleTestCase* CExampleTestCase::NewL(TBool aHost)
    44 CExampleTestCase* CExampleTestCase::NewL(TBool aHost)
    41 	{
    45 	{
    42 	LOG_FUNC
    46 	if(gVerboseOutput)
       
    47 	    {
       
    48 	    OstTraceFunctionEntry0(CEXAMPLETESTCASE_NEWL);
       
    49 	    }
    43 	CExampleTestCase* self = new (ELeave) CExampleTestCase(aHost);
    50 	CExampleTestCase* self = new (ELeave) CExampleTestCase(aHost);
    44 	CleanupStack::PushL(self);
    51 	CleanupStack::PushL(self);
    45 	self->ConstructL();
    52 	self->ConstructL();
    46 	CleanupStack::Pop(self);
    53 	CleanupStack::Pop(self);
    47 	return self;
    54 	return self;
    49 	
    56 	
    50 
    57 
    51 CExampleTestCase::CExampleTestCase(TBool aHost)
    58 CExampleTestCase::CExampleTestCase(TBool aHost)
    52 :	CTestCaseRoot(KTestCaseId, aHost)
    59 :	CTestCaseRoot(KTestCaseId, aHost)
    53 	{
    60 	{
    54 	LOG_FUNC
    61 	if(gVerboseOutput)
       
    62 	    {
       
    63 	    OstTraceFunctionEntry0(CEXAMPLETESTCASE_CEXAMPLETESTCASE);
       
    64 	    }
    55 	} 
    65 	} 
    56 
    66 
    57 
    67 
    58 void CExampleTestCase::ConstructL()
    68 void CExampleTestCase::ConstructL()
    59 	{
    69 	{
    60 	LOG_FUNC
    70 	if(gVerboseOutput)
       
    71 	    {
       
    72 	    OstTraceFunctionEntry0(CEXAMPLETESTCASE_CONSTRUCTL);
       
    73 	    }
    61 	BaseConstructL();
    74 	BaseConstructL();
    62 	iWDTimer = CTestCaseWatchdog::NewL();
    75 	iWDTimer = CTestCaseWatchdog::NewL();
    63 	}
    76 	}
    64 
    77 
    65 
    78 
    66 CExampleTestCase::~CExampleTestCase()
    79 CExampleTestCase::~CExampleTestCase()
    67 	{
    80 	{
    68 	LOG_FUNC
    81 	if(gVerboseOutput)
       
    82 	    {
       
    83 	    OstTraceFunctionEntry0(CEXAMPLETESTCASE_DCEXAMPLETESTCASE);
       
    84 	    }
    69 
    85 
    70 	delete iWDTimer;
    86 	delete iWDTimer;
    71 	Cancel();
    87 	Cancel();
    72 	}
    88 	}
    73 
    89 
    74 
    90 
    75 void CExampleTestCase::ExecuteTestCaseL()
    91 void CExampleTestCase::ExecuteTestCaseL()
    76 	{
    92 	{
    77 	LOG_FUNC
    93 	if(gVerboseOutput)
       
    94 	    {
       
    95 	    OstTraceFunctionEntry0(CEXAMPLETESTCASE_EXECUTETESTCASEL);
       
    96 	    }
    78 	iCaseStep = EFirstStep;
    97 	iCaseStep = EFirstStep;
    79 
    98 
    80 	//	
    99 	//	
    81 	CActiveScheduler::Add(this);
   100 	CActiveScheduler::Add(this);
    82 	// run our root RunL()
   101 	// run our root RunL()
    85 	}
   104 	}
    86 
   105 
    87 void CExampleTestCase::DescribePreconditions()
   106 void CExampleTestCase::DescribePreconditions()
    88 	{
   107 	{
    89 	test.Printf(_L("This is an example test, there is nothing to do beforehand.\n"));
   108 	test.Printf(_L("This is an example test, there is nothing to do beforehand.\n"));
       
   109 	OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_DESCRIBEPRECONDITIONS, "This is an example test, there is nothing to do beforehand.\n");
    90 	}
   110 	}
    91 	
   111 	
    92 void CExampleTestCase::DoCancel()
   112 void CExampleTestCase::DoCancel()
    93 	{
   113 	{
    94 	LOG_FUNC
   114 	if(gVerboseOutput)
       
   115 	    {
       
   116 	    OstTraceFunctionEntry0(CEXAMPLETESTCASE_DOCANCEL);
       
   117 	    }
    95 
   118 
    96 	}
   119 	}
    97 
   120 
    98 
   121 
    99 void CExampleTestCase::ProcessKey(TKeyCode &aKey)
   122 void CExampleTestCase::ProcessKey(TKeyCode &aKey)
   105 void CExampleTestCase::FuncA(CTestCaseRoot *pThis)
   128 void CExampleTestCase::FuncA(CTestCaseRoot *pThis)
   106 	{
   129 	{
   107 	CExampleTestCase * p = REINTERPRET_CAST(CExampleTestCase *,pThis);
   130 	CExampleTestCase * p = REINTERPRET_CAST(CExampleTestCase *,pThis);
   108 	// cancel any pending call, and then complete our active obj with a timeout value
   131 	// cancel any pending call, and then complete our active obj with a timeout value
   109 	test.Printf(_L("@@@ FuncA cancel a keyboard Read() @@@\n"));
   132 	test.Printf(_L("@@@ FuncA cancel a keyboard Read() @@@\n"));
       
   133 	OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_FUNCA, "@@@ FuncA cancel a keyboard Read(@@@\n"));
   110 
   134 
   111 	p->iConsole->ReadCancel();
   135 	p->iConsole->ReadCancel();
   112 
   136 
   113 	}
   137 	}
   114 
   138 
   115 void CExampleTestCase::FuncB(CTestCaseRoot *pThis)
   139 void CExampleTestCase::FuncB(CTestCaseRoot *pThis)
   116 	{
   140 	{
   117 	CExampleTestCase * p = REINTERPRET_CAST(CExampleTestCase *,pThis);
   141 	CExampleTestCase * p = REINTERPRET_CAST(CExampleTestCase *,pThis);
   118 	// cancel any pending call, and then complete our active obj with a timeout value
   142 	// cancel any pending call, and then complete our active obj with a timeout value
   119 	test.Printf(_L("@@@ FuncB cancel a 'B' keyboard Read() @@@\n"));
   143 	test.Printf(_L("@@@ FuncB cancel a 'B' keyboard Read() @@@\n"));
       
   144 	OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_FUNCB, "@@@ FuncB cancel a 'B' keyboard Read(@@@\n"));
   120 
   145 
   121 	p->Cancel();
   146 	p->Cancel();
   122 	p->iConsole->ReadCancel();
   147 	p->iConsole->ReadCancel();
   123 
   148 
   124 	TRequestStatus* s = &p->iStatus;
   149 	TRequestStatus* s = &p->iStatus;
   131 
   156 
   132 
   157 
   133 // handle event completion	
   158 // handle event completion	
   134 void CExampleTestCase::RunStepL()
   159 void CExampleTestCase::RunStepL()
   135 	{
   160 	{
   136 	LOG_FUNC
   161 	if(gVerboseOutput)
       
   162 	    {
       
   163 	    OstTraceFunctionEntry0(CEXAMPLETESTCASE_RUNSTEPL);
       
   164 	    }
   137 
   165 
   138 	// Obtain the completion code for this CActive obj.
   166 	// Obtain the completion code for this CActive obj.
   139 	TInt completionCode(iStatus.Int()); 
   167 	TInt completionCode(iStatus.Int()); 
   140 	RDebug::Printf("Example test iStatus compl.=%d\n", completionCode);
   168 	OstTrace1(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP01, "Example test iStatus compl.=%d\n", completionCode);
   141 	//test.Printf(_L("Example test iStatus compl.=%d\n"), completionCode);
       
   142 
   169 
   143 	switch(iCaseStep)
   170 	switch(iCaseStep)
   144 		{
   171 		{
   145 		case EFirstStep:
   172 		case EFirstStep:
   146 			iCaseStep=ESecondStep;
   173 			iCaseStep=ESecondStep;
   147 			test.Printf(_L("Test step 1\n"));
   174 			test.Printf(_L("Test step 1\n"));
       
   175 			OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP03, "Test step 1\n");
   148 
   176 
   149 			SelfComplete();
   177 			SelfComplete();
   150 			break;
   178 			break;
   151 		case ESecondStep:
   179 		case ESecondStep:
   152 			iCaseStep=EThirdStep;
   180 			iCaseStep=EThirdStep;
   153 			test.Printf(_L("Test step 2\n"));
   181 			test.Printf(_L("Test step 2\n"));
       
   182 			OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP04, "Test step 2\n");
   154 			test.Printf(_L("(this test step uses Keyboard)\n"));
   183 			test.Printf(_L("(this test step uses Keyboard)\n"));
       
   184 			OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP05, "(this test step uses Keyboard\n"));
   155 			test.Printf(_L("Press ANY key once you have removed the 'A' connector...\n"));
   185 			test.Printf(_L("Press ANY key once you have removed the 'A' connector...\n"));
       
   186 			OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP06, "Press ANY key once you have removed the 'A' connector...\n");
   156 			RequestCharacter();
   187 			RequestCharacter();
   157 			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &FuncA);
   188 			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &FuncA);
   158 			break;
   189 			break;
   159 		case EThirdStep:
   190 		case EThirdStep:
   160 			test.Printf(_L("key was a '%c'\n"), iKeyCodeInput);
   191 			test.Printf(_L("key was a '%c'\n"), iKeyCodeInput);
       
   192 			OstTrace1(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP07, "key was a '%c'\n", iKeyCodeInput);
   161 			iWDTimer->Cancel();
   193 			iWDTimer->Cancel();
   162 			iCaseStep=EFourthStep;
   194 			iCaseStep=EFourthStep;
   163 			test.Printf(_L("Test step 3\n"));
   195 			test.Printf(_L("Test step 3\n"));
       
   196 			OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP08, "Test step 3\n");
   164 			test.Printf(_L("(this test step uses Keyboard)\n"));
   197 			test.Printf(_L("(this test step uses Keyboard)\n"));
       
   198 			OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP09, "(this test step uses Keyboard\n"));
   165 			test.Printf(_L("Press <SPACE> key once you have removed the 'A' connector...\n"));
   199 			test.Printf(_L("Press <SPACE> key once you have removed the 'A' connector...\n"));
       
   200 			OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP10, "Press <SPACE> key once you have removed the 'A' connector...\n");
   166 			RequestCharacter();
   201 			RequestCharacter();
   167 			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &FuncB);
   202 			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &FuncB);
   168 			
   203 			
   169 			break;
   204 			break;
   170 		case EFourthStep:
   205 		case EFourthStep:
   171 			test.Printf(_L("key was a '%c'\n"), iKeyCodeInput);
   206 			test.Printf(_L("key was a '%c'\n"), iKeyCodeInput);
       
   207 			OstTrace1(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP11, "key was a '%c'\n", iKeyCodeInput);
   172 			test.Printf(_L("Test step 4\n"));
   208 			test.Printf(_L("Test step 4\n"));
       
   209 			OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP12, "Test step 4\n");
   173 			iWDTimer->Cancel();
   210 			iWDTimer->Cancel();
   174 
   211 
   175 			iCaseStep=EFifthStep;
   212 			iCaseStep=EFifthStep;
   176 			if (' ' != iKeyCodeInput)
   213 			if (' ' != iKeyCodeInput)
   177 				{
   214 				{
   181 			SelfComplete();
   218 			SelfComplete();
   182 			break;
   219 			break;
   183 		case EFifthStep:
   220 		case EFifthStep:
   184 			iCaseStep=ESixthStep;
   221 			iCaseStep=ESixthStep;
   185 			test.Printf(_L("Test step 5\n"));
   222 			test.Printf(_L("Test step 5\n"));
       
   223 			OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP13, "Test step 5\n");
   186 			test.Printf(_L("(this test uses a delay)\n"));
   224 			test.Printf(_L("(this test uses a delay)\n"));
       
   225 			OstTrace0(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP14, "(this test uses a delay\n"));
   187 			iTimer.After(iStatus, 500000);
   226 			iTimer.After(iStatus, 500000);
   188 			SetActive();
   227 			SetActive();
   189 			break;
   228 			break;
   190 		case ESixthStep:
   229 		case ESixthStep:
   191 			iCaseStep=ELastStep;
   230 			iCaseStep=ELastStep;
   192 			test.Printf(_L("Test step 6(%d)\n"), completionCode);
   231 			test.Printf(_L("Test step 6(%d)\n"), completionCode);
       
   232 			OstTrace1(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP15, "Test step 6(%d)\n", completionCode);
   193 			RequestCharacter();
   233 			RequestCharacter();
   194 			iConsole->ReadCancel();
   234 			iConsole->ReadCancel();
   195 			Cancel();
   235 			Cancel();
   196 			RequestCharacter();
   236 			RequestCharacter();
   197 			
   237 			
   198 			//SelfComplete();
   238 			//SelfComplete();
   199 			break;
   239 			break;
   200 		case ELastStep:
   240 		case ELastStep:
   201 			iCaseStep=ESecondStep;
   241 			iCaseStep=ESecondStep;
   202 			test.Printf(_L("LAST step7 code (%d)\n"), completionCode);
   242 			test.Printf(_L("LAST step7 code (%d)\n"), completionCode);
       
   243 			OstTrace1(TRACE_NORMAL, CEXAMPLETESTCASE_RUNSTEPL_DUP16, "LAST step7 code (%d)\n", completionCode);
   203 			TestPolicy().SignalTestComplete(KErrNone);
   244 			TestPolicy().SignalTestComplete(KErrNone);
   204 			return TestPassed();
   245 			return TestPassed();
   205 			//break;
   246 			//break;
   206 
   247 
   207 		default:
   248 		default:
   208 			//test.Printf(_L("<Error> unknown test step"));
       
   209 			Cancel();
   249 			Cancel();
   210 			TestFailed(KErrCorrupt, _L("unknown test step"));
   250 			TestFailed(KErrCorrupt, _L("unknown test step"));
   211 			break;
   251 			break;
   212 		}
   252 		}
   213 	
   253