17 // |
17 // |
18 |
18 |
19 #include "PBASE-T_USBDI-0474.h" |
19 #include "PBASE-T_USBDI-0474.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-0474Traces.h" |
|
25 #endif |
|
26 |
22 |
27 |
23 |
28 namespace NUnitTesting_USBDI |
24 namespace NUnitTesting_USBDI |
29 { |
25 { |
30 |
26 |
31 _LIT(KTestCaseId,"PBASE-T_USBDI-0474"); |
27 _LIT(KTestCaseId,"PBASE-T_USBDI-0474"); |
32 const TFunctorTestCase<CUT_PBASE_T_USBDI_0474,TBool> CUT_PBASE_T_USBDI_0474::iFunctor(KTestCaseId); |
28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0474,TBool> CUT_PBASE_T_USBDI_0474::iFunctor(KTestCaseId); |
33 |
29 |
34 CUT_PBASE_T_USBDI_0474* CUT_PBASE_T_USBDI_0474::NewL(TBool aHostRole) |
30 CUT_PBASE_T_USBDI_0474* CUT_PBASE_T_USBDI_0474::NewL(TBool aHostRole) |
35 { |
31 { |
36 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0474_NEWL_ENTRY, aHostRole ); |
|
37 CUT_PBASE_T_USBDI_0474* self = new (ELeave) CUT_PBASE_T_USBDI_0474(aHostRole); |
32 CUT_PBASE_T_USBDI_0474* self = new (ELeave) CUT_PBASE_T_USBDI_0474(aHostRole); |
38 CleanupStack::PushL(self); |
33 CleanupStack::PushL(self); |
39 self->ConstructL(); |
34 self->ConstructL(); |
40 CleanupStack::Pop(self); |
35 CleanupStack::Pop(self); |
41 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_NEWL_EXIT, ( TUint )( self ) ); |
|
42 return self; |
36 return self; |
43 } |
37 } |
44 |
38 |
45 |
39 |
46 CUT_PBASE_T_USBDI_0474::CUT_PBASE_T_USBDI_0474(TBool aHostRole) |
40 CUT_PBASE_T_USBDI_0474::CUT_PBASE_T_USBDI_0474(TBool aHostRole) |
47 : CBaseTestCase(KTestCaseId,aHostRole), |
41 : CBaseTestCase(KTestCaseId,aHostRole), |
48 iCaseStep(EInProgress) |
42 iCaseStep(EInProgress) |
49 { |
43 { |
50 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0474_CUT_PBASE_T_USBDI_0474_ENTRY, this ); |
|
51 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_CUT_PBASE_T_USBDI_0474_EXIT, this ); |
|
52 } |
44 } |
53 |
45 |
54 |
46 |
55 void CUT_PBASE_T_USBDI_0474::ConstructL() |
47 void CUT_PBASE_T_USBDI_0474::ConstructL() |
56 { |
48 { |
57 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0474_CONSTRUCTL_ENTRY, this ); |
|
58 iTestDevice = new RUsbDeviceB(this); |
49 iTestDevice = new RUsbDeviceB(this); |
59 BaseConstructL(); |
50 BaseConstructL(); |
60 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_CONSTRUCTL_EXIT, this ); |
|
61 } |
51 } |
62 |
52 |
63 |
53 |
64 CUT_PBASE_T_USBDI_0474::~CUT_PBASE_T_USBDI_0474() |
54 CUT_PBASE_T_USBDI_0474::~CUT_PBASE_T_USBDI_0474() |
65 { |
55 { |
66 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0474_CUT_PBASE_T_USBDI_0474_ENTRY_DUP01, this ); |
56 LOG_FUNC |
67 Cancel(); |
57 Cancel(); |
68 |
58 |
69 iUsbInterface0.Close(); |
59 iUsbInterface0.Close(); |
70 |
60 |
71 delete iClientAction; |
61 delete iClientAction; |
73 if(!IsHost() && iTestDevice) |
63 if(!IsHost() && iTestDevice) |
74 { |
64 { |
75 iTestDevice->Close(); |
65 iTestDevice->Close(); |
76 } |
66 } |
77 delete iTestDevice; |
67 delete iTestDevice; |
78 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_CUT_PBASE_T_USBDI_0474_EXIT_DUP01, this ); |
|
79 } |
68 } |
80 |
69 |
81 |
70 |
82 void CUT_PBASE_T_USBDI_0474::ExecuteHostTestCaseL() |
71 void CUT_PBASE_T_USBDI_0474::ExecuteHostTestCaseL() |
83 { |
72 { |
84 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0474_EXECUTEHOSTTESTCASEL_ENTRY, this ); |
73 LOG_FUNC |
85 |
74 |
86 iActorFDF = CActorFDF::NewL(*this); |
75 iActorFDF = CActorFDF::NewL(*this); |
87 iClientAction = new (ELeave) CEp0Transfer(iUsbInterface0); |
76 iClientAction = new (ELeave) CEp0Transfer(iUsbInterface0); |
88 iActorFDF->Monitor(); |
77 iActorFDF->Monitor(); |
89 TimeoutIn(30); |
78 TimeoutIn(30); |
90 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_EXECUTEHOSTTESTCASEL_EXIT, this ); |
|
91 } |
79 } |
92 |
80 |
93 |
81 |
94 void CUT_PBASE_T_USBDI_0474::ExecuteDeviceTestCaseL() |
82 void CUT_PBASE_T_USBDI_0474::ExecuteDeviceTestCaseL() |
95 { |
83 { |
96 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0474_EXECUTEDEVICETESTCASEL_ENTRY, this ); |
84 LOG_FUNC |
97 |
85 |
98 iTestDevice->OpenL(TestCaseId()); |
86 iTestDevice->OpenL(TestCaseId()); |
99 iTestDevice->SubscribeToReports(iStatus); |
87 iTestDevice->SubscribeToReports(iStatus); |
100 SetActive(); |
88 SetActive(); |
101 iTestDevice->SoftwareConnect(); |
89 iTestDevice->SoftwareConnect(); |
102 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_EXECUTEDEVICETESTCASEL_EXIT, this ); |
|
103 } |
90 } |
104 |
91 |
105 |
92 |
106 void CUT_PBASE_T_USBDI_0474::HostDoCancel() |
93 void CUT_PBASE_T_USBDI_0474::HostDoCancel() |
107 { |
94 { |
108 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0474_HOSTDOCANCEL_ENTRY, this ); |
95 LOG_FUNC |
109 |
96 |
110 // Cancel the test step timeout |
97 // Cancel the test step timeout |
111 |
98 |
112 CancelTimeout(); |
99 CancelTimeout(); |
113 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_HOSTDOCANCEL_EXIT, this ); |
|
114 } |
100 } |
115 |
101 |
116 |
102 |
117 void CUT_PBASE_T_USBDI_0474::DeviceDoCancel() |
103 void CUT_PBASE_T_USBDI_0474::DeviceDoCancel() |
118 { |
104 { |
119 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0474_DEVICEDOCANCEL_ENTRY, this ); |
105 LOG_FUNC |
120 |
106 |
121 // Cancel the device |
107 // Cancel the device |
122 |
108 |
123 iTestDevice->CancelSubscriptionToReports(); |
109 iTestDevice->CancelSubscriptionToReports(); |
124 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_DEVICEDOCANCEL_EXIT, this ); |
|
125 } |
110 } |
126 |
111 |
127 void CUT_PBASE_T_USBDI_0474::DeviceInsertedL(TUint aDeviceHandle) |
112 void CUT_PBASE_T_USBDI_0474::DeviceInsertedL(TUint aDeviceHandle) |
128 { |
113 { |
129 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0474_DEVICEINSERTEDL_ENTRY, this ); |
114 LOG_FUNC |
130 Cancel(); |
115 Cancel(); |
131 TInt err(KErrNone); |
116 TInt err(KErrNone); |
132 |
117 |
133 // Validate that device is as expected |
118 // Validate that device is as expected |
134 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle); |
119 CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle); |
135 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0) |
120 if(testDevice.SerialNumber().Compare(TestCaseId()) != 0) |
136 { |
121 { |
137 // Incorrect device for this test case |
122 // Incorrect device for this test case |
138 |
123 |
139 OstTraceExt3(TRACE_NORMAL, CUT_PBASE_T_USBDI_0474_DEVICEINSERTEDL, "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)", |
124 RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)", |
140 KErrNotFound,testDevice.SerialNumber(),TestCaseId()); |
125 KErrNotFound,&testDevice.SerialNumber(),&TestCaseId()); |
141 |
126 |
142 // Start the connection timeout again |
127 // Start the connection timeout again |
143 |
128 |
144 TimeoutIn(30); |
129 TimeoutIn(30); |
145 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_DEVICEINSERTEDL_EXIT, this ); |
|
146 return; |
130 return; |
147 } |
131 } |
148 |
132 |
149 // Check tree now |
133 // Check tree now |
150 TUsbGenericDescriptor deviceDesc = testDevice.DeviceDescriptor(); |
134 TUsbGenericDescriptor deviceDesc = testDevice.DeviceDescriptor(); |
156 // Inform client device test case successful |
140 // Inform client device test case successful |
157 TUint32 token0; |
141 TUint32 token0; |
158 err = testDevice.Device().GetTokenForInterface(0,token0); |
142 err = testDevice.Device().GetTokenForInterface(0,token0); |
159 if(err != KErrNone) |
143 if(err != KErrNone) |
160 { |
144 { |
161 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0474_DEVICEINSERTEDL_DUP01, "<Error %d> Token for interface 0 could not be retrieved",err); |
145 RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err); |
162 return TestFailed(err); |
146 return TestFailed(err); |
163 } |
147 } |
164 err = iUsbInterface0.Open(token0); // Default interface setting 0 |
148 err = iUsbInterface0.Open(token0); // Default interface setting 0 |
165 if(err != KErrNone) |
149 if(err != KErrNone) |
166 { |
150 { |
167 OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0474_DEVICEINSERTEDL_DUP02, "<Error %d> Unable to open interface 1 using token %d",err,token0); |
151 RDebug::Printf("<Error %d> Unable to open interface 1 using token %d",err,token0); |
168 return TestFailed(err); |
152 return TestFailed(err); |
169 } |
153 } |
170 |
154 |
171 iCaseStep = EPassed; |
155 iCaseStep = EPassed; |
172 TTestCasePassed request; |
156 TTestCasePassed request; |
173 iClientAction->SendRequest(request,this); |
157 iClientAction->SendRequest(request,this); |
174 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_DEVICEINSERTEDL_EXIT_DUP01, this ); |
|
175 } |
158 } |
176 |
159 |
177 |
160 |
178 void CUT_PBASE_T_USBDI_0474::DeviceRemovedL(TUint aDeviceHandle) |
161 void CUT_PBASE_T_USBDI_0474::DeviceRemovedL(TUint aDeviceHandle) |
179 { |
162 { |
180 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0474_DEVICEREMOVEDL_ENTRY, this ); |
163 LOG_FUNC |
181 |
164 |
182 // The test device should not be removed until the test case has passed |
165 // The test device should not be removed until the test case has passed |
183 // so this test case has not completed, and state this event as an error |
166 // so this test case has not completed, and state this event as an error |
184 |
167 |
185 TestFailed(KErrDisconnected); |
168 TestFailed(KErrDisconnected); |
186 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_DEVICEREMOVEDL_EXIT, this ); |
|
187 } |
169 } |
188 |
170 |
189 |
171 |
190 void CUT_PBASE_T_USBDI_0474::BusErrorL(TInt aError) |
172 void CUT_PBASE_T_USBDI_0474::BusErrorL(TInt aError) |
191 { |
173 { |
192 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0474_BUSERRORL_ENTRY, this ); |
174 LOG_FUNC |
193 |
175 |
194 // This test case handles no failiures on the bus |
176 // This test case handles no failiures on the bus |
195 |
177 |
196 TestFailed(aError); |
178 TestFailed(aError); |
197 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_BUSERRORL_EXIT, this ); |
|
198 } |
179 } |
199 |
180 |
200 |
181 |
201 void CUT_PBASE_T_USBDI_0474::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState, |
182 void CUT_PBASE_T_USBDI_0474::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState, |
202 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode) |
183 RUsbDevice::TDeviceState aNewState,TInt aCompletionCode) |
203 { |
184 { |
204 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0474_DEVICESTATECHANGEL_ENTRY, this ); |
185 LOG_FUNC |
205 Cancel(); |
186 Cancel(); |
206 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_DEVICESTATECHANGEL_EXIT, this ); |
|
207 } |
187 } |
208 |
188 |
209 void CUT_PBASE_T_USBDI_0474::Ep0TransferCompleteL(TInt aCompletionCode) |
189 void CUT_PBASE_T_USBDI_0474::Ep0TransferCompleteL(TInt aCompletionCode) |
210 { |
190 { |
211 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0474_EP0TRANSFERCOMPLETEL_ENTRY, this ); |
191 LOG_FUNC |
212 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0474_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode); |
192 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode); |
213 |
193 |
214 if(iCaseStep == EPassed) |
194 if(iCaseStep == EPassed) |
215 { |
195 { |
216 TestPassed(); |
196 TestPassed(); |
217 } |
197 } |
218 |
198 |
219 if(iCaseStep == EFailed) |
199 if(iCaseStep == EFailed) |
220 { |
200 { |
221 TestFailed(KErrCompletion); |
201 TestFailed(KErrCompletion); |
222 } |
202 } |
223 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_EP0TRANSFERCOMPLETEL_EXIT, this ); |
|
224 } |
203 } |
225 |
204 |
226 |
205 |
227 void CUT_PBASE_T_USBDI_0474::HostRunL() |
206 void CUT_PBASE_T_USBDI_0474::HostRunL() |
228 { |
207 { |
229 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0474_HOSTRUNL_ENTRY, this ); |
208 LOG_FUNC |
230 |
209 |
231 // Obtain the completion code |
210 // Obtain the completion code |
232 TInt completionCode(iStatus.Int()); |
211 TInt completionCode(iStatus.Int()); |
233 |
212 |
234 if(completionCode == KErrNone) |
213 if(completionCode == KErrNone) |
235 { |
214 { |
236 // Action timeout |
215 // Action timeout |
237 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0474_HOSTRUNL, "<Error> Action timeout"); |
216 RDebug::Printf("<Error> Action timeout"); |
238 TestFailed(KErrTimedOut); |
217 TestFailed(KErrTimedOut); |
239 } |
218 } |
240 else |
219 else |
241 { |
220 { |
242 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0474_HOSTRUNL_DUP01, "<Error %d> Timeout timer could not complete",completionCode); |
221 RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode); |
243 TestFailed(completionCode); |
222 TestFailed(completionCode); |
244 } |
223 } |
245 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_HOSTRUNL_EXIT, this ); |
|
246 } |
224 } |
247 |
225 |
248 void CUT_PBASE_T_USBDI_0474::DeviceRunL() |
226 void CUT_PBASE_T_USBDI_0474::DeviceRunL() |
249 { |
227 { |
250 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0474_DEVICERUNL_ENTRY, this ); |
228 LOG_FUNC |
251 |
229 |
252 // Disconnect the device |
230 // Disconnect the device |
253 |
231 |
254 iTestDevice->SoftwareDisconnect(); |
232 iTestDevice->SoftwareDisconnect(); |
255 |
233 |
256 // Complete the test case request |
234 // Complete the test case request |
257 |
235 |
258 TestPolicy().SignalTestComplete(iStatus.Int()); |
236 TestPolicy().SignalTestComplete(iStatus.Int()); |
259 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0474_DEVICERUNL_EXIT, this ); |
237 } |
260 } |
238 |
261 |
239 |
262 |
240 } |
263 } |
241 |
264 |
|