kerneltest/e32test/usbho/t_otgdi/src/testcase0459.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 "testcasefactory.h"
    26 #include "testcasefactory.h"
    27 #include "testcase0459.h"
    27 #include "testcase0459.h"
       
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "testcase0459Traces.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-0459");
    37 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0459");
    34 const TTestCaseFactoryReceipt<CTestCase0459> CTestCase0459::iFactoryReceipt(KTestCaseId);	
    38 const TTestCaseFactoryReceipt<CTestCase0459> CTestCase0459::iFactoryReceipt(KTestCaseId);	
    35 
    39 
    36 CTestCase0459* CTestCase0459::NewL(TBool aHost)
    40 CTestCase0459* CTestCase0459::NewL(TBool aHost)
    37 	{
    41 	{
    38 	LOG_FUNC
    42 	if(gVerboseOutput)
       
    43 	    {
       
    44 	    OstTraceFunctionEntry0(CTESTCASE0459_NEWL);
       
    45 	    }
    39 	CTestCase0459* self = new (ELeave) CTestCase0459(aHost);
    46 	CTestCase0459* self = new (ELeave) CTestCase0459(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 CTestCase0459::CTestCase0459(TBool aHost)
    54 CTestCase0459::CTestCase0459(TBool aHost)
    48 :	CTestCaseRoot(KTestCaseId, aHost)
    55 :	CTestCaseRoot(KTestCaseId, aHost)
    49 	{
    56 	{
    50 	LOG_FUNC
    57 	if(gVerboseOutput)
       
    58 	    {
       
    59 	    OstTraceFunctionEntry0(CTESTCASE0459_CTESTCASE0459);
       
    60 	    }
    51 		
    61 		
    52 	} 
    62 	} 
    53 
    63 
    54 
    64 
    55 /**
    65 /**
    56  ConstructL
    66  ConstructL
    57 */
    67 */
    58 void CTestCase0459::ConstructL()
    68 void CTestCase0459::ConstructL()
    59 	{
    69 	{
    60 	LOG_FUNC
    70 	if(gVerboseOutput)
       
    71 	    {
       
    72 	    OstTraceFunctionEntry0(CTESTCASE0459_CONSTRUCTL);
       
    73 	    }
    61 	
    74 	
    62 	BaseConstructL();
    75 	BaseConstructL();
    63 	}
    76 	}
    64 
    77 
    65 
    78 
    66 CTestCase0459::~CTestCase0459()
    79 CTestCase0459::~CTestCase0459()
    67 	{
    80 	{
    68 	LOG_FUNC
    81 	if(gVerboseOutput)
       
    82 	    {
       
    83 	    OstTraceFunctionEntry0(CTESTCASE0459_DCTESTCASE0459);
       
    84 	    }
    69 
    85 
    70 	Cancel();
    86 	Cancel();
    71 	}
    87 	}
    72 
    88 
    73 
    89 
    74 void CTestCase0459::ExecuteTestCaseL()
    90 void CTestCase0459::ExecuteTestCaseL()
    75 	{
    91 	{
    76 	LOG_FUNC
    92 	if(gVerboseOutput)
       
    93 	    {
       
    94 	    OstTraceFunctionEntry0(CTESTCASE0459_EXECUTETESTCASEL);
       
    95 	    }
    77 	iCaseStep = EPreconditions;
    96 	iCaseStep = EPreconditions;
    78 	
    97 	
    79 	CActiveScheduler::Add(this);
    98 	CActiveScheduler::Add(this);
    80 	SelfComplete();
    99 	SelfComplete();
    81 
   100 
    83 
   102 
    84 
   103 
    85 void CTestCase0459::DescribePreconditions()
   104 void CTestCase0459::DescribePreconditions()
    86 	{
   105 	{
    87 	test.Printf(_L("Remove 'A' connector beforehand.\n"));
   106 	test.Printf(_L("Remove 'A' connector beforehand.\n"));
       
   107 	OstTrace0(TRACE_NORMAL, CTESTCASE0459_DESCRIBEPRECONDITIONS, "Remove 'A' connector beforehand.\n");
    88 	}
   108 	}
    89 
   109 
    90 	
   110 	
    91 void CTestCase0459::DoCancel()
   111 void CTestCase0459::DoCancel()
    92 	{
   112 	{
    93 	LOG_FUNC
   113 	if(gVerboseOutput)
       
   114 	    {
       
   115 	    OstTraceFunctionEntry0(CTESTCASE0459_DOCANCEL);
       
   116 	    }
    94 
   117 
    95 	// cancel our timer
   118 	// cancel our timer
    96 	iTimer.Cancel();
   119 	iTimer.Cancel();
    97 	}
   120 	}
    98 	
   121 	
    99 
   122 
   100 // handle event completion	
   123 // handle event completion	
   101 void CTestCase0459::RunStepL()
   124 void CTestCase0459::RunStepL()
   102 	{
   125 	{
   103 	LOG_FUNC
   126 	if(gVerboseOutput)
       
   127 	    {
       
   128 	    OstTraceFunctionEntry0(CTESTCASE0459_RUNSTEPL);
       
   129 	    }
   104 	// Obtain the completion code for this CActive obj.
   130 	// Obtain the completion code for this CActive obj.
   105 	TInt completionCode(iStatus.Int()); 
   131 	TInt completionCode(iStatus.Int()); 
   106 	TBuf<MAX_DSTRLEN> aDescription;
   132 	TBuf<MAX_DSTRLEN> aDescription;
   107 		
   133 		
   108 	switch(iCaseStep)
   134 	switch(iCaseStep)
   115 				SelfComplete();
   141 				SelfComplete();
   116 				break;
   142 				break;
   117 				}
   143 				}
   118 			// prompt to remove connector
   144 			// prompt to remove connector
   119 			test.Printf(KRemoveAConnectorPrompt);
   145 			test.Printf(KRemoveAConnectorPrompt);
       
   146 			OstTrace0(TRACE_NORMAL, CTESTCASE0459_RUNSTEPL_DUP01, KRemoveAConnectorPrompt);
   120 			test.Printf(KPressAnyKeyToContinue);
   147 			test.Printf(KPressAnyKeyToContinue);
       
   148 			OstTrace0(TRACE_NORMAL, CTESTCASE0459_RUNSTEPL_DUP02, KPressAnyKeyToContinue);
   121 			RequestCharacter();			
   149 			RequestCharacter();			
   122 			break;
   150 			break;
   123 			
   151 			
   124 		case ELoadLdd:
   152 		case ELoadLdd:
   125 			if (!StepLoadLDD())
   153 			if (!StepLoadLDD())
   138 				{
   166 				{
   139 				return (TestFailed(KErrCorrupt, _L("<Error> too many irrelevant/incorrect events")));
   167 				return (TestFailed(KErrCorrupt, _L("<Error> too many irrelevant/incorrect events")));
   140 				}
   168 				}
   141 
   169 
   142 			test.Printf(KInsertAConnectorPrompt);
   170 			test.Printf(KInsertAConnectorPrompt);
       
   171 			OstTrace0(TRACE_NORMAL, CTESTCASE0459_RUNSTEPL_DUP03, KInsertAConnectorPrompt);
   143 			iCaseStep = ETestStateA;
   172 			iCaseStep = ETestStateA;
   144 			test.Printf(_L("Waiting for OTG Event\n"));
   173 			test.Printf(_L("Waiting for OTG Event\n"));
       
   174 			OstTrace0(TRACE_NORMAL, CTESTCASE0459_RUNSTEPL_DUP04, "Waiting for OTG Event\n");
   145 
   175 
   146 			otgQueueOtgEventRequest( iOTGEvent, iStatus);
   176 			otgQueueOtgEventRequest( iOTGEvent, iStatus);
   147 
   177 
   148 			// start timer
   178 			// start timer
   149 			iIDcheckStart.HomeTime();
   179 			iIDcheckStart.HomeTime();
   164 
   194 
   165 			iIDcheckEnd.HomeTime();
   195 			iIDcheckEnd.HomeTime();
   166 			TTimeIntervalMicroSeconds ivlMicro(iIDcheckEnd.MicroSecondsFrom(iIDcheckStart));
   196 			TTimeIntervalMicroSeconds ivlMicro(iIDcheckEnd.MicroSecondsFrom(iIDcheckStart));
   167 			aMillisec = (TInt)(ivlMicro.Int64())/1000;	// USB times are in uSec, but in ms for the user layer
   197 			aMillisec = (TInt)(ivlMicro.Int64())/1000;	// USB times are in uSec, but in ms for the user layer
   168 			test.Printf(_L("Received event %d '%S' status(%d) in %d ms"), iOTGEvent, &aDescription, completionCode, aMillisec);
   198 			test.Printf(_L("Received event %d '%S' status(%d) in %d ms"), iOTGEvent, &aDescription, completionCode, aMillisec);
       
   199 			OstTraceExt4(TRACE_NORMAL, CTESTCASE0459_RUNSTEPL_DUP05, "Received event %d '%S' status(%d) in %d ms", iOTGEvent, aDescription, completionCode, aMillisec);
   169 			
   200 			
   170 			// check the parameters gathered
   201 			// check the parameters gathered
   171 			if (RUsbOtgDriver::EEventAPlugInserted == iOTGEvent)
   202 			if (RUsbOtgDriver::EEventAPlugInserted == iOTGEvent)
   172 				{
   203 				{
   173 				iCaseStep = EUnloadLdd;
   204 				iCaseStep = EUnloadLdd;
   174 				// test if too quick!
   205 				// test if too quick!
   175 				if(aMillisec < KDelayDurationForQEmpty) // use 200ms - clocked at 17ms
   206 				if(aMillisec < KDelayDurationForQEmpty) // use 200ms - clocked at 17ms
   176 					{
   207 					{
   177 					// 'A' was in the receptacle when we started the stack, so it fires immediately, consume it and wait for another.
   208 					// 'A' was in the receptacle when we started the stack, so it fires immediately, consume it and wait for another.
   178 					test.Printf(_L("Please first remove and then replace the A connector.\n"));
   209 					test.Printf(_L("Please first remove and then replace the A connector.\n"));
       
   210 					OstTrace0(TRACE_NORMAL, CTESTCASE0459_RUNSTEPL_DUP06, "Please first remove and then replace the A connector.\n");
   179 					// wrong event in the Q already, keep at it
   211 					// wrong event in the Q already, keep at it
   180 					iCaseStep = ERegisterForEvents;	
   212 					iCaseStep = ERegisterForEvents;	
   181 					}
   213 					}
   182 				}
   214 				}
   183 			else
   215 			else
   197 				}
   229 				}
   198 			return TestPassed();
   230 			return TestPassed();
   199 
   231 
   200 		default:
   232 		default:
   201 			test.Printf(_L("<Error> unknown test step"));
   233 			test.Printf(_L("<Error> unknown test step"));
       
   234 			OstTrace0(TRACE_NORMAL, CTESTCASE0459_RUNSTEPL_DUP07, "<Error> unknown test step");
   202 			Cancel();
   235 			Cancel();
   203 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   236 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   204 
   237 
   205 		}
   238 		}
   206 
   239