1 /*
2  * Unit test suite for gdiplus regions
3  *
4  * Copyright (C) 2008 Huw Davies
5  * Copyright (C) 2013 Dmitry Timoshkov
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21 
22 #include <math.h>
23 
24 #include "objbase.h"
25 #include "gdiplus.h"
26 #include "wine/test.h"
27 
28 #define RGNDATA_RECT            0x10000000
29 #define RGNDATA_PATH            0x10000001
30 #define RGNDATA_EMPTY_RECT      0x10000002
31 #define RGNDATA_INFINITE_RECT   0x10000003
32 
33 #define RGNDATA_MAGIC           0xdbc01001
34 #define RGNDATA_MAGIC2          0xdbc01002
35 
36 #define expect(expected, got) ok((got) == (expected), "Expected %.8x, got %.8x\n", (expected), (got))
37 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) < (precision), "Expected %f, got %f\n", (expected), (got))
38 #define expectf(expected, got) expectf_((expected), (got), 0.001)
39 
40 #define expect_magic(value) ok(broken(*(value) == RGNDATA_MAGIC) || *(value) == RGNDATA_MAGIC2, "Expected a known magic value, got %8x\n", *(value))
41 #define expect_dword(value, expected) expect((expected), *(value))
42 #define expect_float(value, expected) expectf((expected), *(FLOAT *)(value))
43 
44 /* We get shorts back, not INTs like a GpPoint */
45 typedef struct RegionDataPoint
46 {
47     short X, Y;
48 } RegionDataPoint;
49 
50 static void verify_region(HRGN hrgn, const RECT *rc)
51 {
52     union
53     {
54         RGNDATA data;
55         char buf[sizeof(RGNDATAHEADER) + sizeof(RECT)];
56     } rgn;
57     const RECT *rect;
58     DWORD ret;
59 
60     ret = GetRegionData(hrgn, 0, NULL);
61     if (IsRectEmpty(rc))
62         ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
63     else
64         ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
65 
66     if (!ret) return;
67 
68     ret = GetRegionData(hrgn, sizeof(rgn), &rgn.data);
69     if (IsRectEmpty(rc))
70         ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
71     else
72         ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
73 
74     trace("size %u, type %u, count %u, rgn size %u, bound %s\n",
75           rgn.data.rdh.dwSize, rgn.data.rdh.iType,
76           rgn.data.rdh.nCount, rgn.data.rdh.nRgnSize,
77           wine_dbgstr_rect(&rgn.data.rdh.rcBound));
78     if (rgn.data.rdh.nCount != 0)
79     {
80         rect = (const RECT *)rgn.data.Buffer;
81         trace("rect %s\n", wine_dbgstr_rect(rect));
82         ok(EqualRect(rect, rc), "expected %s, got %s\n",
83            wine_dbgstr_rect(rc), wine_dbgstr_rect(rect));
84     }
85 
86     ok(rgn.data.rdh.dwSize == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", rgn.data.rdh.dwSize);
87     ok(rgn.data.rdh.iType == RDH_RECTANGLES, "expected RDH_RECTANGLES, got %u\n", rgn.data.rdh.iType);
88     if (IsRectEmpty(rc))
89     {
90         ok(rgn.data.rdh.nCount == 0, "expected 0, got %u\n", rgn.data.rdh.nCount);
91         ok(rgn.data.rdh.nRgnSize == 0,  "expected 0, got %u\n", rgn.data.rdh.nRgnSize);
92     }
93     else
94     {
95         ok(rgn.data.rdh.nCount == 1, "expected 1, got %u\n", rgn.data.rdh.nCount);
96         ok(rgn.data.rdh.nRgnSize == sizeof(RECT),  "expected sizeof(RECT), got %u\n", rgn.data.rdh.nRgnSize);
97     }
98     ok(EqualRect(&rgn.data.rdh.rcBound, rc), "expected %s, got %s\n",
99        wine_dbgstr_rect(rc), wine_dbgstr_rect(&rgn.data.rdh.rcBound));
100 }
101 
102 static void test_region_data(DWORD *data, UINT size, INT line)
103 {
104     GpStatus status;
105     GpRegion *region;
106     DWORD buf[256];
107     UINT needed, i;
108 
109     status = GdipCreateRegionRgnData((BYTE *)data, size, &region);
110     /* Windows always fails to create an empty path in a region */
111     if (data[4] == RGNDATA_PATH)
112     {
113         struct path_header
114         {
115             DWORD size;
116             DWORD magic;
117             DWORD count;
118             DWORD flags;
119         } *path_header = (struct path_header *)(data + 5);
120         if (!path_header->count)
121         {
122             ok_(__FILE__, line)(status == GenericError, "expected GenericError, got %d\n", status);
123             return;
124         }
125     }
126 
127     ok_(__FILE__, line)(status == Ok, "GdipCreateRegionRgnData error %d\n", status);
128     if (status != Ok) return;
129 
130     needed = 0;
131     status = GdipGetRegionDataSize(region, &needed);
132     ok_(__FILE__, line)(status == Ok, "status %d\n", status);
133     ok_(__FILE__, line)(needed == size, "data size mismatch: %u != %u\n", needed, size);
134 
135     memset(buf, 0xee, sizeof(buf));
136     needed = 0;
137     status = GdipGetRegionData(region, (BYTE *)buf, sizeof(buf), &needed);
138     ok_(__FILE__, line)(status == Ok, "status %08x\n", status);
139     ok_(__FILE__, line)(needed == size, "data size mismatch: %u != %u\n", needed, size);
140 
141     size /= sizeof(DWORD);
142     for (i = 0; i < size - 1; i++)
143     {
144         if (i == 1) continue; /* data[1] never matches */
145         ok_(__FILE__, line)(data[i] == buf[i], "off %u: %#x != %#x\n", i, data[i], buf[i]);
146     }
147     /* some Windows versions fail to properly clear the aligned DWORD */
148     ok_(__FILE__, line)(data[size - 1] == buf[size - 1] || broken(data[size - 1] != buf[size - 1]),
149         "off %u: %#x != %#x\n", size - 1, data[size - 1], buf[size - 1]);
150 
151     GdipDeleteRegion(region);
152 }
153 
154 static void test_getregiondata(void)
155 {
156     GpStatus status;
157     GpRegion *region, *region2;
158     RegionDataPoint *point;
159     UINT needed;
160     DWORD buf[256];
161     GpRect rect;
162     GpPath *path;
163     GpMatrix *matrix;
164 
165     status = GdipCreateRegion(&region);
166     ok(status == Ok, "status %08x\n", status);
167 
168     needed = 0;
169     status = GdipGetRegionDataSize(region, &needed);
170     ok(status == Ok, "status %08x\n", status);
171     expect(20, needed);
172 
173     needed = 0;
174     status = GdipGetRegionData(region, (BYTE*)buf, 0, &needed);
175     ok(status == InvalidParameter, "status %08x\n", status);
176 
177     memset(buf, 0xee, sizeof(buf));
178     needed = 0;
179     status = GdipGetRegionData(region, (BYTE*)buf, 4, &needed);
180     ok(status == InsufficientBuffer, "status %08x\n", status);
181     expect(4, needed);
182     expect_dword(buf, 0xeeeeeeee);
183 
184     memset(buf, 0xee, sizeof(buf));
185     needed = 0;
186     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
187     ok(status == Ok, "status %08x\n", status);
188     expect(20, needed);
189     expect_dword(buf, 12);
190     trace("buf[1] = %08x\n", buf[1]);
191     expect_magic(buf + 2);
192     expect_dword(buf + 3, 0);
193     expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
194     expect_dword(buf + 6, 0xeeeeeeee);
195     test_region_data(buf, needed, __LINE__);
196 
197     status = GdipSetEmpty(region);
198     ok(status == Ok, "status %08x\n", status);
199     status = GdipGetRegionDataSize(region, &needed);
200     ok(status == Ok, "status %08x\n", status);
201     expect(20, needed);
202     memset(buf, 0xee, sizeof(buf));
203     needed = 0;
204     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
205     ok(status == Ok, "status %08x\n", status);
206     expect(20, needed);
207     expect_dword(buf, 12);
208     trace("buf[1] = %08x\n", buf[1]);
209     expect_magic(buf + 2);
210     expect_dword(buf + 3, 0);
211     expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
212     expect_dword(buf + 6, 0xeeeeeeee);
213     test_region_data(buf, needed, __LINE__);
214 
215     status = GdipSetInfinite(region);
216     ok(status == Ok, "status %08x\n", status);
217     status = GdipGetRegionDataSize(region, &needed);
218     ok(status == Ok, "status %08x\n", status);
219     expect(20, needed);
220     memset(buf, 0xee, sizeof(buf));
221     needed = 0;
222     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
223     ok(status == Ok, "status %08x\n", status);
224     expect(20, needed);
225     expect_dword(buf, 12);
226     trace("buf[1] = %08x\n", buf[1]);
227     expect_magic(buf + 2);
228     expect_dword(buf + 3, 0);
229     expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
230     expect_dword(buf + 6, 0xeeeeeeee);
231     test_region_data(buf, needed, __LINE__);
232 
233     status = GdipDeleteRegion(region);
234     ok(status == Ok, "status %08x\n", status);
235 
236     rect.X = 10;
237     rect.Y = 20;
238     rect.Width = 100;
239     rect.Height = 200;
240     status = GdipCreateRegionRectI(&rect, &region);
241     ok(status == Ok, "status %08x\n", status);
242     status = GdipGetRegionDataSize(region, &needed);
243     ok(status == Ok, "status %08x\n", status);
244     expect(36, needed);
245     memset(buf, 0xee, sizeof(buf));
246     needed = 0;
247     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
248     ok(status == Ok, "status %08x\n", status);
249     expect(36, needed);
250     expect_dword(buf, 28);
251     trace("buf[1] = %08x\n", buf[1]);
252     expect_magic(buf + 2);
253     expect_dword(buf + 3, 0);
254     expect_dword(buf + 4, RGNDATA_RECT);
255     expect_float(buf + 5, 10.0);
256     expect_float(buf + 6, 20.0);
257     expect_float(buf + 7, 100.0);
258     expect_float(buf + 8, 200.0);
259     expect_dword(buf + 10, 0xeeeeeeee);
260     test_region_data(buf, needed, __LINE__);
261 
262     rect.X = 50;
263     rect.Y = 30;
264     rect.Width = 10;
265     rect.Height = 20;
266     status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
267     ok(status == Ok, "status %08x\n", status);
268     rect.X = 100;
269     rect.Y = 300;
270     rect.Width = 30;
271     rect.Height = 50;
272     status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
273     ok(status == Ok, "status %08x\n", status);
274 
275     rect.X = 200;
276     rect.Y = 100;
277     rect.Width = 133;
278     rect.Height = 266;
279     status = GdipCreateRegionRectI(&rect, &region2);
280     ok(status == Ok, "status %08x\n", status);
281     rect.X = 20;
282     rect.Y = 10;
283     rect.Width = 40;
284     rect.Height = 66;
285     status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
286     ok(status == Ok, "status %08x\n", status);
287 
288     status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
289     ok(status == Ok, "status %08x\n", status);
290 
291     rect.X = 400;
292     rect.Y = 500;
293     rect.Width = 22;
294     rect.Height = 55;
295     status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
296     ok(status == Ok, "status %08x\n", status);
297 
298     status = GdipGetRegionDataSize(region, &needed);
299     ok(status == Ok, "status %08x\n", status);
300     expect(156, needed);
301     memset(buf, 0xee, sizeof(buf));
302     needed = 0;
303     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
304     ok(status == Ok, "status %08x\n", status);
305     expect(156, needed);
306     expect_dword(buf, 148);
307     trace("buf[1] = %08x\n", buf[1]);
308     expect_magic(buf + 2);
309     expect_dword(buf + 3, 10);
310     expect_dword(buf + 4, CombineModeExclude);
311     expect_dword(buf + 5, CombineModeComplement);
312     expect_dword(buf + 6, CombineModeXor);
313     expect_dword(buf + 7, CombineModeIntersect);
314     expect_dword(buf + 8, RGNDATA_RECT);
315     expect_float(buf + 9, 10.0);
316     expect_float(buf + 10, 20.0);
317     expect_float(buf + 11, 100.0);
318     expect_float(buf + 12, 200.0);
319     expect_dword(buf + 13, RGNDATA_RECT);
320     expect_float(buf + 14, 50.0);
321     expect_float(buf + 15, 30.0);
322     expect_float(buf + 16, 10.0);
323     expect_float(buf + 17, 20.0);
324     expect_dword(buf + 18, RGNDATA_RECT);
325     expect_float(buf + 19, 100.0);
326     expect_float(buf + 20, 300.0);
327     expect_float(buf + 21, 30.0);
328     expect_float(buf + 22, 50.0);
329     expect_dword(buf + 23, CombineModeUnion);
330     expect_dword(buf + 24, RGNDATA_RECT);
331     expect_float(buf + 25, 200.0);
332     expect_float(buf + 26, 100.0);
333     expect_float(buf + 27, 133.0);
334     expect_float(buf + 28, 266.0);
335     expect_dword(buf + 29, RGNDATA_RECT);
336     expect_float(buf + 30, 20.0);
337     expect_float(buf + 31, 10.0);
338     expect_float(buf + 32, 40.0);
339     expect_float(buf + 33, 66.0);
340     expect_dword(buf + 34, RGNDATA_RECT);
341     expect_float(buf + 35, 400.0);
342     expect_float(buf + 36, 500.0);
343     expect_float(buf + 37, 22.0);
344     expect_float(buf + 38, 55.0);
345     expect_dword(buf + 39, 0xeeeeeeee);
346     test_region_data(buf, needed, __LINE__);
347 
348     status = GdipDeleteRegion(region2);
349     ok(status == Ok, "status %08x\n", status);
350     status = GdipDeleteRegion(region);
351     ok(status == Ok, "status %08x\n", status);
352 
353     /* Try some paths */
354 
355     status = GdipCreatePath(FillModeAlternate, &path);
356     ok(status == Ok, "status %08x\n", status);
357     GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
358 
359     status = GdipCreateRegionPath(path, &region);
360     ok(status == Ok, "status %08x\n", status);
361     status = GdipGetRegionDataSize(region, &needed);
362     ok(status == Ok, "status %08x\n", status);
363     expect(72, needed);
364     memset(buf, 0xee, sizeof(buf));
365     needed = 0;
366     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
367     ok(status == Ok, "status %08x\n", status);
368     expect(72, needed);
369     expect_dword(buf, 64);
370     trace("buf[1] = %08x\n", buf[1]);
371     expect_magic(buf + 2);
372     expect_dword(buf + 3, 0);
373     expect_dword(buf + 4, RGNDATA_PATH);
374     expect_dword(buf + 5, 0x00000030);
375     expect_magic(buf + 6);
376     expect_dword(buf + 7, 0x00000004);
377     expect_dword(buf + 8, 0x00000000);
378     expect_float(buf + 9, 12.5);
379     expect_float(buf + 10, 13.0);
380     expect_float(buf + 11, 26.5);
381     expect_float(buf + 12, 13.0);
382     expect_float(buf + 13, 26.5);
383     expect_float(buf + 14, 28.0);
384     expect_float(buf + 15, 12.5);
385     expect_float(buf + 16, 28.0);
386     expect_dword(buf + 17, 0x81010100);
387     expect_dword(buf + 18, 0xeeeeeeee);
388     test_region_data(buf, needed, __LINE__);
389 
390     rect.X = 50;
391     rect.Y = 30;
392     rect.Width = 10;
393     rect.Height = 20;
394     status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
395     ok(status == Ok, "status %08x\n", status);
396     status = GdipGetRegionDataSize(region, &needed);
397     ok(status == Ok, "status %08x\n", status);
398     expect(96, needed);
399     memset(buf, 0xee, sizeof(buf));
400     needed = 0;
401     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
402     ok(status == Ok, "status %08x\n", status);
403     expect(96, needed);
404     expect_dword(buf, 88);
405     trace("buf[1] = %08x\n", buf[1]);
406     expect_magic(buf + 2);
407     expect_dword(buf + 3, 2);
408     expect_dword(buf + 4, CombineModeIntersect);
409     expect_dword(buf + 5, RGNDATA_PATH);
410     expect_dword(buf + 6, 0x00000030);
411     expect_magic(buf + 7);
412     expect_dword(buf + 8, 0x00000004);
413     expect_dword(buf + 9, 0x00000000);
414     expect_float(buf + 10, 12.5);
415     expect_float(buf + 11, 13.0);
416     expect_float(buf + 12, 26.5);
417     expect_float(buf + 13, 13.0);
418     expect_float(buf + 14, 26.5);
419     expect_float(buf + 15, 28.0);
420     expect_float(buf + 16, 12.5);
421     expect_float(buf + 17, 28.0);
422     expect_dword(buf + 18, 0x81010100);
423     expect_dword(buf + 19, RGNDATA_RECT);
424     expect_float(buf + 20, 50.0);
425     expect_float(buf + 21, 30.0);
426     expect_float(buf + 22, 10.0);
427     expect_float(buf + 23, 20.0);
428     expect_dword(buf + 24, 0xeeeeeeee);
429     test_region_data(buf, needed, __LINE__);
430 
431     status = GdipDeleteRegion(region);
432     ok(status == Ok, "status %08x\n", status);
433     status = GdipDeletePath(path);
434     ok(status == Ok, "status %08x\n", status);
435 
436     /* Test an empty path */
437     status = GdipCreatePath(FillModeAlternate, &path);
438     expect(Ok, status);
439     status = GdipCreateRegionPath(path, &region);
440     expect(Ok, status);
441     status = GdipGetRegionDataSize(region, &needed);
442     expect(Ok, status);
443     expect(36, needed);
444     memset(buf, 0xee, sizeof(buf));
445     needed = 0;
446     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
447     expect(Ok, status);
448     expect(36, needed);
449     expect_dword(buf, 28);
450     trace("buf[1] = %08x\n", buf[1]);
451     expect_magic(buf + 2);
452     expect_dword(buf + 3, 0);
453     expect_dword(buf + 4, RGNDATA_PATH);
454     /* Second signature for pathdata */
455     expect_dword(buf + 5, 12);
456     expect_magic(buf + 6);
457     expect_dword(buf + 7, 0);
458     /* flags 0 means that a path is an array of FLOATs */
459     ok(*(buf + 8) == 0x4000 /* before win7 */ || *(buf + 8) == 0,
460        "expected 0x4000 or 0, got %08x\n", *(buf + 8));
461     expect_dword(buf + 10, 0xeeeeeeee);
462     test_region_data(buf, needed, __LINE__);
463 
464     /* Transform an empty region */
465     status = GdipCreateMatrix(&matrix);
466     expect(Ok, status);
467     status = GdipTransformRegion(region, matrix);
468     expect(Ok, status);
469     GdipDeleteMatrix(matrix);
470 
471     status = GdipDeleteRegion(region);
472     expect(Ok, status);
473 
474     /* Test a simple triangle of INTs */
475     status = GdipAddPathLine(path, 5, 6, 7, 8);
476     expect(Ok, status);
477     status = GdipAddPathLine(path, 8, 1, 5, 6);
478     expect(Ok, status);
479     status = GdipClosePathFigure(path);
480     expect(Ok, status);
481     status = GdipCreateRegionPath(path, &region);
482     expect(Ok, status);
483     status = GdipGetRegionDataSize(region, &needed);
484     expect(Ok, status);
485     expect(56, needed);
486     memset(buf, 0xee, sizeof(buf));
487     needed = 0;
488     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
489     expect(Ok, status);
490     expect(56, needed);
491     expect_dword(buf, 48);
492     trace("buf[1] = %08x\n", buf[1]);
493     expect_magic(buf + 2);
494     expect_dword(buf + 3 , 0);
495     expect_dword(buf + 4 , RGNDATA_PATH);
496     expect_dword(buf + 5, 32);
497     expect_magic(buf + 6);
498     expect_dword(buf + 7, 4);
499     /* flags 0x4000 means that a path is an array of shorts instead of FLOATs */
500     expect_dword(buf + 8, 0x4000);
501 
502     point = (RegionDataPoint*)(buf + 9);
503     expect(5, point[0].X);
504     expect(6, point[0].Y);
505     expect(7, point[1].X); /* buf + 10 */
506     expect(8, point[1].Y);
507     expect(8, point[2].X); /* buf + 11 */
508     expect(1, point[2].Y);
509     expect(5, point[3].X); /* buf + 12 */
510     expect(6, point[3].Y);
511     expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
512     expect_dword(buf + 14, 0xeeeeeeee);
513     test_region_data(buf, needed, __LINE__);
514 
515     status = GdipTranslateRegion(region, 0.6, 0.8);
516     expect(Ok, status);
517     memset(buf, 0xee, sizeof(buf));
518     needed = 0;
519     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
520     expect(Ok, status);
521     expect(72, needed);
522     expect_dword(buf, 64);
523     expect_magic(buf + 2);
524     expect_dword(buf + 3 , 0);
525     expect_dword(buf + 4 , RGNDATA_PATH);
526     expect_dword(buf + 5, 48);
527     expect_magic(buf + 6);
528     expect_dword(buf + 7, 4);
529     /* flags 0 means that a path is an array of FLOATs */
530     expect_dword(buf + 8, 0);
531     expect_float(buf + 9, 5.6);
532     expect_float(buf + 10, 6.8);
533     expect_float(buf + 11, 7.6);
534     expect_float(buf + 12, 8.8);
535     expect_float(buf + 13, 8.6);
536     expect_float(buf + 14, 1.8);
537     expect_float(buf + 15, 5.6);
538     expect_float(buf + 16, 6.8);
539     expect_dword(buf + 17, 0x81010100); /* 0x01010100 if we don't close the path */
540     expect_dword(buf + 18, 0xeeeeeeee);
541     test_region_data(buf, needed, __LINE__);
542 
543     status = GdipDeletePath(path);
544     expect(Ok, status);
545     status = GdipDeleteRegion(region);
546     expect(Ok, status);
547 
548     /* Test a floating-point triangle */
549     status = GdipCreatePath(FillModeAlternate, &path);
550     expect(Ok, status);
551     status = GdipAddPathLine(path, 5.6, 6.2, 7.2, 8.9);
552     expect(Ok, status);
553     status = GdipAddPathLine(path, 8.1, 1.6, 5.6, 6.2);
554     expect(Ok, status);
555     status = GdipCreateRegionPath(path, &region);
556     expect(Ok, status);
557     status = GdipGetRegionDataSize(region, &needed);
558     expect(Ok, status);
559     expect(72, needed);
560     memset(buf, 0xee, sizeof(buf));
561     needed = 0;
562     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
563     expect(Ok, status);
564     expect(72, needed);
565     expect_dword(buf, 64);
566     trace("buf[1] = %08x\n", buf[1]);
567     expect_magic(buf + 2);
568     expect_dword(buf + 3, 0);
569     expect_dword(buf + 4, RGNDATA_PATH);
570     expect_dword(buf + 5, 48);
571     expect_magic(buf + 6);
572     expect_dword(buf + 7, 4);
573     expect_dword(buf + 8, 0);
574     expect_float(buf + 9, 5.6);
575     expect_float(buf + 10, 6.2);
576     expect_float(buf + 11, 7.2);
577     expect_float(buf + 12, 8.9);
578     expect_float(buf + 13, 8.1);
579     expect_float(buf + 14, 1.6);
580     expect_float(buf + 15, 5.6);
581     expect_float(buf + 16, 6.2);
582     expect_dword(buf + 17, 0x01010100);
583     expect_dword(buf + 18, 0xeeeeeeee);
584     test_region_data(buf, needed, __LINE__);
585 
586     status = GdipDeletePath(path);
587     expect(Ok, status);
588     status = GdipDeleteRegion(region);
589     expect(Ok, status);
590 
591     /* Test for a path with > 4 points, and CombineRegionPath */
592     GdipCreatePath(FillModeAlternate, &path);
593     status = GdipAddPathLine(path, 50, 70.2, 60, 102.8);
594     expect(Ok, status);
595     status = GdipAddPathLine(path, 55.4, 122.4, 40.4, 60.2);
596     expect(Ok, status);
597     status = GdipAddPathLine(path, 45.6, 20.2, 50, 70.2);
598     expect(Ok, status);
599     rect.X = 20;
600     rect.Y = 25;
601     rect.Width = 60;
602     rect.Height = 120;
603     status = GdipCreateRegionRectI(&rect, &region);
604     expect(Ok, status);
605     status = GdipCombineRegionPath(region, path, CombineModeUnion);
606     expect(Ok, status);
607 
608     status = GdipGetRegionDataSize(region, &needed);
609     expect(Ok, status);
610     expect(116, needed);
611     memset(buf, 0xee, sizeof(buf));
612     needed = 0;
613     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
614     expect(Ok, status);
615     expect(116, needed);
616     expect_dword(buf, 108);
617     trace("buf[1] = %08x\n", buf[1]);
618     expect_magic(buf + 2);
619     expect_dword(buf + 3, 2);
620     expect_dword(buf + 4, CombineModeUnion);
621     expect_dword(buf + 5, RGNDATA_RECT);
622     expect_float(buf + 6, 20.0);
623     expect_float(buf + 7, 25.0);
624     expect_float(buf + 8, 60.0);
625     expect_float(buf + 9, 120.0);
626     expect_dword(buf + 10, RGNDATA_PATH);
627     expect_dword(buf + 11, 68);
628     expect_magic(buf + 12);
629     expect_dword(buf + 13, 6);
630     expect_float(buf + 14, 0.0);
631     expect_float(buf + 15, 50.0);
632     expect_float(buf + 16, 70.2);
633     expect_float(buf + 17, 60.0);
634     expect_float(buf + 18, 102.8);
635     expect_float(buf + 19, 55.4);
636     expect_float(buf + 20, 122.4);
637     expect_float(buf + 21, 40.4);
638     expect_float(buf + 22, 60.2);
639     expect_float(buf + 23, 45.6);
640     expect_float(buf + 24, 20.2);
641     expect_float(buf + 25, 50.0);
642     expect_float(buf + 26, 70.2);
643     expect_dword(buf + 27, 0x01010100);
644     ok(*(buf + 28) == 0x00000101 || *(buf + 28) == 0x43050101 /* Win 7 */,
645        "expected 00000101 or 43050101 got %08x\n", *(buf + 28));
646     expect_dword(buf + 29, 0xeeeeeeee);
647     test_region_data(buf, needed, __LINE__);
648 
649     status = GdipDeletePath(path);
650     expect(Ok, status);
651     status = GdipDeleteRegion(region);
652     expect(Ok, status);
653 
654     /* Test how shorts are stored in the region path data */
655     status = GdipCreatePath(FillModeAlternate, &path);
656     ok(status == Ok, "status %08x\n", status);
657     GdipAddPathRectangleI(path, -1969, -1974, 1995, 1997);
658 
659     status = GdipCreateRegionPath(path, &region);
660     ok(status == Ok, "status %08x\n", status);
661     needed = 0;
662     status = GdipGetRegionDataSize(region, &needed);
663     ok(status == Ok, "status %08x\n", status);
664     expect(56, needed);
665     memset(buf, 0xee, sizeof(buf));
666     needed = 0;
667     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
668     ok(status == Ok, "status %08x\n", status);
669     expect(56, needed);
670     expect_dword(buf, 48);
671     trace("buf[1] = %08x\n", buf[1]);
672     expect_magic(buf + 2);
673     expect_dword(buf + 3, 0);
674     expect_dword(buf + 4, RGNDATA_PATH);
675     expect_dword(buf + 5, 32);
676     expect_magic(buf + 6);
677     expect_dword(buf + 7, 4);
678     /* flags 0x4000 means that a path is an array of shorts instead of FLOATs */
679     expect_dword(buf + 8, 0x4000);
680     point = (RegionDataPoint*)(buf + 9);
681     expect(-1969, point[0].X);
682     expect(-1974, point[0].Y);
683     expect(26, point[1].X); /* buf + 10 */
684     expect(-1974, point[1].Y);
685     expect(26, point[2].X); /* buf + 11 */
686     expect(23, point[2].Y);
687     expect(-1969, point[3].X); /* buf + 12 */
688     expect(23, point[3].Y);
689     expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
690     expect_dword(buf + 14, 0xeeeeeeee);
691     test_region_data(buf, needed, __LINE__);
692 
693     status = GdipDeletePath(path);
694     expect(Ok, status);
695     status = GdipDeleteRegion(region);
696     expect(Ok, status);
697 
698     /* Test with integers that can't be stored as shorts */
699     status = GdipCreatePath(FillModeAlternate, &path);
700     ok(status == Ok, "status %08x\n", status);
701     GdipAddPathRectangleI(path, -196900, -197400, 199500, 199700);
702 
703     status = GdipCreateRegionPath(path, &region);
704     ok(status == Ok, "status %08x\n", status);
705     needed = 0;
706     status = GdipGetRegionDataSize(region, &needed);
707     ok(status == Ok, "status %08x\n", status);
708     expect(72, needed);
709     memset(buf, 0xee, sizeof(buf));
710     needed = 0;
711     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
712     ok(status == Ok, "status %08x\n", status);
713     expect(72, needed);
714     expect_dword(buf, 64);
715     trace("buf[1] = %08x\n", buf[1]);
716     expect_magic(buf + 2);
717     expect_dword(buf + 3, 0);
718     expect_dword(buf + 4, RGNDATA_PATH);
719     expect_dword(buf + 5, 48);
720     expect_magic(buf + 6);
721     expect_dword(buf + 7, 4);
722     /* flags 0 means that a path is an array of FLOATs */
723     expect_dword(buf + 8, 0);
724     expect_float(buf + 9, -196900.0);
725     expect_float(buf + 10, -197400.0);
726     expect_float(buf + 11, 2600.0);
727     expect_float(buf + 12, -197400.0);
728     expect_float(buf + 13, 2600.0);
729     expect_float(buf + 14, 2300.0);
730     expect_float(buf + 15, -196900.0);
731     expect_float(buf + 16, 2300.0);
732     expect_dword(buf + 17, 0x81010100); /* 0x01010100 if we don't close the path */
733     expect_dword(buf + 18, 0xeeeeeeee);
734     test_region_data(buf, needed, __LINE__);
735 
736     status = GdipDeletePath(path);
737     expect(Ok, status);
738     status = GdipDeleteRegion(region);
739     expect(Ok, status);
740 
741     /* Test beziers */
742     GdipCreatePath(FillModeAlternate, &path);
743       /* Exactly 90 degrees */
744     status = GdipAddPathArc(path, 100.0, 100.0, 500.0, 700.0, 0.0, 90.0);
745     expect(Ok, status);
746     /* Over 90 degrees */
747     status = GdipAddPathArc(path, 100.0, 100.0, 500.0, 700.0, 0.0, 100.0);
748     expect(Ok, status);
749     status = GdipCreateRegionPath(path, &region);
750     ok(status == Ok, "status %08x\n", status);
751     needed = 0;
752     status = GdipGetRegionDataSize(region, &needed);
753     ok(status == Ok, "status %08x\n", status);
754     expect(136, needed);
755     memset(buf, 0xee, sizeof(buf));
756     needed = 0;
757     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
758     ok(status == Ok, "status %08x\n", status);
759     expect(136, needed);
760     expect_dword(buf, 128);
761     trace("buf[1] = %08x\n", buf[1]);
762     expect_magic(buf + 2);
763     expect_dword(buf + 3, 0);
764     expect_dword(buf + 4, RGNDATA_PATH);
765     expect_dword(buf + 5, 112);
766     expect_magic(buf + 6);
767     expect_dword(buf + 7, 11);
768     /* flags 0 means that a path is an array of FLOATs */
769     expect_dword(buf + 8, 0);
770     expect_float(buf + 9, 600.0);
771     expect_float(buf + 10, 450.0);
772     expect_float(buf + 11, 600.0);
773     expect_float(buf + 12, 643.299561);
774     expect_float(buf + 13, 488.071198);
775     expect_float(buf + 14, 800.0);
776     expect_float(buf + 15, 350.0);
777     expect_float(buf + 16, 800.0);
778     expect_float(buf + 17, 600.0);
779     expect_float(buf + 18, 450.0);
780     expect_float(buf + 19, 600.0);
781     expect_float(buf + 20, 643.299622);
782     expect_float(buf + 21, 488.071167);
783     expect_float(buf + 22, 800.0);
784     expect_float(buf + 23, 350.0);
785     expect_float(buf + 24, 800.0);
786     expect_float(buf + 25, 329.807129);
787     expect_float(buf + 26, 800.0);
788     expect_float(buf + 27, 309.688568);
789     expect_float(buf + 28, 796.574890);
790     expect_float(buf + 29, 290.084167);
791     expect_float(buf + 30, 789.799561);
792     expect_dword(buf + 31, 0x03030300);
793     expect_dword(buf + 32, 0x03030301);
794     ok(*(buf + 33) == 0x00030303 /* before win7 */ ||
795        *(buf + 33) == 0x43030303 /* 32-bit win7 */ || *(buf + 33) == 0x4c030303 /* 64-bit win7 */,
796        "expected 0x00030303 or 0x43030303 or 0x4c030303 got %08x\n", *(buf + 33));
797     expect_dword(buf + 34, 0xeeeeeeee);
798     test_region_data(buf, needed, __LINE__);
799 
800     status = GdipDeletePath(path);
801     expect(Ok, status);
802     status = GdipDeleteRegion(region);
803     expect(Ok, status);
804 }
805 
806 static void test_isinfinite(void)
807 {
808     GpStatus status;
809     GpRegion *region;
810     GpGraphics *graphics = NULL;
811     GpMatrix *m;
812     HDC hdc = GetDC(0);
813     BOOL res;
814 
815     status = GdipCreateFromHDC(hdc, &graphics);
816     expect(Ok, status);
817     GdipCreateRegion(&region);
818 
819     GdipCreateMatrix2(3.0, 0.0, 0.0, 1.0, 20.0, 30.0, &m);
820 
821     /* NULL arguments */
822     status = GdipIsInfiniteRegion(NULL, NULL, NULL);
823     expect(InvalidParameter, status);
824     status = GdipIsInfiniteRegion(region, NULL, NULL);
825     expect(InvalidParameter, status);
826     status = GdipIsInfiniteRegion(NULL, graphics, NULL);
827     expect(InvalidParameter, status);
828     status = GdipIsInfiniteRegion(NULL, NULL, &res);
829     expect(InvalidParameter, status);
830     status = GdipIsInfiniteRegion(region, NULL, &res);
831     expect(InvalidParameter, status);
832 
833     res = FALSE;
834     status = GdipIsInfiniteRegion(region, graphics, &res);
835     expect(Ok, status);
836     expect(TRUE, res);
837 
838     /* after world transform */
839     status = GdipSetWorldTransform(graphics, m);
840     expect(Ok, status);
841 
842     res = FALSE;
843     status = GdipIsInfiniteRegion(region, graphics, &res);
844     expect(Ok, status);
845     expect(TRUE, res);
846 
847     GdipDeleteMatrix(m);
848     GdipDeleteRegion(region);
849     GdipDeleteGraphics(graphics);
850     ReleaseDC(0, hdc);
851 }
852 
853 static void test_isempty(void)
854 {
855     GpStatus status;
856     GpRegion *region;
857     GpGraphics *graphics = NULL;
858     HDC hdc = GetDC(0);
859     BOOL res;
860 
861     status = GdipCreateFromHDC(hdc, &graphics);
862     expect(Ok, status);
863     GdipCreateRegion(&region);
864 
865     /* NULL arguments */
866     status = GdipIsEmptyRegion(NULL, NULL, NULL);
867     expect(InvalidParameter, status);
868     status = GdipIsEmptyRegion(region, NULL, NULL);
869     expect(InvalidParameter, status);
870     status = GdipIsEmptyRegion(NULL, graphics, NULL);
871     expect(InvalidParameter, status);
872     status = GdipIsEmptyRegion(NULL, NULL, &res);
873     expect(InvalidParameter, status);
874     status = GdipIsEmptyRegion(region, NULL, &res);
875     expect(InvalidParameter, status);
876 
877     /* default is infinite */
878     res = TRUE;
879     status = GdipIsEmptyRegion(region, graphics, &res);
880     expect(Ok, status);
881     expect(FALSE, res);
882 
883     status = GdipSetEmpty(region);
884     expect(Ok, status);
885 
886     res = FALSE;
887     status = GdipIsEmptyRegion(region, graphics, &res);
888     expect(Ok, status);
889     expect(TRUE, res);
890 
891     GdipDeleteRegion(region);
892     GdipDeleteGraphics(graphics);
893     ReleaseDC(0, hdc);
894 }
895 
896 static void test_combinereplace(void)
897 {
898     GpStatus status;
899     GpRegion *region, *region2;
900     GpPath *path;
901     GpRectF rectf;
902     UINT needed;
903     DWORD buf[50];
904 
905     rectf.X = rectf.Y = 0.0;
906     rectf.Width = rectf.Height = 100.0;
907 
908     status = GdipCreateRegionRect(&rectf, &region);
909     expect(Ok, status);
910 
911     /* replace with the same rectangle */
912     status = GdipCombineRegionRect(region, &rectf,CombineModeReplace);
913     expect(Ok, status);
914 
915     status = GdipGetRegionDataSize(region, &needed);
916     expect(Ok, status);
917     expect(36, needed);
918     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
919     expect(Ok, status);
920     expect(36, needed);
921     expect_dword(buf, 28);
922     trace("buf[1] = %08x\n", buf[1]);
923     expect_magic(buf + 2);
924     expect_dword(buf + 3, 0);
925     expect_dword(buf + 4, RGNDATA_RECT);
926 
927     /* replace with path */
928     status = GdipCreatePath(FillModeAlternate, &path);
929     expect(Ok, status);
930     status = GdipAddPathEllipse(path, 0.0, 0.0, 100.0, 250.0);
931     expect(Ok, status);
932     status = GdipCombineRegionPath(region, path, CombineModeReplace);
933     expect(Ok, status);
934 
935     status = GdipGetRegionDataSize(region, &needed);
936     expect(Ok, status);
937     expect(156, needed);
938     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
939     expect(Ok, status);
940     expect(156, needed);
941     expect_dword(buf, 148);
942     trace("buf[1] = %08x\n", buf[1]);
943     expect_magic(buf + 2);
944     expect_dword(buf + 3, 0);
945     expect_dword(buf + 4, RGNDATA_PATH);
946     GdipDeletePath(path);
947 
948     /* replace with infinite rect */
949     status = GdipCreateRegion(&region2);
950     expect(Ok, status);
951     status = GdipCombineRegionRegion(region, region2, CombineModeReplace);
952     expect(Ok, status);
953 
954     status = GdipGetRegionDataSize(region, &needed);
955     expect(Ok, status);
956     expect(20, needed);
957     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
958     expect(Ok, status);
959     expect(20, needed);
960     expect_dword(buf, 12);
961     trace("buf[1] = %08x\n", buf[1]);
962     expect_magic(buf + 2);
963     expect_dword(buf + 3, 0);
964     expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
965     GdipDeleteRegion(region2);
966 
967     /* more complex case : replace with a combined region */
968     status = GdipCreateRegionRect(&rectf, &region2);
969     expect(Ok, status);
970     status = GdipCreatePath(FillModeAlternate, &path);
971     expect(Ok, status);
972     status = GdipAddPathEllipse(path, 0.0, 0.0, 100.0, 250.0);
973     expect(Ok, status);
974     status = GdipCombineRegionPath(region2, path, CombineModeUnion);
975     expect(Ok, status);
976     GdipDeletePath(path);
977     status = GdipCombineRegionRegion(region, region2, CombineModeReplace);
978     expect(Ok, status);
979     GdipDeleteRegion(region2);
980 
981     status = GdipGetRegionDataSize(region, &needed);
982     expect(Ok, status);
983     expect(180, needed);
984     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
985     expect(Ok, status);
986     expect(180, needed);
987     expect_dword(buf, 172);
988     trace("buf[1] = %08x\n", buf[1]);
989     expect_magic(buf + 2);
990     expect_dword(buf + 3, 2);
991     expect_dword(buf + 4, CombineModeUnion);
992 
993     GdipDeleteRegion(region);
994 }
995 
996 static void test_fromhrgn(void)
997 {
998     GpStatus status;
999     GpRegion *region = (GpRegion*)0xabcdef01;
1000     HRGN hrgn;
1001     UINT needed;
1002     DWORD buf[220];
1003     RegionDataPoint *point;
1004     GpGraphics *graphics = NULL;
1005     HDC hdc;
1006     BOOL res;
1007 
1008     /* NULL */
1009     status = GdipCreateRegionHrgn(NULL, NULL);
1010     expect(InvalidParameter, status);
1011     status = GdipCreateRegionHrgn(NULL, &region);
1012     expect(InvalidParameter, status);
1013     status = GdipCreateRegionHrgn((HRGN)0xdeadbeef, &region);
1014     expect(InvalidParameter, status);
1015     ok(region == (GpRegion*)0xabcdef01, "Expected region not to be created\n");
1016 
1017     /* empty rectangle */
1018     hrgn = CreateRectRgn(0, 0, 0, 0);
1019     status = GdipCreateRegionHrgn(hrgn, &region);
1020     expect(Ok, status);
1021     if(status == Ok) {
1022 
1023     hdc = GetDC(0);
1024     status = GdipCreateFromHDC(hdc, &graphics);
1025     expect(Ok, status);
1026     res = FALSE;
1027     status = GdipIsEmptyRegion(region, graphics, &res);
1028     expect(Ok, status);
1029     expect(TRUE, res);
1030     GdipDeleteGraphics(graphics);
1031     ReleaseDC(0, hdc);
1032     GdipDeleteRegion(region);
1033 
1034     }
1035     DeleteObject(hrgn);
1036 
1037     /* rectangle */
1038     hrgn = CreateRectRgn(0, 0, 100, 10);
1039     status = GdipCreateRegionHrgn(hrgn, &region);
1040     expect(Ok, status);
1041 
1042     status = GdipGetRegionDataSize(region, &needed);
1043     expect(Ok, status);
1044     expect(56, needed);
1045 
1046     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
1047     expect(Ok, status);
1048 
1049     if(status == Ok){
1050 
1051     expect(56, needed);
1052     expect_dword(buf, 48);
1053     expect_magic(buf + 2);
1054     expect_dword(buf + 3, 0);
1055     expect_dword(buf + 4, RGNDATA_PATH);
1056     expect_dword(buf + 5, 0x00000020);
1057     expect_magic(buf + 6);
1058     expect_dword(buf + 7, 0x00000004);
1059     todo_wine expect_dword(buf + 8, 0x00006000); /* ?? */
1060 
1061     point = (RegionDataPoint*)buf + 9;
1062 
1063     expect(0,  point[0].X);
1064     expect(0,  point[0].Y);
1065 
1066     expect(100,point[1].X); /* buf + 10 */
1067     expect(0,  point[1].Y);
1068     expect(100,point[2].X); /* buf + 11 */
1069     expect(10, point[2].Y);
1070 
1071     expect(0,  point[3].X); /* buf + 12 */
1072 
1073     expect(10, point[3].Y);
1074     expect_dword(buf + 13, 0x81010100); /* closed */
1075 
1076     }
1077 
1078     GdipDeleteRegion(region);
1079     DeleteObject(hrgn);
1080 
1081     /* ellipse */
1082     hrgn = CreateEllipticRgn(0, 0, 100, 10);
1083     status = GdipCreateRegionHrgn(hrgn, &region);
1084     expect(Ok, status);
1085 
1086     status = GdipGetRegionDataSize(region, &needed);
1087     expect(Ok, status);
1088     ok(needed == 216 ||
1089        needed == 196, /* win98 */
1090        "Got %.8x\n", needed);
1091 
1092     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
1093     expect(Ok, status);
1094 
1095     if(status == Ok && needed == 216) /* Don't try to test win98 layout */
1096     {
1097     expect(Ok, status);
1098     expect(216, needed);
1099     expect_dword(buf, 208);
1100     expect_magic(buf + 2);
1101     expect_dword(buf + 3, 0);
1102     expect_dword(buf + 4, RGNDATA_PATH);
1103     expect_dword(buf + 5, 0x000000C0);
1104     expect_magic(buf + 6);
1105     expect_dword(buf + 7, 0x00000024);
1106     todo_wine expect_dword(buf + 8, 0x00006000); /* ?? */
1107     }
1108 
1109     GdipDeleteRegion(region);
1110     DeleteObject(hrgn);
1111 }
1112 
1113 static void test_gethrgn(void)
1114 {
1115     GpStatus status;
1116     GpRegion *region, *region2;
1117     GpPath *path;
1118     GpGraphics *graphics;
1119     HRGN hrgn;
1120     HDC hdc=GetDC(0);
1121     INT rgntype;
1122     RECT rgnbox;
1123     static const RECT empty_rect = {0,0,0,0};
1124     static const RECT test_rect = {10, 11, 20, 21};
1125     static const GpRectF test_rectF = {10.0, 11.0, 10.0, 10.0};
1126     static const RECT scaled_rect = {20, 22, 40, 42};
1127     static const RECT test_rect2 = {10, 21, 20, 31};
1128     static const GpRectF test_rect2F = {10.0, 21.0, 10.0, 10.0};
1129     static const RECT test_rect3 = {10, 11, 20, 31};
1130     static const GpRectF test_rect3F = {10.0, 11.0, 10.0, 20.0};
1131 
1132     status = GdipCreateFromHDC(hdc, &graphics);
1133     ok(status == Ok, "status %08x\n", status);
1134 
1135     status = GdipCreateRegion(&region);
1136     ok(status == Ok, "status %08x\n", status);
1137 
1138     status = GdipGetRegionHRgn(NULL, graphics, &hrgn);
1139     ok(status == InvalidParameter, "status %08x\n", status);
1140     status = GdipGetRegionHRgn(region, graphics, NULL);
1141     ok(status == InvalidParameter, "status %08x\n", status);
1142 
1143     status = GdipGetRegionHRgn(region, NULL, &hrgn);
1144     ok(status == Ok, "status %08x\n", status);
1145     ok(hrgn == NULL, "hrgn=%p\n", hrgn);
1146 
1147     status = GdipGetRegionHRgn(region, graphics, &hrgn);
1148     ok(status == Ok, "status %08x\n", status);
1149     ok(hrgn == NULL, "hrgn=%p\n", hrgn);
1150 
1151     status = GdipSetEmpty(region);
1152     ok(status == Ok, "status %08x\n", status);
1153     status = GdipGetRegionHRgn(region, NULL, &hrgn);
1154     ok(status == Ok, "status %08x\n", status);
1155     verify_region(hrgn, &empty_rect);
1156     DeleteObject(hrgn);
1157 
1158     status = GdipCreatePath(FillModeAlternate, &path);
1159     ok(status == Ok, "status %08x\n", status);
1160     status = GdipAddPathRectangle(path, 10.0, 11.0, 10.0, 10.0);
1161     ok(status == Ok, "status %08x\n", status);
1162 
1163     status = GdipCreateRegionPath(path, &region2);
1164     ok(status == Ok, "status %08x\n", status);
1165     status = GdipGetRegionHRgn(region2, NULL, &hrgn);
1166     ok(status == Ok, "status %08x\n", status);
1167     verify_region(hrgn, &test_rect);
1168     DeleteObject(hrgn);
1169 
1170     /* resulting HRGN is in device coordinates */
1171     status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
1172     ok(status == Ok, "status %08x\n", status);
1173     status = GdipGetRegionHRgn(region2, graphics, &hrgn);
1174     ok(status == Ok, "status %08x\n", status);
1175     verify_region(hrgn, &scaled_rect);
1176     DeleteObject(hrgn);
1177 
1178     status = GdipCombineRegionRect(region2, &test_rectF, CombineModeReplace);
1179     ok(status == Ok, "status %08x\n", status);
1180     status = GdipGetRegionHRgn(region2, NULL, &hrgn);
1181     ok(status == Ok, "status %08x\n", status);
1182     verify_region(hrgn, &test_rect);
1183     DeleteObject(hrgn);
1184 
1185     status = GdipGetRegionHRgn(region2, graphics, &hrgn);
1186     ok(status == Ok, "status %08x\n", status);
1187     verify_region(hrgn, &scaled_rect);
1188     DeleteObject(hrgn);
1189 
1190     status = GdipSetInfinite(region);
1191     ok(status == Ok, "status %08x\n", status);
1192     status = GdipCombineRegionRect(region, &test_rectF, CombineModeIntersect);
1193     ok(status == Ok, "status %08x\n", status);
1194     status = GdipGetRegionHRgn(region, NULL, &hrgn);
1195     ok(status == Ok, "status %08x\n", status);
1196     verify_region(hrgn, &test_rect);
1197     DeleteObject(hrgn);
1198 
1199     status = GdipCombineRegionRect(region, &test_rectF, CombineModeReplace);
1200     ok(status == Ok, "status %08x\n", status);
1201     status = GdipCombineRegionRect(region, &test_rect2F, CombineModeUnion);
1202     ok(status == Ok, "status %08x\n", status);
1203     status = GdipGetRegionHRgn(region, NULL, &hrgn);
1204     ok(status == Ok, "status %08x\n", status);
1205     verify_region(hrgn, &test_rect3);
1206     DeleteObject(hrgn);
1207 
1208     status = GdipCombineRegionRect(region, &test_rect3F, CombineModeReplace);
1209     ok(status == Ok, "status %08x\n", status);
1210     status = GdipCombineRegionRect(region, &test_rect2F, CombineModeXor);
1211     ok(status == Ok, "status %08x\n", status);
1212     status = GdipGetRegionHRgn(region, NULL, &hrgn);
1213     ok(status == Ok, "status %08x\n", status);
1214     verify_region(hrgn, &test_rect);
1215     DeleteObject(hrgn);
1216 
1217     status = GdipCombineRegionRect(region, &test_rect3F, CombineModeReplace);
1218     ok(status == Ok, "status %08x\n", status);
1219     status = GdipCombineRegionRect(region, &test_rectF, CombineModeExclude);
1220     ok(status == Ok, "status %08x\n", status);
1221     status = GdipGetRegionHRgn(region, NULL, &hrgn);
1222     ok(status == Ok, "status %08x\n", status);
1223     verify_region(hrgn, &test_rect2);
1224     DeleteObject(hrgn);
1225 
1226     status = GdipCombineRegionRect(region, &test_rectF, CombineModeReplace);
1227     ok(status == Ok, "status %08x\n", status);
1228     status = GdipCombineRegionRect(region, &test_rect3F, CombineModeComplement);
1229     ok(status == Ok, "status %08x\n", status);
1230     status = GdipGetRegionHRgn(region, NULL, &hrgn);
1231     ok(status == Ok, "status %08x\n", status);
1232     verify_region(hrgn, &test_rect2);
1233     DeleteObject(hrgn);
1234 
1235     status = GdipDeletePath(path);
1236     ok(status == Ok, "status %08x\n", status);
1237     status = GdipDeleteRegion(region);
1238     ok(status == Ok, "status %08x\n", status);
1239     status = GdipDeleteRegion(region2);
1240     ok(status == Ok, "status %08x\n", status);
1241     status = GdipDeleteGraphics(graphics);
1242     ok(status == Ok, "status %08x\n", status);
1243 
1244     /* test with gdi32 transform */
1245     SetViewportOrgEx(hdc, 10, 10, NULL);
1246 
1247     status = GdipCreateFromHDC(hdc, &graphics);
1248     expect(Ok, status);
1249 
1250     status = GdipCreateRegionRect(&test_rectF, &region);
1251     expect(Ok, status);
1252 
1253     status = GdipGetRegionHRgn(region, graphics, &hrgn);
1254     expect(Ok, status);
1255 
1256     rgntype = GetRgnBox(hrgn, &rgnbox);
1257     DeleteObject(hrgn);
1258 
1259     expect(SIMPLEREGION, rgntype);
1260     expect(20, rgnbox.left);
1261     expect(21, rgnbox.top);
1262     expect(30, rgnbox.right);
1263     expect(31, rgnbox.bottom);
1264 
1265     status = GdipDeleteRegion(region);
1266     expect(Ok, status);
1267     status = GdipDeleteGraphics(graphics);
1268     expect(Ok, status);
1269 
1270     SetViewportOrgEx(hdc, 0, 0, NULL);
1271 
1272     ReleaseDC(0, hdc);
1273 }
1274 
1275 static void test_isequal(void)
1276 {
1277     GpRegion *region1, *region2;
1278     GpGraphics *graphics;
1279     GpRectF rectf;
1280     GpStatus status;
1281     HDC hdc = GetDC(0);
1282     BOOL res;
1283 
1284     status = GdipCreateFromHDC(hdc, &graphics);
1285     ok(status == Ok, "status %08x\n", status);
1286 
1287     status = GdipCreateRegion(&region1);
1288     ok(status == Ok, "status %08x\n", status);
1289     status = GdipCreateRegion(&region2);
1290     ok(status == Ok, "status %08x\n", status);
1291 
1292     /* NULL */
1293     status = GdipIsEqualRegion(NULL, NULL, NULL, NULL);
1294     ok(status == InvalidParameter, "status %08x\n", status);
1295     status = GdipIsEqualRegion(region1, region2, NULL, NULL);
1296     ok(status == InvalidParameter, "status %08x\n", status);
1297     status = GdipIsEqualRegion(region1, region2, graphics, NULL);
1298     ok(status == InvalidParameter, "status %08x\n", status);
1299     status = GdipIsEqualRegion(region1, region2, NULL, &res);
1300     ok(status == InvalidParameter, "status %08x\n", status);
1301 
1302     /* infinite regions */
1303     res = FALSE;
1304     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1305     ok(status == Ok, "status %08x\n", status);
1306     ok(res, "Expected to be equal.\n");
1307     /* empty regions */
1308     status = GdipSetEmpty(region1);
1309     ok(status == Ok, "status %08x\n", status);
1310     status = GdipSetEmpty(region2);
1311     ok(status == Ok, "status %08x\n", status);
1312     res = FALSE;
1313     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1314     ok(status == Ok, "status %08x\n", status);
1315     ok(res, "Expected to be equal.\n");
1316     /* empty & infinite */
1317     status = GdipSetInfinite(region1);
1318     ok(status == Ok, "status %08x\n", status);
1319     res = TRUE;
1320     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1321     ok(status == Ok, "status %08x\n", status);
1322     ok(!res, "Expected to be unequal.\n");
1323     /* rect & (inf/empty) */
1324     rectf.X = rectf.Y = 0.0;
1325     rectf.Width = rectf.Height = 100.0;
1326     status = GdipCombineRegionRect(region1, &rectf, CombineModeReplace);
1327     ok(status == Ok, "status %08x\n", status);
1328     res = TRUE;
1329     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1330     ok(status == Ok, "status %08x\n", status);
1331     ok(!res, "Expected to be unequal.\n");
1332     status = GdipSetInfinite(region2);
1333     ok(status == Ok, "status %08x\n", status);
1334     res = TRUE;
1335     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1336     ok(status == Ok, "status %08x\n", status);
1337     ok(!res, "Expected to be unequal.\n");
1338     /* roughly equal rectangles */
1339     rectf.X = rectf.Y = 0.0;
1340     rectf.Width = rectf.Height = 100.001;
1341     status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1342     ok(status == Ok, "status %08x\n", status);
1343     res = FALSE;
1344     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1345     ok(status == Ok, "status %08x\n", status);
1346     ok(res, "Expected to be equal.\n");
1347     /* equal rectangles */
1348     rectf.X = rectf.Y = 0.0;
1349     rectf.Width = rectf.Height = 100.0;
1350     status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1351     ok(status == Ok, "status %08x\n", status);
1352     res = FALSE;
1353     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1354     ok(status == Ok, "status %08x\n", status);
1355     ok(res, "Expected to be equal.\n");
1356 
1357     /* cleanup */
1358     status = GdipDeleteRegion(region1);
1359     ok(status == Ok, "status %08x\n", status);
1360     status = GdipDeleteRegion(region2);
1361     ok(status == Ok, "status %08x\n", status);
1362     status = GdipDeleteGraphics(graphics);
1363     ok(status == Ok, "status %08x\n", status);
1364     ReleaseDC(0, hdc);
1365 }
1366 
1367 static void test_translate(void)
1368 {
1369     GpRegion *region, *region2;
1370     GpGraphics *graphics;
1371     GpPath *path;
1372     GpRectF rectf;
1373     GpStatus status;
1374     HDC hdc = GetDC(0);
1375     BOOL res;
1376 
1377     status = GdipCreateFromHDC(hdc, &graphics);
1378     ok(status == Ok, "status %08x\n", status);
1379 
1380     status = GdipCreatePath(FillModeAlternate, &path);
1381     ok(status == Ok, "status %08x\n", status);
1382 
1383     status = GdipCreateRegion(&region);
1384     ok(status == Ok, "status %08x\n", status);
1385     status = GdipCreateRegion(&region2);
1386     ok(status == Ok, "status %08x\n", status);
1387 
1388     /* NULL */
1389     status = GdipTranslateRegion(NULL, 0.0, 0.0);
1390     ok(status == InvalidParameter, "status %08x\n", status);
1391 
1392     /* infinite */
1393     status = GdipTranslateRegion(region, 10.0, 10.0);
1394     ok(status == Ok, "status %08x\n", status);
1395     /* empty */
1396     status = GdipSetEmpty(region);
1397     ok(status == Ok, "status %08x\n", status);
1398     status = GdipTranslateRegion(region, 10.0, 10.0);
1399     ok(status == Ok, "status %08x\n", status);
1400     /* rect */
1401     rectf.X = 10.0; rectf.Y = 0.0;
1402     rectf.Width = rectf.Height = 100.0;
1403     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1404     ok(status == Ok, "status %08x\n", status);
1405     rectf.X = 15.0; rectf.Y = -2.0;
1406     rectf.Width = rectf.Height = 100.0;
1407     status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1408     ok(status == Ok, "status %08x\n", status);
1409     status = GdipTranslateRegion(region, 5.0, -2.0);
1410     ok(status == Ok, "status %08x\n", status);
1411     res = FALSE;
1412     status = GdipIsEqualRegion(region, region2, graphics, &res);
1413     ok(status == Ok, "status %08x\n", status);
1414     ok(res, "Expected to be equal.\n");
1415     /* path */
1416     status = GdipAddPathEllipse(path, 0.0, 10.0, 100.0, 150.0);
1417     ok(status == Ok, "status %08x\n", status);
1418     status = GdipCombineRegionPath(region, path, CombineModeReplace);
1419     ok(status == Ok, "status %08x\n", status);
1420     status = GdipResetPath(path);
1421     ok(status == Ok, "status %08x\n", status);
1422     status = GdipAddPathEllipse(path, 10.0, 21.0, 100.0, 150.0);
1423     ok(status == Ok, "status %08x\n", status);
1424     status = GdipCombineRegionPath(region2, path, CombineModeReplace);
1425     ok(status == Ok, "status %08x\n", status);
1426     status = GdipTranslateRegion(region, 10.0, 11.0);
1427     ok(status == Ok, "status %08x\n", status);
1428     res = FALSE;
1429     status = GdipIsEqualRegion(region, region2, graphics, &res);
1430     ok(status == Ok, "status %08x\n", status);
1431     ok(res, "Expected to be equal.\n");
1432 
1433     status = GdipDeleteRegion(region);
1434     ok(status == Ok, "status %08x\n", status);
1435     status = GdipDeleteRegion(region2);
1436     ok(status == Ok, "status %08x\n", status);
1437     status = GdipDeleteGraphics(graphics);
1438     ok(status == Ok, "status %08x\n", status);
1439     status = GdipDeletePath(path);
1440     ok(status == Ok, "status %08x\n", status);
1441     ReleaseDC(0, hdc);
1442 }
1443 
1444 static void test_transform(void)
1445 {
1446     GpRegion *region, *region2;
1447     GpMatrix *matrix;
1448     GpGraphics *graphics;
1449     GpPath *path;
1450     GpRectF rectf;
1451     GpStatus status;
1452     HDC hdc = GetDC(0);
1453     BOOL res;
1454 
1455     status = GdipCreateFromHDC(hdc, &graphics);
1456     expect(Ok, status);
1457 
1458     status = GdipCreatePath(FillModeAlternate, &path);
1459     expect(Ok, status);
1460 
1461     status = GdipCreateRegion(&region);
1462     expect(Ok, status);
1463     status = GdipCreateRegion(&region2);
1464     expect(Ok, status);
1465 
1466     status = GdipCreateMatrix(&matrix);
1467     expect(Ok, status);
1468     status = GdipScaleMatrix(matrix, 2.0, 3.0, MatrixOrderAppend);
1469     expect(Ok, status);
1470 
1471     /* NULL */
1472     status = GdipTransformRegion(NULL, matrix);
1473     expect(InvalidParameter, status);
1474 
1475     status = GdipTransformRegion(region, NULL);
1476     expect(InvalidParameter, status);
1477 
1478     /* infinite */
1479     status = GdipTransformRegion(region, matrix);
1480     expect(Ok, status);
1481 
1482     res = FALSE;
1483     status = GdipIsEqualRegion(region, region2, graphics, &res);
1484     expect(Ok, status);
1485     ok(res, "Expected to be equal.\n");
1486 
1487     /* empty */
1488     status = GdipSetEmpty(region);
1489     expect(Ok, status);
1490     status = GdipTransformRegion(region, matrix);
1491     expect(Ok, status);
1492 
1493     status = GdipSetEmpty(region2);
1494     expect(Ok, status);
1495 
1496     res = FALSE;
1497     status = GdipIsEqualRegion(region, region2, graphics, &res);
1498     expect(Ok, status);
1499     ok(res, "Expected to be equal.\n");
1500 
1501     /* rect */
1502     rectf.X = 10.0;
1503     rectf.Y = 0.0;
1504     rectf.Width = rectf.Height = 100.0;
1505     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1506     expect(Ok, status);
1507     rectf.X = 20.0;
1508     rectf.Y = 0.0;
1509     rectf.Width = 200.0;
1510     rectf.Height = 300.0;
1511     status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1512     expect(Ok, status);
1513     status = GdipTransformRegion(region, matrix);
1514     expect(Ok, status);
1515     res = FALSE;
1516     status = GdipIsEqualRegion(region, region2, graphics, &res);
1517     expect(Ok, status);
1518     ok(res, "Expected to be equal.\n");
1519 
1520     /* path */
1521     status = GdipAddPathEllipse(path, 0.0, 10.0, 100.0, 150.0);
1522     expect(Ok, status);
1523     status = GdipCombineRegionPath(region, path, CombineModeReplace);
1524     expect(Ok, status);
1525     status = GdipResetPath(path);
1526     expect(Ok, status);
1527     status = GdipAddPathEllipse(path, 0.0, 30.0, 200.0, 450.0);
1528     expect(Ok, status);
1529     status = GdipCombineRegionPath(region2, path, CombineModeReplace);
1530     expect(Ok, status);
1531     status = GdipTransformRegion(region, matrix);
1532     expect(Ok, status);
1533     res = FALSE;
1534     status = GdipIsEqualRegion(region, region2, graphics, &res);
1535     expect(Ok, status);
1536     ok(res, "Expected to be equal.\n");
1537 
1538     status = GdipDeleteRegion(region);
1539     expect(Ok, status);
1540     status = GdipDeleteRegion(region2);
1541     expect(Ok, status);
1542     status = GdipDeleteGraphics(graphics);
1543     expect(Ok, status);
1544     status = GdipDeletePath(path);
1545     expect(Ok, status);
1546     status = GdipDeleteMatrix(matrix);
1547     expect(Ok, status);
1548     ReleaseDC(0, hdc);
1549 }
1550 
1551 static void test_scans(void)
1552 {
1553     GpRegion *region;
1554     GpMatrix *matrix;
1555     GpRectF rectf;
1556     GpStatus status;
1557     ULONG count=80085;
1558     INT icount;
1559     GpRectF scans[2];
1560     GpRect scansi[2];
1561 
1562     status = GdipCreateRegion(&region);
1563     expect(Ok, status);
1564 
1565     status = GdipCreateMatrix(&matrix);
1566     expect(Ok, status);
1567 
1568     /* test NULL values */
1569     status = GdipGetRegionScansCount(NULL, &count, matrix);
1570     expect(InvalidParameter, status);
1571 
1572     status = GdipGetRegionScansCount(region, NULL, matrix);
1573     expect(InvalidParameter, status);
1574 
1575     status = GdipGetRegionScansCount(region, &count, NULL);
1576     expect(InvalidParameter, status);
1577 
1578     status = GdipGetRegionScans(NULL, scans, &icount, matrix);
1579     expect(InvalidParameter, status);
1580 
1581     status = GdipGetRegionScans(region, scans, NULL, matrix);
1582     expect(InvalidParameter, status);
1583 
1584     status = GdipGetRegionScans(region, scans, &icount, NULL);
1585     expect(InvalidParameter, status);
1586 
1587     /* infinite */
1588     status = GdipGetRegionScansCount(region, &count, matrix);
1589     expect(Ok, status);
1590     expect(1, count);
1591 
1592     status = GdipGetRegionScans(region, NULL, &icount, matrix);
1593     expect(Ok, status);
1594     expect(1, icount);
1595 
1596     status = GdipGetRegionScans(region, scans, &icount, matrix);
1597     expect(Ok, status);
1598     expect(1, icount);
1599 
1600     status = GdipGetRegionScansI(region, scansi, &icount, matrix);
1601     expect(Ok, status);
1602     expect(1, icount);
1603     expect(-0x400000, scansi[0].X);
1604     expect(-0x400000, scansi[0].Y);
1605     expect(0x800000, scansi[0].Width);
1606     expect(0x800000, scansi[0].Height);
1607 
1608     status = GdipGetRegionScans(region, scans, &icount, matrix);
1609     expect(Ok, status);
1610     expect(1, icount);
1611     expectf((double)-0x400000, scans[0].X);
1612     expectf((double)-0x400000, scans[0].Y);
1613     expectf((double)0x800000, scans[0].Width);
1614     expectf((double)0x800000, scans[0].Height);
1615 
1616     /* empty */
1617     status = GdipSetEmpty(region);
1618     expect(Ok, status);
1619 
1620     status = GdipGetRegionScansCount(region, &count, matrix);
1621     expect(Ok, status);
1622     expect(0, count);
1623 
1624     status = GdipGetRegionScans(region, scans, &icount, matrix);
1625     expect(Ok, status);
1626     expect(0, icount);
1627 
1628     /* single rectangle */
1629     rectf.X = rectf.Y = 0.0;
1630     rectf.Width = rectf.Height = 5.0;
1631     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1632     expect(Ok, status);
1633 
1634     status = GdipGetRegionScansCount(region, &count, matrix);
1635     expect(Ok, status);
1636     expect(1, count);
1637 
1638     status = GdipGetRegionScans(region, scans, &icount, matrix);
1639     expect(Ok, status);
1640     expect(1, icount);
1641     expectf(0.0, scans[0].X);
1642     expectf(0.0, scans[0].Y);
1643     expectf(5.0, scans[0].Width);
1644     expectf(5.0, scans[0].Height);
1645 
1646     /* two rectangles */
1647     rectf.X = rectf.Y = 5.0;
1648     rectf.Width = rectf.Height = 5.0;
1649     status = GdipCombineRegionRect(region, &rectf, CombineModeUnion);
1650     expect(Ok, status);
1651 
1652     status = GdipGetRegionScansCount(region, &count, matrix);
1653     expect(Ok, status);
1654     expect(2, count);
1655 
1656     /* Native ignores the initial value of count */
1657     scans[1].X = scans[1].Y = scans[1].Width = scans[1].Height = 8.0;
1658     icount = 1;
1659     status = GdipGetRegionScans(region, scans, &icount, matrix);
1660     expect(Ok, status);
1661     expect(2, icount);
1662     expectf(0.0, scans[0].X);
1663     expectf(0.0, scans[0].Y);
1664     expectf(5.0, scans[0].Width);
1665     expectf(5.0, scans[0].Height);
1666     expectf(5.0, scans[1].X);
1667     expectf(5.0, scans[1].Y);
1668     expectf(5.0, scans[1].Width);
1669     expectf(5.0, scans[1].Height);
1670 
1671     status = GdipGetRegionScansI(region, scansi, &icount, matrix);
1672     expect(Ok, status);
1673     expect(2, icount);
1674     expect(0, scansi[0].X);
1675     expect(0, scansi[0].Y);
1676     expect(5, scansi[0].Width);
1677     expect(5, scansi[0].Height);
1678     expect(5, scansi[1].X);
1679     expect(5, scansi[1].Y);
1680     expect(5, scansi[1].Width);
1681     expect(5, scansi[1].Height);
1682 
1683     status = GdipDeleteRegion(region);
1684     expect(Ok, status);
1685     status = GdipDeleteMatrix(matrix);
1686     expect(Ok, status);
1687 }
1688 
1689 static void test_getbounds(void)
1690 {
1691     GpRegion *region;
1692     GpGraphics *graphics;
1693     GpStatus status;
1694     GpRectF rectf;
1695     HDC hdc = GetDC(0);
1696 
1697     status = GdipCreateFromHDC(hdc, &graphics);
1698     ok(status == Ok, "status %08x\n", status);
1699     status = GdipCreateRegion(&region);
1700     ok(status == Ok, "status %08x\n", status);
1701 
1702     /* NULL */
1703     status = GdipGetRegionBounds(NULL, NULL, NULL);
1704     ok(status == InvalidParameter, "status %08x\n", status);
1705     status = GdipGetRegionBounds(region, NULL, NULL);
1706     ok(status == InvalidParameter, "status %08x\n", status);
1707     status = GdipGetRegionBounds(region, graphics, NULL);
1708     ok(status == InvalidParameter, "status %08x\n", status);
1709     /* infinite */
1710     rectf.X = rectf.Y = 0.0;
1711     rectf.Height = rectf.Width = 100.0;
1712     status = GdipGetRegionBounds(region, graphics, &rectf);
1713     ok(status == Ok, "status %08x\n", status);
1714     ok(rectf.X == -(REAL)(1 << 22), "Expected X = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.X);
1715     ok(rectf.Y == -(REAL)(1 << 22), "Expected Y = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.Y);
1716     ok(rectf.Width  == (REAL)(1 << 23), "Expected width = %.2f, got %.2f\n", (REAL)(1 << 23), rectf.Width);
1717     ok(rectf.Height == (REAL)(1 << 23), "Expected height = %.2f, got %.2f\n",(REAL)(1 << 23), rectf.Height);
1718     /* empty */
1719     rectf.X = rectf.Y = 0.0;
1720     rectf.Height = rectf.Width = 100.0;
1721     status = GdipSetEmpty(region);
1722     ok(status == Ok, "status %08x\n", status);
1723     status = GdipGetRegionBounds(region, graphics, &rectf);
1724     ok(status == Ok, "status %08x\n", status);
1725     ok(rectf.X == 0.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1726     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1727     ok(rectf.Width  == 0.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1728     ok(rectf.Height == 0.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1729     /* rect */
1730     rectf.X = 10.0; rectf.Y = 0.0;
1731     rectf.Width = rectf.Height = 100.0;
1732     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1733     ok(status == Ok, "status %08x\n", status);
1734     rectf.X = rectf.Y = 0.0;
1735     rectf.Height = rectf.Width = 0.0;
1736     status = GdipGetRegionBounds(region, graphics, &rectf);
1737     ok(status == Ok, "status %08x\n", status);
1738     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1739     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1740     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1741     ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1742 
1743     /* the world and page transforms are ignored */
1744     GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
1745     GdipSetPageUnit(graphics, UnitInch);
1746     GdipSetPageScale(graphics, 2.0);
1747     status = GdipGetRegionBounds(region, graphics, &rectf);
1748     ok(status == Ok, "status %08x\n", status);
1749     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1750     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1751     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1752 
1753     rectf.X = 10.0; rectf.Y = 0.0;
1754     rectf.Width = rectf.Height = 100.0;
1755     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1756     ok(status == Ok, "status %08x\n", status);
1757     rectf.X = rectf.Y = 0.0;
1758     rectf.Height = rectf.Width = 0.0;
1759     status = GdipGetRegionBounds(region, graphics, &rectf);
1760     ok(status == Ok, "status %08x\n", status);
1761     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1762     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1763     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1764     ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1765 
1766     status = GdipDeleteRegion(region);
1767     ok(status == Ok, "status %08x\n", status);
1768     status = GdipDeleteGraphics(graphics);
1769     ok(status == Ok, "status %08x\n", status);
1770     ReleaseDC(0, hdc);
1771 }
1772 
1773 static void test_isvisiblepoint(void)
1774 {
1775     HDC hdc = GetDC(0);
1776     GpGraphics* graphics;
1777     GpRegion* region;
1778     GpPath* path;
1779     GpRectF rectf;
1780     GpStatus status;
1781     BOOL res;
1782     REAL x, y;
1783 
1784     status = GdipCreateFromHDC(hdc, &graphics);
1785     expect(Ok, status);
1786 
1787     status = GdipCreateRegion(&region);
1788     expect(Ok, status);
1789 
1790     /* null parameters */
1791     status = GdipIsVisibleRegionPoint(NULL, 0, 0, graphics, &res);
1792     expect(InvalidParameter, status);
1793     status = GdipIsVisibleRegionPointI(NULL, 0, 0, graphics, &res);
1794     expect(InvalidParameter, status);
1795 
1796     status = GdipIsVisibleRegionPoint(region, 0, 0, NULL, &res);
1797     expect(Ok, status);
1798     status = GdipIsVisibleRegionPointI(region, 0, 0, NULL, &res);
1799     expect(Ok, status);
1800 
1801     status = GdipIsVisibleRegionPoint(region, 0, 0, graphics, NULL);
1802     expect(InvalidParameter, status);
1803     status = GdipIsVisibleRegionPointI(region, 0, 0, graphics, NULL);
1804     expect(InvalidParameter, status);
1805 
1806     /* infinite region */
1807     status = GdipIsInfiniteRegion(region, graphics, &res);
1808     expect(Ok, status);
1809     ok(res == TRUE, "Region should be infinite\n");
1810 
1811     x = 10;
1812     y = 10;
1813     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1814     expect(Ok, status);
1815     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1816     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1817     expect(Ok, status);
1818     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1819 
1820     x = -10;
1821     y = -10;
1822     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1823     expect(Ok, status);
1824     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1825     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1826     expect(Ok, status);
1827     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1828 
1829     /* rectangular region */
1830     rectf.X = 10;
1831     rectf.Y = 20;
1832     rectf.Width = 30;
1833     rectf.Height = 40;
1834 
1835     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1836     expect(Ok, status);
1837 
1838     x = 0;
1839     y = 0;
1840     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1841     expect(Ok, status);
1842     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1843     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1844     expect(Ok, status);
1845     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1846 
1847     x = 9;
1848     y = 19;
1849     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1850     expect(Ok, status);
1851     ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1852 
1853     x = 9.25;
1854     y = 19.25;
1855     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1856     expect(Ok, status);
1857     ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1858 
1859     x = 9.5;
1860     y = 19.5;
1861     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1862     expect(Ok, status);
1863     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1864 
1865     x = 9.75;
1866     y = 19.75;
1867     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1868     expect(Ok, status);
1869     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1870 
1871     x = 10;
1872     y = 20;
1873     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1874     expect(Ok, status);
1875     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1876 
1877     x = 25;
1878     y = 40;
1879     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1880     expect(Ok, status);
1881     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1882     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1883     expect(Ok, status);
1884     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1885 
1886     x = 40;
1887     y = 60;
1888     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1889     expect(Ok, status);
1890     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1891     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1892     expect(Ok, status);
1893     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1894 
1895     /* translate into the center of the rectangle */
1896     status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1897     expect(Ok, status);
1898 
1899     /* native ignores the world transform, so treat these as if
1900      * no transform exists */
1901     x = -20;
1902     y = -30;
1903     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1904     expect(Ok, status);
1905     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1906     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1907     expect(Ok, status);
1908     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1909 
1910     x = 0;
1911     y = 0;
1912     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1913     expect(Ok, status);
1914     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1915     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1916     expect(Ok, status);
1917     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1918 
1919     x = 25;
1920     y = 40;
1921     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1922     expect(Ok, status);
1923     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1924     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1925     expect(Ok, status);
1926     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1927 
1928     /* translate back to origin */
1929     status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1930     expect(Ok, status);
1931 
1932     /* region from path */
1933     status = GdipCreatePath(FillModeAlternate, &path);
1934     expect(Ok, status);
1935 
1936     status = GdipAddPathEllipse(path, 10, 20, 30, 40);
1937     expect(Ok, status);
1938 
1939     status = GdipCombineRegionPath(region, path, CombineModeReplace);
1940     expect(Ok, status);
1941 
1942     x = 11;
1943     y = 21;
1944     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1945     expect(Ok, status);
1946     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1947     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1948     expect(Ok, status);
1949     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1950 
1951     x = 25;
1952     y = 40;
1953     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1954     expect(Ok, status);
1955     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1956     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1957     expect(Ok, status);
1958     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1959 
1960     x = 40;
1961     y = 60;
1962     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1963     expect(Ok, status);
1964     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1965     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1966     expect(Ok, status);
1967     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1968 
1969     GdipDeletePath(path);
1970 
1971     GdipDeleteRegion(region);
1972     GdipDeleteGraphics(graphics);
1973     ReleaseDC(0, hdc);
1974 }
1975 
1976 static void test_isvisiblerect(void)
1977 {
1978     HDC hdc = GetDC(0);
1979     GpGraphics* graphics;
1980     GpRegion* region;
1981     GpPath* path;
1982     GpRectF rectf;
1983     GpStatus status;
1984     BOOL res;
1985     REAL x, y, w, h;
1986 
1987     status = GdipCreateFromHDC(hdc, &graphics);
1988     expect(Ok, status);
1989 
1990     status = GdipCreateRegion(&region);
1991     expect(Ok, status);
1992 
1993     /* null parameters */
1994     status = GdipIsVisibleRegionRect(NULL, 0, 0, 0, 0, graphics, &res);
1995     expect(InvalidParameter, status);
1996     status = GdipIsVisibleRegionRectI(NULL, 0, 0, 0, 0, graphics, &res);
1997     expect(InvalidParameter, status);
1998 
1999     status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, NULL, &res);
2000     expect(Ok, status);
2001     status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, NULL, &res);
2002     expect(Ok, status);
2003 
2004     status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, graphics, NULL);
2005     expect(InvalidParameter, status);
2006     status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, graphics, NULL);
2007     expect(InvalidParameter, status);
2008 
2009     /* infinite region */
2010     status = GdipIsInfiniteRegion(region, graphics, &res);
2011     expect(Ok, status);
2012     ok(res == TRUE, "Region should be infinite\n");
2013 
2014     x = 10; w = 10;
2015     y = 10; h = 10;
2016     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2017     expect(Ok, status);
2018     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2019 
2020     x = -10; w = 5;
2021     y = -10; h = 5;
2022     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2023     expect(Ok, status);
2024     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2025 
2026     /* rectangular region */
2027     rectf.X = 10;
2028     rectf.Y = 20;
2029     rectf.Width = 30;
2030     rectf.Height = 40;
2031 
2032     status = GdipCombineRegionRect(region, &rectf, CombineModeIntersect);
2033     expect(Ok, status);
2034 
2035     /* entirely within the region */
2036     x = 11; w = 10;
2037     y = 12; h = 10;
2038     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2039     expect(Ok, status);
2040     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2041     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2042     expect(Ok, status);
2043     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2044 
2045     /* entirely outside of the region */
2046     x = 0; w = 5;
2047     y = 0; h = 5;
2048     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2049     expect(Ok, status);
2050     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2051     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2052     expect(Ok, status);
2053     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2054 
2055     /* corner cases */
2056     x = 0; w = 10;
2057     y = 0; h = 20;
2058     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2059     expect(Ok, status);
2060     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2061 
2062     x = 0; w = 10.25;
2063     y = 0; h = 20.25;
2064     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2065     expect(Ok, status);
2066     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2067 
2068     x = 39; w = 10;
2069     y = 59; h = 10;
2070     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2071     expect(Ok, status);
2072     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2073 
2074     x = 39.25; w = 10;
2075     y = 59.25; h = 10;
2076     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2077     expect(Ok, status);
2078     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2079 
2080     /* corners outside, but some intersection */
2081     x = 0; w = 100;
2082     y = 0; h = 100;
2083     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2084     expect(Ok, status);
2085     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2086 
2087     x = 0; w = 100;
2088     y = 0; h = 40;
2089     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2090     expect(Ok, status);
2091     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2092 
2093     x = 0; w = 25;
2094     y = 0; h = 100;
2095     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2096     expect(Ok, status);
2097     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2098 
2099     /* translate into the center of the rectangle */
2100     status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2101     expect(Ok, status);
2102 
2103     /* native ignores the world transform, so treat these as if
2104      * no transform exists */
2105     x = 0; w = 5;
2106     y = 0; h = 5;
2107     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2108     expect(Ok, status);
2109     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2110     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2111     expect(Ok, status);
2112     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2113 
2114     x = 11; w = 10;
2115     y = 12; h = 10;
2116     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2117     expect(Ok, status);
2118     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2119     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2120     expect(Ok, status);
2121     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2122 
2123     /* translate back to origin */
2124     status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2125     expect(Ok, status);
2126 
2127     /* region from path */
2128     status = GdipCreatePath(FillModeAlternate, &path);
2129     expect(Ok, status);
2130 
2131     status = GdipAddPathEllipse(path, 10, 20, 30, 40);
2132     expect(Ok, status);
2133 
2134     status = GdipCombineRegionPath(region, path, CombineModeReplace);
2135     expect(Ok, status);
2136 
2137     x = 0; w = 12;
2138     y = 0; h = 22;
2139     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2140     expect(Ok, status);
2141     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2142     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2143     expect(Ok, status);
2144     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2145 
2146     x = 0; w = 25;
2147     y = 0; h = 40;
2148     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2149     expect(Ok, status);
2150     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2151     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2152     expect(Ok, status);
2153     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2154 
2155     x = 38; w = 10;
2156     y = 55; h = 10;
2157     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2158     expect(Ok, status);
2159     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2160     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2161     expect(Ok, status);
2162     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2163 
2164     x = 0; w = 100;
2165     y = 0; h = 100;
2166     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2167     expect(Ok, status);
2168     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2169     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2170     expect(Ok, status);
2171     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2172 
2173     GdipDeletePath(path);
2174 
2175     GdipDeleteRegion(region);
2176     GdipDeleteGraphics(graphics);
2177     ReleaseDC(0, hdc);
2178 }
2179 
2180 static void test_excludeinfinite(void)
2181 {
2182     GpStatus status;
2183     GpRegion *region;
2184     UINT count=0xdeadbeef;
2185     GpRectF scans[4];
2186     GpMatrix *identity;
2187     static const RectF rect_exclude = {0.0, 0.0, 1.0, 1.0};
2188 
2189     status = GdipCreateMatrix(&identity);
2190     expect(Ok, status);
2191 
2192     status = GdipCreateRegion(&region);
2193     expect(Ok, status);
2194 
2195     status = GdipCombineRegionRect(region, &rect_exclude, CombineModeExclude);
2196     expect(Ok, status);
2197 
2198     status = GdipGetRegionScansCount(region, &count, identity);
2199     expect(Ok, status);
2200     expect(4, count);
2201 
2202     count = 4;
2203     status = GdipGetRegionScans(region, scans, (INT*)&count, identity);
2204     expect(Ok, status);
2205 
2206     expectf(-4194304.0, scans[0].X);
2207     expectf(-4194304.0, scans[0].Y);
2208     expectf(8388608.0, scans[0].Width);
2209     expectf(4194304.0, scans[0].Height);
2210 
2211     expectf(-4194304.0, scans[1].X);
2212     expectf(0.0, scans[1].Y);
2213     expectf(4194304.0, scans[1].Width);
2214     expectf(1.0, scans[1].Height);
2215 
2216     expectf(1.0, scans[2].X);
2217     expectf(0.0, scans[2].Y);
2218     expectf(4194303.0, scans[2].Width);
2219     expectf(1.0, scans[2].Height);
2220 
2221     expectf(-4194304.0, scans[3].X);
2222     expectf(1.0, scans[3].Y);
2223     expectf(8388608.0, scans[3].Width);
2224     expectf(4194303.0, scans[3].Height);
2225 
2226     GdipDeleteRegion(region);
2227     GdipDeleteMatrix(identity);
2228 }
2229 
2230 static void test_GdipCreateRegionRgnData(void)
2231 {
2232     GpGraphics *graphics = NULL;
2233     GpRegion *region, *region2;
2234     HDC hdc = GetDC(0);
2235     GpStatus status;
2236     BYTE buf[512];
2237     UINT needed;
2238     BOOL ret;
2239 
2240     status = GdipCreateRegionRgnData(NULL, 0, NULL);
2241     ok(status == InvalidParameter, "status %d\n", status);
2242 
2243     status = GdipCreateFromHDC(hdc, &graphics);
2244     ok(status == Ok, "status %d\n", status);
2245 
2246     status = GdipCreateRegion(&region);
2247     ok(status == Ok, "status %d\n", status);
2248 
2249     /* infinite region */
2250     memset(buf, 0xee, sizeof(buf));
2251     needed = 0;
2252     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
2253     ok(status == Ok, "status %d\n", status);
2254     expect(20, needed);
2255 
2256     status = GdipCreateRegionRgnData(buf, needed, NULL);
2257     ok(status == InvalidParameter, "status %d\n", status);
2258 
2259     status = GdipCreateRegionRgnData(buf, needed, &region2);
2260     ok(status == Ok, "status %d\n", status);
2261 
2262     ret = FALSE;
2263     status = GdipIsInfiniteRegion(region2, graphics, &ret);
2264     ok(status == Ok, "status %d\n", status);
2265     ok(ret, "got %d\n", ret);
2266     GdipDeleteRegion(region2);
2267 
2268     /* empty region */
2269     status = GdipSetEmpty(region);
2270     ok(status == Ok, "status %d\n", status);
2271 
2272     memset(buf, 0xee, sizeof(buf));
2273     needed = 0;
2274     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
2275     ok(status == Ok, "status %d\n", status);
2276     expect(20, needed);
2277 
2278     status = GdipCreateRegionRgnData(buf, needed, &region2);
2279     ok(status == Ok, "status %d\n", status);
2280 
2281     ret = FALSE;
2282     status = GdipIsEmptyRegion(region2, graphics, &ret);
2283     ok(status == Ok, "status %d\n", status);
2284     ok(ret, "got %d\n", ret);
2285     GdipDeleteRegion(region2);
2286 
2287     GdipDeleteGraphics(graphics);
2288     GdipDeleteRegion(region);
2289     ReleaseDC(0, hdc);
2290 }
2291 
2292 START_TEST(region)
2293 {
2294     struct GdiplusStartupInput gdiplusStartupInput;
2295     ULONG_PTR gdiplusToken;
2296     HMODULE hmsvcrt;
2297     int (CDECL * _controlfp_s)(unsigned int *cur, unsigned int newval, unsigned int mask);
2298 
2299     /* Enable all FP exceptions except _EM_INEXACT, which gdi32 can trigger */
2300     hmsvcrt = LoadLibraryA("msvcrt");
2301     _controlfp_s = (void*)GetProcAddress(hmsvcrt, "_controlfp_s");
2302     if (_controlfp_s) _controlfp_s(0, 0, 0x0008001e);
2303 
2304     gdiplusStartupInput.GdiplusVersion              = 1;
2305     gdiplusStartupInput.DebugEventCallback          = NULL;
2306     gdiplusStartupInput.SuppressBackgroundThread    = 0;
2307     gdiplusStartupInput.SuppressExternalCodecs      = 0;
2308 
2309     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2310 
2311     test_getregiondata();
2312     test_isinfinite();
2313     test_isempty();
2314     test_combinereplace();
2315     test_fromhrgn();
2316     test_gethrgn();
2317     test_isequal();
2318     test_translate();
2319     test_transform();
2320     test_scans();
2321     test_getbounds();
2322     test_isvisiblepoint();
2323     test_isvisiblerect();
2324     test_excludeinfinite();
2325     test_GdipCreateRegionRgnData();
2326 
2327     GdiplusShutdown(gdiplusToken);
2328 }
2329