msi: Set all folders' source paths to the root directory if the source type is compre...
[wine] / dlls / gdiplus / tests / 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 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wingdi.h"
24 #include "wine/test.h"
25
26 #define RGNDATA_RECT            0x10000000
27 #define RGNDATA_PATH            0x10000001
28 #define RGNDATA_EMPTY_RECT      0x10000002
29 #define RGNDATA_INFINITE_RECT   0x10000003
30
31 #define RGNDATA_MAGIC           0xdbc01001
32 #define RGNDATA_MAGIC2          0xdbc01002
33
34 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
35
36 #define expect_magic(value) ok(*value == RGNDATA_MAGIC || *value == RGNDATA_MAGIC2, "Expected a known magic value, got %8x\n", *value)
37
38 static inline void expect_dword(DWORD *value, DWORD expected)
39 {
40     ok(*value == expected, "expected %08x got %08x\n", expected, *value);
41 }
42
43 static inline void expect_float(DWORD *value, FLOAT expected)
44 {
45     FLOAT valuef = *(FLOAT*)value;
46     ok(valuef == expected, "expected %f got %f\n", expected, valuef);
47 }
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 test_getregiondata(void)
56 {
57     GpStatus status;
58     GpRegion *region, *region2;
59     RegionDataPoint *point;
60     UINT needed;
61     DWORD buf[100];
62     GpRect rect;
63     GpPath *path;
64
65     status = GdipCreateRegion(&region);
66 todo_wine
67     ok(status == Ok, "status %08x\n", status);
68
69     if(status != Ok) return;
70
71     status = GdipGetRegionDataSize(region, &needed);
72     ok(status == Ok, "status %08x\n", status);
73     ok(needed == 20, "got %d\n", needed);
74     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
75     ok(status == Ok, "status %08x\n", status);
76     ok(needed == 20, "got %d\n", needed);
77     expect_dword(buf, 12);
78     trace("buf[1] = %08x\n", buf[1]);
79     expect_magic((DWORD*)(buf + 2));
80     expect_dword(buf + 3, 0);
81     expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
82
83     status = GdipSetEmpty(region);
84     ok(status == Ok, "status %08x\n", status);
85     status = GdipGetRegionDataSize(region, &needed);
86     ok(status == Ok, "status %08x\n", status);
87     ok(needed == 20, "got %d\n", needed);
88     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
89     ok(status == Ok, "status %08x\n", status);
90     ok(needed == 20, "got %d\n", needed);
91     expect_dword(buf, 12);
92     trace("buf[1] = %08x\n", buf[1]);
93     expect_magic((DWORD*)(buf + 2));
94     expect_dword(buf + 3, 0);
95     expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
96
97     status = GdipSetInfinite(region);
98     ok(status == Ok, "status %08x\n", status);
99     status = GdipGetRegionDataSize(region, &needed);
100     ok(status == Ok, "status %08x\n", status);
101     ok(needed == 20, "got %d\n", needed);
102     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
103     ok(status == Ok, "status %08x\n", status);
104     ok(needed == 20, "got %d\n", needed);
105     expect_dword(buf, 12);
106     trace("buf[1] = %08x\n", buf[1]);
107     expect_magic((DWORD*)(buf + 2));
108     expect_dword(buf + 3, 0);
109     expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
110
111     status = GdipDeleteRegion(region);
112     ok(status == Ok, "status %08x\n", status);
113
114     rect.X = 10;
115     rect.Y = 20;
116     rect.Width = 100;
117     rect.Height = 200;
118     status = GdipCreateRegionRectI(&rect, &region);
119     ok(status == Ok, "status %08x\n", status);
120     status = GdipGetRegionDataSize(region, &needed);
121     ok(status == Ok, "status %08x\n", status);
122     ok(needed == 36, "got %d\n", needed);
123     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
124     ok(status == Ok, "status %08x\n", status);
125     ok(needed == 36, "got %d\n", needed);
126     expect_dword(buf, 28);
127     trace("buf[1] = %08x\n", buf[1]);
128     expect_magic((DWORD*)(buf + 2));
129     expect_dword(buf + 3, 0);
130     expect_dword(buf + 4, RGNDATA_RECT);
131     expect_float(buf + 5, 10.0);
132     expect_float(buf + 6, 20.0);
133     expect_float(buf + 7, 100.0);
134     expect_float(buf + 8, 200.0);
135
136     rect.X = 50;
137     rect.Y = 30;
138     rect.Width = 10;
139     rect.Height = 20;
140     status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
141     ok(status == Ok, "status %08x\n", status);
142     rect.X = 100;
143     rect.Y = 300;
144     rect.Width = 30;
145     rect.Height = 50;
146     status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
147     ok(status == Ok, "status %08x\n", status);
148
149     rect.X = 200;
150     rect.Y = 100;
151     rect.Width = 133;
152     rect.Height = 266;
153     status = GdipCreateRegionRectI(&rect, &region2);
154     ok(status == Ok, "status %08x\n", status);
155     rect.X = 20;
156     rect.Y = 10;
157     rect.Width = 40;
158     rect.Height = 66;
159     status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
160     ok(status == Ok, "status %08x\n", status);
161
162     status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
163     ok(status == Ok, "status %08x\n", status);
164
165     rect.X = 400;
166     rect.Y = 500;
167     rect.Width = 22;
168     rect.Height = 55;
169     status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
170     ok(status == Ok, "status %08x\n", status);
171
172     status = GdipGetRegionDataSize(region, &needed);
173     ok(status == Ok, "status %08x\n", status);
174     ok(needed == 156, "got %d\n", needed);
175     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
176     ok(status == Ok, "status %08x\n", status);
177     ok(needed == 156, "got %d\n", needed);
178     expect_dword(buf, 148);
179     trace("buf[1] = %08x\n", buf[1]);
180     expect_magic((DWORD*)(buf + 2));
181     expect_dword(buf + 3, 10);
182     expect_dword(buf + 4, CombineModeExclude);
183     expect_dword(buf + 5, CombineModeComplement);
184     expect_dword(buf + 6, CombineModeXor);
185     expect_dword(buf + 7, CombineModeIntersect);
186     expect_dword(buf + 8, RGNDATA_RECT);
187     expect_float(buf + 9, 10.0);
188     expect_float(buf + 10, 20.0);
189     expect_float(buf + 11, 100.0);
190     expect_float(buf + 12, 200.0);
191     expect_dword(buf + 13, RGNDATA_RECT);
192     expect_float(buf + 14, 50.0);
193     expect_float(buf + 15, 30.0);
194     expect_float(buf + 16, 10.0);
195     expect_float(buf + 17, 20.0);
196     expect_dword(buf + 18, RGNDATA_RECT);
197     expect_float(buf + 19, 100.0);
198     expect_float(buf + 20, 300.0);
199     expect_float(buf + 21, 30.0);
200     expect_float(buf + 22, 50.0);
201     expect_dword(buf + 23, CombineModeUnion);
202     expect_dword(buf + 24, RGNDATA_RECT);
203     expect_float(buf + 25, 200.0);
204     expect_float(buf + 26, 100.0);
205     expect_float(buf + 27, 133.0);
206     expect_float(buf + 28, 266.0);
207     expect_dword(buf + 29, RGNDATA_RECT);
208     expect_float(buf + 30, 20.0);
209     expect_float(buf + 31, 10.0);
210     expect_float(buf + 32, 40.0);
211     expect_float(buf + 33, 66.0);
212     expect_dword(buf + 34, RGNDATA_RECT);
213     expect_float(buf + 35, 400.0);
214     expect_float(buf + 36, 500.0);
215     expect_float(buf + 37, 22.0);
216     expect_float(buf + 38, 55.0);
217
218
219     status = GdipDeleteRegion(region2);
220     ok(status == Ok, "status %08x\n", status);
221     status = GdipDeleteRegion(region);
222     ok(status == Ok, "status %08x\n", status);
223
224     /* Try some paths */
225
226     status = GdipCreatePath(FillModeAlternate, &path);
227     ok(status == Ok, "status %08x\n", status);
228     GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
229
230     status = GdipCreateRegionPath(path, &region);
231     ok(status == Ok, "status %08x\n", status);
232     status = GdipGetRegionDataSize(region, &needed);
233     ok(status == Ok, "status %08x\n", status);
234     ok(needed == 72, "got %d\n", needed);
235     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
236     ok(status == Ok, "status %08x\n", status);
237     ok(needed == 72, "got %d\n", needed);
238     expect_dword(buf, 64);
239     trace("buf[1] = %08x\n", buf[1]);
240     expect_magic((DWORD*)(buf + 2));
241     expect_dword(buf + 3, 0);
242     expect_dword(buf + 4, RGNDATA_PATH);
243     expect_dword(buf + 5, 0x00000030);
244     expect_magic((DWORD*)(buf + 6));
245     expect_dword(buf + 7, 0x00000004);
246     expect_dword(buf + 8, 0x00000000);
247     expect_float(buf + 9, 12.5);
248     expect_float(buf + 10, 13.0);
249     expect_float(buf + 11, 26.5);
250     expect_float(buf + 12, 13.0);
251     expect_float(buf + 13, 26.5);
252     expect_float(buf + 14, 28.0);
253     expect_float(buf + 15, 12.5);
254     expect_float(buf + 16, 28.0);
255     expect_dword(buf + 17, 0x81010100);
256
257
258     rect.X = 50;
259     rect.Y = 30;
260     rect.Width = 10;
261     rect.Height = 20;
262     status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
263     ok(status == Ok, "status %08x\n", status);
264     status = GdipGetRegionDataSize(region, &needed);
265     ok(status == Ok, "status %08x\n", status);
266     ok(needed == 96, "got %d\n", needed);
267     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
268     ok(status == Ok, "status %08x\n", status);
269     ok(needed == 96, "got %d\n", needed);
270     expect_dword(buf, 88);
271     trace("buf[1] = %08x\n", buf[1]);
272     expect_magic((DWORD*)(buf + 2));
273     expect_dword(buf + 3, 2);
274     expect_dword(buf + 4, CombineModeIntersect);
275     expect_dword(buf + 5, RGNDATA_PATH);
276     expect_dword(buf + 6, 0x00000030);
277     expect_magic((DWORD*)(buf + 7));
278     expect_dword(buf + 8, 0x00000004);
279     expect_dword(buf + 9, 0x00000000);
280     expect_float(buf + 10, 12.5);
281     expect_float(buf + 11, 13.0);
282     expect_float(buf + 12, 26.5);
283     expect_float(buf + 13, 13.0);
284     expect_float(buf + 14, 26.5);
285     expect_float(buf + 15, 28.0);
286     expect_float(buf + 16, 12.5);
287     expect_float(buf + 17, 28.0);
288     expect_dword(buf + 18, 0x81010100);
289     expect_dword(buf + 19, RGNDATA_RECT);
290     expect_float(buf + 20, 50.0);
291     expect_float(buf + 21, 30.0);
292     expect_float(buf + 22, 10.0);
293     expect_float(buf + 23, 20.0);
294
295     status = GdipDeleteRegion(region);
296     ok(status == Ok, "status %08x\n", status);
297     status = GdipDeletePath(path);
298     ok(status == Ok, "status %08x\n", status);
299
300     /* Test an empty path */
301     status = GdipCreatePath(FillModeAlternate, &path);
302     expect(Ok, status);
303     status = GdipCreateRegionPath(path, &region);
304     expect(Ok, status);
305     status = GdipGetRegionDataSize(region, &needed);
306     expect(Ok, status);
307     ok(needed == 36, "got %d\n", needed);
308     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
309     expect(Ok, status);
310     ok(needed == 36, "got %d\n", needed);
311     expect_dword(buf, 28);
312     trace("buf[1] = %08x\n", buf[1]);
313     expect_magic((DWORD*)(buf + 2));
314     expect_dword(buf + 3, 0);
315     expect_dword(buf + 4, RGNDATA_PATH);
316
317     /* Second signature for pathdata */
318     expect_dword(buf + 5, 12);
319     expect_magic((DWORD*)(buf + 6));
320     expect_dword(buf + 7, 0);
321     expect_dword(buf + 8, 0x00004000);
322
323     status = GdipDeleteRegion(region);
324     expect(Ok, status);
325
326     /* Test a simple triangle of INTs */
327     status = GdipAddPathLine(path, 5, 6, 7, 8);
328     expect(Ok, status);
329     status = GdipAddPathLine(path, 7, 8, 8, 1);
330     expect(Ok, status);
331     status = GdipAddPathLine(path, 8, 1, 5, 6);
332     expect(Ok, status);
333     status = GdipClosePathFigure(path);
334     expect(Ok, status);
335     status = GdipCreateRegionPath(path, &region);
336     expect(Ok, status);
337     status = GdipGetRegionDataSize(region, &needed);
338     expect(Ok, status);
339     ok(needed == 56, "Expected 56, got %d\n", needed);
340     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
341     expect(Ok, status);
342     expect_dword(buf, 48);
343     trace("buf[1] = %08x\n", buf[1]);
344     expect_magic((DWORD*)(buf + 2));
345     expect_dword(buf + 3 , 0);
346     expect_dword(buf + 4 , RGNDATA_PATH);
347
348     expect_dword(buf + 5, 32);
349     expect_magic((DWORD*)(buf + 6));
350     expect_dword(buf + 7, 4);
351     expect_dword(buf + 8, 0x00004000); /* ?? */
352
353     point = (RegionDataPoint*)buf + 9;
354     expect(5, point[0].X);
355     expect(6, point[0].Y);
356     expect(7, point[1].X); /* buf + 10 */
357     expect(8, point[1].Y);
358     expect(8, point[2].X); /* buf + 11 */
359     expect(1, point[2].Y);
360     expect(5, point[3].X); /* buf + 12 */
361     expect(6, point[3].Y);
362     expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */
363     status = GdipDeletePath(path);
364     expect(Ok, status);
365     status = GdipDeleteRegion(region);
366     expect(Ok, status);
367
368     /* Test a floating-point triangle */
369     status = GdipCreatePath(FillModeAlternate, &path);
370     expect(Ok, status);
371     status = GdipAddPathLine(path, 5.6, 6.2, 7.2, 8.9);
372     expect(Ok, status);
373     status = GdipAddPathLine(path, 7.2, 8.9, 8.1, 1.6);
374     expect(Ok, status);
375     status = GdipAddPathLine(path, 8.1, 1.6, 5.6, 6.2);
376     expect(Ok, status);
377     status = GdipCreateRegionPath(path, &region);
378     expect(Ok, status);
379     status = GdipGetRegionDataSize(region, &needed);
380     expect(Ok, status);
381     ok(needed == 72, "Expected 72, got %d\n", needed);
382     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
383     expect(Ok, status);
384     expect_dword(buf, 64);
385     trace("buf[1] = %08x\n", buf[1]);
386     expect_magic((DWORD*)(buf + 2));
387     expect_dword(buf + 3, 0);
388     expect_dword(buf + 4, RGNDATA_PATH);
389
390     expect_dword(buf + 5, 48);
391     expect_magic((DWORD*)(buf + 6));
392     expect_dword(buf + 7, 4);
393     expect_dword(buf + 8, 0);
394     expect_float(buf + 9, 5.6);
395     expect_float(buf + 10, 6.2);
396     expect_float(buf + 11, 7.2);
397     expect_float(buf + 12, 8.9);
398     expect_float(buf + 13, 8.1);
399     expect_float(buf + 14, 1.6);
400     expect_float(buf + 15, 5.6);
401     expect_float(buf + 16, 6.2);
402
403     status = GdipDeleteRegion(region);
404     expect(Ok, status);
405 }
406
407 START_TEST(region)
408 {
409     struct GdiplusStartupInput gdiplusStartupInput;
410     ULONG_PTR gdiplusToken;
411
412     gdiplusStartupInput.GdiplusVersion              = 1;
413     gdiplusStartupInput.DebugEventCallback          = NULL;
414     gdiplusStartupInput.SuppressBackgroundThread    = 0;
415     gdiplusStartupInput.SuppressExternalCodecs      = 0;
416
417     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
418
419     test_getregiondata();
420
421     GdiplusShutdown(gdiplusToken);
422
423 }