sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include // unicode builds sl@0: #include sl@0: #include sl@0: #include // RTest headder sl@0: #include "testcaseroot.h" sl@0: #include "testcasewd.h" sl@0: #include "testcase0467.h" sl@0: sl@0: sl@0: sl@0: // # times to repeat the steps (default=3) sl@0: #define INSERT_REPEATS gOpenIterations sl@0: sl@0: // the name below is used to add a pointer to our construction method to a pointer MAP in sl@0: // the class factory sl@0: _LIT(KTestCaseId,"PBASE-USB_OTGDI-0467"); sl@0: const TTestCaseFactoryReceipt CTestCase0467::iFactoryReceipt(KTestCaseId); sl@0: sl@0: CTestCase0467* CTestCase0467::NewL(TBool aHost) sl@0: { sl@0: LOG_FUNC sl@0: CTestCase0467* self = new (ELeave) CTestCase0467(aHost); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CTestCase0467::CTestCase0467(TBool aHost) sl@0: : CTestCaseRoot(KTestCaseId, aHost) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: } sl@0: sl@0: sl@0: /** sl@0: ConstructL sl@0: */ sl@0: void CTestCase0467::ConstructL() sl@0: { sl@0: LOG_FUNC sl@0: iRepeats = INSERT_REPEATS; sl@0: iWDTimer = CTestCaseWatchdog::NewL(); sl@0: sl@0: BaseConstructL(); sl@0: } sl@0: sl@0: sl@0: CTestCase0467::~CTestCase0467() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: Cancel(); sl@0: delete iWDTimer; sl@0: sl@0: } sl@0: sl@0: sl@0: void CTestCase0467::ExecuteTestCaseL() sl@0: { sl@0: LOG_FUNC sl@0: iCaseStep = EPreconditions; sl@0: sl@0: iRepeats = KOperationRetriesMax; // VBus event rise retries sl@0: sl@0: CActiveScheduler::Add(this); sl@0: SelfComplete(); sl@0: sl@0: } sl@0: sl@0: sl@0: void CTestCase0467::DoCancel() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // cancel our timer sl@0: iTimer.Cancel(); sl@0: } sl@0: sl@0: sl@0: void CTestCase0467::CancelKB(CTestCaseRoot *pThis) sl@0: { sl@0: CTestCase0467 * p = REINTERPRET_CAST(CTestCase0467 *,pThis); sl@0: // cancel the pending call sl@0: sl@0: p->iConsole->ReadCancel(); sl@0: sl@0: } sl@0: sl@0: sl@0: void CTestCase0467::CancelIdPin(CTestCaseRoot *pThis) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: CTestCase0467 * p = REINTERPRET_CAST(CTestCase0467 *,pThis); sl@0: // cancel any pending call, and then complete our active obj with a timeout value sl@0: p->otgCancelOtgIdPinNotification(); sl@0: p->SelfComplete(KTestCaseWatchdogTO); sl@0: } sl@0: sl@0: sl@0: // This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed sl@0: void CTestCase0467::DescribePreconditions() sl@0: { sl@0: test.Printf(_L("Remove 'A' connector beforehand.\n")); sl@0: test.Printf(_L("ID_PIN detection and VBus driving tests must already pass.\n")); sl@0: } sl@0: sl@0: sl@0: // handle event completion sl@0: void CTestCase0467::RunStepL() sl@0: { sl@0: LOG_FUNC sl@0: // Obtain the completion code for this CActive obj. sl@0: TInt completionCode(iStatus.Int()); sl@0: TBuf aDescription; sl@0: sl@0: switch(iCaseStep) sl@0: { sl@0: case EPreconditions: sl@0: iCaseStep = ELoadLdd; sl@0: if (iAutomated) sl@0: { sl@0: iCaseStep = ELoadLdd; sl@0: SelfComplete(); sl@0: break; sl@0: } sl@0: // prompt to remove connector sl@0: test.Printf(KRemoveAConnectorPrompt); sl@0: test.Printf(KPressAnyKeyToContinue); sl@0: RequestCharacter(); sl@0: break; sl@0: sl@0: case ELoadLdd: sl@0: // 1. load the LDD and init. sl@0: if (!StepLoadLDD()) sl@0: { sl@0: break; sl@0: } sl@0: // initialize variables for loop control sl@0: sl@0: iCaseStep = EWaitForIDPresent; sl@0: SelfComplete(); sl@0: break; sl@0: sl@0: case ERepeatLoop: // 2 sl@0: test.Printf(_L("Repeat test %d/%d\n"), INSERT_REPEATS-iRepeats+1, INSERT_REPEATS); sl@0: sl@0: if (--iRepeats) sl@0: iCaseStep = EWaitForIDPresent; sl@0: else sl@0: iCaseStep = EUnloadLdd; sl@0: SelfComplete(); sl@0: break; sl@0: sl@0: case EWaitForIDPresent: sl@0: // 3. prompt for insertion sl@0: test.Printf(KInsertAConnectorPrompt); sl@0: otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); sl@0: sl@0: SetActive(); sl@0: iCaseStep = EVerifyIDPresent; sl@0: iDetectionRetry = 0; sl@0: break; sl@0: sl@0: case EVerifyIDPresent: sl@0: // 4. detect id_pin event sl@0: LOG_VERBOSE1(_L("STEP4 - detect id_pin event 'A'\n")); sl@0: sl@0: // retrieve the current ID_PIN value sl@0: otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); sl@0: otgCancelOtgIdPinNotification(); sl@0: User::WaitForRequest(iStatus); // swallow the cancellation event (serves to test that it does cancel) sl@0: sl@0: sl@0: if (iOTGIdPin != RUsbOtgDriver::EIdPinAPlug) sl@0: { sl@0: if (iDetectionRetry++ < 3) sl@0: { sl@0: iCaseStep = EVerifyIDPresent; sl@0: otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); sl@0: sl@0: SetActive(); sl@0: break; sl@0: } sl@0: else sl@0: { sl@0: return TestFailed(KErrAbort, _L("ID_PIN NOT 'seen' - FAILED!")); sl@0: } sl@0: } sl@0: sl@0: // check using the API in a syncronous way too sl@0: // NOTE: we test this twice to explore and expose timing problems sl@0: if (!otgIdPinPresent()) sl@0: { sl@0: return TestFailed(KErrAbort, _L("ID_PIN syncronous call error - FAILED!")); sl@0: } sl@0: iCaseStep = EWaitForIDGone; sl@0: SelfComplete(); sl@0: iDetectionRetry = 0; sl@0: break; sl@0: sl@0: case EWaitForIDGone: sl@0: // 5. prompt for insertion sl@0: test.Printf(KRemoveAConnectorPrompt); sl@0: otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); sl@0: SetActive(); sl@0: iCaseStep = EVerifyIDGone; sl@0: break; sl@0: sl@0: case EVerifyIDGone: sl@0: // 6. detect id_pin gone event sl@0: LOG_VERBOSE1(_L("STEP4 - detect id_pin remove event 'B'\n")); sl@0: test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin); sl@0: sl@0: User::After(5000); // 5ms sl@0: otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); sl@0: otgCancelOtgIdPinNotification(); sl@0: User::WaitForRequest(iStatus); // swallow it sl@0: test.Printf(_L("ID_PIN=%d\n"), iOTGIdPin); sl@0: sl@0: if (iOTGIdPin != RUsbOtgDriver::EIdPinBPlug) sl@0: { sl@0: if (iDetectionRetry++ < 3) sl@0: { sl@0: iCaseStep = EVerifyIDGone; sl@0: otgQueueOtgIdPinNotification( iOTGIdPin, iStatus ); sl@0: SetActive(); sl@0: break; sl@0: } sl@0: else sl@0: { sl@0: return TestFailed(KErrAbort, _L("ID_PIN NOT 'removed' - FAILED!")); sl@0: } sl@0: } sl@0: // check using the API in a syncronous way too sl@0: if (otgIdPinPresent()) sl@0: { sl@0: return TestFailed(KErrAbort, _L("ID_PIN syncronous call error - FAILED!")); sl@0: } sl@0: iCaseStep = ERepeatLoop; sl@0: SelfComplete(); sl@0: break; sl@0: sl@0: case EUnloadLdd: sl@0: // 7. unload sl@0: if (EFalse == StepUnloadLDD()) sl@0: return TestFailed(KErrAbort,_L("Unload Ldd failure")); sl@0: sl@0: iCaseStep = ELastStep; sl@0: SelfComplete(); sl@0: break; sl@0: sl@0: case ELastStep: sl@0: TestPassed(); sl@0: break; sl@0: sl@0: default: sl@0: test.Printf(_L(" unknown test step")); sl@0: Cancel(); sl@0: return (TestFailed(KErrCorrupt, _L(" unknown test step"))); sl@0: } sl@0: } sl@0: