253
|
1 |
// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// @file PBASE-T_USBDI-0472.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "PBASE-T_USBDI-0472.h"
|
|
20 |
#include <e32test.h>
|
|
21 |
#include <d32usbc.h>
|
|
22 |
#include <e32debug.h>
|
|
23 |
#include "UsbDescriptorOffsets.h"
|
|
24 |
#include "TestPolicy.h"
|
253
|
25 |
#include "OstTraceDefinitions.h"
|
|
26 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
27 |
#include "PBASE-T_USBDI-0472Traces.h"
|
|
28 |
#endif
|
0
|
29 |
|
|
30 |
namespace NUnitTesting_USBDI
|
|
31 |
{
|
|
32 |
|
|
33 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0472");
|
|
34 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0472,TBool> CUT_PBASE_T_USBDI_0472::iFunctor(KTestCaseId);
|
|
35 |
|
|
36 |
CUT_PBASE_T_USBDI_0472* CUT_PBASE_T_USBDI_0472::NewL(TBool aHostRole)
|
|
37 |
{
|
253
|
38 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0472_NEWL_ENTRY, aHostRole );
|
0
|
39 |
CUT_PBASE_T_USBDI_0472* self = new (ELeave) CUT_PBASE_T_USBDI_0472(aHostRole);
|
|
40 |
CleanupStack::PushL(self);
|
|
41 |
self->ConstructL();
|
|
42 |
CleanupStack::Pop(self);
|
253
|
43 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_NEWL_EXIT, ( TUint )( self ) );
|
0
|
44 |
return self;
|
|
45 |
}
|
|
46 |
|
|
47 |
|
|
48 |
CUT_PBASE_T_USBDI_0472::CUT_PBASE_T_USBDI_0472(TBool aHostRole)
|
|
49 |
: CBaseTestCase(KTestCaseId,aHostRole)
|
|
50 |
{
|
253
|
51 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0472_CUT_PBASE_T_USBDI_0472_ENTRY, this );
|
|
52 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_CUT_PBASE_T_USBDI_0472_EXIT, this );
|
0
|
53 |
}
|
|
54 |
|
|
55 |
|
|
56 |
void CUT_PBASE_T_USBDI_0472::ConstructL()
|
|
57 |
{
|
253
|
58 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0472_CONSTRUCTL_ENTRY, this );
|
0
|
59 |
iTestDevice = new RUsbDeviceVendor(this);
|
|
60 |
BaseConstructL();
|
253
|
61 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_CONSTRUCTL_EXIT, this );
|
0
|
62 |
}
|
|
63 |
|
|
64 |
|
|
65 |
CUT_PBASE_T_USBDI_0472::~CUT_PBASE_T_USBDI_0472()
|
|
66 |
{
|
253
|
67 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0472_CUT_PBASE_T_USBDI_0472_ENTRY_DUP01, this );
|
0
|
68 |
Cancel();
|
|
69 |
|
|
70 |
delete iClientAction;
|
|
71 |
delete iActorFDF;
|
|
72 |
if(!IsHost() && iTestDevice)
|
|
73 |
{
|
|
74 |
iTestDevice->Close();
|
|
75 |
}
|
|
76 |
delete iTestDevice;
|
253
|
77 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_CUT_PBASE_T_USBDI_0472_EXIT_DUP01, this );
|
0
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
void CUT_PBASE_T_USBDI_0472::ExecuteHostTestCaseL()
|
|
82 |
{
|
253
|
83 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0472_EXECUTEHOSTTESTCASEL_ENTRY, this );
|
0
|
84 |
iActorFDF = CActorFDF::NewL(*this);
|
|
85 |
iClientAction = new (ELeave) CEp0Transfer(iInterface0);
|
|
86 |
iCaseStep = EConnectDevice;
|
|
87 |
iActorFDF->Monitor();
|
|
88 |
TimeoutIn(30);
|
253
|
89 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_EXECUTEHOSTTESTCASEL_EXIT, this );
|
0
|
90 |
}
|
|
91 |
|
|
92 |
void CUT_PBASE_T_USBDI_0472::ExecuteDeviceTestCaseL()
|
|
93 |
{
|
253
|
94 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0472_EXECUTEDEVICETESTCASEL_ENTRY, this );
|
0
|
95 |
|
|
96 |
iTestDevice->OpenL(TestCaseId());
|
|
97 |
iTestDevice->SubscribeToReports(iStatus);
|
|
98 |
SetActive();
|
|
99 |
iTestDevice->SoftwareConnect();
|
253
|
100 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_EXECUTEDEVICETESTCASEL_EXIT, this );
|
0
|
101 |
}
|
|
102 |
|
|
103 |
void CUT_PBASE_T_USBDI_0472::HostDoCancel()
|
|
104 |
{
|
253
|
105 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0472_HOSTDOCANCEL_ENTRY, this );
|
0
|
106 |
|
|
107 |
// Cancel the test step action timeout timer
|
|
108 |
|
|
109 |
CancelTimeout();
|
253
|
110 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_HOSTDOCANCEL_EXIT, this );
|
0
|
111 |
}
|
|
112 |
|
|
113 |
|
|
114 |
void CUT_PBASE_T_USBDI_0472::DeviceDoCancel()
|
|
115 |
{
|
253
|
116 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0472_DEVICEDOCANCEL_ENTRY, this );
|
0
|
117 |
|
|
118 |
// Cancel the test device
|
|
119 |
|
|
120 |
iTestDevice->CancelSubscriptionToReports();
|
253
|
121 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_DEVICEDOCANCEL_EXIT, this );
|
0
|
122 |
}
|
|
123 |
|
|
124 |
|
|
125 |
void CUT_PBASE_T_USBDI_0472::DeviceInsertedL(TUint aDeviceHandle)
|
|
126 |
{
|
253
|
127 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_ENTRY, this );
|
0
|
128 |
|
|
129 |
Cancel();
|
|
130 |
TInt err(KErrNone);
|
|
131 |
|
|
132 |
// Validate that device is as expected
|
|
133 |
|
|
134 |
CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
|
|
135 |
if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
|
|
136 |
{
|
|
137 |
// Incorrect device for this test case
|
|
138 |
|
253
|
139 |
OstTraceExt3(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL, "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
|
|
140 |
KErrNotFound,testDevice.SerialNumber(),TestCaseId());
|
0
|
141 |
|
|
142 |
// Start the connection timeout again
|
|
143 |
|
|
144 |
TimeoutIn(30);
|
253
|
145 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_EXIT, this );
|
0
|
146 |
return;
|
|
147 |
}
|
|
148 |
|
|
149 |
// Perform the correct test step
|
|
150 |
|
|
151 |
switch(iCaseStep)
|
|
152 |
{
|
|
153 |
case EConnectDevice:
|
|
154 |
{
|
|
155 |
// Validate vendor identity
|
253
|
156 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP01, "Vendor identity: 0x%04x",testDevice.VendorId());
|
0
|
157 |
if(testDevice.VendorId() != 0x0E22)
|
|
158 |
{
|
253
|
159 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP02, "<Error> Vendor identity is not 0x0E22");
|
0
|
160 |
return TestFailed(KErrCorrupt);
|
|
161 |
}
|
|
162 |
|
|
163 |
// Validate product information
|
253
|
164 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP03, "Usb device supported specification: 0x%04x",testDevice.DeviceSpec());
|
0
|
165 |
if(testDevice.DeviceSpec() != 0x0200)
|
|
166 |
{
|
253
|
167 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP04, "<Error> Usb device supported specification is not 2.0");
|
0
|
168 |
return TestFailed(KErrCorrupt);
|
|
169 |
}
|
253
|
170 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP05, "Usb product identity: 0x%04x",testDevice.ProductId());
|
0
|
171 |
if(testDevice.ProductId() != 0x0040)
|
|
172 |
{
|
253
|
173 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP06, "<Error> Usb product idenity is not 0x0040");
|
0
|
174 |
return TestFailed(KErrCorrupt);
|
|
175 |
}
|
|
176 |
|
253
|
177 |
OstTraceExt1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP07, "testDevice.ConfigurationString() = %S",testDevice.ConfigurationString());
|
0
|
178 |
gtest(KErrNone == testDevice.ConfigurationString().Compare(KConfigurationString()));
|
|
179 |
|
253
|
180 |
OstTraceExt1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP08, "testDevice.Manufacturer() = %S",testDevice.Manufacturer());
|
0
|
181 |
gtest(KErrNone == testDevice.Manufacturer().Compare(KManufacturer()));
|
|
182 |
|
253
|
183 |
OstTraceExt1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP09, "testDevice.SerialNumber = %s",testDevice.SerialNumber());
|
0
|
184 |
gtest(KErrNone == testDevice.SerialNumber().Compare(KTestCaseId()));
|
|
185 |
|
253
|
186 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP10, "Waiting for device removal");
|
0
|
187 |
iCaseStep = ERemoveDevice;
|
|
188 |
|
|
189 |
TUint32 token;
|
|
190 |
err = testDevice.Device().GetTokenForInterface(0,token);
|
|
191 |
if(err != KErrNone)
|
|
192 |
{
|
253
|
193 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP11, "<Error %d> Unable to get token for interface 0",err);
|
0
|
194 |
return TestFailed(err);
|
|
195 |
}
|
|
196 |
err = iInterface0.Open(token);
|
|
197 |
if(err != KErrNone)
|
|
198 |
{
|
253
|
199 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP12, "<Error %d> Unable to open interface 0",err);
|
0
|
200 |
return TestFailed(err);
|
|
201 |
}
|
|
202 |
|
|
203 |
// Send request to client to reconnect in 3 seconds
|
|
204 |
|
|
205 |
TReconnectRequest request(3);
|
|
206 |
iClientAction->SendRequest(request,this);
|
|
207 |
|
|
208 |
// Monitor for the reconnection from the client
|
|
209 |
|
|
210 |
iActorFDF->Monitor();
|
|
211 |
TimeoutIn(30);
|
|
212 |
}
|
|
213 |
break;
|
|
214 |
|
|
215 |
case EConnectCancelled:
|
253
|
216 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP13, "<Error> Bus event cancellation not successful");
|
0
|
217 |
TestFailed(KErrCorrupt);
|
|
218 |
break;
|
|
219 |
|
|
220 |
case EPassed: // Test case has been successfully concluded
|
|
221 |
{
|
|
222 |
TUint32 token;
|
|
223 |
err = testDevice.Device().GetTokenForInterface(0,token);
|
|
224 |
if(err != KErrNone)
|
|
225 |
{
|
253
|
226 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP14, "<Error %d> Unable to get token for interface 0",err);
|
0
|
227 |
return TestFailed(err);
|
|
228 |
}
|
|
229 |
err = iInterface0.Open(token);
|
|
230 |
if(err != KErrNone)
|
|
231 |
{
|
253
|
232 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP15, "<Error %d> Unable to open interface 0",err);
|
0
|
233 |
return TestFailed(err);
|
|
234 |
}
|
|
235 |
|
|
236 |
// Send test case passed request to client
|
|
237 |
TTestCasePassed request;
|
|
238 |
iClientAction->SendRequest(request,this);
|
|
239 |
}
|
|
240 |
break;
|
|
241 |
|
|
242 |
default:
|
253
|
243 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_DUP16, "<Error> Test case actions out of sync");
|
0
|
244 |
TestFailed(KErrCorrupt);
|
|
245 |
break;
|
|
246 |
}
|
253
|
247 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_DEVICEINSERTEDL_EXIT_DUP01, this );
|
0
|
248 |
}
|
|
249 |
|
|
250 |
|
|
251 |
void CUT_PBASE_T_USBDI_0472::Ep0TransferCompleteL(TInt aCompletionCode)
|
|
252 |
{
|
253
|
253 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0472_EP0TRANSFERCOMPLETEL_ENTRY, this );
|
0
|
254 |
|
|
255 |
switch(iCaseStep)
|
|
256 |
{
|
|
257 |
case EPassed:
|
|
258 |
{
|
|
259 |
TestPassed();
|
|
260 |
}
|
|
261 |
break;
|
|
262 |
|
|
263 |
case EFailed:
|
|
264 |
{
|
|
265 |
TestFailed(KErrCompletion);
|
|
266 |
}
|
|
267 |
break;
|
|
268 |
|
|
269 |
case ERemoveDevice:
|
|
270 |
{
|
|
271 |
// Doing nothing, client should be re-connecting
|
|
272 |
}
|
|
273 |
break;
|
|
274 |
|
|
275 |
default:
|
253
|
276 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_EP0TRANSFERCOMPLETEL, "<Error %d> Unknown test step",KErrCorrupt);
|
0
|
277 |
TestFailed(KErrCorrupt);
|
|
278 |
break;
|
|
279 |
}
|
253
|
280 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_EP0TRANSFERCOMPLETEL_EXIT, this );
|
0
|
281 |
}
|
|
282 |
|
|
283 |
|
|
284 |
void CUT_PBASE_T_USBDI_0472::DeviceRemovedL(TUint aDeviceHandle)
|
|
285 |
{
|
253
|
286 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0472_DEVICEREMOVEDL_ENTRY, this );
|
0
|
287 |
|
|
288 |
Cancel();
|
|
289 |
|
|
290 |
switch(iCaseStep)
|
|
291 |
{
|
|
292 |
case ERemoveDevice:
|
|
293 |
{
|
|
294 |
iCaseStep = EConnectCancelled;
|
|
295 |
|
|
296 |
// start timer now
|
|
297 |
TimeoutIn(5);
|
|
298 |
}
|
|
299 |
break;
|
|
300 |
|
|
301 |
default:
|
253
|
302 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_DEVICEREMOVEDL, "<Error> Test case actions out of sync");
|
0
|
303 |
TestFailed(KErrCorrupt);
|
|
304 |
break;
|
|
305 |
}
|
253
|
306 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_DEVICEREMOVEDL_EXIT, this );
|
0
|
307 |
}
|
|
308 |
|
|
309 |
void CUT_PBASE_T_USBDI_0472::BusErrorL(TInt aError)
|
|
310 |
{
|
253
|
311 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0472_BUSERRORL_ENTRY, this );
|
0
|
312 |
// This test case handles no failiures on the bus
|
|
313 |
|
|
314 |
TestFailed(aError);
|
253
|
315 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_BUSERRORL_EXIT, this );
|
0
|
316 |
}
|
|
317 |
|
|
318 |
void CUT_PBASE_T_USBDI_0472::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
|
|
319 |
RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
|
|
320 |
{
|
253
|
321 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0472_DEVICESTATECHANGEL_ENTRY, this );
|
|
322 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_DEVICESTATECHANGEL_EXIT, this );
|
0
|
323 |
}
|
|
324 |
|
|
325 |
void CUT_PBASE_T_USBDI_0472::HostRunL()
|
|
326 |
{
|
253
|
327 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0472_HOSTRUNL_ENTRY, this );
|
0
|
328 |
|
|
329 |
// Obtain the completion code
|
|
330 |
TInt completionCode(iStatus.Int());
|
|
331 |
|
|
332 |
if(completionCode == KErrNone)
|
|
333 |
{
|
|
334 |
if(iCaseStep == EConnectCancelled)
|
|
335 |
{
|
|
336 |
// not a time-out
|
253
|
337 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_HOSTRUNL, "Timer elapsed, reactivating notifications now");
|
0
|
338 |
iCaseStep = EPassed;
|
|
339 |
iActorFDF->Monitor();
|
|
340 |
}
|
|
341 |
else
|
|
342 |
{
|
|
343 |
// Action timeout
|
253
|
344 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_HOSTRUNL_DUP01, "<Error> Action timeout");
|
0
|
345 |
TestFailed(KErrTimedOut);
|
|
346 |
}
|
|
347 |
}
|
|
348 |
else
|
|
349 |
{
|
253
|
350 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0472_HOSTRUNL_DUP02, "<Error %d> Timeout timer could not complete",completionCode);
|
0
|
351 |
TestFailed(completionCode);
|
|
352 |
}
|
253
|
353 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_HOSTRUNL_EXIT, this );
|
0
|
354 |
}
|
|
355 |
|
|
356 |
|
|
357 |
void CUT_PBASE_T_USBDI_0472::DeviceRunL()
|
|
358 |
{
|
253
|
359 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0472_DEVICERUNL_ENTRY, this );
|
0
|
360 |
|
|
361 |
// Disconnect the device
|
|
362 |
|
|
363 |
iTestDevice->SoftwareDisconnect();
|
|
364 |
|
|
365 |
// Complete the test case request
|
|
366 |
|
|
367 |
TestPolicy().SignalTestComplete(iStatus.Int());
|
253
|
368 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0472_DEVICERUNL_EXIT, this );
|
0
|
369 |
}
|
|
370 |
|
|
371 |
|
|
372 |
}
|
|
373 |
|