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