gdiplus: Implement GdipTransformRegion.
[wine] / dlls / gdiplus / tests / region.c
1 /*
2  * Unit test suite for gdiplus regions
3  *
4  * Copyright (C) 2008 Huw Davies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wingdi.h"
24 #include "wine/test.h"
25
26 #define RGNDATA_RECT            0x10000000
27 #define RGNDATA_PATH            0x10000001
28 #define RGNDATA_EMPTY_RECT      0x10000002
29 #define RGNDATA_INFINITE_RECT   0x10000003
30
31 #define RGNDATA_MAGIC           0xdbc01001
32 #define RGNDATA_MAGIC2          0xdbc01002
33
34 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
35
36 #define expect_magic(value) ok(*value == RGNDATA_MAGIC || *value == RGNDATA_MAGIC2, "Expected a known magic value, got %8x\n", *value)
37
38 #define expect_dword(value, expected) ok(*(value) == expected, "expected %08x got %08x\n", expected, *(value))
39
40 static inline void expect_float(DWORD *value, FLOAT expected)
41 {
42     FLOAT valuef = *(FLOAT*)value;
43     ok(valuef == expected, "expected %f got %f\n", expected, valuef);
44 }
45
46 /* We get shorts back, not INTs like a GpPoint */
47 typedef struct RegionDataPoint
48 {
49     short X, Y;
50 } RegionDataPoint;
51
52 static void verify_region(HRGN hrgn, const RECT *rc)
53 {
54     union
55     {
56         RGNDATA data;
57         char buf[sizeof(RGNDATAHEADER) + sizeof(RECT)];
58     } rgn;
59     const RECT *rect;
60     DWORD ret;
61
62     ret = GetRegionData(hrgn, 0, NULL);
63     if (IsRectEmpty(rc))
64         ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
65     else
66         ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
67
68     if (!ret) return;
69
70     ret = GetRegionData(hrgn, sizeof(rgn), &rgn.data);
71     if (IsRectEmpty(rc))
72         ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
73     else
74         ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
75
76     trace("size %u, type %u, count %u, rgn size %u, bound (%d,%d-%d,%d)\n",
77           rgn.data.rdh.dwSize, rgn.data.rdh.iType,
78           rgn.data.rdh.nCount, rgn.data.rdh.nRgnSize,
79           rgn.data.rdh.rcBound.left, rgn.data.rdh.rcBound.top,
80           rgn.data.rdh.rcBound.right, rgn.data.rdh.rcBound.bottom);
81     if (rgn.data.rdh.nCount != 0)
82     {
83         rect = (const RECT *)rgn.data.Buffer;
84         trace("rect (%d,%d-%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom);
85         ok(EqualRect(rect, rc), "rects don't match\n");
86     }
87
88     ok(rgn.data.rdh.dwSize == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", rgn.data.rdh.dwSize);
89     ok(rgn.data.rdh.iType == RDH_RECTANGLES, "expected RDH_RECTANGLES, got %u\n", rgn.data.rdh.iType);
90     if (IsRectEmpty(rc))
91     {
92         ok(rgn.data.rdh.nCount == 0, "expected 0, got %u\n", rgn.data.rdh.nCount);
93         ok(rgn.data.rdh.nRgnSize == 0,  "expected 0, got %u\n", rgn.data.rdh.nRgnSize);
94     }
95     else
96     {
97         ok(rgn.data.rdh.nCount == 1, "expected 1, got %u\n", rgn.data.rdh.nCount);
98         ok(rgn.data.rdh.nRgnSize == sizeof(RECT),  "expected sizeof(RECT), got %u\n", rgn.data.rdh.nRgnSize);
99     }
100     ok(EqualRect(&rgn.data.rdh.rcBound, rc), "rects don't match\n");
101 }
102
103 static void test_getregiondata(void)
104 {
105     GpStatus status;
106     GpRegion *region, *region2;
107     RegionDataPoint *point;
108     UINT needed;
109     DWORD buf[100];
110     GpRect rect;
111     GpPath *path;
112
113     memset(buf, 0xee, sizeof(buf));
114
115     status = GdipCreateRegion(&region);
116     ok(status == Ok, "status %08x\n", status);
117
118     status = GdipGetRegionDataSize(region, &needed);
119     ok(status == Ok, "status %08x\n", status);
120     expect(20, needed);
121     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
122     ok(status == Ok, "status %08x\n", status);
123     expect(20, needed);
124     expect_dword(buf, 12);
125     trace("buf[1] = %08x\n", buf[1]);
126     expect_magic((DWORD*)(buf + 2));
127     expect_dword(buf + 3, 0);
128     expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
129
130     status = GdipSetEmpty(region);
131     ok(status == Ok, "status %08x\n", status);
132     status = GdipGetRegionDataSize(region, &needed);
133     ok(status == Ok, "status %08x\n", status);
134     expect(20, needed);
135     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
136     ok(status == Ok, "status %08x\n", status);
137     expect(20, needed);
138     expect_dword(buf, 12);
139     trace("buf[1] = %08x\n", buf[1]);
140     expect_magic((DWORD*)(buf + 2));
141     expect_dword(buf + 3, 0);
142     expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
143
144     status = GdipSetInfinite(region);
145     ok(status == Ok, "status %08x\n", status);
146     status = GdipGetRegionDataSize(region, &needed);
147     ok(status == Ok, "status %08x\n", status);
148     expect(20, needed);
149     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
150     ok(status == Ok, "status %08x\n", status);
151     expect(20, needed);
152     expect_dword(buf, 12);
153     trace("buf[1] = %08x\n", buf[1]);
154     expect_magic((DWORD*)(buf + 2));
155     expect_dword(buf + 3, 0);
156     expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
157
158     status = GdipDeleteRegion(region);
159     ok(status == Ok, "status %08x\n", status);
160
161     rect.X = 10;
162     rect.Y = 20;
163     rect.Width = 100;
164     rect.Height = 200;
165     status = GdipCreateRegionRectI(&rect, &region);
166     ok(status == Ok, "status %08x\n", status);
167     status = GdipGetRegionDataSize(region, &needed);
168     ok(status == Ok, "status %08x\n", status);
169     expect(36, needed);
170     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
171     ok(status == Ok, "status %08x\n", status);
172     expect(36, needed);
173     expect_dword(buf, 28);
174     trace("buf[1] = %08x\n", buf[1]);
175     expect_magic((DWORD*)(buf + 2));
176     expect_dword(buf + 3, 0);
177     expect_dword(buf + 4, RGNDATA_RECT);
178     expect_float(buf + 5, 10.0);
179     expect_float(buf + 6, 20.0);
180     expect_float(buf + 7, 100.0);
181     expect_float(buf + 8, 200.0);
182
183     rect.X = 50;
184     rect.Y = 30;
185     rect.Width = 10;
186     rect.Height = 20;
187     status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
188     ok(status == Ok, "status %08x\n", status);
189     rect.X = 100;
190     rect.Y = 300;
191     rect.Width = 30;
192     rect.Height = 50;
193     status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
194     ok(status == Ok, "status %08x\n", status);
195
196     rect.X = 200;
197     rect.Y = 100;
198     rect.Width = 133;
199     rect.Height = 266;
200     status = GdipCreateRegionRectI(&rect, &region2);
201     ok(status == Ok, "status %08x\n", status);
202     rect.X = 20;
203     rect.Y = 10;
204     rect.Width = 40;
205     rect.Height = 66;
206     status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
207     ok(status == Ok, "status %08x\n", status);
208
209     status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
210     ok(status == Ok, "status %08x\n", status);
211
212     rect.X = 400;
213     rect.Y = 500;
214     rect.Width = 22;
215     rect.Height = 55;
216     status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
217     ok(status == Ok, "status %08x\n", status);
218
219     status = GdipGetRegionDataSize(region, &needed);
220     ok(status == Ok, "status %08x\n", status);
221     expect(156, needed);
222     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
223     ok(status == Ok, "status %08x\n", status);
224     expect(156, needed);
225     expect_dword(buf, 148);
226     trace("buf[1] = %08x\n", buf[1]);
227     expect_magic((DWORD*)(buf + 2));
228     expect_dword(buf + 3, 10);
229     expect_dword(buf + 4, CombineModeExclude);
230     expect_dword(buf + 5, CombineModeComplement);
231     expect_dword(buf + 6, CombineModeXor);
232     expect_dword(buf + 7, CombineModeIntersect);
233     expect_dword(buf + 8, RGNDATA_RECT);
234     expect_float(buf + 9, 10.0);
235     expect_float(buf + 10, 20.0);
236     expect_float(buf + 11, 100.0);
237     expect_float(buf + 12, 200.0);
238     expect_dword(buf + 13, RGNDATA_RECT);
239     expect_float(buf + 14, 50.0);
240     expect_float(buf + 15, 30.0);
241     expect_float(buf + 16, 10.0);
242     expect_float(buf + 17, 20.0);
243     expect_dword(buf + 18, RGNDATA_RECT);
244     expect_float(buf + 19, 100.0);
245     expect_float(buf + 20, 300.0);
246     expect_float(buf + 21, 30.0);
247     expect_float(buf + 22, 50.0);
248     expect_dword(buf + 23, CombineModeUnion);
249     expect_dword(buf + 24, RGNDATA_RECT);
250     expect_float(buf + 25, 200.0);
251     expect_float(buf + 26, 100.0);
252     expect_float(buf + 27, 133.0);
253     expect_float(buf + 28, 266.0);
254     expect_dword(buf + 29, RGNDATA_RECT);
255     expect_float(buf + 30, 20.0);
256     expect_float(buf + 31, 10.0);
257     expect_float(buf + 32, 40.0);
258     expect_float(buf + 33, 66.0);
259     expect_dword(buf + 34, RGNDATA_RECT);
260     expect_float(buf + 35, 400.0);
261     expect_float(buf + 36, 500.0);
262     expect_float(buf + 37, 22.0);
263     expect_float(buf + 38, 55.0);
264
265     status = GdipDeleteRegion(region2);
266     ok(status == Ok, "status %08x\n", status);
267     status = GdipDeleteRegion(region);
268     ok(status == Ok, "status %08x\n", status);
269
270     /* Try some paths */
271
272     status = GdipCreatePath(FillModeAlternate, &path);
273     ok(status == Ok, "status %08x\n", status);
274     GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
275
276     status = GdipCreateRegionPath(path, &region);
277     ok(status == Ok, "status %08x\n", status);
278     status = GdipGetRegionDataSize(region, &needed);
279     ok(status == Ok, "status %08x\n", status);
280     expect(72, needed);
281     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
282     ok(status == Ok, "status %08x\n", status);
283     expect(72, needed);
284     expect_dword(buf, 64);
285     trace("buf[1] = %08x\n", buf[1]);
286     expect_magic((DWORD*)(buf + 2));
287     expect_dword(buf + 3, 0);
288     expect_dword(buf + 4, RGNDATA_PATH);
289     expect_dword(buf + 5, 0x00000030);
290     expect_magic((DWORD*)(buf + 6));
291     expect_dword(buf + 7, 0x00000004);
292     expect_dword(buf + 8, 0x00000000);
293     expect_float(buf + 9, 12.5);
294     expect_float(buf + 10, 13.0);
295     expect_float(buf + 11, 26.5);
296     expect_float(buf + 12, 13.0);
297     expect_float(buf + 13, 26.5);
298     expect_float(buf + 14, 28.0);
299     expect_float(buf + 15, 12.5);
300     expect_float(buf + 16, 28.0);
301     expect_dword(buf + 17, 0x81010100);
302
303
304     rect.X = 50;
305     rect.Y = 30;
306     rect.Width = 10;
307     rect.Height = 20;
308     status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
309     ok(status == Ok, "status %08x\n", status);
310     status = GdipGetRegionDataSize(region, &needed);
311     ok(status == Ok, "status %08x\n", status);
312     expect(96, needed);
313     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
314     ok(status == Ok, "status %08x\n", status);
315     expect(96, needed);
316     expect_dword(buf, 88);
317     trace("buf[1] = %08x\n", buf[1]);
318     expect_magic((DWORD*)(buf + 2));
319     expect_dword(buf + 3, 2);
320     expect_dword(buf + 4, CombineModeIntersect);
321     expect_dword(buf + 5, RGNDATA_PATH);
322     expect_dword(buf + 6, 0x00000030);
323     expect_magic((DWORD*)(buf + 7));
324     expect_dword(buf + 8, 0x00000004);
325     expect_dword(buf + 9, 0x00000000);
326     expect_float(buf + 10, 12.5);
327     expect_float(buf + 11, 13.0);
328     expect_float(buf + 12, 26.5);
329     expect_float(buf + 13, 13.0);
330     expect_float(buf + 14, 26.5);
331     expect_float(buf + 15, 28.0);
332     expect_float(buf + 16, 12.5);
333     expect_float(buf + 17, 28.0);
334     expect_dword(buf + 18, 0x81010100);
335     expect_dword(buf + 19, RGNDATA_RECT);
336     expect_float(buf + 20, 50.0);
337     expect_float(buf + 21, 30.0);
338     expect_float(buf + 22, 10.0);
339     expect_float(buf + 23, 20.0);
340
341     status = GdipDeleteRegion(region);
342     ok(status == Ok, "status %08x\n", status);
343     status = GdipDeletePath(path);
344     ok(status == Ok, "status %08x\n", status);
345
346     /* Test an empty path */
347     status = GdipCreatePath(FillModeAlternate, &path);
348     expect(Ok, status);
349     status = GdipCreateRegionPath(path, &region);
350     expect(Ok, status);
351     status = GdipGetRegionDataSize(region, &needed);
352     expect(Ok, status);
353     expect(36, needed);
354     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
355     expect(Ok, status);
356     expect(36, needed);
357     expect_dword(buf, 28);
358     trace("buf[1] = %08x\n", buf[1]);
359     expect_magic((DWORD*)(buf + 2));
360     expect_dword(buf + 3, 0);
361     expect_dword(buf + 4, RGNDATA_PATH);
362
363     /* Second signature for pathdata */
364     expect_dword(buf + 5, 12);
365     expect_magic((DWORD*)(buf + 6));
366     expect_dword(buf + 7, 0);
367     /* flags 0x4000 means its a path of shorts instead of FLOAT */
368     ok((*(buf + 8) & (~ 0x00004000)) == 0x00000000,
369        "expected 00000000 got %08x\n", *(buf + 8) & (~ 0x00004000));
370
371     status = GdipDeleteRegion(region);
372     expect(Ok, status);
373
374     /* Test a simple triangle of INTs */
375     status = GdipAddPathLine(path, 5, 6, 7, 8);
376     expect(Ok, status);
377     status = GdipAddPathLine(path, 8, 1, 5, 6);
378     expect(Ok, status);
379     status = GdipClosePathFigure(path);
380     expect(Ok, status);
381     status = GdipCreateRegionPath(path, &region);
382     expect(Ok, status);
383     status = GdipGetRegionDataSize(region, &needed);
384     expect(Ok, status);
385     expect(56, needed);
386     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
387     expect(Ok, status);
388     expect(56, needed);
389     expect_dword(buf, 48);
390     trace("buf[1] = %08x\n", buf[1]);
391     expect_magic((DWORD*)(buf + 2));
392     expect_dword(buf + 3 , 0);
393     expect_dword(buf + 4 , RGNDATA_PATH);
394
395     expect_dword(buf + 5, 32);
396     expect_magic((DWORD*)(buf + 6));
397     expect_dword(buf + 7, 4);
398     expect_dword(buf + 8, 0x00004000); /* ?? */
399
400     point = (RegionDataPoint*)buf + 9;
401     expect(5, point[0].X);
402     expect(6, point[0].Y);
403     expect(7, point[1].X); /* buf + 10 */
404     expect(8, point[1].Y);
405     expect(8, point[2].X); /* buf + 11 */
406     expect(1, point[2].Y);
407     expect(5, point[3].X); /* buf + 12 */
408     expect(6, point[3].Y);
409     expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
410
411     status = GdipDeletePath(path);
412     expect(Ok, status);
413     status = GdipDeleteRegion(region);
414     expect(Ok, status);
415
416     /* Test a floating-point triangle */
417     status = GdipCreatePath(FillModeAlternate, &path);
418     expect(Ok, status);
419     status = GdipAddPathLine(path, 5.6, 6.2, 7.2, 8.9);
420     expect(Ok, status);
421     status = GdipAddPathLine(path, 8.1, 1.6, 5.6, 6.2);
422     expect(Ok, status);
423     status = GdipCreateRegionPath(path, &region);
424     expect(Ok, status);
425     status = GdipGetRegionDataSize(region, &needed);
426     expect(Ok, status);
427     expect(72, needed);
428     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
429     expect(Ok, status);
430     expect(72, needed);
431     expect_dword(buf, 64);
432     trace("buf[1] = %08x\n", buf[1]);
433     expect_magic((DWORD*)(buf + 2));
434     expect_dword(buf + 3, 0);
435     expect_dword(buf + 4, RGNDATA_PATH);
436
437     expect_dword(buf + 5, 48);
438     expect_magic((DWORD*)(buf + 6));
439     expect_dword(buf + 7, 4);
440     expect_dword(buf + 8, 0);
441     expect_float(buf + 9, 5.6);
442     expect_float(buf + 10, 6.2);
443     expect_float(buf + 11, 7.2);
444     expect_float(buf + 12, 8.9);
445     expect_float(buf + 13, 8.1);
446     expect_float(buf + 14, 1.6);
447     expect_float(buf + 15, 5.6);
448     expect_float(buf + 16, 6.2);
449
450     status = GdipDeletePath(path);
451     expect(Ok, status);
452     status = GdipDeleteRegion(region);
453     expect(Ok, status);
454
455     /* Test for a path with > 4 points, and CombineRegionPath */
456     GdipCreatePath(FillModeAlternate, &path);
457     status = GdipAddPathLine(path, 50, 70.2, 60, 102.8);
458     expect(Ok, status);
459     status = GdipAddPathLine(path, 55.4, 122.4, 40.4, 60.2);
460     expect(Ok, status);
461     status = GdipAddPathLine(path, 45.6, 20.2, 50, 70.2);
462     expect(Ok, status);
463     rect.X = 20;
464     rect.Y = 25;
465     rect.Width = 60;
466     rect.Height = 120;
467     status = GdipCreateRegionRectI(&rect, &region);
468     expect(Ok, status);
469     status = GdipCombineRegionPath(region, path, CombineModeUnion);
470     expect(Ok, status);
471
472     status = GdipGetRegionDataSize(region, &needed);
473     expect(Ok, status);
474     expect(116, needed);
475     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
476     expect(Ok, status);
477     expect(116, needed);
478     expect_dword(buf, 108);
479     trace("buf[1] = %08x\n", buf[1]);
480     expect_magic((DWORD*)(buf + 2));
481     expect_dword(buf + 3, 2);
482     expect_dword(buf + 4, CombineModeUnion);
483     expect_dword(buf + 5, RGNDATA_RECT);
484     expect_float(buf + 6, 20);
485     expect_float(buf + 7, 25);
486     expect_float(buf + 8, 60);
487     expect_float(buf + 9, 120);
488     expect_dword(buf + 10, RGNDATA_PATH);
489
490     expect_dword(buf + 11, 68);
491     expect_magic((DWORD*)(buf + 12));
492     expect_dword(buf + 13, 6);
493     expect_float(buf + 14, 0x0);
494
495     expect_float(buf + 15, 50);
496     expect_float(buf + 16, 70.2);
497     expect_float(buf + 17, 60);
498     expect_float(buf + 18, 102.8);
499     expect_float(buf + 19, 55.4);
500     expect_float(buf + 20, 122.4);
501     expect_float(buf + 21, 40.4);
502     expect_float(buf + 22, 60.2);
503     expect_float(buf + 23, 45.6);
504     expect_float(buf + 24, 20.2);
505     expect_float(buf + 25, 50);
506     expect_float(buf + 26, 70.2);
507     expect_dword(buf + 27, 0x01010100);
508     ok(*(buf + 28) == 0x00000101 || *(buf + 28) == 0x43050101 /* Win 7 */,
509        "expected 00000101 or 43050101 got %08x\n", *(buf + 28));
510
511     status = GdipDeletePath(path);
512     expect(Ok, status);
513     status = GdipDeleteRegion(region);
514     expect(Ok, status);
515 }
516
517 static void test_isinfinite(void)
518 {
519     GpStatus status;
520     GpRegion *region;
521     GpGraphics *graphics = NULL;
522     GpMatrix *m;
523     HDC hdc = GetDC(0);
524     BOOL res;
525
526     status = GdipCreateFromHDC(hdc, &graphics);
527     expect(Ok, status);
528     GdipCreateRegion(&region);
529
530     GdipCreateMatrix2(3.0, 0.0, 0.0, 1.0, 20.0, 30.0, &m);
531
532     /* NULL arguments */
533     status = GdipIsInfiniteRegion(NULL, NULL, NULL);
534     expect(InvalidParameter, status);
535     status = GdipIsInfiniteRegion(region, NULL, NULL);
536     expect(InvalidParameter, status);
537     status = GdipIsInfiniteRegion(NULL, graphics, NULL);
538     expect(InvalidParameter, status);
539     status = GdipIsInfiniteRegion(NULL, NULL, &res);
540     expect(InvalidParameter, status);
541     status = GdipIsInfiniteRegion(region, NULL, &res);
542     expect(InvalidParameter, status);
543
544     res = FALSE;
545     status = GdipIsInfiniteRegion(region, graphics, &res);
546     expect(Ok, status);
547     expect(TRUE, res);
548
549     /* after world transform */
550     status = GdipSetWorldTransform(graphics, m);
551     expect(Ok, status);
552
553     res = FALSE;
554     status = GdipIsInfiniteRegion(region, graphics, &res);
555     expect(Ok, status);
556     expect(TRUE, res);
557
558     GdipDeleteMatrix(m);
559     GdipDeleteRegion(region);
560     GdipDeleteGraphics(graphics);
561     ReleaseDC(0, hdc);
562 }
563
564 static void test_isempty(void)
565 {
566     GpStatus status;
567     GpRegion *region;
568     GpGraphics *graphics = NULL;
569     HDC hdc = GetDC(0);
570     BOOL res;
571
572     status = GdipCreateFromHDC(hdc, &graphics);
573     expect(Ok, status);
574     GdipCreateRegion(&region);
575
576     /* NULL arguments */
577     status = GdipIsEmptyRegion(NULL, NULL, NULL);
578     expect(InvalidParameter, status);
579     status = GdipIsEmptyRegion(region, NULL, NULL);
580     expect(InvalidParameter, status);
581     status = GdipIsEmptyRegion(NULL, graphics, NULL);
582     expect(InvalidParameter, status);
583     status = GdipIsEmptyRegion(NULL, NULL, &res);
584     expect(InvalidParameter, status);
585     status = GdipIsEmptyRegion(region, NULL, &res);
586     expect(InvalidParameter, status);
587
588     /* default is infinite */
589     res = TRUE;
590     status = GdipIsEmptyRegion(region, graphics, &res);
591     expect(Ok, status);
592     expect(FALSE, res);
593
594     status = GdipSetEmpty(region);
595     expect(Ok, status);
596
597     res = FALSE;
598     status = GdipIsEmptyRegion(region, graphics, &res);
599     expect(Ok, status);
600     expect(TRUE, res);
601
602     GdipDeleteRegion(region);
603     GdipDeleteGraphics(graphics);
604     ReleaseDC(0, hdc);
605 }
606
607 static void test_combinereplace(void)
608 {
609     GpStatus status;
610     GpRegion *region, *region2;
611     GpPath *path;
612     GpRectF rectf;
613     UINT needed;
614     DWORD buf[50];
615
616     rectf.X = rectf.Y = 0.0;
617     rectf.Width = rectf.Height = 100.0;
618
619     status = GdipCreateRegionRect(&rectf, &region);
620     expect(Ok, status);
621
622     /* replace with the same rectangle */
623     status = GdipCombineRegionRect(region, &rectf,CombineModeReplace);
624     expect(Ok, status);
625
626     status = GdipGetRegionDataSize(region, &needed);
627     expect(Ok, status);
628     expect(36, needed);
629     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
630     expect(Ok, status);
631     expect(36, needed);
632     expect_dword(buf, 28);
633     trace("buf[1] = %08x\n", buf[1]);
634     expect_magic((DWORD*)(buf + 2));
635     expect_dword(buf + 3, 0);
636     expect_dword(buf + 4, RGNDATA_RECT);
637
638     /* replace with path */
639     status = GdipCreatePath(FillModeAlternate, &path);
640     expect(Ok, status);
641     status = GdipAddPathEllipse(path, 0.0, 0.0, 100.0, 250.0);
642     expect(Ok, status);
643     status = GdipCombineRegionPath(region, path, CombineModeReplace);
644     expect(Ok, status);
645
646     status = GdipGetRegionDataSize(region, &needed);
647     expect(Ok, status);
648     expect(156, needed);
649     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
650     expect(Ok, status);
651     expect(156, needed);
652     expect_dword(buf, 148);
653     trace("buf[1] = %08x\n", buf[1]);
654     expect_magic((DWORD*)(buf + 2));
655     expect_dword(buf + 3, 0);
656     expect_dword(buf + 4, RGNDATA_PATH);
657     GdipDeletePath(path);
658
659     /* replace with infinite rect */
660     status = GdipCreateRegion(&region2);
661     expect(Ok, status);
662     status = GdipCombineRegionRegion(region, region2, CombineModeReplace);
663     expect(Ok, status);
664
665     status = GdipGetRegionDataSize(region, &needed);
666     expect(Ok, status);
667     expect(20, needed);
668     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
669     expect(Ok, status);
670     expect(20, needed);
671     expect_dword(buf, 12);
672     trace("buf[1] = %08x\n", buf[1]);
673     expect_magic((DWORD*)(buf + 2));
674     expect_dword(buf + 3, 0);
675     expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
676     GdipDeleteRegion(region2);
677
678     /* more complex case : replace with a combined region */
679     status = GdipCreateRegionRect(&rectf, &region2);
680     expect(Ok, status);
681     status = GdipCreatePath(FillModeAlternate, &path);
682     expect(Ok, status);
683     status = GdipAddPathEllipse(path, 0.0, 0.0, 100.0, 250.0);
684     expect(Ok, status);
685     status = GdipCombineRegionPath(region2, path, CombineModeUnion);
686     expect(Ok, status);
687     GdipDeletePath(path);
688     status = GdipCombineRegionRegion(region, region2, CombineModeReplace);
689     expect(Ok, status);
690     GdipDeleteRegion(region2);
691
692     status = GdipGetRegionDataSize(region, &needed);
693     expect(Ok, status);
694     expect(180, needed);
695     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
696     expect(Ok, status);
697     expect(180, needed);
698     expect_dword(buf, 172);
699     trace("buf[1] = %08x\n", buf[1]);
700     expect_magic((DWORD*)(buf + 2));
701     expect_dword(buf + 3, 2);
702     expect_dword(buf + 4, CombineModeUnion);
703
704     GdipDeleteRegion(region);
705 }
706
707 static void test_fromhrgn(void)
708 {
709     GpStatus status;
710     GpRegion *region = (GpRegion*)0xabcdef01;
711     HRGN hrgn;
712     UINT needed;
713     DWORD buf[220];
714     RegionDataPoint *point;
715     GpGraphics *graphics = NULL;
716     HDC hdc;
717     BOOL res;
718
719     /* NULL */
720     status = GdipCreateRegionHrgn(NULL, NULL);
721     expect(InvalidParameter, status);
722     status = GdipCreateRegionHrgn(NULL, &region);
723     expect(InvalidParameter, status);
724     status = GdipCreateRegionHrgn((HRGN)0xdeadbeef, &region);
725     expect(InvalidParameter, status);
726     ok(region == (GpRegion*)0xabcdef01, "Expected region not to be created\n");
727
728     /* empty rectangle */
729     hrgn = CreateRectRgn(0, 0, 0, 0);
730     status = GdipCreateRegionHrgn(hrgn, &region);
731     expect(Ok, status);
732     if(status == Ok) {
733
734     hdc = GetDC(0);
735     status = GdipCreateFromHDC(hdc, &graphics);
736     expect(Ok, status);
737     res = FALSE;
738     status = GdipIsEmptyRegion(region, graphics, &res);
739     expect(Ok, status);
740     expect(TRUE, res);
741     GdipDeleteGraphics(graphics);
742     ReleaseDC(0, hdc);
743     GdipDeleteRegion(region);
744
745     }
746     DeleteObject(hrgn);
747
748     /* rectangle */
749     hrgn = CreateRectRgn(0, 0, 100, 10);
750     status = GdipCreateRegionHrgn(hrgn, &region);
751     expect(Ok, status);
752
753     status = GdipGetRegionDataSize(region, &needed);
754     expect(Ok, status);
755     expect(56, needed);
756
757     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
758     expect(Ok, status);
759
760     if(status == Ok){
761
762     expect(56, needed);
763     expect_dword(buf, 48);
764     expect_magic((DWORD*)(buf + 2));
765     expect_dword(buf + 3, 0);
766     expect_dword(buf + 4, RGNDATA_PATH);
767     expect_dword(buf + 5, 0x00000020);
768     expect_magic((DWORD*)(buf + 6));
769     expect_dword(buf + 7, 0x00000004);
770     todo_wine expect_dword(buf + 8, 0x00006000); /* ?? */
771
772     point = (RegionDataPoint*)buf + 9;
773
774     expect(0,  point[0].X);
775     expect(0,  point[0].Y);
776
777     expect(100,point[1].X); /* buf + 10 */
778     expect(0,  point[1].Y);
779     expect(100,point[2].X); /* buf + 11 */
780     expect(10, point[2].Y);
781
782     expect(0,  point[3].X); /* buf + 12 */
783
784     expect(10, point[3].Y);
785     expect_dword(buf + 13, 0x81010100); /* closed */
786
787     }
788
789     GdipDeleteRegion(region);
790     DeleteObject(hrgn);
791
792     /* ellipse */
793     hrgn = CreateEllipticRgn(0, 0, 100, 10);
794     status = GdipCreateRegionHrgn(hrgn, &region);
795     expect(Ok, status);
796
797     status = GdipGetRegionDataSize(region, &needed);
798     expect(Ok, status);
799     ok(needed == 216 ||
800        needed == 196, /* win98 */
801        "Got %.8x\n", needed);
802
803     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
804     expect(Ok, status);
805
806     if(status == Ok && needed == 216) /* Don't try to test win98 layout */
807     {
808     expect(Ok, status);
809     expect(216, needed);
810     expect_dword(buf, 208);
811     expect_magic((DWORD*)(buf + 2));
812     expect_dword(buf + 3, 0);
813     expect_dword(buf + 4, RGNDATA_PATH);
814     expect_dword(buf + 5, 0x000000C0);
815     expect_magic((DWORD*)(buf + 6));
816     expect_dword(buf + 7, 0x00000024);
817     todo_wine expect_dword(buf + 8, 0x00006000); /* ?? */
818     }
819
820     GdipDeleteRegion(region);
821     DeleteObject(hrgn);
822 }
823
824 static void test_gethrgn(void)
825 {
826     GpStatus status;
827     GpRegion *region, *region2;
828     GpPath *path;
829     GpGraphics *graphics;
830     HRGN hrgn;
831     HDC hdc=GetDC(0);
832     static const RECT empty_rect = {0,0,0,0};
833     static const RECT test_rect = {10, 11, 20, 21};
834     static const GpRectF test_rectF = {10.0, 11.0, 10.0, 10.0};
835     static const RECT scaled_rect = {20, 22, 40, 42};
836     static const RECT test_rect2 = {10, 21, 20, 31};
837     static const GpRectF test_rect2F = {10.0, 21.0, 10.0, 10.0};
838     static const RECT test_rect3 = {10, 11, 20, 31};
839     static const GpRectF test_rect3F = {10.0, 11.0, 10.0, 20.0};
840
841     status = GdipCreateFromHDC(hdc, &graphics);
842     ok(status == Ok, "status %08x\n", status);
843
844     status = GdipCreateRegion(&region);
845     ok(status == Ok, "status %08x\n", status);
846
847     status = GdipGetRegionHRgn(NULL, graphics, &hrgn);
848     ok(status == InvalidParameter, "status %08x\n", status);
849     status = GdipGetRegionHRgn(region, graphics, NULL);
850     ok(status == InvalidParameter, "status %08x\n", status);
851
852     status = GdipGetRegionHRgn(region, NULL, &hrgn);
853     ok(status == Ok, "status %08x\n", status);
854     ok(hrgn == NULL, "hrgn=%p\n", hrgn);
855     DeleteObject(hrgn);
856
857     status = GdipGetRegionHRgn(region, graphics, &hrgn);
858     ok(status == Ok, "status %08x\n", status);
859     ok(hrgn == NULL, "hrgn=%p\n", hrgn);
860     DeleteObject(hrgn);
861
862     status = GdipSetEmpty(region);
863     ok(status == Ok, "status %08x\n", status);
864     status = GdipGetRegionHRgn(region, NULL, &hrgn);
865     ok(status == Ok, "status %08x\n", status);
866     verify_region(hrgn, &empty_rect);
867     DeleteObject(hrgn);
868
869     status = GdipCreatePath(FillModeAlternate, &path);
870     ok(status == Ok, "status %08x\n", status);
871     status = GdipAddPathRectangle(path, 10.0, 11.0, 10.0, 10.0);
872     ok(status == Ok, "status %08x\n", status);
873
874     status = GdipCreateRegionPath(path, &region2);
875     ok(status == Ok, "status %08x\n", status);
876     status = GdipGetRegionHRgn(region2, NULL, &hrgn);
877     ok(status == Ok, "status %08x\n", status);
878     verify_region(hrgn, &test_rect);
879     DeleteObject(hrgn);
880
881     /* resulting HRGN is in device coordinates */
882     status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
883     ok(status == Ok, "status %08x\n", status);
884     status = GdipGetRegionHRgn(region2, graphics, &hrgn);
885     ok(status == Ok, "status %08x\n", status);
886     verify_region(hrgn, &scaled_rect);
887     DeleteObject(hrgn);
888
889     status = GdipCombineRegionRect(region2, &test_rectF, CombineModeReplace);
890     ok(status == Ok, "status %08x\n", status);
891     status = GdipGetRegionHRgn(region2, NULL, &hrgn);
892     ok(status == Ok, "status %08x\n", status);
893     verify_region(hrgn, &test_rect);
894     DeleteObject(hrgn);
895
896     status = GdipGetRegionHRgn(region2, graphics, &hrgn);
897     ok(status == Ok, "status %08x\n", status);
898     verify_region(hrgn, &scaled_rect);
899     DeleteObject(hrgn);
900
901     status = GdipSetInfinite(region);
902     ok(status == Ok, "status %08x\n", status);
903     status = GdipCombineRegionRect(region, &test_rectF, CombineModeIntersect);
904     ok(status == Ok, "status %08x\n", status);
905     status = GdipGetRegionHRgn(region, NULL, &hrgn);
906     ok(status == Ok, "status %08x\n", status);
907     verify_region(hrgn, &test_rect);
908     DeleteObject(hrgn);
909
910     status = GdipCombineRegionRect(region, &test_rectF, CombineModeReplace);
911     ok(status == Ok, "status %08x\n", status);
912     status = GdipCombineRegionRect(region, &test_rect2F, CombineModeUnion);
913     ok(status == Ok, "status %08x\n", status);
914     status = GdipGetRegionHRgn(region, NULL, &hrgn);
915     ok(status == Ok, "status %08x\n", status);
916     verify_region(hrgn, &test_rect3);
917     DeleteObject(hrgn);
918
919     status = GdipCombineRegionRect(region, &test_rect3F, CombineModeReplace);
920     ok(status == Ok, "status %08x\n", status);
921     status = GdipCombineRegionRect(region, &test_rect2F, CombineModeXor);
922     ok(status == Ok, "status %08x\n", status);
923     status = GdipGetRegionHRgn(region, NULL, &hrgn);
924     ok(status == Ok, "status %08x\n", status);
925     verify_region(hrgn, &test_rect);
926     DeleteObject(hrgn);
927
928     status = GdipCombineRegionRect(region, &test_rect3F, CombineModeReplace);
929     ok(status == Ok, "status %08x\n", status);
930     status = GdipCombineRegionRect(region, &test_rectF, CombineModeExclude);
931     ok(status == Ok, "status %08x\n", status);
932     status = GdipGetRegionHRgn(region, NULL, &hrgn);
933     ok(status == Ok, "status %08x\n", status);
934     verify_region(hrgn, &test_rect2);
935     DeleteObject(hrgn);
936
937     status = GdipCombineRegionRect(region, &test_rectF, CombineModeReplace);
938     ok(status == Ok, "status %08x\n", status);
939     status = GdipCombineRegionRect(region, &test_rect3F, CombineModeComplement);
940     ok(status == Ok, "status %08x\n", status);
941     status = GdipGetRegionHRgn(region, NULL, &hrgn);
942     ok(status == Ok, "status %08x\n", status);
943     verify_region(hrgn, &test_rect2);
944     DeleteObject(hrgn);
945
946     status = GdipDeletePath(path);
947     ok(status == Ok, "status %08x\n", status);
948     status = GdipDeleteRegion(region);
949     ok(status == Ok, "status %08x\n", status);
950     status = GdipDeleteRegion(region2);
951     ok(status == Ok, "status %08x\n", status);
952     status = GdipDeleteGraphics(graphics);
953     ok(status == Ok, "status %08x\n", status);
954     ReleaseDC(0, hdc);
955 }
956
957 static void test_isequal(void)
958 {
959     GpRegion *region1, *region2;
960     GpGraphics *graphics;
961     GpRectF rectf;
962     GpStatus status;
963     HDC hdc = GetDC(0);
964     BOOL res;
965
966     status = GdipCreateFromHDC(hdc, &graphics);
967     ok(status == Ok, "status %08x\n", status);
968
969     status = GdipCreateRegion(&region1);
970     ok(status == Ok, "status %08x\n", status);
971     status = GdipCreateRegion(&region2);
972     ok(status == Ok, "status %08x\n", status);
973
974     /* NULL */
975     status = GdipIsEqualRegion(NULL, NULL, NULL, NULL);
976     ok(status == InvalidParameter, "status %08x\n", status);
977     status = GdipIsEqualRegion(region1, region2, NULL, NULL);
978     ok(status == InvalidParameter, "status %08x\n", status);
979     status = GdipIsEqualRegion(region1, region2, graphics, NULL);
980     ok(status == InvalidParameter, "status %08x\n", status);
981     status = GdipIsEqualRegion(region1, region2, NULL, &res);
982     ok(status == InvalidParameter, "status %08x\n", status);
983
984     /* infinite regions */
985     res = FALSE;
986     status = GdipIsEqualRegion(region1, region2, graphics, &res);
987     ok(status == Ok, "status %08x\n", status);
988     ok(res, "Expected to be equal.\n");
989     /* empty regions */
990     status = GdipSetEmpty(region1);
991     ok(status == Ok, "status %08x\n", status);
992     status = GdipSetEmpty(region2);
993     ok(status == Ok, "status %08x\n", status);
994     res = FALSE;
995     status = GdipIsEqualRegion(region1, region2, graphics, &res);
996     ok(status == Ok, "status %08x\n", status);
997     ok(res, "Expected to be equal.\n");
998     /* empty & infinite */
999     status = GdipSetInfinite(region1);
1000     ok(status == Ok, "status %08x\n", status);
1001     res = TRUE;
1002     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1003     ok(status == Ok, "status %08x\n", status);
1004     ok(!res, "Expected to be unequal.\n");
1005     /* rect & (inf/empty) */
1006     rectf.X = rectf.Y = 0.0;
1007     rectf.Width = rectf.Height = 100.0;
1008     status = GdipCombineRegionRect(region1, &rectf, CombineModeReplace);
1009     ok(status == Ok, "status %08x\n", status);
1010     res = TRUE;
1011     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1012     ok(status == Ok, "status %08x\n", status);
1013     ok(!res, "Expected to be unequal.\n");
1014     status = GdipSetInfinite(region2);
1015     ok(status == Ok, "status %08x\n", status);
1016     res = TRUE;
1017     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1018     ok(status == Ok, "status %08x\n", status);
1019     ok(!res, "Expected to be unequal.\n");
1020     /* roughly equal rectangles */
1021     rectf.X = rectf.Y = 0.0;
1022     rectf.Width = rectf.Height = 100.001;
1023     status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1024     ok(status == Ok, "status %08x\n", status);
1025     res = FALSE;
1026     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1027     ok(status == Ok, "status %08x\n", status);
1028     ok(res, "Expected to be equal.\n");
1029     /* equal rectangles */
1030     rectf.X = rectf.Y = 0.0;
1031     rectf.Width = rectf.Height = 100.0;
1032     status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1033     ok(status == Ok, "status %08x\n", status);
1034     res = FALSE;
1035     status = GdipIsEqualRegion(region1, region2, graphics, &res);
1036     ok(status == Ok, "status %08x\n", status);
1037     ok(res, "Expected to be equal.\n");
1038
1039     /* cleanup */
1040     status = GdipDeleteRegion(region1);
1041     ok(status == Ok, "status %08x\n", status);
1042     status = GdipDeleteRegion(region2);
1043     ok(status == Ok, "status %08x\n", status);
1044     status = GdipDeleteGraphics(graphics);
1045     ok(status == Ok, "status %08x\n", status);
1046     ReleaseDC(0, hdc);
1047 }
1048
1049 static void test_translate(void)
1050 {
1051     GpRegion *region, *region2;
1052     GpGraphics *graphics;
1053     GpPath *path;
1054     GpRectF rectf;
1055     GpStatus status;
1056     HDC hdc = GetDC(0);
1057     BOOL res;
1058
1059     status = GdipCreateFromHDC(hdc, &graphics);
1060     ok(status == Ok, "status %08x\n", status);
1061
1062     status = GdipCreatePath(FillModeAlternate, &path);
1063     ok(status == Ok, "status %08x\n", status);
1064
1065     status = GdipCreateRegion(&region);
1066     ok(status == Ok, "status %08x\n", status);
1067     status = GdipCreateRegion(&region2);
1068     ok(status == Ok, "status %08x\n", status);
1069
1070     /* NULL */
1071     status = GdipTranslateRegion(NULL, 0.0, 0.0);
1072     ok(status == InvalidParameter, "status %08x\n", status);
1073
1074     /* infinite */
1075     status = GdipTranslateRegion(region, 10.0, 10.0);
1076     ok(status == Ok, "status %08x\n", status);
1077     /* empty */
1078     status = GdipSetEmpty(region);
1079     ok(status == Ok, "status %08x\n", status);
1080     status = GdipTranslateRegion(region, 10.0, 10.0);
1081     ok(status == Ok, "status %08x\n", status);
1082     /* rect */
1083     rectf.X = 10.0; rectf.Y = 0.0;
1084     rectf.Width = rectf.Height = 100.0;
1085     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1086     ok(status == Ok, "status %08x\n", status);
1087     rectf.X = 15.0; rectf.Y = -2.0;
1088     rectf.Width = rectf.Height = 100.0;
1089     status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1090     ok(status == Ok, "status %08x\n", status);
1091     status = GdipTranslateRegion(region, 5.0, -2.0);
1092     ok(status == Ok, "status %08x\n", status);
1093     res = FALSE;
1094     status = GdipIsEqualRegion(region, region2, graphics, &res);
1095     ok(status == Ok, "status %08x\n", status);
1096     ok(res, "Expected to be equal.\n");
1097     /* path */
1098     status = GdipAddPathEllipse(path, 0.0, 10.0, 100.0, 150.0);
1099     ok(status == Ok, "status %08x\n", status);
1100     status = GdipCombineRegionPath(region, path, CombineModeReplace);
1101     ok(status == Ok, "status %08x\n", status);
1102     status = GdipResetPath(path);
1103     ok(status == Ok, "status %08x\n", status);
1104     status = GdipAddPathEllipse(path, 10.0, 21.0, 100.0, 150.0);
1105     ok(status == Ok, "status %08x\n", status);
1106     status = GdipCombineRegionPath(region2, path, CombineModeReplace);
1107     ok(status == Ok, "status %08x\n", status);
1108     status = GdipTranslateRegion(region, 10.0, 11.0);
1109     ok(status == Ok, "status %08x\n", status);
1110     res = FALSE;
1111     status = GdipIsEqualRegion(region, region2, graphics, &res);
1112     ok(status == Ok, "status %08x\n", status);
1113     ok(res, "Expected to be equal.\n");
1114
1115     status = GdipDeleteRegion(region);
1116     ok(status == Ok, "status %08x\n", status);
1117     status = GdipDeleteRegion(region2);
1118     ok(status == Ok, "status %08x\n", status);
1119     status = GdipDeleteGraphics(graphics);
1120     ok(status == Ok, "status %08x\n", status);
1121     status = GdipDeletePath(path);
1122     ok(status == Ok, "status %08x\n", status);
1123     ReleaseDC(0, hdc);
1124 }
1125
1126 static void test_transform(void)
1127 {
1128     GpRegion *region, *region2;
1129     GpMatrix *matrix;
1130     GpGraphics *graphics;
1131     GpPath *path;
1132     GpRectF rectf;
1133     GpStatus status;
1134     HDC hdc = GetDC(0);
1135     BOOL res;
1136
1137     status = GdipCreateFromHDC(hdc, &graphics);
1138     expect(Ok, status);
1139
1140     status = GdipCreatePath(FillModeAlternate, &path);
1141     expect(Ok, status);
1142
1143     status = GdipCreateRegion(&region);
1144     expect(Ok, status);
1145     status = GdipCreateRegion(&region2);
1146     expect(Ok, status);
1147
1148     status = GdipCreateMatrix(&matrix);
1149     expect(Ok, status);
1150     status = GdipScaleMatrix(matrix, 2.0, 3.0, MatrixOrderAppend);
1151     expect(Ok, status);
1152
1153     /* NULL */
1154     status = GdipTransformRegion(NULL, matrix);
1155     expect(InvalidParameter, status);
1156
1157     status = GdipTransformRegion(region, NULL);
1158     expect(InvalidParameter, status);
1159
1160     /* infinite */
1161     status = GdipTransformRegion(region, matrix);
1162     expect(Ok, status);
1163
1164     res = FALSE;
1165     status = GdipIsEqualRegion(region, region2, graphics, &res);
1166     expect(Ok, status);
1167     ok(res, "Expected to be equal.\n");
1168
1169     /* empty */
1170     status = GdipSetEmpty(region);
1171     expect(Ok, status);
1172     status = GdipTransformRegion(region, matrix);
1173     expect(Ok, status);
1174
1175     status = GdipSetEmpty(region2);
1176     expect(Ok, status);
1177
1178     res = FALSE;
1179     status = GdipIsEqualRegion(region, region2, graphics, &res);
1180     expect(Ok, status);
1181     ok(res, "Expected to be equal.\n");
1182
1183     /* rect */
1184     rectf.X = 10.0;
1185     rectf.Y = 0.0;
1186     rectf.Width = rectf.Height = 100.0;
1187     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1188     expect(Ok, status);
1189     rectf.X = 20.0;
1190     rectf.Y = 0.0;
1191     rectf.Width = 200.0;
1192     rectf.Height = 300.0;
1193     status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1194     expect(Ok, status);
1195     status = GdipTransformRegion(region, matrix);
1196     expect(Ok, status);
1197     res = FALSE;
1198     status = GdipIsEqualRegion(region, region2, graphics, &res);
1199     expect(Ok, status);
1200     ok(res, "Expected to be equal.\n");
1201
1202     /* path */
1203     status = GdipAddPathEllipse(path, 0.0, 10.0, 100.0, 150.0);
1204     expect(Ok, status);
1205     status = GdipCombineRegionPath(region, path, CombineModeReplace);
1206     expect(Ok, status);
1207     status = GdipResetPath(path);
1208     expect(Ok, status);
1209     status = GdipAddPathEllipse(path, 0.0, 30.0, 200.0, 450.0);
1210     expect(Ok, status);
1211     status = GdipCombineRegionPath(region2, path, CombineModeReplace);
1212     expect(Ok, status);
1213     status = GdipTransformRegion(region, matrix);
1214     expect(Ok, status);
1215     res = FALSE;
1216     status = GdipIsEqualRegion(region, region2, graphics, &res);
1217     expect(Ok, status);
1218     ok(res, "Expected to be equal.\n");
1219
1220     status = GdipDeleteRegion(region);
1221     expect(Ok, status);
1222     status = GdipDeleteRegion(region2);
1223     expect(Ok, status);
1224     status = GdipDeleteGraphics(graphics);
1225     expect(Ok, status);
1226     status = GdipDeletePath(path);
1227     expect(Ok, status);
1228     status = GdipDeleteMatrix(matrix);
1229     expect(Ok, status);
1230     ReleaseDC(0, hdc);
1231 }
1232
1233 static void test_getbounds(void)
1234 {
1235     GpRegion *region;
1236     GpGraphics *graphics;
1237     GpStatus status;
1238     GpRectF rectf;
1239     HDC hdc = GetDC(0);
1240
1241     status = GdipCreateFromHDC(hdc, &graphics);
1242     ok(status == Ok, "status %08x\n", status);
1243     status = GdipCreateRegion(&region);
1244     ok(status == Ok, "status %08x\n", status);
1245
1246     /* NULL */
1247     status = GdipGetRegionBounds(NULL, NULL, NULL);
1248     ok(status == InvalidParameter, "status %08x\n", status);
1249     status = GdipGetRegionBounds(region, NULL, NULL);
1250     ok(status == InvalidParameter, "status %08x\n", status);
1251     status = GdipGetRegionBounds(region, graphics, NULL);
1252     ok(status == InvalidParameter, "status %08x\n", status);
1253     /* infinite */
1254     rectf.X = rectf.Y = 0.0;
1255     rectf.Height = rectf.Width = 100.0;
1256     status = GdipGetRegionBounds(region, graphics, &rectf);
1257     ok(status == Ok, "status %08x\n", status);
1258     ok(rectf.X == -(REAL)(1 << 22), "Expected X = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.X);
1259     ok(rectf.Y == -(REAL)(1 << 22), "Expected Y = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.Y);
1260     ok(rectf.Width  == (REAL)(1 << 23), "Expected width = %.2f, got %.2f\n", (REAL)(1 << 23), rectf.Width);
1261     ok(rectf.Height == (REAL)(1 << 23), "Expected height = %.2f, got %.2f\n",(REAL)(1 << 23), rectf.Height);
1262     /* empty */
1263     rectf.X = rectf.Y = 0.0;
1264     rectf.Height = rectf.Width = 100.0;
1265     status = GdipSetEmpty(region);
1266     ok(status == Ok, "status %08x\n", status);
1267     status = GdipGetRegionBounds(region, graphics, &rectf);
1268     ok(status == Ok, "status %08x\n", status);
1269     ok(rectf.X == 0.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1270     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1271     ok(rectf.Width  == 0.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1272     ok(rectf.Height == 0.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1273     /* rect */
1274     rectf.X = 10.0; rectf.Y = 0.0;
1275     rectf.Width = rectf.Height = 100.0;
1276     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1277     ok(status == Ok, "status %08x\n", status);
1278     rectf.X = rectf.Y = 0.0;
1279     rectf.Height = rectf.Width = 0.0;
1280     status = GdipGetRegionBounds(region, graphics, &rectf);
1281     ok(status == Ok, "status %08x\n", status);
1282     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1283     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1284     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1285     ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1286
1287     /* the world and page transforms are ignored */
1288     GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
1289     GdipSetPageUnit(graphics, UnitInch);
1290     GdipSetPageScale(graphics, 2.0);
1291     status = GdipGetRegionBounds(region, graphics, &rectf);
1292     ok(status == Ok, "status %08x\n", status);
1293     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1294     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1295     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1296
1297     rectf.X = 10.0; rectf.Y = 0.0;
1298     rectf.Width = rectf.Height = 100.0;
1299     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1300     ok(status == Ok, "status %08x\n", status);
1301     rectf.X = rectf.Y = 0.0;
1302     rectf.Height = rectf.Width = 0.0;
1303     status = GdipGetRegionBounds(region, graphics, &rectf);
1304     ok(status == Ok, "status %08x\n", status);
1305     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1306     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1307     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1308     ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1309
1310     status = GdipDeleteRegion(region);
1311     ok(status == Ok, "status %08x\n", status);
1312     status = GdipDeleteGraphics(graphics);
1313     ok(status == Ok, "status %08x\n", status);
1314     ReleaseDC(0, hdc);
1315 }
1316
1317 static void test_isvisiblepoint(void)
1318 {
1319     HDC hdc = GetDC(0);
1320     GpGraphics* graphics;
1321     GpRegion* region;
1322     GpPath* path;
1323     GpRectF rectf;
1324     GpStatus status;
1325     BOOL res;
1326     REAL x, y;
1327
1328     status = GdipCreateFromHDC(hdc, &graphics);
1329     expect(Ok, status);
1330
1331     status = GdipCreateRegion(&region);
1332     expect(Ok, status);
1333
1334     /* null parameters */
1335     status = GdipIsVisibleRegionPoint(NULL, 0, 0, graphics, &res);
1336     expect(InvalidParameter, status);
1337     status = GdipIsVisibleRegionPointI(NULL, 0, 0, graphics, &res);
1338     expect(InvalidParameter, status);
1339
1340     status = GdipIsVisibleRegionPoint(region, 0, 0, NULL, &res);
1341     expect(Ok, status);
1342     status = GdipIsVisibleRegionPointI(region, 0, 0, NULL, &res);
1343     expect(Ok, status);
1344
1345     status = GdipIsVisibleRegionPoint(region, 0, 0, graphics, NULL);
1346     expect(InvalidParameter, status);
1347     status = GdipIsVisibleRegionPointI(region, 0, 0, graphics, NULL);
1348     expect(InvalidParameter, status);
1349
1350     /* infinite region */
1351     status = GdipIsInfiniteRegion(region, graphics, &res);
1352     expect(Ok, status);
1353     ok(res == TRUE, "Region should be infinite\n");
1354
1355     x = 10;
1356     y = 10;
1357     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1358     expect(Ok, status);
1359     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1360     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1361     expect(Ok, status);
1362     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1363
1364     x = -10;
1365     y = -10;
1366     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1367     expect(Ok, status);
1368     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1369     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1370     expect(Ok, status);
1371     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1372
1373     /* rectangular region */
1374     rectf.X = 10;
1375     rectf.Y = 20;
1376     rectf.Width = 30;
1377     rectf.Height = 40;
1378
1379     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1380     expect(Ok, status);
1381
1382     x = 0;
1383     y = 0;
1384     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1385     expect(Ok, status);
1386     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1387     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1388     expect(Ok, status);
1389     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1390
1391     x = 9;
1392     y = 19;
1393     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1394     expect(Ok, status);
1395     ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1396
1397     x = 9.25;
1398     y = 19.25;
1399     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1400     expect(Ok, status);
1401     ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1402
1403     x = 9.5;
1404     y = 19.5;
1405     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1406     expect(Ok, status);
1407     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1408
1409     x = 9.75;
1410     y = 19.75;
1411     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1412     expect(Ok, status);
1413     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1414
1415     x = 10;
1416     y = 20;
1417     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1418     expect(Ok, status);
1419     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1420
1421     x = 25;
1422     y = 40;
1423     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1424     expect(Ok, status);
1425     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1426     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1427     expect(Ok, status);
1428     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1429
1430     x = 40;
1431     y = 60;
1432     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1433     expect(Ok, status);
1434     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1435     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1436     expect(Ok, status);
1437     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1438
1439     /* translate into the center of the rectangle */
1440     status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1441     expect(Ok, status);
1442
1443     /* native ignores the world transform, so treat these as if
1444      * no transform exists */
1445     x = -20;
1446     y = -30;
1447     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1448     expect(Ok, status);
1449     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1450     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1451     expect(Ok, status);
1452     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1453
1454     x = 0;
1455     y = 0;
1456     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1457     expect(Ok, status);
1458     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1459     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1460     expect(Ok, status);
1461     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1462
1463     x = 25;
1464     y = 40;
1465     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1466     expect(Ok, status);
1467     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1468     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1469     expect(Ok, status);
1470     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1471
1472     /* translate back to origin */
1473     status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1474     expect(Ok, status);
1475
1476     /* region from path */
1477     status = GdipCreatePath(FillModeAlternate, &path);
1478     expect(Ok, status);
1479
1480     status = GdipAddPathEllipse(path, 10, 20, 30, 40);
1481     expect(Ok, status);
1482
1483     status = GdipCombineRegionPath(region, path, CombineModeReplace);
1484     expect(Ok, status);
1485
1486     x = 11;
1487     y = 21;
1488     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1489     expect(Ok, status);
1490     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1491     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1492     expect(Ok, status);
1493     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1494
1495     x = 25;
1496     y = 40;
1497     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1498     expect(Ok, status);
1499     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1500     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1501     expect(Ok, status);
1502     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1503
1504     x = 40;
1505     y = 60;
1506     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1507     expect(Ok, status);
1508     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1509     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1510     expect(Ok, status);
1511     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1512
1513     GdipDeletePath(path);
1514
1515     GdipDeleteRegion(region);
1516     GdipDeleteGraphics(graphics);
1517     ReleaseDC(0, hdc);
1518 }
1519
1520 static void test_isvisiblerect(void)
1521 {
1522     HDC hdc = GetDC(0);
1523     GpGraphics* graphics;
1524     GpRegion* region;
1525     GpPath* path;
1526     GpRectF rectf;
1527     GpStatus status;
1528     BOOL res;
1529     REAL x, y, w, h;
1530
1531     status = GdipCreateFromHDC(hdc, &graphics);
1532     expect(Ok, status);
1533
1534     status = GdipCreateRegion(&region);
1535     expect(Ok, status);
1536
1537     /* null parameters */
1538     status = GdipIsVisibleRegionRect(NULL, 0, 0, 0, 0, graphics, &res);
1539     expect(InvalidParameter, status);
1540     status = GdipIsVisibleRegionRectI(NULL, 0, 0, 0, 0, graphics, &res);
1541     expect(InvalidParameter, status);
1542
1543     status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, NULL, &res);
1544     expect(Ok, status);
1545     status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, NULL, &res);
1546     expect(Ok, status);
1547
1548     status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, graphics, NULL);
1549     expect(InvalidParameter, status);
1550     status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, graphics, NULL);
1551     expect(InvalidParameter, status);
1552
1553     /* infinite region */
1554     status = GdipIsInfiniteRegion(region, graphics, &res);
1555     expect(Ok, status);
1556     ok(res == TRUE, "Region should be infinite\n");
1557
1558     x = 10; w = 10;
1559     y = 10; h = 10;
1560     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1561     expect(Ok, status);
1562     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1563
1564     x = -10; w = 5;
1565     y = -10; h = 5;
1566     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1567     expect(Ok, status);
1568     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1569
1570     /* rectangular region */
1571     rectf.X = 10;
1572     rectf.Y = 20;
1573     rectf.Width = 30;
1574     rectf.Height = 40;
1575
1576     status = GdipCombineRegionRect(region, &rectf, CombineModeIntersect);
1577     expect(Ok, status);
1578
1579     /* entirely within the region */
1580     x = 11; w = 10;
1581     y = 12; h = 10;
1582     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1583     expect(Ok, status);
1584     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1585     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1586     expect(Ok, status);
1587     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1588
1589     /* entirely outside of the region */
1590     x = 0; w = 5;
1591     y = 0; h = 5;
1592     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1593     expect(Ok, status);
1594     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1595     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1596     expect(Ok, status);
1597     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1598
1599     /* corner cases */
1600     x = 0; w = 10;
1601     y = 0; h = 20;
1602     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1603     expect(Ok, status);
1604     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1605
1606     x = 0; w = 10.25;
1607     y = 0; h = 20.25;
1608     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1609     expect(Ok, status);
1610     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1611
1612     x = 39; w = 10;
1613     y = 59; h = 10;
1614     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1615     expect(Ok, status);
1616     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1617
1618     x = 39.25; w = 10;
1619     y = 59.25; h = 10;
1620     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1621     expect(Ok, status);
1622     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1623
1624     /* corners outside, but some intersection */
1625     x = 0; w = 100;
1626     y = 0; h = 100;
1627     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1628     expect(Ok, status);
1629     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1630
1631     x = 0; w = 100;
1632     y = 0; h = 40;
1633     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1634     expect(Ok, status);
1635     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1636
1637     x = 0; w = 25;
1638     y = 0; h = 100;
1639     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1640     expect(Ok, status);
1641     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1642
1643     /* translate into the center of the rectangle */
1644     status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1645     expect(Ok, status);
1646
1647     /* native ignores the world transform, so treat these as if
1648      * no transform exists */
1649     x = 0; w = 5;
1650     y = 0; h = 5;
1651     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1652     expect(Ok, status);
1653     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1654     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1655     expect(Ok, status);
1656     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1657
1658     x = 11; w = 10;
1659     y = 12; h = 10;
1660     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1661     expect(Ok, status);
1662     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1663     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1664     expect(Ok, status);
1665     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1666
1667     /* translate back to origin */
1668     status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1669     expect(Ok, status);
1670
1671     /* region from path */
1672     status = GdipCreatePath(FillModeAlternate, &path);
1673     expect(Ok, status);
1674
1675     status = GdipAddPathEllipse(path, 10, 20, 30, 40);
1676     expect(Ok, status);
1677
1678     status = GdipCombineRegionPath(region, path, CombineModeReplace);
1679     expect(Ok, status);
1680
1681     x = 0; w = 12;
1682     y = 0; h = 22;
1683     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1684     expect(Ok, status);
1685     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1686     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1687     expect(Ok, status);
1688     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1689
1690     x = 0; w = 25;
1691     y = 0; h = 40;
1692     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1693     expect(Ok, status);
1694     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1695     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1696     expect(Ok, status);
1697     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1698
1699     x = 38; w = 10;
1700     y = 55; h = 10;
1701     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1702     expect(Ok, status);
1703     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1704     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1705     expect(Ok, status);
1706     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1707
1708     x = 0; w = 100;
1709     y = 0; h = 100;
1710     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1711     expect(Ok, status);
1712     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1713     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1714     expect(Ok, status);
1715     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1716
1717     GdipDeletePath(path);
1718
1719     GdipDeleteRegion(region);
1720     GdipDeleteGraphics(graphics);
1721     ReleaseDC(0, hdc);
1722 }
1723
1724 START_TEST(region)
1725 {
1726     struct GdiplusStartupInput gdiplusStartupInput;
1727     ULONG_PTR gdiplusToken;
1728
1729     gdiplusStartupInput.GdiplusVersion              = 1;
1730     gdiplusStartupInput.DebugEventCallback          = NULL;
1731     gdiplusStartupInput.SuppressBackgroundThread    = 0;
1732     gdiplusStartupInput.SuppressExternalCodecs      = 0;
1733
1734     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1735
1736     test_getregiondata();
1737     test_isinfinite();
1738     test_isempty();
1739     test_combinereplace();
1740     test_fromhrgn();
1741     test_gethrgn();
1742     test_isequal();
1743     test_translate();
1744     test_transform();
1745     test_getbounds();
1746     test_isvisiblepoint();
1747     test_isvisiblerect();
1748
1749     GdiplusShutdown(gdiplusToken);
1750 }