gdiplus/tests: Convert expect_float() to macro to make failure messages print correct...
[wine.git] / dlls / gdiplus / tests / region.c
blob2b8cf76d80237a5878df0198f75a703b15c26e88
1 /*
2 * Unit test suite for gdiplus regions
4 * Copyright (C) 2008 Huw Davies
5 * Copyright (C) 2013 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <math.h>
24 #include "objbase.h"
25 #include "gdiplus.h"
26 #include "wine/test.h"
28 #define RGNDATA_RECT 0x10000000
29 #define RGNDATA_PATH 0x10000001
30 #define RGNDATA_EMPTY_RECT 0x10000002
31 #define RGNDATA_INFINITE_RECT 0x10000003
33 #define RGNDATA_MAGIC 0xdbc01001
34 #define RGNDATA_MAGIC2 0xdbc01002
36 #define expect(expected, got) ok((got) == (expected), "Expected %.8x, got %.8x\n", (expected), (got))
37 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) < (precision), "Expected %f, got %f\n", (expected), (got))
38 #define expectf(expected, got) expectf_((expected), (got), 0.0001)
40 #define expect_magic(value) ok(*(value) == RGNDATA_MAGIC || *(value) == RGNDATA_MAGIC2, "Expected a known magic value, got %8x\n", *(value))
41 #define expect_dword(value, expected) expect((expected), *(value))
42 #define expect_float(value, expected) expectf((expected), *(FLOAT *)(value))
44 /* We get shorts back, not INTs like a GpPoint */
45 typedef struct RegionDataPoint
47 short X, Y;
48 } RegionDataPoint;
50 static void verify_region(HRGN hrgn, const RECT *rc)
52 union
54 RGNDATA data;
55 char buf[sizeof(RGNDATAHEADER) + sizeof(RECT)];
56 } rgn;
57 const RECT *rect;
58 DWORD ret;
60 ret = GetRegionData(hrgn, 0, NULL);
61 if (IsRectEmpty(rc))
62 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
63 else
64 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
66 if (!ret) return;
68 ret = GetRegionData(hrgn, sizeof(rgn), &rgn.data);
69 if (IsRectEmpty(rc))
70 ok(ret == sizeof(rgn.data.rdh), "expected sizeof(rdh), got %u\n", ret);
71 else
72 ok(ret == sizeof(rgn.data.rdh) + sizeof(RECT), "expected sizeof(rgn), got %u\n", ret);
74 trace("size %u, type %u, count %u, rgn size %u, bound (%d,%d-%d,%d)\n",
75 rgn.data.rdh.dwSize, rgn.data.rdh.iType,
76 rgn.data.rdh.nCount, rgn.data.rdh.nRgnSize,
77 rgn.data.rdh.rcBound.left, rgn.data.rdh.rcBound.top,
78 rgn.data.rdh.rcBound.right, rgn.data.rdh.rcBound.bottom);
79 if (rgn.data.rdh.nCount != 0)
81 rect = (const RECT *)rgn.data.Buffer;
82 trace("rect (%d,%d-%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom);
83 ok(EqualRect(rect, rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
84 rc->left, rc->top, rc->right, rc->bottom,
85 rect->left, rect->top, rect->right, rect->bottom);
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))
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);
95 else
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), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
101 rc->left, rc->top, rc->right, rc->bottom,
102 rgn.data.rdh.rcBound.left, rgn.data.rdh.rcBound.top, rgn.data.rdh.rcBound.right, rgn.data.rdh.rcBound.bottom);
105 static void test_getregiondata(void)
107 GpStatus status;
108 GpRegion *region, *region2;
109 RegionDataPoint *point;
110 UINT needed;
111 DWORD buf[100];
112 GpRect rect;
113 GpPath *path;
114 GpMatrix *matrix;
116 status = GdipCreateRegion(&region);
117 ok(status == Ok, "status %08x\n", status);
119 needed = 0;
120 status = GdipGetRegionDataSize(region, &needed);
121 ok(status == Ok, "status %08x\n", status);
122 expect(20, needed);
124 needed = 0;
125 status = GdipGetRegionData(region, (BYTE*)buf, 0, &needed);
126 ok(status == InvalidParameter, "status %08x\n", status);
128 memset(buf, 0xee, sizeof(buf));
129 needed = 0;
130 status = GdipGetRegionData(region, (BYTE*)buf, 4, &needed);
131 ok(status == InsufficientBuffer, "status %08x\n", status);
132 expect(4, needed);
133 expect_dword(buf, 0xeeeeeeee);
135 memset(buf, 0xee, sizeof(buf));
136 needed = 0;
137 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
138 ok(status == Ok, "status %08x\n", status);
139 expect(20, needed);
140 expect_dword(buf, 12);
141 trace("buf[1] = %08x\n", buf[1]);
142 expect_magic(buf + 2);
143 expect_dword(buf + 3, 0);
144 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
146 status = GdipSetEmpty(region);
147 ok(status == Ok, "status %08x\n", status);
148 status = GdipGetRegionDataSize(region, &needed);
149 ok(status == Ok, "status %08x\n", status);
150 expect(20, needed);
151 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
152 ok(status == Ok, "status %08x\n", status);
153 expect(20, needed);
154 expect_dword(buf, 12);
155 trace("buf[1] = %08x\n", buf[1]);
156 expect_magic(buf + 2);
157 expect_dword(buf + 3, 0);
158 expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
160 status = GdipSetInfinite(region);
161 ok(status == Ok, "status %08x\n", status);
162 status = GdipGetRegionDataSize(region, &needed);
163 ok(status == Ok, "status %08x\n", status);
164 expect(20, needed);
165 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
166 ok(status == Ok, "status %08x\n", status);
167 expect(20, needed);
168 expect_dword(buf, 12);
169 trace("buf[1] = %08x\n", buf[1]);
170 expect_magic(buf + 2);
171 expect_dword(buf + 3, 0);
172 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
174 status = GdipDeleteRegion(region);
175 ok(status == Ok, "status %08x\n", status);
177 rect.X = 10;
178 rect.Y = 20;
179 rect.Width = 100;
180 rect.Height = 200;
181 status = GdipCreateRegionRectI(&rect, &region);
182 ok(status == Ok, "status %08x\n", status);
183 status = GdipGetRegionDataSize(region, &needed);
184 ok(status == Ok, "status %08x\n", status);
185 expect(36, needed);
186 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
187 ok(status == Ok, "status %08x\n", status);
188 expect(36, needed);
189 expect_dword(buf, 28);
190 trace("buf[1] = %08x\n", buf[1]);
191 expect_magic(buf + 2);
192 expect_dword(buf + 3, 0);
193 expect_dword(buf + 4, RGNDATA_RECT);
194 expect_float(buf + 5, 10.0);
195 expect_float(buf + 6, 20.0);
196 expect_float(buf + 7, 100.0);
197 expect_float(buf + 8, 200.0);
199 rect.X = 50;
200 rect.Y = 30;
201 rect.Width = 10;
202 rect.Height = 20;
203 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
204 ok(status == Ok, "status %08x\n", status);
205 rect.X = 100;
206 rect.Y = 300;
207 rect.Width = 30;
208 rect.Height = 50;
209 status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
210 ok(status == Ok, "status %08x\n", status);
212 rect.X = 200;
213 rect.Y = 100;
214 rect.Width = 133;
215 rect.Height = 266;
216 status = GdipCreateRegionRectI(&rect, &region2);
217 ok(status == Ok, "status %08x\n", status);
218 rect.X = 20;
219 rect.Y = 10;
220 rect.Width = 40;
221 rect.Height = 66;
222 status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
223 ok(status == Ok, "status %08x\n", status);
225 status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
226 ok(status == Ok, "status %08x\n", status);
228 rect.X = 400;
229 rect.Y = 500;
230 rect.Width = 22;
231 rect.Height = 55;
232 status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
233 ok(status == Ok, "status %08x\n", status);
235 status = GdipGetRegionDataSize(region, &needed);
236 ok(status == Ok, "status %08x\n", status);
237 expect(156, needed);
238 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
239 ok(status == Ok, "status %08x\n", status);
240 expect(156, needed);
241 expect_dword(buf, 148);
242 trace("buf[1] = %08x\n", buf[1]);
243 expect_magic(buf + 2);
244 expect_dword(buf + 3, 10);
245 expect_dword(buf + 4, CombineModeExclude);
246 expect_dword(buf + 5, CombineModeComplement);
247 expect_dword(buf + 6, CombineModeXor);
248 expect_dword(buf + 7, CombineModeIntersect);
249 expect_dword(buf + 8, RGNDATA_RECT);
250 expect_float(buf + 9, 10.0);
251 expect_float(buf + 10, 20.0);
252 expect_float(buf + 11, 100.0);
253 expect_float(buf + 12, 200.0);
254 expect_dword(buf + 13, RGNDATA_RECT);
255 expect_float(buf + 14, 50.0);
256 expect_float(buf + 15, 30.0);
257 expect_float(buf + 16, 10.0);
258 expect_float(buf + 17, 20.0);
259 expect_dword(buf + 18, RGNDATA_RECT);
260 expect_float(buf + 19, 100.0);
261 expect_float(buf + 20, 300.0);
262 expect_float(buf + 21, 30.0);
263 expect_float(buf + 22, 50.0);
264 expect_dword(buf + 23, CombineModeUnion);
265 expect_dword(buf + 24, RGNDATA_RECT);
266 expect_float(buf + 25, 200.0);
267 expect_float(buf + 26, 100.0);
268 expect_float(buf + 27, 133.0);
269 expect_float(buf + 28, 266.0);
270 expect_dword(buf + 29, RGNDATA_RECT);
271 expect_float(buf + 30, 20.0);
272 expect_float(buf + 31, 10.0);
273 expect_float(buf + 32, 40.0);
274 expect_float(buf + 33, 66.0);
275 expect_dword(buf + 34, RGNDATA_RECT);
276 expect_float(buf + 35, 400.0);
277 expect_float(buf + 36, 500.0);
278 expect_float(buf + 37, 22.0);
279 expect_float(buf + 38, 55.0);
281 status = GdipDeleteRegion(region2);
282 ok(status == Ok, "status %08x\n", status);
283 status = GdipDeleteRegion(region);
284 ok(status == Ok, "status %08x\n", status);
286 /* Try some paths */
288 status = GdipCreatePath(FillModeAlternate, &path);
289 ok(status == Ok, "status %08x\n", status);
290 GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
292 status = GdipCreateRegionPath(path, &region);
293 ok(status == Ok, "status %08x\n", status);
294 status = GdipGetRegionDataSize(region, &needed);
295 ok(status == Ok, "status %08x\n", status);
296 expect(72, needed);
297 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
298 ok(status == Ok, "status %08x\n", status);
299 expect(72, needed);
300 expect_dword(buf, 64);
301 trace("buf[1] = %08x\n", buf[1]);
302 expect_magic(buf + 2);
303 expect_dword(buf + 3, 0);
304 expect_dword(buf + 4, RGNDATA_PATH);
305 expect_dword(buf + 5, 0x00000030);
306 expect_magic(buf + 6);
307 expect_dword(buf + 7, 0x00000004);
308 expect_dword(buf + 8, 0x00000000);
309 expect_float(buf + 9, 12.5);
310 expect_float(buf + 10, 13.0);
311 expect_float(buf + 11, 26.5);
312 expect_float(buf + 12, 13.0);
313 expect_float(buf + 13, 26.5);
314 expect_float(buf + 14, 28.0);
315 expect_float(buf + 15, 12.5);
316 expect_float(buf + 16, 28.0);
317 expect_dword(buf + 17, 0x81010100);
319 rect.X = 50;
320 rect.Y = 30;
321 rect.Width = 10;
322 rect.Height = 20;
323 status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
324 ok(status == Ok, "status %08x\n", status);
325 status = GdipGetRegionDataSize(region, &needed);
326 ok(status == Ok, "status %08x\n", status);
327 expect(96, needed);
328 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
329 ok(status == Ok, "status %08x\n", status);
330 expect(96, needed);
331 expect_dword(buf, 88);
332 trace("buf[1] = %08x\n", buf[1]);
333 expect_magic(buf + 2);
334 expect_dword(buf + 3, 2);
335 expect_dword(buf + 4, CombineModeIntersect);
336 expect_dword(buf + 5, RGNDATA_PATH);
337 expect_dword(buf + 6, 0x00000030);
338 expect_magic(buf + 7);
339 expect_dword(buf + 8, 0x00000004);
340 expect_dword(buf + 9, 0x00000000);
341 expect_float(buf + 10, 12.5);
342 expect_float(buf + 11, 13.0);
343 expect_float(buf + 12, 26.5);
344 expect_float(buf + 13, 13.0);
345 expect_float(buf + 14, 26.5);
346 expect_float(buf + 15, 28.0);
347 expect_float(buf + 16, 12.5);
348 expect_float(buf + 17, 28.0);
349 expect_dword(buf + 18, 0x81010100);
350 expect_dword(buf + 19, RGNDATA_RECT);
351 expect_float(buf + 20, 50.0);
352 expect_float(buf + 21, 30.0);
353 expect_float(buf + 22, 10.0);
354 expect_float(buf + 23, 20.0);
356 status = GdipDeleteRegion(region);
357 ok(status == Ok, "status %08x\n", status);
358 status = GdipDeletePath(path);
359 ok(status == Ok, "status %08x\n", status);
361 /* Test an empty path */
362 status = GdipCreatePath(FillModeAlternate, &path);
363 expect(Ok, status);
364 status = GdipCreateRegionPath(path, &region);
365 expect(Ok, status);
366 status = GdipGetRegionDataSize(region, &needed);
367 expect(Ok, status);
368 expect(36, needed);
369 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
370 expect(Ok, status);
371 expect(36, needed);
372 expect_dword(buf, 28);
373 trace("buf[1] = %08x\n", buf[1]);
374 expect_magic(buf + 2);
375 expect_dword(buf + 3, 0);
376 expect_dword(buf + 4, RGNDATA_PATH);
377 /* Second signature for pathdata */
378 expect_dword(buf + 5, 12);
379 expect_magic(buf + 6);
380 expect_dword(buf + 7, 0);
381 /* flags 0 means that a path is an array of FLOATs */
382 ok(*(buf + 8) == 0x4000 /* before win7 */ || *(buf + 8) == 0,
383 "expected 0x4000 or 0, got %08x\n", *(buf + 8));
385 /* Transform an empty region */
386 status = GdipCreateMatrix(&matrix);
387 expect(Ok, status);
388 status = GdipTransformRegion(region, matrix);
389 expect(Ok, status);
390 GdipDeleteMatrix(matrix);
392 status = GdipDeleteRegion(region);
393 expect(Ok, status);
395 /* Test a simple triangle of INTs */
396 status = GdipAddPathLine(path, 5, 6, 7, 8);
397 expect(Ok, status);
398 status = GdipAddPathLine(path, 8, 1, 5, 6);
399 expect(Ok, status);
400 status = GdipClosePathFigure(path);
401 expect(Ok, status);
402 status = GdipCreateRegionPath(path, &region);
403 expect(Ok, status);
404 status = GdipGetRegionDataSize(region, &needed);
405 expect(Ok, status);
406 expect(56, needed);
407 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
408 expect(Ok, status);
409 expect(56, needed);
410 expect_dword(buf, 48);
411 trace("buf[1] = %08x\n", buf[1]);
412 expect_magic(buf + 2);
413 expect_dword(buf + 3 , 0);
414 expect_dword(buf + 4 , RGNDATA_PATH);
415 expect_dword(buf + 5, 32);
416 expect_magic(buf + 6);
417 expect_dword(buf + 7, 4);
418 /* flags 0x4000 means that a path is an array of shorts instead of FLOATs */
419 expect_dword(buf + 8, 0x4000);
421 point = (RegionDataPoint*)(buf + 9);
422 expect(5, point[0].X);
423 expect(6, point[0].Y);
424 expect(7, point[1].X); /* buf + 10 */
425 expect(8, point[1].Y);
426 expect(8, point[2].X); /* buf + 11 */
427 expect(1, point[2].Y);
428 expect(5, point[3].X); /* buf + 12 */
429 expect(6, point[3].Y);
430 expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
432 status = GdipTranslateRegion(region, 0.6, 0.8);
433 expect(Ok, status);
434 memset(buf, 0, sizeof(buf));
435 needed = 0;
436 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
437 expect(Ok, status);
438 expect(72, needed);
439 expect_dword(buf, 64);
440 expect_magic(buf + 2);
441 expect_dword(buf + 3 , 0);
442 expect_dword(buf + 4 , RGNDATA_PATH);
443 expect_dword(buf + 5, 48);
444 expect_magic(buf + 6);
445 expect_dword(buf + 7, 4);
446 /* flags 0 means that a path is an array of FLOATs */
447 expect_dword(buf + 8, 0);
448 expect_float(buf + 9, 5.6);
449 expect_float(buf + 10, 6.8);
450 expect_float(buf + 11, 7.6);
451 expect_float(buf + 12, 8.8);
452 expect_float(buf + 13, 8.6);
453 expect_float(buf + 14, 1.8);
454 expect_float(buf + 15, 5.6);
455 expect_float(buf + 16, 6.8);
456 expect_dword(buf + 17, 0x81010100); /* 0x01010100 if we don't close the path */
458 status = GdipDeletePath(path);
459 expect(Ok, status);
460 status = GdipDeleteRegion(region);
461 expect(Ok, status);
463 /* Test a floating-point triangle */
464 status = GdipCreatePath(FillModeAlternate, &path);
465 expect(Ok, status);
466 status = GdipAddPathLine(path, 5.6, 6.2, 7.2, 8.9);
467 expect(Ok, status);
468 status = GdipAddPathLine(path, 8.1, 1.6, 5.6, 6.2);
469 expect(Ok, status);
470 status = GdipCreateRegionPath(path, &region);
471 expect(Ok, status);
472 status = GdipGetRegionDataSize(region, &needed);
473 expect(Ok, status);
474 expect(72, needed);
475 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
476 expect(Ok, status);
477 expect(72, needed);
478 expect_dword(buf, 64);
479 trace("buf[1] = %08x\n", buf[1]);
480 expect_magic(buf + 2);
481 expect_dword(buf + 3, 0);
482 expect_dword(buf + 4, RGNDATA_PATH);
484 expect_dword(buf + 5, 48);
485 expect_magic(buf + 6);
486 expect_dword(buf + 7, 4);
487 expect_dword(buf + 8, 0);
488 expect_float(buf + 9, 5.6);
489 expect_float(buf + 10, 6.2);
490 expect_float(buf + 11, 7.2);
491 expect_float(buf + 12, 8.9);
492 expect_float(buf + 13, 8.1);
493 expect_float(buf + 14, 1.6);
494 expect_float(buf + 15, 5.6);
495 expect_float(buf + 16, 6.2);
497 status = GdipDeletePath(path);
498 expect(Ok, status);
499 status = GdipDeleteRegion(region);
500 expect(Ok, status);
502 /* Test for a path with > 4 points, and CombineRegionPath */
503 GdipCreatePath(FillModeAlternate, &path);
504 status = GdipAddPathLine(path, 50, 70.2, 60, 102.8);
505 expect(Ok, status);
506 status = GdipAddPathLine(path, 55.4, 122.4, 40.4, 60.2);
507 expect(Ok, status);
508 status = GdipAddPathLine(path, 45.6, 20.2, 50, 70.2);
509 expect(Ok, status);
510 rect.X = 20;
511 rect.Y = 25;
512 rect.Width = 60;
513 rect.Height = 120;
514 status = GdipCreateRegionRectI(&rect, &region);
515 expect(Ok, status);
516 status = GdipCombineRegionPath(region, path, CombineModeUnion);
517 expect(Ok, status);
519 status = GdipGetRegionDataSize(region, &needed);
520 expect(Ok, status);
521 expect(116, needed);
522 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
523 expect(Ok, status);
524 expect(116, needed);
525 expect_dword(buf, 108);
526 trace("buf[1] = %08x\n", buf[1]);
527 expect_magic(buf + 2);
528 expect_dword(buf + 3, 2);
529 expect_dword(buf + 4, CombineModeUnion);
530 expect_dword(buf + 5, RGNDATA_RECT);
531 expect_float(buf + 6, 20.0);
532 expect_float(buf + 7, 25.0);
533 expect_float(buf + 8, 60.0);
534 expect_float(buf + 9, 120.0);
535 expect_dword(buf + 10, RGNDATA_PATH);
537 expect_dword(buf + 11, 68);
538 expect_magic(buf + 12);
539 expect_dword(buf + 13, 6);
540 expect_float(buf + 14, 0.0);
542 expect_float(buf + 15, 50.0);
543 expect_float(buf + 16, 70.2);
544 expect_float(buf + 17, 60.0);
545 expect_float(buf + 18, 102.8);
546 expect_float(buf + 19, 55.4);
547 expect_float(buf + 20, 122.4);
548 expect_float(buf + 21, 40.4);
549 expect_float(buf + 22, 60.2);
550 expect_float(buf + 23, 45.6);
551 expect_float(buf + 24, 20.2);
552 expect_float(buf + 25, 50.0);
553 expect_float(buf + 26, 70.2);
554 expect_dword(buf + 27, 0x01010100);
555 ok(*(buf + 28) == 0x00000101 || *(buf + 28) == 0x43050101 /* Win 7 */,
556 "expected 00000101 or 43050101 got %08x\n", *(buf + 28));
558 status = GdipDeletePath(path);
559 expect(Ok, status);
560 status = GdipDeleteRegion(region);
561 expect(Ok, status);
563 /* Test how shorts are stored in the region path data */
564 status = GdipCreatePath(FillModeAlternate, &path);
565 ok(status == Ok, "status %08x\n", status);
566 GdipAddPathRectangleI(path, -1969, -1974, 1995, 1997);
568 status = GdipCreateRegionPath(path, &region);
569 ok(status == Ok, "status %08x\n", status);
570 needed = 0;
571 status = GdipGetRegionDataSize(region, &needed);
572 ok(status == Ok, "status %08x\n", status);
573 expect(56, needed);
574 memset(buf, 0xee, sizeof(buf));
575 needed = 0;
576 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
577 ok(status == Ok, "status %08x\n", status);
578 expect(56, needed);
579 expect_dword(buf, 48);
580 trace("buf[1] = %08x\n", buf[1]);
581 expect_magic(buf + 2);
582 expect_dword(buf + 3, 0);
583 expect_dword(buf + 4, RGNDATA_PATH);
584 expect_dword(buf + 5, 32);
585 expect_magic(buf + 6);
586 expect_dword(buf + 7, 4);
587 /* flags 0x4000 means that a path is an array of shorts instead of FLOATs */
588 expect_dword(buf + 8, 0x4000);
589 point = (RegionDataPoint*)(buf + 9);
590 expect(-1969, point[0].X);
591 expect(-1974, point[0].Y);
592 expect(26, point[1].X); /* buf + 10 */
593 expect(-1974, point[1].Y);
594 expect(26, point[2].X); /* buf + 11 */
595 expect(23, point[2].Y);
596 expect(-1969, point[3].X); /* buf + 12 */
597 expect(23, point[3].Y);
598 expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
600 status = GdipDeletePath(path);
601 expect(Ok, status);
602 status = GdipDeleteRegion(region);
603 expect(Ok, status);
605 /* Test with integers that can't be stored as shorts */
606 status = GdipCreatePath(FillModeAlternate, &path);
607 ok(status == Ok, "status %08x\n", status);
608 GdipAddPathRectangleI(path, -196900, -197400, 199500, 199700);
610 status = GdipCreateRegionPath(path, &region);
611 ok(status == Ok, "status %08x\n", status);
612 needed = 0;
613 status = GdipGetRegionDataSize(region, &needed);
614 ok(status == Ok, "status %08x\n", status);
615 expect(72, needed);
616 memset(buf, 0xee, sizeof(buf));
617 needed = 0;
618 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
619 ok(status == Ok, "status %08x\n", status);
620 expect(72, needed);
621 expect_dword(buf, 64);
622 trace("buf[1] = %08x\n", buf[1]);
623 expect_magic(buf + 2);
624 expect_dword(buf + 3, 0);
625 expect_dword(buf + 4, RGNDATA_PATH);
626 expect_dword(buf + 5, 48);
627 expect_magic(buf + 6);
628 expect_dword(buf + 7, 4);
629 /* flags 0 means that a path is an array of FLOATs */
630 expect_dword(buf + 8, 0);
631 expect_float(buf + 9, -196900.0);
632 expect_float(buf + 10, -197400.0);
633 expect_float(buf + 11, 2600.0);
634 expect_float(buf + 12, -197400.0);
635 expect_float(buf + 13, 2600.0);
636 expect_float(buf + 14, 2300.0);
637 expect_float(buf + 15, -196900.0);
638 expect_float(buf + 16, 2300.0);
639 expect_dword(buf + 17, 0x81010100); /* 0x01010100 if we don't close the path */
641 status = GdipDeletePath(path);
642 expect(Ok, status);
643 status = GdipDeleteRegion(region);
644 expect(Ok, status);
647 static void test_isinfinite(void)
649 GpStatus status;
650 GpRegion *region;
651 GpGraphics *graphics = NULL;
652 GpMatrix *m;
653 HDC hdc = GetDC(0);
654 BOOL res;
656 status = GdipCreateFromHDC(hdc, &graphics);
657 expect(Ok, status);
658 GdipCreateRegion(&region);
660 GdipCreateMatrix2(3.0, 0.0, 0.0, 1.0, 20.0, 30.0, &m);
662 /* NULL arguments */
663 status = GdipIsInfiniteRegion(NULL, NULL, NULL);
664 expect(InvalidParameter, status);
665 status = GdipIsInfiniteRegion(region, NULL, NULL);
666 expect(InvalidParameter, status);
667 status = GdipIsInfiniteRegion(NULL, graphics, NULL);
668 expect(InvalidParameter, status);
669 status = GdipIsInfiniteRegion(NULL, NULL, &res);
670 expect(InvalidParameter, status);
671 status = GdipIsInfiniteRegion(region, NULL, &res);
672 expect(InvalidParameter, status);
674 res = FALSE;
675 status = GdipIsInfiniteRegion(region, graphics, &res);
676 expect(Ok, status);
677 expect(TRUE, res);
679 /* after world transform */
680 status = GdipSetWorldTransform(graphics, m);
681 expect(Ok, status);
683 res = FALSE;
684 status = GdipIsInfiniteRegion(region, graphics, &res);
685 expect(Ok, status);
686 expect(TRUE, res);
688 GdipDeleteMatrix(m);
689 GdipDeleteRegion(region);
690 GdipDeleteGraphics(graphics);
691 ReleaseDC(0, hdc);
694 static void test_isempty(void)
696 GpStatus status;
697 GpRegion *region;
698 GpGraphics *graphics = NULL;
699 HDC hdc = GetDC(0);
700 BOOL res;
702 status = GdipCreateFromHDC(hdc, &graphics);
703 expect(Ok, status);
704 GdipCreateRegion(&region);
706 /* NULL arguments */
707 status = GdipIsEmptyRegion(NULL, NULL, NULL);
708 expect(InvalidParameter, status);
709 status = GdipIsEmptyRegion(region, NULL, NULL);
710 expect(InvalidParameter, status);
711 status = GdipIsEmptyRegion(NULL, graphics, NULL);
712 expect(InvalidParameter, status);
713 status = GdipIsEmptyRegion(NULL, NULL, &res);
714 expect(InvalidParameter, status);
715 status = GdipIsEmptyRegion(region, NULL, &res);
716 expect(InvalidParameter, status);
718 /* default is infinite */
719 res = TRUE;
720 status = GdipIsEmptyRegion(region, graphics, &res);
721 expect(Ok, status);
722 expect(FALSE, res);
724 status = GdipSetEmpty(region);
725 expect(Ok, status);
727 res = FALSE;
728 status = GdipIsEmptyRegion(region, graphics, &res);
729 expect(Ok, status);
730 expect(TRUE, res);
732 GdipDeleteRegion(region);
733 GdipDeleteGraphics(graphics);
734 ReleaseDC(0, hdc);
737 static void test_combinereplace(void)
739 GpStatus status;
740 GpRegion *region, *region2;
741 GpPath *path;
742 GpRectF rectf;
743 UINT needed;
744 DWORD buf[50];
746 rectf.X = rectf.Y = 0.0;
747 rectf.Width = rectf.Height = 100.0;
749 status = GdipCreateRegionRect(&rectf, &region);
750 expect(Ok, status);
752 /* replace with the same rectangle */
753 status = GdipCombineRegionRect(region, &rectf,CombineModeReplace);
754 expect(Ok, status);
756 status = GdipGetRegionDataSize(region, &needed);
757 expect(Ok, status);
758 expect(36, needed);
759 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
760 expect(Ok, status);
761 expect(36, needed);
762 expect_dword(buf, 28);
763 trace("buf[1] = %08x\n", buf[1]);
764 expect_magic(buf + 2);
765 expect_dword(buf + 3, 0);
766 expect_dword(buf + 4, RGNDATA_RECT);
768 /* replace with path */
769 status = GdipCreatePath(FillModeAlternate, &path);
770 expect(Ok, status);
771 status = GdipAddPathEllipse(path, 0.0, 0.0, 100.0, 250.0);
772 expect(Ok, status);
773 status = GdipCombineRegionPath(region, path, CombineModeReplace);
774 expect(Ok, status);
776 status = GdipGetRegionDataSize(region, &needed);
777 expect(Ok, status);
778 expect(156, needed);
779 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
780 expect(Ok, status);
781 expect(156, needed);
782 expect_dword(buf, 148);
783 trace("buf[1] = %08x\n", buf[1]);
784 expect_magic(buf + 2);
785 expect_dword(buf + 3, 0);
786 expect_dword(buf + 4, RGNDATA_PATH);
787 GdipDeletePath(path);
789 /* replace with infinite rect */
790 status = GdipCreateRegion(&region2);
791 expect(Ok, status);
792 status = GdipCombineRegionRegion(region, region2, CombineModeReplace);
793 expect(Ok, status);
795 status = GdipGetRegionDataSize(region, &needed);
796 expect(Ok, status);
797 expect(20, needed);
798 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
799 expect(Ok, status);
800 expect(20, needed);
801 expect_dword(buf, 12);
802 trace("buf[1] = %08x\n", buf[1]);
803 expect_magic(buf + 2);
804 expect_dword(buf + 3, 0);
805 expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
806 GdipDeleteRegion(region2);
808 /* more complex case : replace with a combined region */
809 status = GdipCreateRegionRect(&rectf, &region2);
810 expect(Ok, status);
811 status = GdipCreatePath(FillModeAlternate, &path);
812 expect(Ok, status);
813 status = GdipAddPathEllipse(path, 0.0, 0.0, 100.0, 250.0);
814 expect(Ok, status);
815 status = GdipCombineRegionPath(region2, path, CombineModeUnion);
816 expect(Ok, status);
817 GdipDeletePath(path);
818 status = GdipCombineRegionRegion(region, region2, CombineModeReplace);
819 expect(Ok, status);
820 GdipDeleteRegion(region2);
822 status = GdipGetRegionDataSize(region, &needed);
823 expect(Ok, status);
824 expect(180, needed);
825 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
826 expect(Ok, status);
827 expect(180, needed);
828 expect_dword(buf, 172);
829 trace("buf[1] = %08x\n", buf[1]);
830 expect_magic(buf + 2);
831 expect_dword(buf + 3, 2);
832 expect_dword(buf + 4, CombineModeUnion);
834 GdipDeleteRegion(region);
837 static void test_fromhrgn(void)
839 GpStatus status;
840 GpRegion *region = (GpRegion*)0xabcdef01;
841 HRGN hrgn;
842 UINT needed;
843 DWORD buf[220];
844 RegionDataPoint *point;
845 GpGraphics *graphics = NULL;
846 HDC hdc;
847 BOOL res;
849 /* NULL */
850 status = GdipCreateRegionHrgn(NULL, NULL);
851 expect(InvalidParameter, status);
852 status = GdipCreateRegionHrgn(NULL, &region);
853 expect(InvalidParameter, status);
854 status = GdipCreateRegionHrgn((HRGN)0xdeadbeef, &region);
855 expect(InvalidParameter, status);
856 ok(region == (GpRegion*)0xabcdef01, "Expected region not to be created\n");
858 /* empty rectangle */
859 hrgn = CreateRectRgn(0, 0, 0, 0);
860 status = GdipCreateRegionHrgn(hrgn, &region);
861 expect(Ok, status);
862 if(status == Ok) {
864 hdc = GetDC(0);
865 status = GdipCreateFromHDC(hdc, &graphics);
866 expect(Ok, status);
867 res = FALSE;
868 status = GdipIsEmptyRegion(region, graphics, &res);
869 expect(Ok, status);
870 expect(TRUE, res);
871 GdipDeleteGraphics(graphics);
872 ReleaseDC(0, hdc);
873 GdipDeleteRegion(region);
876 DeleteObject(hrgn);
878 /* rectangle */
879 hrgn = CreateRectRgn(0, 0, 100, 10);
880 status = GdipCreateRegionHrgn(hrgn, &region);
881 expect(Ok, status);
883 status = GdipGetRegionDataSize(region, &needed);
884 expect(Ok, status);
885 expect(56, needed);
887 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
888 expect(Ok, status);
890 if(status == Ok){
892 expect(56, needed);
893 expect_dword(buf, 48);
894 expect_magic(buf + 2);
895 expect_dword(buf + 3, 0);
896 expect_dword(buf + 4, RGNDATA_PATH);
897 expect_dword(buf + 5, 0x00000020);
898 expect_magic(buf + 6);
899 expect_dword(buf + 7, 0x00000004);
900 todo_wine expect_dword(buf + 8, 0x00006000); /* ?? */
902 point = (RegionDataPoint*)buf + 9;
904 expect(0, point[0].X);
905 expect(0, point[0].Y);
907 expect(100,point[1].X); /* buf + 10 */
908 expect(0, point[1].Y);
909 expect(100,point[2].X); /* buf + 11 */
910 expect(10, point[2].Y);
912 expect(0, point[3].X); /* buf + 12 */
914 expect(10, point[3].Y);
915 expect_dword(buf + 13, 0x81010100); /* closed */
919 GdipDeleteRegion(region);
920 DeleteObject(hrgn);
922 /* ellipse */
923 hrgn = CreateEllipticRgn(0, 0, 100, 10);
924 status = GdipCreateRegionHrgn(hrgn, &region);
925 expect(Ok, status);
927 status = GdipGetRegionDataSize(region, &needed);
928 expect(Ok, status);
929 ok(needed == 216 ||
930 needed == 196, /* win98 */
931 "Got %.8x\n", needed);
933 status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
934 expect(Ok, status);
936 if(status == Ok && needed == 216) /* Don't try to test win98 layout */
938 expect(Ok, status);
939 expect(216, needed);
940 expect_dword(buf, 208);
941 expect_magic(buf + 2);
942 expect_dword(buf + 3, 0);
943 expect_dword(buf + 4, RGNDATA_PATH);
944 expect_dword(buf + 5, 0x000000C0);
945 expect_magic(buf + 6);
946 expect_dword(buf + 7, 0x00000024);
947 todo_wine expect_dword(buf + 8, 0x00006000); /* ?? */
950 GdipDeleteRegion(region);
951 DeleteObject(hrgn);
954 static void test_gethrgn(void)
956 GpStatus status;
957 GpRegion *region, *region2;
958 GpPath *path;
959 GpGraphics *graphics;
960 HRGN hrgn;
961 HDC hdc=GetDC(0);
962 static const RECT empty_rect = {0,0,0,0};
963 static const RECT test_rect = {10, 11, 20, 21};
964 static const GpRectF test_rectF = {10.0, 11.0, 10.0, 10.0};
965 static const RECT scaled_rect = {20, 22, 40, 42};
966 static const RECT test_rect2 = {10, 21, 20, 31};
967 static const GpRectF test_rect2F = {10.0, 21.0, 10.0, 10.0};
968 static const RECT test_rect3 = {10, 11, 20, 31};
969 static const GpRectF test_rect3F = {10.0, 11.0, 10.0, 20.0};
971 status = GdipCreateFromHDC(hdc, &graphics);
972 ok(status == Ok, "status %08x\n", status);
974 status = GdipCreateRegion(&region);
975 ok(status == Ok, "status %08x\n", status);
977 status = GdipGetRegionHRgn(NULL, graphics, &hrgn);
978 ok(status == InvalidParameter, "status %08x\n", status);
979 status = GdipGetRegionHRgn(region, graphics, NULL);
980 ok(status == InvalidParameter, "status %08x\n", status);
982 status = GdipGetRegionHRgn(region, NULL, &hrgn);
983 ok(status == Ok, "status %08x\n", status);
984 ok(hrgn == NULL, "hrgn=%p\n", hrgn);
986 status = GdipGetRegionHRgn(region, graphics, &hrgn);
987 ok(status == Ok, "status %08x\n", status);
988 ok(hrgn == NULL, "hrgn=%p\n", hrgn);
990 status = GdipSetEmpty(region);
991 ok(status == Ok, "status %08x\n", status);
992 status = GdipGetRegionHRgn(region, NULL, &hrgn);
993 ok(status == Ok, "status %08x\n", status);
994 verify_region(hrgn, &empty_rect);
995 DeleteObject(hrgn);
997 status = GdipCreatePath(FillModeAlternate, &path);
998 ok(status == Ok, "status %08x\n", status);
999 status = GdipAddPathRectangle(path, 10.0, 11.0, 10.0, 10.0);
1000 ok(status == Ok, "status %08x\n", status);
1002 status = GdipCreateRegionPath(path, &region2);
1003 ok(status == Ok, "status %08x\n", status);
1004 status = GdipGetRegionHRgn(region2, NULL, &hrgn);
1005 ok(status == Ok, "status %08x\n", status);
1006 verify_region(hrgn, &test_rect);
1007 DeleteObject(hrgn);
1009 /* resulting HRGN is in device coordinates */
1010 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
1011 ok(status == Ok, "status %08x\n", status);
1012 status = GdipGetRegionHRgn(region2, graphics, &hrgn);
1013 ok(status == Ok, "status %08x\n", status);
1014 verify_region(hrgn, &scaled_rect);
1015 DeleteObject(hrgn);
1017 status = GdipCombineRegionRect(region2, &test_rectF, CombineModeReplace);
1018 ok(status == Ok, "status %08x\n", status);
1019 status = GdipGetRegionHRgn(region2, NULL, &hrgn);
1020 ok(status == Ok, "status %08x\n", status);
1021 verify_region(hrgn, &test_rect);
1022 DeleteObject(hrgn);
1024 status = GdipGetRegionHRgn(region2, graphics, &hrgn);
1025 ok(status == Ok, "status %08x\n", status);
1026 verify_region(hrgn, &scaled_rect);
1027 DeleteObject(hrgn);
1029 status = GdipSetInfinite(region);
1030 ok(status == Ok, "status %08x\n", status);
1031 status = GdipCombineRegionRect(region, &test_rectF, CombineModeIntersect);
1032 ok(status == Ok, "status %08x\n", status);
1033 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1034 ok(status == Ok, "status %08x\n", status);
1035 verify_region(hrgn, &test_rect);
1036 DeleteObject(hrgn);
1038 status = GdipCombineRegionRect(region, &test_rectF, CombineModeReplace);
1039 ok(status == Ok, "status %08x\n", status);
1040 status = GdipCombineRegionRect(region, &test_rect2F, CombineModeUnion);
1041 ok(status == Ok, "status %08x\n", status);
1042 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1043 ok(status == Ok, "status %08x\n", status);
1044 verify_region(hrgn, &test_rect3);
1045 DeleteObject(hrgn);
1047 status = GdipCombineRegionRect(region, &test_rect3F, CombineModeReplace);
1048 ok(status == Ok, "status %08x\n", status);
1049 status = GdipCombineRegionRect(region, &test_rect2F, CombineModeXor);
1050 ok(status == Ok, "status %08x\n", status);
1051 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1052 ok(status == Ok, "status %08x\n", status);
1053 verify_region(hrgn, &test_rect);
1054 DeleteObject(hrgn);
1056 status = GdipCombineRegionRect(region, &test_rect3F, CombineModeReplace);
1057 ok(status == Ok, "status %08x\n", status);
1058 status = GdipCombineRegionRect(region, &test_rectF, CombineModeExclude);
1059 ok(status == Ok, "status %08x\n", status);
1060 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1061 ok(status == Ok, "status %08x\n", status);
1062 verify_region(hrgn, &test_rect2);
1063 DeleteObject(hrgn);
1065 status = GdipCombineRegionRect(region, &test_rectF, CombineModeReplace);
1066 ok(status == Ok, "status %08x\n", status);
1067 status = GdipCombineRegionRect(region, &test_rect3F, CombineModeComplement);
1068 ok(status == Ok, "status %08x\n", status);
1069 status = GdipGetRegionHRgn(region, NULL, &hrgn);
1070 ok(status == Ok, "status %08x\n", status);
1071 verify_region(hrgn, &test_rect2);
1072 DeleteObject(hrgn);
1074 status = GdipDeletePath(path);
1075 ok(status == Ok, "status %08x\n", status);
1076 status = GdipDeleteRegion(region);
1077 ok(status == Ok, "status %08x\n", status);
1078 status = GdipDeleteRegion(region2);
1079 ok(status == Ok, "status %08x\n", status);
1080 status = GdipDeleteGraphics(graphics);
1081 ok(status == Ok, "status %08x\n", status);
1082 ReleaseDC(0, hdc);
1085 static void test_isequal(void)
1087 GpRegion *region1, *region2;
1088 GpGraphics *graphics;
1089 GpRectF rectf;
1090 GpStatus status;
1091 HDC hdc = GetDC(0);
1092 BOOL res;
1094 status = GdipCreateFromHDC(hdc, &graphics);
1095 ok(status == Ok, "status %08x\n", status);
1097 status = GdipCreateRegion(&region1);
1098 ok(status == Ok, "status %08x\n", status);
1099 status = GdipCreateRegion(&region2);
1100 ok(status == Ok, "status %08x\n", status);
1102 /* NULL */
1103 status = GdipIsEqualRegion(NULL, NULL, NULL, NULL);
1104 ok(status == InvalidParameter, "status %08x\n", status);
1105 status = GdipIsEqualRegion(region1, region2, NULL, NULL);
1106 ok(status == InvalidParameter, "status %08x\n", status);
1107 status = GdipIsEqualRegion(region1, region2, graphics, NULL);
1108 ok(status == InvalidParameter, "status %08x\n", status);
1109 status = GdipIsEqualRegion(region1, region2, NULL, &res);
1110 ok(status == InvalidParameter, "status %08x\n", status);
1112 /* infinite regions */
1113 res = FALSE;
1114 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1115 ok(status == Ok, "status %08x\n", status);
1116 ok(res, "Expected to be equal.\n");
1117 /* empty regions */
1118 status = GdipSetEmpty(region1);
1119 ok(status == Ok, "status %08x\n", status);
1120 status = GdipSetEmpty(region2);
1121 ok(status == Ok, "status %08x\n", status);
1122 res = FALSE;
1123 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1124 ok(status == Ok, "status %08x\n", status);
1125 ok(res, "Expected to be equal.\n");
1126 /* empty & infinite */
1127 status = GdipSetInfinite(region1);
1128 ok(status == Ok, "status %08x\n", status);
1129 res = TRUE;
1130 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1131 ok(status == Ok, "status %08x\n", status);
1132 ok(!res, "Expected to be unequal.\n");
1133 /* rect & (inf/empty) */
1134 rectf.X = rectf.Y = 0.0;
1135 rectf.Width = rectf.Height = 100.0;
1136 status = GdipCombineRegionRect(region1, &rectf, CombineModeReplace);
1137 ok(status == Ok, "status %08x\n", status);
1138 res = TRUE;
1139 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1140 ok(status == Ok, "status %08x\n", status);
1141 ok(!res, "Expected to be unequal.\n");
1142 status = GdipSetInfinite(region2);
1143 ok(status == Ok, "status %08x\n", status);
1144 res = TRUE;
1145 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1146 ok(status == Ok, "status %08x\n", status);
1147 ok(!res, "Expected to be unequal.\n");
1148 /* roughly equal rectangles */
1149 rectf.X = rectf.Y = 0.0;
1150 rectf.Width = rectf.Height = 100.001;
1151 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1152 ok(status == Ok, "status %08x\n", status);
1153 res = FALSE;
1154 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1155 ok(status == Ok, "status %08x\n", status);
1156 ok(res, "Expected to be equal.\n");
1157 /* equal rectangles */
1158 rectf.X = rectf.Y = 0.0;
1159 rectf.Width = rectf.Height = 100.0;
1160 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1161 ok(status == Ok, "status %08x\n", status);
1162 res = FALSE;
1163 status = GdipIsEqualRegion(region1, region2, graphics, &res);
1164 ok(status == Ok, "status %08x\n", status);
1165 ok(res, "Expected to be equal.\n");
1167 /* cleanup */
1168 status = GdipDeleteRegion(region1);
1169 ok(status == Ok, "status %08x\n", status);
1170 status = GdipDeleteRegion(region2);
1171 ok(status == Ok, "status %08x\n", status);
1172 status = GdipDeleteGraphics(graphics);
1173 ok(status == Ok, "status %08x\n", status);
1174 ReleaseDC(0, hdc);
1177 static void test_translate(void)
1179 GpRegion *region, *region2;
1180 GpGraphics *graphics;
1181 GpPath *path;
1182 GpRectF rectf;
1183 GpStatus status;
1184 HDC hdc = GetDC(0);
1185 BOOL res;
1187 status = GdipCreateFromHDC(hdc, &graphics);
1188 ok(status == Ok, "status %08x\n", status);
1190 status = GdipCreatePath(FillModeAlternate, &path);
1191 ok(status == Ok, "status %08x\n", status);
1193 status = GdipCreateRegion(&region);
1194 ok(status == Ok, "status %08x\n", status);
1195 status = GdipCreateRegion(&region2);
1196 ok(status == Ok, "status %08x\n", status);
1198 /* NULL */
1199 status = GdipTranslateRegion(NULL, 0.0, 0.0);
1200 ok(status == InvalidParameter, "status %08x\n", status);
1202 /* infinite */
1203 status = GdipTranslateRegion(region, 10.0, 10.0);
1204 ok(status == Ok, "status %08x\n", status);
1205 /* empty */
1206 status = GdipSetEmpty(region);
1207 ok(status == Ok, "status %08x\n", status);
1208 status = GdipTranslateRegion(region, 10.0, 10.0);
1209 ok(status == Ok, "status %08x\n", status);
1210 /* rect */
1211 rectf.X = 10.0; rectf.Y = 0.0;
1212 rectf.Width = rectf.Height = 100.0;
1213 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1214 ok(status == Ok, "status %08x\n", status);
1215 rectf.X = 15.0; rectf.Y = -2.0;
1216 rectf.Width = rectf.Height = 100.0;
1217 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1218 ok(status == Ok, "status %08x\n", status);
1219 status = GdipTranslateRegion(region, 5.0, -2.0);
1220 ok(status == Ok, "status %08x\n", status);
1221 res = FALSE;
1222 status = GdipIsEqualRegion(region, region2, graphics, &res);
1223 ok(status == Ok, "status %08x\n", status);
1224 ok(res, "Expected to be equal.\n");
1225 /* path */
1226 status = GdipAddPathEllipse(path, 0.0, 10.0, 100.0, 150.0);
1227 ok(status == Ok, "status %08x\n", status);
1228 status = GdipCombineRegionPath(region, path, CombineModeReplace);
1229 ok(status == Ok, "status %08x\n", status);
1230 status = GdipResetPath(path);
1231 ok(status == Ok, "status %08x\n", status);
1232 status = GdipAddPathEllipse(path, 10.0, 21.0, 100.0, 150.0);
1233 ok(status == Ok, "status %08x\n", status);
1234 status = GdipCombineRegionPath(region2, path, CombineModeReplace);
1235 ok(status == Ok, "status %08x\n", status);
1236 status = GdipTranslateRegion(region, 10.0, 11.0);
1237 ok(status == Ok, "status %08x\n", status);
1238 res = FALSE;
1239 status = GdipIsEqualRegion(region, region2, graphics, &res);
1240 ok(status == Ok, "status %08x\n", status);
1241 ok(res, "Expected to be equal.\n");
1243 status = GdipDeleteRegion(region);
1244 ok(status == Ok, "status %08x\n", status);
1245 status = GdipDeleteRegion(region2);
1246 ok(status == Ok, "status %08x\n", status);
1247 status = GdipDeleteGraphics(graphics);
1248 ok(status == Ok, "status %08x\n", status);
1249 status = GdipDeletePath(path);
1250 ok(status == Ok, "status %08x\n", status);
1251 ReleaseDC(0, hdc);
1254 static void test_transform(void)
1256 GpRegion *region, *region2;
1257 GpMatrix *matrix;
1258 GpGraphics *graphics;
1259 GpPath *path;
1260 GpRectF rectf;
1261 GpStatus status;
1262 HDC hdc = GetDC(0);
1263 BOOL res;
1265 status = GdipCreateFromHDC(hdc, &graphics);
1266 expect(Ok, status);
1268 status = GdipCreatePath(FillModeAlternate, &path);
1269 expect(Ok, status);
1271 status = GdipCreateRegion(&region);
1272 expect(Ok, status);
1273 status = GdipCreateRegion(&region2);
1274 expect(Ok, status);
1276 status = GdipCreateMatrix(&matrix);
1277 expect(Ok, status);
1278 status = GdipScaleMatrix(matrix, 2.0, 3.0, MatrixOrderAppend);
1279 expect(Ok, status);
1281 /* NULL */
1282 status = GdipTransformRegion(NULL, matrix);
1283 expect(InvalidParameter, status);
1285 status = GdipTransformRegion(region, NULL);
1286 expect(InvalidParameter, status);
1288 /* infinite */
1289 status = GdipTransformRegion(region, matrix);
1290 expect(Ok, status);
1292 res = FALSE;
1293 status = GdipIsEqualRegion(region, region2, graphics, &res);
1294 expect(Ok, status);
1295 ok(res, "Expected to be equal.\n");
1297 /* empty */
1298 status = GdipSetEmpty(region);
1299 expect(Ok, status);
1300 status = GdipTransformRegion(region, matrix);
1301 expect(Ok, status);
1303 status = GdipSetEmpty(region2);
1304 expect(Ok, status);
1306 res = FALSE;
1307 status = GdipIsEqualRegion(region, region2, graphics, &res);
1308 expect(Ok, status);
1309 ok(res, "Expected to be equal.\n");
1311 /* rect */
1312 rectf.X = 10.0;
1313 rectf.Y = 0.0;
1314 rectf.Width = rectf.Height = 100.0;
1315 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1316 expect(Ok, status);
1317 rectf.X = 20.0;
1318 rectf.Y = 0.0;
1319 rectf.Width = 200.0;
1320 rectf.Height = 300.0;
1321 status = GdipCombineRegionRect(region2, &rectf, CombineModeReplace);
1322 expect(Ok, status);
1323 status = GdipTransformRegion(region, matrix);
1324 expect(Ok, status);
1325 res = FALSE;
1326 status = GdipIsEqualRegion(region, region2, graphics, &res);
1327 expect(Ok, status);
1328 ok(res, "Expected to be equal.\n");
1330 /* path */
1331 status = GdipAddPathEllipse(path, 0.0, 10.0, 100.0, 150.0);
1332 expect(Ok, status);
1333 status = GdipCombineRegionPath(region, path, CombineModeReplace);
1334 expect(Ok, status);
1335 status = GdipResetPath(path);
1336 expect(Ok, status);
1337 status = GdipAddPathEllipse(path, 0.0, 30.0, 200.0, 450.0);
1338 expect(Ok, status);
1339 status = GdipCombineRegionPath(region2, path, CombineModeReplace);
1340 expect(Ok, status);
1341 status = GdipTransformRegion(region, matrix);
1342 expect(Ok, status);
1343 res = FALSE;
1344 status = GdipIsEqualRegion(region, region2, graphics, &res);
1345 expect(Ok, status);
1346 ok(res, "Expected to be equal.\n");
1348 status = GdipDeleteRegion(region);
1349 expect(Ok, status);
1350 status = GdipDeleteRegion(region2);
1351 expect(Ok, status);
1352 status = GdipDeleteGraphics(graphics);
1353 expect(Ok, status);
1354 status = GdipDeletePath(path);
1355 expect(Ok, status);
1356 status = GdipDeleteMatrix(matrix);
1357 expect(Ok, status);
1358 ReleaseDC(0, hdc);
1361 static void test_scans(void)
1363 GpRegion *region;
1364 GpMatrix *matrix;
1365 GpRectF rectf;
1366 GpStatus status;
1367 ULONG count=80085;
1368 INT icount;
1369 GpRectF scans[2];
1370 GpRect scansi[2];
1372 status = GdipCreateRegion(&region);
1373 expect(Ok, status);
1375 status = GdipCreateMatrix(&matrix);
1376 expect(Ok, status);
1378 /* test NULL values */
1379 status = GdipGetRegionScansCount(NULL, &count, matrix);
1380 expect(InvalidParameter, status);
1382 status = GdipGetRegionScansCount(region, NULL, matrix);
1383 expect(InvalidParameter, status);
1385 status = GdipGetRegionScansCount(region, &count, NULL);
1386 expect(InvalidParameter, status);
1388 status = GdipGetRegionScans(NULL, scans, &icount, matrix);
1389 expect(InvalidParameter, status);
1391 status = GdipGetRegionScans(region, scans, NULL, matrix);
1392 expect(InvalidParameter, status);
1394 status = GdipGetRegionScans(region, scans, &icount, NULL);
1395 expect(InvalidParameter, status);
1397 /* infinite */
1398 status = GdipGetRegionScansCount(region, &count, matrix);
1399 expect(Ok, status);
1400 expect(1, count);
1402 status = GdipGetRegionScans(region, NULL, &icount, matrix);
1403 expect(Ok, status);
1404 expect(1, icount);
1406 status = GdipGetRegionScans(region, scans, &icount, matrix);
1407 expect(Ok, status);
1408 expect(1, icount);
1410 status = GdipGetRegionScansI(region, scansi, &icount, matrix);
1411 expect(Ok, status);
1412 expect(1, icount);
1413 expect(-0x400000, scansi[0].X);
1414 expect(-0x400000, scansi[0].Y);
1415 expect(0x800000, scansi[0].Width);
1416 expect(0x800000, scansi[0].Height);
1418 status = GdipGetRegionScans(region, scans, &icount, matrix);
1419 expect(Ok, status);
1420 expect(1, icount);
1421 expectf((double)-0x400000, scans[0].X);
1422 expectf((double)-0x400000, scans[0].Y);
1423 expectf((double)0x800000, scans[0].Width);
1424 expectf((double)0x800000, scans[0].Height);
1426 /* empty */
1427 status = GdipSetEmpty(region);
1428 expect(Ok, status);
1430 status = GdipGetRegionScansCount(region, &count, matrix);
1431 expect(Ok, status);
1432 expect(0, count);
1434 status = GdipGetRegionScans(region, scans, &icount, matrix);
1435 expect(Ok, status);
1436 expect(0, icount);
1438 /* single rectangle */
1439 rectf.X = rectf.Y = 0.0;
1440 rectf.Width = rectf.Height = 5.0;
1441 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1442 expect(Ok, status);
1444 status = GdipGetRegionScansCount(region, &count, matrix);
1445 expect(Ok, status);
1446 expect(1, count);
1448 status = GdipGetRegionScans(region, scans, &icount, matrix);
1449 expect(Ok, status);
1450 expect(1, icount);
1451 expectf(0.0, scans[0].X);
1452 expectf(0.0, scans[0].Y);
1453 expectf(5.0, scans[0].Width);
1454 expectf(5.0, scans[0].Height);
1456 /* two rectangles */
1457 rectf.X = rectf.Y = 5.0;
1458 rectf.Width = rectf.Height = 5.0;
1459 status = GdipCombineRegionRect(region, &rectf, CombineModeUnion);
1460 expect(Ok, status);
1462 status = GdipGetRegionScansCount(region, &count, matrix);
1463 expect(Ok, status);
1464 expect(2, count);
1466 /* Native ignores the initial value of count */
1467 scans[1].X = scans[1].Y = scans[1].Width = scans[1].Height = 8.0;
1468 icount = 1;
1469 status = GdipGetRegionScans(region, scans, &icount, matrix);
1470 expect(Ok, status);
1471 expect(2, icount);
1472 expectf(0.0, scans[0].X);
1473 expectf(0.0, scans[0].Y);
1474 expectf(5.0, scans[0].Width);
1475 expectf(5.0, scans[0].Height);
1476 expectf(5.0, scans[1].X);
1477 expectf(5.0, scans[1].Y);
1478 expectf(5.0, scans[1].Width);
1479 expectf(5.0, scans[1].Height);
1481 status = GdipGetRegionScansI(region, scansi, &icount, matrix);
1482 expect(Ok, status);
1483 expect(2, icount);
1484 expect(0, scansi[0].X);
1485 expect(0, scansi[0].Y);
1486 expect(5, scansi[0].Width);
1487 expect(5, scansi[0].Height);
1488 expect(5, scansi[1].X);
1489 expect(5, scansi[1].Y);
1490 expect(5, scansi[1].Width);
1491 expect(5, scansi[1].Height);
1493 status = GdipDeleteRegion(region);
1494 expect(Ok, status);
1495 status = GdipDeleteMatrix(matrix);
1496 expect(Ok, status);
1499 static void test_getbounds(void)
1501 GpRegion *region;
1502 GpGraphics *graphics;
1503 GpStatus status;
1504 GpRectF rectf;
1505 HDC hdc = GetDC(0);
1507 status = GdipCreateFromHDC(hdc, &graphics);
1508 ok(status == Ok, "status %08x\n", status);
1509 status = GdipCreateRegion(&region);
1510 ok(status == Ok, "status %08x\n", status);
1512 /* NULL */
1513 status = GdipGetRegionBounds(NULL, NULL, NULL);
1514 ok(status == InvalidParameter, "status %08x\n", status);
1515 status = GdipGetRegionBounds(region, NULL, NULL);
1516 ok(status == InvalidParameter, "status %08x\n", status);
1517 status = GdipGetRegionBounds(region, graphics, NULL);
1518 ok(status == InvalidParameter, "status %08x\n", status);
1519 /* infinite */
1520 rectf.X = rectf.Y = 0.0;
1521 rectf.Height = rectf.Width = 100.0;
1522 status = GdipGetRegionBounds(region, graphics, &rectf);
1523 ok(status == Ok, "status %08x\n", status);
1524 ok(rectf.X == -(REAL)(1 << 22), "Expected X = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.X);
1525 ok(rectf.Y == -(REAL)(1 << 22), "Expected Y = %.2f, got %.2f\n", -(REAL)(1 << 22), rectf.Y);
1526 ok(rectf.Width == (REAL)(1 << 23), "Expected width = %.2f, got %.2f\n", (REAL)(1 << 23), rectf.Width);
1527 ok(rectf.Height == (REAL)(1 << 23), "Expected height = %.2f, got %.2f\n",(REAL)(1 << 23), rectf.Height);
1528 /* empty */
1529 rectf.X = rectf.Y = 0.0;
1530 rectf.Height = rectf.Width = 100.0;
1531 status = GdipSetEmpty(region);
1532 ok(status == Ok, "status %08x\n", status);
1533 status = GdipGetRegionBounds(region, graphics, &rectf);
1534 ok(status == Ok, "status %08x\n", status);
1535 ok(rectf.X == 0.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1536 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1537 ok(rectf.Width == 0.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1538 ok(rectf.Height == 0.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1539 /* rect */
1540 rectf.X = 10.0; rectf.Y = 0.0;
1541 rectf.Width = rectf.Height = 100.0;
1542 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1543 ok(status == Ok, "status %08x\n", status);
1544 rectf.X = rectf.Y = 0.0;
1545 rectf.Height = rectf.Width = 0.0;
1546 status = GdipGetRegionBounds(region, graphics, &rectf);
1547 ok(status == Ok, "status %08x\n", status);
1548 ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1549 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1550 ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1551 ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1553 /* the world and page transforms are ignored */
1554 GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
1555 GdipSetPageUnit(graphics, UnitInch);
1556 GdipSetPageScale(graphics, 2.0);
1557 status = GdipGetRegionBounds(region, graphics, &rectf);
1558 ok(status == Ok, "status %08x\n", status);
1559 ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1560 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1561 ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1563 rectf.X = 10.0; rectf.Y = 0.0;
1564 rectf.Width = rectf.Height = 100.0;
1565 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1566 ok(status == Ok, "status %08x\n", status);
1567 rectf.X = rectf.Y = 0.0;
1568 rectf.Height = rectf.Width = 0.0;
1569 status = GdipGetRegionBounds(region, graphics, &rectf);
1570 ok(status == Ok, "status %08x\n", status);
1571 ok(rectf.X == 10.0, "Expected X = 0.0, got %.2f\n", rectf.X);
1572 ok(rectf.Y == 0.0, "Expected Y = 0.0, got %.2f\n", rectf.Y);
1573 ok(rectf.Width == 100.0, "Expected width = 0.0, got %.2f\n", rectf.Width);
1574 ok(rectf.Height == 100.0, "Expected height = 0.0, got %.2f\n", rectf.Height);
1576 status = GdipDeleteRegion(region);
1577 ok(status == Ok, "status %08x\n", status);
1578 status = GdipDeleteGraphics(graphics);
1579 ok(status == Ok, "status %08x\n", status);
1580 ReleaseDC(0, hdc);
1583 static void test_isvisiblepoint(void)
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;
1594 status = GdipCreateFromHDC(hdc, &graphics);
1595 expect(Ok, status);
1597 status = GdipCreateRegion(&region);
1598 expect(Ok, status);
1600 /* null parameters */
1601 status = GdipIsVisibleRegionPoint(NULL, 0, 0, graphics, &res);
1602 expect(InvalidParameter, status);
1603 status = GdipIsVisibleRegionPointI(NULL, 0, 0, graphics, &res);
1604 expect(InvalidParameter, status);
1606 status = GdipIsVisibleRegionPoint(region, 0, 0, NULL, &res);
1607 expect(Ok, status);
1608 status = GdipIsVisibleRegionPointI(region, 0, 0, NULL, &res);
1609 expect(Ok, status);
1611 status = GdipIsVisibleRegionPoint(region, 0, 0, graphics, NULL);
1612 expect(InvalidParameter, status);
1613 status = GdipIsVisibleRegionPointI(region, 0, 0, graphics, NULL);
1614 expect(InvalidParameter, status);
1616 /* infinite region */
1617 status = GdipIsInfiniteRegion(region, graphics, &res);
1618 expect(Ok, status);
1619 ok(res == TRUE, "Region should be infinite\n");
1621 x = 10;
1622 y = 10;
1623 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1624 expect(Ok, status);
1625 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1626 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1627 expect(Ok, status);
1628 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1630 x = -10;
1631 y = -10;
1632 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1633 expect(Ok, status);
1634 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1635 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1636 expect(Ok, status);
1637 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1639 /* rectangular region */
1640 rectf.X = 10;
1641 rectf.Y = 20;
1642 rectf.Width = 30;
1643 rectf.Height = 40;
1645 status = GdipCombineRegionRect(region, &rectf, CombineModeReplace);
1646 expect(Ok, status);
1648 x = 0;
1649 y = 0;
1650 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1651 expect(Ok, status);
1652 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1653 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1654 expect(Ok, status);
1655 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1657 x = 9;
1658 y = 19;
1659 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1660 expect(Ok, status);
1661 ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1663 x = 9.25;
1664 y = 19.25;
1665 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1666 expect(Ok, status);
1667 ok(res == FALSE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1669 x = 9.5;
1670 y = 19.5;
1671 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1672 expect(Ok, status);
1673 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1675 x = 9.75;
1676 y = 19.75;
1677 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1678 expect(Ok, status);
1679 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1681 x = 10;
1682 y = 20;
1683 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1684 expect(Ok, status);
1685 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1687 x = 25;
1688 y = 40;
1689 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1690 expect(Ok, status);
1691 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1692 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1693 expect(Ok, status);
1694 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1696 x = 40;
1697 y = 60;
1698 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1699 expect(Ok, status);
1700 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1701 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1702 expect(Ok, status);
1703 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1705 /* translate into the center of the rectangle */
1706 status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1707 expect(Ok, status);
1709 /* native ignores the world transform, so treat these as if
1710 * no transform exists */
1711 x = -20;
1712 y = -30;
1713 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1714 expect(Ok, status);
1715 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1716 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1717 expect(Ok, status);
1718 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1720 x = 0;
1721 y = 0;
1722 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1723 expect(Ok, status);
1724 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1725 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1726 expect(Ok, status);
1727 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1729 x = 25;
1730 y = 40;
1731 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1732 expect(Ok, status);
1733 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1734 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1735 expect(Ok, status);
1736 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1738 /* translate back to origin */
1739 status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1740 expect(Ok, status);
1742 /* region from path */
1743 status = GdipCreatePath(FillModeAlternate, &path);
1744 expect(Ok, status);
1746 status = GdipAddPathEllipse(path, 10, 20, 30, 40);
1747 expect(Ok, status);
1749 status = GdipCombineRegionPath(region, path, CombineModeReplace);
1750 expect(Ok, status);
1752 x = 11;
1753 y = 21;
1754 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1755 expect(Ok, status);
1756 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1757 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1758 expect(Ok, status);
1759 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1761 x = 25;
1762 y = 40;
1763 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1764 expect(Ok, status);
1765 ok(res == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1766 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1767 expect(Ok, status);
1768 ok(res == TRUE, "Expected (%d, %d) to be visible\n", (INT)x, (INT)y);
1770 x = 40;
1771 y = 60;
1772 status = GdipIsVisibleRegionPoint(region, x, y, graphics, &res);
1773 expect(Ok, status);
1774 ok(res == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1775 status = GdipIsVisibleRegionPointI(region, (INT)x, (INT)y, graphics, &res);
1776 expect(Ok, status);
1777 ok(res == FALSE, "Expected (%d, %d) not to be visible\n", (INT)x, (INT)y);
1779 GdipDeletePath(path);
1781 GdipDeleteRegion(region);
1782 GdipDeleteGraphics(graphics);
1783 ReleaseDC(0, hdc);
1786 static void test_isvisiblerect(void)
1788 HDC hdc = GetDC(0);
1789 GpGraphics* graphics;
1790 GpRegion* region;
1791 GpPath* path;
1792 GpRectF rectf;
1793 GpStatus status;
1794 BOOL res;
1795 REAL x, y, w, h;
1797 status = GdipCreateFromHDC(hdc, &graphics);
1798 expect(Ok, status);
1800 status = GdipCreateRegion(&region);
1801 expect(Ok, status);
1803 /* null parameters */
1804 status = GdipIsVisibleRegionRect(NULL, 0, 0, 0, 0, graphics, &res);
1805 expect(InvalidParameter, status);
1806 status = GdipIsVisibleRegionRectI(NULL, 0, 0, 0, 0, graphics, &res);
1807 expect(InvalidParameter, status);
1809 status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, NULL, &res);
1810 expect(Ok, status);
1811 status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, NULL, &res);
1812 expect(Ok, status);
1814 status = GdipIsVisibleRegionRect(region, 0, 0, 0, 0, graphics, NULL);
1815 expect(InvalidParameter, status);
1816 status = GdipIsVisibleRegionRectI(region, 0, 0, 0, 0, graphics, NULL);
1817 expect(InvalidParameter, status);
1819 /* infinite region */
1820 status = GdipIsInfiniteRegion(region, graphics, &res);
1821 expect(Ok, status);
1822 ok(res == TRUE, "Region should be infinite\n");
1824 x = 10; w = 10;
1825 y = 10; h = 10;
1826 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1827 expect(Ok, status);
1828 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1830 x = -10; w = 5;
1831 y = -10; h = 5;
1832 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1833 expect(Ok, status);
1834 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1836 /* rectangular region */
1837 rectf.X = 10;
1838 rectf.Y = 20;
1839 rectf.Width = 30;
1840 rectf.Height = 40;
1842 status = GdipCombineRegionRect(region, &rectf, CombineModeIntersect);
1843 expect(Ok, status);
1845 /* entirely within the region */
1846 x = 11; w = 10;
1847 y = 12; h = 10;
1848 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1849 expect(Ok, status);
1850 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1851 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1852 expect(Ok, status);
1853 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1855 /* entirely outside of the region */
1856 x = 0; w = 5;
1857 y = 0; h = 5;
1858 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1859 expect(Ok, status);
1860 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1861 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1862 expect(Ok, status);
1863 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1865 /* corner cases */
1866 x = 0; w = 10;
1867 y = 0; h = 20;
1868 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1869 expect(Ok, status);
1870 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1872 x = 0; w = 10.25;
1873 y = 0; h = 20.25;
1874 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1875 expect(Ok, status);
1876 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1878 x = 39; w = 10;
1879 y = 59; h = 10;
1880 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1881 expect(Ok, status);
1882 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1884 x = 39.25; w = 10;
1885 y = 59.25; h = 10;
1886 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1887 expect(Ok, status);
1888 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1890 /* corners outside, but some intersection */
1891 x = 0; w = 100;
1892 y = 0; h = 100;
1893 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1894 expect(Ok, status);
1895 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1897 x = 0; w = 100;
1898 y = 0; h = 40;
1899 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1900 expect(Ok, status);
1901 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1903 x = 0; w = 25;
1904 y = 0; h = 100;
1905 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1906 expect(Ok, status);
1907 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1909 /* translate into the center of the rectangle */
1910 status = GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1911 expect(Ok, status);
1913 /* native ignores the world transform, so treat these as if
1914 * no transform exists */
1915 x = 0; w = 5;
1916 y = 0; h = 5;
1917 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1918 expect(Ok, status);
1919 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1920 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1921 expect(Ok, status);
1922 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1924 x = 11; w = 10;
1925 y = 12; h = 10;
1926 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1927 expect(Ok, status);
1928 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1929 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1930 expect(Ok, status);
1931 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1933 /* translate back to origin */
1934 status = GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1935 expect(Ok, status);
1937 /* region from path */
1938 status = GdipCreatePath(FillModeAlternate, &path);
1939 expect(Ok, status);
1941 status = GdipAddPathEllipse(path, 10, 20, 30, 40);
1942 expect(Ok, status);
1944 status = GdipCombineRegionPath(region, path, CombineModeReplace);
1945 expect(Ok, status);
1947 x = 0; w = 12;
1948 y = 0; h = 22;
1949 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1950 expect(Ok, status);
1951 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1952 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1953 expect(Ok, status);
1954 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1956 x = 0; w = 25;
1957 y = 0; h = 40;
1958 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1959 expect(Ok, status);
1960 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1961 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1962 expect(Ok, status);
1963 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1965 x = 38; w = 10;
1966 y = 55; h = 10;
1967 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1968 expect(Ok, status);
1969 ok(res == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, w, h);
1970 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1971 expect(Ok, status);
1972 ok(res == FALSE, "Expected (%d, %d, %d, %d) not to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1974 x = 0; w = 100;
1975 y = 0; h = 100;
1976 status = GdipIsVisibleRegionRect(region, x, y, w, h, graphics, &res);
1977 expect(Ok, status);
1978 ok(res == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, w, h);
1979 status = GdipIsVisibleRegionRectI(region, (INT)x, (INT)y, (INT)w, (INT)h, graphics, &res);
1980 expect(Ok, status);
1981 ok(res == TRUE, "Expected (%d, %d, %d, %d) to be visible\n", (INT)x, (INT)y, (INT)w, (INT)h);
1983 GdipDeletePath(path);
1985 GdipDeleteRegion(region);
1986 GdipDeleteGraphics(graphics);
1987 ReleaseDC(0, hdc);
1990 START_TEST(region)
1992 struct GdiplusStartupInput gdiplusStartupInput;
1993 ULONG_PTR gdiplusToken;
1995 gdiplusStartupInput.GdiplusVersion = 1;
1996 gdiplusStartupInput.DebugEventCallback = NULL;
1997 gdiplusStartupInput.SuppressBackgroundThread = 0;
1998 gdiplusStartupInput.SuppressExternalCodecs = 0;
2000 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2002 test_getregiondata();
2003 test_isinfinite();
2004 test_isempty();
2005 test_combinereplace();
2006 test_fromhrgn();
2007 test_gethrgn();
2008 test_isequal();
2009 test_translate();
2010 test_transform();
2011 test_scans();
2012 test_getbounds();
2013 test_isvisiblepoint();
2014 test_isvisiblerect();
2016 GdiplusShutdown(gdiplusToken);