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