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