|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // @file PBASE-T_USBDI-0492.cpp |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 #include "PBASE-T_USBDI-0492.h" |
|
20 #include "testpolicy.h" |
|
21 #include "modelleddevices.h" |
|
22 #include "testliterals.h" |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 namespace NUnitTesting_USBDI |
|
28 { |
|
29 const TInt KBulkTransferSize = 583; |
|
30 const TUint KHostNumWriteBytes1 = 210; |
|
31 const TUint KHostNumWriteBytes2 = 350; |
|
32 const TUint KHostNumWriteBytes3 = KBulkTransferSize - KHostNumWriteBytes1 - KHostNumWriteBytes2; // 23 |
|
33 const TUint KHostNumReadBytes1 = 301; |
|
34 const TUint KHostNumReadBytes2 = 21; |
|
35 const TUint KHostNumReadBytes3 = KBulkTransferSize - KHostNumReadBytes1 - KHostNumReadBytes2; // 261 |
|
36 |
|
37 |
|
38 //Make these single bit values ... |
|
39 // ... so that their completion can be easily recorded in a bit mask! |
|
40 const TInt KBulkTransferInId0 = 1<<0; |
|
41 const TInt KBulkTransferInId1 = 1<<1; |
|
42 const TInt KBulkTransferInId2 = 1<<2; |
|
43 const TInt KBulkTransferOutId0 = 1<<3; |
|
44 const TInt KBulkTransferOutId1 = 1<<4; |
|
45 const TInt KBulkTransferOutId2 = 1<<5; |
|
46 |
|
47 const TInt KUnexpectedTransferID = -101; |
|
48 const TInt KUndefinedStep = -102; |
|
49 |
|
50 |
|
51 _LIT(KTestCaseId,"PBASE-T_USBDI-0492"); |
|
52 const TFunctorTestCase<CUT_PBASE_T_USBDI_0492,TBool> CUT_PBASE_T_USBDI_0492::iFunctor(KTestCaseId); |
|
53 |
|
54 CUT_PBASE_T_USBDI_0492* CUT_PBASE_T_USBDI_0492::NewL(TBool aHostRole) |
|
55 { |
|
56 CUT_PBASE_T_USBDI_0492* self = new (ELeave) CUT_PBASE_T_USBDI_0492(aHostRole); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop(self); |
|
60 return self; |
|
61 } |
|
62 |
|
63 |
|
64 CUT_PBASE_T_USBDI_0492::CUT_PBASE_T_USBDI_0492(TBool aHostRole) |
|
65 : CBaseBulkTestCase(KTestCaseId,aHostRole), |
|
66 iCaseStep(EInProgress) |
|
67 { |
|
68 } |
|
69 |
|
70 |
|
71 void CUT_PBASE_T_USBDI_0492::ConstructL() |
|
72 { |
|
73 BaseBulkConstructL(); |
|
74 } |
|
75 |
|
76 |
|
77 CUT_PBASE_T_USBDI_0492::~CUT_PBASE_T_USBDI_0492() |
|
78 { |
|
79 LOG_FUNC |
|
80 } |
|
81 |
|
82 |
|
83 void CUT_PBASE_T_USBDI_0492::Ep0TransferCompleteL(TInt aCompletionCode) |
|
84 { |
|
85 LOG_FUNC |
|
86 |
|
87 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode); |
|
88 |
|
89 if(aCompletionCode != KErrNone) |
|
90 { |
|
91 if(iCaseStep == EFailed) |
|
92 {// ignore error, nad catch the TestFailed method called further down. |
|
93 RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***"); |
|
94 } |
|
95 else |
|
96 { |
|
97 TBuf<256> msg; |
|
98 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode); |
|
99 RDebug::Print(msg); |
|
100 iCaseStep = EFailed; |
|
101 TTestCaseFailed request(aCompletionCode,msg); |
|
102 iControlEp0->SendRequest(request,this); |
|
103 return; |
|
104 } |
|
105 } |
|
106 |
|
107 switch(iCaseStep) |
|
108 { |
|
109 // Test case passed |
|
110 case EPassed: |
|
111 TestPassed(); |
|
112 break; |
|
113 |
|
114 // Test case failed |
|
115 case EFailed: |
|
116 TestFailed(KErrCompletion); |
|
117 break; |
|
118 |
|
119 case ETransferOut: |
|
120 RDebug::Printf("Try to send data"); |
|
121 iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0, KHostNumWriteBytes1), EFalse); |
|
122 iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytes1, KHostNumWriteBytes2), EFalse); |
|
123 iOutTransfer[2]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytes1+KHostNumWriteBytes2, KHostNumWriteBytes3), ETrue); //do not suppress ZLP on this last one (though should be irrelevant here) |
|
124 break; |
|
125 |
|
126 case ETransferIn: |
|
127 RDebug::Printf("Try to receive data"); |
|
128 iInTransfer[0]->TransferIn(KHostNumReadBytes1); |
|
129 iInTransfer[1]->TransferIn(KHostNumReadBytes2); |
|
130 iInTransfer[2]->TransferIn(KHostNumReadBytes3); |
|
131 break; |
|
132 |
|
133 default: |
|
134 RDebug::Printf("<Error> Unknown test step"); |
|
135 TestFailed(KErrUnknown); |
|
136 break; |
|
137 } |
|
138 } |
|
139 |
|
140 void CUT_PBASE_T_USBDI_0492::TransferCompleteL(TInt aTransferId,TInt aCompletionCode) |
|
141 { |
|
142 LOG_FUNC |
|
143 Cancel(); |
|
144 |
|
145 TInt err(KErrNone); |
|
146 TBuf<256> msg; |
|
147 RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode); |
|
148 |
|
149 switch(iCaseStep) |
|
150 { |
|
151 case ETransferOut: |
|
152 if(aCompletionCode != KErrNone) |
|
153 { |
|
154 err = KErrCorrupt; |
|
155 msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode); |
|
156 break; // switch(iCaseStep) |
|
157 } |
|
158 |
|
159 switch(aTransferId) |
|
160 { |
|
161 case KBulkTransferOutId0: |
|
162 case KBulkTransferOutId1: |
|
163 case KBulkTransferOutId2: |
|
164 iTransferComplete |= aTransferId; |
|
165 RDebug::Printf("Transfer %d completed", aTransferId); |
|
166 break; // switch(aTransferId) |
|
167 |
|
168 default: |
|
169 iTransferComplete = 0; //reset |
|
170 err = KUnexpectedTransferID; |
|
171 msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d, %d or %d, got %d"), |
|
172 err, KBulkTransferOutId0, KBulkTransferOutId1, KBulkTransferOutId2, aTransferId); |
|
173 break; // switch(aTransferId) |
|
174 } |
|
175 |
|
176 if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1 | KBulkTransferOutId2)) |
|
177 { |
|
178 RDebug::Printf("Try to receive back sent data. Transfers Completed %d", iTransferComplete); |
|
179 iCaseStep = ETransferIn; |
|
180 TUint numBytes[KNumSplitWriteSections] = {KHostNumReadBytes1, KHostNumReadBytes2, KHostNumReadBytes3}; |
|
181 TSplitWriteCachedReadDataRequest request(1,1,1,numBytes); |
|
182 iControlEp0->SendRequest(request,this); |
|
183 iTransferComplete = 0; //reset |
|
184 } |
|
185 break; // switch(iCaseStep) |
|
186 |
|
187 case ETransferIn: |
|
188 if(aCompletionCode != KErrNone) |
|
189 { |
|
190 err = KErrCorrupt; |
|
191 msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode); |
|
192 break; // switch(iCaseStep) |
|
193 } |
|
194 |
|
195 switch(aTransferId) |
|
196 { |
|
197 case KBulkTransferInId0: |
|
198 case KBulkTransferInId1: |
|
199 case KBulkTransferInId2: |
|
200 iTransferComplete |= aTransferId; |
|
201 break; // switch(aTransferId) |
|
202 |
|
203 default: |
|
204 iTransferComplete = 0; //reset |
|
205 err = KUnexpectedTransferID; |
|
206 msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d, %d or %d, got %d"), |
|
207 err, KBulkTransferInId0, KBulkTransferInId1, KBulkTransferInId2, aTransferId); |
|
208 break; // switch(aTransferId) |
|
209 } |
|
210 |
|
211 if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1 | KBulkTransferInId2)) |
|
212 { |
|
213 // compare data rcvd now |
|
214 TPtrC8 data1(iInTransfer[0]->DataPolled()); |
|
215 TPtrC8 data2(iInTransfer[1]->DataPolled()); |
|
216 TPtrC8 data3(iInTransfer[2]->DataPolled()); |
|
217 if(ValidateData(data1, KLiteralEnglish8().Mid(0, KHostNumReadBytes1)) == EFalse) |
|
218 { |
|
219 err = KErrCompletion; //indicates data validation failure |
|
220 break; // switch(iCaseStep) |
|
221 } |
|
222 |
|
223 if(ValidateData(data2, KLiteralEnglish8().Mid(KHostNumReadBytes1, KHostNumReadBytes2)) == EFalse) |
|
224 { |
|
225 err = KErrCompletion; //indicates data validation failure |
|
226 break; // switch(iCaseStep) |
|
227 } |
|
228 |
|
229 if(ValidateData(data3, KLiteralEnglish8().Mid(KHostNumReadBytes1+KHostNumReadBytes2, KHostNumReadBytes3)) == EFalse) |
|
230 { |
|
231 err = KErrCompletion; //indicates data validation failure |
|
232 break; // switch(iCaseStep) |
|
233 } |
|
234 |
|
235 // Comparison is a match |
|
236 RDebug::Printf("Comparison for IN transfer is a match"); |
|
237 iCaseStep = EPassed; |
|
238 TTestCasePassed request; |
|
239 iControlEp0->SendRequest(request,this); |
|
240 iTransferComplete = 0; //reset |
|
241 } |
|
242 break; // switch(iCaseStep) |
|
243 |
|
244 default: |
|
245 err = KUndefinedStep; |
|
246 msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep); |
|
247 break; // switch(iCaseStep) |
|
248 } |
|
249 |
|
250 if(err == KErrCompletion) |
|
251 { |
|
252 //indicates data validation failure |
|
253 msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err); |
|
254 } |
|
255 |
|
256 if(err!=KErrNone) |
|
257 { |
|
258 RDebug::Print(msg); |
|
259 iCaseStep = EFailed; |
|
260 TTestCaseFailed request(err,msg); |
|
261 iControlEp0->SendRequest(request,this); |
|
262 } |
|
263 } |
|
264 |
|
265 void CUT_PBASE_T_USBDI_0492::DeviceInsertedL(TUint aDeviceHandle) |
|
266 { |
|
267 LOG_FUNC |
|
268 |
|
269 Cancel(); |
|
270 |
|
271 if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError) |
|
272 // Prepare for response from control transfer to client |
|
273 { |
|
274 iCaseStep = EFailed; |
|
275 } |
|
276 |
|
277 // Create the bulk transfers |
|
278 iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId0); |
|
279 iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId1); |
|
280 iInTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId2); |
|
281 iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId0); |
|
282 iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId1); |
|
283 iOutTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId2); |
|
284 |
|
285 // Initialise the descriptors for transfer |
|
286 RDebug::Printf("Initialising the transfer descriptors"); |
|
287 TInt err = iUsbInterface1.InitialiseTransferDescriptors(); |
|
288 if(err != KErrNone) |
|
289 { |
|
290 TBuf<256> msg; |
|
291 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err); |
|
292 RDebug::Print(msg); |
|
293 iCaseStep = EFailed; |
|
294 TTestCaseFailed request(err,msg); |
|
295 iControlEp0->SendRequest(request,this); |
|
296 return; |
|
297 } |
|
298 |
|
299 iCaseStep = ETransferOut; |
|
300 TEndpointReadRequest request(1,1,KBulkTransferSize);// EP1 means endpoint index 1 not the actual endpoint number |
|
301 iControlEp0->SendRequest(request,this); |
|
302 } |
|
303 |
|
304 } //end namespace |