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-1235.cpp
19 #include "PBASE-T_USBDI-1235.h"
21 #include "testdebug.h"
22 #include "modelleddevices.h"
23 #include "TestPolicy.h"
25 namespace NUnitTesting_USBDI
28 _LIT(KTestCaseId,"PBASE-T_USBDI-1235");
29 // the name is very important
30 const TFunctorTestCase<CUT_PBASE_T_USBDI_1235,TBool>
31 CUT_PBASE_T_USBDI_1235::iFunctor(KTestCaseId);
33 CUT_PBASE_T_USBDI_1235* CUT_PBASE_T_USBDI_1235::NewL(TBool aHostRole)
35 CUT_PBASE_T_USBDI_1235* self = new (ELeave) CUT_PBASE_T_USBDI_1235(aHostRole);
36 CleanupStack::PushL(self);
38 CleanupStack::Pop(self);
42 CUT_PBASE_T_USBDI_1235::CUT_PBASE_T_USBDI_1235(TBool aHostRole) :
43 CBaseTestCase(KTestCaseId, aHostRole), iSuspendedI0(EFalse),
48 void CUT_PBASE_T_USBDI_1235::ConstructL()
50 iTestDevice = new RUsbDeviceA(this);
54 CUT_PBASE_T_USBDI_1235::~CUT_PBASE_T_USBDI_1235()
58 // Cancel any async operations
60 Cancel(); // Cancel host timer
62 // Destroy the watchers
63 delete iInterface1Watcher;
64 delete iInterface0Watcher;
66 // Close the interfaces
67 iUsbInterface1.Close();
68 iUsbInterface0.Close();
72 if (!IsHost() && iTestDevice)
79 void CUT_PBASE_T_USBDI_1235::ExecuteHostTestCaseL()
83 iCaseStep = EInProcess;
84 iActorFDF = CActorFDF::NewL(*this);
85 iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
86 iInterface0Watcher = new (ELeave) CInterfaceWatcher(iUsbInterface0,TCallBack(CUT_PBASE_T_USBDI_1235::Interface0ResumedL,this));
87 iInterface1Watcher = new (ELeave) CInterfaceWatcher(iUsbInterface1,TCallBack(CUT_PBASE_T_USBDI_1235::Interface1ResumedL,this));
89 // Monitor for device connections
92 // Start the connection timeout
96 void CUT_PBASE_T_USBDI_1235::ExecuteDeviceTestCaseL()
100 // Construct the device for the test case
101 iTestDevice->OpenL(TestCaseId());
102 iTestDevice->SubscribeToReports(iStatus);
105 // Connect the test device
106 iTestDevice->SoftwareConnect();
109 void CUT_PBASE_T_USBDI_1235::HostDoCancel()
113 // Cancel the timeout timer
117 void CUT_PBASE_T_USBDI_1235::DeviceDoCancel()
122 iTestDevice->CancelSubscriptionToReports();
125 void CUT_PBASE_T_USBDI_1235::DeviceInsertedL(TUint aDeviceHandle)
129 Cancel(); // Cancel the timer
131 iDeviceHandle = aDeviceHandle;
132 iActorFDF->Monitor();
134 // Validate that device is as expected
135 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
136 if (testDevice.SerialNumber().Compare(TestCaseId()) != 0)
138 // Incorrect device for this test case
141 "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
142 KErrNotFound, &testDevice.SerialNumber(), &TestCaseId());
144 // Start the connection timeout again
149 CHECK(CheckTreeAfterDeviceInsertion(testDevice, _L("RDeviceA")) == KErrNone);
151 // Perform the correct test step
159 RDebug::Printf("Obtaining token for interface 0");
160 err = testDevice.Device().GetTokenForInterface(0, token1);
164 "<Error %d> Token for interface 0 could not be retrieved",
166 return TestFailed(err);
168 RDebug::Printf("Token 1 (%d) retrieved", token1);
169 RDebug::Printf("Opening interface 0");
170 err = iUsbInterface0.Open(token1); // Alternate interface setting 0
174 "<Error %d> Interface 0 could not be opened", err);
175 return TestFailed(err);
177 RDebug::Printf("Interface 0 opened");
179 RDebug::Printf("Obtaining token for interface 1");
180 err = testDevice.Device().GetTokenForInterface(1, token2);
184 "<Error %d> Token for interface 1 could not be retrieved",
186 return TestFailed(err);
188 RDebug::Printf("Opening interface 1");
189 err = iUsbInterface1.Open(token2); // Alternate interface setting 0
193 "<Error %d> Interface 1 could not be opened", err);
194 return TestFailed(err);
196 RDebug::Printf("Interface 1 opened");
198 SuspendDeviceByInterfacesAndCancelWaitForResume();
200 iCaseStep = EValidCancelSuspendAfterInterfaceSuspend;
206 TestFailed(KErrCorrupt);
211 TInt CUT_PBASE_T_USBDI_1235::Interface0ResumedL(TAny* aPtr)
214 RDebug::Printf("Interface 0 resumed");
215 CUT_PBASE_T_USBDI_1235* self =
216 reinterpret_cast<CUT_PBASE_T_USBDI_1235*>(aPtr);
217 TInt completionCode=self->iInterface0Watcher->CompletionCode();
219 "watcher 0 iStatus=%d",
221 self->iSuspendedI0 = EFalse;
223 switch (self->iCaseStep)
226 case EValidCancelSuspendAfterInterfaceSuspend:
228 if (completionCode == KErrCancel)
230 RDebug::Printf("CancelWaitForResume request: Success <>!",completionCode);
231 // do not care the device's status.
232 self->iCaseStep = EPassed;
237 "CancelWaitForResume request: Failed, < err %d >",
239 self->iCaseStep = EFailed;
253 TInt CUT_PBASE_T_USBDI_1235::Interface1ResumedL(TAny* aPtr)
256 RDebug::Printf("Interface 1 resumed");
257 CUT_PBASE_T_USBDI_1235* self =
258 reinterpret_cast<CUT_PBASE_T_USBDI_1235*>(aPtr);
259 TInt completionCode = self->iInterface1Watcher->CompletionCode();
260 RDebug::Printf("watcher 1 iStatus=%d",completionCode);
261 self->iSuspendedI1 = EFalse;
263 if(self->iCaseStep == EPassed && completionCode == KErrNone )
265 RDebug::Printf("Device resumed,test passed!");
266 self->SendEp0Request(); // stop client;
272 void CUT_PBASE_T_USBDI_1235::DeviceRemovedL(TUint aDeviceHandle)
276 // The test device should not be removed until the test case has passed
277 // so this test case has not completed, and state this event as an error
279 TestFailed(KErrDisconnected);
282 void CUT_PBASE_T_USBDI_1235::BusErrorL(TInt aError)
286 // This test case handles no failiures on the bus
292 void CUT_PBASE_T_USBDI_1235::DeviceStateChangeL(
293 RUsbDevice::TDeviceState aPreviousState,
294 RUsbDevice::TDeviceState aNewState, TInt aCompletionCode)
299 // test RInterface , the RUsbDevice notification logic not used .
301 "-Device State change from %d to %d err=%d",
302 aPreviousState, aNewState, aCompletionCode);
306 void CUT_PBASE_T_USBDI_1235::Ep0TransferCompleteL(TInt aCompletionCode)
309 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",
316 TestFailed(KErrCompletion);
325 void CUT_PBASE_T_USBDI_1235::HostRunL()
329 // Obtain the completion code
330 TInt completionCode(iStatus.Int());
332 if (completionCode == KErrNone)
335 RDebug::Printf("<Error> Action timeout");
336 TestFailed(KErrTimedOut);
340 RDebug::Printf("<Error %d> Timeout timer could not complete",
342 TestFailed(completionCode);
346 void CUT_PBASE_T_USBDI_1235::DeviceRunL()
350 // Disconnect the device
352 iTestDevice->SoftwareDisconnect();
354 // Complete the test case request
356 TestPolicy().SignalTestComplete(iStatus.Int());
359 void CUT_PBASE_T_USBDI_1235::SuspendDeviceByInterfacesAndCancelWaitForResume()
361 // Suspend interface 0
362 RDebug::Printf("Suspending interface 0");
363 iInterface0Watcher->SuspendAndWatch();
364 iSuspendedI0 = ETrue;
366 // Suspend interface 1
367 RDebug::Printf("Suspending interface 1");
368 iInterface1Watcher->SuspendAndWatch();
369 iSuspendedI1 = ETrue;
371 RDebug::Printf("CancelPermitSuspend interface 1");
372 // try to resume device,then host can notify peripheral test passed.
373 iUsbInterface1.CancelPermitSuspend();
375 // Only test the CancelWaitForResume() operation
376 // If we let the devic to suspend ,the periperal site could not receive the test control transfer which test finish result.
377 // select interface0 to test the function CancelWaitForResume
378 RDebug::Printf("CacelWaitForResume interface 0");
379 iUsbInterface0.CancelWaitForResume();
383 void CUT_PBASE_T_USBDI_1235::SendEp0Request()
385 TTestCasePassed request;
386 iControlEp0->SendRequest(request, this);