os/graphics/graphicstest/graphicstestharness/inc/extendtef.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicstest/graphicstestharness/inc/extendtef.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,413 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// These macros and templates extend the tef testsuite support.
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @test
    1.24 + @internalComponent - Internal Symbian test code
    1.25 +*/
    1.26 +
    1.27 +#ifndef __EXTENDTEF_H__
    1.28 +#define __EXTENDTEF_H__
    1.29 +
    1.30 +#include <test/tefunit.h>
    1.31 +
    1.32 +// Adds a test suite that is not called CreateSuiteL so that one class can describe multiple subsets of tests.
    1.33 +#define ADD_TEST_SUITE_SUB(subname) \
    1.34 +	_LIT( KTest ## subname, #subname); \
    1.35 +	lTestSuite->AddL( CreateSuiteSub##subname##L( KTest##subname));
    1.36 +
    1.37 +// Calls a subfunction to add more members to the current test suite at the current level. Can be the same function as used to create nested tests.
    1.38 +#define ADD_TEST_SUITE_SUB_FLAT(subname) \
    1.39 +	_LIT( KTest ## subname, #subname); \
    1.40 +	CreateSuiteSub##subname##L( KTest##subname,lTestSuite);
    1.41 +
    1.42 +// Allows the class suite to be added with a name different to the class name, so class names can be computational
    1.43 +#define ADD_TEST_SUITE_MODULE_SUB_AS(module,subname,as) \
    1.44 +	_LIT( KTest ## as, #as); \
    1.45 +	lTestSuite->AddL( module::CreateSuiteSub##subname##L( KTest##as));
    1.46 +
    1.47 +/** Use in a subsuite to distinguish between ADD_TEST_SUITE_SUB and ADD_TEST_SUITE_SUB_FLAT caller
    1.48 + *	ClassName is required - it defines the name of the class containing the referenced methods. 
    1.49 + *	aTestSuite is optional - it should be the function parameter aTestSuite or the keyword NULL 
    1.50 + **/
    1.51 +#define SUB_SUITE_OPT(ClassName,aTestSuite) \
    1.52 +	CTestSuite* lTestSuite = aTestSuite? (CTestSuite*)aTestSuite: CTestSuite::NewL(aName); \
    1.53 +	typedef ClassName	ThisThis;
    1.54 +
    1.55 +// Create a dotted name subtest in the script that represents a parameter to the named test
    1.56 +// This should be called from a ADD_TEST_SUITE_SUB with the same name as the test method,
    1.57 +// so that entries can be inserted of the form CMyTestClass.MyTest.EColor256
    1.58 +#define ADD_TEST_STEP_PARAM_1(method,param)	\
    1.59 +	_LIT( KTest ## method ## param, #param); \
    1.60 +	AddTestCaseParam(lTestSuite, KTest ## method ## param, method, param);
    1.61 +
    1.62 +// Insert a test that takes a parameter and a range of dotted subtests that set that parameter
    1.63 +// This allows tests of the form CMyTestClass.MyLoopTest.8
    1.64 +#define ADD_TEST_STEP_PARAM_RANGE(method,minparam,maxparam)	\
    1.65 +	_LIT(KTest ## method,#method); \
    1.66 +	AddTestCaseParamRangeL(lTestSuite,KTest ## method,&ThisThis::method,minparam,maxparam);
    1.67 +
    1.68 +// Insert a test that takes a parameter and a range of dotted subtests that set that parameter
    1.69 +// This allows tests of the form CMyTestClass.MyLoopTest.8
    1.70 +#define ADD_TEST_STEP_PARAM_RANGE_STEP(method,minparam,maxparam,step)		 \
    1.71 +	_LIT( KTest ## method , #method); \
    1.72 +	AddTestCaseParamRangeL(lTestSuite, KTest ## method, &ThisThis::method, minparam,maxparam,step);
    1.73 +
    1.74 +// Insert a test that takes a boolean parameter and a range of dotted subtests that set that parameter 
    1.75 +// Names for dotted tests include "true", "yes", "on", "1"
    1.76 +// This allows tests of the form CMyTestClass.EnableFeature.on
    1.77 +#define ADD_TEST_STEP_PARAM_BOOL(method)	\
    1.78 +	_LIT(KTest ## method,#method); \
    1.79 +	AddTestCaseParamBoolL(lTestSuite,KTest ## method,&ThisThis::method);
    1.80 +
    1.81 +// Insert a test that that just requires calling a function
    1.82 +#define ADD_WSGCE_TEST_STEP(classname,method) \
    1.83 +	_LIT(KTest ## method,#method); \
    1.84 +	AddTestCase(lTestSuite,KTest ## method,&classname::method);
    1.85 +
    1.86 +// Insert an asyncronus test that that just requires calling a function
    1.87 +#define ADD_WSGCE_ASYNC_TEST_STEP(classname,method) \
    1.88 +	_LIT(KTest ## method,#method); \
    1.89 +	AddAsyncTestCase(lTestSuite,KTest ## method,&classname::method);
    1.90 +
    1.91 +// Insert a test that that just requires calling a function
    1.92 +#define ADD_THIS_TEST_STEP(method) \
    1.93 +	_LIT(KTest ## method,#method); \
    1.94 +	AddTestCase(lTestSuite,KTest ## method,&ThisThis::method);
    1.95 +
    1.96 +// Insert an asyncronus test that that just requires calling a function
    1.97 +#define ADD_THIS_ASYNC_TEST_STEP(method) \
    1.98 +	_LIT(KTest ## method,#method); \
    1.99 +	AddAsyncTestCase(lTestSuite,KTest ## method,&ThisThis::method);
   1.100 +
   1.101 +/*********************************************************************************
   1.102 + * Base class for derived doers that use the Setup/Shutdown
   1.103 + *********************************************************************************/
   1.104 +template <class Fixture>
   1.105 +class CTestCaseDoTemplate : public CTestCase
   1.106 +	{
   1.107 +private:
   1.108 +	
   1.109 +public:
   1.110 +	CTestCaseDoTemplate(const TDesC &aName);
   1.111 +	virtual ~CTestCaseDoTemplate();
   1.112 +
   1.113 +	virtual void RunL(CTestConfig& aConfig, CTestExecuteLogger& aLogger);
   1.114 +	virtual void DoRunL(Fixture*aFixture)=0;
   1.115 +
   1.116 +protected:
   1.117 +	};
   1.118 +
   1.119 +/*********************************************************************************
   1.120 + * Derived dorun to run a test with a parameter
   1.121 + *********************************************************************************/
   1.122 +template <class Fixture,class Param>
   1.123 +class CTestCaseParamTemplate : public CTestCaseDoTemplate<Fixture>
   1.124 +	{
   1.125 +private:
   1.126 +	typedef void (Fixture::*TestMethod)(Param aParam);
   1.127 +	
   1.128 +public:
   1.129 +	CTestCaseParamTemplate(const TDesC &aName, TestMethod aTestMethod, Param aParam)
   1.130 +	:	CTestCaseDoTemplate<Fixture>(aName),
   1.131 +		iTest(aTestMethod),iParam(aParam)
   1.132 +	{}
   1.133 +	virtual void DoRunL(Fixture*aFixture)
   1.134 +		{
   1.135 +		(aFixture->*iTest)(iParam);
   1.136 +		}
   1.137 +
   1.138 +protected:
   1.139 +	TestMethod	iTest;
   1.140 +	Param iParam;
   1.141 +	};
   1.142 +
   1.143 +/***************************************
   1.144 + * 
   1.145 + * Implementation of template <class Fixture,class Param> class CTestCaseTemplate
   1.146 + *
   1.147 + ***************************************/
   1.148 +template <class Fixture>
   1.149 +CTestCaseDoTemplate<Fixture>::CTestCaseDoTemplate(const TDesC &aName)
   1.150 +: CTestCase(aName)
   1.151 +	{
   1.152 +	}
   1.153 +template <class Fixture>
   1.154 +CTestCaseDoTemplate<Fixture>::~CTestCaseDoTemplate()
   1.155 +	{
   1.156 +	}
   1.157 +template <class Fixture>
   1.158 +void CTestCaseDoTemplate<Fixture>::RunL(CTestConfig& aConfig, CTestExecuteLogger& aLogger)
   1.159 +/**
   1.160 + * Creates and destroys the test fixture, but runs the DoRunL in the derived class, which in turn runs the test. 
   1.161 + *
   1.162 + * @param aConfig - Test configuration
   1.163 + * @param aLogger - Test logger
   1.164 + */
   1.165 +	{
   1.166 +	Fixture* iFixture = new (ELeave) Fixture();
   1.167 +	CleanupStack::PushL(iFixture);
   1.168 +	
   1.169 +	// Must set the Logger and Config now
   1.170 +	iFixture->SetLoggerL( aLogger );
   1.171 +	iFixture->SetConfigL( aConfig );
   1.172 +	
   1.173 +	// Setup code
   1.174 +	iFixture->SetupL();
   1.175 +	
   1.176 +	// Run the test
   1.177 +	TRAPD( err, DoRunL(iFixture) );
   1.178 +
   1.179 +	// Log the result
   1.180 +	CTEFLogger::LogResult( iName, err, aLogger );
   1.181 +
   1.182 +	// Now the test case has been logged we need to leave
   1.183 +	// again if that is what the test did
   1.184 +	if( err != KErrTEFUnitPass )
   1.185 +		{
   1.186 +		User::Leave(err);
   1.187 +		}
   1.188 +
   1.189 +	// Teardown code
   1.190 +	iFixture->TearDownL();
   1.191 +
   1.192 +	CleanupStack::PopAndDestroy();
   1.193 +	}
   1.194 +/**
   1.195 + * Support method to add a test that takes a specific value as its parameter.
   1.196 + * Can be used from ADD_TEST_STEP_PARAM_1, or from the methods below
   1.197 + **/
   1.198 +template <class Param,class Fixture>
   1.199 +inline void AddTestCaseParam(CTestSuite* aTestSuite, const TDesC& aName, void (Fixture::*aTestMethod)(Param aParam),Param aParam)
   1.200 +	{
   1.201 +	CTestCaseParamTemplate<Fixture,Param> *testCaseTemplate = new (ELeave) CTestCaseParamTemplate<Fixture,Param>(aName, aTestMethod,aParam);
   1.202 +	CleanupStack::PushL(testCaseTemplate);
   1.203 +	aTestSuite->AddL( testCaseTemplate );
   1.204 +	CleanupStack::Pop(testCaseTemplate);
   1.205 +	}
   1.206 +/**
   1.207 + * Adds a test with a range of parameter values. Usually launched from ADD_TEST_STEP_PARAM_RANGE
   1.208 + * 
   1.209 + **/
   1.210 +template <class Param,class Fixture>
   1.211 +inline void AddTestCaseParamRangeL(CTestSuite* aTestSuite, const TDesC& aName, void (Fixture::*aTestMethod)(Param aParam),TInt aParamMin,TInt aParamMax,TInt aDelta=1)
   1.212 +	{
   1.213 +	CTestSuite* lTestSuite = CTestSuite::NewL(aName);
   1.214 +	CleanupStack::PushL(lTestSuite);
   1.215 +	__ASSERT_ALWAYS(aDelta!=0 && aParamMin!=aParamMax,User::Invariant());
   1.216 +	__ASSERT_ALWAYS((aDelta>0) == (aParamMax>aParamMin),User::Invariant());
   1.217 +	for (TInt count=aParamMin;count!=aParamMax;count+=aDelta)
   1.218 +		{
   1.219 +		TBuf<10> name2;
   1.220 +		name2.AppendNum(count);
   1.221 +		CTestCaseParamTemplate<Fixture,Param> *testCaseTemplate = new (ELeave) CTestCaseParamTemplate<Fixture,Param>(name2, aTestMethod,Param(count));
   1.222 +		CleanupStack::PushL(testCaseTemplate);
   1.223 +		lTestSuite->AddL( testCaseTemplate );
   1.224 +		CleanupStack::Pop(testCaseTemplate);
   1.225 +		}
   1.226 +	aTestSuite->AddL(lTestSuite);
   1.227 +	CleanupStack::Pop(lTestSuite);
   1.228 +	}
   1.229 +
   1.230 +/**
   1.231 + * Adds a test with a range of parameter values. Usually launched from ADD_TEST_STEP_PARAM_BOOL
   1.232 + * 
   1.233 + **/
   1.234 +template <class Param,class Fixture>
   1.235 +inline void AddTestCaseParamBoolL(CTestSuite* aTestSuite, const TDesC& aName, void (Fixture::*aTestMethod)(Param aParam))
   1.236 +	{
   1.237 +	class CTestSuiteBool: public CTestSuite
   1.238 +		{
   1.239 +		public:
   1.240 +		static CTestSuite* NewL(const TTestName& aName)
   1.241 +			{
   1.242 +			CTestSuite* lTestSuite = new (ELeave) CTestSuiteBool(aName);
   1.243 +			CleanupStack::PushL(lTestSuite);
   1.244 +			lTestSuite->ConstructL();
   1.245 +			CleanupStack::Pop();
   1.246 +			return lTestSuite;
   1.247 +			}
   1.248 +		protected:
   1.249 +		CTestSuiteBool(const TTestName& aName):	CTestSuite(aName)
   1.250 +			{	}
   1.251 +		virtual void RunL(CTestConfig& aConfig, CTestExecuteLogger& aLogger)
   1.252 +			{	//run "all the tests"
   1.253 +			// Log that the runner is currently in this suite
   1.254 +			CTEFLogger::LogTraverse( iName, aLogger );
   1.255 +			TInt lError=KErrNone;
   1.256 +			for(TInt lIndex = 0; lIndex < Count() && lIndex<2; lIndex++)
   1.257 +				{
   1.258 +				TRAPD(err,TestL(lIndex)->RunL(aConfig, aLogger));
   1.259 +				if(err != KErrTEFUnitPass)
   1.260 +					{
   1.261 +					lError=err;
   1.262 +					}
   1.263 +				}
   1.264 +			if(lError != KErrTEFUnitPass)
   1.265 +				{
   1.266 +				User::Leave(lError);
   1.267 +				}
   1.268 +			}
   1.269 +		
   1.270 +		};
   1.271 +	typedef Fixture	ThisThis;
   1.272 +	CTestSuite* lTestSuite = CTestSuiteBool::NewL(aName);
   1.273 +	CleanupStack::PushL(lTestSuite);
   1.274 +#define yes 1
   1.275 +#define true 1
   1.276 +#define on 1
   1.277 +#define off 0
   1.278 +#define no 0
   1.279 +#define false 0
   1.280 +	
   1.281 +#define Yes 1
   1.282 +#define True 1
   1.283 +#define On 1
   1.284 +#define Off 0
   1.285 +#define No 0
   1.286 +#define False 0
   1.287 +	
   1.288 +#define YES 1
   1.289 +#define ON 1
   1.290 +#define OFF 0
   1.291 +#define NO 0
   1.292 +
   1.293 +
   1.294 +#define ETrue 1
   1.295 +#define EFalse 0
   1.296 +	//The first two MUST be a true and a false so running "all" will run them both
   1.297 +	ADD_TEST_STEP_PARAM_1(aTestMethod,ETrue);
   1.298 +	ADD_TEST_STEP_PARAM_1(aTestMethod,EFalse);
   1.299 +
   1.300 +	ADD_TEST_STEP_PARAM_1(aTestMethod,1);
   1.301 +	ADD_TEST_STEP_PARAM_1(aTestMethod,0);
   1.302 +	
   1.303 +	ADD_TEST_STEP_PARAM_1(aTestMethod,yes);
   1.304 +	ADD_TEST_STEP_PARAM_1(aTestMethod,true);
   1.305 +	ADD_TEST_STEP_PARAM_1(aTestMethod,on);
   1.306 +	ADD_TEST_STEP_PARAM_1(aTestMethod,no);
   1.307 +	ADD_TEST_STEP_PARAM_1(aTestMethod,false);
   1.308 +	ADD_TEST_STEP_PARAM_1(aTestMethod,off);
   1.309 +
   1.310 +	ADD_TEST_STEP_PARAM_1(aTestMethod,Yes);
   1.311 +	ADD_TEST_STEP_PARAM_1(aTestMethod,True);
   1.312 +	ADD_TEST_STEP_PARAM_1(aTestMethod,On);
   1.313 +	ADD_TEST_STEP_PARAM_1(aTestMethod,No);
   1.314 +	ADD_TEST_STEP_PARAM_1(aTestMethod,False);
   1.315 +	ADD_TEST_STEP_PARAM_1(aTestMethod,Off);
   1.316 +
   1.317 +	ADD_TEST_STEP_PARAM_1(aTestMethod,YES);
   1.318 +	ADD_TEST_STEP_PARAM_1(aTestMethod,TRUE);
   1.319 +	ADD_TEST_STEP_PARAM_1(aTestMethod,ON);
   1.320 +	ADD_TEST_STEP_PARAM_1(aTestMethod,NO);
   1.321 +	ADD_TEST_STEP_PARAM_1(aTestMethod,FALSE);
   1.322 +	ADD_TEST_STEP_PARAM_1(aTestMethod,OFF);
   1.323 +
   1.324 +#undef yes 
   1.325 +#undef true
   1.326 +#undef on 
   1.327 +#undef off
   1.328 +#undef no 
   1.329 +#undef false
   1.330 +
   1.331 +#undef Yes
   1.332 +#undef True
   1.333 +#undef On
   1.334 +#undef Off
   1.335 +#undef No
   1.336 +#undef False
   1.337 +	
   1.338 +#undef YES
   1.339 +#undef ON
   1.340 +#undef OFF
   1.341 +#undef NO
   1.342 +
   1.343 +
   1.344 +#undef ETrue
   1.345 +#undef EFalse
   1.346 +
   1.347 +	aTestSuite->AddL(lTestSuite);
   1.348 +	CleanupStack::Pop(lTestSuite);
   1.349 +	}
   1.350 +
   1.351 +void TefUnitFailLeaveL();
   1.352 +	
   1.353 +#undef 	__ASSERT_SHARED
   1.354 +#define __MAKE_L_STRING(S)	L##S
   1.355 +/**
   1.356 + * Redefining this macro allows the condition text of the assert to be logged when the fail is reported as well as the file and line number
   1.357 + * This allows simple issues to be diagnosed without resorting to the source.
   1.358 + **/
   1.359 +#define __ASSERT_SHARED(aFunction, aMessage) \
   1.360 +	if(!aFunction) \
   1.361 +		{ \
   1.362 +		struct Log	\
   1.363 +			{	/*This wrapper is provided purely to hide the temp string from the debugger.*/ \
   1.364 +			static const TLitC<sizeof("ASSERT FAILED: " #aFunction)>&	Str()\
   1.365 +				{\
   1.366 +				_LIT(aMessage, "ASSERT FAILED: " __MAKE_L_STRING(#aFunction) ); \
   1.367 +				return aMessage;\
   1.368 +				}\
   1.369 +			};\
   1.370 +		Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrAll, Log::Str() );\
   1.371 +		TefUnitFailLeaveL();\
   1.372 +		}
   1.373 +#define ASSERT_NOT_EQUALS(aExpected, aActual) \
   1.374 +	__ASSERT_SHARED(!AssertEquals(aExpected, aActual) , KAssertFailedEquals);
   1.375 +
   1.376 +template <class Pointer>
   1.377 +inline TBool AssertTrue(Pointer* aCondition)
   1.378 +	{
   1.379 +	return AssertTrue((TBool)aCondition);
   1.380 +	}
   1.381 +
   1.382 +
   1.383 +#define LOG_AND_RETURN_IF_GOT_GCE										\
   1.384 +		{																\
   1.385 +		if (GCEIsSupported())											\
   1.386 +			{															\
   1.387 +			INFO_PRINTF1(_L("Test skipped: GCE support is loaded"));	\
   1.388 +			User::Panic(_L("GCE.Wrong.Mode"),1);						\
   1.389 +			return;														\
   1.390 +			}															\
   1.391 +		}
   1.392 +		
   1.393 +#define LOG_AND_PANIC_IF_NOT_GCE											\
   1.394 +		{																	\
   1.395 +		if (!GCEIsSupported())												\
   1.396 +			{																\
   1.397 +			INFO_PRINTF1(_L("Test skipped: GCE support is not loaded"));	\
   1.398 +			User::Panic(_L("GCE.Wrong.Mode"),1);							\
   1.399 +			return;															\
   1.400 +			}																\
   1.401 +		}
   1.402 +
   1.403 +
   1.404 +#define _LIT2(NAME,STRING)											\
   1.405 +    class NAME														\
   1.406 +    	{															\
   1.407 +    public:															\
   1.408 +    	static const TLitC<sizeof(L##STRING)/2>& S()			\
   1.409 +    		{														\
   1.410 +    		_LIT(singleton,STRING);								\
   1.411 +    		return singleton;										\
   1.412 +    		}														\
   1.413 +    	}	;
   1.414 +
   1.415 +
   1.416 +#endif	//__EXTENDTEF_H__