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 "testcase0467.h"
30 // # times to repeat the steps (default=3)
31 #define INSERT_REPEATS gOpenIterations
33 // the name below is used to add a pointer to our construction method to a pointer MAP in
35 _LIT(KTestCaseId,"PBASE-USB_OTGDI-0467");
36 const TTestCaseFactoryReceipt<CTestCase0467> CTestCase0467::iFactoryReceipt(KTestCaseId);
38 CTestCase0467* CTestCase0467::NewL(TBool aHost)
41 CTestCase0467* self = new (ELeave) CTestCase0467(aHost);
42 CleanupStack::PushL(self);
44 CleanupStack::Pop(self);
49 CTestCase0467::CTestCase0467(TBool aHost)
50 : CTestCaseRoot(KTestCaseId, aHost)
60 void CTestCase0467::ConstructL()
63 iRepeats = INSERT_REPEATS;
64 iWDTimer = CTestCaseWatchdog::NewL();
70 CTestCase0467::~CTestCase0467()
80 void CTestCase0467::ExecuteTestCaseL()
83 iCaseStep = EPreconditions;
85 iRepeats = KOperationRetriesMax; // VBus event rise retries
87 CActiveScheduler::Add(this);
93 void CTestCase0467::DoCancel()
102 void CTestCase0467::CancelKB(CTestCaseRoot *pThis)
104 CTestCase0467 * p = REINTERPRET_CAST(CTestCase0467 *,pThis);
105 // cancel the pending call
107 p->iConsole->ReadCancel();
112 void CTestCase0467::CancelIdPin(CTestCaseRoot *pThis)
116 CTestCase0467 * p = REINTERPRET_CAST(CTestCase0467 *,pThis);
117 // cancel any pending call, and then complete our active obj with a timeout value
118 p->otgCancelOtgIdPinNotification();
119 p->SelfComplete(KTestCaseWatchdogTO);
123 // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
124 void CTestCase0467::DescribePreconditions()
126 test.Printf(_L("Remove 'A' connector beforehand.\n"));
127 test.Printf(_L("ID_PIN detection and VBus driving tests must already pass.\n"));
131 // handle event completion
132 void CTestCase0467::RunStepL()
135 // Obtain the completion code for this CActive obj.
136 TInt completionCode(iStatus.Int());
137 TBuf<MAX_DSTRLEN> aDescription;
142 iCaseStep = ELoadLdd;
145 iCaseStep = ELoadLdd;
149 // prompt to remove connector
150 test.Printf(KRemoveAConnectorPrompt);
151 test.Printf(KPressAnyKeyToContinue);
156 // 1. load the LDD and init.
161 // initialize variables for loop control
163 iCaseStep = EWaitForIDPresent;
167 case ERepeatLoop: // 2
168 test.Printf(_L("Repeat test %d/%d\n"), INSERT_REPEATS-iRepeats+1, INSERT_REPEATS);
171 iCaseStep = EWaitForIDPresent;
173 iCaseStep = EUnloadLdd;
177 case EWaitForIDPresent:
178 // 3. prompt for insertion
179 test.Printf(KInsertAConnectorPrompt);
180 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
183 iCaseStep = EVerifyIDPresent;
187 case EVerifyIDPresent:
188 // 4. detect id_pin event
189 LOG_VERBOSE1(_L("STEP4 - detect id_pin event 'A'\n"));
191 // retrieve the current ID_PIN value
192 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
193 otgCancelOtgIdPinNotification();
194 User::WaitForRequest(iStatus); // swallow the cancellation event (serves to test that it does cancel)
197 if (iOTGIdPin != RUsbOtgDriver::EIdPinAPlug)
199 if (iDetectionRetry++ < 3)
201 iCaseStep = EVerifyIDPresent;
202 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
209 return TestFailed(KErrAbort, _L("ID_PIN NOT 'seen' - FAILED!"));
213 // check using the API in a syncronous way too
214 // NOTE: we test this twice to explore and expose timing problems
215 if (!otgIdPinPresent())
217 return TestFailed(KErrAbort, _L("ID_PIN syncronous call error - FAILED!"));
219 iCaseStep = EWaitForIDGone;
225 // 5. prompt for insertion
226 test.Printf(KRemoveAConnectorPrompt);
227 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
229 iCaseStep = EVerifyIDGone;
233 // 6. detect id_pin gone event
234 LOG_VERBOSE1(_L("STEP4 - detect id_pin remove event 'B'\n"));
235 test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin);
237 User::After(5000); // 5ms
238 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
239 otgCancelOtgIdPinNotification();
240 User::WaitForRequest(iStatus); // swallow it
241 test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin);
243 if (iOTGIdPin != RUsbOtgDriver::EIdPinBPlug)
245 if (iDetectionRetry++ < 3)
247 iCaseStep = EVerifyIDGone;
248 otgQueueOtgIdPinNotification( iOTGIdPin, iStatus );
254 return TestFailed(KErrAbort, _L("ID_PIN NOT 'removed' - FAILED!"));
257 // check using the API in a syncronous way too
258 if (otgIdPinPresent())
260 return TestFailed(KErrAbort, _L("ID_PIN syncronous call error - FAILED!"));
262 iCaseStep = ERepeatLoop;
268 if (EFalse == StepUnloadLDD())
269 return TestFailed(KErrAbort,_L("Unload Ldd failure"));
271 iCaseStep = ELastStep;
280 test.Printf(_L("<Error> unknown test step"));
282 return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));