First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "tdirectgdioom.h"
17 #include <graphics/directgdicontext.h>
19 CTDirectGdiOom::CTDirectGdiOom()
21 SetTestStepName(KTDirectGdiOom);
24 CTDirectGdiOom::~CTDirectGdiOom()
30 GRAPHICS-DIRECTGDI-OOM-0001
48 Draw a line with many points to increase coverage of path drawing in OOM conditions.
51 Create an array of 1000 points.
54 @SYMTestExpectedResults
55 No image is produced by this test, it is purely for checking that no OOM errors occur.
57 void CTDirectGdiOom::TestDrawLargePolyLineL()
59 _LIT(KTestName, "OOM_TestDrawLargePolyLine");
62 INFO_PRINTF1(KTestName);
65 TInt err = CDirectGdiDriver::Open();
68 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
69 TESTL(dgdiDriver != NULL);
70 CleanupClosePushL(*dgdiDriver);
72 CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);
74 CleanupStack::PushL(gc);
76 // Set the bitmap up...
78 TSgImageInfo imageInfo;
79 imageInfo.iSizeInPixels = TSize (320, 240);
80 imageInfo.iPixelFormat = iTestParams.iTargetPixelFormat;
81 imageInfo.iUsage = ESgUsageDirectGdiTarget;
82 err = rsgImage.Create(imageInfo, NULL,0);
84 CleanupClosePushL(rsgImage);
86 RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver);
87 err = dgdiImageTarget.Create(rsgImage);
89 CleanupClosePushL(dgdiImageTarget);
91 err = gc->Activate(dgdiImageTarget);
94 // Draw a polygon that had lots of points to attempt to make the AppendPathCommand
95 // methods in vgengine fail
96 const TInt pCount = 1000;
97 CArrayFixFlat<TPoint>* points = new (ELeave)CArrayFixFlat<TPoint>(pCount);
98 TESTL(points != NULL);
99 CleanupStack::PushL(points);
101 for(TInt i = pCount; i > 0; --i)
103 points->AppendL(TPoint(i, i));
106 gc->DrawPolyLine(points->Array());
107 TESTNOERRORL(dgdiDriver->GetError());
109 CleanupStack::PopAndDestroy(5, dgdiDriver);
111 FreeSgImagePixelFormatCache();
116 GRAPHICS-DIRECTGDI-OOM-0002
134 Set the pen size in OOM conditions.
137 Create a graphics context.
140 @SYMTestExpectedResults
141 No memory leak should occur.
143 void CTDirectGdiOom::TestSetPenSizeL()
145 _LIT(KTestName, "OOM_TestSetPenSize");
146 if(!iRunningOomTests)
148 INFO_PRINTF1(KTestName);
151 TInt err = CDirectGdiDriver::Open();
154 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
155 TESTL(dgdiDriver != NULL);
156 CleanupClosePushL(*dgdiDriver);
158 CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);
160 CleanupStack::PushL(gc);
162 // Set the bitmap up...
164 TSgImageInfo imageInfo;
165 imageInfo.iSizeInPixels = TSize (320, 240);
166 imageInfo.iPixelFormat = iTestParams.iTargetPixelFormat;
167 imageInfo.iUsage = ESgUsageDirectGdiTarget;
168 err = rsgImage.Create(imageInfo, NULL,0);
170 CleanupClosePushL(rsgImage);
172 RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver);
173 err = dgdiImageTarget.Create(rsgImage);
175 CleanupClosePushL(dgdiImageTarget);
177 err = gc->Activate(dgdiImageTarget);
180 TRect rect(0, 0, 200, 1000);
181 TSize csize(300, 300);
183 for(TInt i = 0; i < 10; i++)
185 gc->SetPenSize(TSize(i,i));
186 gc->SetPenStyle(DirectGdi::ENullPen);
187 gc->SetBrushStyle(DirectGdi::ESolidBrush);
188 gc->DrawRoundRect(rect, csize);
189 gc->SetPenStyle(DirectGdi::ESolidPen);
190 gc->DrawRoundRect(rect, csize);
191 TESTNOERRORL(dgdiDriver->GetError());
194 CleanupStack::PopAndDestroy(4, dgdiDriver);
196 FreeSgImagePixelFormatCache();
200 Helper function to force SgImage's internal cache of pixel formats to be emptied,
201 by asking it to lookup a configuration that will always return 0.
203 void CTDirectGdiOom::FreeSgImagePixelFormatCache()
205 // This will force the SgImage's cached array of pixel formats to be freed.
208 info.iSizeInPixels = TSize(10, 10);
209 info.iUsage = ESgUsageDirectGdiSource;
210 info.iShareable = EFalse;
211 info.iCpuAccess = ESgCpuAccessReadWrite;
212 info.iScreenId = 100;
213 TEST(KErrNone == RSgImage::GetPixelFormats(info, NULL, count));
218 Override of base class pure virtual
219 Our implementation only gets called if the base class doTestStepPreambleL() did
220 not leave. That being the case, the current test result value will be EPass.
221 @leave Gets system wide error code
222 @return TVerdict code
224 TVerdict CTDirectGdiOom::doTestStepL()
228 // Just test for one pixel format to speed up testing
229 iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[0];
232 SetOverallTestStepID(_L("GRAPHICS-DIRECTGDI-OOM-0001"));
234 SetOverallTestStepID(_L("GRAPHICS-DIRECTGDI-OOM-0002"));
236 CloseTMSGraphicsStep();
237 return TestStepResult();
241 Override of base class virtual
242 @leave Gets system wide error code
243 @return - TVerdict code
245 TVerdict CTDirectGdiOom::doTestStepPreambleL()
247 CTDirectGdiStepBase::doTestStepPreambleL();
248 return TestStepResult();
252 Override of base class pure virtual
253 Lists the tests to be run
255 void CTDirectGdiOom::RunTestsL()
257 TestDrawLargePolyLineL();