|
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 "tcopyrect.h" |
|
17 |
|
18 CTCopyRect::CTCopyRect() |
|
19 { |
|
20 SetTestStepName(KTDirectGdiCopyRectStep); |
|
21 } |
|
22 |
|
23 CTCopyRect::~CTCopyRect() |
|
24 { |
|
25 } |
|
26 |
|
27 /** |
|
28 @SYMTestCaseID |
|
29 GRAPHICS-DIRECTGDI-COPYRECT-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 copying the content of a rectangular area on the target to another location. |
|
45 |
|
46 @SYMTestPriority |
|
47 High |
|
48 |
|
49 @SYMTestStatus |
|
50 Implemented |
|
51 |
|
52 @SYMTestActions |
|
53 Test various combinations of method parameters: |
|
54 target location is out of bounds or partially out of bounds |
|
55 target destination doesn't intersect source destination |
|
56 target destination is clipped |
|
57 source destination intersects clipping region |
|
58 source destination is partially out of bounds |
|
59 target destination overlaps source destination |
|
60 |
|
61 @SYMTestExpectedResults |
|
62 Content should be copied to specified location. |
|
63 Valid bitmap should be created. This bitmap should be the same as a reference bitmap. |
|
64 */ |
|
65 void CTCopyRect::TestCopyRectL() |
|
66 { |
|
67 _LIT(KTestName, "CopyRect-Basic"); |
|
68 if(!iRunningOomTests) |
|
69 { |
|
70 INFO_PRINTF1(KTestName); |
|
71 } |
|
72 TSize size(30,30); |
|
73 CFbsBitmap* bitmap = CreateCheckedBoardBitmapL(iTestParams.iTargetPixelFormat, size); |
|
74 |
|
75 ResetGc(); |
|
76 TPoint point(15,15); |
|
77 TRect rectToCopy(point, size); |
|
78 iGc->BitBlt(point, *bitmap); |
|
79 |
|
80 // copy rect where target destination is out of bounds |
|
81 iGc->CopyRect(TPoint(-100,0), rectToCopy); |
|
82 |
|
83 // copy rect where target destination is partially out of bounds |
|
84 iGc->CopyRect(TPoint(40,-34), rectToCopy); |
|
85 |
|
86 // copy rect where target destination doesn't intersect source destination |
|
87 iGc->CopyRect(TPoint(17,44), rectToCopy); |
|
88 |
|
89 // copy rect where target destination is clipped |
|
90 RRegion clippingRegion(4); |
|
91 clippingRegion.AddRect(TRect(60,90,100,130)); |
|
92 clippingRegion.SubRect(TRect(80,105,90,115)); |
|
93 iGc->SetClippingRegion(clippingRegion); |
|
94 iGc->CopyRect(TPoint(55,85), rectToCopy); |
|
95 clippingRegion.Clear(); |
|
96 |
|
97 // copy rect where source destination intersects clipping region (shouldn't actually be clipped) |
|
98 clippingRegion.AddRect(TRect(25,25,150,150)); |
|
99 iGc->SetClippingRegion(clippingRegion); |
|
100 iGc->CopyRect(TPoint(60,30), rectToCopy); |
|
101 iGc->ResetClippingRegion(); |
|
102 clippingRegion.Close(); |
|
103 |
|
104 // copy rect where source destination is partially out of bounds |
|
105 iGc->CopyRect(TPoint(0,95), TRect(TPoint(-2,15),size)); |
|
106 |
|
107 // copy rect where target destination overlaps source destination |
|
108 iGc->CopyRect(TPoint(12,12), rectToCopy); |
|
109 delete bitmap; |
|
110 |
|
111 TESTNOERROR(iGc->GetError()); |
|
112 if (iUseDirectGdi && !iUseSwDirectGdi) |
|
113 { |
|
114 iVgImageCache->ResetCache(); |
|
115 } |
|
116 TInt err = WriteTargetOutput(iTestParams, TPtrC(KTestName)); |
|
117 TEST(KErrNone == err); |
|
118 } |
|
119 |
|
120 |
|
121 /** |
|
122 @SYMTestCaseID |
|
123 GRAPHICS-DIRECTGDI-COPYRECT-0002 |
|
124 |
|
125 @SYMPREQ |
|
126 PREQ39 |
|
127 |
|
128 @SYMREQ |
|
129 REQ9195 |
|
130 REQ9201 |
|
131 REQ9202 |
|
132 REQ9222 |
|
133 REQ9223 |
|
134 REQ9236 |
|
135 REQ9237 |
|
136 |
|
137 @SYMTestCaseDesc |
|
138 Tests calling CopyRect() with invalid parameters. |
|
139 |
|
140 @SYMTestPriority |
|
141 High |
|
142 |
|
143 @SYMTestStatus |
|
144 Implemented |
|
145 |
|
146 @SYMTestActions |
|
147 Blit a bitmap. |
|
148 Test CopyRect() with invalid rects ( e.g. iTl.iX>iBr.iX and other ). |
|
149 The offset is set to out of blited bitmap area. |
|
150 Clear blited bitmap area. |
|
151 |
|
152 @SYMTestExpectedResults |
|
153 There should be no effect of using CopyRect(). So, after clearing |
|
154 blited bitmap area, the whole target should be clear and |
|
155 no bitmap will be created. |
|
156 */ |
|
157 void CTCopyRect::TestCopyRectInvalidParametersL() |
|
158 { |
|
159 _LIT(KTestName, "CopyRect-InvalidParameters"); |
|
160 if(!iRunningOomTests) |
|
161 { |
|
162 INFO_PRINTF1(KTestName); |
|
163 } |
|
164 |
|
165 ResetGc(); |
|
166 |
|
167 //blit a bitmap |
|
168 TSize size(40,40); |
|
169 CFbsBitmap* bitmap = CreateCheckedBoardBitmapL(iTestParams.iTargetPixelFormat, size); |
|
170 iGc->BitBlt(TPoint(0,0), *bitmap); |
|
171 |
|
172 //test invalid rectangles but on bitmap area drawn above |
|
173 for(TInt i =1; i<9; i++) |
|
174 { |
|
175 TRect rect( (i%3)*20 , (i/3)*20 , 20 , 20 ); |
|
176 iGc->CopyRect(TPoint(40,40),rect); |
|
177 TESTNOERROR(iGc->GetError()); |
|
178 } |
|
179 //test with offset (0,0), this should just return and do nothing |
|
180 iGc->CopyRect(TPoint(0,0),TRect(0,0,100,100)); |
|
181 //clear blited bitmap area |
|
182 iGc->Clear(TRect(0,0,40,40)); |
|
183 TESTNOERROR(iGc->GetError()); |
|
184 |
|
185 delete bitmap; |
|
186 if (iUseDirectGdi && !iUseSwDirectGdi) |
|
187 { |
|
188 iVgImageCache->ResetCache(); |
|
189 } |
|
190 // test if target is still clear |
|
191 TBool pass = TestTargetL(KRgbWhite); |
|
192 if(!pass) |
|
193 { |
|
194 // write target only if test failed |
|
195 TEST(KErrNone == WriteTargetOutput(iTestParams, TPtrC(KTestName))); |
|
196 } |
|
197 TEST(pass); |
|
198 } |
|
199 |
|
200 /** |
|
201 @SYMTestCaseID GRAPHICS-DIRECTGDI-COPYRECT-0003 |
|
202 |
|
203 @SYMDEF PDEF138111 |
|
204 |
|
205 @SYMTestCaseDesc Test CDirectGdiContext::CopyRect() with non-trivial alpha channel |
|
206 |
|
207 @SYMTestPriority Normal |
|
208 |
|
209 @SYMTestStatus Implemented |
|
210 |
|
211 @SYMTestActions Fill the upper half of the bitmap with semi-transparent gray. |
|
212 Call CDirectGdiContext::CopyRect() to copy the upper half to the lower half. |
|
213 Sample one pixel from both the upper and lower half of the bitmap. |
|
214 |
|
215 @SYMTestExpectedResults The two pixels should be the same. Without the fix the lower part |
|
216 would show a lighter shade of the gray. |
|
217 */ |
|
218 void CTCopyRect::CopyRectAlphaL() |
|
219 { |
|
220 ResetGc(); |
|
221 iGc->SetBrushStyle(DirectGdi::ESolidBrush); |
|
222 iGc->Clear(); |
|
223 TRgb color = TRgb(128, 128, 128, 128); |
|
224 iGc->SetBrushColor(color); |
|
225 iGc->SetPenColor(color); |
|
226 iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha); |
|
227 TSize size = iGdiTarget->SizeInPixels(); |
|
228 iGc->DrawRect(TRect(0, 0, size.iWidth, size.iHeight/2)); |
|
229 iGc->SetDrawMode(DirectGdi::EDrawModePEN); |
|
230 iGc->CopyRect(TPoint(0, size.iHeight/2), TRect(0, 0, size.iWidth, size.iHeight/2)); |
|
231 |
|
232 //sample a pixel from the lower part of the bitmap and it should be the same as the upper half |
|
233 TRgb pixelColorUpper; |
|
234 iGdiTarget->GetTargetFbsBitmapL()->GetPixel(pixelColorUpper, TPoint(size.iWidth/2, size.iHeight/4)); |
|
235 TRgb pixelColorLower; |
|
236 iGdiTarget->GetTargetFbsBitmapL()->GetPixel(pixelColorLower, TPoint(size.iWidth/2, size.iHeight*3/4)); |
|
237 TEST(pixelColorUpper == pixelColorLower); |
|
238 } |
|
239 |
|
240 /** |
|
241 Override of base class virtual |
|
242 @leave Gets system wide error code |
|
243 @return - TVerdict code |
|
244 */ |
|
245 TVerdict CTCopyRect::doTestStepPreambleL() |
|
246 { |
|
247 CTDirectGdiStepBase::doTestStepPreambleL(); |
|
248 return TestStepResult(); |
|
249 } |
|
250 |
|
251 /** |
|
252 Override of base class pure virtual |
|
253 Our implementation only gets called if the base class doTestStepPreambleL() did |
|
254 not leave. That being the case, the current test result value will be EPass. |
|
255 @leave Gets system wide error code |
|
256 @return TVerdict code |
|
257 */ |
|
258 TVerdict CTCopyRect::doTestStepL() |
|
259 { |
|
260 // Test for each pixel format |
|
261 for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--) |
|
262 { |
|
263 iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex]; |
|
264 SetTargetL(iTestParams.iTargetPixelFormat); |
|
265 RunTestsL(); |
|
266 RunOomTestsL(); //from base class |
|
267 } |
|
268 CloseTMSGraphicsStep(); |
|
269 return TestStepResult(); |
|
270 } |
|
271 |
|
272 /** |
|
273 Override of base class pure virtual |
|
274 Lists the tests to be run |
|
275 */ |
|
276 void CTCopyRect::RunTestsL() |
|
277 { |
|
278 SetTestStepID(_L("GRAPHICS-DIRECTGDI-COPYRECT-0001")); |
|
279 TestCopyRectL(); |
|
280 RecordTestResultL(); |
|
281 SetTestStepID(_L("GRAPHICS-DIRECTGDI-COPYRECT-0002")); |
|
282 TestCopyRectInvalidParametersL(); |
|
283 RecordTestResultL(); |
|
284 SetTestStepID(_L("GRAPHICS-DIRECTGDI-COPYRECT-0003")); |
|
285 CopyRectAlphaL(); |
|
286 RecordTestResultL(); |
|
287 } |