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.
19 #include <e32std_private.h>
20 #include <u32std.h> // unicode builds
22 #include <e32base_private.h>
23 #include <e32Test.h> // RTest headder
24 #include "testcaseroot.h"
25 #include "testcasewd.h"
26 #include "testcase0462.h"
30 // the name below is used to add a pointer to our construction method to a pointer MAP in
32 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0462");
33 const TTestCaseFactoryReceipt<CTestCase0462> CTestCase0462::iFactoryReceipt(KTestCaseId);
35 CTestCase0462* CTestCase0462::NewL(TBool aHost)
38 CTestCase0462* self = new (ELeave) CTestCase0462(aHost);
39 CleanupStack::PushL(self);
41 CleanupStack::Pop(self);
46 CTestCase0462::CTestCase0462(TBool aHost)
47 : CTestCaseRoot(KTestCaseId, aHost)
57 void CTestCase0462::ConstructL()
60 iRepeats = KOperationRetriesMax;
61 iWDTimer = CTestCaseWatchdog::NewL();
67 CTestCase0462::~CTestCase0462()
76 void CTestCase0462::ExecuteTestCaseL()
81 CActiveScheduler::Add(this);
87 void CTestCase0462::DescribePreconditions()
89 test.Printf(_L("Insert 'A' connector beforehand.\n"));
93 void CTestCase0462::DoCancel()
101 void CTestCase0462::CancelKB(CTestCaseRoot *pThis)
103 CTestCase0462 * p = REINTERPRET_CAST(CTestCase0462 *,pThis);
104 // cancel any pending call, and then complete our active obj with a timeout value
106 p->iConsole->ReadCancel();
111 // handle event completion
112 void CTestCase0462::RunStepL()
115 // Obtain the completion code for this CActive obj.
116 TInt completionCode(iStatus.Int());
117 // NOTE: Look at its iStatus.iFlags.
118 // If it's 1, it's b -> you called SetActive() but the service provider didn't set it to KRequestPending or it got overwritten.
119 // If it's 2, it's a -> you didn't called SetActive() when issuing a request.
121 TBuf<MAX_DSTRLEN> aDescription;
126 iCaseStep = ELoadLdd;
129 iCaseStep = ELoadLdd;
133 // prompt to insert connector
134 test.Printf(KInsertAConnectorPrompt);
135 test.Printf(KPressAnyKeyToContinue);
145 iCaseStep = ERegisterForEvents;
151 case ERegisterForEvents:
152 // prompt to remove connector
153 test.Printf(KRemoveAConnectorPrompt);
154 if (iDequeAttempts > 3)
156 return (TestFailed(KErrCorrupt, _L("<Error> too many irrelevant/incorrect events")));
159 otgQueueOtgEventRequest( iOTGEvent, iStatus);
160 iCaseStep = EEmptyQueue;
161 iIDcheckStart.HomeTime();
165 // 3. pick up events already buffered when we started test
170 iIDcheckEnd.HomeTime();
171 TTimeIntervalMicroSeconds ivlMicro(iIDcheckEnd.MicroSecondsFrom(iIDcheckStart));
172 aMillisec = (TInt)(ivlMicro.Int64())/1000; // USB times are in uSec, but in ms for the user layer
173 iCaseStep = EGetAndCancelEvent;
174 // test if too quick!
175 if(aMillisec < KDelayDurationForQEmpty) // use 200ms - clocked at 17ms
177 iCaseStep = ERegisterForEvents;
182 }// drop through to next step
185 case EGetAndCancelEvent:
186 OtgEventString(iOTGEvent, aDescription);
187 test.Printf(_L("Received event %d '%S' status(%d)"), iOTGEvent, &aDescription, completionCode);
188 if (RUsbOtgDriver::EEventAPlugRemoved == iOTGEvent)
190 otgQueueOtgEventRequest( iOTGEvent, iStatus);
191 // cancel it and then generate 6 more events
192 otgCancelOtgEventRequest();
193 // swallow the cancellation now too
194 User::WaitForRequest(iStatus);
196 iCaseStep = ECancelNotify;
200 // wrong event in the Q already, keep at it
201 iCaseStep = ERegisterForEvents;
207 // 5. prepare to insert 'A'
209 iRepeats = KOperationRetriesMax;
210 iCaseStep = EInsertA;
214 case EInsertA: // 6. remove 'A'
215 iConsole->ReadCancel();
216 test.Printf(KInsertAConnectorPrompt);
218 iCaseStep = ERemoveA;
219 test.Printf(KPressAnyKeyToContinue);
225 iConsole->ReadCancel();
226 test.Printf(KRemoveAConnectorPrompt);
228 iCaseStep = EInsertA;
230 iCaseStep = ETallyEvents;
231 test.Printf(KPressAnyKeyToContinue);
237 iConsole->ReadCancel();
238 // tests if the object became signalled or not!
239 // we expect if it did in fact do so, our Active object would panic (stray signal)
241 iCaseStep = EUnloadLdd;
247 if (EFalse == StepUnloadLDD())
248 return TestFailed(KErrAbort,_L("unload Ldd failure"));
253 test.Printf(_L("<Error> unknown test step"));
255 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));