kerneltest/e32test/usbho/t_otgdi/src/testcase0461.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".
    23 #include <e32base_private.h>
    23 #include <e32base_private.h>
    24 #include <e32Test.h>	// RTest headder
    24 #include <e32Test.h>	// RTest headder
    25 #include "testcaseroot.h"
    25 #include "testcaseroot.h"
    26 #include "testcasewd.h"
    26 #include "testcasewd.h"
    27 #include "testcase0461.h"
    27 #include "testcase0461.h"
       
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "testcase0461Traces.h"
       
    31 #endif
    28 
    32 
    29 
    33 
    30 
    34 
    31 // the name below is used to add a pointer to our construction method to a pointer MAP in 
    35 // the name below is used to add a pointer to our construction method to a pointer MAP in 
    32 // the class factory
    36 // the class factory
    33 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0461");
    37 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0461");
    34 const TTestCaseFactoryReceipt<CTestCase0461> CTestCase0461::iFactoryReceipt(KTestCaseId);	
    38 const TTestCaseFactoryReceipt<CTestCase0461> CTestCase0461::iFactoryReceipt(KTestCaseId);	
    35 
    39 
    36 CTestCase0461* CTestCase0461::NewL(TBool aHost)
    40 CTestCase0461* CTestCase0461::NewL(TBool aHost)
    37 	{
    41 	{
    38 	LOG_FUNC
    42 	if(gVerboseOutput)
       
    43 	    {
       
    44 	    OstTraceFunctionEntry0(CTESTCASE0461_NEWL);
       
    45 	    }
    39 	CTestCase0461* self = new (ELeave) CTestCase0461(aHost);
    46 	CTestCase0461* self = new (ELeave) CTestCase0461(aHost);
    40 	CleanupStack::PushL(self);
    47 	CleanupStack::PushL(self);
    41 	self->ConstructL();
    48 	self->ConstructL();
    42 	CleanupStack::Pop(self);
    49 	CleanupStack::Pop(self);
    43 	return self;
    50 	return self;
    45 	
    52 	
    46 
    53 
    47 CTestCase0461::CTestCase0461(TBool aHost)
    54 CTestCase0461::CTestCase0461(TBool aHost)
    48 :	CTestCaseRoot(KTestCaseId, aHost)
    55 :	CTestCaseRoot(KTestCaseId, aHost)
    49 	{
    56 	{
    50 	LOG_FUNC
    57 	if(gVerboseOutput)
       
    58 	    {
       
    59 	    OstTraceFunctionEntry0(CTESTCASE0461_CTESTCASE0461);
       
    60 	    }
    51 		
    61 		
    52 	} 
    62 	} 
    53 
    63 
    54 
    64 
    55 /**
    65 /**
    56  ConstructL
    66  ConstructL
    57 */
    67 */
    58 void CTestCase0461::ConstructL()
    68 void CTestCase0461::ConstructL()
    59 	{
    69 	{
    60 	LOG_FUNC
    70 	if(gVerboseOutput)
       
    71 	    {
       
    72 	    OstTraceFunctionEntry0(CTESTCASE0461_CONSTRUCTL);
       
    73 	    }
    61 	iRepeats = KOperationRetriesMax;
    74 	iRepeats = KOperationRetriesMax;
    62 	BaseConstructL();
    75 	BaseConstructL();
    63 	
    76 	
    64 	iWDTimer = CTestCaseWatchdog::NewL();
    77 	iWDTimer = CTestCaseWatchdog::NewL();
    65 	}
    78 	}
    66 
    79 
    67 
    80 
    68 CTestCase0461::~CTestCase0461()
    81 CTestCase0461::~CTestCase0461()
    69 	{
    82 	{
    70 	LOG_FUNC
    83 	if(gVerboseOutput)
       
    84 	    {
       
    85 	    OstTraceFunctionEntry0(CTESTCASE0461_DCTESTCASE0461);
       
    86 	    }
    71 
    87 
    72 	Cancel();
    88 	Cancel();
    73 	delete iWDTimer;
    89 	delete iWDTimer;
    74 	}
    90 	}
    75 
    91 
    76 
    92 
    77 void CTestCase0461::ExecuteTestCaseL()
    93 void CTestCase0461::ExecuteTestCaseL()
    78 	{
    94 	{
    79 	LOG_FUNC
    95 	if(gVerboseOutput)
       
    96 	    {
       
    97 	    OstTraceFunctionEntry0(CTESTCASE0461_EXECUTETESTCASEL);
       
    98 	    }
    80 	iCaseStep = ELoadLdd;
    99 	iCaseStep = ELoadLdd;
    81 	
   100 	
    82 	CActiveScheduler::Add(this);
   101 	CActiveScheduler::Add(this);
    83 	SelfComplete();
   102 	SelfComplete();
    84 
   103 
    86 
   105 
    87 
   106 
    88 void CTestCase0461::DescribePreconditions()
   107 void CTestCase0461::DescribePreconditions()
    89 	{
   108 	{
    90 	test.Printf(_L("Insert 'A' connector beforehand.\n"));
   109 	test.Printf(_L("Insert 'A' connector beforehand.\n"));
       
   110 	OstTrace0(TRACE_NORMAL, CTESTCASE0461_DESCRIBEPRECONDITIONS, "Insert 'A' connector beforehand.\n");
    91 	}
   111 	}
    92 
   112 
    93 	
   113 	
    94 void CTestCase0461::DoCancel()
   114 void CTestCase0461::DoCancel()
    95 	{
   115 	{
    96 	LOG_FUNC
   116 	if(gVerboseOutput)
       
   117 	    {
       
   118 	    OstTraceFunctionEntry0(CTESTCASE0461_DOCANCEL);
       
   119 	    }
    97 
   120 
    98 	// cancel our timer
   121 	// cancel our timer
    99 	iTimer.Cancel();
   122 	iTimer.Cancel();
   100 	}
   123 	}
   101 	
   124 	
   109 	}	
   132 	}	
   110 
   133 
   111 // handle event completion	
   134 // handle event completion	
   112 void CTestCase0461::RunStepL()
   135 void CTestCase0461::RunStepL()
   113 	{
   136 	{
   114 	LOG_FUNC
   137 	if(gVerboseOutput)
       
   138 	    {
       
   139 	    OstTraceFunctionEntry0(CTESTCASE0461_RUNSTEPL);
       
   140 	    }
   115 	// Obtain the completion code for this CActive obj.
   141 	// Obtain the completion code for this CActive obj.
   116 	TInt completionCode(iStatus.Int()); 
   142 	TInt completionCode(iStatus.Int()); 
   117 	TBuf<MAX_DSTRLEN> aDescription;
   143 	TBuf<MAX_DSTRLEN> aDescription;
   118 		
   144 		
   119 	switch(iCaseStep)
   145 	switch(iCaseStep)
   126 				SelfComplete();
   152 				SelfComplete();
   127 				break;
   153 				break;
   128 				}
   154 				}
   129 			// prompt to insert connector
   155 			// prompt to insert connector
   130 			test.Printf(KInsertAConnectorPrompt);
   156 			test.Printf(KInsertAConnectorPrompt);
       
   157 			OstTrace0(TRACE_NORMAL, CTESTCASE0461_RUNSTEPL_DUP01, KInsertAConnectorPrompt);
   131 			test.Printf(KPressAnyKeyToContinue);
   158 			test.Printf(KPressAnyKeyToContinue);
       
   159 			OstTrace0(TRACE_NORMAL, CTESTCASE0461_RUNSTEPL_DUP02, KPressAnyKeyToContinue);
   132 			RequestCharacter();			
   160 			RequestCharacter();			
   133 			break;
   161 			break;
   134 			
   162 			
   135 		case ELoadLdd:
   163 		case ELoadLdd:
   136 			if (!StepLoadLDD())
   164 			if (!StepLoadLDD())
   145 			
   173 			
   146 			// 2. Prepare to wait on ID_PIN
   174 			// 2. Prepare to wait on ID_PIN
   147 		case ERegisterForEvents:
   175 		case ERegisterForEvents:
   148 			// prompt to remove connector
   176 			// prompt to remove connector
   149 			test.Printf(KRemoveAConnectorPrompt);		
   177 			test.Printf(KRemoveAConnectorPrompt);		
       
   178 			OstTrace0(TRACE_NORMAL, CTESTCASE0461_RUNSTEPL_DUP03, KRemoveAConnectorPrompt);		
   150 			if (iDequeAttempts > 3)
   179 			if (iDequeAttempts > 3)
   151 				{
   180 				{
   152 				return (TestFailed(KErrCorrupt, _L("<Error> too many irrelevant/incorrect events")));
   181 				return (TestFailed(KErrCorrupt, _L("<Error> too many irrelevant/incorrect events")));
   153 				}
   182 				}
   154 
   183 
   177 				}
   206 				}
   178 			}// drop through to next step
   207 			}// drop through to next step
   179 		case EGetAndCancelEvent: //4.
   208 		case EGetAndCancelEvent: //4.
   180 			OtgEventString(iOTGEvent, aDescription);
   209 			OtgEventString(iOTGEvent, aDescription);
   181 			test.Printf(_L("Received event %d '%S' status(%d)"), iOTGEvent, &aDescription, completionCode);
   210 			test.Printf(_L("Received event %d '%S' status(%d)"), iOTGEvent, &aDescription, completionCode);
       
   211 			OstTraceExt3(TRACE_NORMAL, CTESTCASE0461_RUNSTEPL_DUP04, "Received event %d '%S' status(%d)", iOTGEvent, aDescription, completionCode);
   182 			if (RUsbOtgDriver::EEventAPlugRemoved == iOTGEvent)
   212 			if (RUsbOtgDriver::EEventAPlugRemoved == iOTGEvent)
   183 				{
   213 				{
   184 				otgQueueOtgEventRequest( iOTGEvent, iStatus);
   214 				otgQueueOtgEventRequest( iOTGEvent, iStatus);
   185 				// cancel it and then go into a loop
   215 				// cancel it and then go into a loop
   186 				otgCancelOtgEventRequest();
   216 				otgCancelOtgEventRequest();
   210 			// 6
   240 			// 6
   211 		case EInsertA: // insert 'A' plug
   241 		case EInsertA: // insert 'A' plug
   212 			iWDTimer->Cancel();
   242 			iWDTimer->Cancel();
   213 			iConsole->ReadCancel();
   243 			iConsole->ReadCancel();
   214 			test.Printf(KInsertAConnectorPrompt);
   244 			test.Printf(KInsertAConnectorPrompt);
       
   245 			OstTrace0(TRACE_NORMAL, CTESTCASE0461_RUNSTEPL_DUP05, KInsertAConnectorPrompt);
   215 			iCaseStep = ERemoveA;
   246 			iCaseStep = ERemoveA;
   216 			test.Printf(KPressAnyKeyToContinue);
   247 			test.Printf(KPressAnyKeyToContinue);
       
   248 			OstTrace0(TRACE_NORMAL, CTESTCASE0461_RUNSTEPL_DUP06, KPressAnyKeyToContinue);
   217 			
   249 			
   218 			RequestCharacter();
   250 			RequestCharacter();
   219 			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &CancelKB);			
   251 			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &CancelKB);			
   220 
   252 
   221 			iExpectedEvents++;
   253 			iExpectedEvents++;
   224 			// 7. remove 'A' plug
   256 			// 7. remove 'A' plug
   225 		case ERemoveA:
   257 		case ERemoveA:
   226 			iWDTimer->Cancel();
   258 			iWDTimer->Cancel();
   227 			iConsole->ReadCancel();
   259 			iConsole->ReadCancel();
   228 			test.Printf(KRemoveAConnectorPrompt);
   260 			test.Printf(KRemoveAConnectorPrompt);
       
   261 			OstTrace0(TRACE_NORMAL, CTESTCASE0461_RUNSTEPL_DUP07, KRemoveAConnectorPrompt);
   229 			if (iRepeats-- >0)
   262 			if (iRepeats-- >0)
   230 				{
   263 				{
   231 				// Do it again please
   264 				// Do it again please
   232 				iCaseStep = EInsertA;
   265 				iCaseStep = EInsertA;
   233 				}
   266 				}
   234 			else
   267 			else
   235 				{ // got enough events in Q, let's count them up
   268 				{ // got enough events in Q, let's count them up
   236 				iCaseStep = ETallyEvents;
   269 				iCaseStep = ETallyEvents;
   237 				}
   270 				}
   238 			test.Printf(KPressAnyKeyToContinue);
   271 			test.Printf(KPressAnyKeyToContinue);
       
   272 			OstTrace0(TRACE_NORMAL, CTESTCASE0461_RUNSTEPL_DUP08, KPressAnyKeyToContinue);
   239 
   273 
   240 			RequestCharacter();			
   274 			RequestCharacter();			
   241 			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &CancelKB);			
   275 			iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &CancelKB);			
   242 			iExpectedEvents++;
   276 			iExpectedEvents++;
   243 			break;
   277 			break;
   272 			
   306 			
   273 			return TestPassed();
   307 			return TestPassed();
   274 
   308 
   275 		default:
   309 		default:
   276 			test.Printf(_L("<Error> unknown test step"));
   310 			test.Printf(_L("<Error> unknown test step"));
       
   311 			OstTrace0(TRACE_NORMAL, CTESTCASE0461_RUNSTEPL_DUP09, "<Error> unknown test step");
   277 			Cancel();
   312 			Cancel();
   278 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   313 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   279 
   314 
   280 		}
   315 		}
   281 	}
   316 	}