os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0459.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // @internalComponent
    15 // 'A' connector detection
    16 // 
    17 //
    18 
    19 #include <e32std.h>
    20 #include <e32std_private.h>
    21 #include <u32std.h> 	// unicode builds
    22 #include <e32base.h>
    23 #include <e32base_private.h>
    24 #include <e32Test.h>	// RTest headder
    25 #include "testcaseroot.h"
    26 #include "testcasefactory.h"
    27 #include "testcase0459.h"
    28 
    29 
    30 
    31 // the name below is used to add a pointer to our construction method to a pointer MAP in 
    32 // the class factory
    33 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0459");
    34 const TTestCaseFactoryReceipt<CTestCase0459> CTestCase0459::iFactoryReceipt(KTestCaseId);	
    35 
    36 CTestCase0459* CTestCase0459::NewL(TBool aHost)
    37 	{
    38 	LOG_FUNC
    39 	CTestCase0459* self = new (ELeave) CTestCase0459(aHost);
    40 	CleanupStack::PushL(self);
    41 	self->ConstructL();
    42 	CleanupStack::Pop(self);
    43 	return self;
    44 	}
    45 	
    46 
    47 CTestCase0459::CTestCase0459(TBool aHost)
    48 :	CTestCaseRoot(KTestCaseId, aHost)
    49 	{
    50 	LOG_FUNC
    51 		
    52 	} 
    53 
    54 
    55 /**
    56  ConstructL
    57 */
    58 void CTestCase0459::ConstructL()
    59 	{
    60 	LOG_FUNC
    61 	
    62 	BaseConstructL();
    63 	}
    64 
    65 
    66 CTestCase0459::~CTestCase0459()
    67 	{
    68 	LOG_FUNC
    69 
    70 	Cancel();
    71 	}
    72 
    73 
    74 void CTestCase0459::ExecuteTestCaseL()
    75 	{
    76 	LOG_FUNC
    77 	iCaseStep = EPreconditions;
    78 	
    79 	CActiveScheduler::Add(this);
    80 	SelfComplete();
    81 
    82 	}
    83 
    84 
    85 void CTestCase0459::DescribePreconditions()
    86 	{
    87 	test.Printf(_L("Remove 'A' connector beforehand.\n"));
    88 	}
    89 
    90 	
    91 void CTestCase0459::DoCancel()
    92 	{
    93 	LOG_FUNC
    94 
    95 	// cancel our timer
    96 	iTimer.Cancel();
    97 	}
    98 	
    99 
   100 // handle event completion	
   101 void CTestCase0459::RunStepL()
   102 	{
   103 	LOG_FUNC
   104 	// Obtain the completion code for this CActive obj.
   105 	TInt completionCode(iStatus.Int()); 
   106 	TBuf<MAX_DSTRLEN> aDescription;
   107 		
   108 	switch(iCaseStep)
   109 		{
   110 		case EPreconditions:
   111 			iCaseStep = ELoadLdd;
   112 			if (iAutomated)
   113 				{
   114 				iCaseStep = ELoadLdd;
   115 				SelfComplete();
   116 				break;
   117 				}
   118 			// prompt to remove connector
   119 			test.Printf(KRemoveAConnectorPrompt);
   120 			test.Printf(KPressAnyKeyToContinue);
   121 			RequestCharacter();			
   122 			break;
   123 			
   124 		case ELoadLdd:
   125 			if (!StepLoadLDD())
   126 				{
   127 				break;
   128 				}
   129 
   130 			iCaseStep = ERegisterForEvents;
   131 			iDequeAttempts = 0;	
   132 			SelfComplete();
   133 			break;
   134 			
   135 			// wait on ID_PIN
   136 		case ERegisterForEvents:
   137 			if (iDequeAttempts > 3)
   138 				{
   139 				return (TestFailed(KErrCorrupt, _L("<Error> too many irrelevant/incorrect events")));
   140 				}
   141 
   142 			test.Printf(KInsertAConnectorPrompt);
   143 			iCaseStep = ETestStateA;
   144 			test.Printf(_L("Waiting for OTG Event\n"));
   145 
   146 			otgQueueOtgEventRequest( iOTGEvent, iStatus);
   147 
   148 			// start timer
   149 			iIDcheckStart.HomeTime();
   150 			SetActive();
   151 			break;
   152 			
   153 		case EDriveID_PIN:
   154 			// please turn on ID_PIN prompt (or programming API call)
   155 			// skipped untill we can do this.
   156 			SetActive();
   157 			break;
   158 			
   159 		case EWait5:
   160 		case ETestStateA:
   161 			{
   162 			TInt aMillisec;
   163 			OtgEventString(iOTGEvent, aDescription);
   164 
   165 			iIDcheckEnd.HomeTime();
   166 			TTimeIntervalMicroSeconds ivlMicro(iIDcheckEnd.MicroSecondsFrom(iIDcheckStart));
   167 			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);
   169 			
   170 			// check the parameters gathered
   171 			if (RUsbOtgDriver::EEventAPlugInserted == iOTGEvent)
   172 				{
   173 				iCaseStep = EUnloadLdd;
   174 				// test if too quick!
   175 				if(aMillisec < KDelayDurationForQEmpty) // use 200ms - clocked at 17ms
   176 					{
   177 					// '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"));
   179 					// wrong event in the Q already, keep at it
   180 					iCaseStep = ERegisterForEvents;	
   181 					}
   182 				}
   183 			else
   184 				{
   185 				// wrong event in the Q already, keep at it
   186 				iCaseStep = ERegisterForEvents;	
   187 				iDequeAttempts++;
   188 				}
   189 			SelfComplete();
   190 			}
   191 			break;		
   192 		case EUnloadLdd:
   193 		case ELastStep:
   194 			if (EFalse == StepUnloadLDD())
   195 				{
   196 				return TestFailed(KErrAbort,_L("unload Ldd failure"));	
   197 				}
   198 			return TestPassed();
   199 
   200 		default:
   201 			test.Printf(_L("<Error> unknown test step"));
   202 			Cancel();
   203 			return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
   204 
   205 		}
   206 
   207 	}
   208 
   209