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-0481.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "PBASE-T_USBDI-0481.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-0481Traces.h"
|
|
26 |
#endif
|
0
|
27 |
|
|
28 |
namespace NUnitTesting_USBDI
|
|
29 |
{
|
|
30 |
|
|
31 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0481");
|
|
32 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0481,TBool> CUT_PBASE_T_USBDI_0481::iFunctor(KTestCaseId);
|
|
33 |
|
|
34 |
CUT_PBASE_T_USBDI_0481* CUT_PBASE_T_USBDI_0481::NewL(TBool aHostRole)
|
|
35 |
{
|
253
|
36 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0481_NEWL_ENTRY, aHostRole );
|
0
|
37 |
CUT_PBASE_T_USBDI_0481* self = new (ELeave) CUT_PBASE_T_USBDI_0481(aHostRole);
|
|
38 |
CleanupStack::PushL(self);
|
|
39 |
self->ConstructL();
|
|
40 |
CleanupStack::Pop(self);
|
253
|
41 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_NEWL_EXIT, ( TUint )( self ) );
|
0
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
|
|
46 |
CUT_PBASE_T_USBDI_0481::CUT_PBASE_T_USBDI_0481(TBool aHostRole)
|
|
47 |
: CBaseTestCase(KTestCaseId,aHostRole),
|
|
48 |
iCaseStep(EInProgress)
|
|
49 |
{
|
253
|
50 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0481_CUT_PBASE_T_USBDI_0481_ENTRY, this );
|
|
51 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_CUT_PBASE_T_USBDI_0481_EXIT, this );
|
0
|
52 |
}
|
|
53 |
|
|
54 |
|
|
55 |
void CUT_PBASE_T_USBDI_0481::ConstructL()
|
|
56 |
{
|
253
|
57 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0481_CONSTRUCTL_ENTRY, this );
|
0
|
58 |
iTestDevice = new RUsbDeviceA(this);
|
|
59 |
BaseConstructL();
|
253
|
60 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_CONSTRUCTL_EXIT, this );
|
0
|
61 |
}
|
|
62 |
|
|
63 |
|
|
64 |
CUT_PBASE_T_USBDI_0481::~CUT_PBASE_T_USBDI_0481()
|
|
65 |
{
|
253
|
66 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0481_CUT_PBASE_T_USBDI_0481_ENTRY_DUP01, this );
|
0
|
67 |
|
|
68 |
Cancel();
|
|
69 |
|
|
70 |
// Close interfaces
|
|
71 |
iUsbInterface0.Close();
|
|
72 |
iUsbInterface1.Close();
|
|
73 |
|
|
74 |
// Free resources
|
|
75 |
delete iControlEp0;
|
|
76 |
delete iActorFDF;
|
|
77 |
if(!IsHost() && iTestDevice)
|
|
78 |
{
|
|
79 |
iTestDevice->Close();
|
|
80 |
}
|
|
81 |
delete iTestDevice;
|
253
|
82 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_CUT_PBASE_T_USBDI_0481_EXIT_DUP01, this );
|
0
|
83 |
}
|
|
84 |
|
|
85 |
void CUT_PBASE_T_USBDI_0481::ExecuteHostTestCaseL()
|
|
86 |
{
|
253
|
87 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0481_EXECUTEHOSTTESTCASEL_ENTRY, this );
|
0
|
88 |
|
|
89 |
// Create the actor for the Function Driver Framework
|
|
90 |
iActorFDF = CActorFDF::NewL(*this);
|
|
91 |
|
|
92 |
// Create the control transfer for requests
|
|
93 |
iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
|
|
94 |
|
|
95 |
// Monitor for devices
|
|
96 |
iActorFDF->Monitor();
|
|
97 |
|
|
98 |
// Start the connection timeout timer
|
|
99 |
TimeoutIn(30);
|
253
|
100 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_EXECUTEHOSTTESTCASEL_EXIT, this );
|
0
|
101 |
}
|
|
102 |
|
|
103 |
|
|
104 |
void CUT_PBASE_T_USBDI_0481::ExecuteDeviceTestCaseL()
|
|
105 |
{
|
253
|
106 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0481_EXECUTEDEVICETESTCASEL_ENTRY, this );
|
0
|
107 |
|
|
108 |
// Create the test device
|
|
109 |
iTestDevice->OpenL(TestCaseId());
|
|
110 |
iTestDevice->SubscribeToReports(iStatus);
|
|
111 |
SetActive();
|
|
112 |
|
|
113 |
// Connect the device to the host
|
|
114 |
iTestDevice->SoftwareConnect();
|
253
|
115 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_EXECUTEDEVICETESTCASEL_EXIT, this );
|
0
|
116 |
}
|
|
117 |
|
|
118 |
|
|
119 |
void CUT_PBASE_T_USBDI_0481::HostDoCancel()
|
|
120 |
{
|
253
|
121 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0481_HOSTDOCANCEL_ENTRY, this );
|
0
|
122 |
|
|
123 |
// Cancel the test step action timeout timer
|
|
124 |
CancelTimeout();
|
253
|
125 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_HOSTDOCANCEL_EXIT, this );
|
0
|
126 |
}
|
|
127 |
|
|
128 |
|
|
129 |
void CUT_PBASE_T_USBDI_0481::DeviceDoCancel()
|
|
130 |
{
|
253
|
131 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0481_DEVICEDOCANCEL_ENTRY, this );
|
0
|
132 |
|
|
133 |
// Cancel the device (the activity timer and the error reporting)
|
|
134 |
iTestDevice->CancelSubscriptionToReports();
|
253
|
135 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_DEVICEDOCANCEL_EXIT, this );
|
0
|
136 |
}
|
|
137 |
|
|
138 |
|
|
139 |
void CUT_PBASE_T_USBDI_0481::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
|
|
140 |
RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
|
|
141 |
{
|
253
|
142 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0481_DEVICESTATECHANGEL_ENTRY, this );
|
0
|
143 |
|
253
|
144 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_DEVICESTATECHANGEL_EXIT, this );
|
0
|
145 |
}
|
|
146 |
|
|
147 |
|
|
148 |
void CUT_PBASE_T_USBDI_0481::DeviceInsertedL(TUint aDeviceHandle)
|
|
149 |
{
|
253
|
150 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0481_DEVICEINSERTEDL_ENTRY, this );
|
0
|
151 |
|
|
152 |
// Cancel the timeout timer
|
|
153 |
Cancel();
|
|
154 |
|
|
155 |
TInt err(KErrNone);
|
|
156 |
|
|
157 |
// Validate that device is as expected
|
|
158 |
CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
|
|
159 |
if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
|
|
160 |
{
|
|
161 |
// Incorrect device for this test case
|
253
|
162 |
OstTraceExt3(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_DEVICEINSERTEDL, "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
|
|
163 |
KErrNotFound,testDevice.SerialNumber(),TestCaseId());
|
0
|
164 |
|
|
165 |
// Start the connection timeout again
|
|
166 |
TimeoutIn(30);
|
253
|
167 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_DEVICEINSERTEDL_EXIT, this );
|
0
|
168 |
return;
|
|
169 |
}
|
|
170 |
|
|
171 |
// Get the token for interface 0
|
|
172 |
err = testDevice.Device().GetTokenForInterface(0,iToken0);
|
|
173 |
if(err != KErrNone)
|
|
174 |
{
|
253
|
175 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_DEVICEINSERTEDL_DUP01, "<Error %d> Unable to retrieve token for interface 0",err);
|
0
|
176 |
TestFailed(err);
|
|
177 |
}
|
|
178 |
|
|
179 |
// Open interface 0
|
|
180 |
err = iUsbInterface0.Open(iToken0);
|
|
181 |
if(err != KErrNone)
|
|
182 |
{
|
253
|
183 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_DEVICEINSERTEDL_DUP02, "<Error %d> Unable to open interface 0", err);
|
0
|
184 |
TestFailed(err);
|
|
185 |
}
|
|
186 |
|
|
187 |
// Get the token for interface 1
|
|
188 |
TUint32 token1(0);
|
|
189 |
err = testDevice.Device().GetTokenForInterface(1,token1);
|
|
190 |
if(err != KErrNone)
|
|
191 |
{
|
253
|
192 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_DEVICEINSERTEDL_DUP03, "<Error %d> token1 for interface 1",err);
|
0
|
193 |
return TestFailed(err);
|
|
194 |
}
|
|
195 |
// Open interface 1
|
|
196 |
err = iUsbInterface1.Open(token1); // Alternate interface setting 0
|
|
197 |
if(err != KErrNone)
|
|
198 |
{
|
253
|
199 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_DEVICEINSERTEDL_DUP04, "<Error %d> Unable to open interface 1", err);
|
0
|
200 |
return TestFailed(err);
|
|
201 |
}
|
|
202 |
|
|
203 |
// Get the token for interface 1 again, fails
|
|
204 |
TUint32 token1Bis(0);
|
|
205 |
err = testDevice.Device().GetTokenForInterface(1,token1Bis);
|
|
206 |
if(err != KErrInUse)
|
|
207 |
{
|
253
|
208 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_DEVICEINSERTEDL_DUP05, "GetTokenForInterface(1,token1Bis), err != KErrInUse");
|
0
|
209 |
return TestFailed(err);
|
|
210 |
}
|
|
211 |
|
|
212 |
// Open interface 1 again, fails
|
253
|
213 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_DEVICEINSERTEDL_DUP06, "open it twice, catch error Code");
|
0
|
214 |
err = iUsbInterface1.Open(token1); // Alternate interface setting 0
|
|
215 |
if(err != KErrInUse)
|
|
216 |
{
|
253
|
217 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_DEVICEINSERTEDL_DUP07, "iUsbInterface1.Open(token1), err != KErrInUse");
|
0
|
218 |
return TestFailed(err);
|
|
219 |
}
|
|
220 |
|
|
221 |
// test ok
|
|
222 |
User::After(1000000);
|
|
223 |
iCaseStep = EPassed;
|
|
224 |
TTestCasePassed request;
|
|
225 |
iControlEp0->SendRequest(request,this);
|
253
|
226 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_DEVICEINSERTEDL_EXIT_DUP01, this );
|
0
|
227 |
}
|
|
228 |
|
|
229 |
void CUT_PBASE_T_USBDI_0481::Ep0TransferCompleteL(TInt aCompletionCode)
|
|
230 |
{
|
253
|
231 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0481_EP0TRANSFERCOMPLETEL_ENTRY, this );
|
0
|
232 |
|
253
|
233 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
0
|
234 |
|
|
235 |
if(aCompletionCode != KErrNone)
|
|
236 |
{
|
|
237 |
TBuf<256> msg;
|
|
238 |
msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
|
253
|
239 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_EP0TRANSFERCOMPLETEL_DUP01, msg);
|
0
|
240 |
}
|
|
241 |
|
|
242 |
if(iCaseStep == EPassed)
|
|
243 |
{
|
|
244 |
if(aCompletionCode == KErrNone)
|
|
245 |
{
|
|
246 |
return TestPassed();
|
|
247 |
}
|
|
248 |
// else error
|
|
249 |
iCaseStep = EFailed;
|
|
250 |
}
|
|
251 |
|
|
252 |
if(iCaseStep == EFailed)
|
|
253 |
{
|
|
254 |
return TestFailed(KErrCompletion);
|
|
255 |
}
|
253
|
256 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_EP0TRANSFERCOMPLETEL_EXIT, this );
|
0
|
257 |
}
|
|
258 |
|
|
259 |
void CUT_PBASE_T_USBDI_0481::DeviceRemovedL(TUint aDeviceHandle)
|
|
260 |
{
|
253
|
261 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0481_DEVICEREMOVEDL_ENTRY, this );
|
0
|
262 |
|
|
263 |
// The test device should not be removed until the test case has passed
|
|
264 |
// so this test case has not completed, and state this event as an error
|
|
265 |
TestFailed(KErrDisconnected);
|
253
|
266 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_DEVICEREMOVEDL_EXIT, this );
|
0
|
267 |
}
|
|
268 |
|
|
269 |
|
|
270 |
void CUT_PBASE_T_USBDI_0481::BusErrorL(TInt aError)
|
|
271 |
{
|
253
|
272 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0481_BUSERRORL_ENTRY, this );
|
0
|
273 |
|
|
274 |
// This test case handles no failiures on the bus
|
|
275 |
TestFailed(aError);
|
253
|
276 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_BUSERRORL_EXIT, this );
|
0
|
277 |
}
|
|
278 |
|
|
279 |
|
|
280 |
void CUT_PBASE_T_USBDI_0481::HostRunL()
|
|
281 |
{
|
253
|
282 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0481_HOSTRUNL_ENTRY, this );
|
0
|
283 |
|
|
284 |
// Obtain the completion code
|
|
285 |
TInt completionCode(iStatus.Int());
|
|
286 |
|
|
287 |
if(completionCode == KErrNone)
|
|
288 |
{
|
|
289 |
// Action timeout
|
253
|
290 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_HOSTRUNL, "<Error> Action timeout");
|
0
|
291 |
TestFailed(KErrTimedOut);
|
|
292 |
}
|
|
293 |
else
|
|
294 |
{
|
253
|
295 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0481_HOSTRUNL_DUP01, "<Error %d> Timeout timer could not complete",completionCode);
|
0
|
296 |
TestFailed(completionCode);
|
|
297 |
}
|
253
|
298 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_HOSTRUNL_EXIT, this );
|
0
|
299 |
}
|
|
300 |
|
|
301 |
/**
|
|
302 |
Called when the device has reported any kind of error in its opertaion
|
|
303 |
or when the device has been informed by the host to report success
|
|
304 |
*/
|
|
305 |
void CUT_PBASE_T_USBDI_0481::DeviceRunL()
|
|
306 |
{
|
253
|
307 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0481_DEVICERUNL_ENTRY, this );
|
0
|
308 |
// Disconnect the device
|
|
309 |
iTestDevice->SoftwareDisconnect();
|
|
310 |
// Complete the test case request
|
|
311 |
TestPolicy().SignalTestComplete(iStatus.Int());
|
253
|
312 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0481_DEVICERUNL_EXIT, this );
|
0
|
313 |
}
|
|
314 |
|
|
315 |
|
|
316 |
}
|