|
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 #include "tclipping.h" |
|
17 |
|
18 CTClipping::CTClipping() |
|
19 { |
|
20 SetTestStepName(KTDirectGdiClippingStep); |
|
21 } |
|
22 |
|
23 CTClipping::~CTClipping() |
|
24 { |
|
25 } |
|
26 |
|
27 /** |
|
28 @SYMTestCaseID |
|
29 GRAPHICS-DIRECTGDI-CLIPPING-0001 |
|
30 |
|
31 @SYMPREQ |
|
32 PREQ39 |
|
33 |
|
34 @SYMREQ |
|
35 REQ9195 |
|
36 REQ9201 |
|
37 REQ9202 |
|
38 REQ9222 |
|
39 REQ9223 |
|
40 REQ9236 |
|
41 REQ9237 |
|
42 |
|
43 @SYMTestCaseDesc |
|
44 Tests setting clipping regions. |
|
45 |
|
46 @SYMTestPriority |
|
47 High |
|
48 |
|
49 @SYMTestStatus |
|
50 Implemented |
|
51 |
|
52 @SYMTestActions |
|
53 Set the clipping region consisting of a number of rectangles. Blit a bitmap. |
|
54 Reset the clipping region. |
|
55 |
|
56 @SYMTestExpectedResults |
|
57 Bitmap should be drawn only within the clipped regions successfully. |
|
58 */ |
|
59 void CTClipping::TestClippingBasicL() |
|
60 { |
|
61 _LIT(KTestName, "Clipping-Basic"); |
|
62 if(!iRunningOomTests) |
|
63 { |
|
64 INFO_PRINTF1(KTestName); |
|
65 } |
|
66 |
|
67 CFbsBitmap* bitmap = CreateCheckedBoardBitmapL(iTestParams.iTargetPixelFormat, TSize(150,150)); |
|
68 TESTL(bitmap != NULL); |
|
69 RRegion clippingRegion(8); |
|
70 clippingRegion.AddRect(TRect(10,10,40,40)); // normal square clipping rect |
|
71 clippingRegion.AddRect(TRect(60,70,67,132)); // normal rectangular clipping rect |
|
72 clippingRegion.AddRect(TRect(50,75,110,85)); // clipping rect crosses another clipping rect |
|
73 clippingRegion.AddRect(TRect(125,125,125,125)); // clipping rect with zero size |
|
74 clippingRegion.AddRect(TRect(50,30,45,25)); // clipping rect with negative size |
|
75 |
|
76 ResetGc(); |
|
77 iGc->SetClippingRegion(clippingRegion); |
|
78 TESTNOERROR(iGc->GetError()); |
|
79 iGc->BitBlt(TPoint(0, 0), *bitmap); |
|
80 TESTNOERROR(iGc->GetError()); |
|
81 iGc->ResetClippingRegion(); |
|
82 TESTNOERROR(iGc->GetError()); |
|
83 clippingRegion.Close(); |
|
84 delete bitmap; |
|
85 if (iUseDirectGdi && !iUseSwDirectGdi) |
|
86 { |
|
87 iVgImageCache->ResetCache(); |
|
88 } |
|
89 |
|
90 TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(KTestName))); |
|
91 } |
|
92 |
|
93 |
|
94 |
|
95 /** |
|
96 @SYMTestCaseID |
|
97 GRAPHICS-DIRECTGDI-CLIPPING-0002 |
|
98 |
|
99 @SYMPREQ |
|
100 PREQ39 |
|
101 |
|
102 @SYMREQ |
|
103 REQ9195 |
|
104 REQ9201 |
|
105 REQ9202 |
|
106 REQ9222 |
|
107 REQ9223 |
|
108 REQ9236 |
|
109 REQ9237 |
|
110 |
|
111 @SYMTestCaseDesc |
|
112 Tests the argument checking within SetClippingRegion(TRegion&). |
|
113 |
|
114 @SYMTestPriority |
|
115 High |
|
116 |
|
117 @SYMTestStatus |
|
118 Implemented |
|
119 |
|
120 @SYMTestActions |
|
121 1. Test a region that is outside the bounds of the target. |
|
122 2. Test a region which is partially outside the bounds of the target. |
|
123 3. Test using a region which has its error flag set. |
|
124 |
|
125 @SYMTestExpectedResults |
|
126 Test should return KErrArgument. |
|
127 */ |
|
128 void CTClipping::TestClippingErrors() |
|
129 { |
|
130 _LIT(KTestName, "Clipping-Errors"); |
|
131 if(!iRunningOomTests) |
|
132 { |
|
133 INFO_PRINTF1(KTestName); |
|
134 } |
|
135 |
|
136 RRegion outOfBoundsRegion(TRect(200,200,220,220)); // clipping rect wholly outside target area |
|
137 RRegion partOutOfBoundsRegion(TRect(80,-10,100,25)); // clipping rect partially outside target area |
|
138 TRegionFix<1> regionWithError(TRect(50,75,110,85)); |
|
139 //add more rects than region can hold to set error flag |
|
140 regionWithError.AddRect(TRect(0,0,5,5)); |
|
141 |
|
142 ResetGc(); |
|
143 |
|
144 // Test whether setting clipping region returns error when passed invalid clipping regions |
|
145 // 1: Pass region wholly outside of target. |
|
146 iGc->SetClippingRegion(outOfBoundsRegion); |
|
147 TEST(KErrArgument == iGc->GetError()); |
|
148 iGc->ResetClippingRegion(); |
|
149 TESTNOERROR(iGc->GetError()); |
|
150 // 2: Pass region partially outside of target. |
|
151 iGc->SetClippingRegion(partOutOfBoundsRegion); |
|
152 TEST(KErrArgument == iGc->GetError()); |
|
153 iGc->ResetClippingRegion(); |
|
154 TESTNOERROR(iGc->GetError()); |
|
155 // 3: Pass region with error flag set. |
|
156 iGc->SetClippingRegion(regionWithError); |
|
157 TEST(KErrArgument == iGc->GetError()); |
|
158 iGc->ResetClippingRegion(); |
|
159 TESTNOERROR(iGc->GetError()); |
|
160 outOfBoundsRegion.Close(); |
|
161 partOutOfBoundsRegion.Close(); |
|
162 } |
|
163 |
|
164 /** |
|
165 @SYMTestCaseID |
|
166 GRAPHICS-DIRECTGDI-CLIPPING-0003 |
|
167 |
|
168 @SYMPREQ |
|
169 PREQ39 |
|
170 |
|
171 @SYMREQ |
|
172 REQ9195 |
|
173 REQ9201 |
|
174 REQ9202 |
|
175 REQ9222 |
|
176 REQ9223 |
|
177 REQ9236 |
|
178 REQ9237 |
|
179 |
|
180 @SYMTestCaseDesc |
|
181 Tests using clipping regions while using various APIs to draw images, using a non-zero origin. |
|
182 |
|
183 @SYMTestPriority |
|
184 High |
|
185 |
|
186 @SYMTestStatus |
|
187 Implemented |
|
188 |
|
189 @SYMTestActions |
|
190 Create a bitmap. |
|
191 Set a clipping region rectangle (50,50) from the top-left of the target. |
|
192 Set the origin to 50,50. |
|
193 Draw an image using BitBlt() at (0,0). |
|
194 Reset the clipping. |
|
195 Set a clipping region rectangle (150,50) from the top-left of the target. |
|
196 Set the origin to 150,50. |
|
197 Draw an image using DrawBitmap() at (0,0). |
|
198 Reset the clipping. |
|
199 Set a clipping region rectangle (50,150) from the top-left of the target. |
|
200 Set the origin to 50,150. |
|
201 Draw an image using BitBltMasked() at (0,0). |
|
202 Reset the clipping. |
|
203 Set a clipping region rectangle (150,150) from the top-left of the target. |
|
204 Set the origin to 150,150. |
|
205 Draw an image using DrawBitmapMasked() at (0,0). |
|
206 |
|
207 @SYMTestExpectedResults |
|
208 The first bitmap should be drawn, 50,50 from the top-left of the target. |
|
209 The second bitmap should be drawn, 100,50 from the top-left of the target. |
|
210 The third bitmap should be drawn, 50,100 from the top-left of the target. |
|
211 The fourth bitmap should be drawn, 100,100 from the top-left of the target. |
|
212 None of them should be clipped because although it is always being drawn at (0,0), the |
|
213 drawing and the clipping should take into account the Origin offset. |
|
214 */ |
|
215 void CTClipping::TestClippingWithOriginL() |
|
216 { |
|
217 _LIT(KTestName, "Clipping-WithOrigin"); |
|
218 if(!iRunningOomTests) |
|
219 { |
|
220 INFO_PRINTF1(KTestName); |
|
221 } |
|
222 |
|
223 ResetGc(); |
|
224 |
|
225 const TSize bitmapSrcSize = TSize(40,40); |
|
226 |
|
227 CFbsBitmap* bitmap = CreateCheckedBoardBitmapL(iTestParams.iTargetPixelFormat, bitmapSrcSize); |
|
228 CleanupStack::PushL(bitmap); |
|
229 CFbsBitmap* mask = CreateBlackWhiteBitmapL(iTestParams.iTargetPixelFormat, bitmapSrcSize, TSize(2,2)); |
|
230 CleanupStack::PushL(mask); |
|
231 |
|
232 // Test with BitBlt(). |
|
233 iGc->SetOrigin(TPoint(50,50)); |
|
234 RRegion clippingRegion(1); |
|
235 clippingRegion.AddRect(TRect(TPoint(50,50), TSize(50,50))); |
|
236 iGc->SetClippingRegion(clippingRegion); |
|
237 iGc->BitBlt(TPoint(0,0), *bitmap); |
|
238 iGc->ResetClippingRegion(); |
|
239 clippingRegion.Close(); |
|
240 TESTNOERROR(iGc->GetError()); |
|
241 |
|
242 // Test with DrawBitmap() with scaling. |
|
243 iGc->SetOrigin(TPoint(150, 50)); |
|
244 clippingRegion.AddRect(TRect(TPoint(150,50), TSize(50,50))); |
|
245 iGc->SetClippingRegion(clippingRegion); |
|
246 iGc->DrawBitmap(TRect(TPoint(0,0), TSize(50,50)), *bitmap, TRect(TPoint(0,0), bitmapSrcSize)); |
|
247 iGc->ResetClippingRegion(); |
|
248 clippingRegion.Close(); |
|
249 TESTNOERROR(iGc->GetError()); |
|
250 |
|
251 // Test with BitBltMasked(). |
|
252 iGc->SetOrigin(TPoint(50, 150)); |
|
253 clippingRegion.AddRect(TRect(TPoint(50,150), TSize(50,50))); |
|
254 iGc->SetClippingRegion(clippingRegion); |
|
255 iGc->BitBltMasked(TPoint(0,0), *bitmap, TRect(TPoint(0,0), bitmapSrcSize), *mask, EFalse); |
|
256 iGc->ResetClippingRegion(); |
|
257 clippingRegion.Close(); |
|
258 TESTNOERROR(iGc->GetError()); |
|
259 |
|
260 // Test with DrawBitmapMasked(). |
|
261 iGc->SetOrigin(TPoint(150, 150)); |
|
262 clippingRegion.AddRect(TRect(TPoint(150,150), TSize(50,50))); |
|
263 iGc->SetClippingRegion(clippingRegion); |
|
264 iGc->DrawBitmapMasked(TRect(TPoint(0,0), TSize(50,50)), *bitmap, TRect(TPoint(0,0), bitmapSrcSize), *mask, EFalse); |
|
265 iGc->ResetClippingRegion(); |
|
266 clippingRegion.Close(); |
|
267 TESTNOERROR(iGc->GetError()); |
|
268 |
|
269 CleanupStack::PopAndDestroy(2, bitmap); |
|
270 TESTNOERROR(WriteTargetOutput(iTestParams, TPtrC(KTestName))); |
|
271 } |
|
272 |
|
273 /** |
|
274 Override of base class virtual |
|
275 @leave Gets system wide error code |
|
276 @return - TVerdict code |
|
277 */ |
|
278 TVerdict CTClipping::doTestStepPreambleL() |
|
279 { |
|
280 CTDirectGdiStepBase::doTestStepPreambleL(); |
|
281 return TestStepResult(); |
|
282 } |
|
283 |
|
284 /** |
|
285 Override of base class pure virtual |
|
286 Our implementation only gets called if the base class doTestStepPreambleL() did |
|
287 not leave. That being the case, the current test result value will be EPass. |
|
288 @leave Gets system wide error code |
|
289 @return TVerdict code |
|
290 */ |
|
291 TVerdict CTClipping::doTestStepL() |
|
292 { |
|
293 // Test for each pixel format |
|
294 for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--) |
|
295 { |
|
296 iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex]; |
|
297 SetTargetL(iTestParams.iTargetPixelFormat); |
|
298 RunTestsL(); |
|
299 // only run OOM tests for one target pixel format to prevent duplication of tests |
|
300 if (targetPixelFormatIndex == 0) |
|
301 { |
|
302 RunOomTestsL(); //from base class |
|
303 } |
|
304 } |
|
305 CloseTMSGraphicsStep(); |
|
306 return TestStepResult(); |
|
307 } |
|
308 |
|
309 /** |
|
310 Override of base class pure virtual |
|
311 Lists the tests to be run |
|
312 */ |
|
313 void CTClipping::RunTestsL() |
|
314 { |
|
315 if(iUseDirectGdi && !iUseSwDirectGdi) |
|
316 { |
|
317 // At least one clipping test uses BitBlt() or DrawBitmap(). |
|
318 // In the event that a test leaves after a BitBlt() or DrawBitmap() has occurred |
|
319 // the vgimage cache will need to be reset. |
|
320 // This needs to be the first item on the cleanupstack, |
|
321 // as some tests perform pushes and pops of bitmaps. |
|
322 CleanupStack::PushL(TCleanupItem(ResetCache, iVgImageCache)); |
|
323 } |
|
324 SetTestStepID(_L("GRAPHICS-DIRECTGDI-CLIPPING-0001")); |
|
325 TestClippingBasicL(); |
|
326 RecordTestResultL(); |
|
327 SetTestStepID(_L("GRAPHICS-DIRECTGDI-CLIPPING-0002")); |
|
328 TestClippingErrors(); |
|
329 RecordTestResultL(); |
|
330 SetTestStepID(_L("GRAPHICS-DIRECTGDI-CLIPPING-0003")); |
|
331 TestClippingWithOriginL(); |
|
332 RecordTestResultL(); |
|
333 if(iUseDirectGdi && !iUseSwDirectGdi) |
|
334 { |
|
335 CleanupStack::PopAndDestroy(iVgImageCache); |
|
336 } |
|
337 } |