sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __TGRAPHICSHARNESS_H__ sl@0: #define __TGRAPHICSHARNESS_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: /** sl@0: A main interface for implementation test cases sl@0: */ sl@0: class MTestCases sl@0: { sl@0: public: sl@0: virtual void RunTestCaseL(TInt aCurTestCase) = 0; // this function needs to be implemented by the derived class sl@0: virtual TInt RunTestCaseLeft(TInt aError) = 0; sl@0: }; sl@0: sl@0: class CTestManager; sl@0: sl@0: /** sl@0: The abstract class is base for test programs, encapsulates the MTestCases interface. sl@0: sl@0: All test cases must be implemented in derived classes. sl@0: */ sl@0: class CTGraphicsBase : public CBase, public MTestCases sl@0: { sl@0: friend class CTGraphicsStep; sl@0: public: sl@0: IMPORT_C static const TDesC& ColorModeName(TDisplayMode aMode); sl@0: inline static const TDesC& ColorModeName(TInt aMode); sl@0: IMPORT_C static const TDesC& RotationName(CFbsBitGc::TGraphicsOrientation aOrientation); sl@0: inline static const TDesC& RotationName(TInt aOrientation); sl@0: IMPORT_C static void SaveScreenShotL(CFbsScreenDevice* aScdv); sl@0: IMPORT_C CTGraphicsBase(CTestStep* aStep); sl@0: IMPORT_C ~CTGraphicsBase(); sl@0: CTestExecuteLogger& Logger() {return iStep->Logger();} sl@0: // LEGACY methods sl@0: inline void testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine); sl@0: inline void testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine); sl@0: sl@0: inline void testSoftFailWinscw(TBool aCondition, const TText8* aFile, TInt aLine); sl@0: sl@0: protected: sl@0: IMPORT_C void TestComplete(); //test program has to call this function in order to sl@0: //stop the consequence of test cases and quit the step sl@0: IMPORT_C void SetSelfDrive(TBool aSelfDrive); sl@0: IMPORT_C void CaseComplete(); sl@0: virtual void ConstructL(){} sl@0: IMPORT_C void ResetCounter(TInt aNewCurrentTestCase = 0); sl@0: private: sl@0: void Execute(); sl@0: void InitializeL(); sl@0: IMPORT_C TInt RunTestCaseLeft(TInt aError); sl@0: protected: sl@0: CTestStep* iStep; sl@0: private: sl@0: CTestManager* iTestManager; sl@0: }; sl@0: sl@0: /** Base class for test step */ sl@0: class CTGraphicsStep : public CTTMSGraphicsStep sl@0: { sl@0: public: sl@0: CTGraphicsStep(){} sl@0: virtual ~CTGraphicsStep(){} sl@0: public: sl@0: void SetLogHeapInfo(TBool aLogHeapInfo) {iLogHeapInfo = aLogHeapInfo;} sl@0: protected: sl@0: virtual CTGraphicsBase* CreateTestL() = 0; sl@0: //allocate all test rersources here sl@0: virtual void TestSetupL(){} sl@0: //delete all allocated resourses here sl@0: virtual void TestClose(){} sl@0: //from CTestStep sl@0: IMPORT_C virtual TVerdict doTestStepL(); sl@0: private: sl@0: void ExecuteL(); sl@0: TInt GetScreenSize(TSize& aSize) const; sl@0: void SetupCleanup(CTrapCleanup*& tc); sl@0: void CloseAllPanicWindows(TInt aId, RWsSession& ws) const; sl@0: void LogHeapInfo(RWsSession &aWs, TBool aStart); sl@0: private: sl@0: TBool iLogHeapInfo; // Only perform wserv heap memory checks when this is true (commonly for wserv testing only) sl@0: }; sl@0: sl@0: #define TEST2(a, b) testBooleanTrue((a == b), (TText8*)__FILE__, __LINE__) sl@0: #define TEST_SOFTFAIL_WINSCW(a) testSoftFailWinscw((a), (TText8*)__FILE__, __LINE__) sl@0: sl@0: inline const TDesC& CTGraphicsBase::ColorModeName(TInt aMode) sl@0: {return ColorModeName(reinterpret_cast(aMode));} sl@0: inline const TDesC& CTGraphicsBase::RotationName(TInt aOrientation) sl@0: {return RotationName(reinterpret_cast(aOrientation));} sl@0: sl@0: // Macro for defining test step constructor and creating a test. sl@0: // Work for the following name convention: sl@0: // step class - CTXXStep sl@0: // test class - CTXX, sl@0: // where XX any name sl@0: sl@0: #define __CONSTRUCT_STEP__(a) \ sl@0: CT##a##Step::CT##a##Step() \ sl@0: { \ sl@0: SetTestStepName(KT##a##Step); \ sl@0: } \ sl@0: \ sl@0: CTGraphicsBase* CT##a##Step::CreateTestL() \ sl@0: { \ sl@0: return new (ELeave) CT##a (this); \ sl@0: } sl@0: sl@0: // Macros to automatically test error condition and report when test fails. sl@0: // Essentially same as TESTE(a,b) MACRO that CTestStep uses, except error to sl@0: // check is also error that is reported. sl@0: #define TESTNOERROR(a) \ sl@0: {\ sl@0: TInt b = a;\ sl@0: TBool c = (b == KErrNone);\ sl@0: testBooleanTrueWithErrorCode((c), (b), (TText8*)__FILE__, __LINE__);\ sl@0: } sl@0: sl@0: inline void CTGraphicsBase::testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine) sl@0: { sl@0: ((CTGraphicsStep*)iStep)->MQCTest(aCondition, aFile, aLine); sl@0: } sl@0: sl@0: inline void CTGraphicsBase::testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine) sl@0: { sl@0: ((CTGraphicsStep*)iStep)->MQCTestWithErrorCode(aCondition, aErrorCode, aFile, aLine); sl@0: } sl@0: sl@0: inline void CTGraphicsBase::testSoftFailWinscw(TBool aCondition, const TText8* aFile, TInt aLine) sl@0: { sl@0: #ifdef __WINS__ sl@0: if (!aCondition) sl@0: { sl@0: _LIT(KMessage,"ERROR: Test Failed but is ignored on WINSCW"); sl@0: Logger().LogExtra(aFile, aLine, ESevrErr, KMessage); sl@0: } sl@0: #else // __WINS__ sl@0: testBooleanTrue(aCondition, aFile, aLine); sl@0: #endif //__WINS__ sl@0: } sl@0: #endif