2 * Unit test suite for gdiplus regions
4 * Copyright (C) 2008 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
27 #define RGNDATA_RECT 0x10000000
28 #define RGNDATA_PATH 0x10000001
29 #define RGNDATA_EMPTY_RECT 0x10000002
30 #define RGNDATA_INFINITE_RECT 0x10000003
32 #define RGNDATA_MAGIC 0xdbc01001
33 #define RGNDATA_MAGIC2 0xdbc01002
35 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
37 #define expectf_(expected, got, precision) ok(fabs(expected - got) < precision, "Expected %.2f, got %.2f\n", expected, got)
38 #define expectf(expected, got) expectf_(expected, got, 0.0001)
40 #define expect_magic(value) ok(*value == RGNDATA_MAGIC || *value == RGNDATA_MAGIC2, "Expected a known magic value, got %8x\n", *value)
42 #define expect_dword(value, expected) ok(*(value) == expected, "expected %08x got %08x\n", expected, *(value))
44 static inline void expect_float(DWORD *value, FLOAT expected)
46 FLOAT valuef = *(FLOAT*)value;
47 ok(valuef == expected, "expected %f got %f\n", expected, valuef);
50 /* We get shorts back, not INTs like a GpPoint */
51 typedef struct RegionDataPoint
56 static void verify_region(HRGN hrgn, const RECT *rc)
61 char buf[sizeof(RGNDATAHEADER) + sizeof(RECT)];
66 ret = GetRegionData(hrgn, 0, NULL);
68 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
70 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
74 ret = GetRegionData(hrgn, sizeof(rgn), &rgn.data);
76 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
78 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
80 trace("size %u, type %u, count %u, rgn size %u, bound (%d,%d-%d,%d)\n",
81 rgn.data.rdh.dwSize, rgn.data.rdh.iType,
82 rgn.data.rdh.nCount, rgn.data.rdh.nRgnSize,
83 rgn.data.rdh.rcBound.left, rgn.data.rdh.rcBound.top,
84 rgn.data.rdh.rcBound.right, rgn.data.rdh.rcBound.bottom);
85 if (rgn.data.rdh.nCount != 0)
87 rect = (const RECT *)rgn.data.Buffer;
88 trace("rect (%d,%d-%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom);
89 ok(EqualRect(rect, rc), "rects don't match\n");
92 ok(rgn.data.rdh.dwSize == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", rgn.data.rdh.dwSize);
93 ok(rgn.data.rdh.iType == RDH_RECTANGLES, "expected RDH_RECTANGLES, got %u\n", rgn.data.rdh.iType);
96 ok(rgn.data.rdh.nCount == 0, "expected 0, got %u\n", rgn.data.rdh.nCount);
97 ok(rgn.data.rdh.nRgnSize == 0, "expected 0, got %u\n", rgn.data.rdh.nRgnSize);
101 ok(rgn.data.rdh.nCount == 1, "expected 1, got %u\n", rgn.data.rdh.nCount);
102 ok(rgn.data.rdh.nRgnSize == sizeof(RECT), "expected sizeof(RECT), got %u\n", rgn.data.rdh.nRgnSize);
104 ok(EqualRect(&rgn.data.rdh.rcBound, rc), "rects don't match\n");
107 static void test_getregiondata(void)
110 GpRegion *region, *region2;
111 RegionDataPoint *point;
117 memset(buf, 0xee, sizeof(buf));
119 status = GdipCreateRegion(®ion);
120 ok(status == Ok, "status %08x\n", status);
122 status = GdipGetRegionDataSize(region, &needed);
123 ok(status == Ok, "status %08x\n", status);
125 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
126 ok(status == Ok, "status %08x\n", status);
128 expect_dword(buf, 12);
129 trace("buf[1] = %08x\n", buf[1]);
130 expect_magic((DWORD*)(buf + 2));
131 expect_dword(buf + 3, 0);
132 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
134 status = GdipSetEmpty(region);
135 ok(status == Ok, "status %08x\n", status);
136 status = GdipGetRegionDataSize(region, &needed);
137 ok(status == Ok, "status %08x\n", status);
139 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
140 ok(status == Ok, "status %08x\n", status);
142 expect_dword(buf, 12);
143 trace("buf[1] = %08x\n", buf[1]);
144 expect_magic((DWORD*)(buf + 2));
145 expect_dword(buf + 3, 0);
146 expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
148 status = GdipSetInfinite(region);
149 ok(status == Ok, "status %08x\n", status);
150 status = GdipGetRegionDataSize(region, &needed);
151 ok(status == Ok, "status %08x\n", status);
153 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
154 ok(status == Ok, "status %08x\n", status);
156 expect_dword(buf, 12);
157 trace("buf[1] = %08x\n", buf[1]);
158 expect_magic((DWORD*)(buf + 2));
159 expect_dword(buf + 3, 0);
160 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
162 status = GdipDeleteRegion(region);
163 ok(status == Ok, "status %08x\n", status);
169 status = GdipCreateRegionRectI(&rect, ®ion);
170 ok(status == Ok, "status %08x\n", status);
171 status = GdipGetRegionDataSize(region, &needed);
172 ok(status == Ok, "status %08x\n", status);
174 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
175 ok(status == Ok, "status %08x\n", status);
177 expect_dword(buf, 28);
178 trace("buf[1] = %08x\n", buf[1]);
179 expect_magic((DWORD*)(buf + 2));
180 expect_dword(buf + 3, 0);
181 expect_dword(buf + 4, RGNDATA_RECT);
182 expect_float(buf + 5, 10.0);
183 expect_float(buf + 6, 20.0);
184 expect_float(buf + 7, 100.0);
185 expect_float(buf + 8, 200.0);
191 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
192 ok(status == Ok, "status %08x\n", status);
197 status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
198 ok(status == Ok, "status %08x\n", status);
204 status = GdipCreateRegionRectI(&rect, ®ion2);
205 ok(status == Ok, "status %08x\n", status);
210 status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
211 ok(status == Ok, "status %08x\n", status);
213 status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
214 ok(status == Ok, "status %08x\n", status);
220 status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
221 ok(status == Ok, "status %08x\n", status);
223 status = GdipGetRegionDataSize(region, &needed);
224 ok(status == Ok, "status %08x\n", status);
226 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
227 ok(status == Ok, "status %08x\n", status);
229 expect_dword(buf, 148);
230 trace("buf[1] = %08x\n", buf[1]);
231 expect_magic((DWORD*)(buf + 2));
232 expect_dword(buf + 3, 10);
233 expect_dword(buf + 4, CombineModeExclude);
234 expect_dword(buf + 5, CombineModeComplement);
235 expect_dword(buf + 6, CombineModeXor);
236 expect_dword(buf + 7, CombineModeIntersect);
237 expect_dword(buf + 8, RGNDATA_RECT);
238 expect_float(buf + 9, 10.0);
239 expect_float(buf + 10, 20.0);
240 expect_float(buf + 11, 100.0);
241 expect_float(buf + 12, 200.0);
242 expect_dword(buf + 13, RGNDATA_RECT);
243 expect_float(buf + 14, 50.0);
244 expect_float(buf + 15, 30.0);
245 expect_float(buf + 16, 10.0);
246 expect_float(buf + 17, 20.0);
247 expect_dword(buf + 18, RGNDATA_RECT);
248 expect_float(buf + 19, 100.0);
249 expect_float(buf + 20, 300.0);
250 expect_float(buf + 21, 30.0);
251 expect_float(buf + 22, 50.0);
252 expect_dword(buf + 23, CombineModeUnion);
253 expect_dword(buf + 24, RGNDATA_RECT);
254 expect_float(buf + 25, 200.0);
255 expect_float(buf + 26, 100.0);
256 expect_float(buf + 27, 133.0);
257 expect_float(buf + 28, 266.0);
258 expect_dword(buf + 29, RGNDATA_RECT);
259 expect_float(buf + 30, 20.0);
260 expect_float(buf + 31, 10.0);
261 expect_float(buf + 32, 40.0);
262 expect_float(buf + 33, 66.0);
263 expect_dword(buf + 34, RGNDATA_RECT);
264 expect_float(buf + 35, 400.0);
265 expect_float(buf + 36, 500.0);
266 expect_float(buf + 37, 22.0);
267 expect_float(buf + 38, 55.0);
269 status = GdipDeleteRegion(region2);
270 ok(status == Ok, "status %08x\n", status);
271 status = GdipDeleteRegion(region);
272 ok(status == Ok, "status %08x\n", status);
276 status = GdipCreatePath(FillModeAlternate, &path);
277 ok(status == Ok, "status %08x\n", status);
278 GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
280 status = GdipCreateRegionPath(path, ®ion);
281 ok(status == Ok, "status %08x\n", status);
282 status = GdipGetRegionDataSize(region, &needed);
283 ok(status == Ok, "status %08x\n", status);
285 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
286 ok(status == Ok, "status %08x\n", status);
288 expect_dword(buf, 64);
289 trace("buf[1] = %08x\n", buf[1]);
290 expect_magic((DWORD*)(buf + 2));
291 expect_dword(buf + 3, 0);
292 expect_dword(buf + 4, RGNDATA_PATH);
293 expect_dword(buf + 5, 0x00000030);
294 expect_magic((DWORD*)(buf + 6));
295 expect_dword(buf + 7, 0x00000004);
296 expect_dword(buf + 8, 0x00000000);
297 expect_float(buf + 9, 12.5);
298 expect_float(buf + 10, 13.0);
299 expect_float(buf + 11, 26.5);
300 expect_float(buf + 12, 13.0);
301 expect_float(buf + 13, 26.5);
302 expect_float(buf + 14, 28.0);
303 expect_float(buf + 15, 12.5);
304 expect_float(buf + 16, 28.0);
305 expect_dword(buf + 17, 0x81010100);
312 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
313 ok(status == Ok, "status %08x\n", status);
314 status = GdipGetRegionDataSize(region, &needed);
315 ok(status == Ok, "status %08x\n", status);
317 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
318 ok(status == Ok, "status %08x\n", status);
320 expect_dword(buf, 88);
321 trace("buf[1] = %08x\n", buf[1]);
322 expect_magic((DWORD*)(buf + 2));
323 expect_dword(buf + 3, 2);
324 expect_dword(buf + 4, CombineModeIntersect);
325 expect_dword(buf + 5, RGNDATA_PATH);
326 expect_dword(buf + 6, 0x00000030);
327 expect_magic((DWORD*)(buf + 7));
328 expect_dword(buf + 8, 0x00000004);
329 expect_dword(buf + 9, 0x00000000);
330 expect_float(buf + 10, 12.5);
331 expect_float(buf + 11, 13.0);
332 expect_float(buf + 12, 26.5);
333 expect_float(buf + 13, 13.0);
334 expect_float(buf + 14, 26.5);
335 expect_float(buf + 15, 28.0);
336 expect_float(buf + 16, 12.5);
337 expect_float(buf + 17, 28.0);
338 expect_dword(buf + 18, 0x81010100);
339 expect_dword(buf + 19, RGNDATA_RECT);
340 expect_float(buf + 20, 50.0);
341 expect_float(buf + 21, 30.0);
342 expect_float(buf + 22, 10.0);
343 expect_float(buf + 23, 20.0);
345 status = GdipDeleteRegion(region);
346 ok(status == Ok, "status %08x\n", status);
347 status = GdipDeletePath(path);
348 ok(status == Ok, "status %08x\n", status);
350 /* Test an empty path */
351 status = GdipCreatePath(FillModeAlternate, &path);
353 status = GdipCreateRegionPath(path, ®ion);
355 status = GdipGetRegionDataSize(region, &needed);
358 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
361 expect_dword(buf, 28);
362 trace("buf[1] = %08x\n", buf[1]);
363 expect_magic((DWORD*)(buf + 2));
364 expect_dword(buf + 3, 0);
365 expect_dword(buf + 4, RGNDATA_PATH);
367 /* Second signature for pathdata */
368 expect_dword(buf + 5, 12);
369 expect_magic((DWORD*)(buf + 6));
370 expect_dword(buf + 7, 0);
371 /* flags 0x4000 means its a path of shorts instead of FLOAT */
372 ok((*(buf + 8) & (~ 0x00004000)) == 0x00000000,
373 "expected 00000000 got %08x\n", *(buf + 8) & (~ 0x00004000));
375 status = GdipDeleteRegion(region);
378 /* Test a simple triangle of INTs */
379 status = GdipAddPathLine(path, 5, 6, 7, 8);
381 status = GdipAddPathLine(path, 8, 1, 5, 6);
383 status = GdipClosePathFigure(path);
385 status = GdipCreateRegionPath(path, ®ion);
387 status = GdipGetRegionDataSize(region, &needed);
390 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
393 expect_dword(buf, 48);
394 trace("buf[1] = %08x\n", buf[1]);
395 expect_magic((DWORD*)(buf + 2));
396 expect_dword(buf + 3 , 0);
397 expect_dword(buf + 4 , RGNDATA_PATH);
399 expect_dword(buf + 5, 32);
400 expect_magic((DWORD*)(buf + 6));
401 expect_dword(buf + 7, 4);
402 expect_dword(buf + 8, 0x00004000); /* ?? */
404 point = (RegionDataPoint*)buf + 9;
405 expect(5, point[0].X);
406 expect(6, point[0].Y);
407 expect(7, point[1].X); /* buf + 10 */
408 expect(8, point[1].Y);
409 expect(8, point[2].X); /* buf + 11 */
410 expect(1, point[2].Y);
411 expect(5, point[3].X); /* buf + 12 */
412 expect(6, point[3].Y);
413 expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
415 status = GdipDeletePath(path);
417 status = GdipDeleteRegion(region);
420 /* Test a floating-point triangle */
421 status = GdipCreatePath(FillModeAlternate, &path);
423 status = GdipAddPathLine(path, 5.6, 6.2, 7.2, 8.9);
425 status = GdipAddPathLine(path, 8.1, 1.6, 5.6, 6.2);
427 status = GdipCreateRegionPath(path, ®ion);
429 status = GdipGetRegionDataSize(region, &needed);
432 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
435 expect_dword(buf, 64);
436 trace("buf[1] = %08x\n", buf[1]);
437 expect_magic((DWORD*)(buf + 2));
438 expect_dword(buf + 3, 0);
439 expect_dword(buf + 4, RGNDATA_PATH);
441 expect_dword(buf + 5, 48);
442 expect_magic((DWORD*)(buf + 6));
443 expect_dword(buf + 7, 4);
444 expect_dword(buf + 8, 0);
445 expect_float(buf + 9, 5.6);
446 expect_float(buf + 10, 6.2);
447 expect_float(buf + 11, 7.2);
448 expect_float(buf + 12, 8.9);
449 expect_float(buf + 13, 8.1);
450 expect_float(buf + 14, 1.6);
451 expect_float(buf + 15, 5.6);
452 expect_float(buf + 16, 6.2);
454 status = GdipDeletePath(path);
456 status = GdipDeleteRegion(region);
459 /* Test for a path with > 4 points, and CombineRegionPath */
460 GdipCreatePath(FillModeAlternate, &path);
461 status = GdipAddPathLine(path, 50, 70.2, 60, 102.8);
463 status = GdipAddPathLine(path, 55.4, 122.4, 40.4, 60.2);
465 status = GdipAddPathLine(path, 45.6, 20.2, 50, 70.2);
471 status = GdipCreateRegionRectI(&rect, ®ion);
473 status = GdipCombineRegionPath(region, path, CombineModeUnion);
476 status = GdipGetRegionDataSize(region, &needed);
479 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
482 expect_dword(buf, 108);
483 trace("buf[1] = %08x\n", buf[1]);
484 expect_magic((DWORD*)(buf + 2));
485 expect_dword(buf + 3, 2);
486 expect_dword(buf + 4, CombineModeUnion);
487 expect_dword(buf + 5, RGNDATA_RECT);
488 expect_float(buf + 6, 20);
489 expect_float(buf + 7, 25);
490 expect_float(buf + 8, 60);
491 expect_float(buf + 9, 120);
492 expect_dword(buf + 10, RGNDATA_PATH);
494 expect_dword(buf + 11, 68);
495 expect_magic((DWORD*)(buf + 12));
496 expect_dword(buf + 13, 6);
497 expect_float(buf + 14, 0x0);
499 expect_float(buf + 15, 50);
500 expect_float(buf + 16, 70.2);
501 expect_float(buf + 17, 60);
502 expect_float(buf + 18, 102.8);
503 expect_float(buf + 19, 55.4);
504 expect_float(buf + 20, 122.4);
505 expect_float(buf + 21, 40.4);
506 expect_float(buf + 22, 60.2);
507 expect_float(buf + 23, 45.6);
508 expect_float(buf + 24, 20.2);
509 expect_float(buf + 25, 50);
510 expect_float(buf + 26, 70.2);
511 expect_dword(buf + 27, 0x01010100);
512 ok(*(buf + 28) == 0x00000101 || *(buf + 28) == 0x43050101 /* Win 7 */,
513 "expected 00000101 or 43050101 got %08x\n", *(buf + 28));
515 status = GdipDeletePath(path);
517 status = GdipDeleteRegion(region);
521 static void test_isinfinite(void)
525 GpGraphics *graphics = NULL;
530 status = GdipCreateFromHDC(hdc, &graphics);
532 GdipCreateRegion(®ion);
534 GdipCreateMatrix2(3.0, 0.0, 0.0, 1.0, 20.0, 30.0, &m);
537 status = GdipIsInfiniteRegion(NULL, NULL, NULL);
538 expect(InvalidParameter, status);
539 status = GdipIsInfiniteRegion(region, NULL, NULL);
540 expect(InvalidParameter, status);
541 status = GdipIsInfiniteRegion(NULL, graphics, NULL);
542 expect(InvalidParameter, status);
543 status = GdipIsInfiniteRegion(NULL, NULL, &res);
544 expect(InvalidParameter, status);
545 status = GdipIsInfiniteRegion(region, NULL, &res);
546 expect(InvalidParameter, status);
549 status = GdipIsInfiniteRegion(region, graphics, &res);
553 /* after world transform */
554 status = GdipSetWorldTransform(graphics, m);
558 status = GdipIsInfiniteRegion(region, graphics, &res);
563 GdipDeleteRegion(region);
564 GdipDeleteGraphics(graphics);
568 static void test_isempty(void)
572 GpGraphics *graphics = NULL;
576 status = GdipCreateFromHDC(hdc, &graphics);
578 GdipCreateRegion(®ion);
581 status = GdipIsEmptyRegion(NULL, NULL, NULL);
582 expect(InvalidParameter, status);
583 status = GdipIsEmptyRegion(region, NULL, NULL);
584 expect(InvalidParameter, status);
585 status = GdipIsEmptyRegion(NULL, graphics, NULL);
586 expect(InvalidParameter, status);
587 status = GdipIsEmptyRegion(NULL, NULL, &res);
588 expect(InvalidParameter, status);
589 status = GdipIsEmptyRegion(region, NULL, &res);
590 expect(InvalidParameter, status);
592 /* default is infinite */
594 status = GdipIsEmptyRegion(region, graphics, &res);
598 status = GdipSetEmpty(region);
602 status = GdipIsEmptyRegion(region, graphics, &res);
606 GdipDeleteRegion(region);
607 GdipDeleteGraphics(graphics);
611 static void test_combinereplace(void)
614 GpRegion *region, *region2;
620 rectf.X = rectf.Y = 0.0;
621 rectf.Width = rectf.Height = 100.0;
623 status = GdipCreateRegionRect(&rectf, ®ion);
626 /* replace with the same rectangle */
627 status = GdipCombineRegionRect(region, &rectf,CombineModeReplace);
630 status = GdipGetRegionDataSize(region, &needed);
633 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
636 expect_dword(buf, 28);
637 trace("buf[1] = %08x\n", buf[1]);
638 expect_magic((DWORD*)(buf + 2));
639 expect_dword(buf + 3, 0);
640 expect_dword(buf + 4, RGNDATA_RECT);
642 /* replace with path */
643 status = GdipCreatePath(FillModeAlternate, &path);
645 status = GdipAddPathEllipse(path, 0.0, 0.0, 100.0, 250.0);
647 status = GdipCombineRegionPath(region, path, CombineModeReplace);
650 status = GdipGetRegionDataSize(region, &needed);
653 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
656 expect_dword(buf, 148);
657 trace("buf[1] = %08x\n", buf[1]);
658 expect_magic((DWORD*)(buf + 2));
659 expect_dword(buf + 3, 0);
660 expect_dword(buf + 4, RGNDATA_PATH);
661 GdipDeletePath(path);
663 /* replace with infinite rect */
664 status = GdipCreateRegion(®ion2);
666 status = GdipCombineRegionRegion(region, region2, CombineModeReplace);
669 status = GdipGetRegionDataSize(region, &needed);
672 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
675 expect_dword(buf, 12);
676 trace("buf[1] = %08x\n", buf[1]);
677 expect_magic((DWORD*)(buf + 2));
678 expect_dword(buf + 3, 0);
679 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
680 GdipDeleteRegion(region2);
682 /* more complex case : replace with a combined region */
683 status = GdipCreateRegionRect(&rectf, ®ion2);
685 status = GdipCreatePath(FillModeAlternate, &path);
687 status = GdipAddPathEllipse(path, 0.0, 0.0, 100.0, 250.0);
689 status = GdipCombineRegionPath(region2, path, CombineModeUnion);
691 GdipDeletePath(path);
692 status = GdipCombineRegionRegion(region, region2, CombineModeReplace);
694 GdipDeleteRegion(region2);
696 status = GdipGetRegionDataSize(region, &needed);
699 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
702 expect_dword(buf, 172);
703 trace("buf[1] = %08x\n", buf[1]);
704 expect_magic((DWORD*)(buf + 2));
705 expect_dword(buf + 3, 2);
706 expect_dword(buf + 4, CombineModeUnion);
708 GdipDeleteRegion(region);
711 static void test_fromhrgn(void)
714 GpRegion *region = (GpRegion*)0xabcdef01;
718 RegionDataPoint *point;
719 GpGraphics *graphics = NULL;
724 status = GdipCreateRegionHrgn(NULL, NULL);
725 expect(InvalidParameter, status);
726 status = GdipCreateRegionHrgn(NULL, ®ion);
727 expect(InvalidParameter, status);
728 status = GdipCreateRegionHrgn((HRGN)0xdeadbeef, ®ion);
729 expect(InvalidParameter, status);
730 ok(region == (GpRegion*)0xabcdef01, "Expected region not to be created\n");
732 /* empty rectangle */
733 hrgn = CreateRectRgn(0, 0, 0, 0);
734 status = GdipCreateRegionHrgn(hrgn, ®ion);
739 status = GdipCreateFromHDC(hdc, &graphics);
742 status = GdipIsEmptyRegion(region, graphics, &res);
745 GdipDeleteGraphics(graphics);
747 GdipDeleteRegion(region);
753 hrgn = CreateRectRgn(0, 0, 100, 10);
754 status = GdipCreateRegionHrgn(hrgn, ®ion);
757 status = GdipGetRegionDataSize(region, &needed);
761 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
767 expect_dword(buf, 48);
768 expect_magic((DWORD*)(buf + 2));
769 expect_dword(buf + 3, 0);
770 expect_dword(buf + 4, RGNDATA_PATH);
771 expect_dword(buf + 5, 0x00000020);
772 expect_magic((DWORD*)(buf + 6));
773 expect_dword(buf + 7, 0x00000004);
774 todo_wine expect_dword(buf + 8, 0x00006000); /* ?? */
776 point = (RegionDataPoint*)buf + 9;
778 expect(0, point[0].X);
779 expect(0, point[0].Y);
781 expect(100,point[1].X); /* buf + 10 */
782 expect(0, point[1].Y);
783 expect(100,point[2].X); /* buf + 11 */
784 expect(10, point[2].Y);
786 expect(0, point[3].X); /* buf + 12 */
788 expect(10, point[3].Y);
789 expect_dword(buf + 13, 0x81010100); /* closed */
793 GdipDeleteRegion(region);
797 hrgn = CreateEllipticRgn(0, 0, 100, 10);
798 status = GdipCreateRegionHrgn(hrgn, ®ion);
801 status = GdipGetRegionDataSize(region, &needed);
804 needed == 196, /* win98 */
805 "Got %.8x\n", needed);
807 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
810 if(status == Ok && needed == 216) /* Don't try to test win98 layout */
814 expect_dword(buf, 208);
815 expect_magic((DWORD*)(buf + 2));
816 expect_dword(buf + 3, 0);
817 expect_dword(buf + 4, RGNDATA_PATH);
818 expect_dword(buf + 5, 0x000000C0);
819 expect_magic((DWORD*)(buf + 6));
820 expect_dword(buf + 7, 0x00000024);
821 todo_wine expect_dword(buf + 8, 0x00006000); /* ?? */
824 GdipDeleteRegion(region);
828 static void test_gethrgn(void)
831 GpRegion *region, *region2;
833 GpGraphics *graphics;
836 static const RECT empty_rect = {0,0,0,0};
837 static const RECT test_rect = {10, 11, 20, 21};
838 static const GpRectF test_rectF = {10.0, 11.0, 10.0, 10.0};
839 static const RECT scaled_rect = {20, 22, 40, 42};
840 static const RECT test_rect2 = {10, 21, 20, 31};
841 static const GpRectF test_rect2F = {10.0, 21.0, 10.0, 10.0};
842 static const RECT test_rect3 = {10, 11, 20, 31};
843 static const GpRectF test_rect3F = {10.0, 11.0, 10.0, 20.0};
845 status = GdipCreateFromHDC(hdc, &graphics);
846 ok(status == Ok, "status %08x\n", status);
848 status = GdipCreateRegion(®ion);
849 ok(status == Ok, "status %08x\n", status);
851 status = GdipGetRegionHRgn(NULL, graphics, &hrgn);
852 ok(status == InvalidParameter, "status %08x\n", status);
853 status = GdipGetRegionHRgn(region, graphics, NULL);
854 ok(status == InvalidParameter, "status %08x\n", status);
856 status = GdipGetRegionHRgn(region, NULL, &hrgn);
857 ok(status == Ok, "status %08x\n", status);
858 ok(hrgn == NULL, "hrgn=%p\n", hrgn);
861 status = GdipGetRegionHRgn(region, graphics, &hrgn);
862 ok(status == Ok, "status %08x\n", status);
863 ok(hrgn == NULL, "hrgn=%p\n", hrgn);
866 status = GdipSetEmpty(region);
867 ok(status == Ok, "status %08x\n", status);
868 status = GdipGetRegionHRgn(region, NULL, &hrgn);
869 ok(status == Ok, "status %08x\n", status);
870 verify_region(hrgn, &empty_rect);
873 status = GdipCreatePath(FillModeAlternate, &path);
874 ok(status == Ok, "status %08x\n", status);
875 status = GdipAddPathRectangle(path, 10.0, 11.0, 10.0, 10.0);
876 ok(status == Ok, "status %08x\n", status);
878 status = GdipCreateRegionPath(path, ®ion2);
879 ok(status == Ok, "status %08x\n", status);
880 status = GdipGetRegionHRgn(region2, NULL, &hrgn);
881 ok(status == Ok, "status %08x\n", status);
882 verify_region(hrgn, &test_rect);
885 /* resulting HRGN is in device coordinates */
886 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
887 ok(status == Ok, "status %08x\n", status);
888 status = GdipGetRegionHRgn(region2, graphics, &hrgn);
889 ok(status == Ok, "status %08x\n", status);
890 verify_region(hrgn, &scaled_rect);
893 status = GdipCombineRegionRect(region2, &test_rectF, CombineModeReplace);
894 ok(status == Ok, "status %08x\n", status);
895 status = GdipGetRegionHRgn(region2, NULL, &hrgn);
896 ok(status == Ok, "status %08x\n", status);
897 verify_region(hrgn, &test_rect);
900 status = GdipGetRegionHRgn(region2, graphics, &hrgn);
901 ok(status == Ok, "status %08x\n", status);
902 verify_region(hrgn, &scaled_rect);
905 status = GdipSetInfinite(region);
906 ok(status == Ok, "status %08x\n", status);
907 status = GdipCombineRegionRect(region, &test_rectF, CombineModeIntersect);
908 ok(status == Ok, "status %08x\n", status);
909 status = GdipGetRegionHRgn(region, NULL, &hrgn);
910 ok(status == Ok, "status %08x\n", status);
911 verify_region(hrgn, &test_rect);
914 status = GdipCombineRegionRect(region, &test_rectF, CombineModeReplace);
915 ok(status == Ok, "status %08x\n", status);
916 status = GdipCombineRegionRect(region, &test_rect2F, CombineModeUnion);
917 ok(status == Ok, "status %08x\n", status);
918 status = GdipGetRegionHRgn(region, NULL, &hrgn);
919 ok(status == Ok, "status %08x\n", status);
920 verify_region(hrgn, &test_rect3);
923 status = GdipCombineRegionRect(region, &test_rect3F, CombineModeReplace);
924 ok(status == Ok, "status %08x\n", status);
925 status = GdipCombineRegionRect(region, &test_rect2F, CombineModeXor);
926 ok(status == Ok, "status %08x\n", status);
927 status = GdipGetRegionHRgn(region, NULL, &hrgn);
928 ok(status == Ok, "status %08x\n", status);
929 verify_region(hrgn, &test_rect);
932 status = GdipCombineRegionRect(region, &test_rect3F, CombineModeReplace);
933 ok(status == Ok, "status %08x\n", status);
934 status = GdipCombineRegionRect(region, &test_rectF, CombineModeExclude);
935 ok(status == Ok, "status %08x\n", status);
936 status = GdipGetRegionHRgn(region, NULL, &hrgn);
937 ok(status == Ok, "status %08x\n", status);
938 verify_region(hrgn, &test_rect2);
941 status = GdipCombineRegionRect(region, &test_rectF, CombineModeReplace);
942 ok(status == Ok, "status %08x\n", status);
943 status = GdipCombineRegionRect(region, &test_rect3F, CombineModeComplement);
944 ok(status == Ok, "status %08x\n", status);
945 status = GdipGetRegionHRgn(region, NULL, &hrgn);
946 ok(status == Ok, "status %08x\n", status);
947 verify_region(hrgn, &test_rect2);
950 status = GdipDeletePath(path);
951 ok(status == Ok, "status %08x\n", status);
952 status = GdipDeleteRegion(region);
953 ok(status == Ok, "status %08x\n", status);
954 status = GdipDeleteRegion(region2);
955 ok(status == Ok, "status %08x\n", status);
956 status = GdipDeleteGraphics(graphics);
957 ok(status == Ok, "status %08x\n", status);
961 static void test_isequal(void)
963 GpRegion *region1, *region2;
964 GpGraphics *graphics;
970 status = GdipCreateFromHDC(hdc, &graphics);
971 ok(status == Ok, "status %08x\n", status);
973 status = GdipCreateRegion(®ion1);
974 ok(status == Ok, "status %08x\n", status);
975 status = GdipCreateRegion(®ion2);
976 ok(status == Ok, "status %08x\n", status);
979 status = GdipIsEqualRegion(NULL, NULL, NULL, NULL);
980 ok(status == InvalidParameter, "status %08x\n", status);
981 status = GdipIsEqualRegion(region1, region2, NULL, NULL);
982 ok(status == InvalidParameter, "status %08x\n", status);
983 status = GdipIsEqualRegion(region1, region2, graphics, NULL);
984 ok(status == InvalidParameter, "status %08x\n", status);
985 status = GdipIsEqualRegion(region1, region2, NULL, &res);
986 ok(status == InvalidParameter, "status %08x\n", status);
988 /* infinite regions */
990 status = GdipIsEqualRegion(region1, region2, graphics, &res);
991 ok(status == Ok, "status %08x\n", status);
992 ok(res, "Expected to be equal.\n");
994 status = GdipSetEmpty(region1);
995 ok(status == Ok, "status %08x\n", status);
996 status = GdipSetEmpty(region2);
997 ok(status == Ok, "status %08x\n", status);
999 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1000 ok(status == Ok, "status %08x\n", status);
1001 ok(res, "Expected to be equal.\n");
1002 /* empty & infinite */
1003 status = GdipSetInfinite(region1);
1004 ok(status == Ok, "status %08x\n", status);
1006 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1007 ok(status == Ok, "status %08x\n", status);
1008 ok(!res, "Expected to be unequal.\n");
1009 /* rect & (inf/empty) */
1010 rectf.X = rectf.Y = 0.0;
1011 rectf.Width = rectf.Height = 100.0;
1012 status = GdipCombineRegionRect(region1, &rectf, CombineModeReplace);
1013 ok(status == Ok, "status %08x\n", status);
1015 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1016 ok(status == Ok, "status %08x\n", status);
1017 ok(!res, "Expected to be unequal.\n");
1018 status = GdipSetInfinite(region2);
1019 ok(status == Ok, "status %08x\n", status);
1021 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1022 ok(status == Ok, "status %08x\n", status);
1023 ok(!res, "Expected to be unequal.\n");
1024 /* roughly equal rectangles */
1025 rectf.X = rectf.Y = 0.0;
1026 rectf.Width = rectf.Height = 100.001;
1027 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1028 ok(status == Ok, "status %08x\n", status);
1030 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1031 ok(status == Ok, "status %08x\n", status);
1032 ok(res, "Expected to be equal.\n");
1033 /* equal rectangles */
1034 rectf.X = rectf.Y = 0.0;
1035 rectf.Width = rectf.Height = 100.0;
1036 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1037 ok(status == Ok, "status %08x\n", status);
1039 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1040 ok(status == Ok, "status %08x\n", status);
1041 ok(res, "Expected to be equal.\n");
1044 status = GdipDeleteRegion(region1);
1045 ok(status == Ok, "status %08x\n", status);
1046 status = GdipDeleteRegion(region2);
1047 ok(status == Ok, "status %08x\n", status);
1048 status = GdipDeleteGraphics(graphics);
1049 ok(status == Ok, "status %08x\n", status);
1053 static void test_translate(void)
1055 GpRegion *region, *region2;
1056 GpGraphics *graphics;
1063 status = GdipCreateFromHDC(hdc, &graphics);
1064 ok(status == Ok, "status %08x\n", status);
1066 status = GdipCreatePath(FillModeAlternate, &path);
1067 ok(status == Ok, "status %08x\n", status);
1069 status = GdipCreateRegion(®ion);
1070 ok(status == Ok, "status %08x\n", status);
1071 status = GdipCreateRegion(®ion2);
1072 ok(status == Ok, "status %08x\n", status);
1075 status = GdipTranslateRegion(NULL, 0.0, 0.0);
1076 ok(status == InvalidParameter, "status %08x\n", status);
1079 status = GdipTranslateRegion(region, 10.0, 10.0);
1080 ok(status == Ok, "status %08x\n", status);
1082 status = GdipSetEmpty(region);
1083 ok(status == Ok, "status %08x\n", status);
1084 status = GdipTranslateRegion(region, 10.0, 10.0);
1085 ok(status == Ok, "status %08x\n", status);
1087 rectf.X = 10.0; rectf.Y = 0.0;
1088 rectf.Width = rectf.Height = 100.0;
1089 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1090 ok(status == Ok, "status %08x\n", status);
1091 rectf.X = 15.0; rectf.Y = -2.0;
1092 rectf.Width = rectf.Height = 100.0;
1093 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1094 ok(status == Ok, "status %08x\n", status);
1095 status = GdipTranslateRegion(region, 5.0, -2.0);
1096 ok(status == Ok, "status %08x\n", status);
1098 status = GdipIsEqualRegion(region, region2, graphics, &res);
1099 ok(status == Ok, "status %08x\n", status);
1100 ok(res, "Expected to be equal.\n");
1102 status = GdipAddPathEllipse(path, 0.0, 10.0, 100.0, 150.0);
1103 ok(status == Ok, "status %08x\n", status);
1104 status = GdipCombineRegionPath(region, path, CombineModeReplace);
1105 ok(status == Ok, "status %08x\n", status);
1106 status = GdipResetPath(path);
1107 ok(status == Ok, "status %08x\n", status);
1108 status = GdipAddPathEllipse(path, 10.0, 21.0, 100.0, 150.0);
1109 ok(status == Ok, "status %08x\n", status);
1110 status = GdipCombineRegionPath(region2, path, CombineModeReplace);
1111 ok(status == Ok, "status %08x\n", status);
1112 status = GdipTranslateRegion(region, 10.0, 11.0);
1113 ok(status == Ok, "status %08x\n", status);
1115 status = GdipIsEqualRegion(region, region2, graphics, &res);
1116 ok(status == Ok, "status %08x\n", status);
1117 ok(res, "Expected to be equal.\n");
1119 status = GdipDeleteRegion(region);
1120 ok(status == Ok, "status %08x\n", status);
1121 status = GdipDeleteRegion(region2);
1122 ok(status == Ok, "status %08x\n", status);
1123 status = GdipDeleteGraphics(graphics);
1124 ok(status == Ok, "status %08x\n", status);
1125 status = GdipDeletePath(path);
1126 ok(status == Ok, "status %08x\n", status);
1130 static void test_transform(void)
1132 GpRegion *region, *region2;
1134 GpGraphics *graphics;
1141 status = GdipCreateFromHDC(hdc, &graphics);
1144 status = GdipCreatePath(FillModeAlternate, &path);
1147 status = GdipCreateRegion(®ion);
1149 status = GdipCreateRegion(®ion2);
1152 status = GdipCreateMatrix(&matrix);
1154 status = GdipScaleMatrix(matrix, 2.0, 3.0, MatrixOrderAppend);
1158 status = GdipTransformRegion(NULL, matrix);
1159 expect(InvalidParameter, status);
1161 status = GdipTransformRegion(region, NULL);
1162 expect(InvalidParameter, status);
1165 status = GdipTransformRegion(region, matrix);
1169 status = GdipIsEqualRegion(region, region2, graphics, &res);
1171 ok(res, "Expected to be equal.\n");
1174 status = GdipSetEmpty(region);
1176 status = GdipTransformRegion(region, matrix);
1179 status = GdipSetEmpty(region2);
1183 status = GdipIsEqualRegion(region, region2, graphics, &res);
1185 ok(res, "Expected to be equal.\n");
1190 rectf.Width = rectf.Height = 100.0;
1191 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1195 rectf.Width = 200.0;
1196 rectf.Height = 300.0;
1197 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1199 status = GdipTransformRegion(region, matrix);
1202 status = GdipIsEqualRegion(region, region2, graphics, &res);
1204 ok(res, "Expected to be equal.\n");
1207 status = GdipAddPathEllipse(path, 0.0, 10.0, 100.0, 150.0);
1209 status = GdipCombineRegionPath(region, path, CombineModeReplace);
1211 status = GdipResetPath(path);
1213 status = GdipAddPathEllipse(path, 0.0, 30.0, 200.0, 450.0);
1215 status = GdipCombineRegionPath(region2, path, CombineModeReplace);
1217 status = GdipTransformRegion(region, matrix);
1220 status = GdipIsEqualRegion(region, region2, graphics, &res);
1222 ok(res, "Expected to be equal.\n");
1224 status = GdipDeleteRegion(region);
1226 status = GdipDeleteRegion(region2);
1228 status = GdipDeleteGraphics(graphics);
1230 status = GdipDeletePath(path);
1232 status = GdipDeleteMatrix(matrix);
1237 static void test_scans(void)
1248 status = GdipCreateRegion(®ion);
1251 status = GdipCreateMatrix(&matrix);
1254 /* test NULL values */
1255 status = GdipGetRegionScansCount(NULL, &count, matrix);
1256 expect(InvalidParameter, status);
1258 status = GdipGetRegionScansCount(region, NULL, matrix);
1259 expect(InvalidParameter, status);
1261 status = GdipGetRegionScansCount(region, &count, NULL);
1262 expect(InvalidParameter, status);
1264 status = GdipGetRegionScans(NULL, scans, &icount, matrix);
1265 expect(InvalidParameter, status);
1267 status = GdipGetRegionScans(region, scans, NULL, matrix);
1268 expect(InvalidParameter, status);
1270 status = GdipGetRegionScans(region, scans, &icount, NULL);
1271 expect(InvalidParameter, status);
1274 status = GdipGetRegionScansCount(region, &count, matrix);
1278 status = GdipGetRegionScans(region, NULL, &icount, matrix);
1282 status = GdipGetRegionScans(region, scans, &icount, matrix);
1286 status = GdipGetRegionScansI(region, scansi, &icount, matrix);
1289 expect(-0x400000, scansi[0].X);
1290 expect(-0x400000, scansi[0].Y);
1291 expect(0x800000, scansi[0].Width);
1292 expect(0x800000, scansi[0].Height);
1294 status = GdipGetRegionScans(region, scans, &icount, matrix);
1297 expectf((double)-0x400000, scans[0].X);
1298 expectf((double)-0x400000, scans[0].Y);
1299 expectf((double)0x800000, scans[0].Width);
1300 expectf((double)0x800000, scans[0].Height);
1303 status = GdipSetEmpty(region);
1306 status = GdipGetRegionScansCount(region, &count, matrix);
1310 status = GdipGetRegionScans(region, scans, &icount, matrix);
1314 /* single rectangle */
1315 rectf.X = rectf.Y = 0.0;
1316 rectf.Width = rectf.Height = 5.0;
1317 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1320 status = GdipGetRegionScansCount(region, &count, matrix);
1324 status = GdipGetRegionScans(region, scans, &icount, matrix);
1327 expectf(0.0, scans[0].X);
1328 expectf(0.0, scans[0].Y);
1329 expectf(5.0, scans[0].Width);
1330 expectf(5.0, scans[0].Height);
1332 /* two rectangles */
1333 rectf.X = rectf.Y = 5.0;
1334 rectf.Width = rectf.Height = 5.0;
1335 status = GdipCombineRegionRect(region, &rectf, CombineModeUnion);
1338 status = GdipGetRegionScansCount(region, &count, matrix);
1342 /* Native ignores the initial value of count */
1343 scans[1].X = scans[1].Y = scans[1].Width = scans[1].Height = 8.0;
1345 status = GdipGetRegionScans(region, scans, &icount, matrix);
1348 expectf(0.0, scans[0].X);
1349 expectf(0.0, scans[0].Y);
1350 expectf(5.0, scans[0].Width);
1351 expectf(5.0, scans[0].Height);
1352 expectf(5.0, scans[1].X);
1353 expectf(5.0, scans[1].Y);
1354 expectf(5.0, scans[1].Width);
1355 expectf(5.0, scans[1].Height);
1357 status = GdipGetRegionScansI(region, scansi, &icount, matrix);
1360 expect(0, scansi[0].X);
1361 expect(0, scansi[0].Y);
1362 expect(5, scansi[0].Width);
1363 expect(5, scansi[0].Height);
1364 expect(5, scansi[1].X);
1365 expect(5, scansi[1].Y);
1366 expect(5, scansi[1].Width);
1367 expect(5, scansi[1].Height);
1369 status = GdipDeleteRegion(region);
1371 status = GdipDeleteMatrix(matrix);
1375 static void test_getbounds(void)
1378 GpGraphics *graphics;
1383 status = GdipCreateFromHDC(hdc, &graphics);
1384 ok(status == Ok, "status %08x\n", status);
1385 status = GdipCreateRegion(®ion);
1386 ok(status == Ok, "status %08x\n", status);
1389 status = GdipGetRegionBounds(NULL, NULL, NULL);
1390 ok(status == InvalidParameter, "status %08x\n", status);
1391 status = GdipGetRegionBounds(region, NULL, NULL);
1392 ok(status == InvalidParameter, "status %08x\n", status);
1393 status = GdipGetRegionBounds(region, graphics, NULL);
1394 ok(status == InvalidParameter, "status %08x\n", status);
1396 rectf.X = rectf.Y = 0.0;
1397 rectf.Height = rectf.Width = 100.0;
1398 status = GdipGetRegionBounds(region, graphics, &rectf);
1399 ok(status == Ok, "status %08x\n", status);
1400 ok(rectf.X == -(REAL)(1 << 22), "Expected X = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.X);
1401 ok(rectf.Y == -(REAL)(1 << 22), "Expected Y = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.Y);
1402 ok(rectf.Width == (REAL)(1 << 23), "Expected width = %.2f, got %.2f\n", (REAL)(1 << 23), rectf.Width);
1403 ok(rectf.Height == (REAL)(1 << 23), "Expected height = %.2f, got %.2f\n",(REAL)(1 << 23), rectf.Height);
1405 rectf.X = rectf.Y = 0.0;
1406 rectf.Height = rectf.Width = 100.0;
1407 status = GdipSetEmpty(region);
1408 ok(status == Ok, "status %08x\n", status);
1409 status = GdipGetRegionBounds(region, graphics, &rectf);
1410 ok(status == Ok, "status %08x\n", status);
1411 ok(rectf.X == 0.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1412 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1413 ok(rectf.Width == 0.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1414 ok(rectf.Height == 0.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1416 rectf.X = 10.0; rectf.Y = 0.0;
1417 rectf.Width = rectf.Height = 100.0;
1418 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1419 ok(status == Ok, "status %08x\n", status);
1420 rectf.X = rectf.Y = 0.0;
1421 rectf.Height = rectf.Width = 0.0;
1422 status = GdipGetRegionBounds(region, graphics, &rectf);
1423 ok(status == Ok, "status %08x\n", status);
1424 ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1425 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1426 ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1427 ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1429 /* the world and page transforms are ignored */
1430 GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
1431 GdipSetPageUnit(graphics, UnitInch);
1432 GdipSetPageScale(graphics, 2.0);
1433 status = GdipGetRegionBounds(region, graphics, &rectf);
1434 ok(status == Ok, "status %08x\n", status);
1435 ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1436 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1437 ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1439 rectf.X = 10.0; rectf.Y = 0.0;
1440 rectf.Width = rectf.Height = 100.0;
1441 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1442 ok(status == Ok, "status %08x\n", status);
1443 rectf.X = rectf.Y = 0.0;
1444 rectf.Height = rectf.Width = 0.0;
1445 status = GdipGetRegionBounds(region, graphics, &rectf);
1446 ok(status == Ok, "status %08x\n", status);
1447 ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1448 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1449 ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1450 ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1452 status = GdipDeleteRegion(region);
1453 ok(status == Ok, "status %08x\n", status);
1454 status = GdipDeleteGraphics(graphics);
1455 ok(status == Ok, "status %08x\n", status);
1459 static void test_isvisiblepoint(void)
1462 GpGraphics* graphics;
1470 status = GdipCreateFromHDC(hdc, &graphics);
1473 status = GdipCreateRegion(®ion);
1476 /* null parameters */
1477 status = GdipIsVisibleRegionPoint(NULL, 0, 0, graphics, &res);
1478 expect(InvalidParameter, status);
1479 status = GdipIsVisibleRegionPointI(NULL, 0, 0, graphics, &res);
1480 expect(InvalidParameter, status);
1482 status = GdipIsVisibleRegionPoint(region, 0, 0, NULL, &res);
1484 status = GdipIsVisibleRegionPointI(region, 0, 0, NULL, &res);
1487 status = GdipIsVisibleRegionPoint(region, 0, 0, graphics, NULL);
1488 expect(InvalidParameter, status);
1489 status = GdipIsVisibleRegionPointI(region, 0, 0, graphics, NULL);
1490 expect(InvalidParameter, status);
1492 /* infinite region */
1493 status = GdipIsInfiniteRegion(region, graphics, &res);
1495 ok(res == TRUE, "Region should be infinite\n");
1499 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1501 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1502 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1504 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1508 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1510 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1511 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1513 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1515 /* rectangular region */
1521 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1526 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1528 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1529 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1531 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1535 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1537 ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1541 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1543 ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1547 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1549 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1553 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1555 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1559 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1561 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1565 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1567 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1568 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1570 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1574 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1576 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1577 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1579 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1581 /* translate into the center of the rectangle */
1582 status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1585 /* native ignores the world transform, so treat these as if
1586 * no transform exists */
1589 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1591 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1592 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1594 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1598 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1600 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1601 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1603 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1607 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1609 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1610 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1612 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1614 /* translate back to origin */
1615 status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1618 /* region from path */
1619 status = GdipCreatePath(FillModeAlternate, &path);
1622 status = GdipAddPathEllipse(path, 10, 20, 30, 40);
1625 status = GdipCombineRegionPath(region, path, CombineModeReplace);
1630 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1632 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1633 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1635 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1639 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1641 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1642 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1644 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1648 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1650 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1651 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1653 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1655 GdipDeletePath(path);
1657 GdipDeleteRegion(region);
1658 GdipDeleteGraphics(graphics);
1662 static void test_isvisiblerect(void)
1665 GpGraphics* graphics;
1673 status = GdipCreateFromHDC(hdc, &graphics);
1676 status = GdipCreateRegion(®ion);
1679 /* null parameters */
1680 status = GdipIsVisibleRegionRect(NULL, 0, 0, 0, 0, graphics, &res);
1681 expect(InvalidParameter, status);
1682 status = GdipIsVisibleRegionRectI(NULL, 0, 0, 0, 0, graphics, &res);
1683 expect(InvalidParameter, status);
1685 status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, NULL, &res);
1687 status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, NULL, &res);
1690 status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, graphics, NULL);
1691 expect(InvalidParameter, status);
1692 status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, graphics, NULL);
1693 expect(InvalidParameter, status);
1695 /* infinite region */
1696 status = GdipIsInfiniteRegion(region, graphics, &res);
1698 ok(res == TRUE, "Region should be infinite\n");
1702 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1704 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1708 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1710 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1712 /* rectangular region */
1718 status = GdipCombineRegionRect(region, &rectf, CombineModeIntersect);
1721 /* entirely within the region */
1724 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1726 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1727 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1729 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1731 /* entirely outside of the region */
1734 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1736 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1737 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1739 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1744 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1746 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1750 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1752 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1756 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1758 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1762 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1764 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1766 /* corners outside, but some intersection */
1769 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1771 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1775 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1777 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1781 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1783 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1785 /* translate into the center of the rectangle */
1786 status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1789 /* native ignores the world transform, so treat these as if
1790 * no transform exists */
1793 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1795 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1796 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1798 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1802 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1804 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1805 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1807 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1809 /* translate back to origin */
1810 status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1813 /* region from path */
1814 status = GdipCreatePath(FillModeAlternate, &path);
1817 status = GdipAddPathEllipse(path, 10, 20, 30, 40);
1820 status = GdipCombineRegionPath(region, path, CombineModeReplace);
1825 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1827 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1828 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1830 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1834 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1836 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1837 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1839 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1843 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1845 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1846 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1848 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1852 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1854 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1855 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1857 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1859 GdipDeletePath(path);
1861 GdipDeleteRegion(region);
1862 GdipDeleteGraphics(graphics);
1868 struct GdiplusStartupInput gdiplusStartupInput;
1869 ULONG_PTR gdiplusToken;
1871 gdiplusStartupInput.GdiplusVersion = 1;
1872 gdiplusStartupInput.DebugEventCallback = NULL;
1873 gdiplusStartupInput.SuppressBackgroundThread = 0;
1874 gdiplusStartupInput.SuppressExternalCodecs = 0;
1876 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1878 test_getregiondata();
1881 test_combinereplace();
1889 test_isvisiblepoint();
1890 test_isvisiblerect();
1892 GdiplusShutdown(gdiplusToken);