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-0488.cpp
19 #include "PBASE-T_USBDI-0488.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
22 #include <d32usbdi_errors.h>
24 namespace NUnitTesting_USBDI
27 _LIT(KTestCaseId,"PBASE-T_USBDI-0488");
28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0488,TBool> CUT_PBASE_T_USBDI_0488::iFunctor(KTestCaseId);
30 CUT_PBASE_T_USBDI_0488* CUT_PBASE_T_USBDI_0488::NewL(TBool aHostRole)
32 CUT_PBASE_T_USBDI_0488* self = new (ELeave) CUT_PBASE_T_USBDI_0488(aHostRole);
33 CleanupStack::PushL(self);
35 CleanupStack::Pop(self);
40 CUT_PBASE_T_USBDI_0488::CUT_PBASE_T_USBDI_0488(TBool aHostRole)
41 : CBaseTestCase(KTestCaseId,aHostRole),
42 iCaseStep(EInProgress)
47 void CUT_PBASE_T_USBDI_0488::ConstructL()
49 iTestDevice = new RUsbDeviceA(this);
54 CUT_PBASE_T_USBDI_0488::~CUT_PBASE_T_USBDI_0488()
60 // Close the interface
61 iUsbInterface0.Close();
65 if(!IsHost() && iTestDevice)
73 void CUT_PBASE_T_USBDI_0488::ExecuteHostTestCaseL()
77 iActorFDF = CActorFDF::NewL(*this);
78 iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
84 /*static*/ TInt CUT_PBASE_T_USBDI_0488::TestSelectAlternateInterfaceThenPanic(TAny* aTest)
88 CTrapCleanup* trapHandler=CTrapCleanup::New();
94 CUT_PBASE_T_USBDI_0488* pTest = reinterpret_cast<CUT_PBASE_T_USBDI_0488*>(aTest);
96 // change interface setting whilst pipes are opened in another alt. setting, should panic
97 pTest->iUsbInterface1.SelectAlternateInterface(0); // panic expected
99 // Should never get here.*/
105 void CUT_PBASE_T_USBDI_0488::HostDoCancel()
108 // Cancel the timeout timer
113 void CUT_PBASE_T_USBDI_0488::ExecuteDeviceTestCaseL()
116 iTestDevice->OpenL(TestCaseId());
117 iTestDevice->SubscribeToReports(iStatus);
119 iTestDevice->SoftwareConnect();
122 void CUT_PBASE_T_USBDI_0488::DeviceDoCancel()
126 iTestDevice->CancelSubscriptionToReports();
130 void CUT_PBASE_T_USBDI_0488::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,RUsbDevice::TDeviceState aNewState,
131 TInt aCompletionCode)
137 void CUT_PBASE_T_USBDI_0488::DeviceInsertedL(TUint aDeviceHandle)
143 // Validate that device is as expected
144 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
145 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
147 // Incorrect device for this test case
148 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
149 KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
150 // Start the connection timeout again
152 iTimer.After(iStatus,30000000);
158 TUint32 token0,token1;
159 err = testDevice.Device().GetTokenForInterface(0,token0);
162 RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
163 return TestFailed(err);
165 err = iUsbInterface0.Open(token0); // Default interface setting 0
168 RDebug::Printf("<Error %d> Unable to open interface 0 using token %d",err,token0);
169 return TestFailed(err);
173 err = testDevice.Device().GetTokenForInterface(1,token1);
177 msg.Format(_L("<Error %d> Token for interface 1 could not be retrieved"),err);
180 TTestCaseFailed request(err,msg);
181 return iControlEp0->SendRequest(request,this);
183 err = iUsbInterface1.Open(token1); // Default interface setting 0
187 msg.Format(_L("<Error %d> Unable to open interface 1 using token %d"),err,token1);
190 TTestCaseFailed request(err,msg);
191 return iControlEp0->SendRequest(request,this);
194 // Select alternate interface setting 1
195 err = iUsbInterface1.SelectAlternateInterface(1);
199 msg.Format(_L("<Error %d> Selecting alternate interface setting 1 on interface 1"),err);
202 TTestCaseFailed request(err,msg);
203 iControlEp0->SendRequest(request,this);
207 // Open a pipe for endpoint (Int in)
208 TInt endpointAddress;
209 err = GetEndpointAddress(iUsbInterface1,1,KTransferTypeInterrupt,KEpDirectionIn,endpointAddress);
213 msg.Format(_L("<Error %d> unable to get endpoint address for interrupt in endpoint"),err);
216 TTestCaseFailed request(err,msg);
217 iControlEp0->SendRequest(request,this);
221 err = iUsbInterface1.OpenPipeForEndpoint(iInPipe,endpointAddress,EFalse);
225 msg.Format(_L("<Error %d> Unable to open pipe for endpoint 1"),err);
228 TTestCaseFailed request(err,msg);
229 return iControlEp0->SendRequest(request,this);
233 TInt r = rt.Create(_L("PanicThread"), CUT_PBASE_T_USBDI_0488::TestSelectAlternateInterfaceThenPanic, KDefaultStackSize, 0x1000, 0x1000, reinterpret_cast<TAny*>(this));
234 gtest(r == KErrNone);
235 TRequestStatus status;
239 User::WaitForRequest(status);
240 gtest(status.Int() == UsbdiPanics::EInterfaceSettingChangeWithPipeOpen);
242 iUsbInterface1.Close();
246 // ok now, inform client that the test has passed
248 TTestCasePassed request;
249 return iControlEp0->SendRequest(request,this);
253 void CUT_PBASE_T_USBDI_0488::Ep0TransferCompleteL(TInt aCompletionCode)
257 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
259 if(aCompletionCode != KErrNone)
262 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
266 if(iCaseStep == EPassed)
268 if(aCompletionCode == KErrNone)
276 if(iCaseStep == EFailed)
278 return TestFailed(KErrCompletion);
283 void CUT_PBASE_T_USBDI_0488::DeviceRemovedL(TUint aDeviceHandle)
287 // The test device should not be removed until the test case has passed
288 // so this test case has not completed, and state this event as an error
289 TestFailed(KErrDisconnected);
293 void CUT_PBASE_T_USBDI_0488::BusErrorL(TInt aError)
297 // This test case handles no failiures on the bus
298 TestFailed(KErrCompletion);
301 void CUT_PBASE_T_USBDI_0488::HostRunL()
304 // Obtain the completion code
305 TInt completionCode(iStatus.Int());
307 if(completionCode == KErrNone)
310 RDebug::Printf("<Error> Action timeout");
311 TestFailed(KErrTimedOut);
315 RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
316 TestFailed(completionCode);
320 void CUT_PBASE_T_USBDI_0488::DeviceRunL()
324 // Disconnect the device
325 iTestDevice->SoftwareDisconnect();
327 // Complete the test case request
328 TestPolicy().SignalTestComplete(iStatus.Int());