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-0478.cpp
19 #include "PBASE-T_USBDI-0478.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
24 namespace NUnitTesting_USBDI
27 _LIT(KTestCaseId,"PBASE-T_USBDI-0478");
28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0478,TBool> CUT_PBASE_T_USBDI_0478::iFunctor(KTestCaseId);
30 CUT_PBASE_T_USBDI_0478* CUT_PBASE_T_USBDI_0478::NewL(TBool aHostRole)
32 CUT_PBASE_T_USBDI_0478* self = new (ELeave) CUT_PBASE_T_USBDI_0478(aHostRole);
33 CleanupStack::PushL(self);
35 CleanupStack::Pop(self);
40 CUT_PBASE_T_USBDI_0478::CUT_PBASE_T_USBDI_0478(TBool aHostRole)
41 : CBaseTestCase(KTestCaseId,aHostRole),
42 iCaseStep(EInProgress)
47 void CUT_PBASE_T_USBDI_0478::ConstructL()
49 iTestDevice = new RUsbDeviceA(this);
54 CUT_PBASE_T_USBDI_0478::~CUT_PBASE_T_USBDI_0478()
60 // Close the interfaces
62 iDuplicateUsbInterface1.Close();
63 iUsbInterface1.Close();
64 iUsbInterface0.Close();
68 if(!IsHost() && iTestDevice)
75 void CUT_PBASE_T_USBDI_0478::ExecuteHostTestCaseL()
79 // Create the actor for the Function Driver Framework
81 iActorFDF = CActorFDF::NewL(*this);
83 // Create the control transfer for requests
85 iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
87 // Monitor for devices
91 // Start the connection timeout timer
96 void CUT_PBASE_T_USBDI_0478::HostDoCancel()
100 // Cancel the timeout timer for activity
106 void CUT_PBASE_T_USBDI_0478::ExecuteDeviceTestCaseL()
110 // Create the test device for this test case
112 iTestDevice->OpenL(TestCaseId());
113 iTestDevice->SubscribeToReports(iStatus);
116 // Connect the test device to the host
118 iTestDevice->SoftwareConnect();
121 void CUT_PBASE_T_USBDI_0478::DeviceDoCancel()
125 // Cancel the test device
127 iTestDevice->CancelSubscriptionToReports();
131 void CUT_PBASE_T_USBDI_0478::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
132 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
140 void CUT_PBASE_T_USBDI_0478::DeviceInsertedL(TUint aDeviceHandle)
147 // Validate that device is as expected
148 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
149 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
151 // Incorrect device for this test case
153 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
154 KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
156 // Start the connection timeout again
162 TUint32 token0,token1;
163 err = testDevice.Device().GetTokenForInterface(0,token0);
166 RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
167 return TestFailed(err);
169 err = iUsbInterface0.Open(token0); // Default interface setting 0
172 RDebug::Printf("<Error %d> Unable to open interface 0 using token %d",err,token0);
173 return TestFailed(err);
176 err = testDevice.Device().GetTokenForInterface(1,token1);
179 RDebug::Printf("<Error %d> Token for interface 1 could not be retrieved",err);
180 return TestFailed(err);
183 err = iUsbInterface1.Open(token1);
186 RDebug::Printf("<Error %d> Unable to open interface using token %d",err,token1);
187 return TestFailed(err);
190 // Acting as another FD open the interface
192 err = iDuplicateUsbInterface1.Open(token1);
196 msg.Format(_L("<Error> Able to open a concurrent hande to an interface"));
199 TTestCaseFailed request(KErrCompletion,msg);
200 iControlEp0->SendRequest(request,this);
203 RDebug::Printf("Attempt to open concurrent interface handle failed with: %d",err);
205 // Inform client device test case successful
206 User::After(1000000);
208 TTestCasePassed request;
209 iControlEp0->SendRequest(request,this);
213 void CUT_PBASE_T_USBDI_0478::Ep0TransferCompleteL(TInt aCompletionCode)
217 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
219 if(aCompletionCode != KErrNone)
222 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
226 if(iCaseStep == EPassed)
228 if(aCompletionCode == KErrNone)
236 if(iCaseStep == EFailed)
238 return TestFailed(KErrCompletion);
243 void CUT_PBASE_T_USBDI_0478::DeviceRemovedL(TUint aDeviceHandle)
247 // The test device should not be removed until the test case has passed
248 // so this test case has not completed, and state this event as an error
250 TestFailed(KErrDisconnected);
254 void CUT_PBASE_T_USBDI_0478::BusErrorL(TInt aError)
258 // This test case handles no failiures on the bus
263 void CUT_PBASE_T_USBDI_0478::HostRunL()
267 // Obtain the completion code
268 TInt completionCode(iStatus.Int());
270 if(completionCode == KErrNone)
273 RDebug::Printf("<Error> Action timeout");
274 TestFailed(KErrTimedOut);
278 RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
279 TestFailed(completionCode);
283 void CUT_PBASE_T_USBDI_0478::DeviceRunL()
287 // Disconnect the device
289 iTestDevice->SoftwareDisconnect();
291 // Complete the test case request
293 TestPolicy().SignalTestComplete(iStatus.Int());