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_GdipDrawArcI(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 = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
245 expect(InvalidParameter, status);
247 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
248 expect(InvalidParameter, status);
250 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
251 expect(InvalidParameter, status);
253 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
254 expect(InvalidParameter, status);
256 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
257 expect(InvalidParameter, status);
259 /* successful case */
260 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
267 static void test_GdipDrawBezierI(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 */
288 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
289 expect(InvalidParameter, status);
291 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
292 expect(InvalidParameter, status);
294 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
295 expect(InvalidParameter, status);
297 /* successful case */
298 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
307 struct GdiplusStartupInput gdiplusStartupInput;
308 ULONG_PTR gdiplusToken;
310 gdiplusStartupInput.GdiplusVersion = 1;
311 gdiplusStartupInput.DebugEventCallback = NULL;
312 gdiplusStartupInput.SuppressBackgroundThread = 0;
313 gdiplusStartupInput.SuppressExternalCodecs = 0;
315 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
317 test_constructor_destructor();
319 test_GdipDrawBezierI();
322 GdiplusShutdown(gdiplusToken);