push 9758e6fe7ae8fbab538c98c718d6619029bb3457
[wine/hacks.git] / dlls / gdiplus / tests / region.c
blob8c3badac93a65522a0980a8adaef486c7054c79e
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 todo_wine
75 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
76 ok(status == Ok, "status %08x\n", status);
78 expect(20, needed);
79 todo_wine
81 expect_dword(buf, 12);
82 trace("buf[1] = %08x\n", buf[1]);
83 expect_magic((DWORD*)(buf + 2));
84 expect_dword(buf + 3, 0);
85 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
87 status = GdipSetEmpty(region);
89 ok(status == Ok, "status %08x\n", status);
90 todo_wine
92 status = GdipGetRegionDataSize(region, &needed);
94 ok(status == Ok, "status %08x\n", status);
95 expect(20, needed);
96 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
97 todo_wine
98 ok(status == Ok, "status %08x\n", status);
99 expect(20, needed);
100 todo_wine
102 expect_dword(buf, 12);
103 trace("buf[1] = %08x\n", buf[1]);
104 expect_magic((DWORD*)(buf + 2));
105 expect_dword(buf + 3, 0);
106 expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
109 status = GdipSetInfinite(region);
110 ok(status == Ok, "status %08x\n", status);
111 status = GdipGetRegionDataSize(region, &needed);
112 ok(status == Ok, "status %08x\n", status);
113 expect(20, needed);
114 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
115 todo_wine
116 ok(status == Ok, "status %08x\n", status);
117 expect(20, needed);
118 todo_wine
120 expect_dword(buf, 12);
121 trace("buf[1] = %08x\n", buf[1]);
122 expect_magic((DWORD*)(buf + 2));
123 expect_dword(buf + 3, 0);
124 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
127 status = GdipDeleteRegion(region);
128 ok(status == Ok, "status %08x\n", status);
130 rect.X = 10;
131 rect.Y = 20;
132 rect.Width = 100;
133 rect.Height = 200;
134 todo_wine
136 status = GdipCreateRegionRectI(&rect, &region);
137 ok(status == Ok, "status %08x\n", status);
138 status = GdipGetRegionDataSize(region, &needed);
139 ok(status == Ok, "status %08x\n", status);
140 expect(36, needed);
141 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
142 ok(status == Ok, "status %08x\n", status);
143 expect(36, needed);
144 expect_dword(buf, 28);
145 trace("buf[1] = %08x\n", buf[1]);
146 expect_magic((DWORD*)(buf + 2));
147 expect_dword(buf + 3, 0);
148 expect_dword(buf + 4, RGNDATA_RECT);
149 expect_float(buf + 5, 10.0);
150 expect_float(buf + 6, 20.0);
151 expect_float(buf + 7, 100.0);
152 expect_float(buf + 8, 200.0);
154 rect.X = 50;
155 rect.Y = 30;
156 rect.Width = 10;
157 rect.Height = 20;
158 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
159 ok(status == Ok, "status %08x\n", status);
160 rect.X = 100;
161 rect.Y = 300;
162 rect.Width = 30;
163 rect.Height = 50;
164 status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
165 ok(status == Ok, "status %08x\n", status);
167 rect.X = 200;
168 rect.Y = 100;
169 rect.Width = 133;
170 rect.Height = 266;
171 status = GdipCreateRegionRectI(&rect, &region2);
172 ok(status == Ok, "status %08x\n", status);
173 rect.X = 20;
174 rect.Y = 10;
175 rect.Width = 40;
176 rect.Height = 66;
177 status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
178 ok(status == Ok, "status %08x\n", status);
180 status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
181 ok(status == Ok, "status %08x\n", status);
183 rect.X = 400;
184 rect.Y = 500;
185 rect.Width = 22;
186 rect.Height = 55;
187 status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
188 ok(status == Ok, "status %08x\n", status);
190 status = GdipGetRegionDataSize(region, &needed);
191 ok(status == Ok, "status %08x\n", status);
192 expect(156, needed);
193 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
194 ok(status == Ok, "status %08x\n", status);
195 expect(156, needed);
196 expect_dword(buf, 148);
197 trace("buf[1] = %08x\n", buf[1]);
198 expect_magic((DWORD*)(buf + 2));
199 expect_dword(buf + 3, 10);
200 expect_dword(buf + 4, CombineModeExclude);
201 expect_dword(buf + 5, CombineModeComplement);
202 expect_dword(buf + 6, CombineModeXor);
203 expect_dword(buf + 7, CombineModeIntersect);
204 expect_dword(buf + 8, RGNDATA_RECT);
205 expect_float(buf + 9, 10.0);
206 expect_float(buf + 10, 20.0);
207 expect_float(buf + 11, 100.0);
208 expect_float(buf + 12, 200.0);
209 expect_dword(buf + 13, RGNDATA_RECT);
210 expect_float(buf + 14, 50.0);
211 expect_float(buf + 15, 30.0);
212 expect_float(buf + 16, 10.0);
213 expect_float(buf + 17, 20.0);
214 expect_dword(buf + 18, RGNDATA_RECT);
215 expect_float(buf + 19, 100.0);
216 expect_float(buf + 20, 300.0);
217 expect_float(buf + 21, 30.0);
218 expect_float(buf + 22, 50.0);
219 expect_dword(buf + 23, CombineModeUnion);
220 expect_dword(buf + 24, RGNDATA_RECT);
221 expect_float(buf + 25, 200.0);
222 expect_float(buf + 26, 100.0);
223 expect_float(buf + 27, 133.0);
224 expect_float(buf + 28, 266.0);
225 expect_dword(buf + 29, RGNDATA_RECT);
226 expect_float(buf + 30, 20.0);
227 expect_float(buf + 31, 10.0);
228 expect_float(buf + 32, 40.0);
229 expect_float(buf + 33, 66.0);
230 expect_dword(buf + 34, RGNDATA_RECT);
231 expect_float(buf + 35, 400.0);
232 expect_float(buf + 36, 500.0);
233 expect_float(buf + 37, 22.0);
234 expect_float(buf + 38, 55.0);
236 status = GdipDeleteRegion(region2);
237 ok(status == Ok, "status %08x\n", status);
238 status = GdipDeleteRegion(region);
239 ok(status == Ok, "status %08x\n", status);
242 /* Try some paths */
244 status = GdipCreatePath(FillModeAlternate, &path);
245 ok(status == Ok, "status %08x\n", status);
246 todo_wine
248 GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
250 status = GdipCreateRegionPath(path, &region);
251 ok(status == Ok, "status %08x\n", status);
252 status = GdipGetRegionDataSize(region, &needed);
253 ok(status == Ok, "status %08x\n", status);
254 expect(72, needed);
255 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
256 ok(status == Ok, "status %08x\n", status);
257 expect(72, needed);
258 expect_dword(buf, 64);
259 trace("buf[1] = %08x\n", buf[1]);
260 expect_magic((DWORD*)(buf + 2));
261 expect_dword(buf + 3, 0);
262 expect_dword(buf + 4, RGNDATA_PATH);
263 expect_dword(buf + 5, 0x00000030);
264 expect_magic((DWORD*)(buf + 6));
265 expect_dword(buf + 7, 0x00000004);
266 expect_dword(buf + 8, 0x00000000);
267 expect_float(buf + 9, 12.5);
268 expect_float(buf + 10, 13.0);
269 expect_float(buf + 11, 26.5);
270 expect_float(buf + 12, 13.0);
271 expect_float(buf + 13, 26.5);
272 expect_float(buf + 14, 28.0);
273 expect_float(buf + 15, 12.5);
274 expect_float(buf + 16, 28.0);
275 expect_dword(buf + 17, 0x81010100);
278 rect.X = 50;
279 rect.Y = 30;
280 rect.Width = 10;
281 rect.Height = 20;
282 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
283 ok(status == Ok, "status %08x\n", status);
284 status = GdipGetRegionDataSize(region, &needed);
285 ok(status == Ok, "status %08x\n", status);
286 expect(96, needed);
287 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
288 ok(status == Ok, "status %08x\n", status);
289 expect(96, needed);
290 expect_dword(buf, 88);
291 trace("buf[1] = %08x\n", buf[1]);
292 expect_magic((DWORD*)(buf + 2));
293 expect_dword(buf + 3, 2);
294 expect_dword(buf + 4, CombineModeIntersect);
295 expect_dword(buf + 5, RGNDATA_PATH);
296 expect_dword(buf + 6, 0x00000030);
297 expect_magic((DWORD*)(buf + 7));
298 expect_dword(buf + 8, 0x00000004);
299 expect_dword(buf + 9, 0x00000000);
300 expect_float(buf + 10, 12.5);
301 expect_float(buf + 11, 13.0);
302 expect_float(buf + 12, 26.5);
303 expect_float(buf + 13, 13.0);
304 expect_float(buf + 14, 26.5);
305 expect_float(buf + 15, 28.0);
306 expect_float(buf + 16, 12.5);
307 expect_float(buf + 17, 28.0);
308 expect_dword(buf + 18, 0x81010100);
309 expect_dword(buf + 19, RGNDATA_RECT);
310 expect_float(buf + 20, 50.0);
311 expect_float(buf + 21, 30.0);
312 expect_float(buf + 22, 10.0);
313 expect_float(buf + 23, 20.0);
315 status = GdipDeleteRegion(region);
316 ok(status == Ok, "status %08x\n", status);
318 status = GdipDeletePath(path);
319 ok(status == Ok, "status %08x\n", status);
321 /* Test an empty path */
322 status = GdipCreatePath(FillModeAlternate, &path);
323 expect(Ok, status);
324 todo_wine
326 status = GdipCreateRegionPath(path, &region);
327 expect(Ok, status);
328 status = GdipGetRegionDataSize(region, &needed);
329 expect(Ok, status);
330 expect(36, needed);
331 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
332 expect(Ok, status);
333 expect(36, needed);
334 expect_dword(buf, 28);
335 trace("buf[1] = %08x\n", buf[1]);
336 expect_magic((DWORD*)(buf + 2));
337 expect_dword(buf + 3, 0);
338 expect_dword(buf + 4, RGNDATA_PATH);
340 /* Second signature for pathdata */
341 expect_dword(buf + 5, 12);
342 expect_magic((DWORD*)(buf + 6));
343 expect_dword(buf + 7, 0);
344 expect_dword(buf + 8, 0x00004000);
346 status = GdipDeleteRegion(region);
347 expect(Ok, status);
350 /* Test a simple triangle of INTs */
351 status = GdipAddPathLine(path, 5, 6, 7, 8);
352 expect(Ok, status);
353 status = GdipAddPathLine(path, 8, 1, 5, 6);
354 expect(Ok, status);
355 status = GdipClosePathFigure(path);
356 expect(Ok, status);
357 todo_wine
359 status = GdipCreateRegionPath(path, &region);
360 expect(Ok, status);
361 status = GdipGetRegionDataSize(region, &needed);
362 expect(Ok, status);
363 expect(56, needed);
364 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
365 expect(Ok, status);
366 expect(56, needed);
367 expect_dword(buf, 48);
368 trace("buf[1] = %08x\n", buf[1]);
369 expect_magic((DWORD*)(buf + 2));
370 expect_dword(buf + 3 , 0);
371 expect_dword(buf + 4 , RGNDATA_PATH);
373 expect_dword(buf + 5, 32);
374 expect_magic((DWORD*)(buf + 6));
375 expect_dword(buf + 7, 4);
376 expect_dword(buf + 8, 0x00004000); /* ?? */
378 point = (RegionDataPoint*)buf + 9;
379 expect(5, point[0].X);
380 expect(6, point[0].Y);
381 expect(7, point[1].X); /* buf + 10 */
382 expect(8, point[1].Y);
383 expect(8, point[2].X); /* buf + 11 */
384 expect(1, point[2].Y);
385 expect(5, point[3].X); /* buf + 12 */
386 expect(6, point[3].Y);
387 expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
389 status = GdipDeletePath(path);
390 expect(Ok, status);
391 status = GdipDeleteRegion(region);
392 todo_wine
393 expect(Ok, status);
395 /* Test a floating-point triangle */
396 status = GdipCreatePath(FillModeAlternate, &path);
397 expect(Ok, status);
398 status = GdipAddPathLine(path, 5.6, 6.2, 7.2, 8.9);
399 expect(Ok, status);
400 status = GdipAddPathLine(path, 8.1, 1.6, 5.6, 6.2);
401 expect(Ok, status);
402 todo_wine
404 status = GdipCreateRegionPath(path, &region);
405 expect(Ok, status);
406 status = GdipGetRegionDataSize(region, &needed);
407 expect(Ok, status);
408 expect(72, needed);
409 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
410 expect(Ok, status);
411 expect(72, needed);
412 expect_dword(buf, 64);
413 trace("buf[1] = %08x\n", buf[1]);
414 expect_magic((DWORD*)(buf + 2));
415 expect_dword(buf + 3, 0);
416 expect_dword(buf + 4, RGNDATA_PATH);
418 expect_dword(buf + 5, 48);
419 expect_magic((DWORD*)(buf + 6));
420 expect_dword(buf + 7, 4);
421 expect_dword(buf + 8, 0);
422 expect_float(buf + 9, 5.6);
423 expect_float(buf + 10, 6.2);
424 expect_float(buf + 11, 7.2);
425 expect_float(buf + 12, 8.9);
426 expect_float(buf + 13, 8.1);
427 expect_float(buf + 14, 1.6);
428 expect_float(buf + 15, 5.6);
429 expect_float(buf + 16, 6.2);
432 status = GdipDeletePath(path);
433 expect(Ok, status);
434 status = GdipDeleteRegion(region);
435 todo_wine
436 expect(Ok, status);
439 START_TEST(region)
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_getregiondata();
453 GdiplusShutdown(gdiplusToken);