1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdi/test/tdirectgdi_test_step_base.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,455 @@
1.4 +// Copyright (c) 2007-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 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Internal Symbian test code
1.23 +*/
1.24 +
1.25 +#ifndef __TDIRECTGDI_TEST_STEP_BASE__
1.26 +#define __TDIRECTGDI_TEST_STEP_BASE__
1.27 +
1.28 +#include "tdisplaymode_mapping.h"
1.29 +#include "tcontextbase.h"
1.30 +#include <test/testexecutestepbase.h>
1.31 +#include <bitdev.h>
1.32 +#include <graphics/sgimage.h>
1.33 +#include <graphics/directgdiimagetarget.h>
1.34 +#include <graphics/directgdidrawablesource.h>
1.35 +#include <graphics/directgdidriver.h>
1.36 +#include <graphics/directgdiextensioninterfaces.h>
1.37 +#include <test/ttmsgraphicsstep.h>
1.38 +
1.39 +/**
1.40 +Default size of the off screen image in pixels
1.41 +*/
1.42 +const TSize KDefaultOffScreenImageSizeInPixels(200, 200);
1.43 +const TInt KTestCaseLength = 100;
1.44 +
1.45 +_LIT(KCom, "Compressed");
1.46 +_LIT(KSeparator, "_");
1.47 +_LIT(KDirectGc, "DirectGdi");
1.48 +_LIT(KBitGc, "BitGdi");
1.49 +_LIT(KTargetString, "TGT");
1.50 +_LIT(KSourceString, "SRC");
1.51 +
1.52 +const TInt KFileNameLength = 200;
1.53 +const TInt KPixelFormatNameLength = 40;
1.54 +
1.55 +// Define 16 RGB colors
1.56 +#define KRgbBlack TRgb(0x000000)
1.57 +#define KRgbDarkGray TRgb(0x555555)
1.58 +#define KRgbDarkRed TRgb(0x000080)
1.59 +#define KRgbDarkGreen TRgb(0x008000)
1.60 +#define KRgbDarkYellow TRgb(0x008080)
1.61 +#define KRgbDarkBlue TRgb(0x800000)
1.62 +#define KRgbDarkMagenta TRgb(0x800080)
1.63 +#define KRgbDarkCyan TRgb(0x808000)
1.64 +#define KRgbRed TRgb(0x0000ff)
1.65 +#define KRgbGreen TRgb(0x00ff00)
1.66 +#define KRgbYellow TRgb(0x00ffff)
1.67 +#define KRgbBlue TRgb(0xff0000)
1.68 +#define KRgbMagenta TRgb(0xff00ff)
1.69 +#define KRgbCyan TRgb(0xffff00)
1.70 +#define KRgbGray TRgb(0xaaaaaa)
1.71 +#define KRgbWhite TRgb(0xffffff)
1.72 +
1.73 +// A 16 RGB color table
1.74 +const TRgb KColor16Table[] =
1.75 + {
1.76 + KRgbWhite,
1.77 + KRgbGray,
1.78 + KRgbCyan,
1.79 + KRgbMagenta,
1.80 + KRgbBlue,
1.81 + KRgbYellow,
1.82 + KRgbGreen,
1.83 + KRgbRed,
1.84 + KRgbDarkCyan,
1.85 + KRgbDarkMagenta,
1.86 + KRgbDarkBlue,
1.87 + KRgbDarkYellow,
1.88 + KRgbDarkGreen,
1.89 + KRgbDarkRed,
1.90 + KRgbDarkGray,
1.91 + KRgbBlack,
1.92 + };
1.93 +
1.94 +_LIT(KColorNameWhite,"White");
1.95 +_LIT(KColorNameGray,"Gray");
1.96 +_LIT(KColorNameCyan,"Cyan");
1.97 +_LIT(KColorNameMagenta,"Magenta");
1.98 +_LIT(KColorNameBlue,"Blue");
1.99 +_LIT(KColorNameYellow,"Yellow");
1.100 +_LIT(KColorNameGreen,"Green");
1.101 +_LIT(KColorNameRed,"Red");
1.102 +_LIT(KColorNameDarkCyan,"DarkCyan");
1.103 +_LIT(KColorNameDarkMagenta,"DarkMagenta");
1.104 +_LIT(KColorNameDarkBlue,"DarkBlue");
1.105 +_LIT(KColorNameDarkYellow,"DarkYellow");
1.106 +_LIT(KColorNameDarkGreen,"DarkGreen");
1.107 +_LIT(KColorNameDarkRed,"DarkRed");
1.108 +_LIT(KColorNameDarkGrey,"DarkGrey");
1.109 +_LIT(KColorNameBlack,"Black");
1.110 +
1.111 +const TPtrC KColor16TableNames[] =
1.112 + {
1.113 + KColorNameWhite(),
1.114 + KColorNameGray(),
1.115 + KColorNameCyan(),
1.116 + KColorNameMagenta(),
1.117 + KColorNameBlue(),
1.118 + KColorNameYellow(),
1.119 + KColorNameGreen(),
1.120 + KColorNameRed(),
1.121 + KColorNameDarkCyan(),
1.122 + KColorNameDarkMagenta(),
1.123 + KColorNameDarkBlue(),
1.124 + KColorNameDarkYellow(),
1.125 + KColorNameDarkGreen(),
1.126 + KColorNameDarkRed(),
1.127 + KColorNameDarkGrey(),
1.128 + KColorNameBlack(),
1.129 + };
1.130 +
1.131 +
1.132 +
1.133 +const DirectGdi::TBrushStyle KBrushStyleTable[] =
1.134 + {
1.135 + DirectGdi::ENullBrush,
1.136 + DirectGdi::ESolidBrush,
1.137 + DirectGdi::EPatternedBrush,
1.138 + DirectGdi::EVerticalHatchBrush,
1.139 + DirectGdi::EForwardDiagonalHatchBrush,
1.140 + DirectGdi::EHorizontalHatchBrush,
1.141 + DirectGdi::ERearwardDiagonalHatchBrush,
1.142 + DirectGdi::ESquareCrossHatchBrush,
1.143 + DirectGdi::EDiamondCrossHatchBrush,
1.144 + };
1.145 +const TInt KNumBrushStyles = sizeof(KBrushStyleTable) / sizeof(DirectGdi::TBrushStyle);
1.146 +
1.147 +_LIT(KBrushStyleNullBrush,"NullBrush");
1.148 +_LIT(KBrushStyleSolidBrush,"SolidBrush");
1.149 +_LIT(KBrushStylePatternedBrush,"PatternedBrush");
1.150 +_LIT(KBrushStyleVerticalHatchBrush,"VerticalHatchBrush");
1.151 +_LIT(KBrushStyleForwardDiagonalHatchBrush,"ForwardDiagonalHatchBrush");
1.152 +_LIT(KBrushStyleHorizontalHatchBrush,"HorizontalHatchBrush");
1.153 +_LIT(KBrushStyleRearwardDiagonalHatchBrush,"RearwardDiagonalHatchBrush");
1.154 +_LIT(KBrushStyleSquareCrossHatchBrush,"SquareCrossHatchBrush");
1.155 +_LIT(KBrushStyleDiamondCrossHatchBrush,"DiamondCrossHatchBrush");
1.156 +
1.157 +const TPtrC KBrushStyleTableNames[] =
1.158 + {
1.159 + KBrushStyleNullBrush(),
1.160 + KBrushStyleSolidBrush(),
1.161 + KBrushStylePatternedBrush(),
1.162 + KBrushStyleVerticalHatchBrush(),
1.163 + KBrushStyleForwardDiagonalHatchBrush(),
1.164 + KBrushStyleHorizontalHatchBrush(),
1.165 + KBrushStyleRearwardDiagonalHatchBrush(),
1.166 + KBrushStyleSquareCrossHatchBrush(),
1.167 + KBrushStyleDiamondCrossHatchBrush(),
1.168 + };
1.169 +
1.170 +const DirectGdi::TPenStyle KPenStyleTable[] =
1.171 + {
1.172 + DirectGdi::ENullPen,
1.173 + DirectGdi::ESolidPen,
1.174 + DirectGdi::EDottedPen,
1.175 + DirectGdi::EDashedPen,
1.176 + DirectGdi::EDotDashPen,
1.177 + DirectGdi::EDotDotDashPen,
1.178 + };
1.179 +
1.180 +const DirectGdi::TTextAlign KTextAlignTable[] =
1.181 + {
1.182 + DirectGdi::ELeft,
1.183 + DirectGdi::ECenter,
1.184 + DirectGdi::ERight,
1.185 + };
1.186 +
1.187 +_LIT(KTextAlignNameLeft,"Left");
1.188 +_LIT(KTextAlignNameCenter,"Center");
1.189 +_LIT(KTextAlignNameRight,"Right");
1.190 +
1.191 +const TPtrC KTextAlignTableNames[] =
1.192 + {
1.193 + KTextAlignNameLeft(),
1.194 + KTextAlignNameCenter(),
1.195 + KTextAlignNameRight(),
1.196 + };
1.197 +
1.198 +// Look-up table for pen-names.
1.199 +_LIT(KPenNameNull,"NullPen");
1.200 +_LIT(KPenNameSolid,"SolidPen");
1.201 +_LIT(KPenNameDotted,"DottedPen");
1.202 +_LIT(KPenNameDashed,"DashedPen");
1.203 +_LIT(KPenNameDotDash,"DotDashPen");
1.204 +_LIT(KPenNameDotDotDash,"DotDotDashPen");
1.205 +
1.206 +const TPtrC KPenNames[] =
1.207 + {
1.208 + KPenNameNull(),
1.209 + KPenNameSolid(),
1.210 + KPenNameDotted(),
1.211 + KPenNameDashed(),
1.212 + KPenNameDotDash(),
1.213 + KPenNameDotDotDash()
1.214 + };
1.215 +
1.216 +// Look-up table for all available pen-styles.
1.217 +const DirectGdi::TPenStyle KPenStyles[] =
1.218 + {
1.219 + DirectGdi::ENullPen,
1.220 + DirectGdi::ESolidPen,
1.221 + DirectGdi::EDottedPen,
1.222 + DirectGdi::EDashedPen,
1.223 + DirectGdi::EDotDashPen,
1.224 + DirectGdi::EDotDotDashPen
1.225 + };
1.226 +const TInt KNumPenStyles = sizeof(KPenStyles)/sizeof(DirectGdi::TPenStyle);
1.227 +
1.228 +// Look-up table for fill rule names.
1.229 +_LIT(KFillRuleAlternate,"Alternate");
1.230 +_LIT(KFillRuleWinding,"Winding");
1.231 +
1.232 +const TPtrC KFillRuleNames[] =
1.233 + {
1.234 + KFillRuleAlternate(),
1.235 + KFillRuleWinding()
1.236 + };
1.237 +
1.238 +/**
1.239 +Possible use cases of contexts and targets.
1.240 +*/
1.241 +enum TContextTestCase
1.242 + {
1.243 + EOneContextOneTarget,
1.244 + EOneContextTwoTargets_SamePixelType,
1.245 + EOneContextTwoTargets_DifferentPixelType,
1.246 + ETwoContextsOneTarget,
1.247 + ETwoContextsTwoTargets_WithoutSharing_SamePixelType,
1.248 + ETwoContextsTwoTargets_WithoutSharing_DifferentPixelType,
1.249 + ETwoContextsTwoTargets_WithSharing_SamePixelType,
1.250 + ETwoContextsTwoTargets_WithSharing_DifferentPixelType,
1.251 + EOneContextOneTarget_TwiceActivate,
1.252 + ELast
1.253 + };
1.254 +
1.255 +/**
1.256 +Position iterator helper class.
1.257 +Position iterator generates all possible positions from given start position to end position
1.258 +with step. All combinations of horizontal and vertical positions are generated.
1.259 +Additionaly x and y position index is iterated.
1.260 + */
1.261 +class TPositionIterator
1.262 + {
1.263 +public:
1.264 + TPositionIterator(TInt aStartX, TInt aEndX, TInt aStepX,
1.265 + TInt aStartY, TInt aEndY, TInt aStepY);
1.266 + void Begin();
1.267 + TBool Next();
1.268 +public:
1.269 + TInt iStartX;
1.270 + TInt iEndX;
1.271 + TInt iStepX;
1.272 + TInt iStartY;
1.273 + TInt iEndY;
1.274 + TInt iStepY;
1.275 + TInt iPosX; // current x position
1.276 + TInt iPosY; // current y position
1.277 + TInt iIndexX; // current x position index
1.278 + TInt iIndexY; // current y position index
1.279 + };
1.280 +
1.281 +/**
1.282 +Base class for creating an off screen image target
1.283 +*/
1.284 +class CTImageTarget : public CBase
1.285 + {
1.286 +public:
1.287 + virtual TSize SizeInPixels() const = 0;
1.288 + virtual CFbsBitmap* GetTargetFbsBitmapL() = 0;
1.289 + virtual TInt CreateContext(CTContextBase*& aGc, TBool aActivate=ETrue) = 0;
1.290 + virtual void Finish() = 0;
1.291 + virtual TInt Activate(CTContextBase*& aGc) = 0;
1.292 + virtual void Close() = 0;
1.293 + virtual CBitmapDevice* BitmapDevice() const;
1.294 +
1.295 +protected:
1.296 + CBitmapDevice* iBitmapDevice; // The virtual device
1.297 + CFbsBitmap* iBitmap; // Virtual bitmap
1.298 + };
1.299 +
1.300 +/**
1.301 +Create an image target using CFbsBitGc
1.302 +*/
1.303 +class CTBitGdiTarget : public CTImageTarget
1.304 + {
1.305 +public:
1.306 + virtual ~CTBitGdiTarget();
1.307 + static CTBitGdiTarget* NewL(TUidPixelFormat aPixelFormat, const TSize& aSize);
1.308 + virtual TSize SizeInPixels() const;
1.309 + virtual CFbsBitmap* GetTargetFbsBitmapL();
1.310 + virtual TInt CreateContext(CTContextBase*& aGc, TBool aActivate=ETrue);
1.311 + virtual void Finish();
1.312 + virtual TInt Activate(CTContextBase*& aGc);
1.313 + virtual void Close();
1.314 +private:
1.315 + void ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize);
1.316 + };
1.317 +
1.318 +/**
1.319 +Create an image target using DirectGDiGc
1.320 + */
1.321 +class CTDirectGdiTarget : public CTImageTarget
1.322 + {
1.323 +public:
1.324 + CTDirectGdiTarget();
1.325 + virtual ~CTDirectGdiTarget();
1.326 + static CTDirectGdiTarget* NewL(TUidPixelFormat aPixelFormat, const TSize& aSize);
1.327 + virtual TSize SizeInPixels() const;
1.328 + virtual CFbsBitmap* GetTargetFbsBitmapL();
1.329 + virtual TInt CreateContext(CTContextBase*& aGc, TBool aActivate=ETrue);
1.330 + virtual void Finish();
1.331 + virtual TInt Activate(CTContextBase*& aGc);
1.332 + virtual void Close();
1.333 +private:
1.334 + void ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize);
1.335 +
1.336 +public:
1.337 + CDirectGdiDriver* iDGdiDriver; // Driver for Direct GDI support
1.338 + RDirectGdiImageTarget* iDGdiImageTarget;
1.339 + RSgImage iRSgImage;
1.340 + TSgImageInfo iImageInfo; // image info for RSgImage
1.341 + };
1.342 +
1.343 +/**
1.344 +The reason to have a new step base is that it is very much possible that the all
1.345 +individual test steps have project related common variables and members
1.346 +and this is the place to define these common variable and members.
1.347 +All directgdi test classes derive from this class
1.348 +*/
1.349 +class CTDirectGdiStepBase : public CTTMSGraphicsStep
1.350 + {
1.351 +
1.352 +protected:
1.353 + // This structure is used to help manage parameters on a per test-case
1.354 + // basis. A pointer to an instance of this structure is passed through
1.355 + // to each test case as it executes.
1.356 + //
1.357 + struct TTestParams
1.358 + {
1.359 + TUidPixelFormat iTargetPixelFormat;
1.360 + TUidPixelFormat iSourcePixelFormat;
1.361 + TUidPixelFormat iSourceResourcePixelFormat;
1.362 + TBool iDoCompressed;
1.363 +
1.364 + TTestParams () :
1.365 + iTargetPixelFormat(EUidPixelFormatUnknown),
1.366 + iSourcePixelFormat(EUidPixelFormatUnknown),
1.367 + iSourceResourcePixelFormat(EUidPixelFormatUnknown),
1.368 + iDoCompressed(EFalse){};
1.369 + };
1.370 +
1.371 + virtual ~CTDirectGdiStepBase();
1.372 + CTDirectGdiStepBase();
1.373 + void SetTargetL(TUidPixelFormat aPixelFormat, const TContextTestCase aCase = EOneContextOneTarget, const TSize& aSize=KDefaultOffScreenImageSizeInPixels);
1.374 + void ConvertPixelFormats(TPtrC aPixelFormatInput, RArray<TUidPixelFormat>& aPixelFormatArray);
1.375 + void CreateFileName(TTestParams& aParams, TDes& aTestName, TPtrC& aTestCaseName, TDesC* namePostfix = NULL);
1.376 + void DisplayTargetImageL(TUidPixelFormat aPixelFormat);
1.377 + void DisplayTargetImageL(TUidPixelFormat aPixelFormat, CTImageTarget* aGdiTarget);
1.378 + TInt WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, TDesC* namePostfix = NULL);
1.379 + TInt WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, CTImageTarget* aImageTarget, TDesC* namePostfix = NULL);
1.380 + void ResetGc();
1.381 + CFbsBitmap* CreateConcentricRectsBitmapL(TUidPixelFormat aPixelFormat, const TSize& aSize);
1.382 + CFbsBitmap* CreateCheckedBoardBitmapL(TUidPixelFormat aPixelFormat,
1.383 + const TSize& aSize, const TSize& aChecksPerAxis = TSize(10, 10), TBool aGenAlpha = EFalse);
1.384 + CFbsBitmap* CreateBlackWhiteBitmapL(TUidPixelFormat aPixelFormat,
1.385 + const TSize& aSize, const TSize& aChecksPerAxis = TSize(10, 10));
1.386 + CFbsBitmap* CreateMaskingPixmapL (TUidPixelFormat aPixelFormat, const TSize& aSize);
1.387 + CFont* GetFont();
1.388 + void ReleaseFont(CFont* aFont);
1.389 + TBool TestTargetL(const TRgb& aColour);
1.390 + void CheckErrorsL(TInt aDirectGdiErrorCode, TInt aBitGdiErrorCode, const TText8* aFile, TInt aLine);
1.391 +
1.392 +protected:
1.393 + // From CTestStep
1.394 + virtual TVerdict doTestStepPreambleL();
1.395 + virtual TVerdict doTestStepPostambleL();
1.396 + virtual void testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine);
1.397 + virtual void testBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine);
1.398 + virtual void testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine);
1.399 + virtual void testBooleanTrueWithErrorCodeL(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine);
1.400 + // Functions specific to CTDirectGdiStepBase (and derived classes)
1.401 + virtual void RunTestsL() = 0;
1.402 + void RunOomTestsL();
1.403 + static void ResetCache(TAny* aPtr);
1.404 + static void ResetPenSize(TAny* aPtr);
1.405 +
1.406 +protected:
1.407 + CTContextBase* iGc;
1.408 + CTContextBase* iGc2;
1.409 + CTImageTarget* iGdiTarget;
1.410 + CTImageTarget* iGdiTarget2;
1.411 + TBool iMakeRefImg; // switch on (ETrue) and off the control of generating reference images, from .ini file
1.412 + TBool iUseDirectGdi; // switch on (ETrue) and off the control of using Directgdi or old bitgdi, from .ini file
1.413 + RArray<TUidPixelFormat> iTargetPixelFormatArray; // target pixel format(s) for testing
1.414 + RArray<TUidPixelFormat> iSourcePixelFormatArray; // source pixel format(s) for testing
1.415 + RArray<TUidPixelFormat> iSourceResourcePixelFormatArray; // source resource pixel format(s) for testing (for DrawResource)
1.416 + TTestParams iTestParams; // Parameters used for testing in derived classes
1.417 + TBool iDoOomTests; // switch on (ETrue) and off whether out of memory tests are run, from .ini file
1.418 + TBool iRunningOomTests; // ETrue if out of memory tests are running
1.419 +
1.420 + CFbsTypefaceStore* iFontStore;
1.421 + TInt iFontId;
1.422 + MVgImageCache* iVgImageCache;
1.423 + TBool iUseSwDirectGdi; // ETrue if software DirectGDI is being used
1.424 +private:
1.425 + CActiveScheduler* iScheduler;
1.426 + };
1.427 +
1.428 +// Macros to automatically test error condition and report when test fails.
1.429 +// Essentially same as TESTE(a,b) MACRO that base class uses, except error to check is also error that is reported.
1.430 +#define TESTNOERROR(a) \
1.431 + {\
1.432 + TInt b = a;\
1.433 + TBool c = (b == KErrNone);\
1.434 + testBooleanTrueWithErrorCode((c), (b), (TText8*)__FILE__, __LINE__);\
1.435 + }
1.436 +
1.437 +#define TESTNOERRORL(a) \
1.438 + {\
1.439 + TInt b = a;\
1.440 + TBool c = (b == KErrNone);\
1.441 + testBooleanTrueWithErrorCodeL((c), (b), (TText8*)__FILE__, __LINE__);\
1.442 + }
1.443 +
1.444 +#define TESTWITHFILENAMEANDLINENUMBERL(a, f, l) \
1.445 + {\
1.446 + testBooleanTrueL((a), f, l); \
1.447 + }
1.448 +
1.449 +/**
1.450 +Gets the size of the hardware display in pixels
1.451 +@return TSize object containing the screen size
1.452 +*/
1.453 +inline TSize GetDisplaySizeInPixels()
1.454 + {
1.455 + return TSize(150, 150);
1.456 + }
1.457 +
1.458 +#endif