jscript: Add index, input and lastIndex properties to regexp functions results.
[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_scans(void)
1234 {
1235     GpRegion *region;
1236     GpMatrix *matrix;
1237     GpRectF rectf;
1238     GpStatus status;
1239     ULONG count=80085;
1240
1241     status = GdipCreateRegion(&region);
1242     expect(Ok, status);
1243
1244     status = GdipCreateMatrix(&matrix);
1245     expect(Ok, status);
1246
1247     /* test NULL values */
1248     status = GdipGetRegionScansCount(NULL, &count, matrix);
1249     expect(InvalidParameter, status);
1250
1251     status = GdipGetRegionScansCount(region, NULL, matrix);
1252     expect(InvalidParameter, status);
1253
1254     status = GdipGetRegionScansCount(region, &count, NULL);
1255     expect(InvalidParameter, status);
1256
1257     /* infinite */
1258     status = GdipGetRegionScansCount(region, &count, matrix);
1259     expect(Ok, status);
1260     expect(1, count);
1261
1262     /* empty */
1263     status = GdipSetEmpty(region);
1264     expect(Ok, status);
1265
1266     status = GdipGetRegionScansCount(region, &count, matrix);
1267     expect(Ok, status);
1268     expect(0, count);
1269
1270     /* single rectangle */
1271     rectf.X = rectf.Y = 0.0;
1272     rectf.Width = rectf.Height = 5.0;
1273     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1274     expect(Ok, status);
1275
1276     status = GdipGetRegionScansCount(region, &count, matrix);
1277     expect(Ok, status);
1278     expect(1, count);
1279
1280     /* two rectangles */
1281     rectf.X = rectf.Y = 5.0;
1282     rectf.Width = rectf.Height = 5.0;
1283     status = GdipCombineRegionRect(region, &rectf, CombineModeUnion);
1284     expect(Ok, status);
1285
1286     status = GdipGetRegionScansCount(region, &count, matrix);
1287     expect(Ok, status);
1288     expect(2, count);
1289
1290     status = GdipDeleteRegion(region);
1291     expect(Ok, status);
1292     status = GdipDeleteMatrix(matrix);
1293     expect(Ok, status);
1294 }
1295
1296 static void test_getbounds(void)
1297 {
1298     GpRegion *region;
1299     GpGraphics *graphics;
1300     GpStatus status;
1301     GpRectF rectf;
1302     HDC hdc = GetDC(0);
1303
1304     status = GdipCreateFromHDC(hdc, &graphics);
1305     ok(status == Ok, "status %08x\n", status);
1306     status = GdipCreateRegion(&region);
1307     ok(status == Ok, "status %08x\n", status);
1308
1309     /* NULL */
1310     status = GdipGetRegionBounds(NULL, NULL, NULL);
1311     ok(status == InvalidParameter, "status %08x\n", status);
1312     status = GdipGetRegionBounds(region, NULL, NULL);
1313     ok(status == InvalidParameter, "status %08x\n", status);
1314     status = GdipGetRegionBounds(region, graphics, NULL);
1315     ok(status == InvalidParameter, "status %08x\n", status);
1316     /* infinite */
1317     rectf.X = rectf.Y = 0.0;
1318     rectf.Height = rectf.Width = 100.0;
1319     status = GdipGetRegionBounds(region, graphics, &rectf);
1320     ok(status == Ok, "status %08x\n", status);
1321     ok(rectf.X == -(REAL)(1 << 22), "Expected X = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.X);
1322     ok(rectf.Y == -(REAL)(1 << 22), "Expected Y = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.Y);
1323     ok(rectf.Width  == (REAL)(1 << 23), "Expected width = %.2f, got %.2f\n", (REAL)(1 << 23), rectf.Width);
1324     ok(rectf.Height == (REAL)(1 << 23), "Expected height = %.2f, got %.2f\n",(REAL)(1 << 23), rectf.Height);
1325     /* empty */
1326     rectf.X = rectf.Y = 0.0;
1327     rectf.Height = rectf.Width = 100.0;
1328     status = GdipSetEmpty(region);
1329     ok(status == Ok, "status %08x\n", status);
1330     status = GdipGetRegionBounds(region, graphics, &rectf);
1331     ok(status == Ok, "status %08x\n", status);
1332     ok(rectf.X == 0.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1333     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1334     ok(rectf.Width  == 0.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1335     ok(rectf.Height == 0.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1336     /* rect */
1337     rectf.X = 10.0; rectf.Y = 0.0;
1338     rectf.Width = rectf.Height = 100.0;
1339     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1340     ok(status == Ok, "status %08x\n", status);
1341     rectf.X = rectf.Y = 0.0;
1342     rectf.Height = rectf.Width = 0.0;
1343     status = GdipGetRegionBounds(region, graphics, &rectf);
1344     ok(status == Ok, "status %08x\n", status);
1345     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1346     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1347     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1348     ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1349
1350     /* the world and page transforms are ignored */
1351     GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
1352     GdipSetPageUnit(graphics, UnitInch);
1353     GdipSetPageScale(graphics, 2.0);
1354     status = GdipGetRegionBounds(region, graphics, &rectf);
1355     ok(status == Ok, "status %08x\n", status);
1356     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1357     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1358     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1359
1360     rectf.X = 10.0; rectf.Y = 0.0;
1361     rectf.Width = rectf.Height = 100.0;
1362     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1363     ok(status == Ok, "status %08x\n", status);
1364     rectf.X = rectf.Y = 0.0;
1365     rectf.Height = rectf.Width = 0.0;
1366     status = GdipGetRegionBounds(region, graphics, &rectf);
1367     ok(status == Ok, "status %08x\n", status);
1368     ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1369     ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1370     ok(rectf.Width  == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1371     ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1372
1373     status = GdipDeleteRegion(region);
1374     ok(status == Ok, "status %08x\n", status);
1375     status = GdipDeleteGraphics(graphics);
1376     ok(status == Ok, "status %08x\n", status);
1377     ReleaseDC(0, hdc);
1378 }
1379
1380 static void test_isvisiblepoint(void)
1381 {
1382     HDC hdc = GetDC(0);
1383     GpGraphics* graphics;
1384     GpRegion* region;
1385     GpPath* path;
1386     GpRectF rectf;
1387     GpStatus status;
1388     BOOL res;
1389     REAL x, y;
1390
1391     status = GdipCreateFromHDC(hdc, &graphics);
1392     expect(Ok, status);
1393
1394     status = GdipCreateRegion(&region);
1395     expect(Ok, status);
1396
1397     /* null parameters */
1398     status = GdipIsVisibleRegionPoint(NULL, 0, 0, graphics, &res);
1399     expect(InvalidParameter, status);
1400     status = GdipIsVisibleRegionPointI(NULL, 0, 0, graphics, &res);
1401     expect(InvalidParameter, status);
1402
1403     status = GdipIsVisibleRegionPoint(region, 0, 0, NULL, &res);
1404     expect(Ok, status);
1405     status = GdipIsVisibleRegionPointI(region, 0, 0, NULL, &res);
1406     expect(Ok, status);
1407
1408     status = GdipIsVisibleRegionPoint(region, 0, 0, graphics, NULL);
1409     expect(InvalidParameter, status);
1410     status = GdipIsVisibleRegionPointI(region, 0, 0, graphics, NULL);
1411     expect(InvalidParameter, status);
1412
1413     /* infinite region */
1414     status = GdipIsInfiniteRegion(region, graphics, &res);
1415     expect(Ok, status);
1416     ok(res == TRUE, "Region should be infinite\n");
1417
1418     x = 10;
1419     y = 10;
1420     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1421     expect(Ok, status);
1422     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1423     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1424     expect(Ok, status);
1425     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1426
1427     x = -10;
1428     y = -10;
1429     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1430     expect(Ok, status);
1431     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1432     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1433     expect(Ok, status);
1434     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1435
1436     /* rectangular region */
1437     rectf.X = 10;
1438     rectf.Y = 20;
1439     rectf.Width = 30;
1440     rectf.Height = 40;
1441
1442     status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1443     expect(Ok, status);
1444
1445     x = 0;
1446     y = 0;
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 = 9;
1455     y = 19;
1456     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1457     expect(Ok, status);
1458     ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1459
1460     x = 9.25;
1461     y = 19.25;
1462     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1463     expect(Ok, status);
1464     ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1465
1466     x = 9.5;
1467     y = 19.5;
1468     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1469     expect(Ok, status);
1470     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1471
1472     x = 9.75;
1473     y = 19.75;
1474     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1475     expect(Ok, status);
1476     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1477
1478     x = 10;
1479     y = 20;
1480     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1481     expect(Ok, status);
1482     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1483
1484     x = 25;
1485     y = 40;
1486     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1487     expect(Ok, status);
1488     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1489     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1490     expect(Ok, status);
1491     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1492
1493     x = 40;
1494     y = 60;
1495     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1496     expect(Ok, status);
1497     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1498     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1499     expect(Ok, status);
1500     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1501
1502     /* translate into the center of the rectangle */
1503     status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1504     expect(Ok, status);
1505
1506     /* native ignores the world transform, so treat these as if
1507      * no transform exists */
1508     x = -20;
1509     y = -30;
1510     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1511     expect(Ok, status);
1512     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1513     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1514     expect(Ok, status);
1515     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1516
1517     x = 0;
1518     y = 0;
1519     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1520     expect(Ok, status);
1521     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1522     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1523     expect(Ok, status);
1524     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1525
1526     x = 25;
1527     y = 40;
1528     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1529     expect(Ok, status);
1530     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1531     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1532     expect(Ok, status);
1533     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1534
1535     /* translate back to origin */
1536     status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1537     expect(Ok, status);
1538
1539     /* region from path */
1540     status = GdipCreatePath(FillModeAlternate, &path);
1541     expect(Ok, status);
1542
1543     status = GdipAddPathEllipse(path, 10, 20, 30, 40);
1544     expect(Ok, status);
1545
1546     status = GdipCombineRegionPath(region, path, CombineModeReplace);
1547     expect(Ok, status);
1548
1549     x = 11;
1550     y = 21;
1551     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1552     expect(Ok, status);
1553     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1554     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1555     expect(Ok, status);
1556     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1557
1558     x = 25;
1559     y = 40;
1560     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1561     expect(Ok, status);
1562     ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1563     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1564     expect(Ok, status);
1565     ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1566
1567     x = 40;
1568     y = 60;
1569     status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1570     expect(Ok, status);
1571     ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1572     status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1573     expect(Ok, status);
1574     ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1575
1576     GdipDeletePath(path);
1577
1578     GdipDeleteRegion(region);
1579     GdipDeleteGraphics(graphics);
1580     ReleaseDC(0, hdc);
1581 }
1582
1583 static void test_isvisiblerect(void)
1584 {
1585     HDC hdc = GetDC(0);
1586     GpGraphics* graphics;
1587     GpRegion* region;
1588     GpPath* path;
1589     GpRectF rectf;
1590     GpStatus status;
1591     BOOL res;
1592     REAL x, y, w, h;
1593
1594     status = GdipCreateFromHDC(hdc, &graphics);
1595     expect(Ok, status);
1596
1597     status = GdipCreateRegion(&region);
1598     expect(Ok, status);
1599
1600     /* null parameters */
1601     status = GdipIsVisibleRegionRect(NULL, 0, 0, 0, 0, graphics, &res);
1602     expect(InvalidParameter, status);
1603     status = GdipIsVisibleRegionRectI(NULL, 0, 0, 0, 0, graphics, &res);
1604     expect(InvalidParameter, status);
1605
1606     status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, NULL, &res);
1607     expect(Ok, status);
1608     status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, NULL, &res);
1609     expect(Ok, status);
1610
1611     status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, graphics, NULL);
1612     expect(InvalidParameter, status);
1613     status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, graphics, NULL);
1614     expect(InvalidParameter, status);
1615
1616     /* infinite region */
1617     status = GdipIsInfiniteRegion(region, graphics, &res);
1618     expect(Ok, status);
1619     ok(res == TRUE, "Region should be infinite\n");
1620
1621     x = 10; w = 10;
1622     y = 10; h = 10;
1623     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1624     expect(Ok, status);
1625     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1626
1627     x = -10; w = 5;
1628     y = -10; h = 5;
1629     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1630     expect(Ok, status);
1631     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1632
1633     /* rectangular region */
1634     rectf.X = 10;
1635     rectf.Y = 20;
1636     rectf.Width = 30;
1637     rectf.Height = 40;
1638
1639     status = GdipCombineRegionRect(region, &rectf, CombineModeIntersect);
1640     expect(Ok, status);
1641
1642     /* entirely within the region */
1643     x = 11; w = 10;
1644     y = 12; h = 10;
1645     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1646     expect(Ok, status);
1647     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1648     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1649     expect(Ok, status);
1650     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1651
1652     /* entirely outside of the region */
1653     x = 0; w = 5;
1654     y = 0; h = 5;
1655     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1656     expect(Ok, status);
1657     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1658     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1659     expect(Ok, status);
1660     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1661
1662     /* corner cases */
1663     x = 0; w = 10;
1664     y = 0; h = 20;
1665     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1666     expect(Ok, status);
1667     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1668
1669     x = 0; w = 10.25;
1670     y = 0; h = 20.25;
1671     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1672     expect(Ok, status);
1673     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1674
1675     x = 39; w = 10;
1676     y = 59; h = 10;
1677     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1678     expect(Ok, status);
1679     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1680
1681     x = 39.25; w = 10;
1682     y = 59.25; h = 10;
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
1687     /* corners outside, but some intersection */
1688     x = 0; w = 100;
1689     y = 0; h = 100;
1690     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1691     expect(Ok, status);
1692     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1693
1694     x = 0; w = 100;
1695     y = 0; h = 40;
1696     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1697     expect(Ok, status);
1698     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1699
1700     x = 0; w = 25;
1701     y = 0; h = 100;
1702     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1703     expect(Ok, status);
1704     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1705
1706     /* translate into the center of the rectangle */
1707     status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1708     expect(Ok, status);
1709
1710     /* native ignores the world transform, so treat these as if
1711      * no transform exists */
1712     x = 0; w = 5;
1713     y = 0; h = 5;
1714     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1715     expect(Ok, status);
1716     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1717     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1718     expect(Ok, status);
1719     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1720
1721     x = 11; w = 10;
1722     y = 12; h = 10;
1723     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1724     expect(Ok, status);
1725     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1726     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1727     expect(Ok, status);
1728     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1729
1730     /* translate back to origin */
1731     status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1732     expect(Ok, status);
1733
1734     /* region from path */
1735     status = GdipCreatePath(FillModeAlternate, &path);
1736     expect(Ok, status);
1737
1738     status = GdipAddPathEllipse(path, 10, 20, 30, 40);
1739     expect(Ok, status);
1740
1741     status = GdipCombineRegionPath(region, path, CombineModeReplace);
1742     expect(Ok, status);
1743
1744     x = 0; w = 12;
1745     y = 0; h = 22;
1746     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1747     expect(Ok, status);
1748     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1749     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1750     expect(Ok, status);
1751     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1752
1753     x = 0; w = 25;
1754     y = 0; h = 40;
1755     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1756     expect(Ok, status);
1757     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1758     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1759     expect(Ok, status);
1760     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1761
1762     x = 38; w = 10;
1763     y = 55; h = 10;
1764     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1765     expect(Ok, status);
1766     ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1767     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1768     expect(Ok, status);
1769     ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1770
1771     x = 0; w = 100;
1772     y = 0; h = 100;
1773     status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1774     expect(Ok, status);
1775     ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1776     status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1777     expect(Ok, status);
1778     ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1779
1780     GdipDeletePath(path);
1781
1782     GdipDeleteRegion(region);
1783     GdipDeleteGraphics(graphics);
1784     ReleaseDC(0, hdc);
1785 }
1786
1787 START_TEST(region)
1788 {
1789     struct GdiplusStartupInput gdiplusStartupInput;
1790     ULONG_PTR gdiplusToken;
1791
1792     gdiplusStartupInput.GdiplusVersion              = 1;
1793     gdiplusStartupInput.DebugEventCallback          = NULL;
1794     gdiplusStartupInput.SuppressBackgroundThread    = 0;
1795     gdiplusStartupInput.SuppressExternalCodecs      = 0;
1796
1797     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1798
1799     test_getregiondata();
1800     test_isinfinite();
1801     test_isempty();
1802     test_combinereplace();
1803     test_fromhrgn();
1804     test_gethrgn();
1805     test_isequal();
1806     test_translate();
1807     test_transform();
1808     test_scans();
1809     test_getbounds();
1810     test_isvisiblepoint();
1811     test_isvisiblerect();
1812
1813     GdiplusShutdown(gdiplusToken);
1814 }