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: // @file PBASE-T_USBDI-0472.cpp sl@0: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: #include "PBASE-T_USBDI-0472.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include "UsbDescriptorOffsets.h" sl@0: #include "TestPolicy.h" sl@0: sl@0: namespace NUnitTesting_USBDI sl@0: { sl@0: sl@0: _LIT(KTestCaseId,"PBASE-T_USBDI-0472"); sl@0: const TFunctorTestCase CUT_PBASE_T_USBDI_0472::iFunctor(KTestCaseId); sl@0: sl@0: CUT_PBASE_T_USBDI_0472* CUT_PBASE_T_USBDI_0472::NewL(TBool aHostRole) sl@0: { sl@0: CUT_PBASE_T_USBDI_0472* self = new (ELeave) CUT_PBASE_T_USBDI_0472(aHostRole); 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: CUT_PBASE_T_USBDI_0472::CUT_PBASE_T_USBDI_0472(TBool aHostRole) sl@0: : CBaseTestCase(KTestCaseId,aHostRole) sl@0: { sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::ConstructL() sl@0: { sl@0: iTestDevice = new RUsbDeviceVendor(this); sl@0: BaseConstructL(); sl@0: } sl@0: sl@0: sl@0: CUT_PBASE_T_USBDI_0472::~CUT_PBASE_T_USBDI_0472() sl@0: { sl@0: LOG_FUNC sl@0: Cancel(); sl@0: sl@0: delete iClientAction; sl@0: delete iActorFDF; sl@0: if(!IsHost() && iTestDevice) sl@0: { sl@0: iTestDevice->Close(); sl@0: } sl@0: delete iTestDevice; sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::ExecuteHostTestCaseL() sl@0: { sl@0: LOG_FUNC sl@0: iActorFDF = CActorFDF::NewL(*this); sl@0: iClientAction = new (ELeave) CEp0Transfer(iInterface0); sl@0: iCaseStep = EConnectDevice; sl@0: iActorFDF->Monitor(); sl@0: TimeoutIn(30); sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::ExecuteDeviceTestCaseL() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: iTestDevice->OpenL(TestCaseId()); sl@0: iTestDevice->SubscribeToReports(iStatus); sl@0: SetActive(); sl@0: iTestDevice->SoftwareConnect(); sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::HostDoCancel() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Cancel the test step action timeout timer sl@0: sl@0: CancelTimeout(); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::DeviceDoCancel() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Cancel the test device sl@0: sl@0: iTestDevice->CancelSubscriptionToReports(); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::DeviceInsertedL(TUint aDeviceHandle) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: Cancel(); sl@0: TInt err(KErrNone); sl@0: sl@0: // Validate that device is as expected sl@0: sl@0: CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle); sl@0: if(testDevice.SerialNumber().Compare(TestCaseId()) != 0) sl@0: { sl@0: // Incorrect device for this test case sl@0: sl@0: RDebug::Printf(" Incorrect device serial number (%S) connected for this test case (%S)", sl@0: KErrNotFound,&testDevice.SerialNumber(),&TestCaseId()); sl@0: sl@0: // Start the connection timeout again sl@0: sl@0: TimeoutIn(30); sl@0: return; sl@0: } sl@0: sl@0: // Perform the correct test step sl@0: sl@0: switch(iCaseStep) sl@0: { sl@0: case EConnectDevice: sl@0: { sl@0: // Validate vendor identity sl@0: RDebug::Printf("Vendor identity: 0x%04x",testDevice.VendorId()); sl@0: if(testDevice.VendorId() != 0x0E22) sl@0: { sl@0: RDebug::Printf(" Vendor identity is not 0x0E22"); sl@0: return TestFailed(KErrCorrupt); sl@0: } sl@0: sl@0: // Validate product information sl@0: RDebug::Printf("Usb device supported specification: 0x%04x",testDevice.DeviceSpec()); sl@0: if(testDevice.DeviceSpec() != 0x0200) sl@0: { sl@0: RDebug::Printf(" Usb device supported specification is not 2.0"); sl@0: return TestFailed(KErrCorrupt); sl@0: } sl@0: RDebug::Printf("Usb product identity: 0x%04x",testDevice.ProductId()); sl@0: if(testDevice.ProductId() != 0x0040) sl@0: { sl@0: RDebug::Printf(" Usb product idenity is not 0x0040"); sl@0: return TestFailed(KErrCorrupt); sl@0: } sl@0: sl@0: RDebug::Printf("testDevice.ConfigurationString() = %S",&testDevice.ConfigurationString()); sl@0: gtest(KErrNone == testDevice.ConfigurationString().Compare(KConfigurationString())); sl@0: sl@0: RDebug::Printf("testDevice.Manufacturer() = %S",&testDevice.Manufacturer()); sl@0: gtest(KErrNone == testDevice.Manufacturer().Compare(KManufacturer())); sl@0: sl@0: RDebug::Printf("testDevice.SerialNumber = %s",&testDevice.SerialNumber()); sl@0: gtest(KErrNone == testDevice.SerialNumber().Compare(KTestCaseId())); sl@0: sl@0: RDebug::Printf("Waiting for device removal"); sl@0: iCaseStep = ERemoveDevice; sl@0: sl@0: TUint32 token; sl@0: err = testDevice.Device().GetTokenForInterface(0,token); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Printf(" Unable to get token for interface 0",err); sl@0: return TestFailed(err); sl@0: } sl@0: err = iInterface0.Open(token); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Printf(" Unable to open interface 0",err); sl@0: return TestFailed(err); sl@0: } sl@0: sl@0: // Send request to client to reconnect in 3 seconds sl@0: sl@0: TReconnectRequest request(3); sl@0: iClientAction->SendRequest(request,this); sl@0: sl@0: // Monitor for the reconnection from the client sl@0: sl@0: iActorFDF->Monitor(); sl@0: TimeoutIn(30); sl@0: } sl@0: break; sl@0: sl@0: case EConnectCancelled: sl@0: RDebug::Printf(" Bus event cancellation not successful"); sl@0: TestFailed(KErrCorrupt); sl@0: break; sl@0: sl@0: case EPassed: // Test case has been successfully concluded sl@0: { sl@0: TUint32 token; sl@0: err = testDevice.Device().GetTokenForInterface(0,token); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Printf(" Unable to get token for interface 0",err); sl@0: return TestFailed(err); sl@0: } sl@0: err = iInterface0.Open(token); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Printf(" Unable to open interface 0",err); sl@0: return TestFailed(err); sl@0: } sl@0: sl@0: // Send test case passed request to client sl@0: TTestCasePassed request; sl@0: iClientAction->SendRequest(request,this); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: RDebug::Printf(" Test case actions out of sync"); sl@0: TestFailed(KErrCorrupt); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::Ep0TransferCompleteL(TInt aCompletionCode) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: switch(iCaseStep) sl@0: { sl@0: case EPassed: sl@0: { sl@0: TestPassed(); sl@0: } sl@0: break; sl@0: sl@0: case EFailed: sl@0: { sl@0: TestFailed(KErrCompletion); sl@0: } sl@0: break; sl@0: sl@0: case ERemoveDevice: sl@0: { sl@0: // Doing nothing, client should be re-connecting sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: RDebug::Printf(" Unknown test step",KErrCorrupt); sl@0: TestFailed(KErrCorrupt); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::DeviceRemovedL(TUint aDeviceHandle) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: Cancel(); sl@0: sl@0: switch(iCaseStep) sl@0: { sl@0: case ERemoveDevice: sl@0: { sl@0: iCaseStep = EConnectCancelled; sl@0: sl@0: // start timer now sl@0: TimeoutIn(5); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: RDebug::Printf(" Test case actions out of sync"); sl@0: TestFailed(KErrCorrupt); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::BusErrorL(TInt aError) sl@0: { sl@0: // This test case handles no failiures on the bus sl@0: sl@0: TestFailed(aError); sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState, sl@0: RUsbDevice::TDeviceState aNewState,TInt aCompletionCode) sl@0: { sl@0: LOG_FUNC sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::HostRunL() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Obtain the completion code sl@0: TInt completionCode(iStatus.Int()); sl@0: sl@0: if(completionCode == KErrNone) sl@0: { sl@0: if(iCaseStep == EConnectCancelled) sl@0: { sl@0: // not a time-out sl@0: RDebug::Printf("Timer elapsed, reactivating notifications now"); sl@0: iCaseStep = EPassed; sl@0: iActorFDF->Monitor(); sl@0: } sl@0: else sl@0: { sl@0: // Action timeout sl@0: RDebug::Printf(" Action timeout"); sl@0: TestFailed(KErrTimedOut); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: RDebug::Printf(" Timeout timer could not complete",completionCode); sl@0: TestFailed(completionCode); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0472::DeviceRunL() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Disconnect the device sl@0: sl@0: iTestDevice->SoftwareDisconnect(); sl@0: sl@0: // Complete the test case request sl@0: sl@0: TestPolicy().SignalTestComplete(iStatus.Int()); sl@0: } sl@0: sl@0: sl@0: } sl@0: