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"
26 #define RGNDATA_RECT 0x10000000
27 #define RGNDATA_PATH 0x10000001
28 #define RGNDATA_EMPTY_RECT 0x10000002
29 #define RGNDATA_INFINITE_RECT 0x10000003
31 #define RGNDATA_MAGIC 0xdbc01001
32 #define RGNDATA_MAGIC2 0xdbc01002
34 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
36 #define expect_magic(value) ok(*value == RGNDATA_MAGIC || *value == RGNDATA_MAGIC2, "Expected a known magic value, got %8x\n", *value)
38 #define expect_dword(value, expected) ok(*(value) == expected, "expected %08x got %08x\n", expected, *(value))
40 static inline void expect_float(DWORD
*value
, FLOAT expected
)
42 FLOAT valuef
= *(FLOAT
*)value
;
43 ok(valuef
== expected
, "expected %f got %f\n", expected
, valuef
);
46 /* We get shorts back, not INTs like a GpPoint */
47 typedef struct RegionDataPoint
52 static void verify_region(HRGN hrgn
, const RECT
*rc
)
57 char buf
[sizeof(RGNDATAHEADER
) + sizeof(RECT
)];
62 ret
= GetRegionData(hrgn
, 0, NULL
);
64 ok(ret
== sizeof(rgn
.data
.rdh
), "expected sizeof(rdh), got %u\n", ret
);
66 ok(ret
== sizeof(rgn
.data
.rdh
) + sizeof(RECT
), "expected sizeof(rgn), got %u\n", ret
);
70 ret
= GetRegionData(hrgn
, sizeof(rgn
), &rgn
.data
);
72 ok(ret
== sizeof(rgn
.data
.rdh
), "expected sizeof(rdh), got %u\n", ret
);
74 ok(ret
== sizeof(rgn
.data
.rdh
) + sizeof(RECT
), "expected sizeof(rgn), got %u\n", ret
);
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)
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");
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
);
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
);
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
);
100 ok(EqualRect(&rgn
.data
.rdh
.rcBound
, rc
), "rects don't match\n");
103 static void test_getregiondata(void)
106 GpRegion
*region
, *region2
;
107 RegionDataPoint
*point
;
113 memset(buf
, 0xee, sizeof(buf
));
115 status
= GdipCreateRegion(®ion
);
116 ok(status
== Ok
, "status %08x\n", status
);
118 status
= GdipGetRegionDataSize(region
, &needed
);
119 ok(status
== Ok
, "status %08x\n", status
);
121 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
122 ok(status
== Ok
, "status %08x\n", status
);
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
);
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
);
135 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
136 ok(status
== Ok
, "status %08x\n", status
);
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
);
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
);
149 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
150 ok(status
== Ok
, "status %08x\n", status
);
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
);
158 status
= GdipDeleteRegion(region
);
159 ok(status
== Ok
, "status %08x\n", status
);
165 status
= GdipCreateRegionRectI(&rect
, ®ion
);
166 ok(status
== Ok
, "status %08x\n", status
);
167 status
= GdipGetRegionDataSize(region
, &needed
);
168 ok(status
== Ok
, "status %08x\n", status
);
170 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
171 ok(status
== Ok
, "status %08x\n", status
);
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);
187 status
= GdipCombineRegionRectI(region
, &rect
, CombineModeIntersect
);
188 ok(status
== Ok
, "status %08x\n", status
);
193 status
= GdipCombineRegionRectI(region
, &rect
, CombineModeXor
);
194 ok(status
== Ok
, "status %08x\n", status
);
200 status
= GdipCreateRegionRectI(&rect
, ®ion2
);
201 ok(status
== Ok
, "status %08x\n", status
);
206 status
= GdipCombineRegionRectI(region2
, &rect
, CombineModeUnion
);
207 ok(status
== Ok
, "status %08x\n", status
);
209 status
= GdipCombineRegionRegion(region
, region2
, CombineModeComplement
);
210 ok(status
== Ok
, "status %08x\n", status
);
216 status
= GdipCombineRegionRectI(region
, &rect
, CombineModeExclude
);
217 ok(status
== Ok
, "status %08x\n", status
);
219 status
= GdipGetRegionDataSize(region
, &needed
);
220 ok(status
== Ok
, "status %08x\n", status
);
222 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
223 ok(status
== Ok
, "status %08x\n", status
);
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);
265 status
= GdipDeleteRegion(region2
);
266 ok(status
== Ok
, "status %08x\n", status
);
267 status
= GdipDeleteRegion(region
);
268 ok(status
== Ok
, "status %08x\n", status
);
272 status
= GdipCreatePath(FillModeAlternate
, &path
);
273 ok(status
== Ok
, "status %08x\n", status
);
274 GdipAddPathRectangle(path
, 12.5, 13.0, 14.0, 15.0);
276 status
= GdipCreateRegionPath(path
, ®ion
);
277 ok(status
== Ok
, "status %08x\n", status
);
278 status
= GdipGetRegionDataSize(region
, &needed
);
279 ok(status
== Ok
, "status %08x\n", status
);
281 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
282 ok(status
== Ok
, "status %08x\n", status
);
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);
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
);
313 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
314 ok(status
== Ok
, "status %08x\n", status
);
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);
341 status
= GdipDeleteRegion(region
);
342 ok(status
== Ok
, "status %08x\n", status
);
343 status
= GdipDeletePath(path
);
344 ok(status
== Ok
, "status %08x\n", status
);
346 /* Test an empty path */
347 status
= GdipCreatePath(FillModeAlternate
, &path
);
349 status
= GdipCreateRegionPath(path
, ®ion
);
351 status
= GdipGetRegionDataSize(region
, &needed
);
354 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &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
);
363 /* Second signature for pathdata */
364 expect_dword(buf
+ 5, 12);
365 expect_magic((DWORD
*)(buf
+ 6));
366 expect_dword(buf
+ 7, 0);
367 expect_dword(buf
+ 8, 0x00004000);
369 status
= GdipDeleteRegion(region
);
372 /* Test a simple triangle of INTs */
373 status
= GdipAddPathLine(path
, 5, 6, 7, 8);
375 status
= GdipAddPathLine(path
, 8, 1, 5, 6);
377 status
= GdipClosePathFigure(path
);
379 status
= GdipCreateRegionPath(path
, ®ion
);
381 status
= GdipGetRegionDataSize(region
, &needed
);
384 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
387 expect_dword(buf
, 48);
388 trace("buf[1] = %08x\n", buf
[1]);
389 expect_magic((DWORD
*)(buf
+ 2));
390 expect_dword(buf
+ 3 , 0);
391 expect_dword(buf
+ 4 , RGNDATA_PATH
);
393 expect_dword(buf
+ 5, 32);
394 expect_magic((DWORD
*)(buf
+ 6));
395 expect_dword(buf
+ 7, 4);
396 expect_dword(buf
+ 8, 0x00004000); /* ?? */
398 point
= (RegionDataPoint
*)buf
+ 9;
399 expect(5, point
[0].X
);
400 expect(6, point
[0].Y
);
401 expect(7, point
[1].X
); /* buf + 10 */
402 expect(8, point
[1].Y
);
403 expect(8, point
[2].X
); /* buf + 11 */
404 expect(1, point
[2].Y
);
405 expect(5, point
[3].X
); /* buf + 12 */
406 expect(6, point
[3].Y
);
407 expect_dword(buf
+ 13, 0x81010100); /* 0x01010100 if we don't close the path */
409 status
= GdipDeletePath(path
);
411 status
= GdipDeleteRegion(region
);
414 /* Test a floating-point triangle */
415 status
= GdipCreatePath(FillModeAlternate
, &path
);
417 status
= GdipAddPathLine(path
, 5.6, 6.2, 7.2, 8.9);
419 status
= GdipAddPathLine(path
, 8.1, 1.6, 5.6, 6.2);
421 status
= GdipCreateRegionPath(path
, ®ion
);
423 status
= GdipGetRegionDataSize(region
, &needed
);
426 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
429 expect_dword(buf
, 64);
430 trace("buf[1] = %08x\n", buf
[1]);
431 expect_magic((DWORD
*)(buf
+ 2));
432 expect_dword(buf
+ 3, 0);
433 expect_dword(buf
+ 4, RGNDATA_PATH
);
435 expect_dword(buf
+ 5, 48);
436 expect_magic((DWORD
*)(buf
+ 6));
437 expect_dword(buf
+ 7, 4);
438 expect_dword(buf
+ 8, 0);
439 expect_float(buf
+ 9, 5.6);
440 expect_float(buf
+ 10, 6.2);
441 expect_float(buf
+ 11, 7.2);
442 expect_float(buf
+ 12, 8.9);
443 expect_float(buf
+ 13, 8.1);
444 expect_float(buf
+ 14, 1.6);
445 expect_float(buf
+ 15, 5.6);
446 expect_float(buf
+ 16, 6.2);
448 status
= GdipDeletePath(path
);
450 status
= GdipDeleteRegion(region
);
453 /* Test for a path with > 4 points, and CombineRegionPath */
454 GdipCreatePath(FillModeAlternate
, &path
);
455 status
= GdipAddPathLine(path
, 50, 70.2, 60, 102.8);
457 status
= GdipAddPathLine(path
, 55.4, 122.4, 40.4, 60.2);
459 status
= GdipAddPathLine(path
, 45.6, 20.2, 50, 70.2);
465 status
= GdipCreateRegionRectI(&rect
, ®ion
);
467 status
= GdipCombineRegionPath(region
, path
, CombineModeUnion
);
470 status
= GdipGetRegionDataSize(region
, &needed
);
473 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
476 expect_dword(buf
, 108);
477 trace("buf[1] = %08x\n", buf
[1]);
478 expect_magic((DWORD
*)(buf
+ 2));
479 expect_dword(buf
+ 3, 2);
480 expect_dword(buf
+ 4, CombineModeUnion
);
481 expect_dword(buf
+ 5, RGNDATA_RECT
);
482 expect_float(buf
+ 6, 20);
483 expect_float(buf
+ 7, 25);
484 expect_float(buf
+ 8, 60);
485 expect_float(buf
+ 9, 120);
486 expect_dword(buf
+ 10, RGNDATA_PATH
);
488 expect_dword(buf
+ 11, 68);
489 expect_magic((DWORD
*)(buf
+ 12));
490 expect_dword(buf
+ 13, 6);
491 expect_float(buf
+ 14, 0x0);
493 expect_float(buf
+ 15, 50);
494 expect_float(buf
+ 16, 70.2);
495 expect_float(buf
+ 17, 60);
496 expect_float(buf
+ 18, 102.8);
497 expect_float(buf
+ 19, 55.4);
498 expect_float(buf
+ 20, 122.4);
499 expect_float(buf
+ 21, 40.4);
500 expect_float(buf
+ 22, 60.2);
501 expect_float(buf
+ 23, 45.6);
502 expect_float(buf
+ 24, 20.2);
503 expect_float(buf
+ 25, 50);
504 expect_float(buf
+ 26, 70.2);
505 expect_dword(buf
+ 27, 0x01010100);
506 expect_dword(buf
+ 28, 0x00000101);
508 status
= GdipDeletePath(path
);
510 status
= GdipDeleteRegion(region
);
514 static void test_isinfinite(void)
518 GpGraphics
*graphics
= NULL
;
523 status
= GdipCreateFromHDC(hdc
, &graphics
);
525 GdipCreateRegion(®ion
);
527 GdipCreateMatrix2(3.0, 0.0, 0.0, 1.0, 20.0, 30.0, &m
);
530 status
= GdipIsInfiniteRegion(NULL
, NULL
, NULL
);
531 expect(InvalidParameter
, status
);
532 status
= GdipIsInfiniteRegion(region
, NULL
, NULL
);
533 expect(InvalidParameter
, status
);
534 status
= GdipIsInfiniteRegion(NULL
, graphics
, NULL
);
535 expect(InvalidParameter
, status
);
536 status
= GdipIsInfiniteRegion(NULL
, NULL
, &res
);
537 expect(InvalidParameter
, status
);
538 status
= GdipIsInfiniteRegion(region
, NULL
, &res
);
539 expect(InvalidParameter
, status
);
542 status
= GdipIsInfiniteRegion(region
, graphics
, &res
);
546 /* after world transform */
547 status
= GdipSetWorldTransform(graphics
, m
);
551 status
= GdipIsInfiniteRegion(region
, graphics
, &res
);
556 GdipDeleteRegion(region
);
557 GdipDeleteGraphics(graphics
);
561 static void test_isempty(void)
565 GpGraphics
*graphics
= NULL
;
569 status
= GdipCreateFromHDC(hdc
, &graphics
);
571 GdipCreateRegion(®ion
);
574 status
= GdipIsEmptyRegion(NULL
, NULL
, NULL
);
575 expect(InvalidParameter
, status
);
576 status
= GdipIsEmptyRegion(region
, NULL
, NULL
);
577 expect(InvalidParameter
, status
);
578 status
= GdipIsEmptyRegion(NULL
, graphics
, NULL
);
579 expect(InvalidParameter
, status
);
580 status
= GdipIsEmptyRegion(NULL
, NULL
, &res
);
581 expect(InvalidParameter
, status
);
582 status
= GdipIsEmptyRegion(region
, NULL
, &res
);
583 expect(InvalidParameter
, status
);
585 /* default is infinite */
587 status
= GdipIsEmptyRegion(region
, graphics
, &res
);
591 status
= GdipSetEmpty(region
);
595 status
= GdipIsEmptyRegion(region
, graphics
, &res
);
599 GdipDeleteRegion(region
);
600 GdipDeleteGraphics(graphics
);
604 static void test_combinereplace(void)
607 GpRegion
*region
, *region2
;
613 rectf
.X
= rectf
.Y
= 0.0;
614 rectf
.Width
= rectf
.Height
= 100.0;
616 status
= GdipCreateRegionRect(&rectf
, ®ion
);
619 /* replace with the same rectangle */
620 status
= GdipCombineRegionRect(region
, &rectf
,CombineModeReplace
);
623 status
= GdipGetRegionDataSize(region
, &needed
);
626 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
629 expect_dword(buf
, 28);
630 trace("buf[1] = %08x\n", buf
[1]);
631 expect_magic((DWORD
*)(buf
+ 2));
632 expect_dword(buf
+ 3, 0);
633 expect_dword(buf
+ 4, RGNDATA_RECT
);
635 /* replace with path */
636 status
= GdipCreatePath(FillModeAlternate
, &path
);
638 status
= GdipAddPathEllipse(path
, 0.0, 0.0, 100.0, 250.0);
640 status
= GdipCombineRegionPath(region
, path
, CombineModeReplace
);
643 status
= GdipGetRegionDataSize(region
, &needed
);
646 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
649 expect_dword(buf
, 148);
650 trace("buf[1] = %08x\n", buf
[1]);
651 expect_magic((DWORD
*)(buf
+ 2));
652 expect_dword(buf
+ 3, 0);
653 expect_dword(buf
+ 4, RGNDATA_PATH
);
654 GdipDeletePath(path
);
656 /* replace with infinite rect */
657 status
= GdipCreateRegion(®ion2
);
659 status
= GdipCombineRegionRegion(region
, region2
, CombineModeReplace
);
662 status
= GdipGetRegionDataSize(region
, &needed
);
665 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
668 expect_dword(buf
, 12);
669 trace("buf[1] = %08x\n", buf
[1]);
670 expect_magic((DWORD
*)(buf
+ 2));
671 expect_dword(buf
+ 3, 0);
672 expect_dword(buf
+ 4, RGNDATA_INFINITE_RECT
);
673 GdipDeleteRegion(region2
);
675 /* more complex case : replace with a combined region */
676 status
= GdipCreateRegionRect(&rectf
, ®ion2
);
678 status
= GdipCreatePath(FillModeAlternate
, &path
);
680 status
= GdipAddPathEllipse(path
, 0.0, 0.0, 100.0, 250.0);
682 status
= GdipCombineRegionPath(region2
, path
, CombineModeUnion
);
684 GdipDeletePath(path
);
685 status
= GdipCombineRegionRegion(region
, region2
, CombineModeReplace
);
687 GdipDeleteRegion(region2
);
689 status
= GdipGetRegionDataSize(region
, &needed
);
692 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
695 expect_dword(buf
, 172);
696 trace("buf[1] = %08x\n", buf
[1]);
697 expect_magic((DWORD
*)(buf
+ 2));
698 expect_dword(buf
+ 3, 2);
699 expect_dword(buf
+ 4, CombineModeUnion
);
701 GdipDeleteRegion(region
);
704 static void test_fromhrgn(void)
711 RegionDataPoint
*point
;
712 GpGraphics
*graphics
= NULL
;
717 status
= GdipCreateRegionHrgn(NULL
, NULL
);
718 expect(InvalidParameter
, status
);
719 status
= GdipCreateRegionHrgn(NULL
, ®ion
);
720 expect(InvalidParameter
, status
);
721 status
= GdipCreateRegionHrgn((HRGN
)0xdeadbeef, ®ion
);
722 expect(InvalidParameter
, status
);
724 /* empty rectangle */
725 hrgn
= CreateRectRgn(0, 0, 0, 0);
726 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
731 status
= GdipCreateFromHDC(hdc
, &graphics
);
734 status
= GdipIsEmptyRegion(region
, graphics
, &res
);
737 GdipDeleteGraphics(graphics
);
739 GdipDeleteRegion(region
);
745 hrgn
= CreateRectRgn(0, 0, 100, 10);
746 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
749 status
= GdipGetRegionDataSize(region
, &needed
);
753 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
759 expect_dword(buf
, 48);
760 expect_magic((DWORD
*)(buf
+ 2));
761 expect_dword(buf
+ 3, 0);
762 expect_dword(buf
+ 4, RGNDATA_PATH
);
763 expect_dword(buf
+ 5, 0x00000020);
764 expect_magic((DWORD
*)(buf
+ 6));
765 expect_dword(buf
+ 7, 0x00000004);
766 todo_wine
expect_dword(buf
+ 8, 0x00006000); /* ?? */
768 point
= (RegionDataPoint
*)buf
+ 9;
770 expect(0, point
[0].X
);
771 expect(0, point
[0].Y
);
773 expect(100,point
[1].X
); /* buf + 10 */
774 expect(0, point
[1].Y
);
775 expect(100,point
[2].X
); /* buf + 11 */
776 expect(10, point
[2].Y
);
778 expect(0, point
[3].X
); /* buf + 12 */
780 expect(10, point
[3].Y
);
781 expect_dword(buf
+ 13, 0x81010100); /* closed */
785 GdipDeleteRegion(region
);
789 hrgn
= CreateEllipticRgn(0, 0, 100, 10);
790 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
791 todo_wine
expect(Ok
, status
);
793 status
= GdipGetRegionDataSize(region
, &needed
);
798 status
= GdipGetRegionData(region
, (BYTE
*)buf
, sizeof(buf
), &needed
);
799 todo_wine
expect(Ok
, status
);
806 expect_dword(buf
, 208);
807 expect_magic((DWORD
*)(buf
+ 2));
808 expect_dword(buf
+ 3, 0);
809 expect_dword(buf
+ 4, RGNDATA_PATH
);
810 expect_dword(buf
+ 5, 0x000000C0);
811 expect_magic((DWORD
*)(buf
+ 6));
812 expect_dword(buf
+ 7, 0x00000024);
813 expect_dword(buf
+ 8, 0x00006000); /* ?? */
817 GdipDeleteRegion(region
);
821 static void test_gethrgn(void)
824 GpRegion
*region
, *region2
;
826 GpGraphics
*graphics
;
829 static const RECT empty_rect
= {0,0,0,0};
830 static const RECT test_rect
= {10, 11, 20, 21};
831 static const GpRectF test_rectF
= {10.0, 11.0, 10.0, 10.0};
832 static const RECT scaled_rect
= {20, 22, 40, 42};
833 static const RECT test_rect2
= {10, 21, 20, 31};
834 static const GpRectF test_rect2F
= {10.0, 21.0, 10.0, 10.0};
835 static const RECT test_rect3
= {10, 11, 20, 31};
836 static const GpRectF test_rect3F
= {10.0, 11.0, 10.0, 20.0};
838 status
= GdipCreateFromHDC(hdc
, &graphics
);
839 ok(status
== Ok
, "status %08x\n", status
);
841 status
= GdipCreateRegion(®ion
);
842 ok(status
== Ok
, "status %08x\n", status
);
844 status
= GdipGetRegionHRgn(NULL
, graphics
, &hrgn
);
845 ok(status
== InvalidParameter
, "status %08x\n", status
);
846 status
= GdipGetRegionHRgn(region
, graphics
, NULL
);
847 ok(status
== InvalidParameter
, "status %08x\n", status
);
849 status
= GdipGetRegionHRgn(region
, NULL
, &hrgn
);
850 ok(status
== Ok
, "status %08x\n", status
);
851 ok(hrgn
== NULL
, "hrgn=%p\n", hrgn
);
854 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
855 ok(status
== Ok
, "status %08x\n", status
);
856 ok(hrgn
== NULL
, "hrgn=%p\n", hrgn
);
859 status
= GdipSetEmpty(region
);
860 ok(status
== Ok
, "status %08x\n", status
);
861 status
= GdipGetRegionHRgn(region
, NULL
, &hrgn
);
862 ok(status
== Ok
, "status %08x\n", status
);
863 verify_region(hrgn
, &empty_rect
);
866 status
= GdipCreatePath(FillModeAlternate
, &path
);
867 ok(status
== Ok
, "status %08x\n", status
);
868 status
= GdipAddPathRectangle(path
, 10.0, 11.0, 10.0, 10.0);
869 ok(status
== Ok
, "status %08x\n", status
);
871 status
= GdipCreateRegionPath(path
, ®ion2
);
872 ok(status
== Ok
, "status %08x\n", status
);
873 status
= GdipGetRegionHRgn(region2
, NULL
, &hrgn
);
874 ok(status
== Ok
, "status %08x\n", status
);
875 verify_region(hrgn
, &test_rect
);
878 /* resulting HRGN is in device coordinates */
879 status
= GdipScaleWorldTransform(graphics
, 2.0, 2.0, MatrixOrderPrepend
);
880 ok(status
== Ok
, "status %08x\n", status
);
881 status
= GdipGetRegionHRgn(region2
, graphics
, &hrgn
);
882 ok(status
== Ok
, "status %08x\n", status
);
883 verify_region(hrgn
, &scaled_rect
);
886 status
= GdipCombineRegionRect(region2
, &test_rectF
, CombineModeReplace
);
887 ok(status
== Ok
, "status %08x\n", status
);
888 status
= GdipGetRegionHRgn(region2
, NULL
, &hrgn
);
889 ok(status
== Ok
, "status %08x\n", status
);
890 verify_region(hrgn
, &test_rect
);
893 status
= GdipGetRegionHRgn(region2
, graphics
, &hrgn
);
894 ok(status
== Ok
, "status %08x\n", status
);
895 verify_region(hrgn
, &scaled_rect
);
898 status
= GdipSetInfinite(region
);
899 ok(status
== Ok
, "status %08x\n", status
);
900 status
= GdipCombineRegionRect(region
, &test_rectF
, CombineModeIntersect
);
901 ok(status
== Ok
, "status %08x\n", status
);
902 status
= GdipGetRegionHRgn(region
, NULL
, &hrgn
);
903 ok(status
== Ok
, "status %08x\n", status
);
904 verify_region(hrgn
, &test_rect
);
907 status
= GdipCombineRegionRect(region
, &test_rectF
, CombineModeReplace
);
908 ok(status
== Ok
, "status %08x\n", status
);
909 status
= GdipCombineRegionRect(region
, &test_rect2F
, CombineModeUnion
);
910 ok(status
== Ok
, "status %08x\n", status
);
911 status
= GdipGetRegionHRgn(region
, NULL
, &hrgn
);
912 ok(status
== Ok
, "status %08x\n", status
);
913 verify_region(hrgn
, &test_rect3
);
916 status
= GdipCombineRegionRect(region
, &test_rect3F
, CombineModeReplace
);
917 ok(status
== Ok
, "status %08x\n", status
);
918 status
= GdipCombineRegionRect(region
, &test_rect2F
, CombineModeXor
);
919 ok(status
== Ok
, "status %08x\n", status
);
920 status
= GdipGetRegionHRgn(region
, NULL
, &hrgn
);
921 ok(status
== Ok
, "status %08x\n", status
);
922 verify_region(hrgn
, &test_rect
);
925 status
= GdipCombineRegionRect(region
, &test_rect3F
, CombineModeReplace
);
926 ok(status
== Ok
, "status %08x\n", status
);
927 status
= GdipCombineRegionRect(region
, &test_rectF
, CombineModeExclude
);
928 ok(status
== Ok
, "status %08x\n", status
);
929 status
= GdipGetRegionHRgn(region
, NULL
, &hrgn
);
930 ok(status
== Ok
, "status %08x\n", status
);
931 verify_region(hrgn
, &test_rect2
);
934 status
= GdipCombineRegionRect(region
, &test_rectF
, CombineModeReplace
);
935 ok(status
== Ok
, "status %08x\n", status
);
936 status
= GdipCombineRegionRect(region
, &test_rect3F
, CombineModeComplement
);
937 ok(status
== Ok
, "status %08x\n", status
);
938 status
= GdipGetRegionHRgn(region
, NULL
, &hrgn
);
939 ok(status
== Ok
, "status %08x\n", status
);
940 verify_region(hrgn
, &test_rect2
);
943 status
= GdipDeletePath(path
);
944 ok(status
== Ok
, "status %08x\n", status
);
945 status
= GdipDeleteRegion(region
);
946 ok(status
== Ok
, "status %08x\n", status
);
947 status
= GdipDeleteRegion(region2
);
948 ok(status
== Ok
, "status %08x\n", status
);
949 status
= GdipDeleteGraphics(graphics
);
950 ok(status
== Ok
, "status %08x\n", status
);
956 struct GdiplusStartupInput gdiplusStartupInput
;
957 ULONG_PTR gdiplusToken
;
959 gdiplusStartupInput
.GdiplusVersion
= 1;
960 gdiplusStartupInput
.DebugEventCallback
= NULL
;
961 gdiplusStartupInput
.SuppressBackgroundThread
= 0;
962 gdiplusStartupInput
.SuppressExternalCodecs
= 0;
964 GdiplusStartup(&gdiplusToken
, &gdiplusStartupInput
, NULL
);
966 test_getregiondata();
969 test_combinereplace();
973 GdiplusShutdown(gdiplusToken
);