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-0480.cpp
|
sl@0
|
15 |
// @internalComponent
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "PBASE-T_USBDI-0480.h"
|
sl@0
|
20 |
#include "testpolicy.h"
|
sl@0
|
21 |
#include "modelleddevices.h"
|
sl@0
|
22 |
|
sl@0
|
23 |
|
sl@0
|
24 |
namespace NUnitTesting_USBDI
|
sl@0
|
25 |
{
|
sl@0
|
26 |
|
sl@0
|
27 |
_LIT8(KDataPayload,"DEADBEEF");
|
sl@0
|
28 |
|
sl@0
|
29 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0480");
|
sl@0
|
30 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0480,TBool> CUT_PBASE_T_USBDI_0480::iFunctor(KTestCaseId);
|
sl@0
|
31 |
|
sl@0
|
32 |
CUT_PBASE_T_USBDI_0480* CUT_PBASE_T_USBDI_0480::NewL(TBool aHostRole)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
CUT_PBASE_T_USBDI_0480* self = new (ELeave) CUT_PBASE_T_USBDI_0480(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_0480::CUT_PBASE_T_USBDI_0480(TBool aHostRole)
|
sl@0
|
43 |
: CBaseTestCase(KTestCaseId,aHostRole),
|
sl@0
|
44 |
iPtrTemp(NULL,0)
|
sl@0
|
45 |
{
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
|
sl@0
|
49 |
void CUT_PBASE_T_USBDI_0480::ConstructL()
|
sl@0
|
50 |
{
|
sl@0
|
51 |
iTestDevice = new RUsbDeviceA(this);
|
sl@0
|
52 |
BaseConstructL();
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
|
sl@0
|
56 |
CUT_PBASE_T_USBDI_0480::~CUT_PBASE_T_USBDI_0480()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
LOG_FUNC
|
sl@0
|
59 |
|
sl@0
|
60 |
Cancel();
|
sl@0
|
61 |
|
sl@0
|
62 |
// Close pipe before interface
|
sl@0
|
63 |
iUsbInterface1.Close();
|
sl@0
|
64 |
iUsbInterface0.Close();
|
sl@0
|
65 |
|
sl@0
|
66 |
delete iTemp;
|
sl@0
|
67 |
delete iControlEp0;
|
sl@0
|
68 |
delete iActorFDF;
|
sl@0
|
69 |
if(!IsHost() && iTestDevice)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
iTestDevice->Close();
|
sl@0
|
72 |
}
|
sl@0
|
73 |
delete iTestDevice;
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
void CUT_PBASE_T_USBDI_0480::ExecuteHostTestCaseL()
|
sl@0
|
77 |
{
|
sl@0
|
78 |
LOG_FUNC
|
sl@0
|
79 |
|
sl@0
|
80 |
iActorFDF = CActorFDF::NewL(*this);
|
sl@0
|
81 |
iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
|
sl@0
|
82 |
iActorFDF->Monitor();
|
sl@0
|
83 |
|
sl@0
|
84 |
TimeoutIn(30);
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
void CUT_PBASE_T_USBDI_0480::HostDoCancel()
|
sl@0
|
88 |
{
|
sl@0
|
89 |
LOG_FUNC
|
sl@0
|
90 |
|
sl@0
|
91 |
CancelTimeout();
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
|
sl@0
|
95 |
void CUT_PBASE_T_USBDI_0480::ExecuteDeviceTestCaseL()
|
sl@0
|
96 |
{
|
sl@0
|
97 |
LOG_FUNC
|
sl@0
|
98 |
|
sl@0
|
99 |
iTestDevice->OpenL(TestCaseId());
|
sl@0
|
100 |
iTestDevice->SubscribeToReports(iStatus);
|
sl@0
|
101 |
SetActive();
|
sl@0
|
102 |
iTestDevice->SoftwareConnect();
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
void CUT_PBASE_T_USBDI_0480::DeviceDoCancel()
|
sl@0
|
106 |
{
|
sl@0
|
107 |
LOG_FUNC
|
sl@0
|
108 |
|
sl@0
|
109 |
// Cancel the device
|
sl@0
|
110 |
iTestDevice->CancelSubscriptionToReports();
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
|
sl@0
|
114 |
void CUT_PBASE_T_USBDI_0480::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
|
sl@0
|
115 |
RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
LOG_FUNC
|
sl@0
|
118 |
|
sl@0
|
119 |
Cancel();
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
|
sl@0
|
123 |
void CUT_PBASE_T_USBDI_0480::DeviceInsertedL(TUint aDeviceHandle)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
LOG_FUNC
|
sl@0
|
126 |
|
sl@0
|
127 |
Cancel();
|
sl@0
|
128 |
TInt err(KErrNone);
|
sl@0
|
129 |
|
sl@0
|
130 |
// Validate that device is as expected
|
sl@0
|
131 |
CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
|
sl@0
|
132 |
if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
// Incorrect device for this test case
|
sl@0
|
135 |
|
sl@0
|
136 |
RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
|
sl@0
|
137 |
KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
|
sl@0
|
138 |
|
sl@0
|
139 |
// Start the connection timeout again
|
sl@0
|
140 |
TimeoutIn(30);
|
sl@0
|
141 |
return;
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
TUint32 token0,token1;
|
sl@0
|
145 |
|
sl@0
|
146 |
err = testDevice.Device().GetTokenForInterface(0,token0);
|
sl@0
|
147 |
if(err != KErrNone)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
|
sl@0
|
150 |
return TestFailed(err);
|
sl@0
|
151 |
}
|
sl@0
|
152 |
err = iUsbInterface0.Open(token0); // Default interface setting 0
|
sl@0
|
153 |
if(err != KErrNone)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
RDebug::Printf("<Error %d> Unable to open interface 0 using token %d",err,token0);
|
sl@0
|
156 |
return TestFailed(err);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
err = testDevice.Device().GetTokenForInterface(1,token1);
|
sl@0
|
160 |
if(err != KErrNone)
|
sl@0
|
161 |
{
|
sl@0
|
162 |
TBuf<64> msg;
|
sl@0
|
163 |
msg.Format(_L("<Error %d> Token for interface 1 could not be retrieved"),err);
|
sl@0
|
164 |
RDebug::Print(msg);
|
sl@0
|
165 |
iCaseStep = EFailed;
|
sl@0
|
166 |
TTestCaseFailed request(err,msg);
|
sl@0
|
167 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
168 |
return;
|
sl@0
|
169 |
}
|
sl@0
|
170 |
err = iUsbInterface1.Open(token1);
|
sl@0
|
171 |
if(err != KErrNone)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
TBuf<256> msg;
|
sl@0
|
174 |
msg.Format(_L("<Error %d> Unable to open interface 1 using token %d"),err,token1);
|
sl@0
|
175 |
RDebug::Print(msg);
|
sl@0
|
176 |
iCaseStep = EFailed;
|
sl@0
|
177 |
TTestCaseFailed request(err,msg);
|
sl@0
|
178 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
179 |
return;
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
// Get the endpoint descriptor
|
sl@0
|
183 |
TUsbEndpointDescriptor endpointDescriptor;
|
sl@0
|
184 |
|
sl@0
|
185 |
err = iUsbInterface1.GetEndpointDescriptor(0,1,endpointDescriptor);
|
sl@0
|
186 |
if(err != KErrNone)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
TBuf<256> msg;
|
sl@0
|
189 |
msg.Format(_L("<Error %d> Descriptor for endpoint 0 cannot be obtained"),err);
|
sl@0
|
190 |
RDebug::Print(msg);
|
sl@0
|
191 |
iCaseStep = EFailed;
|
sl@0
|
192 |
TTestCaseFailed request(err,msg);
|
sl@0
|
193 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
194 |
return;
|
sl@0
|
195 |
}
|
sl@0
|
196 |
TUint16 maxPacketSize(endpointDescriptor.MaxPacketSize());
|
sl@0
|
197 |
|
sl@0
|
198 |
RDebug::Printf("Maximum packet size for endpoint 1 on interface 1 setting 0 is: %d",maxPacketSize);
|
sl@0
|
199 |
|
sl@0
|
200 |
// Perform a device directed control transfer
|
sl@0
|
201 |
User::After(1000000);
|
sl@0
|
202 |
iCaseStep = EEmptyDeviceXfer;
|
sl@0
|
203 |
TEmptyDeviceRequest request;
|
sl@0
|
204 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
|
sl@0
|
208 |
void CUT_PBASE_T_USBDI_0480::Ep0TransferCompleteL(TInt aCompletionCode)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
LOG_FUNC
|
sl@0
|
211 |
|
sl@0
|
212 |
RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
sl@0
|
213 |
|
sl@0
|
214 |
if(aCompletionCode != KErrNone)
|
sl@0
|
215 |
{
|
sl@0
|
216 |
if(iCaseStep == EFailed)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
}
|
sl@0
|
219 |
else
|
sl@0
|
220 |
{
|
sl@0
|
221 |
TBuf<256> msg;
|
sl@0
|
222 |
msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
|
sl@0
|
223 |
RDebug::Print(msg);
|
sl@0
|
224 |
iCaseStep = EFailed;
|
sl@0
|
225 |
TTestCaseFailed request(aCompletionCode,msg);
|
sl@0
|
226 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
227 |
return;
|
sl@0
|
228 |
}
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
switch(iCaseStep)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
// Test case passed
|
sl@0
|
234 |
case EPassed:
|
sl@0
|
235 |
TestPassed();
|
sl@0
|
236 |
break;
|
sl@0
|
237 |
|
sl@0
|
238 |
// Test case failed
|
sl@0
|
239 |
case EFailed:
|
sl@0
|
240 |
TestFailed(KErrCompletion);
|
sl@0
|
241 |
break;
|
sl@0
|
242 |
|
sl@0
|
243 |
// Send an empty interface directed request
|
sl@0
|
244 |
case EEmptyDeviceXfer:
|
sl@0
|
245 |
{
|
sl@0
|
246 |
iCaseStep = EEmptyInterfaceXfer;
|
sl@0
|
247 |
TEmptyInterfaceRequest request(1); // Direct at interface 1
|
sl@0
|
248 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
249 |
}
|
sl@0
|
250 |
break;
|
sl@0
|
251 |
|
sl@0
|
252 |
// Send a test payload request to device directed
|
sl@0
|
253 |
case EEmptyInterfaceXfer:
|
sl@0
|
254 |
{
|
sl@0
|
255 |
iCaseStep = EDataPutDeviceXfer;
|
sl@0
|
256 |
TDevicePutPayloadRequest request(KDataPayload);
|
sl@0
|
257 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
258 |
}
|
sl@0
|
259 |
break;
|
sl@0
|
260 |
|
sl@0
|
261 |
// Send a test payload request to interface directed
|
sl@0
|
262 |
case EDataPutDeviceXfer:
|
sl@0
|
263 |
{
|
sl@0
|
264 |
iCaseStep = EDataPutInterfaceXfer;
|
sl@0
|
265 |
TInterfacePutPayloadRequest request(1,KDataPayload); // Direct at interface 1
|
sl@0
|
266 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
267 |
}
|
sl@0
|
268 |
break;
|
sl@0
|
269 |
|
sl@0
|
270 |
// Test case passed
|
sl@0
|
271 |
case EDataPutInterfaceXfer:
|
sl@0
|
272 |
{
|
sl@0
|
273 |
iCaseStep = EPassed;
|
sl@0
|
274 |
User::After(1000000);
|
sl@0
|
275 |
TTestCasePassed request;
|
sl@0
|
276 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
277 |
}
|
sl@0
|
278 |
break;
|
sl@0
|
279 |
|
sl@0
|
280 |
default:
|
sl@0
|
281 |
RDebug::Printf("<Error> Unknown test step");
|
sl@0
|
282 |
TestFailed(KErrUnknown);
|
sl@0
|
283 |
break;
|
sl@0
|
284 |
}
|
sl@0
|
285 |
}
|
sl@0
|
286 |
|
sl@0
|
287 |
|
sl@0
|
288 |
void CUT_PBASE_T_USBDI_0480::DeviceRemovedL(TUint aDeviceHandle)
|
sl@0
|
289 |
{
|
sl@0
|
290 |
LOG_FUNC
|
sl@0
|
291 |
|
sl@0
|
292 |
// The test device should not be removed until the test case has passed
|
sl@0
|
293 |
// so this test case has not completed, and state this event as an error
|
sl@0
|
294 |
TestFailed(KErrDisconnected);
|
sl@0
|
295 |
}
|
sl@0
|
296 |
|
sl@0
|
297 |
|
sl@0
|
298 |
void CUT_PBASE_T_USBDI_0480::BusErrorL(TInt aError)
|
sl@0
|
299 |
{
|
sl@0
|
300 |
LOG_FUNC
|
sl@0
|
301 |
|
sl@0
|
302 |
// This test case handles no failiures on the bus
|
sl@0
|
303 |
TestFailed(KErrGeneral);
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
void CUT_PBASE_T_USBDI_0480::HostRunL()
|
sl@0
|
307 |
{
|
sl@0
|
308 |
LOG_FUNC
|
sl@0
|
309 |
|
sl@0
|
310 |
// Obtain the completion code
|
sl@0
|
311 |
TInt completionCode(iStatus.Int());
|
sl@0
|
312 |
|
sl@0
|
313 |
if(completionCode == KErrNone)
|
sl@0
|
314 |
{
|
sl@0
|
315 |
// Action timeout
|
sl@0
|
316 |
RDebug::Printf("<Error> Action timeout");
|
sl@0
|
317 |
TestFailed(KErrTimedOut);
|
sl@0
|
318 |
}
|
sl@0
|
319 |
else
|
sl@0
|
320 |
{
|
sl@0
|
321 |
RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
|
sl@0
|
322 |
TestFailed(completionCode);
|
sl@0
|
323 |
}
|
sl@0
|
324 |
}
|
sl@0
|
325 |
|
sl@0
|
326 |
void CUT_PBASE_T_USBDI_0480::DeviceRunL()
|
sl@0
|
327 |
{
|
sl@0
|
328 |
LOG_FUNC
|
sl@0
|
329 |
|
sl@0
|
330 |
// Disconnect the device
|
sl@0
|
331 |
iTestDevice->SoftwareDisconnect();
|
sl@0
|
332 |
|
sl@0
|
333 |
// Complete the test case request
|
sl@0
|
334 |
TestPolicy().SignalTestComplete(iStatus.Int());
|
sl@0
|
335 |
}
|
sl@0
|
336 |
|
sl@0
|
337 |
|
sl@0
|
338 |
}
|