Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // @file PBASE-T_USBDI-0474.cpp
19 #include "PBASE-T_USBDI-0474.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
24 namespace NUnitTesting_USBDI
27 _LIT(KTestCaseId,"PBASE-T_USBDI-0474");
28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0474,TBool> CUT_PBASE_T_USBDI_0474::iFunctor(KTestCaseId);
30 CUT_PBASE_T_USBDI_0474* CUT_PBASE_T_USBDI_0474::NewL(TBool aHostRole)
32 CUT_PBASE_T_USBDI_0474* self = new (ELeave) CUT_PBASE_T_USBDI_0474(aHostRole);
33 CleanupStack::PushL(self);
35 CleanupStack::Pop(self);
40 CUT_PBASE_T_USBDI_0474::CUT_PBASE_T_USBDI_0474(TBool aHostRole)
41 : CBaseTestCase(KTestCaseId,aHostRole),
42 iCaseStep(EInProgress)
47 void CUT_PBASE_T_USBDI_0474::ConstructL()
49 iTestDevice = new RUsbDeviceB(this);
54 CUT_PBASE_T_USBDI_0474::~CUT_PBASE_T_USBDI_0474()
59 iUsbInterface0.Close();
63 if(!IsHost() && iTestDevice)
71 void CUT_PBASE_T_USBDI_0474::ExecuteHostTestCaseL()
75 iActorFDF = CActorFDF::NewL(*this);
76 iClientAction = new (ELeave) CEp0Transfer(iUsbInterface0);
82 void CUT_PBASE_T_USBDI_0474::ExecuteDeviceTestCaseL()
86 iTestDevice->OpenL(TestCaseId());
87 iTestDevice->SubscribeToReports(iStatus);
89 iTestDevice->SoftwareConnect();
93 void CUT_PBASE_T_USBDI_0474::HostDoCancel()
97 // Cancel the test step timeout
103 void CUT_PBASE_T_USBDI_0474::DeviceDoCancel()
109 iTestDevice->CancelSubscriptionToReports();
112 void CUT_PBASE_T_USBDI_0474::DeviceInsertedL(TUint aDeviceHandle)
118 // Validate that device is as expected
119 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
120 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
122 // Incorrect device for this test case
124 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
125 KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
127 // Start the connection timeout again
134 TUsbGenericDescriptor deviceDesc = testDevice.DeviceDescriptor();
135 TUsbGenericDescriptor configDesc = testDevice.ConfigurationDescriptor();
138 CHECK(CheckTreeAfterDeviceInsertion(testDevice, _L("RDeviceB")) == KErrNone);
140 // Inform client device test case successful
142 err = testDevice.Device().GetTokenForInterface(0,token0);
145 RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
146 return TestFailed(err);
148 err = iUsbInterface0.Open(token0); // Default interface setting 0
151 RDebug::Printf("<Error %d> Unable to open interface 1 using token %d",err,token0);
152 return TestFailed(err);
156 TTestCasePassed request;
157 iClientAction->SendRequest(request,this);
161 void CUT_PBASE_T_USBDI_0474::DeviceRemovedL(TUint aDeviceHandle)
165 // The test device should not be removed until the test case has passed
166 // so this test case has not completed, and state this event as an error
168 TestFailed(KErrDisconnected);
172 void CUT_PBASE_T_USBDI_0474::BusErrorL(TInt aError)
176 // This test case handles no failiures on the bus
182 void CUT_PBASE_T_USBDI_0474::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
183 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
189 void CUT_PBASE_T_USBDI_0474::Ep0TransferCompleteL(TInt aCompletionCode)
192 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
194 if(iCaseStep == EPassed)
199 if(iCaseStep == EFailed)
201 TestFailed(KErrCompletion);
206 void CUT_PBASE_T_USBDI_0474::HostRunL()
210 // Obtain the completion code
211 TInt completionCode(iStatus.Int());
213 if(completionCode == KErrNone)
216 RDebug::Printf("<Error> Action timeout");
217 TestFailed(KErrTimedOut);
221 RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
222 TestFailed(completionCode);
226 void CUT_PBASE_T_USBDI_0474::DeviceRunL()
230 // Disconnect the device
232 iTestDevice->SoftwareDisconnect();
234 // Complete the test case request
236 TestPolicy().SignalTestComplete(iStatus.Int());