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)
80 HeapFree(GetProcessHeap(), 0, temp);
82 while((temp = temp->next))
83 if(log->data == temp->data)
86 }while((log = log->next));
88 HeapFree(GetProcessHeap(), 0, temp);
94 static void test_save_restore(void)
97 GraphicsState state_a, state_b, state_c;
98 InterpolationMode mode;
99 GpGraphics *graphics1, *graphics2;
100 node * state_log = NULL;
103 /* Invalid saving. */
104 GdipCreateFromHDC(hdc, &graphics1);
105 stat = GdipSaveGraphics(graphics1, NULL);
106 expect(InvalidParameter, stat);
107 stat = GdipSaveGraphics(NULL, &state_a);
108 expect(InvalidParameter, stat);
109 GdipDeleteGraphics(graphics1);
111 log_state(state_a, &state_log);
113 /* Basic save/restore. */
114 GdipCreateFromHDC(hdc, &graphics1);
115 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
116 stat = GdipSaveGraphics(graphics1, &state_a);
119 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
120 stat = GdipRestoreGraphics(graphics1, state_a);
123 GdipGetInterpolationMode(graphics1, &mode);
125 expect(InterpolationModeBilinear, mode);
126 GdipDeleteGraphics(graphics1);
128 log_state(state_a, &state_log);
130 /* Restoring garbage doesn't affect saves. */
131 GdipCreateFromHDC(hdc, &graphics1);
132 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
133 GdipSaveGraphics(graphics1, &state_a);
134 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
135 GdipSaveGraphics(graphics1, &state_b);
136 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
137 stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
140 GdipRestoreGraphics(graphics1, state_b);
141 GdipGetInterpolationMode(graphics1, &mode);
143 expect(InterpolationModeBicubic, mode);
144 GdipRestoreGraphics(graphics1, state_a);
145 GdipGetInterpolationMode(graphics1, &mode);
147 expect(InterpolationModeBilinear, mode);
148 GdipDeleteGraphics(graphics1);
150 log_state(state_a, &state_log);
151 log_state(state_b, &state_log);
153 /* Restoring older state invalidates newer saves (but not older saves). */
154 GdipCreateFromHDC(hdc, &graphics1);
155 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
156 GdipSaveGraphics(graphics1, &state_a);
157 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
158 GdipSaveGraphics(graphics1, &state_b);
159 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
160 GdipSaveGraphics(graphics1, &state_c);
161 GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
162 GdipRestoreGraphics(graphics1, state_b);
163 GdipGetInterpolationMode(graphics1, &mode);
165 expect(InterpolationModeBicubic, mode);
166 GdipRestoreGraphics(graphics1, state_c);
167 GdipGetInterpolationMode(graphics1, &mode);
169 expect(InterpolationModeBicubic, mode);
170 GdipRestoreGraphics(graphics1, state_a);
171 GdipGetInterpolationMode(graphics1, &mode);
173 expect(InterpolationModeBilinear, mode);
174 GdipDeleteGraphics(graphics1);
176 log_state(state_a, &state_log);
177 log_state(state_b, &state_log);
178 log_state(state_c, &state_log);
180 /* Restoring older save from one graphics object does not invalidate
181 * newer save from other graphics object. */
182 GdipCreateFromHDC(hdc, &graphics1);
183 GdipCreateFromHDC(hdc, &graphics2);
184 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
185 GdipSaveGraphics(graphics1, &state_a);
186 GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
187 GdipSaveGraphics(graphics2, &state_b);
188 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
189 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
190 GdipRestoreGraphics(graphics1, state_a);
191 GdipGetInterpolationMode(graphics1, &mode);
193 expect(InterpolationModeBilinear, mode);
194 GdipRestoreGraphics(graphics2, state_b);
195 GdipGetInterpolationMode(graphics2, &mode);
197 expect(InterpolationModeBicubic, mode);
198 GdipDeleteGraphics(graphics1);
199 GdipDeleteGraphics(graphics2);
201 /* You can't restore a state to a graphics object that didn't save it. */
202 GdipCreateFromHDC(hdc, &graphics1);
203 GdipCreateFromHDC(hdc, &graphics2);
204 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
205 GdipSaveGraphics(graphics1, &state_a);
206 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
207 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
208 GdipRestoreGraphics(graphics2, state_a);
209 GdipGetInterpolationMode(graphics2, &mode);
210 expect(InterpolationModeNearestNeighbor, mode);
211 GdipDeleteGraphics(graphics1);
212 GdipDeleteGraphics(graphics2);
214 log_state(state_a, &state_log);
216 /* The same state value should never be returned twice. */
218 check_no_duplicates(state_log);
223 static void test_GdipDrawArc(void)
226 GpGraphics *graphics = NULL;
230 /* make a graphics object and pen object */
231 status = GdipCreateFromHDC(hdc, &graphics);
233 ok(hdc != NULL, "Expected HDC to be initialized\n");
235 status = GdipCreateFromHDC(hdc, &graphics);
237 ok(graphics != NULL, "Expected graphics to be initialized\n");
239 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
241 ok(pen != NULL, "Expected pen to be initialized\n");
243 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
244 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
245 expect(InvalidParameter, status);
247 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
248 expect(InvalidParameter, status);
250 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
251 expect(InvalidParameter, status);
253 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
254 expect(InvalidParameter, status);
256 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
257 expect(InvalidParameter, status);
259 /* successful case */
260 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
267 static void test_GdipDrawArcI(void)
270 GpGraphics *graphics = NULL;
274 /* make a graphics object and pen object */
275 status = GdipCreateFromHDC(hdc, &graphics);
277 ok(hdc != NULL, "Expected HDC to be initialized\n");
279 status = GdipCreateFromHDC(hdc, &graphics);
281 ok(graphics != NULL, "Expected graphics to be initialized\n");
283 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
285 ok(pen != NULL, "Expected pen to be initialized\n");
287 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
288 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
289 expect(InvalidParameter, status);
291 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
292 expect(InvalidParameter, status);
294 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
295 expect(InvalidParameter, status);
297 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
298 expect(InvalidParameter, status);
300 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
301 expect(InvalidParameter, status);
303 /* successful case */
304 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
311 static void test_GdipDrawBezierI(void)
314 GpGraphics *graphics = NULL;
318 /* make a graphics object and pen object */
319 status = GdipCreateFromHDC(hdc, &graphics);
321 ok(hdc != NULL, "Expected HDC to be initialized\n");
323 status = GdipCreateFromHDC(hdc, &graphics);
325 ok(graphics != NULL, "Expected graphics to be initialized\n");
327 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
329 ok(pen != NULL, "Expected pen to be initialized\n");
331 /* InvalidParameter cases: null graphics, null pen */
332 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
333 expect(InvalidParameter, status);
335 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
336 expect(InvalidParameter, status);
338 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
339 expect(InvalidParameter, status);
341 /* successful case */
342 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
349 static void test_GdipDrawLineI(void)
352 GpGraphics *graphics = NULL;
356 /* make a graphics object and pen object */
357 status = GdipCreateFromHDC(hdc, &graphics);
359 ok(hdc != NULL, "Expected HDC to be initialized\n");
361 status = GdipCreateFromHDC(hdc, &graphics);
363 ok(graphics != NULL, "Expected graphics to be initialized\n");
365 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
367 ok(pen != NULL, "Expected pen to be initialized\n");
369 /* InvalidParameter cases: null graphics, null pen */
370 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
371 expect(InvalidParameter, status);
373 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
374 expect(InvalidParameter, status);
376 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
377 expect(InvalidParameter, status);
379 /* successful case */
380 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
387 static void test_GdipDrawLinesI(void)
390 GpGraphics *graphics = NULL;
395 /* make a graphics object and pen object */
396 status = GdipCreateFromHDC(hdc, &graphics);
398 ok(hdc != NULL, "Expected HDC to be initialized\n");
400 status = GdipCreateFromHDC(hdc, &graphics);
402 ok(graphics != NULL, "Expected graphics to be initialized\n");
404 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
406 ok(pen != NULL, "Expected pen to be initialized\n");
408 /* make some arbitrary valid points*/
409 ptf = GdipAlloc(2 * sizeof(GpPointF));
417 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
418 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
419 expect(InvalidParameter, status);
421 status = GdipDrawLinesI(graphics, pen, ptf, 0);
422 expect(InvalidParameter, status);
424 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
425 expect(InvalidParameter, status);
427 status = GdipDrawLinesI(NULL, pen, ptf, 2);
428 expect(InvalidParameter, status);
430 /* successful case */
431 status = GdipDrawLinesI(graphics, pen, ptf, 2);
441 struct GdiplusStartupInput gdiplusStartupInput;
442 ULONG_PTR gdiplusToken;
444 gdiplusStartupInput.GdiplusVersion = 1;
445 gdiplusStartupInput.DebugEventCallback = NULL;
446 gdiplusStartupInput.SuppressBackgroundThread = 0;
447 gdiplusStartupInput.SuppressExternalCodecs = 0;
449 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
451 test_constructor_destructor();
453 test_GdipDrawBezierI();
456 test_GdipDrawLineI();
457 test_GdipDrawLinesI();
459 GdiplusShutdown(gdiplusToken);