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-0479.cpp
19 #include "PBASE-T_USBDI-0479.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
24 namespace NUnitTesting_USBDI
27 _LIT(KTestCaseId,"PBASE-T_USBDI-0479");
28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0479,TBool> CUT_PBASE_T_USBDI_0479::iFunctor(KTestCaseId);
30 CUT_PBASE_T_USBDI_0479* CUT_PBASE_T_USBDI_0479::NewL(TBool aHostRole)
32 CUT_PBASE_T_USBDI_0479* self = new (ELeave) CUT_PBASE_T_USBDI_0479(aHostRole);
33 CleanupStack::PushL(self);
35 CleanupStack::Pop(self);
40 CUT_PBASE_T_USBDI_0479::CUT_PBASE_T_USBDI_0479(TBool aHostRole)
41 : CBaseTestCase(KTestCaseId,aHostRole),
42 iCaseStep(EInProgress)
47 void CUT_PBASE_T_USBDI_0479::ConstructL()
49 iTestDevice = new RUsbDeviceVendor(this);
54 CUT_PBASE_T_USBDI_0479::~CUT_PBASE_T_USBDI_0479()
60 iDuplicateUsbInterface0.Close();
61 iUsbInterface0.Close();
65 if(!IsHost() && iTestDevice)
72 void CUT_PBASE_T_USBDI_0479::ExecuteHostTestCaseL()
76 iActorFDF = CActorFDF::NewL(*this);
77 iClientAction = new (ELeave) CEp0Transfer(iUsbInterface0);
82 void CUT_PBASE_T_USBDI_0479::HostDoCancel()
86 // Cancel timing out the test step
92 void CUT_PBASE_T_USBDI_0479::ExecuteDeviceTestCaseL()
96 iTestDevice->OpenL(TestCaseId());
97 iTestDevice->SubscribeToReports(iStatus);
99 iTestDevice->SoftwareConnect();
102 void CUT_PBASE_T_USBDI_0479::DeviceDoCancel()
107 iTestDevice->CancelSubscriptionToReports();
111 void CUT_PBASE_T_USBDI_0479::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
112 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
118 void CUT_PBASE_T_USBDI_0479::DeviceInsertedL(TUint aDeviceHandle)
123 // Validate that device is as expected
124 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
125 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
127 // Incorrect device for this test case
129 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
130 KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
132 // Start the connection timeout again
139 TUint32 invalidToken(KMaxTUint-1); // The known invalid token
141 err = testDevice.Device().GetTokenForInterface(0,validToken);
144 RDebug::Printf("<Error %d> Token for interface could not be retrieved",err);
145 return TestFailed(err);
147 err = iUsbInterface0.Open(validToken); // Default interface setting 0
150 RDebug::Printf("<Error %d> Unable to open interface 0 using token %d",err,validToken);
151 return TestFailed(err);
154 err = iDuplicateUsbInterface0.Open(invalidToken);
158 msg.Format(_L("<Error %d> Able to open an interface that is not present"),KErrCorrupt);
161 TTestCaseFailed request(KErrCorrupt,msg);
162 iClientAction->SendRequest(request,this);
166 RDebug::Printf("Opening interface with invalid token failed with %d",err);
167 User::After(1000000);
169 TTestCasePassed request;
170 iClientAction->SendRequest(request,this);
175 void CUT_PBASE_T_USBDI_0479::DeviceRemovedL(TUint aDeviceHandle)
179 // The test device should not be removed until the test case has passed
180 // so this test case has not completed, and state this event as an error
182 TestFailed(KErrDisconnected);
186 void CUT_PBASE_T_USBDI_0479::BusErrorL(TInt aError)
190 // This test case handles no failiures on the bus
196 void CUT_PBASE_T_USBDI_0479::Ep0TransferCompleteL(TInt aCompletionCode)
200 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
202 if(aCompletionCode != KErrNone)
205 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
209 if(iCaseStep == EPassed)
211 if(aCompletionCode == KErrNone)
219 if(iCaseStep == EFailed)
221 return TestFailed(KErrCompletion);
226 void CUT_PBASE_T_USBDI_0479::HostRunL()
228 // Obtain the completion code
229 TInt completionCode(iStatus.Int());
231 if(completionCode == KErrNone)
234 RDebug::Printf("<Error> Action timeout");
235 TestFailed(KErrTimedOut);
239 RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
240 TestFailed(completionCode);
244 void CUT_PBASE_T_USBDI_0479::DeviceRunL()
248 // Disconnect the device
250 iTestDevice->SoftwareDisconnect();
252 // Complete the test case request
254 TestPolicy().SignalTestComplete(iStatus.Int());