1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2008-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". |
47 _LIT(KTestCaseId,"PBASE-T_USBDI-0500"); |
51 _LIT(KTestCaseId,"PBASE-T_USBDI-0500"); |
48 const TFunctorTestCase<CUT_PBASE_T_USBDI_0500,TBool> CUT_PBASE_T_USBDI_0500::iFunctor(KTestCaseId); |
52 const TFunctorTestCase<CUT_PBASE_T_USBDI_0500,TBool> CUT_PBASE_T_USBDI_0500::iFunctor(KTestCaseId); |
49 |
53 |
50 CUT_PBASE_T_USBDI_0500* CUT_PBASE_T_USBDI_0500::NewL(TBool aHostRole) |
54 CUT_PBASE_T_USBDI_0500* CUT_PBASE_T_USBDI_0500::NewL(TBool aHostRole) |
51 { |
55 { |
|
56 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0500_NEWL_ENTRY, aHostRole ); |
52 CUT_PBASE_T_USBDI_0500* self = new (ELeave) CUT_PBASE_T_USBDI_0500(aHostRole); |
57 CUT_PBASE_T_USBDI_0500* self = new (ELeave) CUT_PBASE_T_USBDI_0500(aHostRole); |
53 CleanupStack::PushL(self); |
58 CleanupStack::PushL(self); |
54 self->ConstructL(); |
59 self->ConstructL(); |
55 CleanupStack::Pop(self); |
60 CleanupStack::Pop(self); |
|
61 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0500_NEWL_EXIT, ( TUint )( self ) ); |
56 return self; |
62 return self; |
57 } |
63 } |
58 |
64 |
59 |
65 |
60 CUT_PBASE_T_USBDI_0500::CUT_PBASE_T_USBDI_0500(TBool aHostRole) |
66 CUT_PBASE_T_USBDI_0500::CUT_PBASE_T_USBDI_0500(TBool aHostRole) |
61 : CBaseBulkTestCase(KTestCaseId,aHostRole), |
67 : CBaseBulkTestCase(KTestCaseId,aHostRole), |
62 iCaseStep(EInProgress) |
68 iCaseStep(EInProgress) |
63 { |
69 { |
|
70 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0500_CUT_PBASE_T_USBDI_0500_ENTRY, this ); |
|
71 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0500_CUT_PBASE_T_USBDI_0500_EXIT, this ); |
64 } |
72 } |
65 |
73 |
66 |
74 |
67 void CUT_PBASE_T_USBDI_0500::ConstructL() |
75 void CUT_PBASE_T_USBDI_0500::ConstructL() |
68 { |
76 { |
|
77 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0500_CONSTRUCTL_ENTRY, this ); |
69 BaseBulkConstructL(); |
78 BaseBulkConstructL(); |
|
79 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0500_CONSTRUCTL_EXIT, this ); |
70 } |
80 } |
71 |
81 |
72 |
82 |
73 CUT_PBASE_T_USBDI_0500::~CUT_PBASE_T_USBDI_0500() |
83 CUT_PBASE_T_USBDI_0500::~CUT_PBASE_T_USBDI_0500() |
74 { |
84 { |
75 LOG_FUNC |
85 OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0500_CUT_PBASE_T_USBDI_0500_ENTRY_DUP01, this ); |
|
86 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0500_CUT_PBASE_T_USBDI_0500_EXIT_DUP01, this ); |
76 } |
87 } |
77 |
88 |
78 |
89 |
79 void CUT_PBASE_T_USBDI_0500::Ep0TransferCompleteL(TInt aCompletionCode) |
90 void CUT_PBASE_T_USBDI_0500::Ep0TransferCompleteL(TInt aCompletionCode) |
80 { |
91 { |
81 LOG_FUNC |
92 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0500_EP0TRANSFERCOMPLETEL_ENTRY, this ); |
82 |
93 |
83 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode); |
94 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode); |
84 |
95 |
85 if(aCompletionCode != KErrNone) |
96 if(aCompletionCode != KErrNone) |
86 { |
97 { |
87 if(iCaseStep == EFailed) |
98 if(iCaseStep == EFailed) |
88 {// ignore error, nad catch the TestFailed method called further down. |
99 {// ignore error, nad catch the TestFailed method called further down. |
89 RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***"); |
100 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_EP0TRANSFERCOMPLETEL_DUP01, "***Failure sending FAIL message to client on endpoint 0***"); |
90 } |
101 } |
91 else |
102 else |
92 { |
103 { |
93 TBuf<256> msg; |
104 TBuf<256> msg; |
94 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode); |
105 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode); |
95 RDebug::Print(msg); |
106 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_EP0TRANSFERCOMPLETEL_DUP02, msg); |
96 iCaseStep = EFailed; |
107 iCaseStep = EFailed; |
97 TTestCaseFailed request(aCompletionCode,msg); |
108 TTestCaseFailed request(aCompletionCode,msg); |
98 iControlEp0->SendRequest(request,this); |
109 iControlEp0->SendRequest(request,this); |
|
110 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0500_EP0TRANSFERCOMPLETEL_EXIT, this ); |
99 return; |
111 return; |
100 } |
112 } |
101 } |
113 } |
102 |
114 |
103 switch(iCaseStep) |
115 switch(iCaseStep) |
111 case EFailed: |
123 case EFailed: |
112 TestFailed(KErrCompletion); |
124 TestFailed(KErrCompletion); |
113 break; |
125 break; |
114 |
126 |
115 case ETransferInHalt: |
127 case ETransferInHalt: |
116 RDebug::Printf("Try to receive data (pre halt)"); |
128 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_EP0TRANSFERCOMPLETEL_DUP03, "Try to receive data (pre halt)"); |
117 iInTransfer[0]->TransferIn(KHostNumReadBytesPreHalt1); |
129 iInTransfer[0]->TransferIn(KHostNumReadBytesPreHalt1); |
118 iInTransfer[1]->TransferIn(KHostNumReadBytesPreHalt2); |
130 iInTransfer[1]->TransferIn(KHostNumReadBytesPreHalt2); |
119 break; |
131 break; |
120 |
132 |
121 case ETransferIn: |
133 case ETransferIn: |
122 RDebug::Printf("Try to receive data"); |
134 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_EP0TRANSFERCOMPLETEL_DUP04, "Try to receive data"); |
123 iInTransfer[0]->TransferIn(KHostNumReadBytesPostHalt1); |
135 iInTransfer[0]->TransferIn(KHostNumReadBytesPostHalt1); |
124 iInTransfer[1]->TransferIn(KHostNumReadBytesPostHalt2); |
136 iInTransfer[1]->TransferIn(KHostNumReadBytesPostHalt2); |
125 break; |
137 break; |
126 |
138 |
127 default: |
139 default: |
128 RDebug::Printf("<Error> Unknown test step"); |
140 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_EP0TRANSFERCOMPLETEL_DUP05, "<Error> Unknown test step"); |
129 TestFailed(KErrUnknown); |
141 TestFailed(KErrUnknown); |
130 break; |
142 break; |
131 } |
143 } |
|
144 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0500_EP0TRANSFERCOMPLETEL_EXIT_DUP01, this ); |
132 } |
145 } |
133 |
146 |
134 void CUT_PBASE_T_USBDI_0500::TransferCompleteL(TInt aTransferId,TInt aCompletionCode) |
147 void CUT_PBASE_T_USBDI_0500::TransferCompleteL(TInt aTransferId,TInt aCompletionCode) |
135 { |
148 { |
136 LOG_FUNC |
149 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0500_TRANSFERCOMPLETEL_ENTRY, this ); |
137 Cancel(); |
150 Cancel(); |
138 |
151 |
139 TInt err(KErrNone); |
152 TInt err(KErrNone); |
140 TBuf<256> msg; |
153 TBuf<256> msg; |
141 RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode); |
154 OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_TRANSFERCOMPLETEL, "Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode); |
142 |
155 |
143 switch(iCaseStep) |
156 switch(iCaseStep) |
144 { |
157 { |
145 case ETransferInHalt: |
158 case ETransferInHalt: |
146 { |
159 { |
156 switch(aTransferId) |
169 switch(aTransferId) |
157 { |
170 { |
158 case KBulkTransferInId0: |
171 case KBulkTransferInId0: |
159 case KBulkTransferInId1: |
172 case KBulkTransferInId1: |
160 iTransferComplete |= aTransferId; |
173 iTransferComplete |= aTransferId; |
161 RDebug::Printf("Transfer %d completed", aTransferId); |
174 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_TRANSFERCOMPLETEL_DUP01, "Transfer %d completed", aTransferId); |
162 break; //switch(aTransferId) |
175 break; //switch(aTransferId) |
163 |
176 |
164 default: |
177 default: |
165 iTransferComplete = 0; //reset |
178 iTransferComplete = 0; //reset |
166 err = KUnexpectedTransferID; |
179 err = KUnexpectedTransferID; |
169 break; //switch(aTransferId) |
182 break; //switch(aTransferId) |
170 } |
183 } |
171 |
184 |
172 if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1)) |
185 if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1)) |
173 { |
186 { |
174 RDebug::Printf("Clear halt and try to send data again. Transfers Completed %d", iTransferComplete); |
187 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_TRANSFERCOMPLETEL_DUP02, "Clear halt and try to send data again. Transfers Completed %d", iTransferComplete); |
175 iTransferComplete = 0; //reset |
188 iTransferComplete = 0; //reset |
176 // Acknowledge the stall and clear |
189 // Acknowledge the stall and clear |
177 err = iTestPipeInterface1BulkIn.ClearRemoteStall(); |
190 err = iTestPipeInterface1BulkIn.ClearRemoteStall(); |
178 if(err != KErrNone) |
191 if(err != KErrNone) |
179 { |
192 { |
202 switch(aTransferId) |
215 switch(aTransferId) |
203 { |
216 { |
204 case KBulkTransferInId0: |
217 case KBulkTransferInId0: |
205 case KBulkTransferInId1: |
218 case KBulkTransferInId1: |
206 iTransferComplete |= aTransferId; |
219 iTransferComplete |= aTransferId; |
207 RDebug::Printf("Transfer %d completed", aTransferId); |
220 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_TRANSFERCOMPLETEL_DUP03, "Transfer %d completed", aTransferId); |
208 break; //switch(aTransferId) |
221 break; //switch(aTransferId) |
209 |
222 |
210 default: |
223 default: |
211 iTransferComplete = 0; //reset |
224 iTransferComplete = 0; //reset |
212 err = KUnexpectedTransferID; |
225 err = KUnexpectedTransferID; |
257 msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err); |
270 msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err); |
258 } |
271 } |
259 |
272 |
260 if(err!=KErrNone) |
273 if(err!=KErrNone) |
261 { |
274 { |
262 RDebug::Print(msg); |
275 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_TRANSFERCOMPLETEL_DUP05, msg); |
263 iCaseStep = EFailed; |
276 iCaseStep = EFailed; |
264 TTestCaseFailed request(err,msg); |
277 TTestCaseFailed request(err,msg); |
265 return iControlEp0->SendRequest(request,this); |
278 return iControlEp0->SendRequest(request,this); |
266 } |
279 } |
|
280 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0500_TRANSFERCOMPLETEL_EXIT, this ); |
267 } |
281 } |
268 |
282 |
269 void CUT_PBASE_T_USBDI_0500::DeviceInsertedL(TUint aDeviceHandle) |
283 void CUT_PBASE_T_USBDI_0500::DeviceInsertedL(TUint aDeviceHandle) |
270 { |
284 { |
271 LOG_FUNC |
285 OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0500_DEVICEINSERTEDL_ENTRY, this ); |
272 |
286 |
273 Cancel(); |
287 Cancel(); |
274 RDebug::Printf("this - %08x", this); |
288 OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_DEVICEINSERTEDL, "this - %08x", this); |
275 |
289 |
276 TBuf<256> msg; |
290 TBuf<256> msg; |
277 TInt err = KErrNone; |
291 TInt err = KErrNone; |
278 if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError) |
292 if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError) |
279 // Prepare for response from control transfer to client |
293 // Prepare for response from control transfer to client |
285 { |
299 { |
286 iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId0); |
300 iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId0); |
287 iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId1); |
301 iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId1); |
288 |
302 |
289 // Initialise the descriptors for transfer |
303 // Initialise the descriptors for transfer |
290 RDebug::Printf("Initialising the transfer descriptors"); |
304 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_DEVICEINSERTEDL_DUP01, "Initialising the transfer descriptors"); |
291 err = iUsbInterface1.InitialiseTransferDescriptors(); |
305 err = iUsbInterface1.InitialiseTransferDescriptors(); |
292 if(err != KErrNone) |
306 if(err != KErrNone) |
293 { |
307 { |
294 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err); |
308 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err); |
295 } |
309 } |
296 } |
310 } |
297 if(err != KErrNone) |
311 if(err != KErrNone) |
298 { |
312 { |
299 RDebug::Print(msg); |
313 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_DEVICEINSERTEDL_DUP02, msg); |
300 iCaseStep = EFailed; |
314 iCaseStep = EFailed; |
301 TTestCaseFailed request(err,msg); |
315 TTestCaseFailed request(err,msg); |
302 iControlEp0->SendRequest(request,this); |
316 iControlEp0->SendRequest(request,this); |
303 } |
317 } |
304 else |
318 else |
305 { |
319 { |
306 RDebug::Printf("Asking client for 'Write' and 'Halt'"); |
320 OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0500_DEVICEINSERTEDL_DUP03, "Asking client for 'Write' and 'Halt'"); |
307 iCaseStep = ETransferInHalt; |
321 iCaseStep = ETransferInHalt; |
308 TEndpointPatternSynchronousWriteAndHaltRequest request(1,1,KLiteralFrench4(),KDeviceNumWriteBytesPreHalt);// EP1 means endpoint index 1 not the actual endpoint number |
322 TEndpointPatternSynchronousWriteAndHaltRequest request(1,1,KLiteralFrench4(),KDeviceNumWriteBytesPreHalt);// EP1 means endpoint index 1 not the actual endpoint number |
309 iControlEp0->SendRequest(request,this); |
323 iControlEp0->SendRequest(request,this); |
310 } |
324 } |
|
325 OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0500_DEVICEINSERTEDL_EXIT, this ); |
311 } |
326 } |
312 |
327 |
313 } //end namespace |
328 } //end namespace |