gdiplus: Implemented GdipPathIterHasCurve with tests.
[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 static inline void expect_dword(DWORD *value, DWORD expected)
27 {
28     ok(*value == expected, "expected %08x got %08x\n", expected, *value);
29 }
30
31 static inline void expect_float(DWORD *value, FLOAT expected)
32 {
33     FLOAT valuef = *(FLOAT*)value;
34     ok(valuef == expected, "expected %f got %f\n", expected, valuef);
35 }
36
37 static void test_create_rgn(void)
38 {
39     GpStatus status;
40     GpRegion *region, *region2;
41     UINT needed;
42     DWORD buf[100];
43     GpRect rect;
44
45     status = GdipCreateRegion(&region);
46 todo_wine
47     ok(status == Ok, "status %08x\n", status);
48
49     if(status != Ok) return;
50
51     status = GdipGetRegionDataSize(region, &needed);
52     ok(status == Ok, "status %08x\n", status);
53     ok(needed == 20, "got %d\n", needed);
54     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
55     ok(status == Ok, "status %08x\n", status);
56     ok(needed == 20, "got %d\n", needed);
57     expect_dword(buf, 12);
58     trace("buf[1] = %08x\n", buf[1]);
59     expect_dword(buf + 2, 0xdbc01001);
60     expect_dword(buf + 3, 0);
61     expect_dword(buf + 4, 0x10000003);
62
63     status = GdipSetEmpty(region);
64     ok(status == Ok, "status %08x\n", status);
65     status = GdipGetRegionDataSize(region, &needed);
66     ok(status == Ok, "status %08x\n", status);
67     ok(needed == 20, "got %d\n", needed);
68     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
69     ok(status == Ok, "status %08x\n", status);
70     ok(needed == 20, "got %d\n", needed);
71     expect_dword(buf, 12);
72     trace("buf[1] = %08x\n", buf[1]);
73     expect_dword(buf + 2, 0xdbc01001);
74     expect_dword(buf + 3, 0);
75     expect_dword(buf + 4, 0x10000002);
76
77     status = GdipSetInfinite(region);
78     ok(status == Ok, "status %08x\n", status);
79     status = GdipGetRegionDataSize(region, &needed);
80     ok(status == Ok, "status %08x\n", status);
81     ok(needed == 20, "got %d\n", needed);
82     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
83     ok(status == Ok, "status %08x\n", status);
84     ok(needed == 20, "got %d\n", needed);
85     expect_dword(buf, 12);
86     trace("buf[1] = %08x\n", buf[1]);
87     expect_dword(buf + 2, 0xdbc01001);
88     expect_dword(buf + 3, 0);
89     expect_dword(buf + 4, 0x10000003);
90
91     status = GdipDeleteRegion(region);
92     ok(status == Ok, "status %08x\n", status);
93
94     rect.X = 10;
95     rect.Y = 20;
96     rect.Width = 100;
97     rect.Height = 200;
98     status = GdipCreateRegionRectI(&rect, &region);
99     ok(status == Ok, "status %08x\n", status);
100     status = GdipGetRegionDataSize(region, &needed);
101     ok(status == Ok, "status %08x\n", status);
102     ok(needed == 36, "got %d\n", needed);
103     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
104     ok(status == Ok, "status %08x\n", status);
105     ok(needed == 36, "got %d\n", needed);
106     expect_dword(buf, 28);
107     trace("buf[1] = %08x\n", buf[1]);
108     expect_dword(buf + 2, 0xdbc01001);
109     expect_dword(buf + 3, 0);
110     expect_dword(buf + 4, 0x10000000);
111     expect_float(buf + 5, 10.0);
112     expect_float(buf + 6, 20.0);
113     expect_float(buf + 7, 100.0);
114     expect_float(buf + 8, 200.0);
115
116     rect.X = 50;
117     rect.Y = 30;
118     rect.Width = 10;
119     rect.Height = 20;
120     status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect);
121     ok(status == Ok, "status %08x\n", status);
122     rect.X = 100;
123     rect.Y = 300;
124     rect.Width = 30;
125     rect.Height = 50;
126     status = GdipCombineRegionRectI(region, &rect, CombineModeXor);
127     ok(status == Ok, "status %08x\n", status);
128
129     rect.X = 200;
130     rect.Y = 100;
131     rect.Width = 133;
132     rect.Height = 266;
133     status = GdipCreateRegionRectI(&rect, &region2);
134     ok(status == Ok, "status %08x\n", status);
135     rect.X = 20;
136     rect.Y = 10;
137     rect.Width = 40;
138     rect.Height = 66;
139     status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion);
140     ok(status == Ok, "status %08x\n", status);
141
142     status = GdipCombineRegionRegion(region, region2, CombineModeComplement);
143     ok(status == Ok, "status %08x\n", status);
144
145     rect.X = 400;
146     rect.Y = 500;
147     rect.Width = 22;
148     rect.Height = 55;
149     status = GdipCombineRegionRectI(region, &rect, CombineModeExclude);
150     ok(status == Ok, "status %08x\n", status);
151
152     status = GdipGetRegionDataSize(region, &needed);
153     ok(status == Ok, "status %08x\n", status);
154     ok(needed == 156, "got %d\n", needed);
155     status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed);
156     ok(status == Ok, "status %08x\n", status);
157     ok(needed == 156, "got %d\n", needed);
158     expect_dword(buf, 148);
159     trace("buf[1] = %08x\n", buf[1]);
160     expect_dword(buf + 2, 0xdbc01001);
161     expect_dword(buf + 3, 10);
162     expect_dword(buf + 4, CombineModeExclude);
163     expect_dword(buf + 5, CombineModeComplement);
164     expect_dword(buf + 6, CombineModeXor);
165     expect_dword(buf + 7, CombineModeIntersect);
166     expect_dword(buf + 8, 0x10000000);
167     expect_float(buf + 9, 10.0);
168     expect_float(buf + 10, 20.0);
169     expect_float(buf + 11, 100.0);
170     expect_float(buf + 12, 200.0);
171     expect_dword(buf + 13, 0x10000000);
172     expect_float(buf + 14, 50.0);
173     expect_float(buf + 15, 30.0);
174     expect_float(buf + 16, 10.0);
175     expect_float(buf + 17, 20.0);
176     expect_dword(buf + 18, 0x10000000);
177     expect_float(buf + 19, 100.0);
178     expect_float(buf + 20, 300.0);
179     expect_float(buf + 21, 30.0);
180     expect_float(buf + 22, 50.0);
181     expect_dword(buf + 23, CombineModeUnion);
182     expect_dword(buf + 24, 0x10000000);
183     expect_float(buf + 25, 200.0);
184     expect_float(buf + 26, 100.0);
185     expect_float(buf + 27, 133.0);
186     expect_float(buf + 28, 266.0);
187     expect_dword(buf + 29, 0x10000000);
188     expect_float(buf + 30, 20.0);
189     expect_float(buf + 31, 10.0);
190     expect_float(buf + 32, 40.0);
191     expect_float(buf + 33, 66.0);
192     expect_dword(buf + 34, 0x10000000);
193     expect_float(buf + 35, 400.0);
194     expect_float(buf + 36, 500.0);
195     expect_float(buf + 37, 22.0);
196     expect_float(buf + 38, 55.0);
197
198
199     status = GdipDeleteRegion(region2);
200     ok(status == Ok, "status %08x\n", status);
201     status = GdipDeleteRegion(region);
202     ok(status == Ok, "status %08x\n", status);
203
204 }
205
206 START_TEST(region)
207 {
208     struct GdiplusStartupInput gdiplusStartupInput;
209     ULONG_PTR gdiplusToken;
210
211     gdiplusStartupInput.GdiplusVersion              = 1;
212     gdiplusStartupInput.DebugEventCallback          = NULL;
213     gdiplusStartupInput.SuppressBackgroundThread    = 0;
214     gdiplusStartupInput.SuppressExternalCodecs      = 0;
215
216     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
217
218     test_create_rgn();
219
220     GdiplusShutdown(gdiplusToken);
221
222 }