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-0483.cpp sl@0: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: #include "PBASE-T_USBDI-0483.h" sl@0: #include "testpolicy.h" sl@0: #include "modelleddevices.h" sl@0: sl@0: sl@0: namespace NUnitTesting_USBDI sl@0: { sl@0: const TInt KGetConfigDescriptor = 0x0200; sl@0: _LIT(KTestCaseId,"PBASE-T_USBDI-0483"); sl@0: const TFunctorTestCase CUT_PBASE_T_USBDI_0483::iFunctor(KTestCaseId); sl@0: sl@0: CUT_PBASE_T_USBDI_0483* CUT_PBASE_T_USBDI_0483::NewL(TBool aHostRole) sl@0: { sl@0: CUT_PBASE_T_USBDI_0483* self = new (ELeave) CUT_PBASE_T_USBDI_0483(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_0483::CUT_PBASE_T_USBDI_0483(TBool aHostRole) sl@0: : CBaseTestCase(KTestCaseId,aHostRole), sl@0: iCaseStep(EInProgress) sl@0: { sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0483::ConstructL() sl@0: { sl@0: iTestDevice = new RUsbDeviceB(this); sl@0: BaseConstructL(); sl@0: } sl@0: sl@0: sl@0: CUT_PBASE_T_USBDI_0483::~CUT_PBASE_T_USBDI_0483() sl@0: { sl@0: Cancel(); sl@0: sl@0: // Close the interface sl@0: iUsbInterface0.Close(); sl@0: sl@0: delete iActorFDF; sl@0: delete iConfigDescriptorData; sl@0: if(!IsHost() && iTestDevice) sl@0: { sl@0: iTestDevice->Close(); sl@0: } sl@0: delete iTestDevice; sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0483::ExecuteHostTestCaseL() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Create the actor for the Function Driver Framework sl@0: sl@0: iActorFDF = CActorFDF::NewL(*this); sl@0: sl@0: // Create the control transfer for requests sl@0: sl@0: iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0); sl@0: sl@0: // Monitor for devices sl@0: sl@0: iActorFDF->Monitor(); sl@0: sl@0: // Start the connection timeout timer sl@0: sl@0: TimeoutIn(30); sl@0: sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0483::HostDoCancel() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Cancel the test step timeout timer sl@0: sl@0: CancelTimeout(); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0483::ExecuteDeviceTestCaseL() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Create the test device sl@0: sl@0: iTestDevice->OpenL(TestCaseId()); sl@0: iTestDevice->SubscribeToReports(iStatus); sl@0: SetActive(); sl@0: sl@0: // Connect the device to the host sl@0: sl@0: iTestDevice->SoftwareConnect(); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0483::DeviceDoCancel() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Cancel the reporting or errors from opertaions perfomed by the test device sl@0: sl@0: iTestDevice->CancelSubscriptionToReports(); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0483::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState, sl@0: RUsbDevice::TDeviceState aNewState,TInt aCompletionCode) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0483::Ep0TransferCompleteL(TInt aCompletionCode) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode); sl@0: sl@0: if(aCompletionCode != KErrNone) sl@0: { sl@0: if(iCaseStep == EFailed) sl@0: {// todo, cope with errors sl@0: } sl@0: else sl@0: { sl@0: TBuf<256> msg; sl@0: msg.Format(_L(" Transfer to control endpoint 0 was not successful"),aCompletionCode); sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(aCompletionCode,msg); sl@0: iControlEp0->SendRequest(request,this); sl@0: return; sl@0: } sl@0: } sl@0: sl@0: switch(iCaseStep) sl@0: { sl@0: // Test case passed sl@0: sl@0: case EPassed: sl@0: TestPassed(); sl@0: break; sl@0: sl@0: // Test case failed sl@0: sl@0: case EFailed: sl@0: TestFailed(KErrCompletion); sl@0: break; sl@0: sl@0: case EInProgress: sl@0: { sl@0: iCaseStep = EPassed; sl@0: User::After(1000000); sl@0: TTestCasePassed request; sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: RDebug::Printf(" Unknown test step"); sl@0: TestFailed(KErrUnknown); sl@0: break; sl@0: } sl@0: } sl@0: void CUT_PBASE_T_USBDI_0483::DeviceInsertedL(TUint aDeviceHandle) sl@0: { sl@0: LOG_FUNC sl@0: Cancel(); sl@0: 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: RDebug::Printf("iControlEp0->SendRequest(getConfiguration,this)"); sl@0: TUint32 token0; sl@0: err = testDevice.Device().GetTokenForInterface(0,token0); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Printf(" Token for interface 0 could not be retrieved",err); sl@0: return TestFailed(err); sl@0: } sl@0: err = iUsbInterface0.Open(token0); // Default interface setting 0 sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Printf(" Unable to open interface 1 using token %d",err,token0); sl@0: return TestFailed(err); sl@0: } sl@0: sl@0: // get config. descriptor now sl@0: TUint totalLength = testDevice.ConfigurationDescriptor().TotalLength(); sl@0: RDebug::Printf("totalLength ==== %d",totalLength); sl@0: iConfigDescriptorData = HBufC8::NewL(totalLength); sl@0: TPtr8 des(iConfigDescriptorData->Des()); sl@0: des.SetLength(totalLength); sl@0: TDescriptorGetRequest getConfiguration(KGetConfigDescriptor,0,des); sl@0: iControlEp0->SendRequest(getConfiguration,this); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0483::DeviceRemovedL(TUint aDeviceHandle) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // The test device should not be removed until the test case has passed sl@0: // so this test case has not completed, and state this event as an error sl@0: sl@0: TestFailed(KErrDisconnected); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0483::BusErrorL(TInt aError) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // This test case handles no failiures on the bus sl@0: sl@0: TestFailed(KErrCompletion); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0483::HostRunL() 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: // Action timeout sl@0: RDebug::Printf(" Action timeout"); sl@0: TestFailed(KErrTimedOut); 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: void CUT_PBASE_T_USBDI_0483::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: }