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-0500.cpp
19 #include "PBASE-T_USBDI-0500.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
22 #include "testliterals.h"
27 namespace NUnitTesting_USBDI
29 const TInt KBulkMaxINTransferSize = 600;
30 const TInt KDeviceNumWriteBytesPreHalt = 256;
31 const TUint KHostNumReadBytesPreHalt1 = 512;
32 const TUint KHostNumReadBytesPreHalt2 = 512;
33 const TUint KHostNumReadBytesPostHalt1 = 256;
34 const TUint KHostNumReadBytesPostHalt2 = 257;
35 const TInt KDeviceNumWriteBytesPostHalt = 512;
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<<4;
43 const TInt KUnexpectedTransferID = -101;
44 const TInt KUndefinedStep = -102;
47 _LIT(KTestCaseId,"PBASE-T_USBDI-0500");
48 const TFunctorTestCase<CUT_PBASE_T_USBDI_0500,TBool> CUT_PBASE_T_USBDI_0500::iFunctor(KTestCaseId);
50 CUT_PBASE_T_USBDI_0500* CUT_PBASE_T_USBDI_0500::NewL(TBool aHostRole)
52 CUT_PBASE_T_USBDI_0500* self = new (ELeave) CUT_PBASE_T_USBDI_0500(aHostRole);
53 CleanupStack::PushL(self);
55 CleanupStack::Pop(self);
60 CUT_PBASE_T_USBDI_0500::CUT_PBASE_T_USBDI_0500(TBool aHostRole)
61 : CBaseBulkTestCase(KTestCaseId,aHostRole),
62 iCaseStep(EInProgress)
67 void CUT_PBASE_T_USBDI_0500::ConstructL()
73 CUT_PBASE_T_USBDI_0500::~CUT_PBASE_T_USBDI_0500()
79 void CUT_PBASE_T_USBDI_0500::Ep0TransferCompleteL(TInt aCompletionCode)
83 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
85 if(aCompletionCode != KErrNone)
87 if(iCaseStep == EFailed)
88 {// ignore error, nad catch the TestFailed method called further down.
89 RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
94 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
97 TTestCaseFailed request(aCompletionCode,msg);
98 iControlEp0->SendRequest(request,this);
112 TestFailed(KErrCompletion);
115 case ETransferInHalt:
116 RDebug::Printf("Try to receive data (pre halt)");
117 iInTransfer[0]->TransferIn(KHostNumReadBytesPreHalt1);
118 iInTransfer[1]->TransferIn(KHostNumReadBytesPreHalt2);
122 RDebug::Printf("Try to receive data");
123 iInTransfer[0]->TransferIn(KHostNumReadBytesPostHalt1);
124 iInTransfer[1]->TransferIn(KHostNumReadBytesPostHalt2);
128 RDebug::Printf("<Error> Unknown test step");
129 TestFailed(KErrUnknown);
134 void CUT_PBASE_T_USBDI_0500::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
141 RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
145 case ETransferInHalt:
147 if(aCompletionCode != KErrUsbStalled)
149 iInTransfer[0]->Cancel();
150 iInTransfer[1]->Cancel();
152 msg.Format(_L("<Error %d> The transfer completed with no errors but the endpoint should have halted"),aCompletionCode);
153 break; //switch(iCaseStep)
158 case KBulkTransferInId0:
159 case KBulkTransferInId1:
160 iTransferComplete |= aTransferId;
161 RDebug::Printf("Transfer %d completed", aTransferId);
162 break; //switch(aTransferId)
165 iTransferComplete = 0; //reset
166 err = KUnexpectedTransferID;
167 msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d, got %d"),
168 err, KBulkTransferInId0, KBulkTransferInId1, aTransferId);
169 break; //switch(aTransferId)
172 if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1))
174 RDebug::Printf("Clear halt and try to send data again. Transfers Completed %d", iTransferComplete);
175 iTransferComplete = 0; //reset
176 // Acknowledge the stall and clear
177 err = iTestPipeInterface1BulkIn.ClearRemoteStall();
180 msg.Format(_L("<Error %d> The remote stall cannot be cleared"),err);
181 break; //switch(iCaseStep)
183 iCaseStep = ETransferIn;
184 TEndpointPatternSynchronousWriteRequest request(1,1, KLiteralEnglish8().Mid(0,KDeviceNumWriteBytesPostHalt), KDeviceNumWriteBytesPostHalt);// EP1 because 1st writter EP
185 iControlEp0->SendRequest(request,this);
188 break; //switch(iCaseStep)
192 if(aCompletionCode != KErrNone)
194 iInTransfer[0]->Cancel();
195 iInTransfer[1]->Cancel();
198 msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
199 break; //switch(iCaseStep)
204 case KBulkTransferInId0:
205 case KBulkTransferInId1:
206 iTransferComplete |= aTransferId;
207 RDebug::Printf("Transfer %d completed", aTransferId);
208 break; //switch(aTransferId)
211 iTransferComplete = 0; //reset
212 err = KUnexpectedTransferID;
213 msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d, got %d"),
214 err, KBulkTransferInId0, KBulkTransferInId1, aTransferId);
215 break; //switch(aTransferId)
218 if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1))
220 // ok, compare data rcvd now
221 iTransferComplete = 0; //reset
222 TPtrC8 data1(iInTransfer[0]->DataPolled());
223 TPtrC8 data2(iInTransfer[1]->DataPolled());
224 //Validate first transfer for number of bytes requested.
225 if(ValidateData(data1, KLiteralEnglish8(), KHostNumReadBytesPostHalt1) == EFalse)
227 err = KErrCompletion; //indicates data validation failure
228 break; //switch(iCaseStep)
231 //Validate second transfer for the remainder of bytes that the device should have written.
232 //NB The number of bytes requested is more than this remainder to accommodate the ZLP.
233 if(ValidateData(data2, KLiteralEnglish8(), KHostNumReadBytesPostHalt1, KDeviceNumWriteBytesPostHalt-KHostNumReadBytesPostHalt1) == EFalse)
235 err = KErrCompletion; //indicates data validation failure
236 break; //switch(iCaseStep)
239 // Comparison is a match
240 RDebug::Printf("Comparison for IN transfer is a match");
242 TTestCasePassed request;
243 iControlEp0->SendRequest(request,this);
246 break; //switch(iCaseStep)
249 err = KUndefinedStep;
250 msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
251 break; //switch(iCaseStep)
254 if(err == KErrCompletion)
255 //indicates data validation failure
257 msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
264 TTestCaseFailed request(err,msg);
265 return iControlEp0->SendRequest(request,this);
269 void CUT_PBASE_T_USBDI_0500::DeviceInsertedL(TUint aDeviceHandle)
274 RDebug::Printf("this - %08x", this);
278 if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError)
279 // Prepare for response from control transfer to client
282 msg.Format(_L("Base class DeviceInsertedL failed"));
286 iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId0);
287 iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId1);
289 // Initialise the descriptors for transfer
290 RDebug::Printf("Initialising the transfer descriptors");
291 err = iUsbInterface1.InitialiseTransferDescriptors();
294 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
301 TTestCaseFailed request(err,msg);
302 iControlEp0->SendRequest(request,this);
306 RDebug::Printf("Asking client for 'Write' and 'Halt'");
307 iCaseStep = ETransferInHalt;
308 TEndpointPatternSynchronousWriteAndHaltRequest request(1,1,KLiteralFrench4(),KDeviceNumWriteBytesPreHalt);// EP1 means endpoint index 1 not the actual endpoint number
309 iControlEp0->SendRequest(request,this);