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