gdiplus: Add some defines for the magic values.
[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
33 static inline void expect_dword(DWORD *value, DWORD expected)
34 {
35     ok(*value == expected, "expected %08x got %08x\n", expected, *value);
36 }
37
38 static inline void expect_float(DWORD *value, FLOAT expected)
39 {
40     FLOAT valuef = *(FLOAT*)value;
41     ok(valuef == expected, "expected %f got %f\n", expected, valuef);
42 }
43
44 static void test_getregiondata(void)
45 {
46     GpStatus status;
47     GpRegion *region, *region2;
48     UINT needed;
49     DWORD buf[100];
50     GpRect rect;
51     GpPath *path;
52
53     status = GdipCreateRegion(&region);
54 todo_wine
55     ok(status == Ok, "status %08x\n", status);
56
57     if(status != Ok) return;
58
59     status = GdipGetRegionDataSize(region, &needed);
60     ok(status == Ok, "status %08x\n", status);
61     ok(needed == 20, "got %d\n", needed);
62     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
63     ok(status == Ok, "status %08x\n", status);
64     ok(needed == 20, "got %d\n", needed);
65     expect_dword(buf, 12);
66     trace("buf[1] = %08x\n", buf[1]);
67     expect_dword(buf + 2, RGNDATA_MAGIC);
68     expect_dword(buf + 3, 0);
69     expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
70
71     status = GdipSetEmpty(region);
72     ok(status == Ok, "status %08x\n", status);
73     status = GdipGetRegionDataSize(region, &needed);
74     ok(status == Ok, "status %08x\n", status);
75     ok(needed == 20, "got %d\n", needed);
76     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
77     ok(status == Ok, "status %08x\n", status);
78     ok(needed == 20, "got %d\n", needed);
79     expect_dword(buf, 12);
80     trace("buf[1] = %08x\n", buf[1]);
81     expect_dword(buf + 2, RGNDATA_MAGIC);
82     expect_dword(buf + 3, 0);
83     expect_dword(buf + 4, RGNDATA_EMPTY_RECT);
84
85     status = GdipSetInfinite(region);
86     ok(status == Ok, "status %08x\n", status);
87     status = GdipGetRegionDataSize(region, &needed);
88     ok(status == Ok, "status %08x\n", status);
89     ok(needed == 20, "got %d\n", needed);
90     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
91     ok(status == Ok, "status %08x\n", status);
92     ok(needed == 20, "got %d\n", needed);
93     expect_dword(buf, 12);
94     trace("buf[1] = %08x\n", buf[1]);
95     expect_dword(buf + 2, RGNDATA_MAGIC);
96     expect_dword(buf + 3, 0);
97     expect_dword(buf + 4, RGNDATA_INFINITE_RECT);
98
99     status = GdipDeleteRegion(region);
100     ok(status == Ok, "status %08x\n", status);
101
102     rect.X = 10;
103     rect.Y = 20;
104     rect.Width = 100;
105     rect.Height = 200;
106     status = GdipCreateRegionRectI(&rect, &region);
107     ok(status == Ok, "status %08x\n", status);
108     status = GdipGetRegionDataSize(region, &needed);
109     ok(status == Ok, "status %08x\n", status);
110     ok(needed == 36, "got %d\n", needed);
111     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
112     ok(status == Ok, "status %08x\n", status);
113     ok(needed == 36, "got %d\n", needed);
114     expect_dword(buf, 28);
115     trace("buf[1] = %08x\n", buf[1]);
116     expect_dword(buf + 2, RGNDATA_MAGIC);
117     expect_dword(buf + 3, 0);
118     expect_dword(buf + 4, RGNDATA_RECT);
119     expect_float(buf + 5, 10.0);
120     expect_float(buf + 6, 20.0);
121     expect_float(buf + 7, 100.0);
122     expect_float(buf + 8, 200.0);
123
124     rect.X = 50;
125     rect.Y = 30;
126     rect.Width = 10;
127     rect.Height = 20;
128     status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
129     ok(status == Ok, "status %08x\n", status);
130     rect.X = 100;
131     rect.Y = 300;
132     rect.Width = 30;
133     rect.Height = 50;
134     status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
135     ok(status == Ok, "status %08x\n", status);
136
137     rect.X = 200;
138     rect.Y = 100;
139     rect.Width = 133;
140     rect.Height = 266;
141     status = GdipCreateRegionRectI(&rect, &region2);
142     ok(status == Ok, "status %08x\n", status);
143     rect.X = 20;
144     rect.Y = 10;
145     rect.Width = 40;
146     rect.Height = 66;
147     status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
148     ok(status == Ok, "status %08x\n", status);
149
150     status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
151     ok(status == Ok, "status %08x\n", status);
152
153     rect.X = 400;
154     rect.Y = 500;
155     rect.Width = 22;
156     rect.Height = 55;
157     status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
158     ok(status == Ok, "status %08x\n", status);
159
160     status = GdipGetRegionDataSize(region, &needed);
161     ok(status == Ok, "status %08x\n", status);
162     ok(needed == 156, "got %d\n", needed);
163     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
164     ok(status == Ok, "status %08x\n", status);
165     ok(needed == 156, "got %d\n", needed);
166     expect_dword(buf, 148);
167     trace("buf[1] = %08x\n", buf[1]);
168     expect_dword(buf + 2, RGNDATA_MAGIC);
169     expect_dword(buf + 3, 10);
170     expect_dword(buf + 4, CombineModeExclude);
171     expect_dword(buf + 5, CombineModeComplement);
172     expect_dword(buf + 6, CombineModeXor);
173     expect_dword(buf + 7, CombineModeIntersect);
174     expect_dword(buf + 8, RGNDATA_RECT);
175     expect_float(buf + 9, 10.0);
176     expect_float(buf + 10, 20.0);
177     expect_float(buf + 11, 100.0);
178     expect_float(buf + 12, 200.0);
179     expect_dword(buf + 13, RGNDATA_RECT);
180     expect_float(buf + 14, 50.0);
181     expect_float(buf + 15, 30.0);
182     expect_float(buf + 16, 10.0);
183     expect_float(buf + 17, 20.0);
184     expect_dword(buf + 18, RGNDATA_RECT);
185     expect_float(buf + 19, 100.0);
186     expect_float(buf + 20, 300.0);
187     expect_float(buf + 21, 30.0);
188     expect_float(buf + 22, 50.0);
189     expect_dword(buf + 23, CombineModeUnion);
190     expect_dword(buf + 24, RGNDATA_RECT);
191     expect_float(buf + 25, 200.0);
192     expect_float(buf + 26, 100.0);
193     expect_float(buf + 27, 133.0);
194     expect_float(buf + 28, 266.0);
195     expect_dword(buf + 29, RGNDATA_RECT);
196     expect_float(buf + 30, 20.0);
197     expect_float(buf + 31, 10.0);
198     expect_float(buf + 32, 40.0);
199     expect_float(buf + 33, 66.0);
200     expect_dword(buf + 34, RGNDATA_RECT);
201     expect_float(buf + 35, 400.0);
202     expect_float(buf + 36, 500.0);
203     expect_float(buf + 37, 22.0);
204     expect_float(buf + 38, 55.0);
205
206
207     status = GdipDeleteRegion(region2);
208     ok(status == Ok, "status %08x\n", status);
209     status = GdipDeleteRegion(region);
210     ok(status == Ok, "status %08x\n", status);
211
212     /* Try some paths */
213
214     status = GdipCreatePath(FillModeAlternate, &path);
215     ok(status == Ok, "status %08x\n", status);
216     GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0);
217
218     status = GdipCreateRegionPath(path, &region);
219     ok(status == Ok, "status %08x\n", status);
220     status = GdipGetRegionDataSize(region, &needed);
221     ok(status == Ok, "status %08x\n", status);
222     ok(needed == 72, "got %d\n", needed);
223     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
224     ok(status == Ok, "status %08x\n", status);
225     ok(needed == 72, "got %d\n", needed);
226     expect_dword(buf, 64);
227     trace("buf[1] = %08x\n", buf[1]);
228     expect_dword(buf + 2, RGNDATA_MAGIC);
229     expect_dword(buf + 3, 0);
230     expect_dword(buf + 4, RGNDATA_PATH);
231     expect_dword(buf + 5, 0x00000030);
232     expect_dword(buf + 6, RGNDATA_MAGIC);
233     expect_dword(buf + 7, 0x00000004);
234     expect_dword(buf + 8, 0x00000000);
235     expect_float(buf + 9, 12.5);
236     expect_float(buf + 10, 13.0);
237     expect_float(buf + 11, 26.5);
238     expect_float(buf + 12, 13.0);
239     expect_float(buf + 13, 26.5);
240     expect_float(buf + 14, 28.0);
241     expect_float(buf + 15, 12.5);
242     expect_float(buf + 16, 28.0);
243     expect_dword(buf + 17, 0x81010100);
244
245
246     rect.X = 50;
247     rect.Y = 30;
248     rect.Width = 10;
249     rect.Height = 20;
250     status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
251     ok(status == Ok, "status %08x\n", status);
252     status = GdipGetRegionDataSize(region, &needed);
253     ok(status == Ok, "status %08x\n", status);
254     ok(needed == 96, "got %d\n", needed);
255     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
256     ok(status == Ok, "status %08x\n", status);
257     ok(needed == 96, "got %d\n", needed);
258     expect_dword(buf, 88);
259     trace("buf[1] = %08x\n", buf[1]);
260     expect_dword(buf + 2, RGNDATA_MAGIC);
261     expect_dword(buf + 3, 2);
262     expect_dword(buf + 4, CombineModeIntersect);
263     expect_dword(buf + 5, RGNDATA_PATH);
264     expect_dword(buf + 6, 0x00000030);
265     expect_dword(buf + 7, RGNDATA_MAGIC);
266     expect_dword(buf + 8, 0x00000004);
267     expect_dword(buf + 9, 0x00000000);
268     expect_float(buf + 10, 12.5);
269     expect_float(buf + 11, 13.0);
270     expect_float(buf + 12, 26.5);
271     expect_float(buf + 13, 13.0);
272     expect_float(buf + 14, 26.5);
273     expect_float(buf + 15, 28.0);
274     expect_float(buf + 16, 12.5);
275     expect_float(buf + 17, 28.0);
276     expect_dword(buf + 18, 0x81010100);
277     expect_dword(buf + 19, RGNDATA_RECT);
278     expect_float(buf + 20, 50.0);
279     expect_float(buf + 21, 30.0);
280     expect_float(buf + 22, 10.0);
281     expect_float(buf + 23, 20.0);
282
283     status = GdipDeleteRegion(region);
284     ok(status == Ok, "status %08x\n", status);
285     status = GdipDeletePath(path);
286     ok(status == Ok, "status %08x\n", status);
287
288 }
289
290 START_TEST(region)
291 {
292     struct GdiplusStartupInput gdiplusStartupInput;
293     ULONG_PTR gdiplusToken;
294
295     gdiplusStartupInput.GdiplusVersion              = 1;
296     gdiplusStartupInput.DebugEventCallback          = NULL;
297     gdiplusStartupInput.SuppressBackgroundThread    = 0;
298     gdiplusStartupInput.SuppressExternalCodecs      = 0;
299
300     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
301
302     test_getregiondata();
303
304     GdiplusShutdown(gdiplusToken);
305
306 }