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-0483.cpp
19 #include "PBASE-T_USBDI-0483.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
24 namespace NUnitTesting_USBDI
26 const TInt KGetConfigDescriptor = 0x0200;
27 _LIT(KTestCaseId,"PBASE-T_USBDI-0483");
28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0483,TBool> CUT_PBASE_T_USBDI_0483::iFunctor(KTestCaseId);
30 CUT_PBASE_T_USBDI_0483* CUT_PBASE_T_USBDI_0483::NewL(TBool aHostRole)
32 CUT_PBASE_T_USBDI_0483* self = new (ELeave) CUT_PBASE_T_USBDI_0483(aHostRole);
33 CleanupStack::PushL(self);
35 CleanupStack::Pop(self);
40 CUT_PBASE_T_USBDI_0483::CUT_PBASE_T_USBDI_0483(TBool aHostRole)
41 : CBaseTestCase(KTestCaseId,aHostRole),
42 iCaseStep(EInProgress)
47 void CUT_PBASE_T_USBDI_0483::ConstructL()
49 iTestDevice = new RUsbDeviceB(this);
54 CUT_PBASE_T_USBDI_0483::~CUT_PBASE_T_USBDI_0483()
58 // Close the interface
59 iUsbInterface0.Close();
62 delete iConfigDescriptorData;
63 if(!IsHost() && iTestDevice)
70 void CUT_PBASE_T_USBDI_0483::ExecuteHostTestCaseL()
74 // Create the actor for the Function Driver Framework
76 iActorFDF = CActorFDF::NewL(*this);
78 // Create the control transfer for requests
80 iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
82 // Monitor for devices
86 // Start the connection timeout timer
92 void CUT_PBASE_T_USBDI_0483::HostDoCancel()
96 // Cancel the test step timeout timer
102 void CUT_PBASE_T_USBDI_0483::ExecuteDeviceTestCaseL()
106 // Create the test device
108 iTestDevice->OpenL(TestCaseId());
109 iTestDevice->SubscribeToReports(iStatus);
112 // Connect the device to the host
114 iTestDevice->SoftwareConnect();
118 void CUT_PBASE_T_USBDI_0483::DeviceDoCancel()
122 // Cancel the reporting or errors from opertaions perfomed by the test device
124 iTestDevice->CancelSubscriptionToReports();
128 void CUT_PBASE_T_USBDI_0483::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
129 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
136 void CUT_PBASE_T_USBDI_0483::Ep0TransferCompleteL(TInt aCompletionCode)
140 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
142 if(aCompletionCode != KErrNone)
144 if(iCaseStep == EFailed)
145 {// todo, cope with errors
150 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
153 TTestCaseFailed request(aCompletionCode,msg);
154 iControlEp0->SendRequest(request,this);
170 TestFailed(KErrCompletion);
176 User::After(1000000);
177 TTestCasePassed request;
178 iControlEp0->SendRequest(request,this);
183 RDebug::Printf("<Error> Unknown test step");
184 TestFailed(KErrUnknown);
188 void CUT_PBASE_T_USBDI_0483::DeviceInsertedL(TUint aDeviceHandle)
195 // Validate that device is as expected
197 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
198 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
200 // Incorrect device for this test case
202 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
203 KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
205 // Start the connection timeout again
211 RDebug::Printf("iControlEp0->SendRequest(getConfiguration,this)");
213 err = testDevice.Device().GetTokenForInterface(0,token0);
216 RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
217 return TestFailed(err);
219 err = iUsbInterface0.Open(token0); // Default interface setting 0
222 RDebug::Printf("<Error %d> Unable to open interface 1 using token %d",err,token0);
223 return TestFailed(err);
226 // get config. descriptor now
227 TUint totalLength = testDevice.ConfigurationDescriptor().TotalLength();
228 RDebug::Printf("totalLength ==== %d",totalLength);
229 iConfigDescriptorData = HBufC8::NewL(totalLength);
230 TPtr8 des(iConfigDescriptorData->Des());
231 des.SetLength(totalLength);
232 TDescriptorGetRequest getConfiguration(KGetConfigDescriptor,0,des);
233 iControlEp0->SendRequest(getConfiguration,this);
237 void CUT_PBASE_T_USBDI_0483::DeviceRemovedL(TUint aDeviceHandle)
241 // The test device should not be removed until the test case has passed
242 // so this test case has not completed, and state this event as an error
244 TestFailed(KErrDisconnected);
248 void CUT_PBASE_T_USBDI_0483::BusErrorL(TInt aError)
252 // This test case handles no failiures on the bus
254 TestFailed(KErrCompletion);
258 void CUT_PBASE_T_USBDI_0483::HostRunL()
260 // Obtain the completion code
261 TInt completionCode(iStatus.Int());
263 if(completionCode == KErrNone)
266 RDebug::Printf("<Error> Action timeout");
267 TestFailed(KErrTimedOut);
271 RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
272 TestFailed(completionCode);
276 void CUT_PBASE_T_USBDI_0483::DeviceRunL()
280 // Disconnect the device
282 iTestDevice->SoftwareDisconnect();
284 // Complete the test case request
286 TestPolicy().SignalTestComplete(iStatus.Int());