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 DWORD get_region_type(GpRegion *region)
1445 {
1446     DWORD *data;
1447     DWORD size;
1448     DWORD result;
1449     DWORD status;
1450     status = GdipGetRegionDataSize(region, &size);
1451     expect(Ok, status);
1452     data = GdipAlloc(size);
1453     status = GdipGetRegionData(region, (BYTE*)data, size, NULL);
1454     ok(status == Ok || status == InsufficientBuffer, "unexpected status 0x%x\n", status);
1455     result = data[4];
1456     GdipFree(data);
1457     return result;
1458 }
1459 
1460 static void test_transform(void)
1461 {
1462     GpRegion *region, *region2;
1463     GpMatrix *matrix;
1464     GpGraphics *graphics;
1465     GpPath *path;
1466     GpRectF rectf;
1467     GpStatus status;
1468     HDC hdc = GetDC(0);
1469     BOOL res;
1470     DWORD type;
1471 
1472     status = GdipCreateFromHDC(hdc, &graphics);
1473     expect(Ok, status);
1474 
1475     status = GdipCreatePath(FillModeAlternate, &path);
1476     expect(Ok, status);
1477 
1478     status = GdipCreateRegion(&region);
1479     expect(Ok, status);
1480     status = GdipCreateRegion(&region2);
1481     expect(Ok, status);
1482 
1483     status = GdipCreateMatrix(&matrix);
1484     expect(Ok, status);
1485     status = GdipScaleMatrix(matrix, 2.0, 3.0, MatrixOrderAppend);
1486     expect(Ok, status);
1487 
1488     /* NULL */
1489     status = GdipTransformRegion(NULL, matrix);
1490     expect(InvalidParameter, status);
1491 
1492     status = GdipTransformRegion(region, NULL);
1493     expect(InvalidParameter, status);
1494 
1495     /* infinite */
1496     status = GdipTransformRegion(region, matrix);
1497     expect(Ok, status);
1498 
1499     res = FALSE;
1500     status = GdipIsEqualRegion(region, region2, graphics, &res);
1501     expect(Ok, status);
1502     ok(res, "Expected to be equal.\n");
1503     type = get_region_type(region);
1504     expect(0x10000003 /* RegionDataInfiniteRect */, type);
1505 
1506     /* empty */
1507     status = GdipSetEmpty(region);
1508     expect(Ok, status);
1509     status = GdipTransformRegion(region, matrix);
1510     expect(Ok, status);
1511 
1512     status = GdipSetEmpty(region2);
1513     expect(Ok, status);
1514 
1515     res = FALSE;
1516     status = GdipIsEqualRegion(region, region2, graphics, &res);
1517     expect(Ok, status);
1518     ok(res, "Expected to be equal.\n");
1519     type = get_region_type(region);
1520     expect(0x10000002 /* RegionDataEmptyRect */, type);
1521 
1522     /* rect */
1523     rectf.X = 10.0;
1524     rectf.Y = 0.0;
1525     rectf.Width = rectf.Height = 100.0;
1526     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1527     expect(Ok, status);
1528     rectf.X = 20.0;
1529     rectf.Y = 0.0;
1530     rectf.Width = 200.0;
1531     rectf.Height = 300.0;
1532     status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1533     expect(Ok, status);
1534     status = GdipTransformRegion(region, matrix);
1535     expect(Ok, status);
1536     res = FALSE;
1537     status = GdipIsEqualRegion(region, region2, graphics, &res);
1538     expect(Ok, status);
1539     ok(res, "Expected to be equal.\n");
1540     type = get_region_type(region);
1541     expect(0x10000000 /* RegionDataRect */, type);
1542 
1543     /* path */
1544     status = GdipAddPathEllipse(path, 0.0, 10.0, 100.0, 150.0);
1545     expect(Ok, status);
1546     status = GdipCombineRegionPath(region, path, CombineModeReplace);
1547     expect(Ok, status);
1548     status = GdipResetPath(path);
1549     expect(Ok, status);
1550     status = GdipAddPathEllipse(path, 0.0, 30.0, 200.0, 450.0);
1551     expect(Ok, status);
1552     status = GdipCombineRegionPath(region2, path, CombineModeReplace);
1553     expect(Ok, status);
1554     status = GdipTransformRegion(region, matrix);
1555     expect(Ok, status);
1556     res = FALSE;
1557     status = GdipIsEqualRegion(region, region2, graphics, &res);
1558     expect(Ok, status);
1559     ok(res, "Expected to be equal.\n");
1560     type = get_region_type(region);
1561     expect(0x10000001 /* RegionDataPath */, type);
1562 
1563     /* rotated rect -> path */
1564     rectf.X = 10.0;
1565     rectf.Y = 0.0;
1566     rectf.Width = rectf.Height = 100.0;
1567     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1568     expect(Ok, status);
1569     status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
1570     expect(Ok, status);
1571     status = GdipTransformRegion(region, matrix);
1572     expect(Ok, status);
1573     type = get_region_type(region);
1574     expect(0x10000001 /* RegionDataPath */, type);
1575 
1576     status = GdipDeleteRegion(region);
1577     expect(Ok, status);
1578     status = GdipDeleteRegion(region2);
1579     expect(Ok, status);
1580     status = GdipDeleteGraphics(graphics);
1581     expect(Ok, status);
1582     status = GdipDeletePath(path);
1583     expect(Ok, status);
1584     status = GdipDeleteMatrix(matrix);
1585     expect(Ok, status);
1586     ReleaseDC(0, hdc);
1587 }
1588 
1589 static void test_scans(void)
1590 {
1591     GpRegion *region;
1592     GpMatrix *matrix;
1593     GpRectF rectf;
1594     GpStatus status;
1595     ULONG count=80085;
1596     INT icount;
1597     GpRectF scans[2];
1598     GpRect scansi[2];
1599 
1600     status = GdipCreateRegion(&region);
1601     expect(Ok, status);
1602 
1603     status = GdipCreateMatrix(&matrix);
1604     expect(Ok, status);
1605 
1606     /* test NULL values */
1607     status = GdipGetRegionScansCount(NULL, &count, matrix);
1608     expect(InvalidParameter, status);
1609 
1610     status = GdipGetRegionScansCount(region, NULL, matrix);
1611     expect(InvalidParameter, status);
1612 
1613     status = GdipGetRegionScansCount(region, &count, NULL);
1614     expect(InvalidParameter, status);
1615 
1616     status = GdipGetRegionScans(NULL, scans, &icount, matrix);
1617     expect(InvalidParameter, status);
1618 
1619     status = GdipGetRegionScans(region, scans, NULL, matrix);
1620     expect(InvalidParameter, status);
1621 
1622     status = GdipGetRegionScans(region, scans, &icount, NULL);
1623     expect(InvalidParameter, status);
1624 
1625     /* infinite */
1626     status = GdipGetRegionScansCount(region, &count, matrix);
1627     expect(Ok, status);
1628     expect(1, count);
1629 
1630     status = GdipGetRegionScans(region, NULL, &icount, matrix);
1631     expect(Ok, status);
1632     expect(1, icount);
1633 
1634     status = GdipGetRegionScans(region, scans, &icount, matrix);
1635     expect(Ok, status);
1636     expect(1, icount);
1637 
1638     status = GdipGetRegionScansI(region, scansi, &icount, matrix);
1639     expect(Ok, status);
1640     expect(1, icount);
1641     expect(-0x400000, scansi[0].X);
1642     expect(-0x400000, scansi[0].Y);
1643     expect(0x800000, scansi[0].Width);
1644     expect(0x800000, scansi[0].Height);
1645 
1646     status = GdipGetRegionScans(region, scans, &icount, matrix);
1647     expect(Ok, status);
1648     expect(1, icount);
1649     expectf((double)-0x400000, scans[0].X);
1650     expectf((double)-0x400000, scans[0].Y);
1651     expectf((double)0x800000, scans[0].Width);
1652     expectf((double)0x800000, scans[0].Height);
1653 
1654     /* empty */
1655     status = GdipSetEmpty(region);
1656     expect(Ok, status);
1657 
1658     status = GdipGetRegionScansCount(region, &count, matrix);
1659     expect(Ok, status);
1660     expect(0, count);
1661 
1662     status = GdipGetRegionScans(region, scans, &icount, matrix);
1663     expect(Ok, status);
1664     expect(0, icount);
1665 
1666     /* single rectangle */
1667     rectf.X = rectf.Y = 0.0;
1668     rectf.Width = rectf.Height = 5.0;
1669     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1670     expect(Ok, status);
1671 
1672     status = GdipGetRegionScansCount(region, &count, matrix);
1673     expect(Ok, status);
1674     expect(1, count);
1675 
1676     status = GdipGetRegionScans(region, scans, &icount, matrix);
1677     expect(Ok, status);
1678     expect(1, icount);
1679     expectf(0.0, scans[0].X);
1680     expectf(0.0, scans[0].Y);
1681     expectf(5.0, scans[0].Width);
1682     expectf(5.0, scans[0].Height);
1683 
1684     /* two rectangles */
1685     rectf.X = rectf.Y = 5.0;
1686     rectf.Width = rectf.Height = 5.0;
1687     status = GdipCombineRegionRect(region, &rectf, CombineModeUnion);
1688     expect(Ok, status);
1689 
1690     status = GdipGetRegionScansCount(region, &count, matrix);
1691     expect(Ok, status);
1692     expect(2, count);
1693 
1694     /* Native ignores the initial value of count */
1695     scans[1].X = scans[1].Y = scans[1].Width = scans[1].Height = 8.0;
1696     icount = 1;
1697     status = GdipGetRegionScans(region, scans, &icount, matrix);
1698     expect(Ok, status);
1699     expect(2, icount);
1700     expectf(0.0, scans[0].X);
1701     expectf(0.0, scans[0].Y);
1702     expectf(5.0, scans[0].Width);
1703     expectf(5.0, scans[0].Height);
1704     expectf(5.0, scans[1].X);
1705     expectf(5.0, scans[1].Y);
1706     expectf(5.0, scans[1].Width);
1707     expectf(5.0, scans[1].Height);
1708 
1709     status = GdipGetRegionScansI(region, scansi, &icount, matrix);
1710     expect(Ok, status);
1711     expect(2, icount);
1712     expect(0, scansi[0].X);
1713     expect(0, scansi[0].Y);
1714     expect(5, scansi[0].Width);
1715     expect(5, scansi[0].Height);
1716     expect(5, scansi[1].X);
1717     expect(5, scansi[1].Y);
1718     expect(5, scansi[1].Width);
1719     expect(5, scansi[1].Height);
1720 
1721     status = GdipDeleteRegion(region);
1722     expect(Ok, status);
1723     status = GdipDeleteMatrix(matrix);
1724     expect(Ok, status);
1725 }
1726 
1727 static void test_getbounds(void)
1728 {
1729     GpRegion *region;
1730     GpGraphics *graphics;
1731     GpStatus status;
1732     GpRectF rectf;
1733     HDC hdc = GetDC(0);
1734 
1735     status = GdipCreateFromHDC(hdc, &graphics);
1736     ok(status == Ok, "status %08x\n", status);
1737     status = GdipCreateRegion(&region);
1738     ok(status == Ok, "status %08x\n", status);
1739 
1740     /* NULL */
1741     status = GdipGetRegionBounds(NULL, NULL, NULL);
1742     ok(status == InvalidParameter, "status %08x\n", status);
1743     status = GdipGetRegionBounds(region, NULL, NULL);
1744     ok(status == InvalidParameter, "status %08x\n", status);
1745     status = GdipGetRegionBounds(region, graphics, NULL);
1746     ok(status == InvalidParameter, "status %08x\n", status);
1747     /* infinite */
1748     rectf.X = rectf.Y = 0.0;
1749     rectf.Height = rectf.Width = 100.0;
1750     status = GdipGetRegionBounds(region, graphics, &rectf);
1751     ok(status == Ok, "status %08x\n", status);
1752     ok(rectf.X == -(REAL)(1 << 22), "Expected X = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.X);
1753     ok(rectf.Y == -(REAL)(1 << 22), "Expected Y = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.Y);
1754     ok(rectf.Width  == (REAL)(1 << 23), "Expected width = %.2f, got %.2f\n", (REAL)(1 << 23), rectf.Width);
1755     ok(rectf.Height == (REAL)(1 << 23), "Expected height = %.2f, got %.2f\n",(REAL)(1 << 23), rectf.Height);
1756     /* empty */
1757     rectf.X = rectf.Y = 0.0;
1758     rectf.Height = rectf.Width = 100.0;
1759     status = GdipSetEmpty(region);
1760     ok(status == Ok, "status %08x\n", status);
1761     status = GdipGetRegionBounds(region, graphics, &rectf);
1762     ok(status == Ok, "status %08x\n", status);
1763     ok(rectf.X == 0.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1764     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1765     ok(rectf.Width  == 0.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1766     ok(rectf.Height == 0.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1767     /* rect */
1768     rectf.X = 10.0; rectf.Y = 0.0;
1769     rectf.Width = rectf.Height = 100.0;
1770     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1771     ok(status == Ok, "status %08x\n", status);
1772     rectf.X = rectf.Y = 0.0;
1773     rectf.Height = rectf.Width = 0.0;
1774     status = GdipGetRegionBounds(region, graphics, &rectf);
1775     ok(status == Ok, "status %08x\n", status);
1776     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1777     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1778     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1779     ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1780 
1781     /* the world and page transforms are ignored */
1782     GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
1783     GdipSetPageUnit(graphics, UnitInch);
1784     GdipSetPageScale(graphics, 2.0);
1785     status = GdipGetRegionBounds(region, graphics, &rectf);
1786     ok(status == Ok, "status %08x\n", status);
1787     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1788     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1789     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1790 
1791     rectf.X = 10.0; rectf.Y = 0.0;
1792     rectf.Width = rectf.Height = 100.0;
1793     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1794     ok(status == Ok, "status %08x\n", status);
1795     rectf.X = rectf.Y = 0.0;
1796     rectf.Height = rectf.Width = 0.0;
1797     status = GdipGetRegionBounds(region, graphics, &rectf);
1798     ok(status == Ok, "status %08x\n", status);
1799     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1800     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1801     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1802     ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1803 
1804     status = GdipDeleteRegion(region);
1805     ok(status == Ok, "status %08x\n", status);
1806     status = GdipDeleteGraphics(graphics);
1807     ok(status == Ok, "status %08x\n", status);
1808     ReleaseDC(0, hdc);
1809 }
1810 
1811 static void test_isvisiblepoint(void)
1812 {
1813     HDC hdc = GetDC(0);
1814     GpGraphics* graphics;
1815     GpRegion* region;
1816     GpPath* path;
1817     GpRectF rectf;
1818     GpStatus status;
1819     BOOL res;
1820     REAL x, y;
1821 
1822     status = GdipCreateFromHDC(hdc, &graphics);
1823     expect(Ok, status);
1824 
1825     status = GdipCreateRegion(&region);
1826     expect(Ok, status);
1827 
1828     /* null parameters */
1829     status = GdipIsVisibleRegionPoint(NULL, 0, 0, graphics, &res);
1830     expect(InvalidParameter, status);
1831     status = GdipIsVisibleRegionPointI(NULL, 0, 0, graphics, &res);
1832     expect(InvalidParameter, status);
1833 
1834     status = GdipIsVisibleRegionPoint(region, 0, 0, NULL, &res);
1835     expect(Ok, status);
1836     status = GdipIsVisibleRegionPointI(region, 0, 0, NULL, &res);
1837     expect(Ok, status);
1838 
1839     status = GdipIsVisibleRegionPoint(region, 0, 0, graphics, NULL);
1840     expect(InvalidParameter, status);
1841     status = GdipIsVisibleRegionPointI(region, 0, 0, graphics, NULL);
1842     expect(InvalidParameter, status);
1843 
1844     /* infinite region */
1845     status = GdipIsInfiniteRegion(region, graphics, &res);
1846     expect(Ok, status);
1847     ok(res == TRUE, "Region should be infinite\n");
1848 
1849     x = 10;
1850     y = 10;
1851     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1852     expect(Ok, status);
1853     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1854     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1855     expect(Ok, status);
1856     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1857 
1858     x = -10;
1859     y = -10;
1860     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1861     expect(Ok, status);
1862     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1863     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1864     expect(Ok, status);
1865     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1866 
1867     /* rectangular region */
1868     rectf.X = 10;
1869     rectf.Y = 20;
1870     rectf.Width = 30;
1871     rectf.Height = 40;
1872 
1873     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1874     expect(Ok, status);
1875 
1876     x = 0;
1877     y = 0;
1878     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1879     expect(Ok, status);
1880     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1881     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1882     expect(Ok, status);
1883     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1884 
1885     x = 9;
1886     y = 19;
1887     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1888     expect(Ok, status);
1889     ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1890 
1891     x = 9.25;
1892     y = 19.25;
1893     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1894     expect(Ok, status);
1895     ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1896 
1897     x = 9.5;
1898     y = 19.5;
1899     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1900     expect(Ok, status);
1901     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1902 
1903     x = 9.75;
1904     y = 19.75;
1905     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1906     expect(Ok, status);
1907     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1908 
1909     x = 10;
1910     y = 20;
1911     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1912     expect(Ok, status);
1913     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1914 
1915     x = 25;
1916     y = 40;
1917     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1918     expect(Ok, status);
1919     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1920     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1921     expect(Ok, status);
1922     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1923 
1924     x = 40;
1925     y = 60;
1926     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1927     expect(Ok, status);
1928     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1929     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1930     expect(Ok, status);
1931     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1932 
1933     /* translate into the center of the rectangle */
1934     status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1935     expect(Ok, status);
1936 
1937     /* native ignores the world transform, so treat these as if
1938      * no transform exists */
1939     x = -20;
1940     y = -30;
1941     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1942     expect(Ok, status);
1943     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1944     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1945     expect(Ok, status);
1946     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1947 
1948     x = 0;
1949     y = 0;
1950     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1951     expect(Ok, status);
1952     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1953     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1954     expect(Ok, status);
1955     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1956 
1957     x = 25;
1958     y = 40;
1959     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1960     expect(Ok, status);
1961     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1962     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1963     expect(Ok, status);
1964     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1965 
1966     /* translate back to origin */
1967     status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1968     expect(Ok, status);
1969 
1970     /* region from path */
1971     status = GdipCreatePath(FillModeAlternate, &path);
1972     expect(Ok, status);
1973 
1974     status = GdipAddPathEllipse(path, 10, 20, 30, 40);
1975     expect(Ok, status);
1976 
1977     status = GdipCombineRegionPath(region, path, CombineModeReplace);
1978     expect(Ok, status);
1979 
1980     x = 11;
1981     y = 21;
1982     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1983     expect(Ok, status);
1984     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1985     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1986     expect(Ok, status);
1987     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1988 
1989     x = 25;
1990     y = 40;
1991     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1992     expect(Ok, status);
1993     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1994     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1995     expect(Ok, status);
1996     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1997 
1998     x = 40;
1999     y = 60;
2000     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
2001     expect(Ok, status);
2002     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2003     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
2004     expect(Ok, status);
2005     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
2006 
2007     GdipDeletePath(path);
2008 
2009     GdipDeleteRegion(region);
2010     GdipDeleteGraphics(graphics);
2011     ReleaseDC(0, hdc);
2012 }
2013 
2014 static void test_isvisiblerect(void)
2015 {
2016     HDC hdc = GetDC(0);
2017     GpGraphics* graphics;
2018     GpRegion* region;
2019     GpPath* path;
2020     GpRectF rectf;
2021     GpStatus status;
2022     BOOL res;
2023     REAL x, y, w, h;
2024 
2025     status = GdipCreateFromHDC(hdc, &graphics);
2026     expect(Ok, status);
2027 
2028     status = GdipCreateRegion(&region);
2029     expect(Ok, status);
2030 
2031     /* null parameters */
2032     status = GdipIsVisibleRegionRect(NULL, 0, 0, 0, 0, graphics, &res);
2033     expect(InvalidParameter, status);
2034     status = GdipIsVisibleRegionRectI(NULL, 0, 0, 0, 0, graphics, &res);
2035     expect(InvalidParameter, status);
2036 
2037     status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, NULL, &res);
2038     expect(Ok, status);
2039     status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, NULL, &res);
2040     expect(Ok, status);
2041 
2042     status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, graphics, NULL);
2043     expect(InvalidParameter, status);
2044     status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, graphics, NULL);
2045     expect(InvalidParameter, status);
2046 
2047     /* infinite region */
2048     status = GdipIsInfiniteRegion(region, graphics, &res);
2049     expect(Ok, status);
2050     ok(res == TRUE, "Region should be infinite\n");
2051 
2052     x = 10; w = 10;
2053     y = 10; h = 10;
2054     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2055     expect(Ok, status);
2056     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2057 
2058     x = -10; w = 5;
2059     y = -10; h = 5;
2060     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2061     expect(Ok, status);
2062     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2063 
2064     /* rectangular region */
2065     rectf.X = 10;
2066     rectf.Y = 20;
2067     rectf.Width = 30;
2068     rectf.Height = 40;
2069 
2070     status = GdipCombineRegionRect(region, &rectf, CombineModeIntersect);
2071     expect(Ok, status);
2072 
2073     /* entirely within the region */
2074     x = 11; w = 10;
2075     y = 12; h = 10;
2076     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2077     expect(Ok, status);
2078     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2079     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2080     expect(Ok, status);
2081     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2082 
2083     /* entirely outside of the region */
2084     x = 0; w = 5;
2085     y = 0; h = 5;
2086     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2087     expect(Ok, status);
2088     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2089     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2090     expect(Ok, status);
2091     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2092 
2093     /* corner cases */
2094     x = 0; w = 10;
2095     y = 0; h = 20;
2096     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2097     expect(Ok, status);
2098     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2099 
2100     x = 0; w = 10.25;
2101     y = 0; h = 20.25;
2102     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2103     expect(Ok, status);
2104     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2105 
2106     x = 39; w = 10;
2107     y = 59; h = 10;
2108     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2109     expect(Ok, status);
2110     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2111 
2112     x = 39.25; w = 10;
2113     y = 59.25; h = 10;
2114     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2115     expect(Ok, status);
2116     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2117 
2118     /* corners outside, but some intersection */
2119     x = 0; w = 100;
2120     y = 0; h = 100;
2121     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2122     expect(Ok, status);
2123     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2124 
2125     x = 0; w = 100;
2126     y = 0; h = 40;
2127     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2128     expect(Ok, status);
2129     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2130 
2131     x = 0; w = 25;
2132     y = 0; h = 100;
2133     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2134     expect(Ok, status);
2135     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2136 
2137     /* translate into the center of the rectangle */
2138     status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2139     expect(Ok, status);
2140 
2141     /* native ignores the world transform, so treat these as if
2142      * no transform exists */
2143     x = 0; w = 5;
2144     y = 0; h = 5;
2145     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2146     expect(Ok, status);
2147     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2148     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2149     expect(Ok, status);
2150     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2151 
2152     x = 11; w = 10;
2153     y = 12; h = 10;
2154     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2155     expect(Ok, status);
2156     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2157     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2158     expect(Ok, status);
2159     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2160 
2161     /* translate back to origin */
2162     status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2163     expect(Ok, status);
2164 
2165     /* region from path */
2166     status = GdipCreatePath(FillModeAlternate, &path);
2167     expect(Ok, status);
2168 
2169     status = GdipAddPathEllipse(path, 10, 20, 30, 40);
2170     expect(Ok, status);
2171 
2172     status = GdipCombineRegionPath(region, path, CombineModeReplace);
2173     expect(Ok, status);
2174 
2175     x = 0; w = 12;
2176     y = 0; h = 22;
2177     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2178     expect(Ok, status);
2179     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2180     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2181     expect(Ok, status);
2182     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2183 
2184     x = 0; w = 25;
2185     y = 0; h = 40;
2186     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2187     expect(Ok, status);
2188     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2189     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2190     expect(Ok, status);
2191     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2192 
2193     x = 38; w = 10;
2194     y = 55; h = 10;
2195     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2196     expect(Ok, status);
2197     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
2198     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2199     expect(Ok, status);
2200     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2201 
2202     x = 0; w = 100;
2203     y = 0; h = 100;
2204     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
2205     expect(Ok, status);
2206     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
2207     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
2208     expect(Ok, status);
2209     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
2210 
2211     GdipDeletePath(path);
2212 
2213     GdipDeleteRegion(region);
2214     GdipDeleteGraphics(graphics);
2215     ReleaseDC(0, hdc);
2216 }
2217 
2218 static void test_excludeinfinite(void)
2219 {
2220     GpStatus status;
2221     GpRegion *region;
2222     UINT count=0xdeadbeef;
2223     GpRectF scans[4];
2224     GpMatrix *identity;
2225     static const RectF rect_exclude = {0.0, 0.0, 1.0, 1.0};
2226 
2227     status = GdipCreateMatrix(&identity);
2228     expect(Ok, status);
2229 
2230     status = GdipCreateRegion(&region);
2231     expect(Ok, status);
2232 
2233     status = GdipCombineRegionRect(region, &rect_exclude, CombineModeExclude);
2234     expect(Ok, status);
2235 
2236     status = GdipGetRegionScansCount(region, &count, identity);
2237     expect(Ok, status);
2238     expect(4, count);
2239 
2240     count = 4;
2241     status = GdipGetRegionScans(region, scans, (INT*)&count, identity);
2242     expect(Ok, status);
2243 
2244     expectf(-4194304.0, scans[0].X);
2245     expectf(-4194304.0, scans[0].Y);
2246     expectf(8388608.0, scans[0].Width);
2247     expectf(4194304.0, scans[0].Height);
2248 
2249     expectf(-4194304.0, scans[1].X);
2250     expectf(0.0, scans[1].Y);
2251     expectf(4194304.0, scans[1].Width);
2252     expectf(1.0, scans[1].Height);
2253 
2254     expectf(1.0, scans[2].X);
2255     expectf(0.0, scans[2].Y);
2256     expectf(4194303.0, scans[2].Width);
2257     expectf(1.0, scans[2].Height);
2258 
2259     expectf(-4194304.0, scans[3].X);
2260     expectf(1.0, scans[3].Y);
2261     expectf(8388608.0, scans[3].Width);
2262     expectf(4194303.0, scans[3].Height);
2263 
2264     GdipDeleteRegion(region);
2265     GdipDeleteMatrix(identity);
2266 }
2267 
2268 static void test_GdipCreateRegionRgnData(void)
2269 {
2270     GpGraphics *graphics = NULL;
2271     GpRegion *region, *region2;
2272     HDC hdc = GetDC(0);
2273     GpStatus status;
2274     BYTE buf[512];
2275     UINT needed;
2276     BOOL ret;
2277 
2278     status = GdipCreateRegionRgnData(NULL, 0, NULL);
2279     ok(status == InvalidParameter, "status %d\n", status);
2280 
2281     status = GdipCreateFromHDC(hdc, &graphics);
2282     ok(status == Ok, "status %d\n", status);
2283 
2284     status = GdipCreateRegion(&region);
2285     ok(status == Ok, "status %d\n", status);
2286 
2287     /* infinite region */
2288     memset(buf, 0xee, sizeof(buf));
2289     needed = 0;
2290     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
2291     ok(status == Ok, "status %d\n", status);
2292     expect(20, needed);
2293 
2294     status = GdipCreateRegionRgnData(buf, needed, NULL);
2295     ok(status == InvalidParameter, "status %d\n", status);
2296 
2297     status = GdipCreateRegionRgnData(buf, needed, &region2);
2298     ok(status == Ok, "status %d\n", status);
2299 
2300     ret = FALSE;
2301     status = GdipIsInfiniteRegion(region2, graphics, &ret);
2302     ok(status == Ok, "status %d\n", status);
2303     ok(ret, "got %d\n", ret);
2304     GdipDeleteRegion(region2);
2305 
2306     /* empty region */
2307     status = GdipSetEmpty(region);
2308     ok(status == Ok, "status %d\n", status);
2309 
2310     memset(buf, 0xee, sizeof(buf));
2311     needed = 0;
2312     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
2313     ok(status == Ok, "status %d\n", status);
2314     expect(20, needed);
2315 
2316     status = GdipCreateRegionRgnData(buf, needed, &region2);
2317     ok(status == Ok, "status %d\n", status);
2318 
2319     ret = FALSE;
2320     status = GdipIsEmptyRegion(region2, graphics, &ret);
2321     ok(status == Ok, "status %d\n", status);
2322     ok(ret, "got %d\n", ret);
2323     GdipDeleteRegion(region2);
2324 
2325     GdipDeleteGraphics(graphics);
2326     GdipDeleteRegion(region);
2327     ReleaseDC(0, hdc);
2328 }
2329 
2330 START_TEST(region)
2331 {
2332     struct GdiplusStartupInput gdiplusStartupInput;
2333     ULONG_PTR gdiplusToken;
2334     HMODULE hmsvcrt;
2335     int (CDECL * _controlfp_s)(unsigned int *cur, unsigned int newval, unsigned int mask);
2336 
2337     /* Enable all FP exceptions except _EM_INEXACT, which gdi32 can trigger */
2338     hmsvcrt = LoadLibraryA("msvcrt");
2339     _controlfp_s = (void*)GetProcAddress(hmsvcrt, "_controlfp_s");
2340     if (_controlfp_s) _controlfp_s(0, 0, 0x0008001e);
2341 
2342     gdiplusStartupInput.GdiplusVersion              = 1;
2343     gdiplusStartupInput.DebugEventCallback          = NULL;
2344     gdiplusStartupInput.SuppressBackgroundThread    = 0;
2345     gdiplusStartupInput.SuppressExternalCodecs      = 0;
2346 
2347     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2348 
2349     test_getregiondata();
2350     test_isinfinite();
2351     test_isempty();
2352     test_combinereplace();
2353     test_fromhrgn();
2354     test_gethrgn();
2355     test_isequal();
2356     test_translate();
2357     test_transform();
2358     test_scans();
2359     test_getbounds();
2360     test_isvisiblepoint();
2361     test_isvisiblerect();
2362     test_excludeinfinite();
2363     test_GdipCreateRegionRgnData();
2364 
2365     GdiplusShutdown(gdiplusToken);
2366 }
2367