Update contrib.
1 // Copyright (c) 2007-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-0484.cpp
19 #include "PBASE-T_USBDI-0484.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
26 namespace NUnitTesting_USBDI
28 _LIT8(KDataPayload1,"opqrstuvwxyzabcdefghijklmnopqrstuvwxyz12345abcdefghijklmnopqrstuvwxyz");
29 _LIT8(KDataPayload2,"12345opqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
30 _LIT8(KDataPayload3,"abcdefghijklmnopqrstuvwxyzopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); // 64bytes
32 const TInt KBulkTransferId1 = 0x01;
33 const TInt KBulkTransferId2 = 0x02;
34 const TInt KBulkTransferId3 = 0x03;
35 _LIT(KTestCaseId,"PBASE-T_USBDI-0484");
36 const TFunctorTestCase<CUT_PBASE_T_USBDI_0484,TBool> CUT_PBASE_T_USBDI_0484::iFunctor(KTestCaseId);
38 CUT_PBASE_T_USBDI_0484* CUT_PBASE_T_USBDI_0484::NewL(TBool aHostRole)
40 CUT_PBASE_T_USBDI_0484* self = new (ELeave) CUT_PBASE_T_USBDI_0484(aHostRole);
41 CleanupStack::PushL(self);
43 CleanupStack::Pop(self);
48 CUT_PBASE_T_USBDI_0484::CUT_PBASE_T_USBDI_0484(TBool aHostRole)
49 : CBaseBulkTestCase(KTestCaseId,aHostRole),
50 iCaseStep(EInProgress)
55 void CUT_PBASE_T_USBDI_0484::ConstructL()
61 CUT_PBASE_T_USBDI_0484::~CUT_PBASE_T_USBDI_0484()
66 void CUT_PBASE_T_USBDI_0484::Ep0TransferCompleteL(TInt aCompletionCode)
71 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
73 if(aCompletionCode != KErrNone)
76 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
80 if(iCaseStep == EPassed)
82 if(aCompletionCode == KErrNone)
90 if(iCaseStep == EFailed)
92 return TestFailed(KErrCompletion);
97 void CUT_PBASE_T_USBDI_0484::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
101 RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
103 if(aTransferId == KBulkTransferId1)
105 if(iCaseStep == EStalled)
107 if(aCompletionCode != KErrUsbStalled)
110 msg.Format(_L("<Error %d> The transfer completed with no errors but should have stalled"),aCompletionCode);
112 TTestCaseFailed request(KErrCorrupt,msg);
113 return iControlEp0->SendRequest(request,this);
117 // Acknowledge the stall and clear
118 err = iTestPipeInterface1BulkIn.ClearRemoteStall();
122 msg.Format(_L("<Error %d> The remote stall cannot be cleared"),err);
125 TTestCaseFailed request(err,msg);
126 return iControlEp0->SendRequest(request,this);
129 // try to get data now, after EP has been stalled
130 RDebug::Printf("try to get data now, after EP has been stalled");
131 iInTransfer[0]->TransferIn(KDataPayload1().Length());
132 iInTransfer[1]->TransferIn(KDataPayload2().Length());
133 iInTransfer[2]->TransferIn(KDataPayload3().Length());
135 iCaseStep = ETransferAfterStall;
136 TEndpointWriteRequest request(1,1,KDataPayload1);// EP1 because 1st writter EP
137 iControlEp0->SendRequest(request,this);
141 if(iCaseStep == ETransferAfterStall)
143 if(aCompletionCode != KErrNone)
146 msg.Format(_L("<Error %d> No data got after EP2 being stalled"),aCompletionCode);
149 TTestCaseFailed request(err,msg);
150 return iControlEp0->SendRequest(request,this);
153 // else ok, compare data rcvd now
154 TPtrC8 data(iInTransfer[0]->DataPolled());
155 // Compare the data to what is expected
156 if(data.Compare(KDataPayload1) != 0)
159 msg.Format(_L("<Error %d> Interrupt data received does not match data sent"),KErrCompletion);
162 TTestCaseFailed request(KErrCompletion,msg);
163 return iControlEp0->SendRequest(request,this);
165 // Comparison is a match, wait for next transfer
166 RDebug::Printf("Comparison is a match, wait for transfer 2");
168 TEndpointWriteRequest request(1,1,KDataPayload2);// EP1 because 1st writter EP
169 iControlEp0->SendRequest(request,this);
172 else if(aTransferId == KBulkTransferId2)
174 if(aCompletionCode != KErrNone)
177 msg.Format(_L("<Error %d> No data got after EP2 being stalled"),aCompletionCode);
180 TTestCaseFailed request(err,msg);
181 return iControlEp0->SendRequest(request,this);
184 // else ok, compare data rcvd now
185 TPtrC8 data(iInTransfer[1]->DataPolled());
186 // Compare the data to what is expected
187 if(data.Compare(KDataPayload2) != 0)
190 msg.Format(_L("<Error %d> Interrupt data received does not match data sent"),KErrCompletion);
193 TTestCaseFailed request(KErrCompletion,msg);
194 return iControlEp0->SendRequest(request,this);
196 // Comparison is a match, wait for next transfer
197 RDebug::Printf("Comparison is a match, wait for transfer 3");
199 TEndpointWriteRequest request(1,1,KDataPayload3);// EP1 because 1st writter EP
200 iControlEp0->SendRequest(request,this);
202 else if(aTransferId == KBulkTransferId3)
204 if(aCompletionCode != KErrNone)
207 msg.Format(_L("<Error %d> No data got after EP2 being stalled"),aCompletionCode);
210 TTestCaseFailed request(err,msg);
211 return iControlEp0->SendRequest(request,this);
213 // else ok, compare data rcvd now
214 TPtrC8 data(iInTransfer[2]->DataPolled());
215 // Compare the data to what is expected
216 if(data.Compare(KDataPayload3) != 0)
219 msg.Format(_L("<Error %d> Interrupt data received does not match data sent"),KErrCompletion);
222 TTestCaseFailed request(KErrCompletion,msg);
223 return iControlEp0->SendRequest(request,this);
225 // Comparison is a match, test passes
227 TTestCasePassed request;
228 return iControlEp0->SendRequest(request,this);
232 RDebug::Printf("<Error> a transfer completed (id=%d) that was not expected",aTransferId);
233 return TestFailed(KErrCorrupt);
238 void CUT_PBASE_T_USBDI_0484::DeviceInsertedL(TUint aDeviceHandle)
243 RDebug::Printf("this - %08x", this);
247 if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError)
248 // Prepare for response from control transfer to client
251 msg.Format(_L("Base class DeviceInsertedL failed"));
255 // Create the bulk transfers
256 iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,256,*this,KBulkTransferId1);
257 iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,256,*this,KBulkTransferId2);
258 iInTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,256,*this,KBulkTransferId3);
260 // Initialise the descriptors for transfer
261 RDebug::Printf("Initialising the transfer descriptors - interface 1");
262 err = iUsbInterface1.InitialiseTransferDescriptors();
265 _LIT(lit, "<Error %d> Unable to initialise transfer descriptors");
273 TTestCaseFailed request(err,msg);
274 iControlEp0->SendRequest(request,this);
278 iCaseStep = EStalled;
279 iInTransfer[0]->TransferIn(KDataPayload1().Length());
281 TStallEndpointRequest r2(2,1); // Stall endpoint 2 interface 1
282 iControlEp0->SendRequest(r2,this);