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