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 "b2bwatchers.h" sl@0: #include "testcase1233.h" sl@0: sl@0: #include sl@0: sl@0: #define LOG_INTO_STEP(a) test.Printf(_L("\nInto Step [%S]\n\n"), &a); sl@0: 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: */ sl@0: _LIT(KTestCaseId,"PBASE-USB_OTGDI-1233"); sl@0: const TTestCaseFactoryReceipt CTestCase1233::iFactoryReceipt(KTestCaseId); sl@0: sl@0: CTestCase1233* CTestCase1233::NewL(TBool aHost) sl@0: { sl@0: LOG_FUNC sl@0: CTestCase1233* self = new (ELeave) CTestCase1233(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: CTestCase1233::CTestCase1233(TBool aHost) sl@0: : CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: } sl@0: sl@0: sl@0: /** sl@0: ConstructL sl@0: */ sl@0: void CTestCase1233::ConstructL() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: iTestVID = 0x0E22; // Symbian sl@0: iTestPID = 0xF000 + 1233; // Test 1233 sl@0: sl@0: BaseConstructL(); sl@0: } sl@0: sl@0: sl@0: CTestCase1233::~CTestCase1233() sl@0: { sl@0: LOG_FUNC sl@0: iCollector.DestroyObservers(); sl@0: Cancel(); sl@0: } sl@0: sl@0: sl@0: void CTestCase1233::ExecuteTestCaseL() sl@0: { sl@0: LOG_FUNC sl@0: iCaseStep = EPreconditions; sl@0: CActiveScheduler::Add(this); sl@0: SelfComplete(); sl@0: } sl@0: sl@0: sl@0: void CTestCase1233::DoCancel() sl@0: { sl@0: LOG_FUNC sl@0: // cancel our timer sl@0: iTimer.Cancel(); sl@0: } sl@0: sl@0: sl@0: void CTestCase1233::RunStepL() sl@0: { sl@0: LOG_FUNC sl@0: 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: /*==================================================*/ sl@0: /* Fixed 'pre' steps */ sl@0: /*==================================================*/ sl@0: case EPreconditions: sl@0: { sl@0: LOG_INTO_STEP(_L("EPreconditions")) sl@0: sl@0: iCaseStep = ELoadLdd; sl@0: StepB2BPreconditions(); sl@0: break; sl@0: } sl@0: sl@0: case ELoadLdd: sl@0: { sl@0: LOG_INTO_STEP(_L("ELoadLdd")) sl@0: sl@0: // Note we use here the hex equivalent of #1233 for the PID sl@0: sl@0: if (!StepLoadClient(0xF4D1/*use default settings for SRP/HNP support*/)) sl@0: { sl@0: return TestFailed(KErrAbort, _L("Client Load Failure")); sl@0: } sl@0: sl@0: // load OTG ldd and init. sl@0: if (!StepLoadLDD()) sl@0: { sl@0: return TestFailed(KErrAbort, _L("OTG Load Failure")); sl@0: } sl@0: sl@0: if(otgActivateFdfActor()!=KErrNone) sl@0: { sl@0: return TestFailed(KErrAbort, _L("Couldn't load FDF Actor")); sl@0: } sl@0: sl@0: // test that the right cable is in sl@0: CheckRoleConnections(); sl@0: sl@0: // subscribe to OTG states,events and messages now that it has loaded OK sl@0: TRAPD(result, iCollector.CreateObserversL(*this)); sl@0: if (KErrNone != result) sl@0: { sl@0: return(TestFailed(KErrNoMemory, _L("Unable to create observers"))); sl@0: } sl@0: sl@0: // Allow enough time for 8 enumerations, say a second each, plus two of the sl@0: // tests require 15 seconds of SOF traffic sl@0: sl@0: const TInt KTestCase1233Timeout = 45000; sl@0: iCollector.AddStepTimeout(KTestCase1233Timeout); sl@0: sl@0: iCollector.ClearAllEvents(); sl@0: iCaseStep = ERaiseVBus; sl@0: sl@0: SelfComplete(); sl@0: break; sl@0: } sl@0: sl@0: /*==================================================*/ sl@0: /* Steps for this test case only */ sl@0: /*==================================================*/ sl@0: sl@0: case ELoopToNextPID: sl@0: { sl@0: LOG_INTO_STEP(_L("ELoopToNextPID")); sl@0: sl@0: if (KTestCaseWatchdogTO == iStatus.Int()) sl@0: { sl@0: iCollector.DestroyObservers(); sl@0: return TestFailed(KErrAbort, _L("Timeout")); sl@0: } sl@0: sl@0: if ( iTestVID == 0x0E22 ) sl@0: { sl@0: iTestVID = 0x1A0A; // OPT and test devices sl@0: iTestPID = 0x0100; // One *before* the first HS test ID sl@0: } sl@0: sl@0: iTestPID++; sl@0: sl@0: if ( iTestPID > 0x0108 ) sl@0: { sl@0: test.Printf(_L("All VID/PID pairs done\n")); sl@0: sl@0: iCaseStep = EUnloadLdd; sl@0: } sl@0: else sl@0: { sl@0: if(gTestRoleMaster) sl@0: { sl@0: // B sl@0: test.Printf(_L("Setting VID/PID of 0x%04x/0x%04x\n"),iTestVID,iTestPID); sl@0: sl@0: if (!StepChangeVidPid(iTestVID,iTestPID)) sl@0: { sl@0: return TestFailed(KErrAbort, _L("VID/PID Change Failure")); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: // A sl@0: test.Printf(_L("Expecting VID/PID of 0x%04x/0x%04x\n"),iTestVID,iTestPID); sl@0: } sl@0: sl@0: iCollector.ClearAllEvents(); sl@0: iCaseStep = ERaiseVBus; sl@0: } sl@0: sl@0: SelfComplete(); sl@0: break; sl@0: } sl@0: sl@0: case ERaiseVBus: sl@0: { sl@0: LOG_INTO_STEP(_L("ERaiseVBus")); sl@0: sl@0: if (KTestCaseWatchdogTO == iStatus.Int()) sl@0: { sl@0: iCollector.DestroyObservers(); sl@0: return TestFailed(KErrAbort, _L("Timeout")); sl@0: } sl@0: sl@0: if (gTestRoleMaster) sl@0: { sl@0: // B device sl@0: iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised); sl@0: iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral); sl@0: iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateDefault); sl@0: iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateAddress); sl@0: iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventHnpEnabled); sl@0: iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured); sl@0: } sl@0: else sl@0: { sl@0: // A device sl@0: test.Printf(_L("Raising VBUS for VID/PID = 0x%04x/0x%04x\n"),iTestVID,iTestPID); sl@0: sl@0: if ( otgBusRequest() != KErrNone ) sl@0: { sl@0: return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!")); sl@0: } sl@0: sl@0: iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised); sl@0: iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy); sl@0: iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost); sl@0: } sl@0: sl@0: iCaseStep = EVBusRaised; sl@0: SetActive(); sl@0: break; sl@0: } sl@0: sl@0: case EVBusRaised: sl@0: { sl@0: LOG_INTO_STEP(_L("EVBusRaised")); sl@0: sl@0: if (KTestCaseWatchdogTO == iStatus.Int()) sl@0: { sl@0: return TestFailed(KErrAbort, _L("Timeout")); sl@0: } sl@0: sl@0: if ( otgVbusPresent() ) sl@0: { sl@0: test.Printf(_L("...VBUS is UP\n")); sl@0: iCaseStep = EDropVBus; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("...VBUS is DOWN\n")); sl@0: return TestFailed(KErrAbort, _L("Vbus did not rise - FAILED!")); sl@0: } sl@0: sl@0: if (gTestRoleMaster) sl@0: { sl@0: // B device sl@0: SelfComplete(); sl@0: } sl@0: else sl@0: { sl@0: // A device sl@0: sl@0: // The default device (0x0E22/0xB4D1) is passed to the FDF, which will (eventually) sl@0: // suspend and enter connection idle state. sl@0: sl@0: // The HS test devices (0x1A0A) will not be presented to FDF, so there will be no sl@0: // trailing connection idle to find. sl@0: sl@0: if ( iTestVID == 0x0E22 ) sl@0: { sl@0: iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle); sl@0: SetActive(); sl@0: } sl@0: else sl@0: { sl@0: SelfComplete(); sl@0: } sl@0: } sl@0: sl@0: break; sl@0: } sl@0: sl@0: case EDropVBus: sl@0: { sl@0: LOG_INTO_STEP(_L("EDropVBus")); sl@0: sl@0: if (KTestCaseWatchdogTO == iStatus.Int()) sl@0: { sl@0: iCollector.DestroyObservers(); sl@0: return TestFailed(KErrAbort, _L("Timeout")); sl@0: } sl@0: sl@0: if ( gTestRoleMaster) sl@0: { sl@0: // B device sl@0: iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped); sl@0: } sl@0: else sl@0: { sl@0: // A device sl@0: otgBusDrop(); sl@0: sl@0: iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped); sl@0: } sl@0: sl@0: iCaseStep = EVBusDropped; sl@0: SetActive(); sl@0: break; sl@0: } sl@0: sl@0: case EVBusDropped: sl@0: { sl@0: LOG_INTO_STEP(_L("EVBusDropped")); sl@0: sl@0: if (KTestCaseWatchdogTO == iStatus.Int()) sl@0: { sl@0: return TestFailed(KErrAbort, _L("Timeout")); sl@0: } sl@0: sl@0: if ( otgVbusPresent() ) sl@0: { sl@0: test.Printf(_L("...VBUS is UP\n")); sl@0: return TestFailed(KErrAbort, _L("Vbus did not rise - FAILED!")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("...VBUS is DOWN\n")); sl@0: iCaseStep = ELoopToNextPID; sl@0: } sl@0: sl@0: SelfComplete(); sl@0: break; sl@0: } sl@0: sl@0: /*==================================================*/ sl@0: /* Fixed 'post' steps */ sl@0: /*==================================================*/ sl@0: sl@0: case EUnloadLdd: sl@0: { sl@0: LOG_INTO_STEP(_L("EUnloadLdd")) sl@0: sl@0: otgDeactivateFdfActor(); sl@0: iCollector.DestroyObservers(); sl@0: if (EFalse == StepUnloadLDD()){ sl@0: return TestFailed(KErrAbort,_L("unload Ldd failure")); sl@0: } sl@0: if (!StepUnloadClient()){ sl@0: return TestFailed(KErrAbort,_L("Client Unload Failure")); sl@0: } sl@0: sl@0: iCaseStep = ELastStep; sl@0: SelfComplete(); sl@0: break; sl@0: } sl@0: sl@0: case ELastStep: sl@0: { sl@0: LOG_INTO_STEP(_L("ELastStep")) sl@0: sl@0: TestPassed(); sl@0: RequestCharacter(); sl@0: break; sl@0: } sl@0: sl@0: default: sl@0: { sl@0: LOG_INTO_STEP(_L("DEFAULT! (unknown test step)")); sl@0: Cancel(); sl@0: RequestCharacter(); sl@0: return (TestFailed(KErrCorrupt, _L(" unknown test step"))); sl@0: } sl@0: } sl@0: sl@0: }