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-0489.cpp
19 #include "PBASE-T_USBDI-0489.h"
20 #include "testpolicy.h"
21 #include "testdebug.h"
22 #include "modelleddevices.h"
24 namespace NUnitTesting_USBDI
27 _LIT(KTestCaseId,"PBASE-T_USBDI-0489");
28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0489,TBool> CUT_PBASE_T_USBDI_0489::iFunctor(KTestCaseId);
30 CUT_PBASE_T_USBDI_0489* CUT_PBASE_T_USBDI_0489::NewL(TBool aHostRole)
32 CUT_PBASE_T_USBDI_0489* self = new (ELeave) CUT_PBASE_T_USBDI_0489(aHostRole);
33 CleanupStack::PushL(self);
35 CleanupStack::Pop(self);
40 CUT_PBASE_T_USBDI_0489::CUT_PBASE_T_USBDI_0489(TBool aHostRole)
41 : CBaseTestCase(KTestCaseId,aHostRole),
42 iCaseStep(EInProgress)
47 void CUT_PBASE_T_USBDI_0489::ConstructL()
49 iTestDevice = new RUsbDeviceVendor(this);
54 CUT_PBASE_T_USBDI_0489::~CUT_PBASE_T_USBDI_0489()
60 // Close the interface
61 iUsbInterface0.Close();
65 if(!IsHost() && iTestDevice)
72 void CUT_PBASE_T_USBDI_0489::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_0489::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_0489::HostDoCancel()
114 // Cancel the test step action timeout timer
120 void CUT_PBASE_T_USBDI_0489::DeviceDoCancel()
124 // Cancel the device (the activity timer and the error reporting)
126 iTestDevice->CancelSubscriptionToReports();
130 void CUT_PBASE_T_USBDI_0489::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
131 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
138 void CUT_PBASE_T_USBDI_0489::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 cancel EP0 transfer
189 User::After(1000000);
190 RDebug::Printf("Cancelling EP0 transfer");
191 iUsbInterface0.CancelEP0Transfer();
194 void CUT_PBASE_T_USBDI_0489::Ep0TransferCompleteL(TInt aCompletionCode)
202 if(aCompletionCode != KErrCancel)
204 RDebug::Printf("<Error %d> Nakking request was not cancelled by stack",aCompletionCode);
205 return TestFailed(aCompletionCode);
208 // No panic or leave so passed
210 RDebug::Printf("No leave or panic occured so open interface again and send test passed");
212 // Open the interface
213 /*TODO DMA TInt err(iUsbInterface0.Open(iToken0));
216 RDebug::Printf("<Error %d> Unable to open interface 0"));
217 return TestFailed(err);
220 RDebug::Printf("Interface 0 re-opened"));*/
223 TTestCasePassed request;
224 iControlEp0->SendRequest(request,this);
234 TestFailed(KErrCompletion);
239 void CUT_PBASE_T_USBDI_0489::DeviceRemovedL(TUint aDeviceHandle)
243 // The test device should not be removed until the test case has passed
244 // so this test case has not completed, and state this event as an error
246 TestFailed(KErrDisconnected);
250 void CUT_PBASE_T_USBDI_0489::BusErrorL(TInt aError)
254 // This test case handles no failiures on the bus
260 void CUT_PBASE_T_USBDI_0489::HostRunL()
264 // Obtain the completion code
265 TInt completionCode(iStatus.Int());
267 if(completionCode == KErrNone)
270 RDebug::Printf("<Error> Action timeout");
271 TestFailed(KErrTimedOut);
275 RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
276 TestFailed(completionCode);
281 Called when the device has reported any kind of error in its opertaion
282 or when the device has been informed by the host to report success
284 void CUT_PBASE_T_USBDI_0489::DeviceRunL()
288 // Disconnect the device
290 iTestDevice->SoftwareDisconnect();
292 // Complete the test case request
294 TestPolicy().SignalTestComplete(iStatus.Int());