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-0500.cpp
|
sl@0
|
15 |
// @internalComponent
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "PBASE-T_USBDI-0500.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 KBulkMaxINTransferSize = 600;
|
sl@0
|
30 |
const TInt KDeviceNumWriteBytesPreHalt = 256;
|
sl@0
|
31 |
const TUint KHostNumReadBytesPreHalt1 = 512;
|
sl@0
|
32 |
const TUint KHostNumReadBytesPreHalt2 = 512;
|
sl@0
|
33 |
const TUint KHostNumReadBytesPostHalt1 = 256;
|
sl@0
|
34 |
const TUint KHostNumReadBytesPostHalt2 = 257;
|
sl@0
|
35 |
const TInt KDeviceNumWriteBytesPostHalt = 512;
|
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<<4;
|
sl@0
|
42 |
|
sl@0
|
43 |
const TInt KUnexpectedTransferID = -101;
|
sl@0
|
44 |
const TInt KUndefinedStep = -102;
|
sl@0
|
45 |
|
sl@0
|
46 |
|
sl@0
|
47 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0500");
|
sl@0
|
48 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0500,TBool> CUT_PBASE_T_USBDI_0500::iFunctor(KTestCaseId);
|
sl@0
|
49 |
|
sl@0
|
50 |
CUT_PBASE_T_USBDI_0500* CUT_PBASE_T_USBDI_0500::NewL(TBool aHostRole)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
CUT_PBASE_T_USBDI_0500* self = new (ELeave) CUT_PBASE_T_USBDI_0500(aHostRole);
|
sl@0
|
53 |
CleanupStack::PushL(self);
|
sl@0
|
54 |
self->ConstructL();
|
sl@0
|
55 |
CleanupStack::Pop(self);
|
sl@0
|
56 |
return self;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
|
sl@0
|
60 |
CUT_PBASE_T_USBDI_0500::CUT_PBASE_T_USBDI_0500(TBool aHostRole)
|
sl@0
|
61 |
: CBaseBulkTestCase(KTestCaseId,aHostRole),
|
sl@0
|
62 |
iCaseStep(EInProgress)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
|
sl@0
|
67 |
void CUT_PBASE_T_USBDI_0500::ConstructL()
|
sl@0
|
68 |
{
|
sl@0
|
69 |
BaseBulkConstructL();
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
|
sl@0
|
73 |
CUT_PBASE_T_USBDI_0500::~CUT_PBASE_T_USBDI_0500()
|
sl@0
|
74 |
{
|
sl@0
|
75 |
LOG_FUNC
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
|
sl@0
|
79 |
void CUT_PBASE_T_USBDI_0500::Ep0TransferCompleteL(TInt aCompletionCode)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
LOG_FUNC
|
sl@0
|
82 |
|
sl@0
|
83 |
RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
sl@0
|
84 |
|
sl@0
|
85 |
if(aCompletionCode != KErrNone)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
if(iCaseStep == EFailed)
|
sl@0
|
88 |
{// ignore error, nad catch the TestFailed method called further down.
|
sl@0
|
89 |
RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
|
sl@0
|
90 |
}
|
sl@0
|
91 |
else
|
sl@0
|
92 |
{
|
sl@0
|
93 |
TBuf<256> msg;
|
sl@0
|
94 |
msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
|
sl@0
|
95 |
RDebug::Print(msg);
|
sl@0
|
96 |
iCaseStep = EFailed;
|
sl@0
|
97 |
TTestCaseFailed request(aCompletionCode,msg);
|
sl@0
|
98 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
99 |
return;
|
sl@0
|
100 |
}
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
switch(iCaseStep)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
// Test case passed
|
sl@0
|
106 |
case EPassed:
|
sl@0
|
107 |
TestPassed();
|
sl@0
|
108 |
break;
|
sl@0
|
109 |
|
sl@0
|
110 |
// Test case failed
|
sl@0
|
111 |
case EFailed:
|
sl@0
|
112 |
TestFailed(KErrCompletion);
|
sl@0
|
113 |
break;
|
sl@0
|
114 |
|
sl@0
|
115 |
case ETransferInHalt:
|
sl@0
|
116 |
RDebug::Printf("Try to receive data (pre halt)");
|
sl@0
|
117 |
iInTransfer[0]->TransferIn(KHostNumReadBytesPreHalt1);
|
sl@0
|
118 |
iInTransfer[1]->TransferIn(KHostNumReadBytesPreHalt2);
|
sl@0
|
119 |
break;
|
sl@0
|
120 |
|
sl@0
|
121 |
case ETransferIn:
|
sl@0
|
122 |
RDebug::Printf("Try to receive data");
|
sl@0
|
123 |
iInTransfer[0]->TransferIn(KHostNumReadBytesPostHalt1);
|
sl@0
|
124 |
iInTransfer[1]->TransferIn(KHostNumReadBytesPostHalt2);
|
sl@0
|
125 |
break;
|
sl@0
|
126 |
|
sl@0
|
127 |
default:
|
sl@0
|
128 |
RDebug::Printf("<Error> Unknown test step");
|
sl@0
|
129 |
TestFailed(KErrUnknown);
|
sl@0
|
130 |
break;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
}
|
sl@0
|
133 |
|
sl@0
|
134 |
void CUT_PBASE_T_USBDI_0500::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
LOG_FUNC
|
sl@0
|
137 |
Cancel();
|
sl@0
|
138 |
|
sl@0
|
139 |
TInt err(KErrNone);
|
sl@0
|
140 |
TBuf<256> msg;
|
sl@0
|
141 |
RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
|
sl@0
|
142 |
|
sl@0
|
143 |
switch(iCaseStep)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
case ETransferInHalt:
|
sl@0
|
146 |
{
|
sl@0
|
147 |
if(aCompletionCode != KErrUsbStalled)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
iInTransfer[0]->Cancel();
|
sl@0
|
150 |
iInTransfer[1]->Cancel();
|
sl@0
|
151 |
err = KErrCorrupt;
|
sl@0
|
152 |
msg.Format(_L("<Error %d> The transfer completed with no errors but the endpoint should have halted"),aCompletionCode);
|
sl@0
|
153 |
break; //switch(iCaseStep)
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
switch(aTransferId)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
case KBulkTransferInId0:
|
sl@0
|
159 |
case KBulkTransferInId1:
|
sl@0
|
160 |
iTransferComplete |= aTransferId;
|
sl@0
|
161 |
RDebug::Printf("Transfer %d completed", aTransferId);
|
sl@0
|
162 |
break; //switch(aTransferId)
|
sl@0
|
163 |
|
sl@0
|
164 |
default:
|
sl@0
|
165 |
iTransferComplete = 0; //reset
|
sl@0
|
166 |
err = KUnexpectedTransferID;
|
sl@0
|
167 |
msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d, got %d"),
|
sl@0
|
168 |
err, KBulkTransferInId0, KBulkTransferInId1, aTransferId);
|
sl@0
|
169 |
break; //switch(aTransferId)
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1))
|
sl@0
|
173 |
{
|
sl@0
|
174 |
RDebug::Printf("Clear halt and try to send data again. Transfers Completed %d", iTransferComplete);
|
sl@0
|
175 |
iTransferComplete = 0; //reset
|
sl@0
|
176 |
// Acknowledge the stall and clear
|
sl@0
|
177 |
err = iTestPipeInterface1BulkIn.ClearRemoteStall();
|
sl@0
|
178 |
if(err != KErrNone)
|
sl@0
|
179 |
{
|
sl@0
|
180 |
msg.Format(_L("<Error %d> The remote stall cannot be cleared"),err);
|
sl@0
|
181 |
break; //switch(iCaseStep)
|
sl@0
|
182 |
}
|
sl@0
|
183 |
iCaseStep = ETransferIn;
|
sl@0
|
184 |
TEndpointPatternSynchronousWriteRequest request(1,1, KLiteralEnglish8().Mid(0,KDeviceNumWriteBytesPostHalt), KDeviceNumWriteBytesPostHalt);// EP1 because 1st writter EP
|
sl@0
|
185 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
186 |
}
|
sl@0
|
187 |
}
|
sl@0
|
188 |
break; //switch(iCaseStep)
|
sl@0
|
189 |
|
sl@0
|
190 |
case ETransferIn:
|
sl@0
|
191 |
{
|
sl@0
|
192 |
if(aCompletionCode != KErrNone)
|
sl@0
|
193 |
{
|
sl@0
|
194 |
iInTransfer[0]->Cancel();
|
sl@0
|
195 |
iInTransfer[1]->Cancel();
|
sl@0
|
196 |
err = KErrCorrupt;
|
sl@0
|
197 |
|
sl@0
|
198 |
msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
|
sl@0
|
199 |
break; //switch(iCaseStep)
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
switch(aTransferId)
|
sl@0
|
203 |
{
|
sl@0
|
204 |
case KBulkTransferInId0:
|
sl@0
|
205 |
case KBulkTransferInId1:
|
sl@0
|
206 |
iTransferComplete |= aTransferId;
|
sl@0
|
207 |
RDebug::Printf("Transfer %d completed", aTransferId);
|
sl@0
|
208 |
break; //switch(aTransferId)
|
sl@0
|
209 |
|
sl@0
|
210 |
default:
|
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, got %d"),
|
sl@0
|
214 |
err, KBulkTransferInId0, KBulkTransferInId1, aTransferId);
|
sl@0
|
215 |
break; //switch(aTransferId)
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1))
|
sl@0
|
219 |
{
|
sl@0
|
220 |
// ok, compare data rcvd now
|
sl@0
|
221 |
iTransferComplete = 0; //reset
|
sl@0
|
222 |
TPtrC8 data1(iInTransfer[0]->DataPolled());
|
sl@0
|
223 |
TPtrC8 data2(iInTransfer[1]->DataPolled());
|
sl@0
|
224 |
//Validate first transfer for number of bytes requested.
|
sl@0
|
225 |
if(ValidateData(data1, KLiteralEnglish8(), KHostNumReadBytesPostHalt1) == 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 |
//Validate second transfer for the remainder of bytes that the device should have written.
|
sl@0
|
232 |
//NB The number of bytes requested is more than this remainder to accommodate the ZLP.
|
sl@0
|
233 |
if(ValidateData(data2, KLiteralEnglish8(), KHostNumReadBytesPostHalt1, KDeviceNumWriteBytesPostHalt-KHostNumReadBytesPostHalt1) == EFalse)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
err = KErrCompletion; //indicates data validation failure
|
sl@0
|
236 |
break; //switch(iCaseStep)
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
// Comparison is a match
|
sl@0
|
240 |
RDebug::Printf("Comparison for IN transfer is a match");
|
sl@0
|
241 |
iCaseStep = EPassed;
|
sl@0
|
242 |
TTestCasePassed request;
|
sl@0
|
243 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
244 |
}
|
sl@0
|
245 |
}
|
sl@0
|
246 |
break; //switch(iCaseStep)
|
sl@0
|
247 |
|
sl@0
|
248 |
default:
|
sl@0
|
249 |
err = KUndefinedStep;
|
sl@0
|
250 |
msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
|
sl@0
|
251 |
break; //switch(iCaseStep)
|
sl@0
|
252 |
}
|
sl@0
|
253 |
|
sl@0
|
254 |
if(err == KErrCompletion)
|
sl@0
|
255 |
//indicates data validation failure
|
sl@0
|
256 |
{
|
sl@0
|
257 |
msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
if(err!=KErrNone)
|
sl@0
|
261 |
{
|
sl@0
|
262 |
RDebug::Print(msg);
|
sl@0
|
263 |
iCaseStep = EFailed;
|
sl@0
|
264 |
TTestCaseFailed request(err,msg);
|
sl@0
|
265 |
return iControlEp0->SendRequest(request,this);
|
sl@0
|
266 |
}
|
sl@0
|
267 |
}
|
sl@0
|
268 |
|
sl@0
|
269 |
void CUT_PBASE_T_USBDI_0500::DeviceInsertedL(TUint aDeviceHandle)
|
sl@0
|
270 |
{
|
sl@0
|
271 |
LOG_FUNC
|
sl@0
|
272 |
|
sl@0
|
273 |
Cancel();
|
sl@0
|
274 |
RDebug::Printf("this - %08x", this);
|
sl@0
|
275 |
|
sl@0
|
276 |
TBuf<256> msg;
|
sl@0
|
277 |
TInt err = KErrNone;
|
sl@0
|
278 |
if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError)
|
sl@0
|
279 |
// Prepare for response from control transfer to client
|
sl@0
|
280 |
{
|
sl@0
|
281 |
err = KErrGeneral;
|
sl@0
|
282 |
msg.Format(_L("Base class DeviceInsertedL failed"));
|
sl@0
|
283 |
}
|
sl@0
|
284 |
else
|
sl@0
|
285 |
{
|
sl@0
|
286 |
iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId0);
|
sl@0
|
287 |
iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId1);
|
sl@0
|
288 |
|
sl@0
|
289 |
// Initialise the descriptors for transfer
|
sl@0
|
290 |
RDebug::Printf("Initialising the transfer descriptors");
|
sl@0
|
291 |
err = iUsbInterface1.InitialiseTransferDescriptors();
|
sl@0
|
292 |
if(err != KErrNone)
|
sl@0
|
293 |
{
|
sl@0
|
294 |
msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
|
sl@0
|
295 |
}
|
sl@0
|
296 |
}
|
sl@0
|
297 |
if(err != KErrNone)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
RDebug::Print(msg);
|
sl@0
|
300 |
iCaseStep = EFailed;
|
sl@0
|
301 |
TTestCaseFailed request(err,msg);
|
sl@0
|
302 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
303 |
}
|
sl@0
|
304 |
else
|
sl@0
|
305 |
{
|
sl@0
|
306 |
RDebug::Printf("Asking client for 'Write' and 'Halt'");
|
sl@0
|
307 |
iCaseStep = ETransferInHalt;
|
sl@0
|
308 |
TEndpointPatternSynchronousWriteAndHaltRequest request(1,1,KLiteralFrench4(),KDeviceNumWriteBytesPreHalt);// EP1 means endpoint index 1 not the actual endpoint number
|
sl@0
|
309 |
iControlEp0->SendRequest(request,this);
|
sl@0
|
310 |
}
|
sl@0
|
311 |
}
|
sl@0
|
312 |
|
sl@0
|
313 |
} //end namespace
|