os/graphics/graphicstest/graphicstestharness/inc/TGraphicsHarness.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.
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef __TGRAPHICSHARNESS_H__
    17 #define __TGRAPHICSHARNESS_H__
    18 
    19 #include <test/testexecutestepbase.h>
    20 #include <w32std.h>
    21 #include <test/ttmsgraphicsstep.h>
    22 
    23 
    24 /**
    25   A main interface for implementation test cases
    26  */
    27 class MTestCases
    28 	{
    29 public:
    30 	virtual void RunTestCaseL(TInt aCurTestCase) = 0; // this function needs to be implemented by the derived class
    31 	virtual TInt RunTestCaseLeft(TInt aError) = 0;
    32 	};
    33 
    34 class CTestManager;
    35 
    36 /**
    37   The abstract class is base for test programs, encapsulates the MTestCases interface.
    38 	
    39   All test cases must be implemented in derived classes.  
    40 */
    41 class CTGraphicsBase : public CBase, public MTestCases
    42 	{
    43 friend class CTGraphicsStep;
    44 public:
    45 	IMPORT_C static const TDesC& ColorModeName(TDisplayMode aMode);
    46 	inline static const TDesC& ColorModeName(TInt aMode);
    47 	IMPORT_C static const TDesC& RotationName(CFbsBitGc::TGraphicsOrientation aOrientation);
    48 	inline static const TDesC& RotationName(TInt aOrientation);
    49 	IMPORT_C static void SaveScreenShotL(CFbsScreenDevice* aScdv);
    50 	IMPORT_C CTGraphicsBase(CTestStep* aStep);
    51 	IMPORT_C ~CTGraphicsBase();
    52 	CTestExecuteLogger&	Logger() {return iStep->Logger();}
    53 	// LEGACY methods
    54 	inline void testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine); 
    55 	inline void testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine);
    56 		
    57 	inline void testSoftFailWinscw(TBool aCondition, const TText8* aFile, TInt aLine);
    58 		
    59 protected:
    60 	IMPORT_C void TestComplete();	//test program has to call this function in order to
    61 									//stop the consequence of test cases and quit the step
    62 	IMPORT_C void SetSelfDrive(TBool aSelfDrive);
    63 	IMPORT_C void CaseComplete();
    64 	virtual void ConstructL(){}
    65 	IMPORT_C void ResetCounter(TInt aNewCurrentTestCase = 0);
    66 private:
    67 	void Execute();
    68 	void InitializeL();
    69 	IMPORT_C TInt RunTestCaseLeft(TInt aError);
    70 protected:	
    71 	CTestStep* iStep;
    72 private:
    73 	CTestManager* iTestManager;
    74 	};
    75 
    76 /** Base class for test step */
    77 class CTGraphicsStep : public CTTMSGraphicsStep 
    78 	{
    79 public:
    80 	CTGraphicsStep(){}
    81 	virtual ~CTGraphicsStep(){}
    82 public:
    83 	void SetLogHeapInfo(TBool aLogHeapInfo) {iLogHeapInfo = aLogHeapInfo;}
    84 protected:
    85 	virtual CTGraphicsBase* CreateTestL() = 0;
    86 	//allocate all test rersources here
    87 	virtual void TestSetupL(){}
    88 	//delete all allocated resourses here
    89 	virtual void TestClose(){}
    90 //from CTestStep
    91 	IMPORT_C virtual TVerdict doTestStepL();
    92 private:
    93 	void ExecuteL();
    94 	TInt GetScreenSize(TSize& aSize) const;
    95 	void SetupCleanup(CTrapCleanup*& tc);
    96 	void CloseAllPanicWindows(TInt aId, RWsSession& ws) const;
    97 	void LogHeapInfo(RWsSession &aWs, TBool aStart);
    98 private:
    99 	TBool iLogHeapInfo;	// Only perform wserv heap memory checks when this is true (commonly for wserv testing only)
   100 	};
   101 
   102 #define TEST2(a, b)  			testBooleanTrue((a == b), (TText8*)__FILE__, __LINE__)
   103 #define TEST_SOFTFAIL_WINSCW(a)	testSoftFailWinscw((a), (TText8*)__FILE__, __LINE__)
   104 
   105 inline const TDesC& CTGraphicsBase::ColorModeName(TInt aMode)
   106 	{return ColorModeName(reinterpret_cast<TDisplayMode&>(aMode));}
   107 inline const TDesC& CTGraphicsBase::RotationName(TInt aOrientation)
   108 	{return RotationName(reinterpret_cast<CFbsBitGc::TGraphicsOrientation&>(aOrientation));}
   109 
   110 // Macro for defining test step constructor and creating a test.
   111 // Work for the following name convention:
   112 // step class - CTXXStep
   113 // test class - CTXX,
   114 //  where XX any name
   115 
   116 #define __CONSTRUCT_STEP__(a) \
   117 	CT##a##Step::CT##a##Step() \
   118 	{ \
   119 	SetTestStepName(KT##a##Step); \
   120 	} \
   121 	 \
   122 CTGraphicsBase* CT##a##Step::CreateTestL() \
   123 	{ \
   124 	return new (ELeave) CT##a (this); \
   125 	}
   126 
   127 // Macros to automatically test error condition and report when test fails.
   128 // Essentially same as TESTE(a,b) MACRO that CTestStep uses, except error to
   129 // check is also error that is reported.
   130 #define TESTNOERROR(a) \
   131 	{\
   132 	TInt b = a;\
   133 	TBool c = (b == KErrNone);\
   134 	testBooleanTrueWithErrorCode((c), (b), (TText8*)__FILE__, __LINE__);\
   135 	}
   136 	
   137 inline void CTGraphicsBase::testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine) 
   138 	{
   139 	((CTGraphicsStep*)iStep)->MQCTest(aCondition, aFile, aLine);
   140 	}
   141 
   142 inline void CTGraphicsBase::testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine)
   143 	{
   144 	((CTGraphicsStep*)iStep)->MQCTestWithErrorCode(aCondition, aErrorCode, aFile, aLine);
   145 	}
   146 
   147 inline void CTGraphicsBase::testSoftFailWinscw(TBool aCondition, const TText8* aFile, TInt aLine)
   148 		{
   149 #ifdef __WINS__
   150 		if (!aCondition)
   151 			{
   152 			_LIT(KMessage,"ERROR: Test Failed but is ignored on WINSCW");
   153 			Logger().LogExtra(aFile, aLine, ESevrErr, KMessage);
   154 			}
   155 #else // __WINS__
   156 		testBooleanTrue(aCondition, aFile, aLine);
   157 #endif //__WINS__
   158 		}
   159 #endif