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-0485.cpp
19 #include "PBASE-T_USBDI-0485.h"
20 #include "testpolicy.h"
21 #include "testdebug.h"
22 #include "modelleddevices.h"
24 namespace NUnitTesting_USBDI
27 _LIT(KTestCaseId,"PBASE-T_USBDI-0485");
28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0485,TBool> CUT_PBASE_T_USBDI_0485::iFunctor(KTestCaseId);
30 CUT_PBASE_T_USBDI_0485* CUT_PBASE_T_USBDI_0485::NewL(TBool aHostRole)
32 CUT_PBASE_T_USBDI_0485* self = new (ELeave) CUT_PBASE_T_USBDI_0485(aHostRole);
33 CleanupStack::PushL(self);
35 CleanupStack::Pop(self);
40 CUT_PBASE_T_USBDI_0485::CUT_PBASE_T_USBDI_0485(TBool aHostRole)
41 : CBaseTestCase(KTestCaseId,aHostRole),
42 iCaseStep(EInProgress)
47 void CUT_PBASE_T_USBDI_0485::ConstructL()
49 iTestDevice = new RUsbDeviceVendor(this);
54 CUT_PBASE_T_USBDI_0485::~CUT_PBASE_T_USBDI_0485()
60 // Close the interface
61 iUsbInterface0.Close();
65 if(!IsHost() && iTestDevice)
72 void CUT_PBASE_T_USBDI_0485::ExecuteHostTestCaseL()
76 // Create the actor for the Function Driver Framework
78 iActorFDF = CActorFDF::NewL(*this);
80 // Create the control transfer for requests
82 iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
84 // Monitor for devices
88 // Start the connection timeout timer
94 void CUT_PBASE_T_USBDI_0485::ExecuteDeviceTestCaseL()
98 // Create the test device
100 iTestDevice->OpenL(TestCaseId());
101 iTestDevice->SubscribeToReports(iStatus);
104 // Connect the device to the host
106 iTestDevice->SoftwareConnect();
110 void CUT_PBASE_T_USBDI_0485::HostDoCancel()
114 // Cancel the test step action timeout timer
120 void CUT_PBASE_T_USBDI_0485::DeviceDoCancel()
124 // Cancel the device (the activity timer and the error reporting)
126 iTestDevice->CancelSubscriptionToReports();
130 void CUT_PBASE_T_USBDI_0485::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
131 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
138 void CUT_PBASE_T_USBDI_0485::DeviceInsertedL(TUint aDeviceHandle)
142 // Cancel the timeout timer
148 // Validate that device is as expected
150 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
151 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
153 // Incorrect device for this test case
155 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
156 KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
158 // Start the connection timeout again
164 // Get the token for the interface
166 err = testDevice.Device().GetTokenForInterface(0,iToken0);
169 RDebug::Printf("<Error %d> Unable to retrieve token for interface 0",err);
173 // Open the interface
174 err = iUsbInterface0.Open(iToken0);
177 RDebug::Printf("<Error %d> Unable to open interface 0");
182 // Send a request to control endpoint 0 to continuously NAK the request
184 iCaseStep = EInProgress;
185 TNakRequest request(0);
186 iControlEp0->SendRequest(request,this);
188 // Wait 1 second then close the interface
189 User::After(1000000);
190 RDebug::Printf("Closing interface 0");
191 iUsbInterface0.Close();
194 void CUT_PBASE_T_USBDI_0485::Ep0TransferCompleteL(TInt aCompletionCode)
198 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
204 if(aCompletionCode != KErrCancel)
206 RDebug::Printf("<Error %d> Nakking request was not cancelled by stack",aCompletionCode);
207 return TestFailed(aCompletionCode);
210 // No panic or leave so passed
212 RDebug::Printf("No leave or panic occured so open interface again and send test passed");
214 // Open the interface
216 TInt err(iUsbInterface0.Open(iToken0));
219 RDebug::Printf("<Error %d> Unable to open interface 0");
220 return TestFailed(err);
223 RDebug::Printf("Interface 0 re-opened");
226 TTestCasePassed request;
227 iControlEp0->SendRequest(request,this);
237 TestFailed(KErrCompletion);
242 void CUT_PBASE_T_USBDI_0485::DeviceRemovedL(TUint aDeviceHandle)
246 // The test device should not be removed until the test case has passed
247 // so this test case has not completed, and state this event as an error
249 TestFailed(KErrDisconnected);
253 void CUT_PBASE_T_USBDI_0485::BusErrorL(TInt aError)
257 // This test case handles no failiures on the bus
263 void CUT_PBASE_T_USBDI_0485::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);
284 Called when the device has reported any kind of error in its opertaion
285 or when the device has been informed by the host to report success
287 void CUT_PBASE_T_USBDI_0485::DeviceRunL()
291 // Disconnect the device
293 iTestDevice->SoftwareDisconnect();
295 // Complete the test case request
297 TestPolicy().SignalTestComplete(iStatus.Int());