2 * Unit test suite for graphics objects
4 * Copyright (C) 2007 Google (Evan Stade)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
26 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
27 #define TABLE_LEN (23)
29 static void test_constructor_destructor(void)
32 GpGraphics
*graphics
= NULL
;
35 stat
= GdipCreateFromHDC(NULL
, &graphics
);
36 expect(OutOfMemory
, stat
);
37 stat
= GdipDeleteGraphics(graphics
);
38 expect(InvalidParameter
, stat
);
40 stat
= GdipCreateFromHDC(hdc
, &graphics
);
42 stat
= GdipDeleteGraphics(graphics
);
45 stat
= GdipCreateFromHWND(NULL
, &graphics
);
47 stat
= GdipDeleteGraphics(graphics
);
50 stat
= GdipDeleteGraphics(NULL
);
51 expect(InvalidParameter
, stat
);
60 /* Linked list prepend function. */
61 static void log_state(GraphicsState data
, node
** log
)
63 node
* new_entry
= HeapAlloc(GetProcessHeap(), 0, sizeof(node
));
65 new_entry
->data
= data
;
66 new_entry
->next
= *log
;
70 /* Checks if there are duplicates in the list, and frees it. */
71 static void check_no_duplicates(node
* log
)
83 while((temp
= temp
->next
)){
84 if(log
->data
== temp
->data
){
91 }while((log
= log
->next
));
96 HeapFree(GetProcessHeap(), 0, temp
);
104 static void test_save_restore(void)
107 GraphicsState state_a
, state_b
, state_c
;
108 InterpolationMode mode
;
109 GpGraphics
*graphics1
, *graphics2
;
110 node
* state_log
= NULL
;
112 state_a
= state_b
= state_c
= 0xdeadbeef;
114 /* Invalid saving. */
115 GdipCreateFromHDC(hdc
, &graphics1
);
116 stat
= GdipSaveGraphics(graphics1
, NULL
);
117 expect(InvalidParameter
, stat
);
118 stat
= GdipSaveGraphics(NULL
, &state_a
);
119 expect(InvalidParameter
, stat
);
120 GdipDeleteGraphics(graphics1
);
122 log_state(state_a
, &state_log
);
124 /* Basic save/restore. */
125 GdipCreateFromHDC(hdc
, &graphics1
);
126 GdipSetInterpolationMode(graphics1
, InterpolationModeBilinear
);
127 stat
= GdipSaveGraphics(graphics1
, &state_a
);
130 GdipSetInterpolationMode(graphics1
, InterpolationModeBicubic
);
131 stat
= GdipRestoreGraphics(graphics1
, state_a
);
134 GdipGetInterpolationMode(graphics1
, &mode
);
136 expect(InterpolationModeBilinear
, mode
);
137 GdipDeleteGraphics(graphics1
);
139 log_state(state_a
, &state_log
);
141 /* Restoring garbage doesn't affect saves. */
142 GdipCreateFromHDC(hdc
, &graphics1
);
143 GdipSetInterpolationMode(graphics1
, InterpolationModeBilinear
);
144 GdipSaveGraphics(graphics1
, &state_a
);
145 GdipSetInterpolationMode(graphics1
, InterpolationModeBicubic
);
146 GdipSaveGraphics(graphics1
, &state_b
);
147 GdipSetInterpolationMode(graphics1
, InterpolationModeNearestNeighbor
);
148 stat
= GdipRestoreGraphics(graphics1
, 0xdeadbeef);
151 GdipRestoreGraphics(graphics1
, state_b
);
152 GdipGetInterpolationMode(graphics1
, &mode
);
154 expect(InterpolationModeBicubic
, mode
);
155 GdipRestoreGraphics(graphics1
, state_a
);
156 GdipGetInterpolationMode(graphics1
, &mode
);
158 expect(InterpolationModeBilinear
, mode
);
159 GdipDeleteGraphics(graphics1
);
161 log_state(state_a
, &state_log
);
162 log_state(state_b
, &state_log
);
164 /* Restoring older state invalidates newer saves (but not older saves). */
165 GdipCreateFromHDC(hdc
, &graphics1
);
166 GdipSetInterpolationMode(graphics1
, InterpolationModeBilinear
);
167 GdipSaveGraphics(graphics1
, &state_a
);
168 GdipSetInterpolationMode(graphics1
, InterpolationModeBicubic
);
169 GdipSaveGraphics(graphics1
, &state_b
);
170 GdipSetInterpolationMode(graphics1
, InterpolationModeNearestNeighbor
);
171 GdipSaveGraphics(graphics1
, &state_c
);
172 GdipSetInterpolationMode(graphics1
, InterpolationModeHighQualityBilinear
);
173 GdipRestoreGraphics(graphics1
, state_b
);
174 GdipGetInterpolationMode(graphics1
, &mode
);
176 expect(InterpolationModeBicubic
, mode
);
177 GdipRestoreGraphics(graphics1
, state_c
);
178 GdipGetInterpolationMode(graphics1
, &mode
);
180 expect(InterpolationModeBicubic
, mode
);
181 GdipRestoreGraphics(graphics1
, state_a
);
182 GdipGetInterpolationMode(graphics1
, &mode
);
184 expect(InterpolationModeBilinear
, mode
);
185 GdipDeleteGraphics(graphics1
);
187 log_state(state_a
, &state_log
);
188 log_state(state_b
, &state_log
);
189 log_state(state_c
, &state_log
);
191 /* Restoring older save from one graphics object does not invalidate
192 * newer save from other graphics object. */
193 GdipCreateFromHDC(hdc
, &graphics1
);
194 GdipCreateFromHDC(hdc
, &graphics2
);
195 GdipSetInterpolationMode(graphics1
, InterpolationModeBilinear
);
196 GdipSaveGraphics(graphics1
, &state_a
);
197 GdipSetInterpolationMode(graphics2
, InterpolationModeBicubic
);
198 GdipSaveGraphics(graphics2
, &state_b
);
199 GdipSetInterpolationMode(graphics1
, InterpolationModeNearestNeighbor
);
200 GdipSetInterpolationMode(graphics2
, InterpolationModeNearestNeighbor
);
201 GdipRestoreGraphics(graphics1
, state_a
);
202 GdipGetInterpolationMode(graphics1
, &mode
);
204 expect(InterpolationModeBilinear
, mode
);
205 GdipRestoreGraphics(graphics2
, state_b
);
206 GdipGetInterpolationMode(graphics2
, &mode
);
208 expect(InterpolationModeBicubic
, mode
);
209 GdipDeleteGraphics(graphics1
);
210 GdipDeleteGraphics(graphics2
);
212 /* You can't restore a state to a graphics object that didn't save it. */
213 GdipCreateFromHDC(hdc
, &graphics1
);
214 GdipCreateFromHDC(hdc
, &graphics2
);
215 GdipSetInterpolationMode(graphics1
, InterpolationModeBilinear
);
216 GdipSaveGraphics(graphics1
, &state_a
);
217 GdipSetInterpolationMode(graphics1
, InterpolationModeNearestNeighbor
);
218 GdipSetInterpolationMode(graphics2
, InterpolationModeNearestNeighbor
);
219 GdipRestoreGraphics(graphics2
, state_a
);
220 GdipGetInterpolationMode(graphics2
, &mode
);
221 expect(InterpolationModeNearestNeighbor
, mode
);
222 GdipDeleteGraphics(graphics1
);
223 GdipDeleteGraphics(graphics2
);
225 log_state(state_a
, &state_log
);
227 /* The same state value should never be returned twice. */
229 check_no_duplicates(state_log
);
234 static void test_GdipDrawArc(void)
237 GpGraphics
*graphics
= NULL
;
241 /* make a graphics object and pen object */
242 status
= GdipCreateFromHDC(hdc
, &graphics
);
244 ok(hdc
!= NULL
, "Expected HDC to be initialized\n");
246 status
= GdipCreateFromHDC(hdc
, &graphics
);
248 ok(graphics
!= NULL
, "Expected graphics to be initialized\n");
250 status
= GdipCreatePen1((ARGB
)0xffff00ff, 10.0f
, UnitPixel
, &pen
);
252 ok(pen
!= NULL
, "Expected pen to be initialized\n");
254 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
255 status
= GdipDrawArc(NULL
, NULL
, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
256 expect(InvalidParameter
, status
);
258 status
= GdipDrawArc(graphics
, NULL
, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
259 expect(InvalidParameter
, status
);
261 status
= GdipDrawArc(NULL
, pen
, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
262 expect(InvalidParameter
, status
);
264 status
= GdipDrawArc(graphics
, pen
, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
265 expect(InvalidParameter
, status
);
267 status
= GdipDrawArc(graphics
, pen
, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
268 expect(InvalidParameter
, status
);
270 /* successful case */
271 status
= GdipDrawArc(graphics
, pen
, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
278 static void test_GdipDrawArcI(void)
281 GpGraphics
*graphics
= NULL
;
285 /* make a graphics object and pen object */
286 status
= GdipCreateFromHDC(hdc
, &graphics
);
288 ok(hdc
!= NULL
, "Expected HDC to be initialized\n");
290 status
= GdipCreateFromHDC(hdc
, &graphics
);
292 ok(graphics
!= NULL
, "Expected graphics to be initialized\n");
294 status
= GdipCreatePen1((ARGB
)0xffff00ff, 10.0f
, UnitPixel
, &pen
);
296 ok(pen
!= NULL
, "Expected pen to be initialized\n");
298 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
299 status
= GdipDrawArcI(NULL
, NULL
, 0, 0, 0, 0, 0, 0);
300 expect(InvalidParameter
, status
);
302 status
= GdipDrawArcI(graphics
, NULL
, 0, 0, 1, 1, 0, 0);
303 expect(InvalidParameter
, status
);
305 status
= GdipDrawArcI(NULL
, pen
, 0, 0, 1, 1, 0, 0);
306 expect(InvalidParameter
, status
);
308 status
= GdipDrawArcI(graphics
, pen
, 0, 0, 1, 0, 0, 0);
309 expect(InvalidParameter
, status
);
311 status
= GdipDrawArcI(graphics
, pen
, 0, 0, 0, 1, 0, 0);
312 expect(InvalidParameter
, status
);
314 /* successful case */
315 status
= GdipDrawArcI(graphics
, pen
, 0, 0, 1, 1, 0, 0);
322 static void test_GdipDrawBezierI(void)
325 GpGraphics
*graphics
= NULL
;
329 /* make a graphics object and pen object */
330 status
= GdipCreateFromHDC(hdc
, &graphics
);
332 ok(hdc
!= NULL
, "Expected HDC to be initialized\n");
334 status
= GdipCreateFromHDC(hdc
, &graphics
);
336 ok(graphics
!= NULL
, "Expected graphics to be initialized\n");
338 status
= GdipCreatePen1((ARGB
)0xffff00ff, 10.0f
, UnitPixel
, &pen
);
340 ok(pen
!= NULL
, "Expected pen to be initialized\n");
342 /* InvalidParameter cases: null graphics, null pen */
343 status
= GdipDrawBezierI(NULL
, NULL
, 0, 0, 0, 0, 0, 0, 0, 0);
344 expect(InvalidParameter
, status
);
346 status
= GdipDrawBezierI(graphics
, NULL
, 0, 0, 0, 0, 0, 0, 0, 0);
347 expect(InvalidParameter
, status
);
349 status
= GdipDrawBezierI(NULL
, pen
, 0, 0, 0, 0, 0, 0, 0, 0);
350 expect(InvalidParameter
, status
);
352 /* successful case */
353 status
= GdipDrawBezierI(graphics
, pen
, 0, 0, 0, 0, 0, 0, 0, 0);
360 static void test_GdipDrawLineI(void)
363 GpGraphics
*graphics
= NULL
;
367 /* make a graphics object and pen object */
368 status
= GdipCreateFromHDC(hdc
, &graphics
);
370 ok(hdc
!= NULL
, "Expected HDC to be initialized\n");
372 status
= GdipCreateFromHDC(hdc
, &graphics
);
374 ok(graphics
!= NULL
, "Expected graphics to be initialized\n");
376 status
= GdipCreatePen1((ARGB
)0xffff00ff, 10.0f
, UnitPixel
, &pen
);
378 ok(pen
!= NULL
, "Expected pen to be initialized\n");
380 /* InvalidParameter cases: null graphics, null pen */
381 status
= GdipDrawLineI(NULL
, NULL
, 0, 0, 0, 0);
382 expect(InvalidParameter
, status
);
384 status
= GdipDrawLineI(graphics
, NULL
, 0, 0, 0, 0);
385 expect(InvalidParameter
, status
);
387 status
= GdipDrawLineI(NULL
, pen
, 0, 0, 0, 0);
388 expect(InvalidParameter
, status
);
390 /* successful case */
391 status
= GdipDrawLineI(graphics
, pen
, 0, 0, 0, 0);
398 static void test_GdipDrawLinesI(void)
401 GpGraphics
*graphics
= NULL
;
406 /* make a graphics object and pen object */
407 status
= GdipCreateFromHDC(hdc
, &graphics
);
409 ok(hdc
!= NULL
, "Expected HDC to be initialized\n");
411 status
= GdipCreateFromHDC(hdc
, &graphics
);
413 ok(graphics
!= NULL
, "Expected graphics to be initialized\n");
415 status
= GdipCreatePen1((ARGB
)0xffff00ff, 10.0f
, UnitPixel
, &pen
);
417 ok(pen
!= NULL
, "Expected pen to be initialized\n");
419 /* make some arbitrary valid points*/
420 ptf
= GdipAlloc(2 * sizeof(GpPointF
));
428 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
429 status
= GdipDrawLinesI(NULL
, NULL
, NULL
, 0);
430 expect(InvalidParameter
, status
);
432 status
= GdipDrawLinesI(graphics
, pen
, ptf
, 0);
433 expect(InvalidParameter
, status
);
435 status
= GdipDrawLinesI(graphics
, NULL
, ptf
, 2);
436 expect(InvalidParameter
, status
);
438 status
= GdipDrawLinesI(NULL
, pen
, ptf
, 2);
439 expect(InvalidParameter
, status
);
441 /* successful case */
442 status
= GdipDrawLinesI(graphics
, pen
, ptf
, 2);
452 struct GdiplusStartupInput gdiplusStartupInput
;
453 ULONG_PTR gdiplusToken
;
455 gdiplusStartupInput
.GdiplusVersion
= 1;
456 gdiplusStartupInput
.DebugEventCallback
= NULL
;
457 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
458 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
460 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
462 test_constructor_destructor();
464 test_GdipDrawBezierI();
467 test_GdipDrawLineI();
468 test_GdipDrawLinesI();
470 GdiplusShutdown(gdiplusToken
);