os/graphics/graphicstest/graphicstestharness/inc/extendtef.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// These macros and templates extend the tef testsuite support.
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @test
sl@0
    21
 @internalComponent - Internal Symbian test code
sl@0
    22
*/
sl@0
    23
sl@0
    24
#ifndef __EXTENDTEF_H__
sl@0
    25
#define __EXTENDTEF_H__
sl@0
    26
sl@0
    27
#include <test/tefunit.h>
sl@0
    28
sl@0
    29
// Adds a test suite that is not called CreateSuiteL so that one class can describe multiple subsets of tests.
sl@0
    30
#define ADD_TEST_SUITE_SUB(subname) \
sl@0
    31
	_LIT( KTest ## subname, #subname); \
sl@0
    32
	lTestSuite->AddL( CreateSuiteSub##subname##L( KTest##subname));
sl@0
    33
sl@0
    34
// 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.
sl@0
    35
#define ADD_TEST_SUITE_SUB_FLAT(subname) \
sl@0
    36
	_LIT( KTest ## subname, #subname); \
sl@0
    37
	CreateSuiteSub##subname##L( KTest##subname,lTestSuite);
sl@0
    38
sl@0
    39
// Allows the class suite to be added with a name different to the class name, so class names can be computational
sl@0
    40
#define ADD_TEST_SUITE_MODULE_SUB_AS(module,subname,as) \
sl@0
    41
	_LIT( KTest ## as, #as); \
sl@0
    42
	lTestSuite->AddL( module::CreateSuiteSub##subname##L( KTest##as));
sl@0
    43
sl@0
    44
/** Use in a subsuite to distinguish between ADD_TEST_SUITE_SUB and ADD_TEST_SUITE_SUB_FLAT caller
sl@0
    45
 *	ClassName is required - it defines the name of the class containing the referenced methods. 
sl@0
    46
 *	aTestSuite is optional - it should be the function parameter aTestSuite or the keyword NULL 
sl@0
    47
 **/
sl@0
    48
#define SUB_SUITE_OPT(ClassName,aTestSuite) \
sl@0
    49
	CTestSuite* lTestSuite = aTestSuite? (CTestSuite*)aTestSuite: CTestSuite::NewL(aName); \
sl@0
    50
	typedef ClassName	ThisThis;
sl@0
    51
sl@0
    52
// Create a dotted name subtest in the script that represents a parameter to the named test
sl@0
    53
// This should be called from a ADD_TEST_SUITE_SUB with the same name as the test method,
sl@0
    54
// so that entries can be inserted of the form CMyTestClass.MyTest.EColor256
sl@0
    55
#define ADD_TEST_STEP_PARAM_1(method,param)	\
sl@0
    56
	_LIT( KTest ## method ## param, #param); \
sl@0
    57
	AddTestCaseParam(lTestSuite, KTest ## method ## param, method, param);
sl@0
    58
sl@0
    59
// Insert a test that takes a parameter and a range of dotted subtests that set that parameter
sl@0
    60
// This allows tests of the form CMyTestClass.MyLoopTest.8
sl@0
    61
#define ADD_TEST_STEP_PARAM_RANGE(method,minparam,maxparam)	\
sl@0
    62
	_LIT(KTest ## method,#method); \
sl@0
    63
	AddTestCaseParamRangeL(lTestSuite,KTest ## method,&ThisThis::method,minparam,maxparam);
sl@0
    64
sl@0
    65
// Insert a test that takes a parameter and a range of dotted subtests that set that parameter
sl@0
    66
// This allows tests of the form CMyTestClass.MyLoopTest.8
sl@0
    67
#define ADD_TEST_STEP_PARAM_RANGE_STEP(method,minparam,maxparam,step)		 \
sl@0
    68
	_LIT( KTest ## method , #method); \
sl@0
    69
	AddTestCaseParamRangeL(lTestSuite, KTest ## method, &ThisThis::method, minparam,maxparam,step);
sl@0
    70
sl@0
    71
// Insert a test that takes a boolean parameter and a range of dotted subtests that set that parameter 
sl@0
    72
// Names for dotted tests include "true", "yes", "on", "1"
sl@0
    73
// This allows tests of the form CMyTestClass.EnableFeature.on
sl@0
    74
#define ADD_TEST_STEP_PARAM_BOOL(method)	\
sl@0
    75
	_LIT(KTest ## method,#method); \
sl@0
    76
	AddTestCaseParamBoolL(lTestSuite,KTest ## method,&ThisThis::method);
sl@0
    77
sl@0
    78
// Insert a test that that just requires calling a function
sl@0
    79
#define ADD_WSGCE_TEST_STEP(classname,method) \
sl@0
    80
	_LIT(KTest ## method,#method); \
sl@0
    81
	AddTestCase(lTestSuite,KTest ## method,&classname::method);
sl@0
    82
sl@0
    83
// Insert an asyncronus test that that just requires calling a function
sl@0
    84
#define ADD_WSGCE_ASYNC_TEST_STEP(classname,method) \
sl@0
    85
	_LIT(KTest ## method,#method); \
sl@0
    86
	AddAsyncTestCase(lTestSuite,KTest ## method,&classname::method);
sl@0
    87
sl@0
    88
// Insert a test that that just requires calling a function
sl@0
    89
#define ADD_THIS_TEST_STEP(method) \
sl@0
    90
	_LIT(KTest ## method,#method); \
sl@0
    91
	AddTestCase(lTestSuite,KTest ## method,&ThisThis::method);
sl@0
    92
sl@0
    93
// Insert an asyncronus test that that just requires calling a function
sl@0
    94
#define ADD_THIS_ASYNC_TEST_STEP(method) \
sl@0
    95
	_LIT(KTest ## method,#method); \
sl@0
    96
	AddAsyncTestCase(lTestSuite,KTest ## method,&ThisThis::method);
sl@0
    97
sl@0
    98
/*********************************************************************************
sl@0
    99
 * Base class for derived doers that use the Setup/Shutdown
sl@0
   100
 *********************************************************************************/
sl@0
   101
template <class Fixture>
sl@0
   102
class CTestCaseDoTemplate : public CTestCase
sl@0
   103
	{
sl@0
   104
private:
sl@0
   105
	
sl@0
   106
public:
sl@0
   107
	CTestCaseDoTemplate(const TDesC &aName);
sl@0
   108
	virtual ~CTestCaseDoTemplate();
sl@0
   109
sl@0
   110
	virtual void RunL(CTestConfig& aConfig, CTestExecuteLogger& aLogger);
sl@0
   111
	virtual void DoRunL(Fixture*aFixture)=0;
sl@0
   112
sl@0
   113
protected:
sl@0
   114
	};
sl@0
   115
sl@0
   116
/*********************************************************************************
sl@0
   117
 * Derived dorun to run a test with a parameter
sl@0
   118
 *********************************************************************************/
sl@0
   119
template <class Fixture,class Param>
sl@0
   120
class CTestCaseParamTemplate : public CTestCaseDoTemplate<Fixture>
sl@0
   121
	{
sl@0
   122
private:
sl@0
   123
	typedef void (Fixture::*TestMethod)(Param aParam);
sl@0
   124
	
sl@0
   125
public:
sl@0
   126
	CTestCaseParamTemplate(const TDesC &aName, TestMethod aTestMethod, Param aParam)
sl@0
   127
	:	CTestCaseDoTemplate<Fixture>(aName),
sl@0
   128
		iTest(aTestMethod),iParam(aParam)
sl@0
   129
	{}
sl@0
   130
	virtual void DoRunL(Fixture*aFixture)
sl@0
   131
		{
sl@0
   132
		(aFixture->*iTest)(iParam);
sl@0
   133
		}
sl@0
   134
sl@0
   135
protected:
sl@0
   136
	TestMethod	iTest;
sl@0
   137
	Param iParam;
sl@0
   138
	};
sl@0
   139
sl@0
   140
/***************************************
sl@0
   141
 * 
sl@0
   142
 * Implementation of template <class Fixture,class Param> class CTestCaseTemplate
sl@0
   143
 *
sl@0
   144
 ***************************************/
sl@0
   145
template <class Fixture>
sl@0
   146
CTestCaseDoTemplate<Fixture>::CTestCaseDoTemplate(const TDesC &aName)
sl@0
   147
: CTestCase(aName)
sl@0
   148
	{
sl@0
   149
	}
sl@0
   150
template <class Fixture>
sl@0
   151
CTestCaseDoTemplate<Fixture>::~CTestCaseDoTemplate()
sl@0
   152
	{
sl@0
   153
	}
sl@0
   154
template <class Fixture>
sl@0
   155
void CTestCaseDoTemplate<Fixture>::RunL(CTestConfig& aConfig, CTestExecuteLogger& aLogger)
sl@0
   156
/**
sl@0
   157
 * Creates and destroys the test fixture, but runs the DoRunL in the derived class, which in turn runs the test. 
sl@0
   158
 *
sl@0
   159
 * @param aConfig - Test configuration
sl@0
   160
 * @param aLogger - Test logger
sl@0
   161
 */
sl@0
   162
	{
sl@0
   163
	Fixture* iFixture = new (ELeave) Fixture();
sl@0
   164
	CleanupStack::PushL(iFixture);
sl@0
   165
	
sl@0
   166
	// Must set the Logger and Config now
sl@0
   167
	iFixture->SetLoggerL( aLogger );
sl@0
   168
	iFixture->SetConfigL( aConfig );
sl@0
   169
	
sl@0
   170
	// Setup code
sl@0
   171
	iFixture->SetupL();
sl@0
   172
	
sl@0
   173
	// Run the test
sl@0
   174
	TRAPD( err, DoRunL(iFixture) );
sl@0
   175
sl@0
   176
	// Log the result
sl@0
   177
	CTEFLogger::LogResult( iName, err, aLogger );
sl@0
   178
sl@0
   179
	// Now the test case has been logged we need to leave
sl@0
   180
	// again if that is what the test did
sl@0
   181
	if( err != KErrTEFUnitPass )
sl@0
   182
		{
sl@0
   183
		User::Leave(err);
sl@0
   184
		}
sl@0
   185
sl@0
   186
	// Teardown code
sl@0
   187
	iFixture->TearDownL();
sl@0
   188
sl@0
   189
	CleanupStack::PopAndDestroy();
sl@0
   190
	}
sl@0
   191
/**
sl@0
   192
 * Support method to add a test that takes a specific value as its parameter.
sl@0
   193
 * Can be used from ADD_TEST_STEP_PARAM_1, or from the methods below
sl@0
   194
 **/
sl@0
   195
template <class Param,class Fixture>
sl@0
   196
inline void AddTestCaseParam(CTestSuite* aTestSuite, const TDesC& aName, void (Fixture::*aTestMethod)(Param aParam),Param aParam)
sl@0
   197
	{
sl@0
   198
	CTestCaseParamTemplate<Fixture,Param> *testCaseTemplate = new (ELeave) CTestCaseParamTemplate<Fixture,Param>(aName, aTestMethod,aParam);
sl@0
   199
	CleanupStack::PushL(testCaseTemplate);
sl@0
   200
	aTestSuite->AddL( testCaseTemplate );
sl@0
   201
	CleanupStack::Pop(testCaseTemplate);
sl@0
   202
	}
sl@0
   203
/**
sl@0
   204
 * Adds a test with a range of parameter values. Usually launched from ADD_TEST_STEP_PARAM_RANGE
sl@0
   205
 * 
sl@0
   206
 **/
sl@0
   207
template <class Param,class Fixture>
sl@0
   208
inline void AddTestCaseParamRangeL(CTestSuite* aTestSuite, const TDesC& aName, void (Fixture::*aTestMethod)(Param aParam),TInt aParamMin,TInt aParamMax,TInt aDelta=1)
sl@0
   209
	{
sl@0
   210
	CTestSuite* lTestSuite = CTestSuite::NewL(aName);
sl@0
   211
	CleanupStack::PushL(lTestSuite);
sl@0
   212
	__ASSERT_ALWAYS(aDelta!=0 && aParamMin!=aParamMax,User::Invariant());
sl@0
   213
	__ASSERT_ALWAYS((aDelta>0) == (aParamMax>aParamMin),User::Invariant());
sl@0
   214
	for (TInt count=aParamMin;count!=aParamMax;count+=aDelta)
sl@0
   215
		{
sl@0
   216
		TBuf<10> name2;
sl@0
   217
		name2.AppendNum(count);
sl@0
   218
		CTestCaseParamTemplate<Fixture,Param> *testCaseTemplate = new (ELeave) CTestCaseParamTemplate<Fixture,Param>(name2, aTestMethod,Param(count));
sl@0
   219
		CleanupStack::PushL(testCaseTemplate);
sl@0
   220
		lTestSuite->AddL( testCaseTemplate );
sl@0
   221
		CleanupStack::Pop(testCaseTemplate);
sl@0
   222
		}
sl@0
   223
	aTestSuite->AddL(lTestSuite);
sl@0
   224
	CleanupStack::Pop(lTestSuite);
sl@0
   225
	}
sl@0
   226
sl@0
   227
/**
sl@0
   228
 * Adds a test with a range of parameter values. Usually launched from ADD_TEST_STEP_PARAM_BOOL
sl@0
   229
 * 
sl@0
   230
 **/
sl@0
   231
template <class Param,class Fixture>
sl@0
   232
inline void AddTestCaseParamBoolL(CTestSuite* aTestSuite, const TDesC& aName, void (Fixture::*aTestMethod)(Param aParam))
sl@0
   233
	{
sl@0
   234
	class CTestSuiteBool: public CTestSuite
sl@0
   235
		{
sl@0
   236
		public:
sl@0
   237
		static CTestSuite* NewL(const TTestName& aName)
sl@0
   238
			{
sl@0
   239
			CTestSuite* lTestSuite = new (ELeave) CTestSuiteBool(aName);
sl@0
   240
			CleanupStack::PushL(lTestSuite);
sl@0
   241
			lTestSuite->ConstructL();
sl@0
   242
			CleanupStack::Pop();
sl@0
   243
			return lTestSuite;
sl@0
   244
			}
sl@0
   245
		protected:
sl@0
   246
		CTestSuiteBool(const TTestName& aName):	CTestSuite(aName)
sl@0
   247
			{	}
sl@0
   248
		virtual void RunL(CTestConfig& aConfig, CTestExecuteLogger& aLogger)
sl@0
   249
			{	//run "all the tests"
sl@0
   250
			// Log that the runner is currently in this suite
sl@0
   251
			CTEFLogger::LogTraverse( iName, aLogger );
sl@0
   252
			TInt lError=KErrNone;
sl@0
   253
			for(TInt lIndex = 0; lIndex < Count() && lIndex<2; lIndex++)
sl@0
   254
				{
sl@0
   255
				TRAPD(err,TestL(lIndex)->RunL(aConfig, aLogger));
sl@0
   256
				if(err != KErrTEFUnitPass)
sl@0
   257
					{
sl@0
   258
					lError=err;
sl@0
   259
					}
sl@0
   260
				}
sl@0
   261
			if(lError != KErrTEFUnitPass)
sl@0
   262
				{
sl@0
   263
				User::Leave(lError);
sl@0
   264
				}
sl@0
   265
			}
sl@0
   266
		
sl@0
   267
		};
sl@0
   268
	typedef Fixture	ThisThis;
sl@0
   269
	CTestSuite* lTestSuite = CTestSuiteBool::NewL(aName);
sl@0
   270
	CleanupStack::PushL(lTestSuite);
sl@0
   271
#define yes 1
sl@0
   272
#define true 1
sl@0
   273
#define on 1
sl@0
   274
#define off 0
sl@0
   275
#define no 0
sl@0
   276
#define false 0
sl@0
   277
	
sl@0
   278
#define Yes 1
sl@0
   279
#define True 1
sl@0
   280
#define On 1
sl@0
   281
#define Off 0
sl@0
   282
#define No 0
sl@0
   283
#define False 0
sl@0
   284
	
sl@0
   285
#define YES 1
sl@0
   286
#define ON 1
sl@0
   287
#define OFF 0
sl@0
   288
#define NO 0
sl@0
   289
sl@0
   290
sl@0
   291
#define ETrue 1
sl@0
   292
#define EFalse 0
sl@0
   293
	//The first two MUST be a true and a false so running "all" will run them both
sl@0
   294
	ADD_TEST_STEP_PARAM_1(aTestMethod,ETrue);
sl@0
   295
	ADD_TEST_STEP_PARAM_1(aTestMethod,EFalse);
sl@0
   296
sl@0
   297
	ADD_TEST_STEP_PARAM_1(aTestMethod,1);
sl@0
   298
	ADD_TEST_STEP_PARAM_1(aTestMethod,0);
sl@0
   299
	
sl@0
   300
	ADD_TEST_STEP_PARAM_1(aTestMethod,yes);
sl@0
   301
	ADD_TEST_STEP_PARAM_1(aTestMethod,true);
sl@0
   302
	ADD_TEST_STEP_PARAM_1(aTestMethod,on);
sl@0
   303
	ADD_TEST_STEP_PARAM_1(aTestMethod,no);
sl@0
   304
	ADD_TEST_STEP_PARAM_1(aTestMethod,false);
sl@0
   305
	ADD_TEST_STEP_PARAM_1(aTestMethod,off);
sl@0
   306
sl@0
   307
	ADD_TEST_STEP_PARAM_1(aTestMethod,Yes);
sl@0
   308
	ADD_TEST_STEP_PARAM_1(aTestMethod,True);
sl@0
   309
	ADD_TEST_STEP_PARAM_1(aTestMethod,On);
sl@0
   310
	ADD_TEST_STEP_PARAM_1(aTestMethod,No);
sl@0
   311
	ADD_TEST_STEP_PARAM_1(aTestMethod,False);
sl@0
   312
	ADD_TEST_STEP_PARAM_1(aTestMethod,Off);
sl@0
   313
sl@0
   314
	ADD_TEST_STEP_PARAM_1(aTestMethod,YES);
sl@0
   315
	ADD_TEST_STEP_PARAM_1(aTestMethod,TRUE);
sl@0
   316
	ADD_TEST_STEP_PARAM_1(aTestMethod,ON);
sl@0
   317
	ADD_TEST_STEP_PARAM_1(aTestMethod,NO);
sl@0
   318
	ADD_TEST_STEP_PARAM_1(aTestMethod,FALSE);
sl@0
   319
	ADD_TEST_STEP_PARAM_1(aTestMethod,OFF);
sl@0
   320
sl@0
   321
#undef yes 
sl@0
   322
#undef true
sl@0
   323
#undef on 
sl@0
   324
#undef off
sl@0
   325
#undef no 
sl@0
   326
#undef false
sl@0
   327
sl@0
   328
#undef Yes
sl@0
   329
#undef True
sl@0
   330
#undef On
sl@0
   331
#undef Off
sl@0
   332
#undef No
sl@0
   333
#undef False
sl@0
   334
	
sl@0
   335
#undef YES
sl@0
   336
#undef ON
sl@0
   337
#undef OFF
sl@0
   338
#undef NO
sl@0
   339
sl@0
   340
sl@0
   341
#undef ETrue
sl@0
   342
#undef EFalse
sl@0
   343
sl@0
   344
	aTestSuite->AddL(lTestSuite);
sl@0
   345
	CleanupStack::Pop(lTestSuite);
sl@0
   346
	}
sl@0
   347
sl@0
   348
void TefUnitFailLeaveL();
sl@0
   349
	
sl@0
   350
#undef 	__ASSERT_SHARED
sl@0
   351
#define __MAKE_L_STRING(S)	L##S
sl@0
   352
/**
sl@0
   353
 * 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
sl@0
   354
 * This allows simple issues to be diagnosed without resorting to the source.
sl@0
   355
 **/
sl@0
   356
#define __ASSERT_SHARED(aFunction, aMessage) \
sl@0
   357
	if(!aFunction) \
sl@0
   358
		{ \
sl@0
   359
		struct Log	\
sl@0
   360
			{	/*This wrapper is provided purely to hide the temp string from the debugger.*/ \
sl@0
   361
			static const TLitC<sizeof("ASSERT FAILED: " #aFunction)>&	Str()\
sl@0
   362
				{\
sl@0
   363
				_LIT(aMessage, "ASSERT FAILED: " __MAKE_L_STRING(#aFunction) ); \
sl@0
   364
				return aMessage;\
sl@0
   365
				}\
sl@0
   366
			};\
sl@0
   367
		Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrAll, Log::Str() );\
sl@0
   368
		TefUnitFailLeaveL();\
sl@0
   369
		}
sl@0
   370
#define ASSERT_NOT_EQUALS(aExpected, aActual) \
sl@0
   371
	__ASSERT_SHARED(!AssertEquals(aExpected, aActual) , KAssertFailedEquals);
sl@0
   372
sl@0
   373
template <class Pointer>
sl@0
   374
inline TBool AssertTrue(Pointer* aCondition)
sl@0
   375
	{
sl@0
   376
	return AssertTrue((TBool)aCondition);
sl@0
   377
	}
sl@0
   378
sl@0
   379
sl@0
   380
#define LOG_AND_RETURN_IF_GOT_GCE										\
sl@0
   381
		{																\
sl@0
   382
		if (GCEIsSupported())											\
sl@0
   383
			{															\
sl@0
   384
			INFO_PRINTF1(_L("Test skipped: GCE support is loaded"));	\
sl@0
   385
			User::Panic(_L("GCE.Wrong.Mode"),1);						\
sl@0
   386
			return;														\
sl@0
   387
			}															\
sl@0
   388
		}
sl@0
   389
		
sl@0
   390
#define LOG_AND_PANIC_IF_NOT_GCE											\
sl@0
   391
		{																	\
sl@0
   392
		if (!GCEIsSupported())												\
sl@0
   393
			{																\
sl@0
   394
			INFO_PRINTF1(_L("Test skipped: GCE support is not loaded"));	\
sl@0
   395
			User::Panic(_L("GCE.Wrong.Mode"),1);							\
sl@0
   396
			return;															\
sl@0
   397
			}																\
sl@0
   398
		}
sl@0
   399
sl@0
   400
sl@0
   401
#define _LIT2(NAME,STRING)											\
sl@0
   402
    class NAME														\
sl@0
   403
    	{															\
sl@0
   404
    public:															\
sl@0
   405
    	static const TLitC<sizeof(L##STRING)/2>& S()			\
sl@0
   406
    		{														\
sl@0
   407
    		_LIT(singleton,STRING);								\
sl@0
   408
    		return singleton;										\
sl@0
   409
    		}														\
sl@0
   410
    	}	;
sl@0
   411
sl@0
   412
sl@0
   413
#endif	//__EXTENDTEF_H__