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