gdiplus: Implement GdipSetEmpty.
[wine/gsoc_dplay.git] / dlls / gdiplus / tests / region.c
blob41359d8c59039fe72c9ae4bd65af75ec96dc7e4f
1 /*
2 * Unit test suite for gdiplus regions
4 * Copyright (C) 2008 Huw Davies
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 RGNDATA_RECT 0x10000000
27 #define RGNDATA_PATH 0x10000001
28 #define RGNDATA_EMPTY_RECT 0x10000002
29 #define RGNDATA_INFINITE_RECT 0x10000003
31 #define RGNDATA_MAGIC 0xdbc01001
32 #define RGNDATA_MAGIC2 0xdbc01002
34 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
36 #define expect_magic(value) ok(*value == RGNDATA_MAGIC || *value == RGNDATA_MAGIC2, "Expected a known magic value, got %8x\n", *value)
38 static inline void expect_dword(DWORD *value, DWORD expected)
40 ok(*value == expected, "expected %08x got %08x\n", expected, *value);
43 static inline void expect_float(DWORD *value, FLOAT expected)
45 FLOAT valuef = *(FLOAT*)value;
46 ok(valuef == expected, "expected %f got %f\n", expected, valuef);
49 /* We get shorts back, not INTs like a GpPoint */
50 typedef struct RegionDataPoint
52 short X, Y;
53 } RegionDataPoint;
55 static void test_getregiondata(void)
57 GpStatus status;
58 GpRegion *region, *region2;
59 RegionDataPoint *point;
60 UINT needed;
61 DWORD buf[100];
62 GpRect rect;
63 GpPath *path;
65 memset(buf, 0xee, sizeof(buf));
67 status = GdipCreateRegion(&region);
68 ok(status == Ok, "status %08x\n", status);
70 todo_wine
72 status = GdipGetRegionDataSize(region, &needed);
73 ok(status == Ok, "status %08x\n", status);
74 expect(20, needed);
75 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
76 ok(status == Ok, "status %08x\n", status);
77 expect(20, needed);
78 expect_dword(buf, 12);
79 trace("buf[1] = %08x\n", buf[1]);
80 expect_magic((DWORD*)(buf + 2));
81 expect_dword(buf + 3, 0);
82 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
84 status = GdipSetEmpty(region);
86 ok(status == Ok, "status %08x\n", status);
87 todo_wine
89 status = GdipGetRegionDataSize(region, &needed);
90 ok(status == Ok, "status %08x\n", status);
91 expect(20, needed);
92 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
93 ok(status == Ok, "status %08x\n", status);
94 expect(20, needed);
95 expect_dword(buf, 12);
96 trace("buf[1] = %08x\n", buf[1]);
97 expect_magic((DWORD*)(buf + 2));
98 expect_dword(buf + 3, 0);
99 expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
101 status = GdipSetInfinite(region);
102 ok(status == Ok, "status %08x\n", status);
103 status = GdipGetRegionDataSize(region, &needed);
104 ok(status == Ok, "status %08x\n", status);
105 expect(20, needed);
106 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
107 ok(status == Ok, "status %08x\n", status);
108 expect(20, needed);
109 expect_dword(buf, 12);
110 trace("buf[1] = %08x\n", buf[1]);
111 expect_magic((DWORD*)(buf + 2));
112 expect_dword(buf + 3, 0);
113 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
116 status = GdipDeleteRegion(region);
117 ok(status == Ok, "status %08x\n", status);
119 rect.X = 10;
120 rect.Y = 20;
121 rect.Width = 100;
122 rect.Height = 200;
123 todo_wine
125 status = GdipCreateRegionRectI(&rect, &region);
126 ok(status == Ok, "status %08x\n", status);
127 status = GdipGetRegionDataSize(region, &needed);
128 ok(status == Ok, "status %08x\n", status);
129 expect(36, needed);
130 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
131 ok(status == Ok, "status %08x\n", status);
132 expect(36, needed);
133 expect_dword(buf, 28);
134 trace("buf[1] = %08x\n", buf[1]);
135 expect_magic((DWORD*)(buf + 2));
136 expect_dword(buf + 3, 0);
137 expect_dword(buf + 4, RGNDATA_RECT);
138 expect_float(buf + 5, 10.0);
139 expect_float(buf + 6, 20.0);
140 expect_float(buf + 7, 100.0);
141 expect_float(buf + 8, 200.0);
143 rect.X = 50;
144 rect.Y = 30;
145 rect.Width = 10;
146 rect.Height = 20;
147 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
148 ok(status == Ok, "status %08x\n", status);
149 rect.X = 100;
150 rect.Y = 300;
151 rect.Width = 30;
152 rect.Height = 50;
153 status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
154 ok(status == Ok, "status %08x\n", status);
156 rect.X = 200;
157 rect.Y = 100;
158 rect.Width = 133;
159 rect.Height = 266;
160 status = GdipCreateRegionRectI(&rect, &region2);
161 ok(status == Ok, "status %08x\n", status);
162 rect.X = 20;
163 rect.Y = 10;
164 rect.Width = 40;
165 rect.Height = 66;
166 status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
167 ok(status == Ok, "status %08x\n", status);
169 status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
170 ok(status == Ok, "status %08x\n", status);
172 rect.X = 400;
173 rect.Y = 500;
174 rect.Width = 22;
175 rect.Height = 55;
176 status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
177 ok(status == Ok, "status %08x\n", status);
179 status = GdipGetRegionDataSize(region, &needed);
180 ok(status == Ok, "status %08x\n", status);
181 expect(156, needed);
182 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
183 ok(status == Ok, "status %08x\n", status);
184 expect(156, needed);
185 expect_dword(buf, 148);
186 trace("buf[1] = %08x\n", buf[1]);
187 expect_magic((DWORD*)(buf + 2));
188 expect_dword(buf + 3, 10);
189 expect_dword(buf + 4, CombineModeExclude);
190 expect_dword(buf + 5, CombineModeComplement);
191 expect_dword(buf + 6, CombineModeXor);
192 expect_dword(buf + 7, CombineModeIntersect);
193 expect_dword(buf + 8, RGNDATA_RECT);
194 expect_float(buf + 9, 10.0);
195 expect_float(buf + 10, 20.0);
196 expect_float(buf + 11, 100.0);
197 expect_float(buf + 12, 200.0);
198 expect_dword(buf + 13, RGNDATA_RECT);
199 expect_float(buf + 14, 50.0);
200 expect_float(buf + 15, 30.0);
201 expect_float(buf + 16, 10.0);
202 expect_float(buf + 17, 20.0);
203 expect_dword(buf + 18, RGNDATA_RECT);
204 expect_float(buf + 19, 100.0);
205 expect_float(buf + 20, 300.0);
206 expect_float(buf + 21, 30.0);
207 expect_float(buf + 22, 50.0);
208 expect_dword(buf + 23, CombineModeUnion);
209 expect_dword(buf + 24, RGNDATA_RECT);
210 expect_float(buf + 25, 200.0);
211 expect_float(buf + 26, 100.0);
212 expect_float(buf + 27, 133.0);
213 expect_float(buf + 28, 266.0);
214 expect_dword(buf + 29, RGNDATA_RECT);
215 expect_float(buf + 30, 20.0);
216 expect_float(buf + 31, 10.0);
217 expect_float(buf + 32, 40.0);
218 expect_float(buf + 33, 66.0);
219 expect_dword(buf + 34, RGNDATA_RECT);
220 expect_float(buf + 35, 400.0);
221 expect_float(buf + 36, 500.0);
222 expect_float(buf + 37, 22.0);
223 expect_float(buf + 38, 55.0);
225 status = GdipDeleteRegion(region2);
226 ok(status == Ok, "status %08x\n", status);
227 status = GdipDeleteRegion(region);
228 ok(status == Ok, "status %08x\n", status);
231 /* Try some paths */
233 status = GdipCreatePath(FillModeAlternate, &path);
234 ok(status == Ok, "status %08x\n", status);
235 todo_wine
237 GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
239 status = GdipCreateRegionPath(path, &region);
240 ok(status == Ok, "status %08x\n", status);
241 status = GdipGetRegionDataSize(region, &needed);
242 ok(status == Ok, "status %08x\n", status);
243 expect(72, needed);
244 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
245 ok(status == Ok, "status %08x\n", status);
246 expect(72, needed);
247 expect_dword(buf, 64);
248 trace("buf[1] = %08x\n", buf[1]);
249 expect_magic((DWORD*)(buf + 2));
250 expect_dword(buf + 3, 0);
251 expect_dword(buf + 4, RGNDATA_PATH);
252 expect_dword(buf + 5, 0x00000030);
253 expect_magic((DWORD*)(buf + 6));
254 expect_dword(buf + 7, 0x00000004);
255 expect_dword(buf + 8, 0x00000000);
256 expect_float(buf + 9, 12.5);
257 expect_float(buf + 10, 13.0);
258 expect_float(buf + 11, 26.5);
259 expect_float(buf + 12, 13.0);
260 expect_float(buf + 13, 26.5);
261 expect_float(buf + 14, 28.0);
262 expect_float(buf + 15, 12.5);
263 expect_float(buf + 16, 28.0);
264 expect_dword(buf + 17, 0x81010100);
267 rect.X = 50;
268 rect.Y = 30;
269 rect.Width = 10;
270 rect.Height = 20;
271 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
272 ok(status == Ok, "status %08x\n", status);
273 status = GdipGetRegionDataSize(region, &needed);
274 ok(status == Ok, "status %08x\n", status);
275 expect(96, needed);
276 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
277 ok(status == Ok, "status %08x\n", status);
278 expect(96, needed);
279 expect_dword(buf, 88);
280 trace("buf[1] = %08x\n", buf[1]);
281 expect_magic((DWORD*)(buf + 2));
282 expect_dword(buf + 3, 2);
283 expect_dword(buf + 4, CombineModeIntersect);
284 expect_dword(buf + 5, RGNDATA_PATH);
285 expect_dword(buf + 6, 0x00000030);
286 expect_magic((DWORD*)(buf + 7));
287 expect_dword(buf + 8, 0x00000004);
288 expect_dword(buf + 9, 0x00000000);
289 expect_float(buf + 10, 12.5);
290 expect_float(buf + 11, 13.0);
291 expect_float(buf + 12, 26.5);
292 expect_float(buf + 13, 13.0);
293 expect_float(buf + 14, 26.5);
294 expect_float(buf + 15, 28.0);
295 expect_float(buf + 16, 12.5);
296 expect_float(buf + 17, 28.0);
297 expect_dword(buf + 18, 0x81010100);
298 expect_dword(buf + 19, RGNDATA_RECT);
299 expect_float(buf + 20, 50.0);
300 expect_float(buf + 21, 30.0);
301 expect_float(buf + 22, 10.0);
302 expect_float(buf + 23, 20.0);
304 status = GdipDeleteRegion(region);
305 ok(status == Ok, "status %08x\n", status);
307 status = GdipDeletePath(path);
308 ok(status == Ok, "status %08x\n", status);
310 /* Test an empty path */
311 status = GdipCreatePath(FillModeAlternate, &path);
312 expect(Ok, status);
313 todo_wine
315 status = GdipCreateRegionPath(path, &region);
316 expect(Ok, status);
317 status = GdipGetRegionDataSize(region, &needed);
318 expect(Ok, status);
319 expect(36, needed);
320 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
321 expect(Ok, status);
322 expect(36, needed);
323 expect_dword(buf, 28);
324 trace("buf[1] = %08x\n", buf[1]);
325 expect_magic((DWORD*)(buf + 2));
326 expect_dword(buf + 3, 0);
327 expect_dword(buf + 4, RGNDATA_PATH);
329 /* Second signature for pathdata */
330 expect_dword(buf + 5, 12);
331 expect_magic((DWORD*)(buf + 6));
332 expect_dword(buf + 7, 0);
333 expect_dword(buf + 8, 0x00004000);
335 status = GdipDeleteRegion(region);
336 expect(Ok, status);
339 /* Test a simple triangle of INTs */
340 status = GdipAddPathLine(path, 5, 6, 7, 8);
341 expect(Ok, status);
342 status = GdipAddPathLine(path, 8, 1, 5, 6);
343 expect(Ok, status);
344 status = GdipClosePathFigure(path);
345 expect(Ok, status);
346 todo_wine
348 status = GdipCreateRegionPath(path, &region);
349 expect(Ok, status);
350 status = GdipGetRegionDataSize(region, &needed);
351 expect(Ok, status);
352 expect(56, needed);
353 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
354 expect(Ok, status);
355 expect(56, needed);
356 expect_dword(buf, 48);
357 trace("buf[1] = %08x\n", buf[1]);
358 expect_magic((DWORD*)(buf + 2));
359 expect_dword(buf + 3 , 0);
360 expect_dword(buf + 4 , RGNDATA_PATH);
362 expect_dword(buf + 5, 32);
363 expect_magic((DWORD*)(buf + 6));
364 expect_dword(buf + 7, 4);
365 expect_dword(buf + 8, 0x00004000); /* ?? */
367 point = (RegionDataPoint*)buf + 9;
368 expect(5, point[0].X);
369 expect(6, point[0].Y);
370 expect(7, point[1].X); /* buf + 10 */
371 expect(8, point[1].Y);
372 expect(8, point[2].X); /* buf + 11 */
373 expect(1, point[2].Y);
374 expect(5, point[3].X); /* buf + 12 */
375 expect(6, point[3].Y);
376 expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
378 status = GdipDeletePath(path);
379 expect(Ok, status);
380 status = GdipDeleteRegion(region);
381 todo_wine
382 expect(Ok, status);
384 /* Test a floating-point triangle */
385 status = GdipCreatePath(FillModeAlternate, &path);
386 expect(Ok, status);
387 status = GdipAddPathLine(path, 5.6, 6.2, 7.2, 8.9);
388 expect(Ok, status);
389 status = GdipAddPathLine(path, 8.1, 1.6, 5.6, 6.2);
390 expect(Ok, status);
391 todo_wine
393 status = GdipCreateRegionPath(path, &region);
394 expect(Ok, status);
395 status = GdipGetRegionDataSize(region, &needed);
396 expect(Ok, status);
397 expect(72, needed);
398 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
399 expect(Ok, status);
400 expect(72, needed);
401 expect_dword(buf, 64);
402 trace("buf[1] = %08x\n", buf[1]);
403 expect_magic((DWORD*)(buf + 2));
404 expect_dword(buf + 3, 0);
405 expect_dword(buf + 4, RGNDATA_PATH);
407 expect_dword(buf + 5, 48);
408 expect_magic((DWORD*)(buf + 6));
409 expect_dword(buf + 7, 4);
410 expect_dword(buf + 8, 0);
411 expect_float(buf + 9, 5.6);
412 expect_float(buf + 10, 6.2);
413 expect_float(buf + 11, 7.2);
414 expect_float(buf + 12, 8.9);
415 expect_float(buf + 13, 8.1);
416 expect_float(buf + 14, 1.6);
417 expect_float(buf + 15, 5.6);
418 expect_float(buf + 16, 6.2);
421 status = GdipDeletePath(path);
422 expect(Ok, status);
423 status = GdipDeleteRegion(region);
424 todo_wine
425 expect(Ok, status);
428 START_TEST(region)
430 struct GdiplusStartupInput gdiplusStartupInput;
431 ULONG_PTR gdiplusToken;
433 gdiplusStartupInput.GdiplusVersion = 1;
434 gdiplusStartupInput.DebugEventCallback = NULL;
435 gdiplusStartupInput.SuppressBackgroundThread = 0;
436 gdiplusStartupInput.SuppressExternalCodecs = 0;
438 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
440 test_getregiondata();
442 GdiplusShutdown(gdiplusToken);