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