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-0485.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "PBASE-T_USBDI-0485.h"
|
|
20 |
#include "testpolicy.h"
|
|
21 |
#include "testdebug.h"
|
|
22 |
#include "modelleddevices.h"
|
253
|
23 |
#include "OstTraceDefinitions.h"
|
|
24 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
25 |
#include "PBASE-T_USBDI-0485Traces.h"
|
|
26 |
#endif
|
0
|
27 |
|
|
28 |
namespace NUnitTesting_USBDI
|
|
29 |
{
|
|
30 |
|
|
31 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0485");
|
|
32 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0485,TBool> CUT_PBASE_T_USBDI_0485::iFunctor(KTestCaseId);
|
|
33 |
|
|
34 |
CUT_PBASE_T_USBDI_0485* CUT_PBASE_T_USBDI_0485::NewL(TBool aHostRole)
|
|
35 |
{
|
253
|
36 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0485_NEWL_ENTRY, aHostRole );
|
0
|
37 |
CUT_PBASE_T_USBDI_0485* self = new (ELeave) CUT_PBASE_T_USBDI_0485(aHostRole);
|
|
38 |
CleanupStack::PushL(self);
|
|
39 |
self->ConstructL();
|
|
40 |
CleanupStack::Pop(self);
|
253
|
41 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_NEWL_EXIT, ( TUint )( self ) );
|
0
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
|
|
46 |
CUT_PBASE_T_USBDI_0485::CUT_PBASE_T_USBDI_0485(TBool aHostRole)
|
|
47 |
: CBaseTestCase(KTestCaseId,aHostRole),
|
|
48 |
iCaseStep(EInProgress)
|
|
49 |
{
|
253
|
50 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0485_CUT_PBASE_T_USBDI_0485_ENTRY, this );
|
|
51 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_CUT_PBASE_T_USBDI_0485_EXIT, this );
|
0
|
52 |
}
|
|
53 |
|
|
54 |
|
|
55 |
void CUT_PBASE_T_USBDI_0485::ConstructL()
|
|
56 |
{
|
253
|
57 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0485_CONSTRUCTL_ENTRY, this );
|
0
|
58 |
iTestDevice = new RUsbDeviceVendor(this);
|
|
59 |
BaseConstructL();
|
253
|
60 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_CONSTRUCTL_EXIT, this );
|
0
|
61 |
}
|
|
62 |
|
|
63 |
|
|
64 |
CUT_PBASE_T_USBDI_0485::~CUT_PBASE_T_USBDI_0485()
|
|
65 |
{
|
253
|
66 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0485_CUT_PBASE_T_USBDI_0485_ENTRY_DUP01, this );
|
0
|
67 |
|
|
68 |
Cancel();
|
|
69 |
|
|
70 |
// Close the interface
|
|
71 |
iUsbInterface0.Close();
|
|
72 |
|
|
73 |
delete iControlEp0;
|
|
74 |
delete iActorFDF;
|
|
75 |
if(!IsHost() && iTestDevice)
|
|
76 |
{
|
|
77 |
iTestDevice->Close();
|
|
78 |
}
|
|
79 |
delete iTestDevice;
|
253
|
80 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_CUT_PBASE_T_USBDI_0485_EXIT_DUP01, this );
|
0
|
81 |
}
|
|
82 |
|
|
83 |
void CUT_PBASE_T_USBDI_0485::ExecuteHostTestCaseL()
|
|
84 |
{
|
253
|
85 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0485_EXECUTEHOSTTESTCASEL_ENTRY, this );
|
0
|
86 |
|
|
87 |
// Create the actor for the Function Driver Framework
|
|
88 |
|
|
89 |
iActorFDF = CActorFDF::NewL(*this);
|
|
90 |
|
|
91 |
// Create the control transfer for requests
|
|
92 |
|
|
93 |
iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
|
|
94 |
|
|
95 |
// Monitor for devices
|
|
96 |
|
|
97 |
iActorFDF->Monitor();
|
|
98 |
|
|
99 |
// Start the connection timeout timer
|
|
100 |
|
|
101 |
TimeoutIn(30);
|
253
|
102 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_EXECUTEHOSTTESTCASEL_EXIT, this );
|
0
|
103 |
}
|
|
104 |
|
|
105 |
|
|
106 |
void CUT_PBASE_T_USBDI_0485::ExecuteDeviceTestCaseL()
|
|
107 |
{
|
253
|
108 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0485_EXECUTEDEVICETESTCASEL_ENTRY, this );
|
0
|
109 |
|
|
110 |
// Create the test device
|
|
111 |
|
|
112 |
iTestDevice->OpenL(TestCaseId());
|
|
113 |
iTestDevice->SubscribeToReports(iStatus);
|
|
114 |
SetActive();
|
|
115 |
|
|
116 |
// Connect the device to the host
|
|
117 |
|
|
118 |
iTestDevice->SoftwareConnect();
|
253
|
119 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_EXECUTEDEVICETESTCASEL_EXIT, this );
|
0
|
120 |
}
|
|
121 |
|
|
122 |
|
|
123 |
void CUT_PBASE_T_USBDI_0485::HostDoCancel()
|
|
124 |
{
|
253
|
125 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0485_HOSTDOCANCEL_ENTRY, this );
|
0
|
126 |
|
|
127 |
// Cancel the test step action timeout timer
|
|
128 |
|
|
129 |
CancelTimeout();
|
253
|
130 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_HOSTDOCANCEL_EXIT, this );
|
0
|
131 |
}
|
|
132 |
|
|
133 |
|
|
134 |
void CUT_PBASE_T_USBDI_0485::DeviceDoCancel()
|
|
135 |
{
|
253
|
136 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0485_DEVICEDOCANCEL_ENTRY, this );
|
0
|
137 |
|
|
138 |
// Cancel the device (the activity timer and the error reporting)
|
|
139 |
|
|
140 |
iTestDevice->CancelSubscriptionToReports();
|
253
|
141 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_DEVICEDOCANCEL_EXIT, this );
|
0
|
142 |
}
|
|
143 |
|
|
144 |
|
|
145 |
void CUT_PBASE_T_USBDI_0485::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
|
|
146 |
RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
|
|
147 |
{
|
253
|
148 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0485_DEVICESTATECHANGEL_ENTRY, this );
|
0
|
149 |
|
253
|
150 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_DEVICESTATECHANGEL_EXIT, this );
|
0
|
151 |
}
|
|
152 |
|
|
153 |
|
|
154 |
void CUT_PBASE_T_USBDI_0485::DeviceInsertedL(TUint aDeviceHandle)
|
|
155 |
{
|
253
|
156 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0485_DEVICEINSERTEDL_ENTRY, this );
|
0
|
157 |
|
|
158 |
// Cancel the timeout timer
|
|
159 |
|
|
160 |
Cancel();
|
|
161 |
|
|
162 |
TInt err(KErrNone);
|
|
163 |
|
|
164 |
// Validate that device is as expected
|
|
165 |
|
|
166 |
CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
|
|
167 |
if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
|
|
168 |
{
|
|
169 |
// Incorrect device for this test case
|
|
170 |
|
253
|
171 |
OstTraceExt3(TRACE_NORMAL, CUT_PBASE_T_USBDI_0485_DEVICEINSERTEDL, "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
|
|
172 |
KErrNotFound,testDevice.SerialNumber(),TestCaseId());
|
0
|
173 |
|
|
174 |
// Start the connection timeout again
|
|
175 |
|
|
176 |
TimeoutIn(30);
|
253
|
177 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_DEVICEINSERTEDL_EXIT, this );
|
0
|
178 |
return;
|
|
179 |
}
|
|
180 |
|
|
181 |
// Get the token for the interface
|
|
182 |
|
|
183 |
err = testDevice.Device().GetTokenForInterface(0,iToken0);
|
|
184 |
if(err != KErrNone)
|
|
185 |
{
|
253
|
186 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0485_DEVICEINSERTEDL_DUP01, "<Error %d> Unable to retrieve token for interface 0",err);
|
0
|
187 |
TestFailed(err);
|
|
188 |
}
|
|
189 |
|
|
190 |
// Open the interface
|
|
191 |
err = iUsbInterface0.Open(iToken0);
|
|
192 |
if(err != KErrNone)
|
|
193 |
{
|
253
|
194 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0485_DEVICEINSERTEDL_DUP02, "<Error %d> Unable to open interface 0", err);
|
0
|
195 |
TestFailed(err);
|
|
196 |
}
|
|
197 |
|
|
198 |
|
|
199 |
// Send a request to control endpoint 0 to continuously NAK the request
|
|
200 |
|
|
201 |
iCaseStep = EInProgress;
|
|
202 |
TNakRequest request(0);
|
|
203 |
iControlEp0->SendRequest(request,this);
|
|
204 |
|
|
205 |
// Wait 1 second then close the interface
|
|
206 |
User::After(1000000);
|
253
|
207 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0485_DEVICEINSERTEDL_DUP03, "Closing interface 0");
|
0
|
208 |
iUsbInterface0.Close();
|
253
|
209 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_DEVICEINSERTEDL_EXIT_DUP01, this );
|
0
|
210 |
}
|
|
211 |
|
|
212 |
void CUT_PBASE_T_USBDI_0485::Ep0TransferCompleteL(TInt aCompletionCode)
|
|
213 |
{
|
253
|
214 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0485_EP0TRANSFERCOMPLETEL_ENTRY, this );
|
0
|
215 |
|
253
|
216 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0485_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
0
|
217 |
|
|
218 |
switch(iCaseStep)
|
|
219 |
{
|
|
220 |
case EInProgress:
|
|
221 |
{
|
|
222 |
if(aCompletionCode != KErrCancel)
|
|
223 |
{
|
253
|
224 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0485_EP0TRANSFERCOMPLETEL_DUP01, "<Error %d> Nakking request was not cancelled by stack",aCompletionCode);
|
0
|
225 |
return TestFailed(aCompletionCode);
|
|
226 |
}
|
|
227 |
|
|
228 |
// No panic or leave so passed
|
|
229 |
|
253
|
230 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0485_EP0TRANSFERCOMPLETEL_DUP02, "No leave or panic occured so open interface again and send test passed");
|
0
|
231 |
|
|
232 |
// Open the interface
|
|
233 |
|
|
234 |
TInt err(iUsbInterface0.Open(iToken0));
|
|
235 |
if(err != KErrNone)
|
|
236 |
{
|
253
|
237 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0485_EP0TRANSFERCOMPLETEL_DUP03, "<Error %d> Unable to open interface 0", err);
|
0
|
238 |
return TestFailed(err);
|
|
239 |
}
|
|
240 |
|
253
|
241 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0485_EP0TRANSFERCOMPLETEL_DUP04, "Interface 0 re-opened");
|
0
|
242 |
|
|
243 |
iCaseStep = EPassed;
|
|
244 |
TTestCasePassed request;
|
|
245 |
iControlEp0->SendRequest(request,this);
|
|
246 |
}
|
|
247 |
break;
|
|
248 |
|
|
249 |
case EPassed:
|
|
250 |
TestPassed();
|
|
251 |
break;
|
|
252 |
|
|
253 |
case EFailed:
|
|
254 |
default:
|
|
255 |
TestFailed(KErrCompletion);
|
|
256 |
break;
|
|
257 |
}
|
253
|
258 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_EP0TRANSFERCOMPLETEL_EXIT, this );
|
0
|
259 |
}
|
|
260 |
|
|
261 |
void CUT_PBASE_T_USBDI_0485::DeviceRemovedL(TUint aDeviceHandle)
|
|
262 |
{
|
253
|
263 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0485_DEVICEREMOVEDL_ENTRY, this );
|
0
|
264 |
|
|
265 |
// The test device should not be removed until the test case has passed
|
|
266 |
// so this test case has not completed, and state this event as an error
|
|
267 |
|
|
268 |
TestFailed(KErrDisconnected);
|
253
|
269 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_DEVICEREMOVEDL_EXIT, this );
|
0
|
270 |
}
|
|
271 |
|
|
272 |
|
|
273 |
void CUT_PBASE_T_USBDI_0485::BusErrorL(TInt aError)
|
|
274 |
{
|
253
|
275 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0485_BUSERRORL_ENTRY, this );
|
0
|
276 |
|
|
277 |
// This test case handles no failiures on the bus
|
|
278 |
|
|
279 |
TestFailed(aError);
|
253
|
280 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_BUSERRORL_EXIT, this );
|
0
|
281 |
}
|
|
282 |
|
|
283 |
|
|
284 |
void CUT_PBASE_T_USBDI_0485::HostRunL()
|
|
285 |
{
|
253
|
286 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0485_HOSTRUNL_ENTRY, this );
|
0
|
287 |
|
|
288 |
// Obtain the completion code
|
|
289 |
TInt completionCode(iStatus.Int());
|
|
290 |
|
|
291 |
if(completionCode == KErrNone)
|
|
292 |
{
|
|
293 |
// Action timeout
|
253
|
294 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0485_HOSTRUNL, "<Error> Action timeout");
|
0
|
295 |
TestFailed(KErrTimedOut);
|
|
296 |
}
|
|
297 |
else
|
|
298 |
{
|
253
|
299 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0485_HOSTRUNL_DUP01, "<Error %d> Timeout timer could not complete",completionCode);
|
0
|
300 |
TestFailed(completionCode);
|
|
301 |
}
|
253
|
302 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_HOSTRUNL_EXIT, this );
|
0
|
303 |
}
|
|
304 |
|
|
305 |
/**
|
|
306 |
Called when the device has reported any kind of error in its opertaion
|
|
307 |
or when the device has been informed by the host to report success
|
|
308 |
*/
|
|
309 |
void CUT_PBASE_T_USBDI_0485::DeviceRunL()
|
|
310 |
{
|
253
|
311 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0485_DEVICERUNL_ENTRY, this );
|
0
|
312 |
|
|
313 |
// Disconnect the device
|
|
314 |
|
|
315 |
iTestDevice->SoftwareDisconnect();
|
|
316 |
|
|
317 |
// Complete the test case request
|
|
318 |
|
|
319 |
TestPolicy().SignalTestComplete(iStatus.Int());
|
253
|
320 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0485_DEVICERUNL_EXIT, this );
|
0
|
321 |
}
|
|
322 |
|
|
323 |
|
|
324 |
}
|