sl@0
|
1 |
#ifndef __BASE_TEST_CASE_H
|
sl@0
|
2 |
#define __BASE_TEST_CASE_H
|
sl@0
|
3 |
|
sl@0
|
4 |
/*
|
sl@0
|
5 |
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
6 |
* All rights reserved.
|
sl@0
|
7 |
* This component and the accompanying materials are made available
|
sl@0
|
8 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
9 |
* which accompanies this distribution, and is available
|
sl@0
|
10 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Initial Contributors:
|
sl@0
|
13 |
* Nokia Corporation - initial contribution.
|
sl@0
|
14 |
*
|
sl@0
|
15 |
* Contributors:
|
sl@0
|
16 |
*
|
sl@0
|
17 |
* Description:
|
sl@0
|
18 |
* @file BaseTestCase.h
|
sl@0
|
19 |
* @internalComponent
|
sl@0
|
20 |
*
|
sl@0
|
21 |
*
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
|
sl@0
|
26 |
#include <e32base.h>
|
sl@0
|
27 |
#include <d32usbdi.h>
|
sl@0
|
28 |
#include "FDFActor.h"
|
sl@0
|
29 |
#include "testdebug.h"
|
sl@0
|
30 |
|
sl@0
|
31 |
namespace NUnitTesting_USBDI
|
sl@0
|
32 |
{
|
sl@0
|
33 |
|
sl@0
|
34 |
#ifdef _DEBUG
|
sl@0
|
35 |
#define _LITDBG(a) _LIT(lit, a)
|
sl@0
|
36 |
#else
|
sl@0
|
37 |
#define _LITDBG(a)
|
sl@0
|
38 |
#endif
|
sl@0
|
39 |
|
sl@0
|
40 |
// Constants for CBaseTestCase::GetEndpointAddress
|
sl@0
|
41 |
|
sl@0
|
42 |
extern const TUint8 KEpDirectionIn;
|
sl@0
|
43 |
extern const TUint8 KEpDirectionOut;
|
sl@0
|
44 |
extern const TUint8 KTransferTypeControl;
|
sl@0
|
45 |
extern const TUint8 KTransferTypeIsoch;
|
sl@0
|
46 |
extern const TUint8 KTransferTypeBulk;
|
sl@0
|
47 |
extern const TUint8 KTransferTypeInterrupt;
|
sl@0
|
48 |
|
sl@0
|
49 |
// Forward declarations
|
sl@0
|
50 |
|
sl@0
|
51 |
class CBasicTestPolicy;
|
sl@0
|
52 |
|
sl@0
|
53 |
#define WS_FILENAME(f) _LIT(KFileName, f);
|
sl@0
|
54 |
#define WS_CONDITION(c) _LIT(KCondition, c);
|
sl@0
|
55 |
_LIT(KFailText, "CHECK fails ---> %S, in file %S @ line %i");
|
sl@0
|
56 |
|
sl@0
|
57 |
// Utility macro to tidy up the test
|
sl@0
|
58 |
#define CHECK(aCondition)\
|
sl@0
|
59 |
if(!(aCondition))\
|
sl@0
|
60 |
{\
|
sl@0
|
61 |
WS_FILENAME(__FILE__);\
|
sl@0
|
62 |
WS_CONDITION(#aCondition);\
|
sl@0
|
63 |
CBaseTestCase::LogWithCondAndInfo(KCondition, KFileName, __LINE__);\
|
sl@0
|
64 |
return TestFailed(KErrAbort);\
|
sl@0
|
65 |
}\
|
sl@0
|
66 |
|
sl@0
|
67 |
// Utility macro to tidy up the test
|
sl@0
|
68 |
#define CHECK_RET_BOOL(aCondition)\
|
sl@0
|
69 |
if(!(aCondition))\
|
sl@0
|
70 |
{\
|
sl@0
|
71 |
WS_FILENAME(__FILE__);\
|
sl@0
|
72 |
WS_CONDITION(#aCondition);\
|
sl@0
|
73 |
CBaseTestCase::LogWithCondAndInfo(KCondition, KFileName, __LINE__);\
|
sl@0
|
74 |
return EFalse;\
|
sl@0
|
75 |
}\
|
sl@0
|
76 |
/**
|
sl@0
|
77 |
Base policy class for test cases. Test cases are active objects that execute their respective test cases
|
sl@0
|
78 |
and asynchronously complete when test case has finished
|
sl@0
|
79 |
*/
|
sl@0
|
80 |
class CBaseTestCase : public CActive
|
sl@0
|
81 |
{
|
sl@0
|
82 |
public:
|
sl@0
|
83 |
/**
|
sl@0
|
84 |
Destructor
|
sl@0
|
85 |
*/
|
sl@0
|
86 |
virtual ~CBaseTestCase();
|
sl@0
|
87 |
|
sl@0
|
88 |
/**
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
void SetTestPolicy(CBasicTestPolicy* aTestPolicy);
|
sl@0
|
91 |
|
sl@0
|
92 |
/**
|
sl@0
|
93 |
Performs the test case
|
sl@0
|
94 |
*/
|
sl@0
|
95 |
void PerformTestL();
|
sl@0
|
96 |
|
sl@0
|
97 |
/**
|
sl@0
|
98 |
Provides to the caller the identity of this test case
|
sl@0
|
99 |
@return descriptor referrence to the test case identity
|
sl@0
|
100 |
*/
|
sl@0
|
101 |
TDesC& TestCaseId();
|
sl@0
|
102 |
|
sl@0
|
103 |
/**
|
sl@0
|
104 |
Retrieve the test result for the executed test case
|
sl@0
|
105 |
@return the test case result
|
sl@0
|
106 |
*/
|
sl@0
|
107 |
TInt TestResult() const;
|
sl@0
|
108 |
|
sl@0
|
109 |
/**
|
sl@0
|
110 |
Check if the test is only be run on the host(no synch. with client needed)
|
sl@0
|
111 |
@return True if test to be run in host only.
|
sl@0
|
112 |
*/
|
sl@0
|
113 |
TBool IsHostOnly() const;
|
sl@0
|
114 |
|
sl@0
|
115 |
/**
|
sl@0
|
116 |
Check if the test is only be run on the host(no synch. with client needed)
|
sl@0
|
117 |
@return True if test to be run in host only.
|
sl@0
|
118 |
*/
|
sl@0
|
119 |
TBool IsHost() const;
|
sl@0
|
120 |
|
sl@0
|
121 |
/**
|
sl@0
|
122 |
static method(util), used to log a test condition.
|
sl@0
|
123 |
@param[in] aCondition checked condition
|
sl@0
|
124 |
@param[in] aFileName __FILE__
|
sl@0
|
125 |
@param[in] aLine __LINE__
|
sl@0
|
126 |
*/
|
sl@0
|
127 |
static void LogWithCondAndInfo(const TDesC& aCondition, const TDesC& aFileName, TInt aLine);
|
sl@0
|
128 |
|
sl@0
|
129 |
protected: // From CActive
|
sl@0
|
130 |
|
sl@0
|
131 |
/**
|
sl@0
|
132 |
Called when Cancel is called (if active)
|
sl@0
|
133 |
*/
|
sl@0
|
134 |
void DoCancel();
|
sl@0
|
135 |
|
sl@0
|
136 |
/**
|
sl@0
|
137 |
Called when the this AO has been scheduled
|
sl@0
|
138 |
*/
|
sl@0
|
139 |
void RunL();
|
sl@0
|
140 |
|
sl@0
|
141 |
/**
|
sl@0
|
142 |
This default implementation just informs the test controller that this specific test case RunL
|
sl@0
|
143 |
left with the error code so that the active scheduler will not Panic. This indicates that the test case failed.
|
sl@0
|
144 |
Derived test cases are expected to override for exact knowledge of error
|
sl@0
|
145 |
@param aError the error from a derived test case execution
|
sl@0
|
146 |
@return KErrNone
|
sl@0
|
147 |
*/
|
sl@0
|
148 |
virtual TInt RunError(TInt aError);
|
sl@0
|
149 |
|
sl@0
|
150 |
protected: // Tree checks
|
sl@0
|
151 |
|
sl@0
|
152 |
/**
|
sl@0
|
153 |
Store dev. and config. desc into internal buffer and check if it is identical to the reference one.
|
sl@0
|
154 |
@param[in] aDevDesc parsed device descriptor
|
sl@0
|
155 |
@param[in] aConfigDesc parsed config. descriptor
|
sl@0
|
156 |
@param[in] aFileName file to be compared with the current tree(doesn't contain the path nor extension)
|
sl@0
|
157 |
or to build a reference tree(after being manually checked once, it could be used as a ref.)
|
sl@0
|
158 |
@return KErrNone if tree is identical to the ref. tree
|
sl@0
|
159 |
*/
|
sl@0
|
160 |
TInt CheckTree(TUsbGenericDescriptor& aDevDesc, TUsbGenericDescriptor& aConfigDesc, const TDesC& aFileName);
|
sl@0
|
161 |
|
sl@0
|
162 |
/**
|
sl@0
|
163 |
Parse configuration descriptor raw data and check if the generated tree is identical to the ref. one.
|
sl@0
|
164 |
FAILS the test if there is any difference.
|
sl@0
|
165 |
@param[in] devDesc already parsed device descriptor
|
sl@0
|
166 |
@param[in] configSet configuration descriptor raw data to be parsed
|
sl@0
|
167 |
@param[in] indexTest index of the test(used to append a number to the generated file name)
|
sl@0
|
168 |
@return KErrNone if parsing is ok and tree is identical to the ref. tree
|
sl@0
|
169 |
*/
|
sl@0
|
170 |
TInt ParseConfigDescriptorAndCheckTree(TUsbDeviceDescriptor *devDesc, const TDesC8& configSet, TUint indexTest);
|
sl@0
|
171 |
/**
|
sl@0
|
172 |
Parse configuration descriptor raw data and check if the generated tree is identical to the ref. one.
|
sl@0
|
173 |
FAILS the test if there is any difference.
|
sl@0
|
174 |
@param[in] aTestDevice device being tested tested
|
sl@0
|
175 |
@param[in] aFileName file to be compared with the current tree(doesn't contain the path nor extension)
|
sl@0
|
176 |
@return KErrNone if tree is identical to the ref. tree after a real device has been inserted.
|
sl@0
|
177 |
*/
|
sl@0
|
178 |
TInt CheckTreeAfterDeviceInsertion(CUsbTestDevice& aTestDevice, const TDesC& aFileName);
|
sl@0
|
179 |
|
sl@0
|
180 |
protected:
|
sl@0
|
181 |
/**
|
sl@0
|
182 |
Constructor
|
sl@0
|
183 |
@param aTestCaseId the identity that this test case is to represent
|
sl@0
|
184 |
@param aHostFlag the flag for host role
|
sl@0
|
185 |
*/
|
sl@0
|
186 |
CBaseTestCase(const TDesC& aTestCaseId,TBool aHostFlag, TBool aHostOnly = EFalse);
|
sl@0
|
187 |
|
sl@0
|
188 |
/**
|
sl@0
|
189 |
Base class 2nd phase constructor
|
sl@0
|
190 |
*/
|
sl@0
|
191 |
void BaseConstructL();
|
sl@0
|
192 |
virtual void ConstructL() = 0;
|
sl@0
|
193 |
|
sl@0
|
194 |
/**
|
sl@0
|
195 |
State that the test case has failed with the given error code
|
sl@0
|
196 |
@param aFailResult the failiure result for the test case
|
sl@0
|
197 |
*/
|
sl@0
|
198 |
void TestFailed(TInt aFailResult);
|
sl@0
|
199 |
|
sl@0
|
200 |
/**
|
sl@0
|
201 |
Instruct the test case that it has passed
|
sl@0
|
202 |
*/
|
sl@0
|
203 |
void TestPassed();
|
sl@0
|
204 |
|
sl@0
|
205 |
/**
|
sl@0
|
206 |
Instruct the test case to asynchronously complete itself now
|
sl@0
|
207 |
*/
|
sl@0
|
208 |
void SelfComplete();
|
sl@0
|
209 |
|
sl@0
|
210 |
/**
|
sl@0
|
211 |
Instruct the test case to asynchronously complete itself now with the supplied error code.
|
sl@0
|
212 |
@param aError the error code to complete this test case with.
|
sl@0
|
213 |
*/
|
sl@0
|
214 |
void SelfComplete(TInt aError);
|
sl@0
|
215 |
|
sl@0
|
216 |
/**
|
sl@0
|
217 |
Timeout in the specified number of seconds
|
sl@0
|
218 |
@param aTimeoutPeriod the timeout interval
|
sl@0
|
219 |
*/
|
sl@0
|
220 |
void TimeoutIn(TInt aTimeoutPeriod);
|
sl@0
|
221 |
|
sl@0
|
222 |
/**
|
sl@0
|
223 |
Cancels the timeout for the test case step
|
sl@0
|
224 |
*/
|
sl@0
|
225 |
void CancelTimeout();
|
sl@0
|
226 |
|
sl@0
|
227 |
/**
|
sl@0
|
228 |
*/
|
sl@0
|
229 |
CBasicTestPolicy& TestPolicy();
|
sl@0
|
230 |
|
sl@0
|
231 |
/**
|
sl@0
|
232 |
*/
|
sl@0
|
233 |
virtual void ExecuteHostTestCaseL() = 0;
|
sl@0
|
234 |
virtual void HostRunL() = 0;
|
sl@0
|
235 |
virtual void HostDoCancel() = 0;
|
sl@0
|
236 |
|
sl@0
|
237 |
/**
|
sl@0
|
238 |
*/
|
sl@0
|
239 |
virtual void ExecuteDeviceTestCaseL() = 0;
|
sl@0
|
240 |
virtual void DeviceRunL() = 0;
|
sl@0
|
241 |
virtual void DeviceDoCancel() = 0;
|
sl@0
|
242 |
|
sl@0
|
243 |
protected:
|
sl@0
|
244 |
|
sl@0
|
245 |
/**
|
sl@0
|
246 |
Finds the address of the first endpoint with the specification of direction and type
|
sl@0
|
247 |
@param aUsbInterface the interface that has the correct interface setting
|
sl@0
|
248 |
@param aInterfaceSetting the alternate interface setting which has the endpoint
|
sl@0
|
249 |
@param aTransferType the type of transfer for this endpoint
|
sl@0
|
250 |
@param aDirection the direction of the endpoint in the host transfer
|
sl@0
|
251 |
@param[out] on return, the first endpoint address found
|
sl@0
|
252 |
@return KErrNone if successful or a system wide error code
|
sl@0
|
253 |
*/
|
sl@0
|
254 |
TInt GetEndpointAddress(RUsbInterface& aUsbInterface,TInt aInterfaceSetting,
|
sl@0
|
255 |
TUint8 aTransferType,TUint8 aDirection,TInt& aEndpointAddress);
|
sl@0
|
256 |
|
sl@0
|
257 |
/**
|
sl@0
|
258 |
Finds the address of the (index+1)th endpoint with the specification of direction and type
|
sl@0
|
259 |
@param aUsbInterface the interface that has the correct interface setting
|
sl@0
|
260 |
@param aInterfaceSetting the alternate interface setting which has the endpoint
|
sl@0
|
261 |
@param aTransferType the type of transfer for this endpoint
|
sl@0
|
262 |
@param aDirection the direction of the endpoint in the host transfer
|
sl@0
|
263 |
@param[out] on return, the first endpoint address found
|
sl@0
|
264 |
@return KErrNone if successful or a system wide error code
|
sl@0
|
265 |
*/
|
sl@0
|
266 |
TInt GetEndpointAddress(RUsbInterface& aUsbInterface,TInt aInterfaceSetting,
|
sl@0
|
267 |
TUint8 aTransferType,TUint8 aDirection,TUint8 aIndex, TInt& aEndpointAddress);
|
sl@0
|
268 |
|
sl@0
|
269 |
protected:
|
sl@0
|
270 |
|
sl@0
|
271 |
/**
|
sl@0
|
272 |
The timer resource for timeout of test actions
|
sl@0
|
273 |
and possibly other uses
|
sl@0
|
274 |
*/
|
sl@0
|
275 |
RTimer iTimer;
|
sl@0
|
276 |
|
sl@0
|
277 |
/**
|
sl@0
|
278 |
The execution result for the test case
|
sl@0
|
279 |
*/
|
sl@0
|
280 |
TInt iTestResult;
|
sl@0
|
281 |
|
sl@0
|
282 |
private: // Tree
|
sl@0
|
283 |
|
sl@0
|
284 |
/**
|
sl@0
|
285 |
Print the tree(logging) and store it into iTreeBuffer.
|
sl@0
|
286 |
@param[in] aDesc usb descriptor(likely to be device descriptor or configuration one)
|
sl@0
|
287 |
@param[in] aDepth tree depth
|
sl@0
|
288 |
*/
|
sl@0
|
289 |
void PrintAndStoreTree(TUsbGenericDescriptor& aDesc, TInt aDepth = 0);
|
sl@0
|
290 |
|
sl@0
|
291 |
/**
|
sl@0
|
292 |
Print a blob(logging) and store it into iTreeBuffer.
|
sl@0
|
293 |
@param[in] aBuf usb descriptor(likely to be device descriptor or configuration one)
|
sl@0
|
294 |
@param[in] aBlob tree depth
|
sl@0
|
295 |
*/
|
sl@0
|
296 |
void PrintAndStoreBlob(TDes8& aBuf, TPtrC8& aBlob);
|
sl@0
|
297 |
|
sl@0
|
298 |
/**
|
sl@0
|
299 |
Print a chunk(logging) and store it into iTreeBuffer.
|
sl@0
|
300 |
@param[in] aChunk chunk buffer
|
sl@0
|
301 |
@param[in] aSize nb of data(for writtings in one go)
|
sl@0
|
302 |
@param[in] aBlob whole Blob
|
sl@0
|
303 |
@param[in] aOffset offset of blob(for writtings in several times)
|
sl@0
|
304 |
@param[in] aIter index of chunk(for writtings in several times)
|
sl@0
|
305 |
@param[in] aBuf buffer needed for proper indentation
|
sl@0
|
306 |
*/
|
sl@0
|
307 |
void PrintAndStoreChunk(HBufC8* aChunk, TUint aSize, TPtrC8& aBlob, TUint aOffset, TUint aIter, TDes8& aBuf);
|
sl@0
|
308 |
|
sl@0
|
309 |
/**
|
sl@0
|
310 |
Generate a Ref. file representing the tree(flushing iTreeBuffer)
|
sl@0
|
311 |
@param[in] aFileName file name(doesn't contain the path nor extension)
|
sl@0
|
312 |
@return KErrNone if successfull.
|
sl@0
|
313 |
*/
|
sl@0
|
314 |
TInt GenerateRefFile(const TDesC& aFileName);
|
sl@0
|
315 |
|
sl@0
|
316 |
/**
|
sl@0
|
317 |
Compare the current tree(iTreeBuffer) to a reference.
|
sl@0
|
318 |
@param[in] aFileName ref. file name(doesn't contain the path nor extension)
|
sl@0
|
319 |
@param[out] aIsIdentical True if equal to the ref.
|
sl@0
|
320 |
@return KErrNone if successfull.
|
sl@0
|
321 |
*/
|
sl@0
|
322 |
TInt CompareCurrentTreeToRef(const TDesC& aFileName, TBool& aIsIdentical);
|
sl@0
|
323 |
|
sl@0
|
324 |
private :
|
sl@0
|
325 |
|
sl@0
|
326 |
/**
|
sl@0
|
327 |
The identity of the test case
|
sl@0
|
328 |
*/
|
sl@0
|
329 |
TBuf<KMaxName> iTestCaseId;
|
sl@0
|
330 |
|
sl@0
|
331 |
/**
|
sl@0
|
332 |
*/
|
sl@0
|
333 |
CBasicTestPolicy* iTestPolicy;
|
sl@0
|
334 |
|
sl@0
|
335 |
/**
|
sl@0
|
336 |
The flag to indicate if this is a test case that performs host test actions
|
sl@0
|
337 |
*/
|
sl@0
|
338 |
TBool iHost;
|
sl@0
|
339 |
|
sl@0
|
340 |
/**
|
sl@0
|
341 |
The flag to indicate if this is a test case that is only run in host, and doesn't need synch. with a device.
|
sl@0
|
342 |
*/
|
sl@0
|
343 |
TBool iHostOnly;
|
sl@0
|
344 |
|
sl@0
|
345 |
/**
|
sl@0
|
346 |
Heap buffer which contains the descriptors tree.
|
sl@0
|
347 |
*/
|
sl@0
|
348 |
RBuf8 iTreeBuffer;
|
sl@0
|
349 |
|
sl@0
|
350 |
/**
|
sl@0
|
351 |
Hanlde to a file session server
|
sl@0
|
352 |
*/
|
sl@0
|
353 |
RFs iFs;
|
sl@0
|
354 |
};
|
sl@0
|
355 |
|
sl@0
|
356 |
}
|
sl@0
|
357 |
|
sl@0
|
358 |
#endif
|