push 63c1876572cbb61a874995ad42ef27c14590d232
[wine/hacks.git] / dlls / gdiplus / tests / region.c
blob0b8ed4160f9c0f43be5706b97c2f5e2aaa110c1e
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 status = GdipGetRegionDataSize(region, &needed);
71 ok(status == Ok, "status %08x\n", status);
72 expect(20, needed);
73 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
74 ok(status == Ok, "status %08x\n", status);
75 expect(20, needed);
76 expect_dword(buf, 12);
77 trace("buf[1] = %08x\n", buf[1]);
78 expect_magic((DWORD*)(buf + 2));
79 expect_dword(buf + 3, 0);
80 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
82 status = GdipSetEmpty(region);
83 ok(status == Ok, "status %08x\n", status);
84 status = GdipGetRegionDataSize(region, &needed);
85 ok(status == Ok, "status %08x\n", status);
86 expect(20, needed);
87 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
88 ok(status == Ok, "status %08x\n", status);
89 expect(20, needed);
90 expect_dword(buf, 12);
91 trace("buf[1] = %08x\n", buf[1]);
92 expect_magic((DWORD*)(buf + 2));
93 expect_dword(buf + 3, 0);
94 expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
96 status = GdipSetInfinite(region);
97 ok(status == Ok, "status %08x\n", status);
98 status = GdipGetRegionDataSize(region, &needed);
99 ok(status == Ok, "status %08x\n", status);
100 expect(20, needed);
101 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
102 ok(status == Ok, "status %08x\n", status);
103 expect(20, needed);
104 expect_dword(buf, 12);
105 trace("buf[1] = %08x\n", buf[1]);
106 expect_magic((DWORD*)(buf + 2));
107 expect_dword(buf + 3, 0);
108 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
110 status = GdipDeleteRegion(region);
111 ok(status == Ok, "status %08x\n", status);
113 rect.X = 10;
114 rect.Y = 20;
115 rect.Width = 100;
116 rect.Height = 200;
117 status = GdipCreateRegionRectI(&rect, &region);
118 ok(status == Ok, "status %08x\n", status);
119 status = GdipGetRegionDataSize(region, &needed);
120 ok(status == Ok, "status %08x\n", status);
121 expect(36, needed);
122 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
123 ok(status == Ok, "status %08x\n", status);
124 expect(36, needed);
125 expect_dword(buf, 28);
126 trace("buf[1] = %08x\n", buf[1]);
127 expect_magic((DWORD*)(buf + 2));
128 expect_dword(buf + 3, 0);
129 expect_dword(buf + 4, RGNDATA_RECT);
130 expect_float(buf + 5, 10.0);
131 expect_float(buf + 6, 20.0);
132 expect_float(buf + 7, 100.0);
133 expect_float(buf + 8, 200.0);
135 rect.X = 50;
136 rect.Y = 30;
137 rect.Width = 10;
138 rect.Height = 20;
139 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
140 ok(status == Ok, "status %08x\n", status);
141 rect.X = 100;
142 rect.Y = 300;
143 rect.Width = 30;
144 rect.Height = 50;
145 status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
146 ok(status == Ok, "status %08x\n", status);
148 rect.X = 200;
149 rect.Y = 100;
150 rect.Width = 133;
151 rect.Height = 266;
152 status = GdipCreateRegionRectI(&rect, &region2);
153 ok(status == Ok, "status %08x\n", status);
154 rect.X = 20;
155 rect.Y = 10;
156 rect.Width = 40;
157 rect.Height = 66;
158 status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
159 ok(status == Ok, "status %08x\n", status);
161 status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
162 ok(status == Ok, "status %08x\n", status);
164 rect.X = 400;
165 rect.Y = 500;
166 rect.Width = 22;
167 rect.Height = 55;
168 status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
169 ok(status == Ok, "status %08x\n", status);
171 status = GdipGetRegionDataSize(region, &needed);
172 ok(status == Ok, "status %08x\n", status);
173 expect(156, needed);
174 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
175 ok(status == Ok, "status %08x\n", status);
176 expect(156, needed);
177 expect_dword(buf, 148);
178 trace("buf[1] = %08x\n", buf[1]);
179 expect_magic((DWORD*)(buf + 2));
180 expect_dword(buf + 3, 10);
181 expect_dword(buf + 4, CombineModeExclude);
182 expect_dword(buf + 5, CombineModeComplement);
183 expect_dword(buf + 6, CombineModeXor);
184 expect_dword(buf + 7, CombineModeIntersect);
185 expect_dword(buf + 8, RGNDATA_RECT);
186 expect_float(buf + 9, 10.0);
187 expect_float(buf + 10, 20.0);
188 expect_float(buf + 11, 100.0);
189 expect_float(buf + 12, 200.0);
190 expect_dword(buf + 13, RGNDATA_RECT);
191 expect_float(buf + 14, 50.0);
192 expect_float(buf + 15, 30.0);
193 expect_float(buf + 16, 10.0);
194 expect_float(buf + 17, 20.0);
195 expect_dword(buf + 18, RGNDATA_RECT);
196 expect_float(buf + 19, 100.0);
197 expect_float(buf + 20, 300.0);
198 expect_float(buf + 21, 30.0);
199 expect_float(buf + 22, 50.0);
200 expect_dword(buf + 23, CombineModeUnion);
201 expect_dword(buf + 24, RGNDATA_RECT);
202 expect_float(buf + 25, 200.0);
203 expect_float(buf + 26, 100.0);
204 expect_float(buf + 27, 133.0);
205 expect_float(buf + 28, 266.0);
206 expect_dword(buf + 29, RGNDATA_RECT);
207 expect_float(buf + 30, 20.0);
208 expect_float(buf + 31, 10.0);
209 expect_float(buf + 32, 40.0);
210 expect_float(buf + 33, 66.0);
211 expect_dword(buf + 34, RGNDATA_RECT);
212 expect_float(buf + 35, 400.0);
213 expect_float(buf + 36, 500.0);
214 expect_float(buf + 37, 22.0);
215 expect_float(buf + 38, 55.0);
217 status = GdipDeleteRegion(region2);
218 ok(status == Ok, "status %08x\n", status);
219 status = GdipDeleteRegion(region);
220 ok(status == Ok, "status %08x\n", status);
222 /* Try some paths */
224 status = GdipCreatePath(FillModeAlternate, &path);
225 ok(status == Ok, "status %08x\n", status);
226 GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
228 status = GdipCreateRegionPath(path, &region);
229 ok(status == Ok, "status %08x\n", status);
230 status = GdipGetRegionDataSize(region, &needed);
231 ok(status == Ok, "status %08x\n", status);
232 expect(72, needed);
233 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
234 ok(status == Ok, "status %08x\n", status);
235 expect(72, needed);
236 expect_dword(buf, 64);
237 trace("buf[1] = %08x\n", buf[1]);
238 expect_magic((DWORD*)(buf + 2));
239 expect_dword(buf + 3, 0);
240 expect_dword(buf + 4, RGNDATA_PATH);
241 expect_dword(buf + 5, 0x00000030);
242 expect_magic((DWORD*)(buf + 6));
243 expect_dword(buf + 7, 0x00000004);
244 expect_dword(buf + 8, 0x00000000);
245 expect_float(buf + 9, 12.5);
246 expect_float(buf + 10, 13.0);
247 expect_float(buf + 11, 26.5);
248 expect_float(buf + 12, 13.0);
249 expect_float(buf + 13, 26.5);
250 expect_float(buf + 14, 28.0);
251 expect_float(buf + 15, 12.5);
252 expect_float(buf + 16, 28.0);
253 expect_dword(buf + 17, 0x81010100);
256 rect.X = 50;
257 rect.Y = 30;
258 rect.Width = 10;
259 rect.Height = 20;
260 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
261 ok(status == Ok, "status %08x\n", status);
262 status = GdipGetRegionDataSize(region, &needed);
263 ok(status == Ok, "status %08x\n", status);
264 expect(96, needed);
265 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
266 ok(status == Ok, "status %08x\n", status);
267 expect(96, needed);
268 expect_dword(buf, 88);
269 trace("buf[1] = %08x\n", buf[1]);
270 expect_magic((DWORD*)(buf + 2));
271 expect_dword(buf + 3, 2);
272 expect_dword(buf + 4, CombineModeIntersect);
273 expect_dword(buf + 5, RGNDATA_PATH);
274 expect_dword(buf + 6, 0x00000030);
275 expect_magic((DWORD*)(buf + 7));
276 expect_dword(buf + 8, 0x00000004);
277 expect_dword(buf + 9, 0x00000000);
278 expect_float(buf + 10, 12.5);
279 expect_float(buf + 11, 13.0);
280 expect_float(buf + 12, 26.5);
281 expect_float(buf + 13, 13.0);
282 expect_float(buf + 14, 26.5);
283 expect_float(buf + 15, 28.0);
284 expect_float(buf + 16, 12.5);
285 expect_float(buf + 17, 28.0);
286 expect_dword(buf + 18, 0x81010100);
287 expect_dword(buf + 19, RGNDATA_RECT);
288 expect_float(buf + 20, 50.0);
289 expect_float(buf + 21, 30.0);
290 expect_float(buf + 22, 10.0);
291 expect_float(buf + 23, 20.0);
293 status = GdipDeleteRegion(region);
294 ok(status == Ok, "status %08x\n", status);
295 status = GdipDeletePath(path);
296 ok(status == Ok, "status %08x\n", status);
298 /* Test an empty path */
299 status = GdipCreatePath(FillModeAlternate, &path);
300 expect(Ok, status);
301 status = GdipCreateRegionPath(path, &region);
302 expect(Ok, status);
303 status = GdipGetRegionDataSize(region, &needed);
304 expect(Ok, status);
305 expect(36, needed);
306 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
307 expect(Ok, status);
308 expect(36, needed);
309 expect_dword(buf, 28);
310 trace("buf[1] = %08x\n", buf[1]);
311 expect_magic((DWORD*)(buf + 2));
312 expect_dword(buf + 3, 0);
313 expect_dword(buf + 4, RGNDATA_PATH);
315 /* Second signature for pathdata */
316 expect_dword(buf + 5, 12);
317 expect_magic((DWORD*)(buf + 6));
318 expect_dword(buf + 7, 0);
319 expect_dword(buf + 8, 0x00004000);
321 status = GdipDeleteRegion(region);
322 expect(Ok, status);
324 /* Test a simple triangle of INTs */
325 status = GdipAddPathLine(path, 5, 6, 7, 8);
326 expect(Ok, status);
327 status = GdipAddPathLine(path, 8, 1, 5, 6);
328 expect(Ok, status);
329 status = GdipClosePathFigure(path);
330 expect(Ok, status);
331 status = GdipCreateRegionPath(path, &region);
332 expect(Ok, status);
333 status = GdipGetRegionDataSize(region, &needed);
334 expect(Ok, status);
335 expect(56, needed);
336 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
337 expect(Ok, status);
338 expect(56, needed);
339 expect_dword(buf, 48);
340 trace("buf[1] = %08x\n", buf[1]);
341 expect_magic((DWORD*)(buf + 2));
342 expect_dword(buf + 3 , 0);
343 expect_dword(buf + 4 , RGNDATA_PATH);
345 expect_dword(buf + 5, 32);
346 expect_magic((DWORD*)(buf + 6));
347 expect_dword(buf + 7, 4);
348 expect_dword(buf + 8, 0x00004000); /* ?? */
350 point = (RegionDataPoint*)buf + 9;
351 expect(5, point[0].X);
352 expect(6, point[0].Y);
353 expect(7, point[1].X); /* buf + 10 */
354 expect(8, point[1].Y);
355 expect(8, point[2].X); /* buf + 11 */
356 expect(1, point[2].Y);
357 expect(5, point[3].X); /* buf + 12 */
358 expect(6, point[3].Y);
359 expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
361 status = GdipDeletePath(path);
362 expect(Ok, status);
363 status = GdipDeleteRegion(region);
364 expect(Ok, status);
366 /* Test a floating-point triangle */
367 status = GdipCreatePath(FillModeAlternate, &path);
368 expect(Ok, status);
369 status = GdipAddPathLine(path, 5.6, 6.2, 7.2, 8.9);
370 expect(Ok, status);
371 status = GdipAddPathLine(path, 8.1, 1.6, 5.6, 6.2);
372 expect(Ok, status);
373 status = GdipCreateRegionPath(path, &region);
374 expect(Ok, status);
375 status = GdipGetRegionDataSize(region, &needed);
376 expect(Ok, status);
377 expect(72, needed);
378 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
379 expect(Ok, status);
380 expect(72, needed);
381 expect_dword(buf, 64);
382 trace("buf[1] = %08x\n", buf[1]);
383 expect_magic((DWORD*)(buf + 2));
384 expect_dword(buf + 3, 0);
385 expect_dword(buf + 4, RGNDATA_PATH);
387 expect_dword(buf + 5, 48);
388 expect_magic((DWORD*)(buf + 6));
389 expect_dword(buf + 7, 4);
390 expect_dword(buf + 8, 0);
391 expect_float(buf + 9, 5.6);
392 expect_float(buf + 10, 6.2);
393 expect_float(buf + 11, 7.2);
394 expect_float(buf + 12, 8.9);
395 expect_float(buf + 13, 8.1);
396 expect_float(buf + 14, 1.6);
397 expect_float(buf + 15, 5.6);
398 expect_float(buf + 16, 6.2);
400 status = GdipDeletePath(path);
401 expect(Ok, status);
402 status = GdipDeleteRegion(region);
403 expect(Ok, status);
405 /* Test for a path with > 4 points, and CombineRegionPath */
406 GdipCreatePath(FillModeAlternate, &path);
407 status = GdipAddPathLine(path, 50, 70.2, 60, 102.8);
408 expect(Ok, status);
409 status = GdipAddPathLine(path, 55.4, 122.4, 40.4, 60.2);
410 expect(Ok, status);
411 status = GdipAddPathLine(path, 45.6, 20.2, 50, 70.2);
412 expect(Ok, status);
413 rect.X = 20;
414 rect.Y = 25;
415 rect.Width = 60;
416 rect.Height = 120;
417 status = GdipCreateRegionRectI(&rect, &region);
418 expect(Ok, status);
419 status = GdipCombineRegionPath(region, path, CombineModeUnion);
420 expect(Ok, status);
422 status = GdipGetRegionDataSize(region, &needed);
423 expect(Ok, status);
424 expect(116, needed);
425 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
426 expect(Ok, status);
427 expect(116, needed);
428 expect_dword(buf, 108);
429 trace("buf[1] = %08x\n", buf[1]);
430 expect_magic((DWORD*)(buf + 2));
431 expect_dword(buf + 3, 2);
432 expect_dword(buf + 4, CombineModeUnion);
433 expect_dword(buf + 5, RGNDATA_RECT);
434 expect_float(buf + 6, 20);
435 expect_float(buf + 7, 25);
436 expect_float(buf + 8, 60);
437 expect_float(buf + 9, 120);
438 expect_dword(buf + 10, RGNDATA_PATH);
440 expect_dword(buf + 11, 68);
441 expect_magic((DWORD*)(buf + 12));
442 expect_dword(buf + 13, 6);
443 expect_float(buf + 14, 0x0);
445 expect_float(buf + 15, 50);
446 expect_float(buf + 16, 70.2);
447 expect_float(buf + 17, 60);
448 expect_float(buf + 18, 102.8);
449 expect_float(buf + 19, 55.4);
450 expect_float(buf + 20, 122.4);
451 expect_float(buf + 21, 40.4);
452 expect_float(buf + 22, 60.2);
453 expect_float(buf + 23, 45.6);
454 expect_float(buf + 24, 20.2);
455 expect_float(buf + 25, 50);
456 expect_float(buf + 26, 70.2);
457 expect_dword(buf + 27, 0x01010100);
458 expect_dword(buf + 28, 0x00000101);
460 status = GdipDeletePath(path);
461 expect(Ok, status);
462 status = GdipDeleteRegion(region);
463 expect(Ok, status);
466 START_TEST(region)
468 struct GdiplusStartupInput gdiplusStartupInput;
469 ULONG_PTR gdiplusToken;
471 gdiplusStartupInput.GdiplusVersion = 1;
472 gdiplusStartupInput.DebugEventCallback = NULL;
473 gdiplusStartupInput.SuppressBackgroundThread = 0;
474 gdiplusStartupInput.SuppressExternalCodecs = 0;
476 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
478 test_getregiondata();
480 GdiplusShutdown(gdiplusToken);