os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/inc/BaseTestCase.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 #ifndef __BASE_TEST_CASE_H
     2 #define __BASE_TEST_CASE_H
     3 
     4 /*
     5 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     6 * All rights reserved.
     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".
    11 *
    12 * Initial Contributors:
    13 * Nokia Corporation - initial contribution.
    14 *
    15 * Contributors:
    16 *
    17 * Description:
    18 * @file BaseTestCase.h
    19 * @internalComponent
    20 * 
    21 *
    22 */
    23 
    24 
    25 
    26 #include <e32base.h>
    27 #include <d32usbdi.h>
    28 #include "FDFActor.h"
    29 #include "testdebug.h"
    30 
    31 namespace NUnitTesting_USBDI
    32 	{
    33 
    34 #ifdef _DEBUG
    35 #define _LITDBG(a)	_LIT(lit, a)
    36 #else
    37 #define _LITDBG(a)
    38 #endif
    39 	
    40 // Constants for CBaseTestCase::GetEndpointAddress
    41 
    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;
    48 	
    49 // Forward declarations
    50 
    51 class CBasicTestPolicy;
    52 
    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");
    56 
    57 // Utility macro to tidy up the test
    58 #define CHECK(aCondition)\
    59 	if(!(aCondition))\
    60 		{\
    61 		WS_FILENAME(__FILE__);\
    62 		WS_CONDITION(#aCondition);\
    63 		CBaseTestCase::LogWithCondAndInfo(KCondition, KFileName, __LINE__);\
    64 		return TestFailed(KErrAbort);\
    65 		}\
    66 		
    67 // Utility macro to tidy up the test
    68 #define CHECK_RET_BOOL(aCondition)\
    69 	if(!(aCondition))\
    70 		{\
    71 		WS_FILENAME(__FILE__);\
    72 		WS_CONDITION(#aCondition);\
    73 		CBaseTestCase::LogWithCondAndInfo(KCondition, KFileName, __LINE__);\
    74 		return EFalse;\
    75 		}\
    76 /**
    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
    79 */
    80 class CBaseTestCase : public CActive
    81 	{
    82 public:
    83 	/**
    84 	Destructor
    85 	*/
    86 	virtual ~CBaseTestCase();
    87 	
    88 	/**
    89 	*/
    90 	void SetTestPolicy(CBasicTestPolicy* aTestPolicy);
    91 	
    92 	/**
    93 	Performs the test case
    94 	*/
    95 	void PerformTestL();
    96 	
    97 	/**
    98 	Provides to the caller the identity of this test case
    99 	@return descriptor referrence to the test case identity
   100 	*/
   101 	TDesC& TestCaseId();
   102 	
   103 	/**
   104 	Retrieve the test result for the executed test case
   105 	@return the test case result
   106 	*/
   107 	TInt TestResult() const;
   108 		
   109 	/**
   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.
   112 	*/
   113 	TBool IsHostOnly() const;
   114 	
   115 	/**
   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.
   118 	*/
   119 	TBool IsHost() const;
   120 	
   121 	/** 
   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__ 	
   126 	*/	 
   127 	static void LogWithCondAndInfo(const TDesC& aCondition, const TDesC& aFileName, TInt aLine);
   128 	
   129 protected: // From CActive 
   130 	
   131 	/**
   132 	Called when Cancel is called (if active)
   133 	*/
   134 	void DoCancel();
   135 	
   136 	/**
   137 	Called when the this AO has been scheduled
   138 	*/
   139 	void RunL();
   140 	
   141 	/**
   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
   146 	@return KErrNone
   147 	*/
   148 	virtual TInt RunError(TInt aError);
   149 	
   150 protected: // Tree checks
   151 
   152 	/**
   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
   159 	*/
   160 	TInt CheckTree(TUsbGenericDescriptor& aDevDesc, TUsbGenericDescriptor& aConfigDesc, const TDesC& aFileName);
   161 	 
   162 	/**
   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
   169 	*/
   170 	TInt ParseConfigDescriptorAndCheckTree(TUsbDeviceDescriptor *devDesc, const TDesC8& configSet, TUint indexTest);
   171     	/**
   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.
   177 	*/
   178     TInt CheckTreeAfterDeviceInsertion(CUsbTestDevice& aTestDevice, const TDesC& aFileName);
   179 
   180 protected:
   181 	/**
   182 	Constructor
   183 	@param aTestCaseId the identity that this test case is to represent
   184 	@param aHostFlag the flag for host role
   185 	*/
   186 	CBaseTestCase(const TDesC& aTestCaseId,TBool aHostFlag, TBool aHostOnly = EFalse);
   187 	
   188 	/**
   189 	Base class 2nd phase constructor
   190 	*/
   191 	void BaseConstructL();	
   192 	virtual void ConstructL() = 0;
   193 	
   194 	/**
   195 	State that the test case has failed with the given error code
   196 	@param aFailResult the failiure result for the test case
   197 	*/
   198 	void TestFailed(TInt aFailResult);
   199 	
   200 	/**
   201 	Instruct the test case that it has passed
   202 	*/
   203 	void TestPassed();
   204 	
   205 	/**
   206 	Instruct the test case to asynchronously complete itself now
   207 	*/
   208 	void SelfComplete();
   209 	
   210 	/**
   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.
   213 	*/
   214 	void SelfComplete(TInt aError);
   215 
   216 	/**
   217 	Timeout in the specified number of seconds
   218 	@param aTimeoutPeriod the timeout interval 
   219 	*/
   220 	void TimeoutIn(TInt aTimeoutPeriod);
   221 	
   222 	/**
   223 	Cancels the timeout for the test case step
   224 	*/
   225 	void CancelTimeout();
   226 	
   227 	/**
   228 	*/	
   229 	CBasicTestPolicy& TestPolicy();
   230 	
   231 	/**
   232 	*/
   233 	virtual void ExecuteHostTestCaseL() = 0;
   234 	virtual void HostRunL() = 0;
   235 	virtual void HostDoCancel() = 0;
   236 	
   237 	/**
   238 	*/
   239 	virtual void ExecuteDeviceTestCaseL() = 0;
   240 	virtual void DeviceRunL() = 0;
   241 	virtual void DeviceDoCancel() = 0;
   242 
   243 protected:
   244 
   245 /**
   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
   253 */
   254 TInt GetEndpointAddress(RUsbInterface& aUsbInterface,TInt aInterfaceSetting,
   255 		TUint8 aTransferType,TUint8 aDirection,TInt& aEndpointAddress);
   256 
   257 /**
   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
   265 */
   266 TInt GetEndpointAddress(RUsbInterface& aUsbInterface,TInt aInterfaceSetting,
   267 		TUint8 aTransferType,TUint8 aDirection,TUint8 aIndex, TInt& aEndpointAddress);
   268 
   269 protected:
   270 
   271 	/**
   272 	The timer resource for timeout of test actions
   273 	and possibly other uses
   274 	*/
   275 	RTimer iTimer;	
   276 	
   277 	/**
   278 	The execution result for the test case
   279 	*/
   280 	TInt iTestResult;
   281 	
   282 private:  // Tree 
   283 
   284 	/**
   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
   288 	*/
   289     void PrintAndStoreTree(TUsbGenericDescriptor& aDesc, TInt aDepth = 0);
   290     
   291     /**
   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
   295 	*/	
   296 	void PrintAndStoreBlob(TDes8& aBuf, TPtrC8& aBlob);
   297 	
   298 	/** 
   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
   306 	*/
   307     void PrintAndStoreChunk(HBufC8* aChunk, TUint aSize, TPtrC8& aBlob, TUint aOffset, TUint aIter, TDes8& aBuf);
   308    	
   309    	/** 
   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.
   313 	*/
   314 	TInt GenerateRefFile(const TDesC& aFileName);
   315 	
   316 	/** 
   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.
   321 	*/
   322 	TInt CompareCurrentTreeToRef(const TDesC& aFileName, TBool& aIsIdentical);
   323 	
   324 private :
   325 
   326 	/**
   327 	The identity of the test case
   328 	*/
   329 	TBuf<KMaxName> iTestCaseId;
   330 	
   331 	/**
   332 	*/
   333 	CBasicTestPolicy* iTestPolicy;
   334 	
   335 	/**
   336 	The flag to indicate if this is a test case that performs host test actions
   337 	*/
   338 	TBool iHost;
   339 	
   340 	/** 
   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.
   342 	*/
   343 	TBool iHostOnly;
   344 	
   345 	/** 
   346 	Heap buffer which contains the descriptors tree.
   347 	*/
   348 	RBuf8 iTreeBuffer;
   349 	
   350 	/**
   351 	Hanlde to a file session server
   352 	*/
   353 	RFs iFs;
   354 	};
   355 
   356 	}
   357 	
   358 #endif