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-0480.cpp
19 #include "PBASE-T_USBDI-0480.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
24 namespace NUnitTesting_USBDI
27 _LIT8(KDataPayload,"DEADBEEF");
29 _LIT(KTestCaseId,"PBASE-T_USBDI-0480");
30 const TFunctorTestCase<CUT_PBASE_T_USBDI_0480,TBool> CUT_PBASE_T_USBDI_0480::iFunctor(KTestCaseId);
32 CUT_PBASE_T_USBDI_0480* CUT_PBASE_T_USBDI_0480::NewL(TBool aHostRole)
34 CUT_PBASE_T_USBDI_0480* self = new (ELeave) CUT_PBASE_T_USBDI_0480(aHostRole);
35 CleanupStack::PushL(self);
37 CleanupStack::Pop(self);
42 CUT_PBASE_T_USBDI_0480::CUT_PBASE_T_USBDI_0480(TBool aHostRole)
43 : CBaseTestCase(KTestCaseId,aHostRole),
49 void CUT_PBASE_T_USBDI_0480::ConstructL()
51 iTestDevice = new RUsbDeviceA(this);
56 CUT_PBASE_T_USBDI_0480::~CUT_PBASE_T_USBDI_0480()
62 // Close pipe before interface
63 iUsbInterface1.Close();
64 iUsbInterface0.Close();
69 if(!IsHost() && iTestDevice)
76 void CUT_PBASE_T_USBDI_0480::ExecuteHostTestCaseL()
80 iActorFDF = CActorFDF::NewL(*this);
81 iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
87 void CUT_PBASE_T_USBDI_0480::HostDoCancel()
95 void CUT_PBASE_T_USBDI_0480::ExecuteDeviceTestCaseL()
99 iTestDevice->OpenL(TestCaseId());
100 iTestDevice->SubscribeToReports(iStatus);
102 iTestDevice->SoftwareConnect();
105 void CUT_PBASE_T_USBDI_0480::DeviceDoCancel()
110 iTestDevice->CancelSubscriptionToReports();
114 void CUT_PBASE_T_USBDI_0480::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
115 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
123 void CUT_PBASE_T_USBDI_0480::DeviceInsertedL(TUint aDeviceHandle)
130 // Validate that device is as expected
131 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
132 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
134 // Incorrect device for this test case
136 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
137 KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
139 // Start the connection timeout again
144 TUint32 token0,token1;
146 err = testDevice.Device().GetTokenForInterface(0,token0);
149 RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
150 return TestFailed(err);
152 err = iUsbInterface0.Open(token0); // Default interface setting 0
155 RDebug::Printf("<Error %d> Unable to open interface 0 using token %d",err,token0);
156 return TestFailed(err);
159 err = testDevice.Device().GetTokenForInterface(1,token1);
163 msg.Format(_L("<Error %d> Token for interface 1 could not be retrieved"),err);
166 TTestCaseFailed request(err,msg);
167 iControlEp0->SendRequest(request,this);
170 err = iUsbInterface1.Open(token1);
174 msg.Format(_L("<Error %d> Unable to open interface 1 using token %d"),err,token1);
177 TTestCaseFailed request(err,msg);
178 iControlEp0->SendRequest(request,this);
182 // Get the endpoint descriptor
183 TUsbEndpointDescriptor endpointDescriptor;
185 err = iUsbInterface1.GetEndpointDescriptor(0,1,endpointDescriptor);
189 msg.Format(_L("<Error %d> Descriptor for endpoint 0 cannot be obtained"),err);
192 TTestCaseFailed request(err,msg);
193 iControlEp0->SendRequest(request,this);
196 TUint16 maxPacketSize(endpointDescriptor.MaxPacketSize());
198 RDebug::Printf("Maximum packet size for endpoint 1 on interface 1 setting 0 is: %d",maxPacketSize);
200 // Perform a device directed control transfer
201 User::After(1000000);
202 iCaseStep = EEmptyDeviceXfer;
203 TEmptyDeviceRequest request;
204 iControlEp0->SendRequest(request,this);
208 void CUT_PBASE_T_USBDI_0480::Ep0TransferCompleteL(TInt aCompletionCode)
212 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
214 if(aCompletionCode != KErrNone)
216 if(iCaseStep == EFailed)
222 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
225 TTestCaseFailed request(aCompletionCode,msg);
226 iControlEp0->SendRequest(request,this);
240 TestFailed(KErrCompletion);
243 // Send an empty interface directed request
244 case EEmptyDeviceXfer:
246 iCaseStep = EEmptyInterfaceXfer;
247 TEmptyInterfaceRequest request(1); // Direct at interface 1
248 iControlEp0->SendRequest(request,this);
252 // Send a test payload request to device directed
253 case EEmptyInterfaceXfer:
255 iCaseStep = EDataPutDeviceXfer;
256 TDevicePutPayloadRequest request(KDataPayload);
257 iControlEp0->SendRequest(request,this);
261 // Send a test payload request to interface directed
262 case EDataPutDeviceXfer:
264 iCaseStep = EDataPutInterfaceXfer;
265 TInterfacePutPayloadRequest request(1,KDataPayload); // Direct at interface 1
266 iControlEp0->SendRequest(request,this);
271 case EDataPutInterfaceXfer:
274 User::After(1000000);
275 TTestCasePassed request;
276 iControlEp0->SendRequest(request,this);
281 RDebug::Printf("<Error> Unknown test step");
282 TestFailed(KErrUnknown);
288 void CUT_PBASE_T_USBDI_0480::DeviceRemovedL(TUint aDeviceHandle)
292 // The test device should not be removed until the test case has passed
293 // so this test case has not completed, and state this event as an error
294 TestFailed(KErrDisconnected);
298 void CUT_PBASE_T_USBDI_0480::BusErrorL(TInt aError)
302 // This test case handles no failiures on the bus
303 TestFailed(KErrGeneral);
306 void CUT_PBASE_T_USBDI_0480::HostRunL()
310 // Obtain the completion code
311 TInt completionCode(iStatus.Int());
313 if(completionCode == KErrNone)
316 RDebug::Printf("<Error> Action timeout");
317 TestFailed(KErrTimedOut);
321 RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
322 TestFailed(completionCode);
326 void CUT_PBASE_T_USBDI_0480::DeviceRunL()
330 // Disconnect the device
331 iTestDevice->SoftwareDisconnect();
333 // Complete the test case request
334 TestPolicy().SignalTestComplete(iStatus.Int());