push 83f6eeab4f78cf34cba36fe6c2150f9c23ec0aba
[wine/hacks.git] / dlls / gdiplus / tests / graphics.c
blobde29bfb2516d716f975071489d0a6ab696b9dec2
1 /*
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
21 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wingdi.h"
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)
31 GpStatus stat;
32 GpGraphics *graphics = NULL;
33 HDC hdc = GetDC(0);
35 stat = GdipCreateFromHDC(NULL, &graphics);
36 expect(OutOfMemory, stat);
37 stat = GdipDeleteGraphics(graphics);
38 expect(InvalidParameter, stat);
40 stat = GdipCreateFromHDC(hdc, &graphics);
41 expect(Ok, stat);
42 stat = GdipDeleteGraphics(graphics);
43 expect(Ok, stat);
45 stat = GdipCreateFromHWND(NULL, &graphics);
46 expect(Ok, stat);
47 stat = GdipDeleteGraphics(graphics);
48 expect(Ok, stat);
50 stat = GdipDeleteGraphics(NULL);
51 expect(InvalidParameter, stat);
52 ReleaseDC(0, hdc);
55 typedef struct node{
56 GraphicsState data;
57 struct node * next;
58 } node;
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;
67 *log = new_entry;
70 /* Checks if there are duplicates in the list, and frees it. */
71 static void check_no_duplicates(node * log)
73 INT dups = 0;
74 node * temp = NULL;
76 if(!log)
77 goto end;
79 do{
80 HeapFree(GetProcessHeap(), 0, temp);
81 temp = log;
82 while((temp = temp->next))
83 if(log->data == temp->data)
84 dups++;
86 }while((log = log->next));
88 HeapFree(GetProcessHeap(), 0, temp);
90 end:
91 expect(0, dups);
94 static void test_save_restore(void)
96 GpStatus stat;
97 GraphicsState state_a, state_b, state_c;
98 InterpolationMode mode;
99 GpGraphics *graphics1, *graphics2;
100 node * state_log = NULL;
101 HDC hdc = GetDC(0);
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);
117 todo_wine
118 expect(Ok, stat);
119 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
120 stat = GdipRestoreGraphics(graphics1, state_a);
121 todo_wine
122 expect(Ok, stat);
123 GdipGetInterpolationMode(graphics1, &mode);
124 todo_wine
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);
138 todo_wine
139 expect(Ok, stat);
140 GdipRestoreGraphics(graphics1, state_b);
141 GdipGetInterpolationMode(graphics1, &mode);
142 todo_wine
143 expect(InterpolationModeBicubic, mode);
144 GdipRestoreGraphics(graphics1, state_a);
145 GdipGetInterpolationMode(graphics1, &mode);
146 todo_wine
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);
164 todo_wine
165 expect(InterpolationModeBicubic, mode);
166 GdipRestoreGraphics(graphics1, state_c);
167 GdipGetInterpolationMode(graphics1, &mode);
168 todo_wine
169 expect(InterpolationModeBicubic, mode);
170 GdipRestoreGraphics(graphics1, state_a);
171 GdipGetInterpolationMode(graphics1, &mode);
172 todo_wine
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);
192 todo_wine
193 expect(InterpolationModeBilinear, mode);
194 GdipRestoreGraphics(graphics2, state_b);
195 GdipGetInterpolationMode(graphics2, &mode);
196 todo_wine
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. */
217 todo_wine
218 check_no_duplicates(state_log);
220 ReleaseDC(0, hdc);
223 START_TEST(graphics)
225 struct GdiplusStartupInput gdiplusStartupInput;
226 ULONG_PTR gdiplusToken;
228 gdiplusStartupInput.GdiplusVersion = 1;
229 gdiplusStartupInput.DebugEventCallback = NULL;
230 gdiplusStartupInput.SuppressBackgroundThread = 0;
231 gdiplusStartupInput.SuppressExternalCodecs = 0;
233 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
235 test_constructor_destructor();
236 test_save_restore();
238 GdiplusShutdown(gdiplusToken);