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-0492.cpp
|
sl@0
|
15 |
// @internalComponent
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "PBASE-T_USBDI-0492.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 KBulkTransferSize = 583;
|
sl@0
|
30 |
const TUint KHostNumWriteBytes1 = 210;
|
sl@0
|
31 |
const TUint KHostNumWriteBytes2 = 350;
|
sl@0
|
32 |
const TUint KHostNumWriteBytes3 = KBulkTransferSize - KHostNumWriteBytes1 - KHostNumWriteBytes2; // 23
|
sl@0
|
33 |
const TUint KHostNumReadBytes1 = 301;
|
sl@0
|
34 |
const TUint KHostNumReadBytes2 = 21;
|
sl@0
|
35 |
const TUint KHostNumReadBytes3 = KBulkTransferSize - KHostNumReadBytes1 - KHostNumReadBytes2; // 261
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
//Make these single bit values ...
|
sl@0
|
39 |
// ... so that their completion can be easily recorded in a bit mask!
|
sl@0
|
40 |
const TInt KBulkTransferInId0 = 1<<0;
|
sl@0
|
41 |
const TInt KBulkTransferInId1 = 1<<1;
|
sl@0
|
42 |
const TInt KBulkTransferInId2 = 1<<2;
|
sl@0
|
43 |
const TInt KBulkTransferOutId0 = 1<<3;
|
sl@0
|
44 |
const TInt KBulkTransferOutId1 = 1<<4;
|
sl@0
|
45 |
const TInt KBulkTransferOutId2 = 1<<5;
|
sl@0
|
46 |
|
sl@0
|
47 |
const TInt KUnexpectedTransferID = -101;
|
sl@0
|
48 |
const TInt KUndefinedStep = -102;
|
sl@0
|
49 |
|
sl@0
|
50 |
|
sl@0
|
51 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0492");
|
sl@0
|
52 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0492,TBool> CUT_PBASE_T_USBDI_0492::iFunctor(KTestCaseId);
|
sl@0
|
53 |
|
sl@0
|
54 |
CUT_PBASE_T_USBDI_0492* CUT_PBASE_T_USBDI_0492::NewL(TBool aHostRole)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
CUT_PBASE_T_USBDI_0492* self = new (ELeave) CUT_PBASE_T_USBDI_0492(aHostRole);
|
sl@0
|
57 |
CleanupStack::PushL(self);
|
sl@0
|
58 |
self->ConstructL();
|
sl@0
|
59 |
CleanupStack::Pop(self);
|
sl@0
|
60 |
return self;
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
|
sl@0
|
64 |
CUT_PBASE_T_USBDI_0492::CUT_PBASE_T_USBDI_0492(TBool aHostRole)
|
sl@0
|
65 |
: CBaseBulkTestCase(KTestCaseId,aHostRole),
|
sl@0
|
66 |
iCaseStep(EInProgress)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
|
sl@0
|
71 |
void CUT_PBASE_T_USBDI_0492::ConstructL()
|
sl@0
|
72 |
{
|
sl@0
|
73 |
BaseBulkConstructL();
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
|
sl@0
|
77 |
CUT_PBASE_T_USBDI_0492::~CUT_PBASE_T_USBDI_0492()
|
sl@0
|
78 |
{
|
sl@0
|
79 |
LOG_FUNC
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
|
sl@0
|
83 |
void CUT_PBASE_T_USBDI_0492::Ep0TransferCompleteL(TInt aCompletionCode)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
LOG_FUNC
|
sl@0
|
86 |
|
sl@0
|
87 |
RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
sl@0
|
88 |
|
sl@0
|
89 |
if(aCompletionCode != KErrNone)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
if(iCaseStep == EFailed)
|
sl@0
|
92 |
{// ignore error, nad catch the TestFailed method called further down.
|
sl@0
|
93 |
RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
|
sl@0
|
94 |
}
|
sl@0
|
95 |
else
|
sl@0
|
96 |
{
|
sl@0
|
97 |
TBuf<256> msg;
|
sl@0
|
98 |
msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
|
sl@0
|
99 |
RDebug::Print(msg);
|
sl@0
|
100 |
iCaseStep = EFailed;
|
sl@0
|
101 |
TTestCaseFailed request(aCompletionCode,msg);
|
sl@0
|
102 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
103 |
return;
|
sl@0
|
104 |
}
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
switch(iCaseStep)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
// Test case passed
|
sl@0
|
110 |
case EPassed:
|
sl@0
|
111 |
TestPassed();
|
sl@0
|
112 |
break;
|
sl@0
|
113 |
|
sl@0
|
114 |
// Test case failed
|
sl@0
|
115 |
case EFailed:
|
sl@0
|
116 |
TestFailed(KErrCompletion);
|
sl@0
|
117 |
break;
|
sl@0
|
118 |
|
sl@0
|
119 |
case ETransferOut:
|
sl@0
|
120 |
RDebug::Printf("Try to send data");
|
sl@0
|
121 |
iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0, KHostNumWriteBytes1), EFalse);
|
sl@0
|
122 |
iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytes1, KHostNumWriteBytes2), EFalse);
|
sl@0
|
123 |
iOutTransfer[2]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytes1+KHostNumWriteBytes2, KHostNumWriteBytes3), ETrue); //do not suppress ZLP on this last one (though should be irrelevant here)
|
sl@0
|
124 |
break;
|
sl@0
|
125 |
|
sl@0
|
126 |
case ETransferIn:
|
sl@0
|
127 |
RDebug::Printf("Try to receive data");
|
sl@0
|
128 |
iInTransfer[0]->TransferIn(KHostNumReadBytes1);
|
sl@0
|
129 |
iInTransfer[1]->TransferIn(KHostNumReadBytes2);
|
sl@0
|
130 |
iInTransfer[2]->TransferIn(KHostNumReadBytes3);
|
sl@0
|
131 |
break;
|
sl@0
|
132 |
|
sl@0
|
133 |
default:
|
sl@0
|
134 |
RDebug::Printf("<Error> Unknown test step");
|
sl@0
|
135 |
TestFailed(KErrUnknown);
|
sl@0
|
136 |
break;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
void CUT_PBASE_T_USBDI_0492::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
LOG_FUNC
|
sl@0
|
143 |
Cancel();
|
sl@0
|
144 |
|
sl@0
|
145 |
TInt err(KErrNone);
|
sl@0
|
146 |
TBuf<256> msg;
|
sl@0
|
147 |
RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
|
sl@0
|
148 |
|
sl@0
|
149 |
switch(iCaseStep)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
case ETransferOut:
|
sl@0
|
152 |
if(aCompletionCode != KErrNone)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
err = KErrCorrupt;
|
sl@0
|
155 |
msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode);
|
sl@0
|
156 |
break; // switch(iCaseStep)
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
switch(aTransferId)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
case KBulkTransferOutId0:
|
sl@0
|
162 |
case KBulkTransferOutId1:
|
sl@0
|
163 |
case KBulkTransferOutId2:
|
sl@0
|
164 |
iTransferComplete |= aTransferId;
|
sl@0
|
165 |
RDebug::Printf("Transfer %d completed", aTransferId);
|
sl@0
|
166 |
break; // switch(aTransferId)
|
sl@0
|
167 |
|
sl@0
|
168 |
default:
|
sl@0
|
169 |
iTransferComplete = 0; //reset
|
sl@0
|
170 |
err = KUnexpectedTransferID;
|
sl@0
|
171 |
msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d, %d or %d, got %d"),
|
sl@0
|
172 |
err, KBulkTransferOutId0, KBulkTransferOutId1, KBulkTransferOutId2, aTransferId);
|
sl@0
|
173 |
break; // switch(aTransferId)
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1 | KBulkTransferOutId2))
|
sl@0
|
177 |
{
|
sl@0
|
178 |
RDebug::Printf("Try to receive back sent data. Transfers Completed %d", iTransferComplete);
|
sl@0
|
179 |
iCaseStep = ETransferIn;
|
sl@0
|
180 |
TUint numBytes[KNumSplitWriteSections] = {KHostNumReadBytes1, KHostNumReadBytes2, KHostNumReadBytes3};
|
sl@0
|
181 |
TSplitWriteCachedReadDataRequest request(1,1,1,numBytes);
|
sl@0
|
182 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
183 |
iTransferComplete = 0; //reset
|
sl@0
|
184 |
}
|
sl@0
|
185 |
break; // switch(iCaseStep)
|
sl@0
|
186 |
|
sl@0
|
187 |
case ETransferIn:
|
sl@0
|
188 |
if(aCompletionCode != KErrNone)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
err = KErrCorrupt;
|
sl@0
|
191 |
msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
|
sl@0
|
192 |
break; // switch(iCaseStep)
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
switch(aTransferId)
|
sl@0
|
196 |
{
|
sl@0
|
197 |
case KBulkTransferInId0:
|
sl@0
|
198 |
case KBulkTransferInId1:
|
sl@0
|
199 |
case KBulkTransferInId2:
|
sl@0
|
200 |
iTransferComplete |= aTransferId;
|
sl@0
|
201 |
break; // switch(aTransferId)
|
sl@0
|
202 |
|
sl@0
|
203 |
default:
|
sl@0
|
204 |
iTransferComplete = 0; //reset
|
sl@0
|
205 |
err = KUnexpectedTransferID;
|
sl@0
|
206 |
msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d, %d or %d, got %d"),
|
sl@0
|
207 |
err, KBulkTransferInId0, KBulkTransferInId1, KBulkTransferInId2, aTransferId);
|
sl@0
|
208 |
break; // switch(aTransferId)
|
sl@0
|
209 |
}
|
sl@0
|
210 |
|
sl@0
|
211 |
if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1 | KBulkTransferInId2))
|
sl@0
|
212 |
{
|
sl@0
|
213 |
// compare data rcvd now
|
sl@0
|
214 |
TPtrC8 data1(iInTransfer[0]->DataPolled());
|
sl@0
|
215 |
TPtrC8 data2(iInTransfer[1]->DataPolled());
|
sl@0
|
216 |
TPtrC8 data3(iInTransfer[2]->DataPolled());
|
sl@0
|
217 |
if(ValidateData(data1, KLiteralEnglish8().Mid(0, KHostNumReadBytes1)) == EFalse)
|
sl@0
|
218 |
{
|
sl@0
|
219 |
err = KErrCompletion; //indicates data validation failure
|
sl@0
|
220 |
break; // switch(iCaseStep)
|
sl@0
|
221 |
}
|
sl@0
|
222 |
|
sl@0
|
223 |
if(ValidateData(data2, KLiteralEnglish8().Mid(KHostNumReadBytes1, KHostNumReadBytes2)) == EFalse)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
err = KErrCompletion; //indicates data validation failure
|
sl@0
|
226 |
break; // switch(iCaseStep)
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
if(ValidateData(data3, KLiteralEnglish8().Mid(KHostNumReadBytes1+KHostNumReadBytes2, KHostNumReadBytes3)) == EFalse)
|
sl@0
|
230 |
{
|
sl@0
|
231 |
err = KErrCompletion; //indicates data validation failure
|
sl@0
|
232 |
break; // switch(iCaseStep)
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
// Comparison is a match
|
sl@0
|
236 |
RDebug::Printf("Comparison for IN transfer is a match");
|
sl@0
|
237 |
iCaseStep = EPassed;
|
sl@0
|
238 |
TTestCasePassed request;
|
sl@0
|
239 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
240 |
iTransferComplete = 0; //reset
|
sl@0
|
241 |
}
|
sl@0
|
242 |
break; // switch(iCaseStep)
|
sl@0
|
243 |
|
sl@0
|
244 |
default:
|
sl@0
|
245 |
err = KUndefinedStep;
|
sl@0
|
246 |
msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
|
sl@0
|
247 |
break; // switch(iCaseStep)
|
sl@0
|
248 |
}
|
sl@0
|
249 |
|
sl@0
|
250 |
if(err == KErrCompletion)
|
sl@0
|
251 |
{
|
sl@0
|
252 |
//indicates data validation failure
|
sl@0
|
253 |
msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
if(err!=KErrNone)
|
sl@0
|
257 |
{
|
sl@0
|
258 |
RDebug::Print(msg);
|
sl@0
|
259 |
iCaseStep = EFailed;
|
sl@0
|
260 |
TTestCaseFailed request(err,msg);
|
sl@0
|
261 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
262 |
}
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
void CUT_PBASE_T_USBDI_0492::DeviceInsertedL(TUint aDeviceHandle)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
LOG_FUNC
|
sl@0
|
268 |
|
sl@0
|
269 |
Cancel();
|
sl@0
|
270 |
|
sl@0
|
271 |
if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
|
sl@0
|
272 |
// Prepare for response from control transfer to client
|
sl@0
|
273 |
{
|
sl@0
|
274 |
iCaseStep = EFailed;
|
sl@0
|
275 |
}
|
sl@0
|
276 |
|
sl@0
|
277 |
// Create the bulk transfers
|
sl@0
|
278 |
iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId0);
|
sl@0
|
279 |
iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId1);
|
sl@0
|
280 |
iInTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferInId2);
|
sl@0
|
281 |
iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId0);
|
sl@0
|
282 |
iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId1);
|
sl@0
|
283 |
iOutTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId2);
|
sl@0
|
284 |
|
sl@0
|
285 |
// Initialise the descriptors for transfer
|
sl@0
|
286 |
RDebug::Printf("Initialising the transfer descriptors");
|
sl@0
|
287 |
TInt err = iUsbInterface1.InitialiseTransferDescriptors();
|
sl@0
|
288 |
if(err != KErrNone)
|
sl@0
|
289 |
{
|
sl@0
|
290 |
TBuf<256> msg;
|
sl@0
|
291 |
msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
|
sl@0
|
292 |
RDebug::Print(msg);
|
sl@0
|
293 |
iCaseStep = EFailed;
|
sl@0
|
294 |
TTestCaseFailed request(err,msg);
|
sl@0
|
295 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
296 |
return;
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
iCaseStep = ETransferOut;
|
sl@0
|
300 |
TEndpointReadRequest request(1,1,KBulkTransferSize);// EP1 means endpoint index 1 not the actual endpoint number
|
sl@0
|
301 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
302 |
}
|
sl@0
|
303 |
|
sl@0
|
304 |
} //end namespace
|