First public contribution.
1 // Copyright (c) 2008-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "textendedbitmap.h"
18 const TDisplayMode KDisplayMode[] = {EColor16MAP, EColor16MA, EColor16MU, EColor16M, EColor64K,
19 EColor4K, EColor256, EColor16, EGray256, EGray16, EGray4, EGray2};
20 // The only display modes supported by the example rasterizer are EGray256, EColor64K,
21 // EColor16MU and EColor16MAP, these tests will fail if KBitmapMode is changed to a
22 // display mode that is not one of these modes.
23 const TDisplayMode KBitmapMode = EColor16MAP;
24 const TSize KBitmapSize(640,240);
26 const TInt KNumColors = 3;
27 const TRgb KColors[KNumColors] = {TRgb(0,255,255), TRgb(255,0,255), TRgb(255,255,0)};
28 const TUid KUidExampleExtendedBitmap = {0x10285A78};
30 //----------------------------------------------------------------------------
31 // Positive Extended Bitmap Tests
32 //----------------------------------------------------------------------------
33 CTExtendedBitmap::CTExtendedBitmap(CTestStep* aStep) :
38 void CTExtendedBitmap::ConstructL()
40 #ifdef USE_SCREEN_DEVICE
41 // Create a screen device
43 TInt err = KErrNotSupported;
44 for(;(ii<TInt(sizeof(KDisplayMode)/sizeof(KDisplayMode[0]))) && (err == KErrNotSupported);++ii)
46 TRAP(err, iDevice = CFbsScreenDevice::NewL(_L("scdv"),KDisplayMode[ii]));
50 _LIT(KLog,"Failed to create screen device %S return value %d");
51 INFO_PRINTF3(KLog,&ColorModeName(KDisplayMode[ii]),err);
56 _LIT(KLog,"Created Screen Device with mode %S");
57 INFO_PRINTF2(KLog,&ColorModeName(KDisplayMode[ii]));
59 static_cast<CFbsScreenDevice*>(iDevice)->SetAutoUpdate(ETrue);
61 // Create a standard bitmap, bitmap device
62 iBitmap = new(ELeave) CFbsBitmap;
63 User::LeaveIfError(iBitmap->Create(KBitmapSize, KBitmapMode));
64 iDevice = CFbsBitmapDevice::NewL(iBitmap);
67 INFO_PRINTF2(_L("Testing CFbsBitGc with an extended bitmap, display mode %d"), KBitmapMode);
69 // Create a graphics context from chosen device
70 User::LeaveIfError(iDevice->CreateContext(iBitGc));
72 // Check to see if the example rasterizer is available
73 CTExtendedBitmapGc::TDrawMode drawMode = CTExtendedBitmapGc::EDrawFlag;
74 if (CFbsBitmap::Rasterizer() == NULL)
75 drawMode = CTExtendedBitmapGc::EDrawWhite;
79 case CTExtendedBitmapGc::EDrawFlag:
80 INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));
82 case CTExtendedBitmapGc::EDrawWhite:
83 INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
86 ERR_PRINTF1(_L("Unknown draw mode"));
91 iExtendedBitmapGcTests = CTExtendedBitmapGc::NewL(this, *iBitGc, drawMode, KBitmapMode);
94 CTExtendedBitmap::~CTExtendedBitmap()
96 ((CTExtendedBitmapStep*)iStep)->CloseTMSGraphicsStep();
97 delete iExtendedBitmapGcTests;
100 #ifndef USE_SCREEN_DEVICE
110 Test extended bitmaps are drawn correctly to an offscreen bitmap using CFbsBitGc.
111 Test that shapes are filled correctly when an extended bitmap is set as the brush pattern
112 using CFbsBitGc::UseBrushPattern().
129 Create an extended bitmap with extended data to generate a flag pattern when rendered,
130 if the example rasterizer is available.
132 Create a matching standard bitmap.
134 Draw the extended bitmap on the left of the screen and the standard bitmap on the right,
135 using each of the following CFbsBitGc APIs.
136 This is done with both vertical and horizonatal flag orientations,
137 and with and without an active region of interest:
138 - BitBlt() (one version tested as both versions call through to DoBitBlt())
140 - DrawBitmap() (one version tested as both versions call through to DoDrawBitmap())
143 - AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp1, const CFbsBitmap* aSrcBmp2, const TRect& aSrcRect1, const TPoint& aSrcPt2,
144 const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt);
145 - AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp, const TRect& aSrcRect, const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt);
147 To test that shapes are filled correctly using an extended bitmap, an extended bitmap that would generate
148 a flag pattern if the example rasterizer is available, and a matching standard bitmap are in turn set as
149 the brush pattern using CFbsBitGc::UseBrushPattern(). Each of the following APIs are used to draw a shape,
150 using the extended bitmap as a brush on the left, and the standard bitmap on the right. Calling each
151 of these APIs is necessary as each one contains code specific to extended bitmaps.
154 - DrawPolygon() (2 versions)
160 Note that the test cases are actually run from a separate test DLL that is built as part of the FbServ
161 tests (textendedbitmapgc.dll). This DLL allows the same extended bitmap tests to be run using different graphics
164 @SYMTestExpectedResults
165 When the rasterizer is available both sides of the test screen should show a horizontally/vertically striped rectangle for every
166 test case, when the rasterizer is not present both sides of the test screen should show a white rectangle for each test case.
167 The left and right side of the test should always match exactly for each test case, i.e. what is drawn using an
168 extended bitmap on the left of the screen should match what is drawn using a corresponding standard bitmap on the right of
171 void CTExtendedBitmap::RunTestCaseL(TInt aCurTestCase)
173 ((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0103"));
174 iExtendedBitmapGcTests->RunTestCaseL(aCurTestCase);
176 // Compare the two sides of the screen, they should match exactly
177 TSize scrSize = iDevice->SizeInPixels();
178 TEST(iDevice->RectCompare(TRect(0,0,scrSize.iWidth>>1,scrSize.iHeight), *iDevice, TRect(scrSize.iWidth>>1,0,scrSize.iWidth,scrSize.iHeight)));
179 ((CTExtendedBitmapStep*)iStep)->RecordTestResultL();
182 CTestExecuteLogger& CTExtendedBitmap::Logger()
184 return CTGraphicsBase::Logger();
187 void CTExtendedBitmap::TestTrue(TBool aCondition)
192 void CTExtendedBitmap::TestComplete()
194 CTGraphicsBase::TestComplete();
197 __CONSTRUCT_STEP__(ExtendedBitmap)
200 //----------------------------------------------------------------------------
201 // Negative Extended Bitmap Tests
202 //----------------------------------------------------------------------------
203 CTExtendedBitmapNegative::CTExtendedBitmapNegative(CTestStep* aStep) :
204 CTGraphicsBase(aStep)
208 void CTExtendedBitmapNegative::RunTestCaseL(TInt aCurTestCase)
210 ((CTExtendedBitmapNegativeStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
214 ((CTExtendedBitmapNegativeStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0104"));
215 TestCFbsBitmapDeviceNewLLeavesL();
218 ((CTExtendedBitmapNegativeStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
219 ((CTExtendedBitmapNegativeStep*)iStep)->CloseTMSGraphicsStep();
223 ((CTExtendedBitmapNegativeStep*)iStep)->RecordTestResultL();
231 Test that passing an extended bitmap to CFbsBitmapDevice::NewL() leaves with error KErrAccessDenied.
247 Create an extended bitmap using test data and test Uid.
248 Call CFbsBitmapDevice::NewL() with the extended bitmap as the parameter.
250 @SYMTestExpectedResults
251 CFbsBitmapDevice::NewL() leaves with error KErrAccessDenied.
253 void CTExtendedBitmapNegative::TestCFbsBitmapDeviceNewLLeavesL()
255 INFO_PRINTF1(_L("Test that CFbsBitmapDevice leaves with KErrAccessDenied when created with an extended bitmap"));
256 TInt dataSize = sizeof(KColors)+sizeof(TUint8); // estimate the data size
257 TUint8* data = new(ELeave) TUint8[dataSize];
258 CleanupStack::PushL(data);
260 // Write the colours to be used in the extended bitmap to the data
261 CTExtendedBitmapGc::WriteExtendedBitmapInfoL(data, dataSize, KColors, CTExtendedBitmapGc::EHorizontalStripe);
263 CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
264 CleanupStack::PushL(bmp);
265 TInt err = bmp->CreateExtendedBitmap(TSize(10,10), KBitmapMode, KUidExampleExtendedBitmap, data, dataSize);
266 TEST(err == KErrNone);
268 // CFbsBitmapDevice::NewL() should leave with KErrAccessDenied
269 CFbsBitmapDevice* bmpDevice1 = NULL;
270 TRAPD(error, bmpDevice1 = CFbsBitmapDevice::NewL(bmp));
271 TEST(error == KErrAccessDenied);
274 CleanupStack::PopAndDestroy(2, data);
277 __CONSTRUCT_STEP__(ExtendedBitmapNegative)