First public contribution.
1 #ifndef __BASE_TEST_CASE_H
2 #define __BASE_TEST_CASE_H
5 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
7 * This component and the accompanying materials are made available
8 * under the terms of the License "Eclipse Public License v1.0"
9 * which accompanies this distribution, and is available
10 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
12 * Initial Contributors:
13 * Nokia Corporation - initial contribution.
18 * @file BaseTestCase.h
29 #include "testdebug.h"
31 namespace NUnitTesting_USBDI
35 #define _LITDBG(a) _LIT(lit, a)
40 // Constants for CBaseTestCase::GetEndpointAddress
42 extern const TUint8 KEpDirectionIn;
43 extern const TUint8 KEpDirectionOut;
44 extern const TUint8 KTransferTypeControl;
45 extern const TUint8 KTransferTypeIsoch;
46 extern const TUint8 KTransferTypeBulk;
47 extern const TUint8 KTransferTypeInterrupt;
49 // Forward declarations
51 class CBasicTestPolicy;
53 #define WS_FILENAME(f) _LIT(KFileName, f);
54 #define WS_CONDITION(c) _LIT(KCondition, c);
55 _LIT(KFailText, "CHECK fails ---> %S, in file %S @ line %i");
57 // Utility macro to tidy up the test
58 #define CHECK(aCondition)\
61 WS_FILENAME(__FILE__);\
62 WS_CONDITION(#aCondition);\
63 CBaseTestCase::LogWithCondAndInfo(KCondition, KFileName, __LINE__);\
64 return TestFailed(KErrAbort);\
67 // Utility macro to tidy up the test
68 #define CHECK_RET_BOOL(aCondition)\
71 WS_FILENAME(__FILE__);\
72 WS_CONDITION(#aCondition);\
73 CBaseTestCase::LogWithCondAndInfo(KCondition, KFileName, __LINE__);\
77 Base policy class for test cases. Test cases are active objects that execute their respective test cases
78 and asynchronously complete when test case has finished
80 class CBaseTestCase : public CActive
86 virtual ~CBaseTestCase();
90 void SetTestPolicy(CBasicTestPolicy* aTestPolicy);
93 Performs the test case
98 Provides to the caller the identity of this test case
99 @return descriptor referrence to the test case identity
104 Retrieve the test result for the executed test case
105 @return the test case result
107 TInt TestResult() const;
110 Check if the test is only be run on the host(no synch. with client needed)
111 @return True if test to be run in host only.
113 TBool IsHostOnly() const;
116 Check if the test is only be run on the host(no synch. with client needed)
117 @return True if test to be run in host only.
119 TBool IsHost() const;
122 static method(util), used to log a test condition.
123 @param[in] aCondition checked condition
124 @param[in] aFileName __FILE__
125 @param[in] aLine __LINE__
127 static void LogWithCondAndInfo(const TDesC& aCondition, const TDesC& aFileName, TInt aLine);
129 protected: // From CActive
132 Called when Cancel is called (if active)
137 Called when the this AO has been scheduled
142 This default implementation just informs the test controller that this specific test case RunL
143 left with the error code so that the active scheduler will not Panic. This indicates that the test case failed.
144 Derived test cases are expected to override for exact knowledge of error
145 @param aError the error from a derived test case execution
148 virtual TInt RunError(TInt aError);
150 protected: // Tree checks
153 Store dev. and config. desc into internal buffer and check if it is identical to the reference one.
154 @param[in] aDevDesc parsed device descriptor
155 @param[in] aConfigDesc parsed config. descriptor
156 @param[in] aFileName file to be compared with the current tree(doesn't contain the path nor extension)
157 or to build a reference tree(after being manually checked once, it could be used as a ref.)
158 @return KErrNone if tree is identical to the ref. tree
160 TInt CheckTree(TUsbGenericDescriptor& aDevDesc, TUsbGenericDescriptor& aConfigDesc, const TDesC& aFileName);
163 Parse configuration descriptor raw data and check if the generated tree is identical to the ref. one.
164 FAILS the test if there is any difference.
165 @param[in] devDesc already parsed device descriptor
166 @param[in] configSet configuration descriptor raw data to be parsed
167 @param[in] indexTest index of the test(used to append a number to the generated file name)
168 @return KErrNone if parsing is ok and tree is identical to the ref. tree
170 TInt ParseConfigDescriptorAndCheckTree(TUsbDeviceDescriptor *devDesc, const TDesC8& configSet, TUint indexTest);
172 Parse configuration descriptor raw data and check if the generated tree is identical to the ref. one.
173 FAILS the test if there is any difference.
174 @param[in] aTestDevice device being tested tested
175 @param[in] aFileName file to be compared with the current tree(doesn't contain the path nor extension)
176 @return KErrNone if tree is identical to the ref. tree after a real device has been inserted.
178 TInt CheckTreeAfterDeviceInsertion(CUsbTestDevice& aTestDevice, const TDesC& aFileName);
183 @param aTestCaseId the identity that this test case is to represent
184 @param aHostFlag the flag for host role
186 CBaseTestCase(const TDesC& aTestCaseId,TBool aHostFlag, TBool aHostOnly = EFalse);
189 Base class 2nd phase constructor
191 void BaseConstructL();
192 virtual void ConstructL() = 0;
195 State that the test case has failed with the given error code
196 @param aFailResult the failiure result for the test case
198 void TestFailed(TInt aFailResult);
201 Instruct the test case that it has passed
206 Instruct the test case to asynchronously complete itself now
211 Instruct the test case to asynchronously complete itself now with the supplied error code.
212 @param aError the error code to complete this test case with.
214 void SelfComplete(TInt aError);
217 Timeout in the specified number of seconds
218 @param aTimeoutPeriod the timeout interval
220 void TimeoutIn(TInt aTimeoutPeriod);
223 Cancels the timeout for the test case step
225 void CancelTimeout();
229 CBasicTestPolicy& TestPolicy();
233 virtual void ExecuteHostTestCaseL() = 0;
234 virtual void HostRunL() = 0;
235 virtual void HostDoCancel() = 0;
239 virtual void ExecuteDeviceTestCaseL() = 0;
240 virtual void DeviceRunL() = 0;
241 virtual void DeviceDoCancel() = 0;
246 Finds the address of the first endpoint with the specification of direction and type
247 @param aUsbInterface the interface that has the correct interface setting
248 @param aInterfaceSetting the alternate interface setting which has the endpoint
249 @param aTransferType the type of transfer for this endpoint
250 @param aDirection the direction of the endpoint in the host transfer
251 @param[out] on return, the first endpoint address found
252 @return KErrNone if successful or a system wide error code
254 TInt GetEndpointAddress(RUsbInterface& aUsbInterface,TInt aInterfaceSetting,
255 TUint8 aTransferType,TUint8 aDirection,TInt& aEndpointAddress);
258 Finds the address of the (index+1)th endpoint with the specification of direction and type
259 @param aUsbInterface the interface that has the correct interface setting
260 @param aInterfaceSetting the alternate interface setting which has the endpoint
261 @param aTransferType the type of transfer for this endpoint
262 @param aDirection the direction of the endpoint in the host transfer
263 @param[out] on return, the first endpoint address found
264 @return KErrNone if successful or a system wide error code
266 TInt GetEndpointAddress(RUsbInterface& aUsbInterface,TInt aInterfaceSetting,
267 TUint8 aTransferType,TUint8 aDirection,TUint8 aIndex, TInt& aEndpointAddress);
272 The timer resource for timeout of test actions
273 and possibly other uses
278 The execution result for the test case
285 Print the tree(logging) and store it into iTreeBuffer.
286 @param[in] aDesc usb descriptor(likely to be device descriptor or configuration one)
287 @param[in] aDepth tree depth
289 void PrintAndStoreTree(TUsbGenericDescriptor& aDesc, TInt aDepth = 0);
292 Print a blob(logging) and store it into iTreeBuffer.
293 @param[in] aBuf usb descriptor(likely to be device descriptor or configuration one)
294 @param[in] aBlob tree depth
296 void PrintAndStoreBlob(TDes8& aBuf, TPtrC8& aBlob);
299 Print a chunk(logging) and store it into iTreeBuffer.
300 @param[in] aChunk chunk buffer
301 @param[in] aSize nb of data(for writtings in one go)
302 @param[in] aBlob whole Blob
303 @param[in] aOffset offset of blob(for writtings in several times)
304 @param[in] aIter index of chunk(for writtings in several times)
305 @param[in] aBuf buffer needed for proper indentation
307 void PrintAndStoreChunk(HBufC8* aChunk, TUint aSize, TPtrC8& aBlob, TUint aOffset, TUint aIter, TDes8& aBuf);
310 Generate a Ref. file representing the tree(flushing iTreeBuffer)
311 @param[in] aFileName file name(doesn't contain the path nor extension)
312 @return KErrNone if successfull.
314 TInt GenerateRefFile(const TDesC& aFileName);
317 Compare the current tree(iTreeBuffer) to a reference.
318 @param[in] aFileName ref. file name(doesn't contain the path nor extension)
319 @param[out] aIsIdentical True if equal to the ref.
320 @return KErrNone if successfull.
322 TInt CompareCurrentTreeToRef(const TDesC& aFileName, TBool& aIsIdentical);
327 The identity of the test case
329 TBuf<KMaxName> iTestCaseId;
333 CBasicTestPolicy* iTestPolicy;
336 The flag to indicate if this is a test case that performs host test actions
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.
346 Heap buffer which contains the descriptors tree.
351 Hanlde to a file session server