17 // |
17 // |
18 |
18 |
19 #include "PBASE-T_USBDI-0483.h" |
19 #include "PBASE-T_USBDI-0483.h" |
20 #include "testpolicy.h" |
20 #include "testpolicy.h" |
21 #include "modelleddevices.h" |
21 #include "modelleddevices.h" |
|
22 #include "OstTraceDefinitions.h" |
|
23 #ifdef OST_TRACE_COMPILER_IN_USE |
|
24 #include "PBASE-T_USBDI-0483Traces.h" |
|
25 #endif |
22 |
26 |
23 |
27 |
24 namespace NUnitTesting_USBDI |
28 namespace NUnitTesting_USBDI |
25 { |
29 { |
26 const TInt KGetConfigDescriptor = 0x0200; |
30 const TInt KGetConfigDescriptor = 0x0200; |
27 _LIT(KTestCaseId,"PBASE-T_USBDI-0483"); |
31 _LIT(KTestCaseId,"PBASE-T_USBDI-0483"); |
28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0483,TBool> CUT_PBASE_T_USBDI_0483::iFunctor(KTestCaseId); |
32 const TFunctorTestCase<CUT_PBASE_T_USBDI_0483,TBool> CUT_PBASE_T_USBDI_0483::iFunctor(KTestCaseId); |
29 |
33 |
30 CUT_PBASE_T_USBDI_0483* CUT_PBASE_T_USBDI_0483::NewL(TBool aHostRole) |
34 CUT_PBASE_T_USBDI_0483* CUT_PBASE_T_USBDI_0483::NewL(TBool aHostRole) |
31 { |
35 { |
|
36 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0483_NEWL_ENTRY, aHostRole ); |
32 CUT_PBASE_T_USBDI_0483* self = new (ELeave) CUT_PBASE_T_USBDI_0483(aHostRole); |
37 CUT_PBASE_T_USBDI_0483* self = new (ELeave) CUT_PBASE_T_USBDI_0483(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_0483_NEWL_EXIT, ( TUint )( self ) ); |
36 return self; |
42 return self; |
37 } |
43 } |
38 |
44 |
39 |
45 |
40 CUT_PBASE_T_USBDI_0483::CUT_PBASE_T_USBDI_0483(TBool aHostRole) |
46 CUT_PBASE_T_USBDI_0483::CUT_PBASE_T_USBDI_0483(TBool aHostRole) |
41 : CBaseTestCase(KTestCaseId,aHostRole), |
47 : CBaseTestCase(KTestCaseId,aHostRole), |
42 iCaseStep(EInProgress) |
48 iCaseStep(EInProgress) |
43 { |
49 { |
|
50 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0483_CUT_PBASE_T_USBDI_0483_ENTRY, this ); |
|
51 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_CUT_PBASE_T_USBDI_0483_EXIT, this ); |
44 } |
52 } |
45 |
53 |
46 |
54 |
47 void CUT_PBASE_T_USBDI_0483::ConstructL() |
55 void CUT_PBASE_T_USBDI_0483::ConstructL() |
48 { |
56 { |
|
57 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0483_CONSTRUCTL_ENTRY, this ); |
49 iTestDevice = new RUsbDeviceB(this); |
58 iTestDevice = new RUsbDeviceB(this); |
50 BaseConstructL(); |
59 BaseConstructL(); |
|
60 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_CONSTRUCTL_EXIT, this ); |
51 } |
61 } |
52 |
62 |
53 |
63 |
54 CUT_PBASE_T_USBDI_0483::~CUT_PBASE_T_USBDI_0483() |
64 CUT_PBASE_T_USBDI_0483::~CUT_PBASE_T_USBDI_0483() |
55 { |
65 { |
|
66 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0483_CUT_PBASE_T_USBDI_0483_ENTRY_DUP01, this ); |
56 Cancel(); |
67 Cancel(); |
57 |
68 |
58 // Close the interface |
69 // Close the interface |
59 iUsbInterface0.Close(); |
70 iUsbInterface0.Close(); |
60 |
71 |
85 |
97 |
86 // Start the connection timeout timer |
98 // Start the connection timeout timer |
87 |
99 |
88 TimeoutIn(30); |
100 TimeoutIn(30); |
89 |
101 |
|
102 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_EXECUTEHOSTTESTCASEL_EXIT, this ); |
90 } |
103 } |
91 |
104 |
92 void CUT_PBASE_T_USBDI_0483::HostDoCancel() |
105 void CUT_PBASE_T_USBDI_0483::HostDoCancel() |
93 { |
106 { |
94 LOG_FUNC |
107 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0483_HOSTDOCANCEL_ENTRY, this ); |
95 |
108 |
96 // Cancel the test step timeout timer |
109 // Cancel the test step timeout timer |
97 |
110 |
98 CancelTimeout(); |
111 CancelTimeout(); |
|
112 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_HOSTDOCANCEL_EXIT, this ); |
99 } |
113 } |
100 |
114 |
101 |
115 |
102 void CUT_PBASE_T_USBDI_0483::ExecuteDeviceTestCaseL() |
116 void CUT_PBASE_T_USBDI_0483::ExecuteDeviceTestCaseL() |
103 { |
117 { |
104 LOG_FUNC |
118 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0483_EXECUTEDEVICETESTCASEL_ENTRY, this ); |
105 |
119 |
106 // Create the test device |
120 // Create the test device |
107 |
121 |
108 iTestDevice->OpenL(TestCaseId()); |
122 iTestDevice->OpenL(TestCaseId()); |
109 iTestDevice->SubscribeToReports(iStatus); |
123 iTestDevice->SubscribeToReports(iStatus); |
110 SetActive(); |
124 SetActive(); |
111 |
125 |
112 // Connect the device to the host |
126 // Connect the device to the host |
113 |
127 |
114 iTestDevice->SoftwareConnect(); |
128 iTestDevice->SoftwareConnect(); |
|
129 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_EXECUTEDEVICETESTCASEL_EXIT, this ); |
115 } |
130 } |
116 |
131 |
117 |
132 |
118 void CUT_PBASE_T_USBDI_0483::DeviceDoCancel() |
133 void CUT_PBASE_T_USBDI_0483::DeviceDoCancel() |
119 { |
134 { |
120 LOG_FUNC |
135 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0483_DEVICEDOCANCEL_ENTRY, this ); |
121 |
136 |
122 // Cancel the reporting or errors from opertaions perfomed by the test device |
137 // Cancel the reporting or errors from opertaions perfomed by the test device |
123 |
138 |
124 iTestDevice->CancelSubscriptionToReports(); |
139 iTestDevice->CancelSubscriptionToReports(); |
|
140 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_DEVICEDOCANCEL_EXIT, this ); |
125 } |
141 } |
126 |
142 |
127 |
143 |
128 void CUT_PBASE_T_USBDI_0483::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState, |
144 void CUT_PBASE_T_USBDI_0483::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState, |
129 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode) |
145 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode) |
130 { |
146 { |
131 LOG_FUNC |
147 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0483_DEVICESTATECHANGEL_ENTRY, this ); |
132 |
148 |
133 |
149 |
|
150 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_DEVICESTATECHANGEL_EXIT, this ); |
134 } |
151 } |
135 |
152 |
136 void CUT_PBASE_T_USBDI_0483::Ep0TransferCompleteL(TInt aCompletionCode) |
153 void CUT_PBASE_T_USBDI_0483::Ep0TransferCompleteL(TInt aCompletionCode) |
137 { |
154 { |
138 LOG_FUNC |
155 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0483_EP0TRANSFERCOMPLETEL_ENTRY, this ); |
139 |
156 |
140 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode); |
157 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0483_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode); |
141 |
158 |
142 if(aCompletionCode != KErrNone) |
159 if(aCompletionCode != KErrNone) |
143 { |
160 { |
144 if(iCaseStep == EFailed) |
161 if(iCaseStep == EFailed) |
145 {// todo, cope with errors |
162 {// todo, cope with errors |
146 } |
163 } |
147 else |
164 else |
148 { |
165 { |
149 TBuf<256> msg; |
166 TBuf<256> msg; |
150 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode); |
167 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode); |
151 RDebug::Print(msg); |
168 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0483_EP0TRANSFERCOMPLETEL_DUP01, msg); |
152 iCaseStep = EFailed; |
169 iCaseStep = EFailed; |
153 TTestCaseFailed request(aCompletionCode,msg); |
170 TTestCaseFailed request(aCompletionCode,msg); |
154 iControlEp0->SendRequest(request,this); |
171 iControlEp0->SendRequest(request,this); |
|
172 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_EP0TRANSFERCOMPLETEL_EXIT, this ); |
155 return; |
173 return; |
156 } |
174 } |
157 } |
175 } |
158 |
176 |
159 switch(iCaseStep) |
177 switch(iCaseStep) |
197 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle); |
216 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle); |
198 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0) |
217 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0) |
199 { |
218 { |
200 // Incorrect device for this test case |
219 // Incorrect device for this test case |
201 |
220 |
202 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)", |
221 OstTraceExt3(TRACE_NORMAL, CUT_PBASE_T_USBDI_0483_DEVICEINSERTEDL, "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)", |
203 KErrNotFound,&testDevice.SerialNumber(),&TestCaseId()); |
222 KErrNotFound,testDevice.SerialNumber(),TestCaseId()); |
204 |
223 |
205 // Start the connection timeout again |
224 // Start the connection timeout again |
206 |
225 |
207 TimeoutIn(30); |
226 TimeoutIn(30); |
|
227 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_DEVICEINSERTEDL_EXIT, this ); |
208 return; |
228 return; |
209 } |
229 } |
210 |
230 |
211 RDebug::Printf("iControlEp0->SendRequest(getConfiguration,this)"); |
231 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0483_DEVICEINSERTEDL_DUP01, "iControlEp0->SendRequest(getConfiguration,this)"); |
212 TUint32 token0; |
232 TUint32 token0; |
213 err = testDevice.Device().GetTokenForInterface(0,token0); |
233 err = testDevice.Device().GetTokenForInterface(0,token0); |
214 if(err != KErrNone) |
234 if(err != KErrNone) |
215 { |
235 { |
216 RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err); |
236 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0483_DEVICEINSERTEDL_DUP02, "<Error %d> Token for interface 0 could not be retrieved",err); |
217 return TestFailed(err); |
237 return TestFailed(err); |
218 } |
238 } |
219 err = iUsbInterface0.Open(token0); // Default interface setting 0 |
239 err = iUsbInterface0.Open(token0); // Default interface setting 0 |
220 if(err != KErrNone) |
240 if(err != KErrNone) |
221 { |
241 { |
222 RDebug::Printf("<Error %d> Unable to open interface 1 using token %d",err,token0); |
242 OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0483_DEVICEINSERTEDL_DUP03, "<Error %d> Unable to open interface 1 using token %d",err,token0); |
223 return TestFailed(err); |
243 return TestFailed(err); |
224 } |
244 } |
225 |
245 |
226 // get config. descriptor now |
246 // get config. descriptor now |
227 TUint totalLength = testDevice.ConfigurationDescriptor().TotalLength(); |
247 TUint totalLength = testDevice.ConfigurationDescriptor().TotalLength(); |
228 RDebug::Printf("totalLength ==== %d",totalLength); |
248 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0483_DEVICEINSERTEDL_DUP04, "totalLength ==== %d",totalLength); |
229 iConfigDescriptorData = HBufC8::NewL(totalLength); |
249 iConfigDescriptorData = HBufC8::NewL(totalLength); |
230 TPtr8 des(iConfigDescriptorData->Des()); |
250 TPtr8 des(iConfigDescriptorData->Des()); |
231 des.SetLength(totalLength); |
251 des.SetLength(totalLength); |
232 TDescriptorGetRequest getConfiguration(KGetConfigDescriptor,0,des); |
252 TDescriptorGetRequest getConfiguration(KGetConfigDescriptor,0,des); |
233 iControlEp0->SendRequest(getConfiguration,this); |
253 iControlEp0->SendRequest(getConfiguration,this); |
|
254 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_DEVICEINSERTEDL_EXIT_DUP01, this ); |
234 } |
255 } |
235 |
256 |
236 |
257 |
237 void CUT_PBASE_T_USBDI_0483::DeviceRemovedL(TUint aDeviceHandle) |
258 void CUT_PBASE_T_USBDI_0483::DeviceRemovedL(TUint aDeviceHandle) |
238 { |
259 { |
239 LOG_FUNC |
260 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0483_DEVICEREMOVEDL_ENTRY, this ); |
240 |
261 |
241 // The test device should not be removed until the test case has passed |
262 // The test device should not be removed until the test case has passed |
242 // so this test case has not completed, and state this event as an error |
263 // so this test case has not completed, and state this event as an error |
243 |
264 |
244 TestFailed(KErrDisconnected); |
265 TestFailed(KErrDisconnected); |
|
266 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_DEVICEREMOVEDL_EXIT, this ); |
245 } |
267 } |
246 |
268 |
247 |
269 |
248 void CUT_PBASE_T_USBDI_0483::BusErrorL(TInt aError) |
270 void CUT_PBASE_T_USBDI_0483::BusErrorL(TInt aError) |
249 { |
271 { |
250 LOG_FUNC |
272 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0483_BUSERRORL_ENTRY, this ); |
251 |
273 |
252 // This test case handles no failiures on the bus |
274 // This test case handles no failiures on the bus |
253 |
275 |
254 TestFailed(KErrCompletion); |
276 TestFailed(KErrCompletion); |
|
277 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_BUSERRORL_EXIT, this ); |
255 } |
278 } |
256 |
279 |
257 |
280 |
258 void CUT_PBASE_T_USBDI_0483::HostRunL() |
281 void CUT_PBASE_T_USBDI_0483::HostRunL() |
259 { |
282 { |
|
283 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0483_HOSTRUNL_ENTRY, this ); |
260 // Obtain the completion code |
284 // Obtain the completion code |
261 TInt completionCode(iStatus.Int()); |
285 TInt completionCode(iStatus.Int()); |
262 |
286 |
263 if(completionCode == KErrNone) |
287 if(completionCode == KErrNone) |
264 { |
288 { |
265 // Action timeout |
289 // Action timeout |
266 RDebug::Printf("<Error> Action timeout"); |
290 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0483_HOSTRUNL, "<Error> Action timeout"); |
267 TestFailed(KErrTimedOut); |
291 TestFailed(KErrTimedOut); |
268 } |
292 } |
269 else |
293 else |
270 { |
294 { |
271 RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode); |
295 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0483_HOSTRUNL_DUP01, "<Error %d> Timeout timer could not complete",completionCode); |
272 TestFailed(completionCode); |
296 TestFailed(completionCode); |
273 } |
297 } |
|
298 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_HOSTRUNL_EXIT, this ); |
274 } |
299 } |
275 |
300 |
276 void CUT_PBASE_T_USBDI_0483::DeviceRunL() |
301 void CUT_PBASE_T_USBDI_0483::DeviceRunL() |
277 { |
302 { |
278 LOG_FUNC |
303 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0483_DEVICERUNL_ENTRY, this ); |
279 |
304 |
280 // Disconnect the device |
305 // Disconnect the device |
281 |
306 |
282 iTestDevice->SoftwareDisconnect(); |
307 iTestDevice->SoftwareDisconnect(); |
283 |
308 |
284 // Complete the test case request |
309 // Complete the test case request |
285 |
310 |
286 TestPolicy().SignalTestComplete(iStatus.Int()); |
311 TestPolicy().SignalTestComplete(iStatus.Int()); |
287 } |
312 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0483_DEVICERUNL_EXIT, this ); |
288 |
313 } |
289 |
314 |
290 } |
315 |
|
316 } |