First public contribution.
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-0499.cpp
19 #include "PBASE-T_USBDI-0499.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
22 #include "testliterals.h"
27 namespace NUnitTesting_USBDI
29 const TInt KBulkMaxINTransferSize = 1200;
30 const TInt KBulkMaxOUTTransferSize = 150000;
31 const TUint KHostNumWriteBytesPreHalt1 = 128000;
32 const TUint KHostNumWriteBytesPreHalt2 = 128000;
33 const TUint KHostNumWriteBytesPostHalt1 = 512;
34 const TUint KHostNumWriteBytesPostHalt2 = 512;
35 const TInt KDeviceNumWrittenBytesPreHalt = KHostNumWriteBytesPreHalt1+KHostNumWriteBytesPreHalt2;
36 const TInt KDeviceNumReadBytesPostHalt = KHostNumWriteBytesPostHalt1+KHostNumWriteBytesPostHalt2;
37 const TInt KDeviceNumReadBytesPreHalt = 128;
38 const TInt KHostNumReadBytesPostHalt = KDeviceNumReadBytesPostHalt+1; //read cached data, allow 1 for ZLP
41 //Make these single bit values ...
42 // ... so that their completion can be easily recorded in a bit mask!
43 const TInt KBulkTransferInId0 = 1<<0;
44 const TInt KBulkTransferOutId0 = 1<<3;
45 const TInt KBulkTransferOutId1 = 1<<4;
47 const TInt KUnexpectedTransferID = -101;
48 const TInt KUndefinedStep = -102;
51 _LIT(KTestCaseId,"PBASE-T_USBDI-0499");
52 const TFunctorTestCase<CUT_PBASE_T_USBDI_0499,TBool> CUT_PBASE_T_USBDI_0499::iFunctor(KTestCaseId);
54 CUT_PBASE_T_USBDI_0499* CUT_PBASE_T_USBDI_0499::NewL(TBool aHostRole)
56 CUT_PBASE_T_USBDI_0499* self = new (ELeave) CUT_PBASE_T_USBDI_0499(aHostRole);
57 CleanupStack::PushL(self);
59 CleanupStack::Pop(self);
64 CUT_PBASE_T_USBDI_0499::CUT_PBASE_T_USBDI_0499(TBool aHostRole)
65 : CBaseBulkTestCase(KTestCaseId,aHostRole),
66 iCaseStep(EInProgress)
71 void CUT_PBASE_T_USBDI_0499::ConstructL()
77 CUT_PBASE_T_USBDI_0499::~CUT_PBASE_T_USBDI_0499()
83 void CUT_PBASE_T_USBDI_0499::Ep0TransferCompleteL(TInt aCompletionCode)
87 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
89 if(aCompletionCode != KErrNone)
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***");
98 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
101 TTestCaseFailed request(aCompletionCode,msg);
102 iControlEp0->SendRequest(request,this);
116 TestFailed(KErrCompletion);
119 case ETransferOutHalt:
120 iOutTransfer[0]->TransferOut(KLiteralFrench4(), KHostNumWriteBytesPreHalt1, EFalse);
121 iOutTransfer[1]->TransferOut(KLiteralFrench4(), KHostNumWriteBytesPreHalt2, EFalse);
124 case EAwaitClearPreHalt:
126 RDebug::Printf("Client has been asked to clear endpoint buffer");
127 User::After(1000000); //Give client time to clear buffer
128 TEndpointCancelReadRequest request(1,1);
129 iControlEp0->SendRequest(request,this);
130 iCaseStep = EAwaitCancelRead;
134 case EAwaitCancelRead:
136 TEndpointReadRequest request(1,1, KDeviceNumReadBytesPostHalt);// EP1 because 1st writter EP
137 iControlEp0->SendRequest(request,this);
138 iCaseStep = ETransferOut;
143 RDebug::Printf("Try to send data (post halt)");
144 iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0, KHostNumWriteBytesPostHalt1), EFalse);
145 iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytesPostHalt1, KHostNumWriteBytesPostHalt2), EFalse);
149 RDebug::Printf("Try to receive data");
150 iInTransfer[0]->TransferIn(KHostNumReadBytesPostHalt);
154 RDebug::Printf("<Error> Unknown test step");
155 TestFailed(KErrUnknown);
160 void CUT_PBASE_T_USBDI_0499::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
167 RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
171 case ETransferOutHalt:
173 if(aCompletionCode != KErrUsbStalled)
175 iOutTransfer[0]->Cancel();
176 iOutTransfer[1]->Cancel();
178 msg.Format(_L("<Error %d> The transfer completed with no errors but the endpoint should have halted"),aCompletionCode);
179 break; //switch(iCaseStep)
184 case KBulkTransferOutId0:
185 case KBulkTransferOutId1:
186 iTransferComplete |= aTransferId;
187 RDebug::Printf("Transfer %d stalled", aTransferId);
188 break; //switch(aTransferId)
191 iTransferComplete = 0; //reset
192 err = KUnexpectedTransferID;
193 msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d, got %d"),
194 err, KBulkTransferOutId0, KBulkTransferOutId1, aTransferId);
195 break; //switch(aTransferId)
198 if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1))
200 RDebug::Printf("Clear halt and try to send data again. Transfers Completed %d", iTransferComplete);
201 // Acknowledge the stall and clear
202 err = iTestPipeInterface1BulkOut.ClearRemoteStall();
205 msg.Format(_L("<Error %d> The remote stall cannot be cleared"),err);
206 break; //switch(iCaseStep)
208 iCaseStep = EAwaitClearPreHalt;
209 TEndpointReadRequest request(1,1, KDeviceNumWrittenBytesPreHalt);// EP1 because 1st writter EP
210 iControlEp0->SendRequest(request,this);
211 iTransferComplete = 0; //reset
214 break; //switch(iCaseStep)
218 if(aCompletionCode != KErrNone)
220 iOutTransfer[0]->Cancel();
221 iOutTransfer[1]->Cancel();
223 msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode);
224 break; //switch(iCaseStep)
229 case KBulkTransferOutId0:
230 case KBulkTransferOutId1:
231 iTransferComplete |= aTransferId;
232 RDebug::Printf("Transfer %d completed", aTransferId);
233 break; //switch(aTransferId)
236 iTransferComplete = 0; //reset
237 err = KUnexpectedTransferID;
238 msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d, got %d"),
239 err, KBulkTransferOutId0, KBulkTransferOutId1, aTransferId);
240 break; //switch(aTransferId)
243 if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1))
245 RDebug::Printf("Try to receive back sent data. Transfers Completed %d", iTransferComplete);
246 iCaseStep = ETransferIn;
247 TWriteSynchronousCachedReadDataRequest request(1,1,1);
248 iControlEp0->SendRequest(request,this);
249 iTransferComplete = 0; //reset
251 break; //switch(iCaseStep)
254 if(aCompletionCode != KErrNone)
257 msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
258 break; //switch(iCaseStep)
261 if(aTransferId != KBulkTransferInId0)
263 iTransferComplete = 0; //reset
264 err = KUnexpectedTransferID;
265 msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d , got %d"),
266 err, KBulkTransferInId0, aTransferId);
267 break; //switch(iCaseStep)
270 // else ok, compare data rcvd now
271 TPtrC8 data1(iInTransfer[0]->DataPolled());
272 if(ValidateData(data1, KLiteralEnglish8().Mid(0, KDeviceNumReadBytesPostHalt)) == EFalse)
274 err = KErrCompletion; //indicates data validation failure
275 msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
276 break; //switch(iCaseStep)
279 // Comparison is a match
280 RDebug::Printf("Comparison for IN transfer is a match");
282 TTestCasePassed request;
283 iControlEp0->SendRequest(request,this);
284 iTransferComplete = 0; //reset
286 break; //switch(iCaseStep)
289 err = KUndefinedStep;
290 msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
291 break; //switch(iCaseStep)
294 if(err == KErrCompletion)
295 //indicates data validation failure
297 msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
304 TTestCaseFailed request(err,msg);
305 return iControlEp0->SendRequest(request,this);
309 void CUT_PBASE_T_USBDI_0499::DeviceInsertedL(TUint aDeviceHandle)
315 if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
316 // Prepare for response from control transfer to client
321 // Create the bulk transfers
322 iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId0);
323 iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxOUTTransferSize,*this,KBulkTransferOutId0);
324 iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxOUTTransferSize,*this,KBulkTransferOutId1);
326 // Initialise the descriptors for transfer
327 RDebug::Printf("Initialising the transfer descriptors");
328 TInt err = iUsbInterface1.InitialiseTransferDescriptors();
332 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
335 TTestCaseFailed request(err,msg);
336 iControlEp0->SendRequest(request,this);
340 iCaseStep = ETransferOutHalt;
341 TEndpointReadAndHaltRequest request(1,1,KDeviceNumReadBytesPreHalt);// EP1 means endpoint index 1 not the actual endpoint number
342 iControlEp0->SendRequest(request,this);