sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// @file PBASE-T_USBDI-0493.cpp
|
sl@0
|
15 |
// @internalComponent
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "PBASE-T_USBDI-0493.h"
|
sl@0
|
20 |
#include "testpolicy.h"
|
sl@0
|
21 |
#include "modelleddevices.h"
|
sl@0
|
22 |
#include "testliterals.h"
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
namespace NUnitTesting_USBDI
|
sl@0
|
28 |
{
|
sl@0
|
29 |
const TInt KLiteralEnglish8Length = KLiteralEnglish8().Length();
|
sl@0
|
30 |
const TUint KBulkTransferMaxSize = 320;
|
sl@0
|
31 |
const TUint KHostNumWriteBytes = 256;
|
sl@0
|
32 |
const TUint KHostNumReadBytes = 256;
|
sl@0
|
33 |
const TUint KHostFinalNumReadBytes = 300;
|
sl@0
|
34 |
|
sl@0
|
35 |
const TUint KStartNumTransferBytes = 1023;
|
sl@0
|
36 |
const TUint KFinishNumTransferBytes = 1025;
|
sl@0
|
37 |
|
sl@0
|
38 |
const TUint KClientNumReadBytes = 2000;
|
sl@0
|
39 |
|
sl@0
|
40 |
//Make these single bit values ...
|
sl@0
|
41 |
// ... so that their completion can be easily recorded in a bit mask!
|
sl@0
|
42 |
const TInt KBulkTransferInId0 = 1<<0;
|
sl@0
|
43 |
const TInt KBulkTransferInId1 = 1<<1;
|
sl@0
|
44 |
const TInt KBulkTransferInId2 = 1<<2;
|
sl@0
|
45 |
const TInt KBulkTransferInId3 = 1<<3;
|
sl@0
|
46 |
const TInt KBulkTransferOutId0 = 1<<4;
|
sl@0
|
47 |
const TInt KBulkTransferOutId1 = 1<<5;
|
sl@0
|
48 |
const TInt KBulkTransferOutId2 = 1<<6;
|
sl@0
|
49 |
const TInt KBulkTransferOutId3 = 1<<7;
|
sl@0
|
50 |
|
sl@0
|
51 |
const TInt KUnexpectedTransferID = -101;
|
sl@0
|
52 |
const TInt KUndefinedStep = -102;
|
sl@0
|
53 |
|
sl@0
|
54 |
|
sl@0
|
55 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0493");
|
sl@0
|
56 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0493,TBool> CUT_PBASE_T_USBDI_0493::iFunctor(KTestCaseId);
|
sl@0
|
57 |
|
sl@0
|
58 |
CUT_PBASE_T_USBDI_0493* CUT_PBASE_T_USBDI_0493::NewL(TBool aHostRole)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
CUT_PBASE_T_USBDI_0493* self = new (ELeave) CUT_PBASE_T_USBDI_0493(aHostRole);
|
sl@0
|
61 |
CleanupStack::PushL(self);
|
sl@0
|
62 |
self->ConstructL();
|
sl@0
|
63 |
CleanupStack::Pop(self);
|
sl@0
|
64 |
return self;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
|
sl@0
|
68 |
CUT_PBASE_T_USBDI_0493::CUT_PBASE_T_USBDI_0493(TBool aHostRole)
|
sl@0
|
69 |
: CBaseBulkTestCase(KTestCaseId,aHostRole),
|
sl@0
|
70 |
iNumTransferBytes(KStartNumTransferBytes),
|
sl@0
|
71 |
iCaseStep(EInProgress)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
|
sl@0
|
76 |
void CUT_PBASE_T_USBDI_0493::ConstructL()
|
sl@0
|
77 |
{
|
sl@0
|
78 |
BaseBulkConstructL();
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
|
sl@0
|
82 |
CUT_PBASE_T_USBDI_0493::~CUT_PBASE_T_USBDI_0493()
|
sl@0
|
83 |
{
|
sl@0
|
84 |
LOG_FUNC
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
void CUT_PBASE_T_USBDI_0493::Ep0TransferCompleteL(TInt aCompletionCode)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
LOG_FUNC
|
sl@0
|
90 |
|
sl@0
|
91 |
RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
sl@0
|
92 |
|
sl@0
|
93 |
if(aCompletionCode != KErrNone)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
if(iCaseStep == EFailed)
|
sl@0
|
96 |
{// todo, cope with errors
|
sl@0
|
97 |
}
|
sl@0
|
98 |
else
|
sl@0
|
99 |
{
|
sl@0
|
100 |
TBuf<256> msg;
|
sl@0
|
101 |
msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
|
sl@0
|
102 |
RDebug::Print(msg);
|
sl@0
|
103 |
iCaseStep = EFailed;
|
sl@0
|
104 |
TTestCaseFailed request(aCompletionCode,msg);
|
sl@0
|
105 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
106 |
return;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
switch(iCaseStep)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
// Test case passed
|
sl@0
|
113 |
case EPassed:
|
sl@0
|
114 |
TestPassed();
|
sl@0
|
115 |
break;
|
sl@0
|
116 |
|
sl@0
|
117 |
// Test case failed
|
sl@0
|
118 |
case EFailed:
|
sl@0
|
119 |
TestFailed(KErrCompletion);
|
sl@0
|
120 |
break;
|
sl@0
|
121 |
|
sl@0
|
122 |
case ETransferOut:
|
sl@0
|
123 |
RDebug::Printf("Try to send %d bytes of data", iNumTransferBytes);
|
sl@0
|
124 |
RDebug::RawPrint(KLiteralEnglish8().Mid(0*KHostNumWriteBytes, KHostNumWriteBytes));
|
sl@0
|
125 |
iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
|
sl@0
|
126 |
iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(1*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
|
sl@0
|
127 |
iOutTransfer[2]->TransferOut(KLiteralEnglish8().Mid(2*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
|
sl@0
|
128 |
iOutTransfer[3]->TransferOut(KLiteralEnglish8().Mid(3*KHostNumWriteBytes, iNumTransferBytes - 3*KHostNumWriteBytes), ETrue);
|
sl@0
|
129 |
break;
|
sl@0
|
130 |
|
sl@0
|
131 |
case ETransferIn:
|
sl@0
|
132 |
RDebug::Printf("Try to receive max %d bytes of data", 3*KHostNumReadBytes + KHostFinalNumReadBytes);
|
sl@0
|
133 |
iInTransfer[0]->TransferIn(KHostNumReadBytes);
|
sl@0
|
134 |
iInTransfer[1]->TransferIn(KHostNumReadBytes);
|
sl@0
|
135 |
iInTransfer[2]->TransferIn(KHostNumReadBytes);
|
sl@0
|
136 |
iInTransfer[3]->TransferIn(KHostFinalNumReadBytes);
|
sl@0
|
137 |
break;
|
sl@0
|
138 |
|
sl@0
|
139 |
default:
|
sl@0
|
140 |
RDebug::Printf("<Error> Unknown test step");
|
sl@0
|
141 |
TestFailed(KErrUnknown);
|
sl@0
|
142 |
break;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
void CUT_PBASE_T_USBDI_0493::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
LOG_FUNC
|
sl@0
|
149 |
Cancel();
|
sl@0
|
150 |
|
sl@0
|
151 |
TInt err(KErrNone);
|
sl@0
|
152 |
TBuf<256> msg;
|
sl@0
|
153 |
RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
|
sl@0
|
154 |
|
sl@0
|
155 |
switch(iCaseStep)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
case ETransferOut:
|
sl@0
|
158 |
if(aCompletionCode != KErrNone)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
err = KErrCorrupt;
|
sl@0
|
161 |
msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode);
|
sl@0
|
162 |
break; //switch(iCaseStep)
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
switch(aTransferId)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
case KBulkTransferOutId0:
|
sl@0
|
168 |
case KBulkTransferOutId1:
|
sl@0
|
169 |
case KBulkTransferOutId2:
|
sl@0
|
170 |
case KBulkTransferOutId3:
|
sl@0
|
171 |
iTransferComplete |= aTransferId;
|
sl@0
|
172 |
RDebug::Printf("Transfer %d completed", aTransferId);
|
sl@0
|
173 |
break; //switch(aTransferId)
|
sl@0
|
174 |
|
sl@0
|
175 |
default:
|
sl@0
|
176 |
iTransferComplete = 0; //reset
|
sl@0
|
177 |
err = KUnexpectedTransferID;
|
sl@0
|
178 |
msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d or %d or %d, got %d"),
|
sl@0
|
179 |
err, KBulkTransferOutId0, KBulkTransferOutId1, KBulkTransferOutId2, KBulkTransferOutId3, aTransferId);
|
sl@0
|
180 |
break; //switch(aTransferId)
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1 | KBulkTransferOutId2 | KBulkTransferOutId3))
|
sl@0
|
184 |
{
|
sl@0
|
185 |
RDebug::Printf("Try to receive back sent data. Transfers Completed %d", iTransferComplete);
|
sl@0
|
186 |
iCaseStep = ETransferIn;
|
sl@0
|
187 |
TWriteSynchronousCachedReadDataRequest request(1,1,1); //Use first read EP and first write EP (on interface 1)
|
sl@0
|
188 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
189 |
iTransferComplete = 0; //reset
|
sl@0
|
190 |
}
|
sl@0
|
191 |
break; //switch(iCaseStep)
|
sl@0
|
192 |
|
sl@0
|
193 |
case ETransferIn:
|
sl@0
|
194 |
if(aCompletionCode != KErrNone)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
err = KErrCorrupt;
|
sl@0
|
197 |
msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
|
sl@0
|
198 |
break; //switch(iCaseStep)
|
sl@0
|
199 |
}
|
sl@0
|
200 |
switch(aTransferId)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
case KBulkTransferInId0:
|
sl@0
|
203 |
case KBulkTransferInId1:
|
sl@0
|
204 |
case KBulkTransferInId2:
|
sl@0
|
205 |
case KBulkTransferInId3:
|
sl@0
|
206 |
iTransferComplete |= aTransferId;
|
sl@0
|
207 |
break; //switch(aTransferId)
|
sl@0
|
208 |
|
sl@0
|
209 |
default:
|
sl@0
|
210 |
RDebug::Printf("Bad Transfer ID");
|
sl@0
|
211 |
iTransferComplete = 0; //reset
|
sl@0
|
212 |
err = KUnexpectedTransferID;
|
sl@0
|
213 |
msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d or %d or %d, got %d"),
|
sl@0
|
214 |
err, KBulkTransferInId0, KBulkTransferInId1, KBulkTransferInId2, KBulkTransferInId3, aTransferId);
|
sl@0
|
215 |
break; //switch(aTransferId)
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1 | KBulkTransferInId2 | KBulkTransferInId3))
|
sl@0
|
219 |
{
|
sl@0
|
220 |
// compare data rcvd now
|
sl@0
|
221 |
TPtrC8 data1(iInTransfer[0]->DataPolled());
|
sl@0
|
222 |
TPtrC8 data2(iInTransfer[1]->DataPolled());
|
sl@0
|
223 |
TPtrC8 data3(iInTransfer[2]->DataPolled());
|
sl@0
|
224 |
TPtrC8 data4(iInTransfer[3]->DataPolled());
|
sl@0
|
225 |
if(ValidateData(data1, KLiteralEnglish8().Mid(0*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
err = KErrCompletion; //indicates data validation failure
|
sl@0
|
228 |
break; //switch(iCaseStep)
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
if(ValidateData(data2, KLiteralEnglish8().Mid(1*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
err = KErrCompletion; //indicates data validation failure
|
sl@0
|
234 |
break; //switch(iCaseStep)
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
if(ValidateData(data3, KLiteralEnglish8().Mid(2*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
err = KErrCompletion; //indicates data validation failure
|
sl@0
|
240 |
break; //switch(iCaseStep)
|
sl@0
|
241 |
}
|
sl@0
|
242 |
|
sl@0
|
243 |
if(ValidateData(data4, KLiteralEnglish8().Mid(3*KHostNumReadBytes, iNumTransferBytes - 3*KHostNumReadBytes)) == EFalse)
|
sl@0
|
244 |
{
|
sl@0
|
245 |
err = KErrCompletion; //indicates data validation failure
|
sl@0
|
246 |
break; //switch(iCaseStep)
|
sl@0
|
247 |
}
|
sl@0
|
248 |
|
sl@0
|
249 |
if(err == KErrNone)
|
sl@0
|
250 |
{
|
sl@0
|
251 |
// Comparison is a match
|
sl@0
|
252 |
RDebug::Printf("Comparison for IN transfer is a match - Number of Transfer Bytes %d", iNumTransferBytes);
|
sl@0
|
253 |
iTransferComplete = 0; //reset
|
sl@0
|
254 |
if(++iNumTransferBytes<=KFinishNumTransferBytes)
|
sl@0
|
255 |
/*
|
sl@0
|
256 |
Loop round again having added one to
|
sl@0
|
257 |
the number of transfer bytes to be used.
|
sl@0
|
258 |
In this test there should be three repeats of the underlying
|
sl@0
|
259 |
"Transfer Out followed by Transfer In" test.
|
sl@0
|
260 |
The repeats will use
|
sl@0
|
261 |
KStartNumTransferBytes,
|
sl@0
|
262 |
KStartNumTransferBytes+1,
|
sl@0
|
263 |
and finally
|
sl@0
|
264 |
KFinishNumTransferBytes.
|
sl@0
|
265 |
*/
|
sl@0
|
266 |
{
|
sl@0
|
267 |
iCaseStep = ETransferOut;
|
sl@0
|
268 |
TEndpointReadUntilShortRequest request(1,1,KClientNumReadBytes);// EP1 because 1st reader EP
|
sl@0
|
269 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
270 |
break; //switch(iCaseStep)
|
sl@0
|
271 |
}
|
sl@0
|
272 |
iCaseStep = EPassed;
|
sl@0
|
273 |
TTestCasePassed request;
|
sl@0
|
274 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
275 |
}
|
sl@0
|
276 |
}
|
sl@0
|
277 |
break; //switch(iCaseStep)
|
sl@0
|
278 |
|
sl@0
|
279 |
default:
|
sl@0
|
280 |
err = KUndefinedStep;
|
sl@0
|
281 |
msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
|
sl@0
|
282 |
break; //switch(iCaseStep)
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
if(err!=KErrNone)
|
sl@0
|
286 |
{
|
sl@0
|
287 |
RDebug::Print(msg);
|
sl@0
|
288 |
iCaseStep = EFailed;
|
sl@0
|
289 |
TTestCaseFailed request(err,msg);
|
sl@0
|
290 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
291 |
return;
|
sl@0
|
292 |
}
|
sl@0
|
293 |
}
|
sl@0
|
294 |
|
sl@0
|
295 |
|
sl@0
|
296 |
void CUT_PBASE_T_USBDI_0493::DeviceInsertedL(TUint aDeviceHandle)
|
sl@0
|
297 |
{
|
sl@0
|
298 |
LOG_FUNC
|
sl@0
|
299 |
Cancel();
|
sl@0
|
300 |
RDebug::Printf("****** Father William Pattern Length is %d bytes! *********", KLiteralEnglish8Length);
|
sl@0
|
301 |
if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
|
sl@0
|
302 |
// Prepare for response from control transfer to client
|
sl@0
|
303 |
{
|
sl@0
|
304 |
iCaseStep = EFailed;
|
sl@0
|
305 |
}
|
sl@0
|
306 |
|
sl@0
|
307 |
// Create the bulk transfers
|
sl@0
|
308 |
RDebug::Printf("Trying to create the bulk transfers - size 0x%u", KBulkTransferMaxSize);
|
sl@0
|
309 |
iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId0);
|
sl@0
|
310 |
iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId1);
|
sl@0
|
311 |
iInTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId2);
|
sl@0
|
312 |
iInTransfer[3] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId3);
|
sl@0
|
313 |
iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId0);
|
sl@0
|
314 |
iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId1);
|
sl@0
|
315 |
iOutTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId2);
|
sl@0
|
316 |
iOutTransfer[3] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId3);
|
sl@0
|
317 |
|
sl@0
|
318 |
// Initialise the descriptors for transfer
|
sl@0
|
319 |
RDebug::Printf("Initialising the transfer descriptors");
|
sl@0
|
320 |
TInt err = iUsbInterface1.InitialiseTransferDescriptors();
|
sl@0
|
321 |
if(err != KErrNone)
|
sl@0
|
322 |
{
|
sl@0
|
323 |
TBuf<256> msg;
|
sl@0
|
324 |
msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
|
sl@0
|
325 |
RDebug::Print(msg);
|
sl@0
|
326 |
iCaseStep = EFailed;
|
sl@0
|
327 |
TTestCaseFailed request(err,msg);
|
sl@0
|
328 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
329 |
return;
|
sl@0
|
330 |
}
|
sl@0
|
331 |
|
sl@0
|
332 |
RDebug::Printf("Ask client to read %d bytes of data", KClientNumReadBytes);
|
sl@0
|
333 |
iCaseStep = ETransferOut;
|
sl@0
|
334 |
TEndpointReadUntilShortRequest request(1,1,KClientNumReadBytes);// EP1 because 1st reader EP
|
sl@0
|
335 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
336 |
}
|
sl@0
|
337 |
|
sl@0
|
338 |
} //end namespace
|