Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 #include <e32std_private.h>
21 #include <u32std.h> // unicode builds
23 #include <e32base_private.h>
24 #include <e32Test.h> // RTest headder
25 #include "testcaseroot.h"
26 #include "testcasewd.h"
27 #include "testcase0461.h"
31 // the name below is used to add a pointer to our construction method to a pointer MAP in
33 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0461");
34 const TTestCaseFactoryReceipt<CTestCase0461> CTestCase0461::iFactoryReceipt(KTestCaseId);
36 CTestCase0461* CTestCase0461::NewL(TBool aHost)
39 CTestCase0461* self = new (ELeave) CTestCase0461(aHost);
40 CleanupStack::PushL(self);
42 CleanupStack::Pop(self);
47 CTestCase0461::CTestCase0461(TBool aHost)
48 : CTestCaseRoot(KTestCaseId, aHost)
58 void CTestCase0461::ConstructL()
61 iRepeats = KOperationRetriesMax;
64 iWDTimer = CTestCaseWatchdog::NewL();
68 CTestCase0461::~CTestCase0461()
77 void CTestCase0461::ExecuteTestCaseL()
82 CActiveScheduler::Add(this);
88 void CTestCase0461::DescribePreconditions()
90 test.Printf(_L("Insert 'A' connector beforehand.\n"));
94 void CTestCase0461::DoCancel()
102 void CTestCase0461::CancelKB(CTestCaseRoot *pThis)
104 CTestCase0461 * p = REINTERPRET_CAST(CTestCase0461 *,pThis);
105 // cancel any pending call, and then complete our active obj with a timeout value
107 p->iConsole->ReadCancel();
111 // handle event completion
112 void CTestCase0461::RunStepL()
115 // Obtain the completion code for this CActive obj.
116 TInt completionCode(iStatus.Int());
117 TBuf<MAX_DSTRLEN> aDescription;
122 iCaseStep = ELoadLdd;
125 iCaseStep = ELoadLdd;
129 // prompt to insert connector
130 test.Printf(KInsertAConnectorPrompt);
131 test.Printf(KPressAnyKeyToContinue);
141 iCaseStep = ERegisterForEvents;
146 // 2. Prepare to wait on ID_PIN
147 case ERegisterForEvents:
148 // prompt to remove connector
149 test.Printf(KRemoveAConnectorPrompt);
150 if (iDequeAttempts > 3)
152 return (TestFailed(KErrCorrupt, _L("<Error> too many irrelevant/incorrect events")));
155 otgQueueOtgEventRequest( iOTGEvent, iStatus);
156 iIDcheckStart.HomeTime();
157 iCaseStep = EGetAndCancelEvent;
161 // 3. pick up events already buffered when we start
166 iIDcheckEnd.HomeTime();
167 TTimeIntervalMicroSeconds ivlMicro(iIDcheckEnd.MicroSecondsFrom(iIDcheckStart));
168 aMillisec = (TInt)(ivlMicro.Int64())/1000; // USB times are in uSec, but in ms for the user layer
169 iCaseStep = EGetAndCancelEvent;
170 // test if too quick!
171 if ((aMillisec < KDelayDurationForQEmpty) &&(!gSemiAutomated)) // use 200ms - clocked at 17ms
173 iCaseStep = ERegisterForEvents;
178 }// drop through to next step
179 case EGetAndCancelEvent: //4.
180 OtgEventString(iOTGEvent, aDescription);
181 test.Printf(_L("Received event %d '%S' status(%d)"), iOTGEvent, &aDescription, completionCode);
182 if (RUsbOtgDriver::EEventAPlugRemoved == iOTGEvent)
184 otgQueueOtgEventRequest( iOTGEvent, iStatus);
185 // cancel it and then go into a loop
186 otgCancelOtgEventRequest();
187 // swallow the cancelation now
188 User::WaitForRequest(iStatus);
190 iCaseStep = ECancelNotify;
194 // wrong event in the Q already, keep at it
195 iCaseStep = ERegisterForEvents;
201 // 5. prepare to go into a loop
202 case ECancelNotify: // insert 'A'
203 iRepeats = 3; // #times to insert+remove
206 iCaseStep = EInsertA;
211 case EInsertA: // insert 'A' plug
213 iConsole->ReadCancel();
214 test.Printf(KInsertAConnectorPrompt);
215 iCaseStep = ERemoveA;
216 test.Printf(KPressAnyKeyToContinue);
219 iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &CancelKB);
224 // 7. remove 'A' plug
227 iConsole->ReadCancel();
228 test.Printf(KRemoveAConnectorPrompt);
231 // Do it again please
232 iCaseStep = EInsertA;
235 { // got enough events in Q, let's count them up
236 iCaseStep = ETallyEvents;
238 test.Printf(KPressAnyKeyToContinue);
241 iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &CancelKB);
247 // Getting here tests if the object does not get double-signalled.
248 // a stray signal anywhere would Panic the scheduler when we self complete
249 iCaseStep = ETallyNewEvent;
250 iStatus = KRequestPending;
251 otgQueueOtgEventRequest( iOTGEvent, iStatus);
256 iEventsInQueue++; // got one, add it
257 if (iExpectedEvents == iEventsInQueue)
259 iCaseStep = EUnloadLdd;
263 iCaseStep = ETallyEvents;
270 if (EFalse == StepUnloadLDD())
271 return TestFailed(KErrAbort,_L("unload Ldd failure"));
276 test.Printf(_L("<Error> unknown test step"));
278 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));