Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // @file PBASE-T_USBDI-0493.cpp
19 #include "PBASE-T_USBDI-0493.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
22 #include "testliterals.h"
27 namespace NUnitTesting_USBDI
29 const TInt KLiteralEnglish8Length = KLiteralEnglish8().Length();
30 const TUint KBulkTransferMaxSize = 320;
31 const TUint KHostNumWriteBytes = 256;
32 const TUint KHostNumReadBytes = 256;
33 const TUint KHostFinalNumReadBytes = 300;
35 const TUint KStartNumTransferBytes = 1023;
36 const TUint KFinishNumTransferBytes = 1025;
38 const TUint KClientNumReadBytes = 2000;
40 //Make these single bit values ...
41 // ... so that their completion can be easily recorded in a bit mask!
42 const TInt KBulkTransferInId0 = 1<<0;
43 const TInt KBulkTransferInId1 = 1<<1;
44 const TInt KBulkTransferInId2 = 1<<2;
45 const TInt KBulkTransferInId3 = 1<<3;
46 const TInt KBulkTransferOutId0 = 1<<4;
47 const TInt KBulkTransferOutId1 = 1<<5;
48 const TInt KBulkTransferOutId2 = 1<<6;
49 const TInt KBulkTransferOutId3 = 1<<7;
51 const TInt KUnexpectedTransferID = -101;
52 const TInt KUndefinedStep = -102;
55 _LIT(KTestCaseId,"PBASE-T_USBDI-0493");
56 const TFunctorTestCase<CUT_PBASE_T_USBDI_0493,TBool> CUT_PBASE_T_USBDI_0493::iFunctor(KTestCaseId);
58 CUT_PBASE_T_USBDI_0493* CUT_PBASE_T_USBDI_0493::NewL(TBool aHostRole)
60 CUT_PBASE_T_USBDI_0493* self = new (ELeave) CUT_PBASE_T_USBDI_0493(aHostRole);
61 CleanupStack::PushL(self);
63 CleanupStack::Pop(self);
68 CUT_PBASE_T_USBDI_0493::CUT_PBASE_T_USBDI_0493(TBool aHostRole)
69 : CBaseBulkTestCase(KTestCaseId,aHostRole),
70 iNumTransferBytes(KStartNumTransferBytes),
71 iCaseStep(EInProgress)
76 void CUT_PBASE_T_USBDI_0493::ConstructL()
82 CUT_PBASE_T_USBDI_0493::~CUT_PBASE_T_USBDI_0493()
87 void CUT_PBASE_T_USBDI_0493::Ep0TransferCompleteL(TInt aCompletionCode)
91 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
93 if(aCompletionCode != KErrNone)
95 if(iCaseStep == EFailed)
96 {// todo, cope with errors
101 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
104 TTestCaseFailed request(aCompletionCode,msg);
105 iControlEp0->SendRequest(request,this);
119 TestFailed(KErrCompletion);
123 RDebug::Printf("Try to send %d bytes of data", iNumTransferBytes);
124 RDebug::RawPrint(KLiteralEnglish8().Mid(0*KHostNumWriteBytes, KHostNumWriteBytes));
125 iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
126 iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(1*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
127 iOutTransfer[2]->TransferOut(KLiteralEnglish8().Mid(2*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
128 iOutTransfer[3]->TransferOut(KLiteralEnglish8().Mid(3*KHostNumWriteBytes, iNumTransferBytes - 3*KHostNumWriteBytes), ETrue);
132 RDebug::Printf("Try to receive max %d bytes of data", 3*KHostNumReadBytes + KHostFinalNumReadBytes);
133 iInTransfer[0]->TransferIn(KHostNumReadBytes);
134 iInTransfer[1]->TransferIn(KHostNumReadBytes);
135 iInTransfer[2]->TransferIn(KHostNumReadBytes);
136 iInTransfer[3]->TransferIn(KHostFinalNumReadBytes);
140 RDebug::Printf("<Error> Unknown test step");
141 TestFailed(KErrUnknown);
146 void CUT_PBASE_T_USBDI_0493::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
153 RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
158 if(aCompletionCode != KErrNone)
161 msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode);
162 break; //switch(iCaseStep)
167 case KBulkTransferOutId0:
168 case KBulkTransferOutId1:
169 case KBulkTransferOutId2:
170 case KBulkTransferOutId3:
171 iTransferComplete |= aTransferId;
172 RDebug::Printf("Transfer %d completed", aTransferId);
173 break; //switch(aTransferId)
176 iTransferComplete = 0; //reset
177 err = KUnexpectedTransferID;
178 msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d or %d or %d, got %d"),
179 err, KBulkTransferOutId0, KBulkTransferOutId1, KBulkTransferOutId2, KBulkTransferOutId3, aTransferId);
180 break; //switch(aTransferId)
183 if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1 | KBulkTransferOutId2 | KBulkTransferOutId3))
185 RDebug::Printf("Try to receive back sent data. Transfers Completed %d", iTransferComplete);
186 iCaseStep = ETransferIn;
187 TWriteSynchronousCachedReadDataRequest request(1,1,1); //Use first read EP and first write EP (on interface 1)
188 iControlEp0->SendRequest(request,this);
189 iTransferComplete = 0; //reset
191 break; //switch(iCaseStep)
194 if(aCompletionCode != KErrNone)
197 msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
198 break; //switch(iCaseStep)
202 case KBulkTransferInId0:
203 case KBulkTransferInId1:
204 case KBulkTransferInId2:
205 case KBulkTransferInId3:
206 iTransferComplete |= aTransferId;
207 break; //switch(aTransferId)
210 RDebug::Printf("Bad Transfer ID");
211 iTransferComplete = 0; //reset
212 err = KUnexpectedTransferID;
213 msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d or %d or %d, got %d"),
214 err, KBulkTransferInId0, KBulkTransferInId1, KBulkTransferInId2, KBulkTransferInId3, aTransferId);
215 break; //switch(aTransferId)
218 if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1 | KBulkTransferInId2 | KBulkTransferInId3))
220 // compare data rcvd now
221 TPtrC8 data1(iInTransfer[0]->DataPolled());
222 TPtrC8 data2(iInTransfer[1]->DataPolled());
223 TPtrC8 data3(iInTransfer[2]->DataPolled());
224 TPtrC8 data4(iInTransfer[3]->DataPolled());
225 if(ValidateData(data1, KLiteralEnglish8().Mid(0*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
227 err = KErrCompletion; //indicates data validation failure
228 break; //switch(iCaseStep)
231 if(ValidateData(data2, KLiteralEnglish8().Mid(1*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
233 err = KErrCompletion; //indicates data validation failure
234 break; //switch(iCaseStep)
237 if(ValidateData(data3, KLiteralEnglish8().Mid(2*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
239 err = KErrCompletion; //indicates data validation failure
240 break; //switch(iCaseStep)
243 if(ValidateData(data4, KLiteralEnglish8().Mid(3*KHostNumReadBytes, iNumTransferBytes - 3*KHostNumReadBytes)) == EFalse)
245 err = KErrCompletion; //indicates data validation failure
246 break; //switch(iCaseStep)
251 // Comparison is a match
252 RDebug::Printf("Comparison for IN transfer is a match - Number of Transfer Bytes %d", iNumTransferBytes);
253 iTransferComplete = 0; //reset
254 if(++iNumTransferBytes<=KFinishNumTransferBytes)
256 Loop round again having added one to
257 the number of transfer bytes to be used.
258 In this test there should be three repeats of the underlying
259 "Transfer Out followed by Transfer In" test.
261 KStartNumTransferBytes,
262 KStartNumTransferBytes+1,
264 KFinishNumTransferBytes.
267 iCaseStep = ETransferOut;
268 TEndpointReadUntilShortRequest request(1,1,KClientNumReadBytes);// EP1 because 1st reader EP
269 iControlEp0->SendRequest(request,this);
270 break; //switch(iCaseStep)
273 TTestCasePassed request;
274 iControlEp0->SendRequest(request,this);
277 break; //switch(iCaseStep)
280 err = KUndefinedStep;
281 msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
282 break; //switch(iCaseStep)
289 TTestCaseFailed request(err,msg);
290 iControlEp0->SendRequest(request,this);
296 void CUT_PBASE_T_USBDI_0493::DeviceInsertedL(TUint aDeviceHandle)
300 RDebug::Printf("****** Father William Pattern Length is %d bytes! *********", KLiteralEnglish8Length);
301 if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
302 // Prepare for response from control transfer to client
307 // Create the bulk transfers
308 RDebug::Printf("Trying to create the bulk transfers - size 0x%u", KBulkTransferMaxSize);
309 iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId0);
310 iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId1);
311 iInTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId2);
312 iInTransfer[3] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId3);
313 iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId0);
314 iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId1);
315 iOutTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId2);
316 iOutTransfer[3] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId3);
318 // Initialise the descriptors for transfer
319 RDebug::Printf("Initialising the transfer descriptors");
320 TInt err = iUsbInterface1.InitialiseTransferDescriptors();
324 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
327 TTestCaseFailed request(err,msg);
328 iControlEp0->SendRequest(request,this);
332 RDebug::Printf("Ask client to read %d bytes of data", KClientNumReadBytes);
333 iCaseStep = ETransferOut;
334 TEndpointReadUntilShortRequest request(1,1,KClientNumReadBytes);// EP1 because 1st reader EP
335 iControlEp0->SendRequest(request,this);