graphicsdeviceinterface/directgdi/test/tdirectgdi_test_step_base.h
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-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 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #ifndef __TDIRECTGDI_TEST_STEP_BASE__
       
    23 #define __TDIRECTGDI_TEST_STEP_BASE__
       
    24 
       
    25 #include "tdisplaymode_mapping.h"
       
    26 #include "tcontextbase.h"
       
    27 #include <test/testexecutestepbase.h>
       
    28 #include <bitdev.h>
       
    29 #include <graphics/sgimage.h>
       
    30 #include <graphics/directgdiimagetarget.h>
       
    31 #include <graphics/directgdidrawablesource.h>
       
    32 #include <graphics/directgdidriver.h>
       
    33 #include <graphics/directgdiextensioninterfaces.h>
       
    34 #include <test/ttmsgraphicsstep.h>
       
    35 
       
    36 /**
       
    37 Default size of the off screen image in pixels
       
    38 */
       
    39 const TSize KDefaultOffScreenImageSizeInPixels(200, 200);
       
    40 const TInt KTestCaseLength = 100;
       
    41 
       
    42 _LIT(KCom, "Compressed");
       
    43 _LIT(KSeparator, "_");
       
    44 _LIT(KDirectGc, "DirectGdi");
       
    45 _LIT(KBitGc, "BitGdi");
       
    46 _LIT(KTargetString, "TGT");
       
    47 _LIT(KSourceString, "SRC");
       
    48 
       
    49 const TInt KFileNameLength = 200;
       
    50 const TInt KPixelFormatNameLength = 40;
       
    51 
       
    52 // Define 16 RGB colors
       
    53 #define KRgbBlack		TRgb(0x000000)
       
    54 #define KRgbDarkGray	TRgb(0x555555)
       
    55 #define KRgbDarkRed		TRgb(0x000080)
       
    56 #define KRgbDarkGreen	TRgb(0x008000)
       
    57 #define KRgbDarkYellow	TRgb(0x008080)
       
    58 #define KRgbDarkBlue	TRgb(0x800000)
       
    59 #define KRgbDarkMagenta	TRgb(0x800080)
       
    60 #define KRgbDarkCyan	TRgb(0x808000)
       
    61 #define KRgbRed			TRgb(0x0000ff)
       
    62 #define KRgbGreen		TRgb(0x00ff00)
       
    63 #define KRgbYellow		TRgb(0x00ffff)
       
    64 #define KRgbBlue		TRgb(0xff0000)
       
    65 #define KRgbMagenta		TRgb(0xff00ff)
       
    66 #define KRgbCyan		TRgb(0xffff00)
       
    67 #define KRgbGray		TRgb(0xaaaaaa)
       
    68 #define KRgbWhite		TRgb(0xffffff)
       
    69 
       
    70 // A 16 RGB color table
       
    71 const TRgb KColor16Table[] = 
       
    72 	{		
       
    73 	KRgbWhite,		
       
    74 	KRgbGray,		
       
    75 	KRgbCyan,		
       
    76 	KRgbMagenta,		
       
    77 	KRgbBlue,		
       
    78 	KRgbYellow,		
       
    79 	KRgbGreen,		
       
    80 	KRgbRed,			
       
    81 	KRgbDarkCyan,	
       
    82 	KRgbDarkMagenta,	
       
    83 	KRgbDarkBlue,	
       
    84 	KRgbDarkYellow,	
       
    85 	KRgbDarkGreen,	
       
    86 	KRgbDarkRed,	
       
    87 	KRgbDarkGray,	
       
    88 	KRgbBlack,					
       
    89 	};
       
    90 
       
    91 _LIT(KColorNameWhite,"White");
       
    92 _LIT(KColorNameGray,"Gray");
       
    93 _LIT(KColorNameCyan,"Cyan");
       
    94 _LIT(KColorNameMagenta,"Magenta");
       
    95 _LIT(KColorNameBlue,"Blue");
       
    96 _LIT(KColorNameYellow,"Yellow");
       
    97 _LIT(KColorNameGreen,"Green");
       
    98 _LIT(KColorNameRed,"Red");
       
    99 _LIT(KColorNameDarkCyan,"DarkCyan");
       
   100 _LIT(KColorNameDarkMagenta,"DarkMagenta");
       
   101 _LIT(KColorNameDarkBlue,"DarkBlue");
       
   102 _LIT(KColorNameDarkYellow,"DarkYellow");
       
   103 _LIT(KColorNameDarkGreen,"DarkGreen");
       
   104 _LIT(KColorNameDarkRed,"DarkRed");
       
   105 _LIT(KColorNameDarkGrey,"DarkGrey");
       
   106 _LIT(KColorNameBlack,"Black");
       
   107 
       
   108 const TPtrC KColor16TableNames[] = 
       
   109 	{
       
   110 		KColorNameWhite(),
       
   111 		KColorNameGray(),
       
   112 		KColorNameCyan(),
       
   113 		KColorNameMagenta(),
       
   114 		KColorNameBlue(),
       
   115 		KColorNameYellow(),
       
   116 		KColorNameGreen(),
       
   117 		KColorNameRed(),
       
   118 		KColorNameDarkCyan(),
       
   119 		KColorNameDarkMagenta(),
       
   120 		KColorNameDarkBlue(),
       
   121 		KColorNameDarkYellow(),
       
   122 		KColorNameDarkGreen(),
       
   123 		KColorNameDarkRed(),
       
   124 		KColorNameDarkGrey(),
       
   125 		KColorNameBlack(),
       
   126 	};
       
   127 
       
   128 
       
   129 
       
   130 const DirectGdi::TBrushStyle KBrushStyleTable[] = 
       
   131 	{
       
   132 	DirectGdi::ENullBrush,	
       
   133 	DirectGdi::ESolidBrush,
       
   134 	DirectGdi::EPatternedBrush,
       
   135 	DirectGdi::EVerticalHatchBrush,
       
   136 	DirectGdi::EForwardDiagonalHatchBrush,
       
   137 	DirectGdi::EHorizontalHatchBrush,
       
   138 	DirectGdi::ERearwardDiagonalHatchBrush,
       
   139 	DirectGdi::ESquareCrossHatchBrush,
       
   140 	DirectGdi::EDiamondCrossHatchBrush,
       
   141 	};
       
   142 const TInt KNumBrushStyles = sizeof(KBrushStyleTable) / sizeof(DirectGdi::TBrushStyle);	
       
   143 
       
   144 _LIT(KBrushStyleNullBrush,"NullBrush");
       
   145 _LIT(KBrushStyleSolidBrush,"SolidBrush");
       
   146 _LIT(KBrushStylePatternedBrush,"PatternedBrush");
       
   147 _LIT(KBrushStyleVerticalHatchBrush,"VerticalHatchBrush");
       
   148 _LIT(KBrushStyleForwardDiagonalHatchBrush,"ForwardDiagonalHatchBrush");
       
   149 _LIT(KBrushStyleHorizontalHatchBrush,"HorizontalHatchBrush");
       
   150 _LIT(KBrushStyleRearwardDiagonalHatchBrush,"RearwardDiagonalHatchBrush");
       
   151 _LIT(KBrushStyleSquareCrossHatchBrush,"SquareCrossHatchBrush");
       
   152 _LIT(KBrushStyleDiamondCrossHatchBrush,"DiamondCrossHatchBrush");
       
   153 
       
   154 const TPtrC KBrushStyleTableNames[] =
       
   155 	{
       
   156 		KBrushStyleNullBrush(),
       
   157 		KBrushStyleSolidBrush(),
       
   158 		KBrushStylePatternedBrush(),
       
   159 		KBrushStyleVerticalHatchBrush(),
       
   160 		KBrushStyleForwardDiagonalHatchBrush(),
       
   161 		KBrushStyleHorizontalHatchBrush(),
       
   162 		KBrushStyleRearwardDiagonalHatchBrush(),
       
   163 		KBrushStyleSquareCrossHatchBrush(),
       
   164 		KBrushStyleDiamondCrossHatchBrush(),
       
   165 	};
       
   166 
       
   167 const DirectGdi::TPenStyle KPenStyleTable[] =
       
   168 	{
       
   169 	DirectGdi::ENullPen,
       
   170 	DirectGdi::ESolidPen,
       
   171 	DirectGdi::EDottedPen,
       
   172 	DirectGdi::EDashedPen,
       
   173 	DirectGdi::EDotDashPen,
       
   174 	DirectGdi::EDotDotDashPen,
       
   175 	};
       
   176 
       
   177 const DirectGdi::TTextAlign KTextAlignTable[] =
       
   178 	{
       
   179 	DirectGdi::ELeft,
       
   180 	DirectGdi::ECenter,
       
   181 	DirectGdi::ERight,
       
   182 	};
       
   183 
       
   184 _LIT(KTextAlignNameLeft,"Left");
       
   185 _LIT(KTextAlignNameCenter,"Center");
       
   186 _LIT(KTextAlignNameRight,"Right");
       
   187 
       
   188 const TPtrC KTextAlignTableNames[] =
       
   189 	{
       
   190 		KTextAlignNameLeft(),
       
   191 		KTextAlignNameCenter(),
       
   192 		KTextAlignNameRight(),
       
   193 	};
       
   194 
       
   195 // Look-up table for pen-names.
       
   196 _LIT(KPenNameNull,"NullPen");
       
   197 _LIT(KPenNameSolid,"SolidPen");
       
   198 _LIT(KPenNameDotted,"DottedPen");
       
   199 _LIT(KPenNameDashed,"DashedPen");
       
   200 _LIT(KPenNameDotDash,"DotDashPen");
       
   201 _LIT(KPenNameDotDotDash,"DotDotDashPen");
       
   202 
       
   203 const TPtrC KPenNames[] = 
       
   204 	{
       
   205 	KPenNameNull(),
       
   206 	KPenNameSolid(),
       
   207 	KPenNameDotted(),
       
   208 	KPenNameDashed(),
       
   209 	KPenNameDotDash(),
       
   210 	KPenNameDotDotDash()
       
   211 	};
       
   212 
       
   213 // Look-up table for all available pen-styles.
       
   214 const DirectGdi::TPenStyle KPenStyles[] = 
       
   215 	{ 
       
   216 	DirectGdi::ENullPen,
       
   217 	DirectGdi::ESolidPen,
       
   218 	DirectGdi::EDottedPen,
       
   219 	DirectGdi::EDashedPen,
       
   220 	DirectGdi::EDotDashPen,
       
   221 	DirectGdi::EDotDotDashPen
       
   222 	};
       
   223 const TInt KNumPenStyles = sizeof(KPenStyles)/sizeof(DirectGdi::TPenStyle);
       
   224 
       
   225 // Look-up table for fill rule names.
       
   226 _LIT(KFillRuleAlternate,"Alternate");
       
   227 _LIT(KFillRuleWinding,"Winding");
       
   228 
       
   229 const TPtrC KFillRuleNames[] = 
       
   230 	{
       
   231 	KFillRuleAlternate(),
       
   232 	KFillRuleWinding()
       
   233 	};
       
   234 
       
   235 /**
       
   236 Possible use cases of contexts and targets. 
       
   237 */
       
   238 enum TContextTestCase
       
   239 	{
       
   240 	EOneContextOneTarget,
       
   241 	EOneContextTwoTargets_SamePixelType,
       
   242 	EOneContextTwoTargets_DifferentPixelType,
       
   243 	ETwoContextsOneTarget,
       
   244 	ETwoContextsTwoTargets_WithoutSharing_SamePixelType,
       
   245 	ETwoContextsTwoTargets_WithoutSharing_DifferentPixelType,
       
   246 	ETwoContextsTwoTargets_WithSharing_SamePixelType,
       
   247 	ETwoContextsTwoTargets_WithSharing_DifferentPixelType,
       
   248 	EOneContextOneTarget_TwiceActivate,	
       
   249 	ELast
       
   250 	};
       
   251 
       
   252 /**
       
   253 Position iterator helper class.
       
   254 Position iterator generates all possible positions from given start position to end position
       
   255 with step. All combinations of horizontal and vertical positions are generated.
       
   256 Additionaly x and y position index is iterated.
       
   257  */
       
   258 class TPositionIterator
       
   259 	{
       
   260 public:
       
   261 	TPositionIterator(TInt aStartX, TInt aEndX, TInt aStepX,
       
   262 		TInt aStartY, TInt aEndY, TInt aStepY);
       
   263 	void Begin();
       
   264 	TBool Next();
       
   265 public:
       
   266 	TInt iStartX;
       
   267 	TInt iEndX;
       
   268 	TInt iStepX;
       
   269 	TInt iStartY;
       
   270 	TInt iEndY;
       
   271 	TInt iStepY;
       
   272 	TInt iPosX; // current x position
       
   273 	TInt iPosY; // current y position
       
   274 	TInt iIndexX; // current x position index
       
   275 	TInt iIndexY; // current y position index
       
   276 	};
       
   277 	
       
   278 /**
       
   279 Base class for creating an off screen image target
       
   280 */
       
   281 class CTImageTarget : public CBase
       
   282 	{
       
   283 public:
       
   284 	virtual TSize SizeInPixels() const = 0;
       
   285 	virtual CFbsBitmap* GetTargetFbsBitmapL() = 0;
       
   286 	virtual TInt CreateContext(CTContextBase*& aGc, TBool aActivate=ETrue) = 0;
       
   287 	virtual void Finish() = 0;
       
   288 	virtual TInt Activate(CTContextBase*& aGc) = 0;
       
   289 	virtual void Close() = 0;
       
   290 	virtual CBitmapDevice* BitmapDevice() const;
       
   291 
       
   292 protected:
       
   293 	CBitmapDevice* iBitmapDevice;	// The virtual device
       
   294 	CFbsBitmap* iBitmap;			// Virtual bitmap
       
   295 	};
       
   296 
       
   297 /**
       
   298 Create an image target using CFbsBitGc
       
   299 */
       
   300 class CTBitGdiTarget : public CTImageTarget 
       
   301 	{
       
   302 public:
       
   303 	virtual ~CTBitGdiTarget();
       
   304 	static CTBitGdiTarget* NewL(TUidPixelFormat aPixelFormat, const TSize& aSize);
       
   305 	virtual TSize SizeInPixels() const;
       
   306 	virtual CFbsBitmap* GetTargetFbsBitmapL();
       
   307 	virtual TInt CreateContext(CTContextBase*& aGc, TBool aActivate=ETrue);
       
   308 	virtual void Finish();	
       
   309 	virtual TInt Activate(CTContextBase*& aGc);
       
   310 	virtual void Close();
       
   311 private:
       
   312 	void ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize);
       
   313 	};
       
   314 
       
   315 /**
       
   316 Create an image target using DirectGDiGc
       
   317  */
       
   318 class CTDirectGdiTarget : public CTImageTarget
       
   319 	{
       
   320 public:
       
   321 	CTDirectGdiTarget();
       
   322 	virtual ~CTDirectGdiTarget();
       
   323 	static CTDirectGdiTarget* NewL(TUidPixelFormat aPixelFormat, const TSize& aSize);
       
   324 	virtual TSize SizeInPixels() const;
       
   325 	virtual CFbsBitmap* GetTargetFbsBitmapL();
       
   326 	virtual TInt CreateContext(CTContextBase*& aGc, TBool aActivate=ETrue);
       
   327 	virtual void Finish();	
       
   328 	virtual TInt Activate(CTContextBase*& aGc);
       
   329 	virtual void Close();
       
   330 private:
       
   331 	void ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize);
       
   332 
       
   333 public:
       
   334 	CDirectGdiDriver*      iDGdiDriver;  // Driver for Direct GDI support
       
   335 	RDirectGdiImageTarget* iDGdiImageTarget;
       
   336 	RSgImage              iRSgImage;
       
   337 	TSgImageInfo	iImageInfo;	// image info for RSgImage
       
   338 	};
       
   339 
       
   340 /**
       
   341 The reason to have a new step base is that it is very much possible that the all 
       
   342 individual test steps have project related common variables and members 
       
   343 and this is the place to define these common variable and members.
       
   344 All directgdi test classes derive from this class
       
   345 */
       
   346 class CTDirectGdiStepBase : public CTTMSGraphicsStep
       
   347 	{
       
   348 
       
   349 protected:
       
   350 	// This structure is used to help manage parameters on a per test-case
       
   351 	// basis. A pointer to an instance of this structure is passed through
       
   352 	// to each test case as it executes.
       
   353 	//
       
   354 	struct TTestParams
       
   355 	{		
       
   356 	TUidPixelFormat iTargetPixelFormat;
       
   357 	TUidPixelFormat iSourcePixelFormat;
       
   358 	TUidPixelFormat iSourceResourcePixelFormat;
       
   359 	TBool 			iDoCompressed;
       
   360 	
       
   361 	TTestParams () : 
       
   362 		iTargetPixelFormat(EUidPixelFormatUnknown), 
       
   363 		iSourcePixelFormat(EUidPixelFormatUnknown), 
       
   364 		iSourceResourcePixelFormat(EUidPixelFormatUnknown),
       
   365 		iDoCompressed(EFalse){};
       
   366 	};
       
   367 	
       
   368 	virtual ~CTDirectGdiStepBase();
       
   369 	CTDirectGdiStepBase();
       
   370 	void SetTargetL(TUidPixelFormat aPixelFormat, const TContextTestCase aCase = EOneContextOneTarget, const TSize& aSize=KDefaultOffScreenImageSizeInPixels);
       
   371 	void ConvertPixelFormats(TPtrC aPixelFormatInput, RArray<TUidPixelFormat>& aPixelFormatArray);
       
   372 	void CreateFileName(TTestParams& aParams, TDes& aTestName, TPtrC& aTestCaseName, TDesC* namePostfix = NULL);
       
   373 	void DisplayTargetImageL(TUidPixelFormat aPixelFormat);
       
   374 	void DisplayTargetImageL(TUidPixelFormat aPixelFormat, CTImageTarget* aGdiTarget);
       
   375 	TInt WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, TDesC* namePostfix = NULL);
       
   376 	TInt WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, CTImageTarget* aImageTarget, TDesC* namePostfix = NULL);
       
   377 	void ResetGc();
       
   378 	CFbsBitmap* CreateConcentricRectsBitmapL(TUidPixelFormat aPixelFormat, const TSize& aSize);
       
   379 	CFbsBitmap* CreateCheckedBoardBitmapL(TUidPixelFormat aPixelFormat,
       
   380 			const TSize& aSize, const TSize& aChecksPerAxis = TSize(10, 10), TBool aGenAlpha = EFalse);
       
   381 	CFbsBitmap* CreateBlackWhiteBitmapL(TUidPixelFormat aPixelFormat,
       
   382 			const TSize& aSize, const TSize& aChecksPerAxis = TSize(10, 10));
       
   383 	CFbsBitmap* CreateMaskingPixmapL (TUidPixelFormat aPixelFormat, const TSize& aSize);
       
   384 	CFont* GetFont();
       
   385 	void ReleaseFont(CFont* aFont);
       
   386 	TBool TestTargetL(const TRgb& aColour);
       
   387 	void CheckErrorsL(TInt aDirectGdiErrorCode, TInt aBitGdiErrorCode, const TText8* aFile, TInt aLine);
       
   388 
       
   389 protected:
       
   390 	// From CTestStep
       
   391 	virtual TVerdict doTestStepPreambleL(); 
       
   392 	virtual TVerdict doTestStepPostambleL();
       
   393 	virtual void testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine);
       
   394 	virtual void testBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine);
       
   395 	virtual void testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine);
       
   396 	virtual void testBooleanTrueWithErrorCodeL(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine);
       
   397 	// Functions specific to CTDirectGdiStepBase (and derived classes)
       
   398 	virtual void RunTestsL() = 0;
       
   399 	void RunOomTestsL();
       
   400 	static void ResetCache(TAny* aPtr);
       
   401 	static void ResetPenSize(TAny* aPtr);
       
   402 	
       
   403 protected:	
       
   404 	CTContextBase* iGc;
       
   405 	CTContextBase* iGc2;
       
   406 	CTImageTarget* iGdiTarget;
       
   407 	CTImageTarget* iGdiTarget2;
       
   408 	TBool	iMakeRefImg; // switch on (ETrue) and off the control of generating reference images, from .ini file
       
   409 	TBool	iUseDirectGdi; // switch on (ETrue) and off the control of using Directgdi or old bitgdi, from .ini file
       
   410 	RArray<TUidPixelFormat> iTargetPixelFormatArray; // target pixel format(s) for testing
       
   411 	RArray<TUidPixelFormat> iSourcePixelFormatArray; // source pixel format(s) for testing
       
   412 	RArray<TUidPixelFormat> iSourceResourcePixelFormatArray; // source resource pixel format(s) for testing (for DrawResource)
       
   413 	TTestParams iTestParams;	// Parameters used for testing in derived classes
       
   414 	TBool iDoOomTests; 	// switch on (ETrue) and off whether out of memory tests are run, from .ini file
       
   415 	TBool iRunningOomTests;	// ETrue if out of memory tests are running
       
   416 
       
   417 	CFbsTypefaceStore* iFontStore;
       
   418 	TInt iFontId;
       
   419 	MVgImageCache* iVgImageCache;
       
   420 	TBool iUseSwDirectGdi;	// ETrue if software DirectGDI is being used
       
   421 private:
       
   422 	CActiveScheduler* 	iScheduler;
       
   423 	};
       
   424 	
       
   425 // Macros to automatically test error condition and report when test fails.
       
   426 // Essentially same as TESTE(a,b) MACRO that base class uses, except error to check is also error that is reported.
       
   427 #define TESTNOERROR(a) \
       
   428 	{\
       
   429 	TInt b = a;\
       
   430 	TBool c = (b == KErrNone);\
       
   431 	testBooleanTrueWithErrorCode((c), (b), (TText8*)__FILE__, __LINE__);\
       
   432 	}
       
   433 
       
   434 #define TESTNOERRORL(a) \
       
   435 	{\
       
   436 	TInt b = a;\
       
   437 	TBool c = (b == KErrNone);\
       
   438 	testBooleanTrueWithErrorCodeL((c), (b), (TText8*)__FILE__, __LINE__);\
       
   439 	}
       
   440 	
       
   441 #define TESTWITHFILENAMEANDLINENUMBERL(a, f, l) \
       
   442 	{\
       
   443 	testBooleanTrueL((a), f, l); \
       
   444 	}
       
   445 	
       
   446 /**
       
   447 Gets the size of the hardware display in pixels
       
   448 @return TSize object containing the screen size
       
   449 */
       
   450 inline TSize GetDisplaySizeInPixels()
       
   451 	{
       
   452 	return TSize(150, 150);
       
   453 	}
       
   454 	
       
   455 #endif