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-0490.cpp
19 #include "PBASE-T_USBDI-0490.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
26 namespace NUnitTesting_USBDI
28 _LIT8(KPayloadPattern,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); // 52bytes
30 const TUint KBulkTransferSize = 52;
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-0490");
39 const TFunctorTestCase<CUT_PBASE_T_USBDI_0490,TBool> CUT_PBASE_T_USBDI_0490::iFunctor(KTestCaseId);
41 CUT_PBASE_T_USBDI_0490* CUT_PBASE_T_USBDI_0490::NewL(TBool aHostRole)
43 CUT_PBASE_T_USBDI_0490* self = new (ELeave) CUT_PBASE_T_USBDI_0490(aHostRole);
44 CleanupStack::PushL(self);
46 CleanupStack::Pop(self);
51 CUT_PBASE_T_USBDI_0490::CUT_PBASE_T_USBDI_0490(TBool aHostRole)
52 : CBaseBulkTestCase(KTestCaseId,aHostRole),
53 iCaseStep(EInProgress)
58 void CUT_PBASE_T_USBDI_0490::ConstructL()
64 CUT_PBASE_T_USBDI_0490::~CUT_PBASE_T_USBDI_0490()
69 void CUT_PBASE_T_USBDI_0490::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(KPayloadPattern);
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_0490::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(), KPayloadPattern, 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_0490::DeviceInsertedL(TUint aDeviceHandle)
209 if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
210 // Prepare for response from control transfer to client
215 // Create the bulk transfers
216 iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId);
217 iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId);
219 // Initialise the descriptors for transfer
220 RDebug::Printf("Initialising the transfer descriptors");
221 TInt err = iUsbInterface1.InitialiseTransferDescriptors();
225 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
228 TTestCaseFailed request(err,msg);
229 iControlEp0->SendRequest(request,this);
233 iCaseStep = ETransferOut;
234 TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP
235 iControlEp0->SendRequest(request,this);