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