2 * Unit test suite for paths
4 * Copyright 2007 Laurent Vromman
5 * Copyright 2007 Misha Koshelev
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.
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.
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
29 #include "wine/test.h"
34 static void test_widenpath(void)
37 HPEN greenPen
, narrowPen
;
42 /* Create a pen to be used in WidenPath */
43 greenPen
= CreatePen(PS_SOLID
, 10, RGB(0,0,0));
44 oldPen
= SelectObject(hdc
, greenPen
);
60 /* Set a polyline path */
62 Polyline(hdc
, pnt
, 6);
65 /* Widen the polyline path */
66 ok(WidenPath(hdc
), "WidenPath fails while widening a poyline path.\n");
68 /* Test if WidenPath seems to have done his job */
69 nSize
= GetPath(hdc
, NULL
, NULL
, 0);
70 ok(nSize
!= -1, "GetPath fails after calling WidenPath.\n");
71 ok(nSize
> 6, "Path number of points is to low. Should be more than 6 but is %d\n", nSize
);
75 /* Test WidenPath with an open path (last error only set on Win2k and later) */
76 SetLastError(0xdeadbeef);
79 ok(ret
== FALSE
&& (GetLastError() == ERROR_CAN_NOT_COMPLETE
|| GetLastError() == 0xdeadbeef),
80 "WidenPath fails while widening an open path. Return value is %d, should be %d. Error is %u\n", ret
, FALSE
, GetLastError());
84 /* Test when the pen width is equal to 1. The path should not change */
85 narrowPen
= CreatePen(PS_SOLID
, 1, RGB(0,0,0));
86 oldPen
= SelectObject(hdc
, narrowPen
);
88 Polyline(hdc
, pnt
, 6);
90 nSize
= GetPath(hdc
, NULL
, NULL
, 0);
91 ok(nSize
== 6, "WidenPath fails detecting 1px wide pen. Path length is %d, should be 6\n", nSize
);
98 * Tests for GDI drawing functions in paths
106 /* How many extra entries before this one only on wine
107 * but not on native? */
108 int wine_only_entries_preceding
;
110 /* 0 - This entry matches on wine.
111 * 1 - This entry corresponds to a single entry on wine that does not match the native entry.
112 * 2 - This entry is currently skipped on wine but present on native. */
116 /* Helper function to verify that the current path in the given DC matches the expected path.
118 * We use a "smart" matching algorithm that allows us to detect partial improvements
119 * in conformance. Specifically, two running indices are kept, one through the actual
120 * path and one through the expected path. The actual path index increases unless there is
121 * no match and the todo field of the appropriate path_test_t element is 2. Similarly,
122 * if the wine_entries_preceding field of the appropriate path_test_t element is non-zero,
123 * the expected path index does not increase for that many elements as long as there
124 * is no match. This allows us to todo_wine extra path elements that are present only
125 * on wine but not on native and vice versa.
127 * Note that if expected_size is zero and the WINETEST_DEBUG environment variable is
128 * greater than 2, the trace() output is a C path_test_t array structure, useful for making
129 * new tests that use this function.
131 static void ok_path(HDC hdc
, const char *path_name
, const path_test_t
*expected
, int expected_size
, BOOL todo_size
)
133 static const char *type_string
[8] = { "Unknown (0)", "PT_CLOSEFIGURE", "PT_LINETO",
134 "PT_LINETO | PT_CLOSEFIGURE", "PT_BEZIERTO",
135 "PT_BEZIERTO | PT_CLOSEFIGURE", "PT_MOVETO", "PT_MOVETO | PT_CLOSEFIGURE"};
143 size
= GetPath(hdc
, NULL
, NULL
, 0);
144 ok(size
> 0, "GetPath returned size %d, last error %d\n", size
, GetLastError());
147 skip("Cannot perform path comparisons due to failure to retrieve path.\n");
150 pnt
= HeapAlloc(GetProcessHeap(), 0, size
*sizeof(POINT
));
152 types
= HeapAlloc(GetProcessHeap(), 0, size
*sizeof(BYTE
));
154 size
= GetPath(hdc
, pnt
, types
, size
);
157 if (todo_size
) todo_wine
158 ok(size
== expected_size
, "Path size %d does not match expected size %d\n", size
, expected_size
);
160 ok(size
== expected_size
, "Path size %d does not match expected size %d\n", size
, expected_size
);
162 if (winetest_debug
> 2)
163 trace("static const path_test_t %s[] = {\n", path_name
);
165 numskip
= expected_size
? expected
[eidx
].wine_only_entries_preceding
: 0;
166 while (idx
< size
&& eidx
< expected_size
)
168 /* We allow a few pixels fudge in matching X and Y coordinates to account for imprecision in
169 * floating point to integer conversion */
170 BOOL match
= (types
[idx
] == expected
[eidx
].type
) &&
171 (pnt
[idx
].x
>= expected
[eidx
].x
-2 && pnt
[idx
].x
<= expected
[eidx
].x
+2) &&
172 (pnt
[idx
].y
>= expected
[eidx
].y
-2 && pnt
[idx
].y
<= expected
[eidx
].y
+2);
174 if (expected
[eidx
].todo
|| numskip
) todo_wine
175 ok(match
, "Expected #%d: %s (%d,%d) but got %s (%d,%d)\n", eidx
,
176 type_string
[expected
[eidx
].type
], expected
[eidx
].x
, expected
[eidx
].y
,
177 type_string
[types
[idx
]], pnt
[idx
].x
, pnt
[idx
].y
);
179 ok(match
, "Expected #%d: %s (%d,%d) but got %s (%d,%d)\n", eidx
,
180 type_string
[expected
[eidx
].type
], expected
[eidx
].x
, expected
[eidx
].y
,
181 type_string
[types
[idx
]], pnt
[idx
].x
, pnt
[idx
].y
);
183 if (match
|| expected
[eidx
].todo
!= 2)
185 if (winetest_debug
> 2)
186 trace(" {%d, %d, %s, 0, 0}%s /* %d */\n", pnt
[idx
].x
, pnt
[idx
].y
,
187 type_string
[types
[idx
]], idx
< size
-1 ? "," : "};", idx
);
190 if (match
|| !numskip
--)
191 numskip
= expected
[++eidx
].wine_only_entries_preceding
;
194 /* If we are debugging and the actual path is longer than the expected path, make
195 * sure to display the entire path */
196 if (winetest_debug
> 2 && idx
< size
)
197 for (; idx
< size
; idx
++)
198 trace(" {%d, %d, %s, 0, 0}%s /* %d */\n", pnt
[idx
].x
, pnt
[idx
].y
,
199 type_string
[types
[idx
]], idx
< size
-1 ? "," : "};", idx
);
201 HeapFree(GetProcessHeap(), 0, types
);
202 HeapFree(GetProcessHeap(), 0, pnt
);
205 static const path_test_t arcto_path
[] = {
206 {0, 0, PT_MOVETO
, 0, 0}, /* 0 */
207 {229, 215, PT_LINETO
, 0, 0}, /* 1 */
208 {248, 205, PT_BEZIERTO
, 0, 0}, /* 2 */
209 {273, 200, PT_BEZIERTO
, 0, 0}, /* 3 */
210 {300, 200, PT_BEZIERTO
, 0, 0}, /* 4 */
211 {355, 200, PT_BEZIERTO
, 0, 0}, /* 5 */
212 {399, 222, PT_BEZIERTO
, 0, 0}, /* 6 */
213 {399, 250, PT_BEZIERTO
, 0, 0}, /* 7 */
214 {399, 263, PT_BEZIERTO
, 0, 0}, /* 8 */
215 {389, 275, PT_BEZIERTO
, 0, 0}, /* 9 */
216 {370, 285, PT_BEZIERTO
, 0, 0}, /* 10 */
217 {363, 277, PT_LINETO
, 0, 0}, /* 11 */
218 {380, 270, PT_BEZIERTO
, 0, 0}, /* 12 */
219 {389, 260, PT_BEZIERTO
, 0, 0}, /* 13 */
220 {389, 250, PT_BEZIERTO
, 0, 0}, /* 14 */
221 {389, 228, PT_BEZIERTO
, 0, 0}, /* 15 */
222 {349, 210, PT_BEZIERTO
, 0, 0}, /* 16 */
223 {300, 210, PT_BEZIERTO
, 0, 0}, /* 17 */
224 {276, 210, PT_BEZIERTO
, 0, 0}, /* 18 */
225 {253, 214, PT_BEZIERTO
, 0, 0}, /* 19 */
226 {236, 222, PT_BEZIERTO
| PT_CLOSEFIGURE
, 0, 0}}; /* 20 */
228 static void test_arcto(void)
233 SetArcDirection(hdc
, AD_CLOCKWISE
);
234 if (!ArcTo(hdc
, 200, 200, 400, 300, 200, 200, 400, 300) &&
235 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
237 /* ArcTo is only available on Win2k and later */
238 skip("ArcTo is not available\n");
241 SetArcDirection(hdc
, AD_COUNTERCLOCKWISE
);
242 ArcTo(hdc
, 210, 210, 390, 290, 390, 290, 210, 210);
246 ok_path(hdc
, "arcto_path", arcto_path
, sizeof(arcto_path
)/sizeof(path_test_t
), 0);
251 static const path_test_t anglearc_path
[] = {
252 {0, 0, PT_MOVETO
, 0, 0}, /* 0 */
253 {371, 229, PT_LINETO
, 0, 0}, /* 1 */
254 {352, 211, PT_BEZIERTO
, 0, 0}, /* 2 */
255 {327, 200, PT_BEZIERTO
, 0, 0}, /* 3 */
256 {300, 200, PT_BEZIERTO
, 0, 0}, /* 4 */
257 {245, 200, PT_BEZIERTO
, 0, 0}, /* 5 */
258 {200, 245, PT_BEZIERTO
, 0, 0}, /* 6 */
259 {200, 300, PT_BEZIERTO
, 0, 0}, /* 7 */
260 {200, 300, PT_BEZIERTO
, 0, 2}, /* 8 */
261 {200, 300, PT_BEZIERTO
, 0, 2}, /* 9 */
262 {200, 300, PT_BEZIERTO
, 0, 2}, /* 10 */
263 {231, 260, PT_LINETO
, 0, 0}, /* 11 */
264 {245, 235, PT_BEZIERTO
, 0, 0}, /* 12 */
265 {271, 220, PT_BEZIERTO
, 0, 0}, /* 13 */
266 {300, 220, PT_BEZIERTO
, 0, 0}, /* 14 */
267 {344, 220, PT_BEZIERTO
, 0, 0}, /* 15 */
268 {380, 256, PT_BEZIERTO
, 0, 0}, /* 16 */
269 {380, 300, PT_BEZIERTO
, 0, 0}, /* 17 */
270 {380, 314, PT_BEZIERTO
, 0, 0}, /* 18 */
271 {376, 328, PT_BEZIERTO
, 0, 0}, /* 19 */
272 {369, 340, PT_BEZIERTO
| PT_CLOSEFIGURE
, 0, 0}}; /* 20 */
274 static void test_anglearc(void)
278 if (!AngleArc(hdc
, 300, 300, 100, 45.0, 135.0) &&
279 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
281 /* AngleArc is only available on Win2k and later */
282 skip("AngleArc is not available\n");
285 AngleArc(hdc
, 300, 300, 80, 150.0, -180.0);
289 ok_path(hdc
, "anglearc_path", anglearc_path
, sizeof(anglearc_path
)/sizeof(path_test_t
), 1);