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-0486.cpp
19 #include "PBASE-T_USBDI-0486.h"
20 #include "testpolicy.h"
21 #include "testdebug.h"
22 #include "modelleddevices.h"
24 namespace NUnitTesting_USBDI
27 _LIT(KTestCaseId,"PBASE-T_USBDI-0486");
28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0486,TBool> CUT_PBASE_T_USBDI_0486::iFunctor(KTestCaseId);
29 const TInt KBulkTranferId = 2;
30 const TInt KExpectedDataSize = 26;
32 CUT_PBASE_T_USBDI_0486* CUT_PBASE_T_USBDI_0486::NewL(TBool aHostRole)
34 CUT_PBASE_T_USBDI_0486* self = new (ELeave) CUT_PBASE_T_USBDI_0486(aHostRole);
35 CleanupStack::PushL(self);
37 CleanupStack::Pop(self);
42 CUT_PBASE_T_USBDI_0486::CUT_PBASE_T_USBDI_0486(TBool aHostRole)
43 : CBaseBulkTestCase(KTestCaseId,aHostRole),
44 iCaseStep(EWaitForDeviceCConnection)
49 void CUT_PBASE_T_USBDI_0486::ConstructL()
52 iTestDeviceC = new RUsbDeviceC(this); // TODO check tree for device C, once inserted
55 CUT_PBASE_T_USBDI_0486::~CUT_PBASE_T_USBDI_0486()
63 Called when the device has reported any kind of error in its operation
64 or when the device has been informed by the host to report success
66 void CUT_PBASE_T_USBDI_0486::DeviceRunL()
69 // Complete the test case request
70 TestPolicy().SignalTestComplete(iStatus.Int());
73 void CUT_PBASE_T_USBDI_0486::DeviceDoCancel()
76 iTestDeviceC->CancelSubscriptionToReports();
79 TBool CUT_PBASE_T_USBDI_0486::CheckSN(const TDesC16& aSerialNumberGot, const TDesC& aExpectedSerialNumber)
81 TBool areSNsIdenticals = (aSerialNumberGot.Compare(aExpectedSerialNumber) == 0);
85 // Incorrect device for this test case
86 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
87 KErrNotFound,&aSerialNumberGot, &aExpectedSerialNumber);
89 return areSNsIdenticals;
93 void CUT_PBASE_T_USBDI_0486::Ep0TransferCompleteL(TInt aCompletionCode)
97 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
98 RDebug::Printf("--->Ep0TransferCompleteL, case step = %d", iCaseStep);
102 case EDeviceCConnected:
104 if(aCompletionCode != KErrNone)
106 RDebug::Printf("<Error %d> aCompletionCode != KErrNone",aCompletionCode);
107 return TestFailed(aCompletionCode);
110 iUsbInterface0.Close();
111 iCaseStep = EWaitForDeviceCDisconnection;
120 TestFailed(KErrCompletion);
125 void CUT_PBASE_T_USBDI_0486::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
129 RDebug::Printf("--->TransferCompleteL, case step = %d", iCaseStep);
131 if(aTransferId == KBulkTranferId)
133 if(aCompletionCode != KErrCancel && aCompletionCode != KErrUsbIOError)
136 msg.Format(_L("<Error %d> The transfer completed with no errors but should have done so"),aCompletionCode);
138 TTestCaseFailed request(KErrCorrupt,msg);
139 return iControlEp0->SendRequest(request,this);
144 RDebug::Printf("<Error> a transfer completed (id=%d) that was not expected",aTransferId);
145 return TestFailed(KErrCorrupt);
150 void CUT_PBASE_T_USBDI_0486::DeviceInsertedL(TUint aDeviceHandle)
153 RDebug::Printf("--->DeviceInsertedL, case step = %d", iCaseStep);
155 // Cancel the timeout timer
159 // Validate that device is as expected
160 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
162 // Perform the correct test step
165 case EWaitForDeviceCConnection:
167 if(!CheckSN(testDevice.SerialNumber(), KTestDeviceC_SN()))
169 return TestFailed(KErrNotFound);
171 iCaseStep = EDeviceCConnected;
173 err = testDevice.Device().GetTokenForInterface(0,iToken0DeviceC);
176 RDebug::Printf("<Error %d> Unable to retrieve token for interface 0",err);
179 // Open the interface
180 err = iUsbInterface0.Open(iToken0DeviceC);
183 RDebug::Printf("<Error %d> Unable to open interface 0");
188 err = testDevice.Device().GetTokenForInterface(1,token1);
192 msg.Format(_L("<Error %d> Token for interface 1 could not be retrieved"),err);
195 TTestCaseFailed request(err,msg);
196 return iControlEp0->SendRequest(request,this);
200 err = iUsbInterface1.Open(token1); // Default interface setting 0
204 msg.Format(_L("<Error %d> Unable to open interface 1 using token %d"),err,token1);
207 TTestCaseFailed request(err,msg);
208 return iControlEp0->SendRequest(request,this);
211 TInt endpointAddress;
212 // Queue a bulk in transfer on endpoint 2
213 err = GetEndpointAddress(iUsbInterface1,0,KTransferTypeBulk,KEpDirectionIn,endpointAddress);
217 msg.Format(_L("<Error %d> Address for bulk in endpoint could not be obtained"),err);
220 TTestCaseFailed request(err,msg);
221 return iControlEp0->SendRequest(request,this);
223 RDebug::Printf("Endpoint adress %08x",endpointAddress);
225 err = iUsbInterface1.OpenPipeForEndpoint(iTestPipeInterface1BulkIn,endpointAddress,ETrue);
229 msg.Format(_L("<Error %d> Unable to open pipe for endpoint %08x"),err,endpointAddress);
232 TTestCaseFailed request(err,msg);
233 return iControlEp0->SendRequest(request,this);
236 // Create the bulk transfers
237 iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,256,*this, KBulkTranferId);
239 // Initialise the descriptors for transfer
240 RDebug::Printf("Initialising the transfer descriptors");
241 err = iUsbInterface1.InitialiseTransferDescriptors();
245 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
248 TTestCaseFailed request(err,msg);
249 return iControlEp0->SendRequest(request,this);
251 iInTransfer[0]->TransferIn(KExpectedDataSize);
253 // disconnect device C and connect device A
254 TDisconnectDeviceCThenConnectDeviceARequest request;
255 iControlEp0->SendRequest(request,this);
257 // Monitor for the reconnection from the client
258 iActorFDF->Monitor();
264 case EWaitForDeviceAConnection:
266 if(!CheckSN(testDevice.SerialNumber(), TestCaseId()))
268 return TestFailed(KErrNotFound);
270 // try to open interface 0
271 err = iUsbInterface0.Open(iToken0DeviceC);
272 if(err != KErrNotFound) // invalid token
274 RDebug::Printf("iUsbInterface0.Open(iToken0DeviceC) === %d", err);
279 TUint32 token0DeviceA;
280 err = testDevice.Device().GetTokenForInterface(0,token0DeviceA);
283 RDebug::Printf("<Error %d> Unable to retrieve token(device A) for interface 0",err);
286 // Open the interface
287 err = iUsbInterface0.Open(token0DeviceA);
290 RDebug::Printf("<Error %d> Unable to open interface 0(device A)");
294 // ok, send EPassed request
296 // Send test case passed request to client
297 User::After(2000000);
298 TTestCasePassed request;
299 iControlEp0->SendRequest(request,this);
305 RDebug::Printf("<Error> Test case actions out of sync");
306 TestFailed(KErrCorrupt);
312 void CUT_PBASE_T_USBDI_0486::DeviceRemovedL(TUint aDeviceHandle)
316 RDebug::Printf("--->DeviceRemovedL, case step = %d", iCaseStep);
320 case EWaitForDeviceCDisconnection: // device C is disconnected now, interface 0 has been closed before
322 iCaseStep = EWaitForDeviceAConnection;
323 iActorFDF->Monitor();
328 RDebug::Printf("<Error> Test case actions out of sync");
329 TestFailed(KErrCorrupt);
334 void CUT_PBASE_T_USBDI_0486::HandleDeviceDConnection()
338 iTestDevice->SubscribeToReports(iStatus);
342 void CUT_PBASE_T_USBDI_0486::ExecuteDeviceTestCaseL()
346 // Create the test device
347 iTestDeviceC->OpenL(KTestDeviceC_SN());
348 iTestDeviceC->SubscribeToReports(iStatus);
351 // Connect the device to the host
352 iTestDeviceC->SoftwareConnect();
355 RUsbDeviceC* CUT_PBASE_T_USBDI_0486::TestDeviceC()
360 RUsbDeviceD* CUT_PBASE_T_USBDI_0486::TestDeviceD()
362 return iTestDevice; //from CBaseBulkTestCase