First public contribution.
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-0481.cpp
19 #include "PBASE-T_USBDI-0481.h"
20 #include "testpolicy.h"
21 #include "testdebug.h"
22 #include "modelleddevices.h"
24 namespace NUnitTesting_USBDI
27 _LIT(KTestCaseId,"PBASE-T_USBDI-0481");
28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0481,TBool> CUT_PBASE_T_USBDI_0481::iFunctor(KTestCaseId);
30 CUT_PBASE_T_USBDI_0481* CUT_PBASE_T_USBDI_0481::NewL(TBool aHostRole)
32 CUT_PBASE_T_USBDI_0481* self = new (ELeave) CUT_PBASE_T_USBDI_0481(aHostRole);
33 CleanupStack::PushL(self);
35 CleanupStack::Pop(self);
40 CUT_PBASE_T_USBDI_0481::CUT_PBASE_T_USBDI_0481(TBool aHostRole)
41 : CBaseTestCase(KTestCaseId,aHostRole),
42 iCaseStep(EInProgress)
47 void CUT_PBASE_T_USBDI_0481::ConstructL()
49 iTestDevice = new RUsbDeviceA(this);
54 CUT_PBASE_T_USBDI_0481::~CUT_PBASE_T_USBDI_0481()
61 iUsbInterface0.Close();
62 iUsbInterface1.Close();
67 if(!IsHost() && iTestDevice)
74 void CUT_PBASE_T_USBDI_0481::ExecuteHostTestCaseL()
78 // Create the actor for the Function Driver Framework
79 iActorFDF = CActorFDF::NewL(*this);
81 // Create the control transfer for requests
82 iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
84 // Monitor for devices
87 // Start the connection timeout timer
92 void CUT_PBASE_T_USBDI_0481::ExecuteDeviceTestCaseL()
96 // Create the test device
97 iTestDevice->OpenL(TestCaseId());
98 iTestDevice->SubscribeToReports(iStatus);
101 // Connect the device to the host
102 iTestDevice->SoftwareConnect();
106 void CUT_PBASE_T_USBDI_0481::HostDoCancel()
110 // Cancel the test step action timeout timer
115 void CUT_PBASE_T_USBDI_0481::DeviceDoCancel()
119 // Cancel the device (the activity timer and the error reporting)
120 iTestDevice->CancelSubscriptionToReports();
124 void CUT_PBASE_T_USBDI_0481::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
125 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
132 void CUT_PBASE_T_USBDI_0481::DeviceInsertedL(TUint aDeviceHandle)
136 // Cancel the timeout timer
141 // Validate that device is as expected
142 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
143 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
145 // Incorrect device for this test case
146 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
147 KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
149 // Start the connection timeout again
154 // Get the token for interface 0
155 err = testDevice.Device().GetTokenForInterface(0,iToken0);
158 RDebug::Printf("<Error %d> Unable to retrieve token for interface 0",err);
163 err = iUsbInterface0.Open(iToken0);
166 RDebug::Printf("<Error %d> Unable to open interface 0");
170 // Get the token for interface 1
172 err = testDevice.Device().GetTokenForInterface(1,token1);
175 RDebug::Printf("<Error %d> token1 for interface 1",err);
176 return TestFailed(err);
179 err = iUsbInterface1.Open(token1); // Alternate interface setting 0
182 RDebug::Printf("<Error %d> Unable to open interface 1");
183 return TestFailed(err);
186 // Get the token for interface 1 again, fails
187 TUint32 token1Bis(0);
188 err = testDevice.Device().GetTokenForInterface(1,token1Bis);
191 RDebug::Printf("GetTokenForInterface(1,token1Bis), err != KErrInUse");
192 return TestFailed(err);
195 // Open interface 1 again, fails
196 RDebug::Printf("open it twice, catch error Code");
197 err = iUsbInterface1.Open(token1); // Alternate interface setting 0
200 RDebug::Printf("iUsbInterface1.Open(token1), err != KErrInUse");
201 return TestFailed(err);
205 User::After(1000000);
207 TTestCasePassed request;
208 iControlEp0->SendRequest(request,this);
211 void CUT_PBASE_T_USBDI_0481::Ep0TransferCompleteL(TInt aCompletionCode)
215 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
217 if(aCompletionCode != KErrNone)
220 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
224 if(iCaseStep == EPassed)
226 if(aCompletionCode == KErrNone)
234 if(iCaseStep == EFailed)
236 return TestFailed(KErrCompletion);
240 void CUT_PBASE_T_USBDI_0481::DeviceRemovedL(TUint aDeviceHandle)
244 // The test device should not be removed until the test case has passed
245 // so this test case has not completed, and state this event as an error
246 TestFailed(KErrDisconnected);
250 void CUT_PBASE_T_USBDI_0481::BusErrorL(TInt aError)
254 // This test case handles no failiures on the bus
259 void CUT_PBASE_T_USBDI_0481::HostRunL()
263 // Obtain the completion code
264 TInt completionCode(iStatus.Int());
266 if(completionCode == KErrNone)
269 RDebug::Printf("<Error> Action timeout");
270 TestFailed(KErrTimedOut);
274 RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
275 TestFailed(completionCode);
280 Called when the device has reported any kind of error in its opertaion
281 or when the device has been informed by the host to report success
283 void CUT_PBASE_T_USBDI_0481::DeviceRunL()
286 // Disconnect the device
287 iTestDevice->SoftwareDisconnect();
288 // Complete the test case request
289 TestPolicy().SignalTestComplete(iStatus.Int());