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-0488.cpp sl@0: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: #include "PBASE-T_USBDI-0488.h" sl@0: #include "testpolicy.h" sl@0: #include "modelleddevices.h" sl@0: #include sl@0: sl@0: namespace NUnitTesting_USBDI sl@0: { sl@0: sl@0: _LIT(KTestCaseId,"PBASE-T_USBDI-0488"); sl@0: const TFunctorTestCase CUT_PBASE_T_USBDI_0488::iFunctor(KTestCaseId); sl@0: sl@0: CUT_PBASE_T_USBDI_0488* CUT_PBASE_T_USBDI_0488::NewL(TBool aHostRole) sl@0: { sl@0: CUT_PBASE_T_USBDI_0488* self = new (ELeave) CUT_PBASE_T_USBDI_0488(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_0488::CUT_PBASE_T_USBDI_0488(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_0488::ConstructL() sl@0: { sl@0: iTestDevice = new RUsbDeviceA(this); sl@0: BaseConstructL(); sl@0: } sl@0: sl@0: sl@0: CUT_PBASE_T_USBDI_0488::~CUT_PBASE_T_USBDI_0488() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: Cancel(); sl@0: sl@0: // Close the interface sl@0: iUsbInterface0.Close(); sl@0: sl@0: delete iControlEp0; 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_0488::ExecuteHostTestCaseL() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: iActorFDF = CActorFDF::NewL(*this); sl@0: iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0); sl@0: iActorFDF->Monitor(); sl@0: sl@0: TimeoutIn(30); sl@0: } sl@0: sl@0: /*static*/ TInt CUT_PBASE_T_USBDI_0488::TestSelectAlternateInterfaceThenPanic(TAny* aTest) sl@0: { sl@0: LOG_CFUNC sl@0: sl@0: CTrapCleanup* trapHandler=CTrapCleanup::New(); sl@0: if(!trapHandler) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: sl@0: CUT_PBASE_T_USBDI_0488* pTest = reinterpret_cast(aTest); sl@0: sl@0: // change interface setting whilst pipes are opened in another alt. setting, should panic sl@0: pTest->iUsbInterface1.SelectAlternateInterface(0); // panic expected sl@0: sl@0: // Should never get here.*/ sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0488::HostDoCancel() sl@0: { sl@0: LOG_FUNC sl@0: // Cancel the timeout timer sl@0: CancelTimeout(); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0488::ExecuteDeviceTestCaseL() sl@0: { sl@0: LOG_FUNC 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_0488::DeviceDoCancel() sl@0: { sl@0: LOG_FUNC sl@0: // Cancel the device sl@0: iTestDevice->CancelSubscriptionToReports(); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0488::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,RUsbDevice::TDeviceState aNewState, sl@0: TInt aCompletionCode) sl@0: { sl@0: LOG_FUNC sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0488::DeviceInsertedL(TUint aDeviceHandle) sl@0: { sl@0: LOG_FUNC sl@0: Cancel(); sl@0: TInt err(KErrNone); sl@0: sl@0: // Validate that device is as expected 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: RDebug::Printf(" Incorrect device serial number (%S) connected for this test case (%S)", sl@0: KErrNotFound,&testDevice.SerialNumber(),&TestCaseId()); sl@0: // Start the connection timeout again sl@0: CancelTimeout(); sl@0: iTimer.After(iStatus,30000000); sl@0: SetActive(); sl@0: return; sl@0: } sl@0: sl@0: sl@0: TUint32 token0,token1; 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 0 using token %d",err,token0); sl@0: return TestFailed(err); sl@0: } sl@0: sl@0: __UHEAP_MARK; sl@0: err = testDevice.Device().GetTokenForInterface(1,token1); sl@0: if(err != KErrNone) sl@0: { sl@0: TBuf<256> msg; sl@0: msg.Format(_L(" Token for interface 1 could not be retrieved"),err); sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(err,msg); sl@0: return iControlEp0->SendRequest(request,this); sl@0: } sl@0: err = iUsbInterface1.Open(token1); // Default interface setting 0 sl@0: if(err != KErrNone) sl@0: { sl@0: TBuf<256> msg; sl@0: msg.Format(_L(" Unable to open interface 1 using token %d"),err,token1); sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(err,msg); sl@0: return iControlEp0->SendRequest(request,this); sl@0: } sl@0: sl@0: // Select alternate interface setting 1 sl@0: err = iUsbInterface1.SelectAlternateInterface(1); sl@0: if(err != KErrNone) sl@0: { sl@0: TBuf<256> msg; sl@0: msg.Format(_L(" Selecting alternate interface setting 1 on interface 1"),err); sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(err,msg); sl@0: iControlEp0->SendRequest(request,this); sl@0: return; sl@0: } sl@0: sl@0: // Open a pipe for endpoint (Int in) sl@0: TInt endpointAddress; sl@0: err = GetEndpointAddress(iUsbInterface1,1,KTransferTypeInterrupt,KEpDirectionIn,endpointAddress); sl@0: if(err != KErrNone) sl@0: { sl@0: TBuf<256> msg; sl@0: msg.Format(_L(" unable to get endpoint address for interrupt in endpoint"),err); sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(err,msg); sl@0: iControlEp0->SendRequest(request,this); sl@0: return; sl@0: } sl@0: sl@0: err = iUsbInterface1.OpenPipeForEndpoint(iInPipe,endpointAddress,EFalse); sl@0: if(err != KErrNone) sl@0: { sl@0: TBuf<256> msg; sl@0: msg.Format(_L(" Unable to open pipe for endpoint 1"),err); sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(err,msg); sl@0: return iControlEp0->SendRequest(request,this); sl@0: } sl@0: sl@0: RThread rt; sl@0: TInt r = rt.Create(_L("PanicThread"), CUT_PBASE_T_USBDI_0488::TestSelectAlternateInterfaceThenPanic, KDefaultStackSize, 0x1000, 0x1000, reinterpret_cast(this)); sl@0: gtest(r == KErrNone); sl@0: TRequestStatus status; sl@0: rt.Logon(status); sl@0: rt.Resume(); sl@0: rt.Close(); sl@0: User::WaitForRequest(status); sl@0: gtest(status.Int() == UsbdiPanics::EInterfaceSettingChangeWithPipeOpen); sl@0: sl@0: iUsbInterface1.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: // ok now, inform client that the test has passed sl@0: iCaseStep = EPassed; sl@0: TTestCasePassed request; sl@0: return iControlEp0->SendRequest(request,this); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0488::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: TBuf<256> msg; sl@0: msg.Format(_L(" Transfer to control endpoint 0 was not successful"),aCompletionCode); sl@0: RDebug::Print(msg); sl@0: } sl@0: sl@0: if(iCaseStep == EPassed) sl@0: { sl@0: if(aCompletionCode == KErrNone) sl@0: { sl@0: return TestPassed(); sl@0: } sl@0: // else error sl@0: iCaseStep = EFailed; sl@0: } sl@0: sl@0: if(iCaseStep == EFailed) sl@0: { sl@0: return TestFailed(KErrCompletion); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0488::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: TestFailed(KErrDisconnected); sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0488::BusErrorL(TInt aError) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // This test case handles no failiures on the bus sl@0: TestFailed(KErrCompletion); sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0488::HostRunL() sl@0: { sl@0: LOG_FUNC 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_0488::DeviceRunL() sl@0: { sl@0: LOG_FUNC sl@0: sl@0: // Disconnect the device sl@0: iTestDevice->SoftwareDisconnect(); sl@0: sl@0: // Complete the test case request sl@0: TestPolicy().SignalTestComplete(iStatus.Int()); sl@0: } sl@0: sl@0: sl@0: }