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