sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// @file PBASE-T_USBDI-1235.cpp
|
sl@0
|
15 |
// @internalComponent
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "PBASE-T_USBDI-1235.h"
|
sl@0
|
20 |
#include <d32usbc.h>
|
sl@0
|
21 |
#include "testdebug.h"
|
sl@0
|
22 |
#include "modelleddevices.h"
|
sl@0
|
23 |
#include "TestPolicy.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
namespace NUnitTesting_USBDI
|
sl@0
|
26 |
{
|
sl@0
|
27 |
|
sl@0
|
28 |
_LIT(KTestCaseId,"PBASE-T_USBDI-1235");
|
sl@0
|
29 |
// the name is very important
|
sl@0
|
30 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_1235,TBool>
|
sl@0
|
31 |
CUT_PBASE_T_USBDI_1235::iFunctor(KTestCaseId);
|
sl@0
|
32 |
|
sl@0
|
33 |
CUT_PBASE_T_USBDI_1235* CUT_PBASE_T_USBDI_1235::NewL(TBool aHostRole)
|
sl@0
|
34 |
{
|
sl@0
|
35 |
CUT_PBASE_T_USBDI_1235* self = new (ELeave) CUT_PBASE_T_USBDI_1235(aHostRole);
|
sl@0
|
36 |
CleanupStack::PushL(self);
|
sl@0
|
37 |
self->ConstructL();
|
sl@0
|
38 |
CleanupStack::Pop(self);
|
sl@0
|
39 |
return self;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
CUT_PBASE_T_USBDI_1235::CUT_PBASE_T_USBDI_1235(TBool aHostRole) :
|
sl@0
|
43 |
CBaseTestCase(KTestCaseId, aHostRole), iSuspendedI0(EFalse),
|
sl@0
|
44 |
iSuspendedI1(EFalse)
|
sl@0
|
45 |
{
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
void CUT_PBASE_T_USBDI_1235::ConstructL()
|
sl@0
|
49 |
{
|
sl@0
|
50 |
iTestDevice = new RUsbDeviceA(this);
|
sl@0
|
51 |
BaseConstructL();
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
CUT_PBASE_T_USBDI_1235::~CUT_PBASE_T_USBDI_1235()
|
sl@0
|
55 |
{
|
sl@0
|
56 |
LOG_FUNC
|
sl@0
|
57 |
|
sl@0
|
58 |
// Cancel any async operations
|
sl@0
|
59 |
|
sl@0
|
60 |
Cancel(); // Cancel host timer
|
sl@0
|
61 |
|
sl@0
|
62 |
// Destroy the watchers
|
sl@0
|
63 |
delete iInterface1Watcher;
|
sl@0
|
64 |
delete iInterface0Watcher;
|
sl@0
|
65 |
|
sl@0
|
66 |
// Close the interfaces
|
sl@0
|
67 |
iUsbInterface1.Close();
|
sl@0
|
68 |
iUsbInterface0.Close();
|
sl@0
|
69 |
|
sl@0
|
70 |
delete iControlEp0;
|
sl@0
|
71 |
delete iActorFDF;
|
sl@0
|
72 |
if (!IsHost() && iTestDevice)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
iTestDevice->Close();
|
sl@0
|
75 |
}
|
sl@0
|
76 |
delete iTestDevice;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
void CUT_PBASE_T_USBDI_1235::ExecuteHostTestCaseL()
|
sl@0
|
80 |
{
|
sl@0
|
81 |
LOG_FUNC
|
sl@0
|
82 |
|
sl@0
|
83 |
iCaseStep = EInProcess;
|
sl@0
|
84 |
iActorFDF = CActorFDF::NewL(*this);
|
sl@0
|
85 |
iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
|
sl@0
|
86 |
iInterface0Watcher = new (ELeave) CInterfaceWatcher(iUsbInterface0,TCallBack(CUT_PBASE_T_USBDI_1235::Interface0ResumedL,this));
|
sl@0
|
87 |
iInterface1Watcher = new (ELeave) CInterfaceWatcher(iUsbInterface1,TCallBack(CUT_PBASE_T_USBDI_1235::Interface1ResumedL,this));
|
sl@0
|
88 |
|
sl@0
|
89 |
// Monitor for device connections
|
sl@0
|
90 |
iActorFDF->Monitor();
|
sl@0
|
91 |
|
sl@0
|
92 |
// Start the connection timeout
|
sl@0
|
93 |
TimeoutIn(30);
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
void CUT_PBASE_T_USBDI_1235::ExecuteDeviceTestCaseL()
|
sl@0
|
97 |
{
|
sl@0
|
98 |
LOG_FUNC
|
sl@0
|
99 |
|
sl@0
|
100 |
// Construct the device for the test case
|
sl@0
|
101 |
iTestDevice->OpenL(TestCaseId());
|
sl@0
|
102 |
iTestDevice->SubscribeToReports(iStatus);
|
sl@0
|
103 |
SetActive();
|
sl@0
|
104 |
|
sl@0
|
105 |
// Connect the test device
|
sl@0
|
106 |
iTestDevice->SoftwareConnect();
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
void CUT_PBASE_T_USBDI_1235::HostDoCancel()
|
sl@0
|
110 |
{
|
sl@0
|
111 |
LOG_FUNC
|
sl@0
|
112 |
|
sl@0
|
113 |
// Cancel the timeout timer
|
sl@0
|
114 |
CancelTimeout();
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
void CUT_PBASE_T_USBDI_1235::DeviceDoCancel()
|
sl@0
|
118 |
{
|
sl@0
|
119 |
LOG_FUNC
|
sl@0
|
120 |
|
sl@0
|
121 |
// Cancel the device
|
sl@0
|
122 |
iTestDevice->CancelSubscriptionToReports();
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
void CUT_PBASE_T_USBDI_1235::DeviceInsertedL(TUint aDeviceHandle)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
LOG_FUNC
|
sl@0
|
128 |
|
sl@0
|
129 |
Cancel(); // Cancel the timer
|
sl@0
|
130 |
TInt err(KErrNone);
|
sl@0
|
131 |
iDeviceHandle = aDeviceHandle;
|
sl@0
|
132 |
iActorFDF->Monitor();
|
sl@0
|
133 |
|
sl@0
|
134 |
// Validate that device is as expected
|
sl@0
|
135 |
CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
|
sl@0
|
136 |
if (testDevice.SerialNumber().Compare(TestCaseId()) != 0)
|
sl@0
|
137 |
{
|
sl@0
|
138 |
// Incorrect device for this test case
|
sl@0
|
139 |
|
sl@0
|
140 |
RDebug::Printf(
|
sl@0
|
141 |
"<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
|
sl@0
|
142 |
KErrNotFound, &testDevice.SerialNumber(), &TestCaseId());
|
sl@0
|
143 |
|
sl@0
|
144 |
// Start the connection timeout again
|
sl@0
|
145 |
TimeoutIn(30);
|
sl@0
|
146 |
return;
|
sl@0
|
147 |
}
|
sl@0
|
148 |
// Check tree now
|
sl@0
|
149 |
CHECK(CheckTreeAfterDeviceInsertion(testDevice, _L("RDeviceA")) == KErrNone);
|
sl@0
|
150 |
|
sl@0
|
151 |
// Perform the correct test step
|
sl@0
|
152 |
switch (iCaseStep)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
case EInProcess:
|
sl@0
|
155 |
{
|
sl@0
|
156 |
TUint32 token1(0);
|
sl@0
|
157 |
TUint32 token2(0);
|
sl@0
|
158 |
|
sl@0
|
159 |
RDebug::Printf("Obtaining token for interface 0");
|
sl@0
|
160 |
err = testDevice.Device().GetTokenForInterface(0, token1);
|
sl@0
|
161 |
if (err != KErrNone)
|
sl@0
|
162 |
{
|
sl@0
|
163 |
RDebug::Printf(
|
sl@0
|
164 |
"<Error %d> Token for interface 0 could not be retrieved",
|
sl@0
|
165 |
err);
|
sl@0
|
166 |
return TestFailed(err);
|
sl@0
|
167 |
}
|
sl@0
|
168 |
RDebug::Printf("Token 1 (%d) retrieved", token1);
|
sl@0
|
169 |
RDebug::Printf("Opening interface 0");
|
sl@0
|
170 |
err = iUsbInterface0.Open(token1); // Alternate interface setting 0
|
sl@0
|
171 |
if (err != KErrNone)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
RDebug::Printf(
|
sl@0
|
174 |
"<Error %d> Interface 0 could not be opened", err);
|
sl@0
|
175 |
return TestFailed(err);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
RDebug::Printf("Interface 0 opened");
|
sl@0
|
178 |
|
sl@0
|
179 |
RDebug::Printf("Obtaining token for interface 1");
|
sl@0
|
180 |
err = testDevice.Device().GetTokenForInterface(1, token2);
|
sl@0
|
181 |
if (err != KErrNone)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
RDebug::Printf(
|
sl@0
|
184 |
"<Error %d> Token for interface 1 could not be retrieved",
|
sl@0
|
185 |
err);
|
sl@0
|
186 |
return TestFailed(err);
|
sl@0
|
187 |
}
|
sl@0
|
188 |
RDebug::Printf("Opening interface 1");
|
sl@0
|
189 |
err = iUsbInterface1.Open(token2); // Alternate interface setting 0
|
sl@0
|
190 |
if (err != KErrNone)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
RDebug::Printf(
|
sl@0
|
193 |
"<Error %d> Interface 1 could not be opened", err);
|
sl@0
|
194 |
return TestFailed(err);
|
sl@0
|
195 |
}
|
sl@0
|
196 |
RDebug::Printf("Interface 1 opened");
|
sl@0
|
197 |
|
sl@0
|
198 |
SuspendDeviceByInterfacesAndCancelWaitForResume();
|
sl@0
|
199 |
|
sl@0
|
200 |
iCaseStep = EValidCancelSuspendAfterInterfaceSuspend;
|
sl@0
|
201 |
|
sl@0
|
202 |
}
|
sl@0
|
203 |
break;
|
sl@0
|
204 |
|
sl@0
|
205 |
default:
|
sl@0
|
206 |
TestFailed(KErrCorrupt);
|
sl@0
|
207 |
break;
|
sl@0
|
208 |
}
|
sl@0
|
209 |
}
|
sl@0
|
210 |
|
sl@0
|
211 |
TInt CUT_PBASE_T_USBDI_1235::Interface0ResumedL(TAny* aPtr)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
LOG_CFUNC
|
sl@0
|
214 |
RDebug::Printf("Interface 0 resumed");
|
sl@0
|
215 |
CUT_PBASE_T_USBDI_1235* self =
|
sl@0
|
216 |
reinterpret_cast<CUT_PBASE_T_USBDI_1235*>(aPtr);
|
sl@0
|
217 |
TInt completionCode=self->iInterface0Watcher->CompletionCode();
|
sl@0
|
218 |
RDebug::Printf(
|
sl@0
|
219 |
"watcher 0 iStatus=%d",
|
sl@0
|
220 |
completionCode);
|
sl@0
|
221 |
self->iSuspendedI0 = EFalse;
|
sl@0
|
222 |
|
sl@0
|
223 |
switch (self->iCaseStep)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
|
sl@0
|
226 |
case EValidCancelSuspendAfterInterfaceSuspend:
|
sl@0
|
227 |
{
|
sl@0
|
228 |
if (completionCode == KErrCancel)
|
sl@0
|
229 |
{
|
sl@0
|
230 |
RDebug::Printf("CancelWaitForResume request: Success <>!",completionCode);
|
sl@0
|
231 |
// do not care the device's status.
|
sl@0
|
232 |
self->iCaseStep = EPassed;
|
sl@0
|
233 |
}
|
sl@0
|
234 |
else
|
sl@0
|
235 |
{
|
sl@0
|
236 |
RDebug::Printf(
|
sl@0
|
237 |
"CancelWaitForResume request: Failed, < err %d >",
|
sl@0
|
238 |
completionCode);
|
sl@0
|
239 |
self->iCaseStep = EFailed;
|
sl@0
|
240 |
|
sl@0
|
241 |
}
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
break;
|
sl@0
|
245 |
|
sl@0
|
246 |
default:
|
sl@0
|
247 |
break;
|
sl@0
|
248 |
};
|
sl@0
|
249 |
|
sl@0
|
250 |
return KErrNone;
|
sl@0
|
251 |
}
|
sl@0
|
252 |
|
sl@0
|
253 |
TInt CUT_PBASE_T_USBDI_1235::Interface1ResumedL(TAny* aPtr)
|
sl@0
|
254 |
{
|
sl@0
|
255 |
LOG_CFUNC
|
sl@0
|
256 |
RDebug::Printf("Interface 1 resumed");
|
sl@0
|
257 |
CUT_PBASE_T_USBDI_1235* self =
|
sl@0
|
258 |
reinterpret_cast<CUT_PBASE_T_USBDI_1235*>(aPtr);
|
sl@0
|
259 |
TInt completionCode = self->iInterface1Watcher->CompletionCode();
|
sl@0
|
260 |
RDebug::Printf("watcher 1 iStatus=%d",completionCode);
|
sl@0
|
261 |
self->iSuspendedI1 = EFalse;
|
sl@0
|
262 |
|
sl@0
|
263 |
if(self->iCaseStep == EPassed && completionCode == KErrNone )
|
sl@0
|
264 |
{
|
sl@0
|
265 |
RDebug::Printf("Device resumed,test passed!");
|
sl@0
|
266 |
self->SendEp0Request(); // stop client;
|
sl@0
|
267 |
}
|
sl@0
|
268 |
|
sl@0
|
269 |
return KErrNone;
|
sl@0
|
270 |
}
|
sl@0
|
271 |
|
sl@0
|
272 |
void CUT_PBASE_T_USBDI_1235::DeviceRemovedL(TUint aDeviceHandle)
|
sl@0
|
273 |
{
|
sl@0
|
274 |
LOG_FUNC
|
sl@0
|
275 |
|
sl@0
|
276 |
// The test device should not be removed until the test case has passed
|
sl@0
|
277 |
// so this test case has not completed, and state this event as an error
|
sl@0
|
278 |
|
sl@0
|
279 |
TestFailed(KErrDisconnected);
|
sl@0
|
280 |
}
|
sl@0
|
281 |
|
sl@0
|
282 |
void CUT_PBASE_T_USBDI_1235::BusErrorL(TInt aError)
|
sl@0
|
283 |
{
|
sl@0
|
284 |
LOG_FUNC
|
sl@0
|
285 |
|
sl@0
|
286 |
// This test case handles no failiures on the bus
|
sl@0
|
287 |
|
sl@0
|
288 |
TestFailed(aError);
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
|
sl@0
|
292 |
void CUT_PBASE_T_USBDI_1235::DeviceStateChangeL(
|
sl@0
|
293 |
RUsbDevice::TDeviceState aPreviousState,
|
sl@0
|
294 |
RUsbDevice::TDeviceState aNewState, TInt aCompletionCode)
|
sl@0
|
295 |
{
|
sl@0
|
296 |
LOG_FUNC
|
sl@0
|
297 |
Cancel();
|
sl@0
|
298 |
|
sl@0
|
299 |
// test RInterface , the RUsbDevice notification logic not used .
|
sl@0
|
300 |
RDebug::Printf(
|
sl@0
|
301 |
"-Device State change from %d to %d err=%d",
|
sl@0
|
302 |
aPreviousState, aNewState, aCompletionCode);
|
sl@0
|
303 |
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
void CUT_PBASE_T_USBDI_1235::Ep0TransferCompleteL(TInt aCompletionCode)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
LOG_FUNC
|
sl@0
|
309 |
RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",
|
sl@0
|
310 |
aCompletionCode);
|
sl@0
|
311 |
switch (iCaseStep)
|
sl@0
|
312 |
{
|
sl@0
|
313 |
|
sl@0
|
314 |
default:
|
sl@0
|
315 |
case EFailed:
|
sl@0
|
316 |
TestFailed(KErrCompletion);
|
sl@0
|
317 |
break;
|
sl@0
|
318 |
|
sl@0
|
319 |
case EPassed:
|
sl@0
|
320 |
TestPassed();
|
sl@0
|
321 |
break;
|
sl@0
|
322 |
}
|
sl@0
|
323 |
}
|
sl@0
|
324 |
|
sl@0
|
325 |
void CUT_PBASE_T_USBDI_1235::HostRunL()
|
sl@0
|
326 |
{
|
sl@0
|
327 |
LOG_FUNC
|
sl@0
|
328 |
|
sl@0
|
329 |
// Obtain the completion code
|
sl@0
|
330 |
TInt completionCode(iStatus.Int());
|
sl@0
|
331 |
|
sl@0
|
332 |
if (completionCode == KErrNone)
|
sl@0
|
333 |
{
|
sl@0
|
334 |
// Action timeout
|
sl@0
|
335 |
RDebug::Printf("<Error> Action timeout");
|
sl@0
|
336 |
TestFailed(KErrTimedOut);
|
sl@0
|
337 |
}
|
sl@0
|
338 |
else
|
sl@0
|
339 |
{
|
sl@0
|
340 |
RDebug::Printf("<Error %d> Timeout timer could not complete",
|
sl@0
|
341 |
completionCode);
|
sl@0
|
342 |
TestFailed(completionCode);
|
sl@0
|
343 |
}
|
sl@0
|
344 |
}
|
sl@0
|
345 |
|
sl@0
|
346 |
void CUT_PBASE_T_USBDI_1235::DeviceRunL()
|
sl@0
|
347 |
{
|
sl@0
|
348 |
LOG_FUNC
|
sl@0
|
349 |
|
sl@0
|
350 |
// Disconnect the device
|
sl@0
|
351 |
|
sl@0
|
352 |
iTestDevice->SoftwareDisconnect();
|
sl@0
|
353 |
|
sl@0
|
354 |
// Complete the test case request
|
sl@0
|
355 |
|
sl@0
|
356 |
TestPolicy().SignalTestComplete(iStatus.Int());
|
sl@0
|
357 |
}
|
sl@0
|
358 |
|
sl@0
|
359 |
void CUT_PBASE_T_USBDI_1235::SuspendDeviceByInterfacesAndCancelWaitForResume()
|
sl@0
|
360 |
{
|
sl@0
|
361 |
// Suspend interface 0
|
sl@0
|
362 |
RDebug::Printf("Suspending interface 0");
|
sl@0
|
363 |
iInterface0Watcher->SuspendAndWatch();
|
sl@0
|
364 |
iSuspendedI0 = ETrue;
|
sl@0
|
365 |
|
sl@0
|
366 |
// Suspend interface 1
|
sl@0
|
367 |
RDebug::Printf("Suspending interface 1");
|
sl@0
|
368 |
iInterface1Watcher->SuspendAndWatch();
|
sl@0
|
369 |
iSuspendedI1 = ETrue;
|
sl@0
|
370 |
|
sl@0
|
371 |
RDebug::Printf("CancelPermitSuspend interface 1");
|
sl@0
|
372 |
// try to resume device,then host can notify peripheral test passed.
|
sl@0
|
373 |
iUsbInterface1.CancelPermitSuspend();
|
sl@0
|
374 |
|
sl@0
|
375 |
// Only test the CancelWaitForResume() operation
|
sl@0
|
376 |
// If we let the devic to suspend ,the periperal site could not receive the test control transfer which test finish result.
|
sl@0
|
377 |
// select interface0 to test the function CancelWaitForResume
|
sl@0
|
378 |
RDebug::Printf("CacelWaitForResume interface 0");
|
sl@0
|
379 |
iUsbInterface0.CancelWaitForResume();
|
sl@0
|
380 |
|
sl@0
|
381 |
}
|
sl@0
|
382 |
|
sl@0
|
383 |
void CUT_PBASE_T_USBDI_1235::SendEp0Request()
|
sl@0
|
384 |
{
|
sl@0
|
385 |
TTestCasePassed request;
|
sl@0
|
386 |
iControlEp0->SendRequest(request, this);
|
sl@0
|
387 |
}
|
sl@0
|
388 |
|
sl@0
|
389 |
}//end namespace
|
sl@0
|
390 |
|
sl@0
|
391 |
|