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-0479.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "PBASE-T_USBDI-0479.h"
|
|
20 |
#include "testpolicy.h"
|
|
21 |
#include "modelleddevices.h"
|
253
|
22 |
#include "OstTraceDefinitions.h"
|
|
23 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
24 |
#include "PBASE-T_USBDI-0479Traces.h"
|
|
25 |
#endif
|
0
|
26 |
|
|
27 |
|
|
28 |
namespace NUnitTesting_USBDI
|
|
29 |
{
|
|
30 |
|
|
31 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0479");
|
|
32 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0479,TBool> CUT_PBASE_T_USBDI_0479::iFunctor(KTestCaseId);
|
|
33 |
|
|
34 |
CUT_PBASE_T_USBDI_0479* CUT_PBASE_T_USBDI_0479::NewL(TBool aHostRole)
|
|
35 |
{
|
253
|
36 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0479_NEWL_ENTRY, aHostRole );
|
0
|
37 |
CUT_PBASE_T_USBDI_0479* self = new (ELeave) CUT_PBASE_T_USBDI_0479(aHostRole);
|
|
38 |
CleanupStack::PushL(self);
|
|
39 |
self->ConstructL();
|
|
40 |
CleanupStack::Pop(self);
|
253
|
41 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_NEWL_EXIT, ( TUint )( self ) );
|
0
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
|
|
46 |
CUT_PBASE_T_USBDI_0479::CUT_PBASE_T_USBDI_0479(TBool aHostRole)
|
|
47 |
: CBaseTestCase(KTestCaseId,aHostRole),
|
|
48 |
iCaseStep(EInProgress)
|
|
49 |
{
|
253
|
50 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0479_CUT_PBASE_T_USBDI_0479_ENTRY, this );
|
|
51 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_CUT_PBASE_T_USBDI_0479_EXIT, this );
|
0
|
52 |
}
|
|
53 |
|
|
54 |
|
|
55 |
void CUT_PBASE_T_USBDI_0479::ConstructL()
|
|
56 |
{
|
253
|
57 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0479_CONSTRUCTL_ENTRY, this );
|
0
|
58 |
iTestDevice = new RUsbDeviceVendor(this);
|
|
59 |
BaseConstructL();
|
253
|
60 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_CONSTRUCTL_EXIT, this );
|
0
|
61 |
}
|
|
62 |
|
|
63 |
|
|
64 |
CUT_PBASE_T_USBDI_0479::~CUT_PBASE_T_USBDI_0479()
|
|
65 |
{
|
253
|
66 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0479_CUT_PBASE_T_USBDI_0479_ENTRY_DUP01, this );
|
0
|
67 |
|
|
68 |
Cancel();
|
|
69 |
|
|
70 |
iDuplicateUsbInterface0.Close();
|
|
71 |
iUsbInterface0.Close();
|
|
72 |
|
|
73 |
delete iClientAction;
|
|
74 |
delete iActorFDF;
|
|
75 |
if(!IsHost() && iTestDevice)
|
|
76 |
{
|
|
77 |
iTestDevice->Close();
|
|
78 |
}
|
|
79 |
delete iTestDevice;
|
253
|
80 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_CUT_PBASE_T_USBDI_0479_EXIT_DUP01, this );
|
0
|
81 |
}
|
|
82 |
|
|
83 |
void CUT_PBASE_T_USBDI_0479::ExecuteHostTestCaseL()
|
|
84 |
{
|
253
|
85 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0479_EXECUTEHOSTTESTCASEL_ENTRY, this );
|
0
|
86 |
|
|
87 |
iActorFDF = CActorFDF::NewL(*this);
|
|
88 |
iClientAction = new (ELeave) CEp0Transfer(iUsbInterface0);
|
|
89 |
iActorFDF->Monitor();
|
|
90 |
TimeoutIn(30);
|
253
|
91 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_EXECUTEHOSTTESTCASEL_EXIT, this );
|
0
|
92 |
}
|
|
93 |
|
|
94 |
void CUT_PBASE_T_USBDI_0479::HostDoCancel()
|
|
95 |
{
|
253
|
96 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0479_HOSTDOCANCEL_ENTRY, this );
|
0
|
97 |
|
|
98 |
// Cancel timing out the test step
|
|
99 |
|
|
100 |
CancelTimeout();
|
253
|
101 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_HOSTDOCANCEL_EXIT, this );
|
0
|
102 |
}
|
|
103 |
|
|
104 |
|
|
105 |
void CUT_PBASE_T_USBDI_0479::ExecuteDeviceTestCaseL()
|
|
106 |
{
|
253
|
107 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0479_EXECUTEDEVICETESTCASEL_ENTRY, this );
|
0
|
108 |
|
|
109 |
iTestDevice->OpenL(TestCaseId());
|
|
110 |
iTestDevice->SubscribeToReports(iStatus);
|
|
111 |
SetActive();
|
|
112 |
iTestDevice->SoftwareConnect();
|
253
|
113 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_EXECUTEDEVICETESTCASEL_EXIT, this );
|
0
|
114 |
}
|
|
115 |
|
|
116 |
void CUT_PBASE_T_USBDI_0479::DeviceDoCancel()
|
|
117 |
{
|
253
|
118 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0479_DEVICEDOCANCEL_ENTRY, this );
|
0
|
119 |
|
|
120 |
// Cancel the device
|
|
121 |
iTestDevice->CancelSubscriptionToReports();
|
253
|
122 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_DEVICEDOCANCEL_EXIT, this );
|
0
|
123 |
}
|
|
124 |
|
|
125 |
|
|
126 |
void CUT_PBASE_T_USBDI_0479::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
|
|
127 |
RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
|
|
128 |
{
|
253
|
129 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0479_DEVICESTATECHANGEL_ENTRY, this );
|
0
|
130 |
Cancel();
|
253
|
131 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_DEVICESTATECHANGEL_EXIT, this );
|
0
|
132 |
}
|
|
133 |
|
|
134 |
void CUT_PBASE_T_USBDI_0479::DeviceInsertedL(TUint aDeviceHandle)
|
|
135 |
{
|
253
|
136 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0479_DEVICEINSERTEDL_ENTRY, this );
|
0
|
137 |
Cancel();
|
|
138 |
TInt err(KErrNone);
|
|
139 |
|
|
140 |
// Validate that device is as expected
|
|
141 |
CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
|
|
142 |
if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
|
|
143 |
{
|
|
144 |
// Incorrect device for this test case
|
|
145 |
|
253
|
146 |
OstTraceExt3(TRACE_NORMAL, CUT_PBASE_T_USBDI_0479_DEVICEINSERTEDL, "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
|
|
147 |
KErrNotFound,testDevice.SerialNumber(),TestCaseId());
|
0
|
148 |
|
|
149 |
// Start the connection timeout again
|
|
150 |
|
|
151 |
TimeoutIn(30);
|
253
|
152 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_DEVICEINSERTEDL_EXIT, this );
|
0
|
153 |
return;
|
|
154 |
}
|
|
155 |
|
|
156 |
TUint32 validToken;
|
|
157 |
TUint32 invalidToken(KMaxTUint-1); // The known invalid token
|
|
158 |
|
|
159 |
err = testDevice.Device().GetTokenForInterface(0,validToken);
|
|
160 |
if(err != KErrNone)
|
|
161 |
{
|
253
|
162 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0479_DEVICEINSERTEDL_DUP01, "<Error %d> Token for interface could not be retrieved",err);
|
0
|
163 |
return TestFailed(err);
|
|
164 |
}
|
|
165 |
err = iUsbInterface0.Open(validToken); // Default interface setting 0
|
|
166 |
if(err != KErrNone)
|
|
167 |
{
|
253
|
168 |
OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0479_DEVICEINSERTEDL_DUP02, "<Error %d> Unable to open interface 0 using token %d",err,validToken);
|
0
|
169 |
return TestFailed(err);
|
|
170 |
}
|
|
171 |
|
|
172 |
err = iDuplicateUsbInterface0.Open(invalidToken);
|
|
173 |
if(err == KErrNone)
|
|
174 |
{
|
|
175 |
TBuf<64> msg;
|
|
176 |
msg.Format(_L("<Error %d> Able to open an interface that is not present"),KErrCorrupt);
|
253
|
177 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0479_DEVICEINSERTEDL_DUP03, msg);
|
0
|
178 |
iCaseStep = EFailed;
|
|
179 |
TTestCaseFailed request(KErrCorrupt,msg);
|
|
180 |
iClientAction->SendRequest(request,this);
|
|
181 |
}
|
|
182 |
else
|
|
183 |
{
|
253
|
184 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0479_DEVICEINSERTEDL_DUP04, "Opening interface with invalid token failed with %d",err);
|
0
|
185 |
User::After(1000000);
|
|
186 |
iCaseStep = EPassed;
|
|
187 |
TTestCasePassed request;
|
|
188 |
iClientAction->SendRequest(request,this);
|
|
189 |
}
|
253
|
190 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_DEVICEINSERTEDL_EXIT_DUP01, this );
|
0
|
191 |
}
|
|
192 |
|
|
193 |
|
|
194 |
void CUT_PBASE_T_USBDI_0479::DeviceRemovedL(TUint aDeviceHandle)
|
|
195 |
{
|
253
|
196 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0479_DEVICEREMOVEDL_ENTRY, this );
|
0
|
197 |
|
|
198 |
// The test device should not be removed until the test case has passed
|
|
199 |
// so this test case has not completed, and state this event as an error
|
|
200 |
|
|
201 |
TestFailed(KErrDisconnected);
|
253
|
202 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_DEVICEREMOVEDL_EXIT, this );
|
0
|
203 |
}
|
|
204 |
|
|
205 |
|
|
206 |
void CUT_PBASE_T_USBDI_0479::BusErrorL(TInt aError)
|
|
207 |
{
|
253
|
208 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0479_BUSERRORL_ENTRY, this );
|
0
|
209 |
|
|
210 |
// This test case handles no failiures on the bus
|
|
211 |
|
|
212 |
TestFailed(aError);
|
253
|
213 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_BUSERRORL_EXIT, this );
|
0
|
214 |
}
|
|
215 |
|
|
216 |
|
|
217 |
void CUT_PBASE_T_USBDI_0479::Ep0TransferCompleteL(TInt aCompletionCode)
|
|
218 |
{
|
253
|
219 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0479_EP0TRANSFERCOMPLETEL_ENTRY, this );
|
0
|
220 |
|
253
|
221 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0479_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
0
|
222 |
|
|
223 |
if(aCompletionCode != KErrNone)
|
|
224 |
{
|
|
225 |
TBuf<256> msg;
|
|
226 |
msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
|
253
|
227 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0479_EP0TRANSFERCOMPLETEL_DUP01, msg);
|
0
|
228 |
}
|
|
229 |
|
|
230 |
if(iCaseStep == EPassed)
|
|
231 |
{
|
|
232 |
if(aCompletionCode == KErrNone)
|
|
233 |
{
|
|
234 |
return TestPassed();
|
|
235 |
}
|
|
236 |
// else error
|
|
237 |
iCaseStep = EFailed;
|
|
238 |
}
|
|
239 |
|
|
240 |
if(iCaseStep == EFailed)
|
|
241 |
{
|
|
242 |
return TestFailed(KErrCompletion);
|
|
243 |
}
|
253
|
244 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_EP0TRANSFERCOMPLETEL_EXIT, this );
|
0
|
245 |
}
|
|
246 |
|
|
247 |
|
|
248 |
void CUT_PBASE_T_USBDI_0479::HostRunL()
|
|
249 |
{
|
253
|
250 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0479_HOSTRUNL_ENTRY, this );
|
0
|
251 |
// Obtain the completion code
|
|
252 |
TInt completionCode(iStatus.Int());
|
|
253 |
|
|
254 |
if(completionCode == KErrNone)
|
|
255 |
{
|
|
256 |
// Action timeout
|
253
|
257 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0479_HOSTRUNL, "<Error> Action timeout");
|
0
|
258 |
TestFailed(KErrTimedOut);
|
|
259 |
}
|
|
260 |
else
|
|
261 |
{
|
253
|
262 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0479_HOSTRUNL_DUP01, "<Error %d> Timeout timer could not complete",completionCode);
|
0
|
263 |
TestFailed(completionCode);
|
|
264 |
}
|
253
|
265 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_HOSTRUNL_EXIT, this );
|
0
|
266 |
}
|
|
267 |
|
|
268 |
void CUT_PBASE_T_USBDI_0479::DeviceRunL()
|
|
269 |
{
|
253
|
270 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0479_DEVICERUNL_ENTRY, this );
|
0
|
271 |
|
|
272 |
// Disconnect the device
|
|
273 |
|
|
274 |
iTestDevice->SoftwareDisconnect();
|
|
275 |
|
|
276 |
// Complete the test case request
|
|
277 |
|
|
278 |
TestPolicy().SignalTestComplete(iStatus.Int());
|
253
|
279 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0479_DEVICERUNL_EXIT, this );
|
0
|
280 |
}
|
|
281 |
|
|
282 |
|
|
283 |
}
|