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-0491.cpp
19 #include "PBASE-T_USBDI-0491.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
22 #include "testliterals.h"
27 namespace NUnitTesting_USBDI
30 const TUint KBulkTransferSize = 210;
31 const TInt KBulkTransferInId = 1<<0;
32 const TInt KBulkTransferOutId = 1<<1;
34 const TInt KUnexpectedTransferID = -101;
35 const TInt KUndefinedStep = -102;
38 _LIT(KTestCaseId,"PBASE-T_USBDI-0491");
39 const TFunctorTestCase<CUT_PBASE_T_USBDI_0491,TBool> CUT_PBASE_T_USBDI_0491::iFunctor(KTestCaseId);
41 CUT_PBASE_T_USBDI_0491* CUT_PBASE_T_USBDI_0491::NewL(TBool aHostRole)
43 CUT_PBASE_T_USBDI_0491* self = new (ELeave) CUT_PBASE_T_USBDI_0491(aHostRole);
44 CleanupStack::PushL(self);
46 CleanupStack::Pop(self);
51 CUT_PBASE_T_USBDI_0491::CUT_PBASE_T_USBDI_0491(TBool aHostRole)
52 : CBaseBulkTestCase(KTestCaseId,aHostRole),
53 iCaseStep(EInProgress)
58 void CUT_PBASE_T_USBDI_0491::ConstructL()
64 CUT_PBASE_T_USBDI_0491::~CUT_PBASE_T_USBDI_0491()
69 void CUT_PBASE_T_USBDI_0491::Ep0TransferCompleteL(TInt aCompletionCode)
73 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
75 if(aCompletionCode != KErrNone)
77 if(iCaseStep == EFailed)
78 {// ignore error, nad catch the TestFailed method called further down.
79 RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
84 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
87 TTestCaseFailed request(aCompletionCode,msg);
88 iControlEp0->SendRequest(request,this);
102 TestFailed(KErrCompletion);
106 RDebug::Printf("Try to send data");
107 iOutTransfer[0]->TransferOut(KLiteralEnglish2(), KBulkTransferSize);
111 RDebug::Printf("Try to receive data");
112 iInTransfer[0]->TransferIn(KBulkTransferSize);
116 RDebug::Printf("<Error> Unknown test step");
117 TestFailed(KErrUnknown);
122 void CUT_PBASE_T_USBDI_0491::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
129 RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
135 if(aCompletionCode != KErrNone)
138 msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode);
141 if(aTransferId != KBulkTransferOutId)
143 err = KUnexpectedTransferID;
144 msg.Format(_L("<Error %d> Unexpected Transfer ID, wanted %d, got %d"),
145 err, KBulkTransferOutId, aTransferId);
148 RDebug::Printf("Try to receive back sent data");
149 iCaseStep = ETransferIn;
150 TWriteSynchronousCachedReadDataRequest request(1,1,1); //Use first read EP and first write EP (on interface 1)
151 iControlEp0->SendRequest(request,this);
157 if(aCompletionCode != KErrNone)
160 msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
163 if(aTransferId != KBulkTransferInId)
165 err = KUnexpectedTransferID;
166 msg.Format(_L("<Error %d> Unexpected Transfer ID, wanted %d, got %d"),
167 err, KBulkTransferInId, aTransferId);
170 // Compare the data to what is expected
171 if(ValidateData(iInTransfer[0]->DataPolled(), KLiteralEnglish2(), KBulkTransferSize) == EFalse)
173 err = KErrCompletion; //indicates data validation failure
174 msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
179 // Comparison is a match
180 RDebug::Printf("Comparison for IN transfer is a match");
182 TTestCasePassed request;
183 iControlEp0->SendRequest(request,this);
190 err = KUndefinedStep;
191 msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
199 TTestCaseFailed request(err,msg);
200 return iControlEp0->SendRequest(request,this);
204 void CUT_PBASE_T_USBDI_0491::DeviceInsertedL(TUint aDeviceHandle)
208 RDebug::Printf("****** Father William Pattern Length is %d bytes! *********", KLiteralEnglish2().Length());
210 if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
211 // Prepare for response from control transfer to client
216 // Create the bulk transfers
217 iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId);
218 iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId);
220 // Initialise the descriptors for transfer
221 RDebug::Printf("Initialising the transfer descriptors");
222 TInt err = iUsbInterface1.InitialiseTransferDescriptors();
226 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
229 TTestCaseFailed request(err,msg);
230 iControlEp0->SendRequest(request,this);
234 iCaseStep = ETransferOut;
235 TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP
236 iControlEp0->SendRequest(request,this);