sl@0
|
1 |
// Copyright (c) 2007-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 basetestcase.cpp
|
sl@0
|
15 |
// @internalComponent
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "BaseTestCase.h"
|
sl@0
|
20 |
#include <e32ver.h>
|
sl@0
|
21 |
#include <d32usbdi.h>
|
sl@0
|
22 |
#include "testdebug.h"
|
sl@0
|
23 |
#include "testpolicy.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
namespace NUnitTesting_USBDI
|
sl@0
|
26 |
{
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
const TUint8 KEpDirectionIn = 0x80;
|
sl@0
|
30 |
const TUint8 KEpDirectionOut = 0x00;
|
sl@0
|
31 |
const TUint8 KTransferTypeControl = 0x00;
|
sl@0
|
32 |
const TUint8 KTransferTypeIsoch = 0x01;
|
sl@0
|
33 |
const TUint8 KTransferTypeBulk = 0x02;
|
sl@0
|
34 |
const TUint8 KTransferTypeInterrupt = 0x03;
|
sl@0
|
35 |
|
sl@0
|
36 |
const TUint8 KChunkSize = 0x80 ; // 128 bytes
|
sl@0
|
37 |
const TUint KTreeBufferSize = 32*1024 ; // 32k bytes
|
sl@0
|
38 |
|
sl@0
|
39 |
_LIT(KRefPath, "Z:\\scripts\\");
|
sl@0
|
40 |
_LIT(KGeneratedFilesPath,"C:\\");
|
sl@0
|
41 |
_LIT(KExtensionFile,".txt");
|
sl@0
|
42 |
|
sl@0
|
43 |
|
sl@0
|
44 |
CBaseTestCase::CBaseTestCase(const TDesC& aTestCaseId,TBool aHostFlag, TBool aHostOnly)
|
sl@0
|
45 |
: CActive(EPriorityStandard),
|
sl@0
|
46 |
iHost(aHostFlag),
|
sl@0
|
47 |
iHostOnly(aHostOnly)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
iTestCaseId.Copy(aTestCaseId);
|
sl@0
|
50 |
CActiveScheduler::Add(this);
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
void CBaseTestCase::BaseConstructL()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
LOG_FUNC
|
sl@0
|
56 |
RDebug::Printf("Creating test case timer");
|
sl@0
|
57 |
TInt err(iTimer.CreateLocal());
|
sl@0
|
58 |
if(err == KErrNone)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
RDebug::Printf("Test case timer created");
|
sl@0
|
61 |
}
|
sl@0
|
62 |
else
|
sl@0
|
63 |
{
|
sl@0
|
64 |
RDebug::Printf("<Error %d> Test case timer could not be created",err);
|
sl@0
|
65 |
User::Leave(err);
|
sl@0
|
66 |
}
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
void CBaseTestCase::TimeoutIn(TInt aTimeoutPeriod)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
LOG_FUNC
|
sl@0
|
72 |
|
sl@0
|
73 |
CancelTimeout();
|
sl@0
|
74 |
iTimer.After(iStatus,aTimeoutPeriod*1000000);
|
sl@0
|
75 |
SetActive();
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
|
sl@0
|
79 |
void CBaseTestCase::CancelTimeout()
|
sl@0
|
80 |
{
|
sl@0
|
81 |
iTimer.Cancel();
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
TInt CBaseTestCase::GenerateRefFile(const TDesC& aFileName)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
|
sl@0
|
87 |
LOG_FUNC
|
sl@0
|
88 |
TBuf<256> refTreeFullFileName(KGeneratedFilesPath);
|
sl@0
|
89 |
refTreeFullFileName.Append(aFileName);
|
sl@0
|
90 |
refTreeFullFileName.Append(KExtensionFile);
|
sl@0
|
91 |
|
sl@0
|
92 |
RFile refFile;
|
sl@0
|
93 |
TInt ret = KErrNone;
|
sl@0
|
94 |
ret = iFs.Connect();
|
sl@0
|
95 |
if(ret!=KErrNone && ret!=KErrAlreadyExists)
|
sl@0
|
96 |
// if already connected, ignore
|
sl@0
|
97 |
{
|
sl@0
|
98 |
RDebug::Printf("iFs.Connect fails, ret = %d", ret);
|
sl@0
|
99 |
return ret;
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
ret = iFs.Delete(refTreeFullFileName);
|
sl@0
|
103 |
if(ret == KErrNone || ret == KErrNotFound)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
ret = refFile.Create(iFs,refTreeFullFileName,EFileShareAny|EFileWrite);
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
if(ret!=KErrNone)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
RDebug::Printf("refFile.Create fails, ret = %d", ret);
|
sl@0
|
111 |
return ret;
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
refFile.Write(iTreeBuffer);
|
sl@0
|
115 |
refFile.Flush();
|
sl@0
|
116 |
refFile.Close();
|
sl@0
|
117 |
|
sl@0
|
118 |
return KErrNone;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
TInt CBaseTestCase::CompareCurrentTreeToRef(const TDesC& aFileName, TBool& aIsIdentical)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
|
sl@0
|
124 |
LOG_FUNC
|
sl@0
|
125 |
TBuf<256> refTreeFullFileName(KRefPath);
|
sl@0
|
126 |
refTreeFullFileName.Append(aFileName);
|
sl@0
|
127 |
refTreeFullFileName.Append(KExtensionFile);
|
sl@0
|
128 |
|
sl@0
|
129 |
TInt ret = KErrNone;
|
sl@0
|
130 |
ret = iFs.Connect();
|
sl@0
|
131 |
if(ret!=KErrNone && ret!=KErrAlreadyExists)
|
sl@0
|
132 |
// if already connected, ignore
|
sl@0
|
133 |
{
|
sl@0
|
134 |
RDebug::Printf("iFs.Connect fails, ret = %d", ret);
|
sl@0
|
135 |
return ret;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
RFile refFile;
|
sl@0
|
139 |
ret = refFile.Open(iFs,refTreeFullFileName,EFileShareAny|EFileRead);
|
sl@0
|
140 |
|
sl@0
|
141 |
if(ret!=KErrNone)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
RDebug::Printf("Reference File path: %S", &refTreeFullFileName);
|
sl@0
|
144 |
RDebug::Printf("refFile.Open fails ret = %d", ret);
|
sl@0
|
145 |
return ret;
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
TInt refFileSize;
|
sl@0
|
149 |
refFile.Size(refFileSize);
|
sl@0
|
150 |
|
sl@0
|
151 |
// check size is identical
|
sl@0
|
152 |
if(refFileSize != iTreeBuffer.Size())
|
sl@0
|
153 |
{
|
sl@0
|
154 |
RDebug::Printf("sizes are NOT identical, refFileSize = %d, iTreeBuffer.Size() = %d ", refFileSize, iTreeBuffer.Size());
|
sl@0
|
155 |
//return KErrGeneral; not an issue, \n encoded differently by perforce... x0D x0A. (x0A only in generated ref file)
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
// read the file, and put it in a local buffer
|
sl@0
|
159 |
RBuf8 refBuf;
|
sl@0
|
160 |
refBuf.CreateL(refFileSize);
|
sl@0
|
161 |
ret = refFile.Read(0, refBuf, refFileSize);
|
sl@0
|
162 |
|
sl@0
|
163 |
if(ret!=KErrNone)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
RDebug::Printf("refFile.Read fails %d", ret);
|
sl@0
|
166 |
return ret;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
// find occurences of \n now
|
sl@0
|
170 |
RBuf8 copyRefBuf;
|
sl@0
|
171 |
copyRefBuf.CreateL(refFileSize);
|
sl@0
|
172 |
|
sl@0
|
173 |
for(TInt iRefBuffer=0; iRefBuffer < refFileSize; iRefBuffer++)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
if(refBuf[iRefBuffer] == 0x0D && iRefBuffer != refFileSize-1) // not the last byte
|
sl@0
|
176 |
{
|
sl@0
|
177 |
if(refBuf[iRefBuffer+1] == 0x0A)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
copyRefBuf.Append(_L8("\n"));
|
sl@0
|
180 |
continue;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
}
|
sl@0
|
183 |
// previous is 0x0D, skip...
|
sl@0
|
184 |
if( refBuf[iRefBuffer] == 0x0A && refBuf[iRefBuffer-1] == 0x0D)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
continue;
|
sl@0
|
187 |
}
|
sl@0
|
188 |
copyRefBuf.AppendFormat(_L8("%c"), refBuf[iRefBuffer]);
|
sl@0
|
189 |
}
|
sl@0
|
190 |
refBuf.Close();
|
sl@0
|
191 |
|
sl@0
|
192 |
RDebug::Printf("copyRefBuf.Size %d", copyRefBuf.Size());
|
sl@0
|
193 |
|
sl@0
|
194 |
|
sl@0
|
195 |
// check size is identical, should be identical now
|
sl@0
|
196 |
if(copyRefBuf.Size() != iTreeBuffer.Size())
|
sl@0
|
197 |
{
|
sl@0
|
198 |
RDebug::Printf("sizes are NOT identical, copyRefBuf.Size() = %d, iTreeBuffer.Size() = %d ", refFileSize, iTreeBuffer.Size());
|
sl@0
|
199 |
return KErrGeneral;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
// now compare the 2 buffers
|
sl@0
|
203 |
// Can only go as far as the smallest buffer
|
sl@0
|
204 |
TInt bufferSizeToCheck = Min(copyRefBuf.Size(), iTreeBuffer.Size());
|
sl@0
|
205 |
RDebug::Print(_L("bufferSizeToCheck = %d"), bufferSizeToCheck);
|
sl@0
|
206 |
|
sl@0
|
207 |
aIsIdentical = ETrue;
|
sl@0
|
208 |
for(TInt iRefBuffer=0; iRefBuffer < bufferSizeToCheck; iRefBuffer++)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
if(iTreeBuffer[iRefBuffer] != copyRefBuf[iRefBuffer])
|
sl@0
|
211 |
{
|
sl@0
|
212 |
RDebug::Print(_L("Failed buffer comparison at position %d"), iRefBuffer);
|
sl@0
|
213 |
RDebug::Print(_L("Missmatching chars (%d %d) (%c %c)"), iTreeBuffer[iRefBuffer], copyRefBuf[iRefBuffer], iTreeBuffer[iRefBuffer], copyRefBuf[iRefBuffer]);
|
sl@0
|
214 |
aIsIdentical = EFalse;
|
sl@0
|
215 |
break;
|
sl@0
|
216 |
}
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
RDebug::Print(_L("Finished Buffer comparison aIsIdentical=%d"), aIsIdentical);
|
sl@0
|
220 |
|
sl@0
|
221 |
copyRefBuf.Close();
|
sl@0
|
222 |
|
sl@0
|
223 |
return KErrNone;
|
sl@0
|
224 |
}
|
sl@0
|
225 |
|
sl@0
|
226 |
CBaseTestCase::~CBaseTestCase()
|
sl@0
|
227 |
{
|
sl@0
|
228 |
LOG_FUNC
|
sl@0
|
229 |
Cancel();
|
sl@0
|
230 |
iTimer.Close();
|
sl@0
|
231 |
iTreeBuffer.Close();
|
sl@0
|
232 |
iFs.Close();
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
void CBaseTestCase::SelfComplete()
|
sl@0
|
236 |
{
|
sl@0
|
237 |
SelfComplete(KErrNone);
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
void CBaseTestCase::SelfComplete(TInt aError)
|
sl@0
|
241 |
{
|
sl@0
|
242 |
TRequestStatus* s = &iStatus;
|
sl@0
|
243 |
iStatus = KRequestPending;
|
sl@0
|
244 |
User::RequestComplete(s,aError);
|
sl@0
|
245 |
SetActive();
|
sl@0
|
246 |
}
|
sl@0
|
247 |
|
sl@0
|
248 |
|
sl@0
|
249 |
void CBaseTestCase::DoCancel()
|
sl@0
|
250 |
{
|
sl@0
|
251 |
LOG_FUNC
|
sl@0
|
252 |
iTimer.Cancel();
|
sl@0
|
253 |
if(iHost)
|
sl@0
|
254 |
{
|
sl@0
|
255 |
HostDoCancel();
|
sl@0
|
256 |
}
|
sl@0
|
257 |
else
|
sl@0
|
258 |
{
|
sl@0
|
259 |
DeviceDoCancel();
|
sl@0
|
260 |
}
|
sl@0
|
261 |
}
|
sl@0
|
262 |
|
sl@0
|
263 |
void CBaseTestCase::RunL()
|
sl@0
|
264 |
{
|
sl@0
|
265 |
if(iHost)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
HostRunL();
|
sl@0
|
268 |
}
|
sl@0
|
269 |
else
|
sl@0
|
270 |
{
|
sl@0
|
271 |
DeviceRunL();
|
sl@0
|
272 |
}
|
sl@0
|
273 |
}
|
sl@0
|
274 |
|
sl@0
|
275 |
TInt CBaseTestCase::RunError(TInt aError)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
LOG_FUNC
|
sl@0
|
278 |
RDebug::Printf("Test case C%lS::RunL left with %d",&iTestCaseId,aError);
|
sl@0
|
279 |
iTestPolicy->SignalTestComplete(aError);
|
sl@0
|
280 |
return KErrNone;
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
TDesC& CBaseTestCase::TestCaseId()
|
sl@0
|
284 |
{
|
sl@0
|
285 |
return iTestCaseId;
|
sl@0
|
286 |
}
|
sl@0
|
287 |
|
sl@0
|
288 |
|
sl@0
|
289 |
TInt CBaseTestCase::TestResult() const
|
sl@0
|
290 |
{
|
sl@0
|
291 |
return iTestResult;
|
sl@0
|
292 |
}
|
sl@0
|
293 |
|
sl@0
|
294 |
TBool CBaseTestCase::IsHostOnly() const
|
sl@0
|
295 |
{
|
sl@0
|
296 |
return iHostOnly;
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
TBool CBaseTestCase::IsHost() const
|
sl@0
|
300 |
{
|
sl@0
|
301 |
return iHost;
|
sl@0
|
302 |
}
|
sl@0
|
303 |
|
sl@0
|
304 |
void CBaseTestCase::PerformTestL()
|
sl@0
|
305 |
{
|
sl@0
|
306 |
|
sl@0
|
307 |
if(iHost)
|
sl@0
|
308 |
{
|
sl@0
|
309 |
iTreeBuffer.CreateL(KTreeBufferSize); //32k
|
sl@0
|
310 |
ExecuteHostTestCaseL();
|
sl@0
|
311 |
}
|
sl@0
|
312 |
else
|
sl@0
|
313 |
{
|
sl@0
|
314 |
ExecuteDeviceTestCaseL();
|
sl@0
|
315 |
}
|
sl@0
|
316 |
}
|
sl@0
|
317 |
|
sl@0
|
318 |
void CBaseTestCase::SetTestPolicy(CBasicTestPolicy* aTestPolicy)
|
sl@0
|
319 |
{
|
sl@0
|
320 |
iTestPolicy = aTestPolicy;
|
sl@0
|
321 |
}
|
sl@0
|
322 |
|
sl@0
|
323 |
void CBaseTestCase::TestFailed(TInt aFailResult)
|
sl@0
|
324 |
{
|
sl@0
|
325 |
LOG_FUNC
|
sl@0
|
326 |
iTestResult = aFailResult;
|
sl@0
|
327 |
if(!iHostOnly)
|
sl@0
|
328 |
{
|
sl@0
|
329 |
RDebug::Printf("CActiveScheduler::Stop CBaseTestCase::TestFailed");
|
sl@0
|
330 |
CActiveScheduler::Stop();
|
sl@0
|
331 |
}
|
sl@0
|
332 |
}
|
sl@0
|
333 |
|
sl@0
|
334 |
void CBaseTestCase::TestPassed()
|
sl@0
|
335 |
{
|
sl@0
|
336 |
LOG_FUNC
|
sl@0
|
337 |
iTestResult = KErrNone;
|
sl@0
|
338 |
if(!iHostOnly)
|
sl@0
|
339 |
{
|
sl@0
|
340 |
RDebug::Printf("CActiveScheduler::Stop CBaseTestCase::TestPassed");
|
sl@0
|
341 |
CActiveScheduler::Stop();
|
sl@0
|
342 |
}
|
sl@0
|
343 |
}
|
sl@0
|
344 |
|
sl@0
|
345 |
CBasicTestPolicy& CBaseTestCase::TestPolicy()
|
sl@0
|
346 |
{
|
sl@0
|
347 |
return *iTestPolicy;
|
sl@0
|
348 |
}
|
sl@0
|
349 |
|
sl@0
|
350 |
|
sl@0
|
351 |
/**
|
sl@0
|
352 |
Gets the first endpoint address that satisfies the parameters
|
sl@0
|
353 |
So caution when there are multiple endpoints on the interface setting
|
sl@0
|
354 |
See method below for specifying the endpoint index if more than
|
sl@0
|
355 |
one endpoint of the given type exists on the interface setting
|
sl@0
|
356 |
*/
|
sl@0
|
357 |
TInt CBaseTestCase::GetEndpointAddress(RUsbInterface& aUsbInterface,TInt aInterfaceSetting,
|
sl@0
|
358 |
TUint8 aTransferType,TUint8 aDirection,TInt& aEndpointAddress)
|
sl@0
|
359 |
{
|
sl@0
|
360 |
LOG_FUNC
|
sl@0
|
361 |
|
sl@0
|
362 |
return GetEndpointAddress(aUsbInterface, aInterfaceSetting, aTransferType, aDirection, 0, aEndpointAddress);
|
sl@0
|
363 |
}
|
sl@0
|
364 |
|
sl@0
|
365 |
/**
|
sl@0
|
366 |
Gets the (aIndex+1)th endpoint address that satisfies the parameters
|
sl@0
|
367 |
Allows the specification of the endpoint index (starting from ZERO)if more than
|
sl@0
|
368 |
one endpoint of the given type exists on the interface setting
|
sl@0
|
369 |
*/
|
sl@0
|
370 |
TInt CBaseTestCase::GetEndpointAddress(RUsbInterface& aUsbInterface,TInt aInterfaceSetting,
|
sl@0
|
371 |
TUint8 aTransferType,TUint8 aDirection,TUint8 aIndex,TInt& aEndpointAddress)
|
sl@0
|
372 |
{
|
sl@0
|
373 |
LOG_FUNC
|
sl@0
|
374 |
|
sl@0
|
375 |
// Get the interface descriptor
|
sl@0
|
376 |
RDebug::Printf("Getting the interface descriptor for this alternate setting");
|
sl@0
|
377 |
|
sl@0
|
378 |
TUsbInterfaceDescriptor alternateInterfaceDescriptor;
|
sl@0
|
379 |
TInt err = aUsbInterface.GetAlternateInterfaceDescriptor(aInterfaceSetting, alternateInterfaceDescriptor);
|
sl@0
|
380 |
|
sl@0
|
381 |
if(err)
|
sl@0
|
382 |
{
|
sl@0
|
383 |
RDebug::Printf("<Error %d> Unable to get alternate interface (%d) descriptor",err,aInterfaceSetting);
|
sl@0
|
384 |
return err;
|
sl@0
|
385 |
}
|
sl@0
|
386 |
|
sl@0
|
387 |
// Parse the descriptor tree from the interface
|
sl@0
|
388 |
RDebug::Printf("Search the child descriptors for matching endpoint attributes");
|
sl@0
|
389 |
|
sl@0
|
390 |
TUsbGenericDescriptor* descriptor = alternateInterfaceDescriptor.iFirstChild;
|
sl@0
|
391 |
TUint8 indexCount = 0;
|
sl@0
|
392 |
while(descriptor)
|
sl@0
|
393 |
{
|
sl@0
|
394 |
RDebug::Printf("Check descriptor type for endpoint");
|
sl@0
|
395 |
|
sl@0
|
396 |
// Cast the descriptor to an endpoint descriptor
|
sl@0
|
397 |
TUsbEndpointDescriptor* endpoint = TUsbEndpointDescriptor::Cast(descriptor);
|
sl@0
|
398 |
|
sl@0
|
399 |
if(endpoint)
|
sl@0
|
400 |
{
|
sl@0
|
401 |
RDebug::Printf("Match attributes for transfer type");
|
sl@0
|
402 |
|
sl@0
|
403 |
if( (endpoint->Attributes() & aTransferType) == aTransferType)
|
sl@0
|
404 |
{
|
sl@0
|
405 |
RDebug::Printf("Match attributes for endpoint direction");
|
sl@0
|
406 |
|
sl@0
|
407 |
if( (endpoint->EndpointAddress() & aDirection) == aDirection)
|
sl@0
|
408 |
{
|
sl@0
|
409 |
if(indexCount==aIndex)
|
sl@0
|
410 |
{
|
sl@0
|
411 |
aEndpointAddress = endpoint->EndpointAddress();
|
sl@0
|
412 |
RDebug::Printf("Endpoint address found");
|
sl@0
|
413 |
return KErrNone;
|
sl@0
|
414 |
}
|
sl@0
|
415 |
else
|
sl@0
|
416 |
{
|
sl@0
|
417 |
indexCount++;
|
sl@0
|
418 |
}
|
sl@0
|
419 |
}
|
sl@0
|
420 |
}
|
sl@0
|
421 |
}
|
sl@0
|
422 |
|
sl@0
|
423 |
descriptor = descriptor->iNextPeer;
|
sl@0
|
424 |
}
|
sl@0
|
425 |
|
sl@0
|
426 |
// Unable to find the endpoint address
|
sl@0
|
427 |
RDebug::Printf("Unable to find endpoint address matching the specified attributes");
|
sl@0
|
428 |
|
sl@0
|
429 |
return KErrNotFound;
|
sl@0
|
430 |
}
|
sl@0
|
431 |
|
sl@0
|
432 |
/*static*/ void CBaseTestCase::LogWithCondAndInfo(const TDesC& aCondition, const TDesC& aFileName, TInt aLine)
|
sl@0
|
433 |
{
|
sl@0
|
434 |
TBuf<256> buf;
|
sl@0
|
435 |
buf.Format(KFailText, &aCondition, &aFileName, aLine);
|
sl@0
|
436 |
RDebug::Print(buf);
|
sl@0
|
437 |
}
|
sl@0
|
438 |
|
sl@0
|
439 |
|
sl@0
|
440 |
/*static*/ void CBaseTestCase::PrintAndStoreTree(TUsbGenericDescriptor& aDesc, TInt aDepth)
|
sl@0
|
441 |
{
|
sl@0
|
442 |
|
sl@0
|
443 |
TBuf8<20> buf;
|
sl@0
|
444 |
for(TInt depth=aDepth;depth>=0;--depth)
|
sl@0
|
445 |
{
|
sl@0
|
446 |
buf.Append(_L8(" "));
|
sl@0
|
447 |
}
|
sl@0
|
448 |
|
sl@0
|
449 |
//##==TBuf16<40> unicodeBuf;
|
sl@0
|
450 |
TBuf8<40> unicodeBuf;
|
sl@0
|
451 |
unicodeBuf.Copy(buf); // Ideally this needs conversion to UNICODE
|
sl@0
|
452 |
if(aDesc.iRecognisedAndParsed == TUsbGenericDescriptor::ERecognised)
|
sl@0
|
453 |
{
|
sl@0
|
454 |
RDebug::Printf("%S+ length=%d, type=0x%02x", &unicodeBuf, aDesc.ibLength, aDesc.ibDescriptorType);
|
sl@0
|
455 |
iTreeBuffer.AppendFormat(_L8("%S+ length=%d, type=0x%02x\n"), &buf, aDesc.ibLength, aDesc.ibDescriptorType);
|
sl@0
|
456 |
}
|
sl@0
|
457 |
else
|
sl@0
|
458 |
{
|
sl@0
|
459 |
RDebug::Printf("%S- length=%d, type=0x%02x", &unicodeBuf, aDesc.ibLength, aDesc.ibDescriptorType);
|
sl@0
|
460 |
iTreeBuffer.AppendFormat(_L8("%S- length=%d, type=0x%02x\n"), &buf, aDesc.ibLength, aDesc.ibDescriptorType);
|
sl@0
|
461 |
}
|
sl@0
|
462 |
|
sl@0
|
463 |
PrintAndStoreBlob(buf ,aDesc.iBlob);
|
sl@0
|
464 |
|
sl@0
|
465 |
if(aDesc.iFirstChild)
|
sl@0
|
466 |
{
|
sl@0
|
467 |
RDebug::Printf("%S \\ ", &unicodeBuf);
|
sl@0
|
468 |
iTreeBuffer.AppendFormat(_L8("%S \\ \n"), &buf);
|
sl@0
|
469 |
|
sl@0
|
470 |
PrintAndStoreTree(*(aDesc.iFirstChild), aDepth+1);
|
sl@0
|
471 |
|
sl@0
|
472 |
RDebug::Printf("%S / ", &unicodeBuf);
|
sl@0
|
473 |
iTreeBuffer.AppendFormat(_L8("%S / \n"), &buf);
|
sl@0
|
474 |
}
|
sl@0
|
475 |
if(aDesc.iNextPeer)
|
sl@0
|
476 |
{
|
sl@0
|
477 |
PrintAndStoreTree(*(aDesc.iNextPeer), aDepth);
|
sl@0
|
478 |
}
|
sl@0
|
479 |
}
|
sl@0
|
480 |
|
sl@0
|
481 |
void CBaseTestCase::PrintAndStoreBlob(TDes8& aBuf, TPtrC8& aBlob)
|
sl@0
|
482 |
{
|
sl@0
|
483 |
|
sl@0
|
484 |
HBufC8* chunk = HBufC8::New(KChunkSize);
|
sl@0
|
485 |
|
sl@0
|
486 |
TUint nbIter = aBlob.Length()/(KChunkSize/2);
|
sl@0
|
487 |
TUint remainderSize = aBlob.Length()%(KChunkSize/2);
|
sl@0
|
488 |
|
sl@0
|
489 |
if(nbIter == 0)
|
sl@0
|
490 |
{
|
sl@0
|
491 |
PrintAndStoreChunk(chunk, aBlob.Length() ,aBlob, 0, 0, aBuf );
|
sl@0
|
492 |
}
|
sl@0
|
493 |
else
|
sl@0
|
494 |
{
|
sl@0
|
495 |
// print chunks
|
sl@0
|
496 |
TUint offset = 0;
|
sl@0
|
497 |
TInt i = 0;
|
sl@0
|
498 |
for(i=0;i<nbIter;++i)
|
sl@0
|
499 |
{
|
sl@0
|
500 |
PrintAndStoreChunk(chunk, (KChunkSize/2) ,aBlob, offset, i, aBuf);
|
sl@0
|
501 |
offset+=(KChunkSize/2);
|
sl@0
|
502 |
}
|
sl@0
|
503 |
// remainder
|
sl@0
|
504 |
PrintAndStoreChunk(chunk, remainderSize ,aBlob,offset, i ,aBuf);
|
sl@0
|
505 |
}
|
sl@0
|
506 |
delete chunk;
|
sl@0
|
507 |
}
|
sl@0
|
508 |
|
sl@0
|
509 |
void CBaseTestCase::PrintAndStoreChunk(HBufC8* aChunk, TUint aSize, TPtrC8& aBlob, TUint aOffset, TUint aIter, TDes8& aBuf)
|
sl@0
|
510 |
{
|
sl@0
|
511 |
for(TInt i=0;i<aSize;++i)
|
sl@0
|
512 |
{
|
sl@0
|
513 |
aChunk->Des().AppendFormat(_L8("%02x"), aBlob[i+aOffset]);
|
sl@0
|
514 |
}
|
sl@0
|
515 |
|
sl@0
|
516 |
TBuf16<40> unicodeBuf;
|
sl@0
|
517 |
unicodeBuf.Copy(aBuf);
|
sl@0
|
518 |
TBuf16<256> unicodeChunk;
|
sl@0
|
519 |
unicodeChunk.Copy(aChunk->Des());
|
sl@0
|
520 |
|
sl@0
|
521 |
if(aIter ==0)
|
sl@0
|
522 |
{
|
sl@0
|
523 |
RDebug::Printf("%S >%S", &unicodeBuf, &unicodeChunk);
|
sl@0
|
524 |
iTreeBuffer.AppendFormat(_L8("%S >%S\n"), &aBuf, aChunk);
|
sl@0
|
525 |
}
|
sl@0
|
526 |
else
|
sl@0
|
527 |
{
|
sl@0
|
528 |
RDebug::Printf("%S %S\n", &unicodeBuf, &unicodeChunk);
|
sl@0
|
529 |
iTreeBuffer.AppendFormat(_L8("%S %S\n"), &aBuf, aChunk);
|
sl@0
|
530 |
}
|
sl@0
|
531 |
aChunk->Des().Zero();
|
sl@0
|
532 |
}
|
sl@0
|
533 |
|
sl@0
|
534 |
TInt CBaseTestCase::CheckTree(TUsbGenericDescriptor& aDevDesc, TUsbGenericDescriptor& aConfigDesc, const TDesC& aFileName)
|
sl@0
|
535 |
{
|
sl@0
|
536 |
LOG_FUNC
|
sl@0
|
537 |
TInt ret = KErrNone;
|
sl@0
|
538 |
|
sl@0
|
539 |
// flush buffer
|
sl@0
|
540 |
iTreeBuffer.Zero();
|
sl@0
|
541 |
|
sl@0
|
542 |
// print and store tree from aDevDesc & aConfigDesc
|
sl@0
|
543 |
PrintAndStoreTree(aDevDesc);
|
sl@0
|
544 |
PrintAndStoreTree(aConfigDesc);
|
sl@0
|
545 |
|
sl@0
|
546 |
// generate file if needed
|
sl@0
|
547 |
#ifdef GENERATE_TREES
|
sl@0
|
548 |
GenerateRefFile(aFileName);
|
sl@0
|
549 |
#endif // GENERATE_TREES
|
sl@0
|
550 |
|
sl@0
|
551 |
// compare tree to ref.
|
sl@0
|
552 |
TBool isIdentical;
|
sl@0
|
553 |
if(KErrNone != CompareCurrentTreeToRef(aFileName, isIdentical))
|
sl@0
|
554 |
{
|
sl@0
|
555 |
RDebug::Printf("CompareCurrentTreeToRef error");
|
sl@0
|
556 |
ret = KErrGeneral;
|
sl@0
|
557 |
}
|
sl@0
|
558 |
if(!isIdentical)
|
sl@0
|
559 |
{
|
sl@0
|
560 |
RDebug::Printf("!isIdentical");
|
sl@0
|
561 |
ret = KErrGeneral;
|
sl@0
|
562 |
}
|
sl@0
|
563 |
return ret;
|
sl@0
|
564 |
}
|
sl@0
|
565 |
|
sl@0
|
566 |
|
sl@0
|
567 |
TInt CBaseTestCase::ParseConfigDescriptorAndCheckTree(TUsbDeviceDescriptor *devDesc, const TDesC8& configSet, TUint indexTest)
|
sl@0
|
568 |
{
|
sl@0
|
569 |
LOG_FUNC
|
sl@0
|
570 |
// Parse config. descriptor
|
sl@0
|
571 |
TUsbGenericDescriptor* parsed = NULL;
|
sl@0
|
572 |
TInt err = UsbDescriptorParser::Parse(configSet, parsed);
|
sl@0
|
573 |
if(err != KErrNone)
|
sl@0
|
574 |
{
|
sl@0
|
575 |
RDebug::Printf("parsing error : UsbDescriptorParser::Parse");
|
sl@0
|
576 |
return err;
|
sl@0
|
577 |
}
|
sl@0
|
578 |
TUsbConfigurationDescriptor* configDesc = TUsbConfigurationDescriptor::Cast(parsed);
|
sl@0
|
579 |
// checks
|
sl@0
|
580 |
if(configDesc == 0)
|
sl@0
|
581 |
{
|
sl@0
|
582 |
RDebug::Printf("configDesc == 0");
|
sl@0
|
583 |
return KErrGeneral;
|
sl@0
|
584 |
}
|
sl@0
|
585 |
|
sl@0
|
586 |
// checking tree
|
sl@0
|
587 |
TBuf<KMaxName> fname(iTestCaseId);
|
sl@0
|
588 |
fname.AppendFormat(_L("_%d"), indexTest);
|
sl@0
|
589 |
return CheckTree(*devDesc, *configDesc, fname);
|
sl@0
|
590 |
}
|
sl@0
|
591 |
|
sl@0
|
592 |
TInt CBaseTestCase::CheckTreeAfterDeviceInsertion(CUsbTestDevice& aTestDevice, const TDesC& aFileName)
|
sl@0
|
593 |
{
|
sl@0
|
594 |
LOG_FUNC
|
sl@0
|
595 |
TUsbGenericDescriptor deviceDesc = aTestDevice.DeviceDescriptor();
|
sl@0
|
596 |
TUsbGenericDescriptor configDesc = aTestDevice.ConfigurationDescriptor();
|
sl@0
|
597 |
return CheckTree(deviceDesc, configDesc, aFileName);
|
sl@0
|
598 |
}
|
sl@0
|
599 |
|
sl@0
|
600 |
}
|