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-0472.cpp
19 #include "PBASE-T_USBDI-0472.h"
23 #include "UsbDescriptorOffsets.h"
24 #include "TestPolicy.h"
26 namespace NUnitTesting_USBDI
29 _LIT(KTestCaseId,"PBASE-T_USBDI-0472");
30 const TFunctorTestCase<CUT_PBASE_T_USBDI_0472,TBool> CUT_PBASE_T_USBDI_0472::iFunctor(KTestCaseId);
32 CUT_PBASE_T_USBDI_0472* CUT_PBASE_T_USBDI_0472::NewL(TBool aHostRole)
34 CUT_PBASE_T_USBDI_0472* self = new (ELeave) CUT_PBASE_T_USBDI_0472(aHostRole);
35 CleanupStack::PushL(self);
37 CleanupStack::Pop(self);
42 CUT_PBASE_T_USBDI_0472::CUT_PBASE_T_USBDI_0472(TBool aHostRole)
43 : CBaseTestCase(KTestCaseId,aHostRole)
48 void CUT_PBASE_T_USBDI_0472::ConstructL()
50 iTestDevice = new RUsbDeviceVendor(this);
55 CUT_PBASE_T_USBDI_0472::~CUT_PBASE_T_USBDI_0472()
62 if(!IsHost() && iTestDevice)
70 void CUT_PBASE_T_USBDI_0472::ExecuteHostTestCaseL()
73 iActorFDF = CActorFDF::NewL(*this);
74 iClientAction = new (ELeave) CEp0Transfer(iInterface0);
75 iCaseStep = EConnectDevice;
80 void CUT_PBASE_T_USBDI_0472::ExecuteDeviceTestCaseL()
84 iTestDevice->OpenL(TestCaseId());
85 iTestDevice->SubscribeToReports(iStatus);
87 iTestDevice->SoftwareConnect();
90 void CUT_PBASE_T_USBDI_0472::HostDoCancel()
94 // Cancel the test step action timeout timer
100 void CUT_PBASE_T_USBDI_0472::DeviceDoCancel()
104 // Cancel the test device
106 iTestDevice->CancelSubscriptionToReports();
110 void CUT_PBASE_T_USBDI_0472::DeviceInsertedL(TUint aDeviceHandle)
117 // Validate that device is as expected
119 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
120 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
122 // Incorrect device for this test case
124 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
125 KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
127 // Start the connection timeout again
133 // Perform the correct test step
139 // Validate vendor identity
140 RDebug::Printf("Vendor identity: 0x%04x",testDevice.VendorId());
141 if(testDevice.VendorId() != 0x0E22)
143 RDebug::Printf("<Error> Vendor identity is not 0x0E22");
144 return TestFailed(KErrCorrupt);
147 // Validate product information
148 RDebug::Printf("Usb device supported specification: 0x%04x",testDevice.DeviceSpec());
149 if(testDevice.DeviceSpec() != 0x0200)
151 RDebug::Printf("<Error> Usb device supported specification is not 2.0");
152 return TestFailed(KErrCorrupt);
154 RDebug::Printf("Usb product identity: 0x%04x",testDevice.ProductId());
155 if(testDevice.ProductId() != 0x0040)
157 RDebug::Printf("<Error> Usb product idenity is not 0x0040");
158 return TestFailed(KErrCorrupt);
161 RDebug::Printf("testDevice.ConfigurationString() = %S",&testDevice.ConfigurationString());
162 gtest(KErrNone == testDevice.ConfigurationString().Compare(KConfigurationString()));
164 RDebug::Printf("testDevice.Manufacturer() = %S",&testDevice.Manufacturer());
165 gtest(KErrNone == testDevice.Manufacturer().Compare(KManufacturer()));
167 RDebug::Printf("testDevice.SerialNumber = %s",&testDevice.SerialNumber());
168 gtest(KErrNone == testDevice.SerialNumber().Compare(KTestCaseId()));
170 RDebug::Printf("Waiting for device removal");
171 iCaseStep = ERemoveDevice;
174 err = testDevice.Device().GetTokenForInterface(0,token);
177 RDebug::Printf("<Error %d> Unable to get token for interface 0",err);
178 return TestFailed(err);
180 err = iInterface0.Open(token);
183 RDebug::Printf("<Error %d> Unable to open interface 0",err);
184 return TestFailed(err);
187 // Send request to client to reconnect in 3 seconds
189 TReconnectRequest request(3);
190 iClientAction->SendRequest(request,this);
192 // Monitor for the reconnection from the client
194 iActorFDF->Monitor();
199 case EConnectCancelled:
200 RDebug::Printf("<Error> Bus event cancellation not successful");
201 TestFailed(KErrCorrupt);
204 case EPassed: // Test case has been successfully concluded
207 err = testDevice.Device().GetTokenForInterface(0,token);
210 RDebug::Printf("<Error %d> Unable to get token for interface 0",err);
211 return TestFailed(err);
213 err = iInterface0.Open(token);
216 RDebug::Printf("<Error %d> Unable to open interface 0",err);
217 return TestFailed(err);
220 // Send test case passed request to client
221 TTestCasePassed request;
222 iClientAction->SendRequest(request,this);
227 RDebug::Printf("<Error> Test case actions out of sync");
228 TestFailed(KErrCorrupt);
234 void CUT_PBASE_T_USBDI_0472::Ep0TransferCompleteL(TInt aCompletionCode)
248 TestFailed(KErrCompletion);
254 // Doing nothing, client should be re-connecting
259 RDebug::Printf("<Error %d> Unknown test step",KErrCorrupt);
260 TestFailed(KErrCorrupt);
266 void CUT_PBASE_T_USBDI_0472::DeviceRemovedL(TUint aDeviceHandle)
276 iCaseStep = EConnectCancelled;
284 RDebug::Printf("<Error> Test case actions out of sync");
285 TestFailed(KErrCorrupt);
290 void CUT_PBASE_T_USBDI_0472::BusErrorL(TInt aError)
292 // This test case handles no failiures on the bus
297 void CUT_PBASE_T_USBDI_0472::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
298 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
303 void CUT_PBASE_T_USBDI_0472::HostRunL()
307 // Obtain the completion code
308 TInt completionCode(iStatus.Int());
310 if(completionCode == KErrNone)
312 if(iCaseStep == EConnectCancelled)
315 RDebug::Printf("Timer elapsed, reactivating notifications now");
317 iActorFDF->Monitor();
322 RDebug::Printf("<Error> Action timeout");
323 TestFailed(KErrTimedOut);
328 RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
329 TestFailed(completionCode);
334 void CUT_PBASE_T_USBDI_0472::DeviceRunL()
338 // Disconnect the device
340 iTestDevice->SoftwareDisconnect();
342 // Complete the test case request
344 TestPolicy().SignalTestComplete(iStatus.Int());