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