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 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
36 static void test_widenpath(void)
39 HPEN greenPen, narrowPen;
44 /* Create a pen to be used in WidenPath */
45 greenPen = CreatePen(PS_SOLID, 10, RGB(0,0,0));
46 oldPen = SelectObject(hdc, greenPen);
62 /* Set a polyline path */
64 Polyline(hdc, pnt, 6);
67 /* Widen the polyline path */
68 ok(WidenPath(hdc), "WidenPath fails while widening a poyline path.\n");
70 /* Test if WidenPath seems to have done his job */
71 nSize = GetPath(hdc, NULL, NULL, 0);
72 ok(nSize != -1, "GetPath fails after calling WidenPath.\n");
73 ok(nSize > 6, "Path number of points is too low. Should be more than 6 but is %d\n", nSize);
77 /* Test WidenPath with an open path (last error only set on Win2k and later) */
78 SetLastError(0xdeadbeef);
81 ok(ret == FALSE && (GetLastError() == ERROR_CAN_NOT_COMPLETE || GetLastError() == 0xdeadbeef),
82 "WidenPath fails while widening an open path. Return value is %d, should be %d. Error is %u\n", ret, FALSE, GetLastError());
86 /* Test when the pen width is equal to 1. The path should change too */
87 narrowPen = CreatePen(PS_SOLID, 1, RGB(0,0,0));
88 oldPen = SelectObject(hdc, narrowPen);
90 Polyline(hdc, pnt, 6);
93 nSize = GetPath(hdc, NULL, NULL, 0);
94 ok(nSize > 6, "WidenPath should compute a widdened path with a 1px wide pen. Path length is %d, should be more than 6\n", nSize);
101 * Tests for GDI drawing functions in paths
109 /* How many extra entries before this one only on wine
110 * but not on native? */
111 int wine_only_entries_preceding;
113 /* 0 - This entry matches on wine.
114 * 1 - This entry corresponds to a single entry on wine that does not match the native entry.
115 * 2 - This entry is currently skipped on wine but present on native. */
119 /* Helper function to verify that the current path in the given DC matches the expected path.
121 * We use a "smart" matching algorithm that allows us to detect partial improvements
122 * in conformance. Specifically, two running indices are kept, one through the actual
123 * path and one through the expected path. The actual path index increases unless there is
124 * no match and the todo field of the appropriate path_test_t element is 2. Similarly,
125 * if the wine_entries_preceding field of the appropriate path_test_t element is non-zero,
126 * the expected path index does not increase for that many elements as long as there
127 * is no match. This allows us to todo_wine extra path elements that are present only
128 * on wine but not on native and vice versa.
130 * Note that if expected_size is zero and the WINETEST_DEBUG environment variable is
131 * greater than 2, the trace() output is a C path_test_t array structure, useful for making
132 * new tests that use this function.
134 static void ok_path(HDC hdc, const char *path_name, const path_test_t *expected, int expected_size, BOOL todo_size)
136 static const char *type_string[8] = { "Unknown (0)", "PT_CLOSEFIGURE", "PT_LINETO",
137 "PT_LINETO | PT_CLOSEFIGURE", "PT_BEZIERTO",
138 "PT_BEZIERTO | PT_CLOSEFIGURE", "PT_MOVETO", "PT_MOVETO | PT_CLOSEFIGURE"};
146 size = GetPath(hdc, NULL, NULL, 0);
147 ok(size > 0, "GetPath returned size %d, last error %d\n", size, GetLastError());
150 skip("Cannot perform path comparisons due to failure to retrieve path.\n");
153 pnt = HeapAlloc(GetProcessHeap(), 0, size*sizeof(POINT));
155 types = HeapAlloc(GetProcessHeap(), 0, size*sizeof(BYTE));
157 size = GetPath(hdc, pnt, types, size);
160 if (todo_size) todo_wine
161 ok(size == expected_size, "Path size %d does not match expected size %d\n", size, expected_size);
163 ok(size == expected_size, "Path size %d does not match expected size %d\n", size, expected_size);
165 if (winetest_debug > 2)
166 trace("static const path_test_t %s[] = {\n", path_name);
168 numskip = expected_size ? expected[eidx].wine_only_entries_preceding : 0;
169 while (idx < size && eidx < expected_size)
171 /* We allow a few pixels fudge in matching X and Y coordinates to account for imprecision in
172 * floating point to integer conversion */
173 BOOL match = (types[idx] == expected[eidx].type) &&
174 (pnt[idx].x >= expected[eidx].x-2 && pnt[idx].x <= expected[eidx].x+2) &&
175 (pnt[idx].y >= expected[eidx].y-2 && pnt[idx].y <= expected[eidx].y+2);
177 if (expected[eidx].todo || numskip) todo_wine
178 ok(match, "Expected #%d: %s (%d,%d) but got %s (%d,%d)\n", eidx,
179 type_string[expected[eidx].type], expected[eidx].x, expected[eidx].y,
180 type_string[types[idx]], pnt[idx].x, pnt[idx].y);
182 ok(match, "Expected #%d: %s (%d,%d) but got %s (%d,%d)\n", eidx,
183 type_string[expected[eidx].type], expected[eidx].x, expected[eidx].y,
184 type_string[types[idx]], pnt[idx].x, pnt[idx].y);
186 if (match || expected[eidx].todo != 2)
188 if (winetest_debug > 2)
189 trace(" {%d, %d, %s, 0, 0}%s /* %d */\n", pnt[idx].x, pnt[idx].y,
190 type_string[types[idx]], idx < size-1 ? "," : "};", idx);
193 if (match || !numskip--)
194 numskip = expected[++eidx].wine_only_entries_preceding;
197 /* If we are debugging and the actual path is longer than the expected path, make
198 * sure to display the entire path */
199 if (winetest_debug > 2 && idx < size)
200 for (; idx < size; idx++)
201 trace(" {%d, %d, %s, 0, 0}%s /* %d */\n", pnt[idx].x, pnt[idx].y,
202 type_string[types[idx]], idx < size-1 ? "," : "};", idx);
204 HeapFree(GetProcessHeap(), 0, types);
205 HeapFree(GetProcessHeap(), 0, pnt);
208 static const path_test_t arcto_path[] = {
209 {0, 0, PT_MOVETO, 0, 0}, /* 0 */
210 {229, 215, PT_LINETO, 0, 0}, /* 1 */
211 {248, 205, PT_BEZIERTO, 0, 0}, /* 2 */
212 {273, 200, PT_BEZIERTO, 0, 0}, /* 3 */
213 {300, 200, PT_BEZIERTO, 0, 0}, /* 4 */
214 {355, 200, PT_BEZIERTO, 0, 0}, /* 5 */
215 {399, 222, PT_BEZIERTO, 0, 0}, /* 6 */
216 {399, 250, PT_BEZIERTO, 0, 0}, /* 7 */
217 {399, 263, PT_BEZIERTO, 0, 0}, /* 8 */
218 {389, 275, PT_BEZIERTO, 0, 0}, /* 9 */
219 {370, 285, PT_BEZIERTO, 0, 0}, /* 10 */
220 {363, 277, PT_LINETO, 0, 0}, /* 11 */
221 {380, 270, PT_BEZIERTO, 0, 0}, /* 12 */
222 {389, 260, PT_BEZIERTO, 0, 0}, /* 13 */
223 {389, 250, PT_BEZIERTO, 0, 0}, /* 14 */
224 {389, 228, PT_BEZIERTO, 0, 0}, /* 15 */
225 {349, 210, PT_BEZIERTO, 0, 0}, /* 16 */
226 {300, 210, PT_BEZIERTO, 0, 0}, /* 17 */
227 {276, 210, PT_BEZIERTO, 0, 0}, /* 18 */
228 {253, 214, PT_BEZIERTO, 0, 0}, /* 19 */
229 {236, 222, PT_BEZIERTO | PT_CLOSEFIGURE, 0, 0}}; /* 20 */
231 static void test_arcto(void)
236 SetArcDirection(hdc, AD_CLOCKWISE);
237 if (!ArcTo(hdc, 200, 200, 400, 300, 200, 200, 400, 300) &&
238 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
240 /* ArcTo is only available on Win2k and later */
241 win_skip("ArcTo is not available\n");
244 SetArcDirection(hdc, AD_COUNTERCLOCKWISE);
245 ArcTo(hdc, 210, 210, 390, 290, 390, 290, 210, 210);
249 ok_path(hdc, "arcto_path", arcto_path, sizeof(arcto_path)/sizeof(path_test_t), 0);
254 static const path_test_t anglearc_path[] = {
255 {0, 0, PT_MOVETO, 0, 0}, /* 0 */
256 {371, 229, PT_LINETO, 0, 0}, /* 1 */
257 {352, 211, PT_BEZIERTO, 0, 0}, /* 2 */
258 {327, 200, PT_BEZIERTO, 0, 0}, /* 3 */
259 {300, 200, PT_BEZIERTO, 0, 0}, /* 4 */
260 {245, 200, PT_BEZIERTO, 0, 0}, /* 5 */
261 {200, 245, PT_BEZIERTO, 0, 0}, /* 6 */
262 {200, 300, PT_BEZIERTO, 0, 0}, /* 7 */
263 {200, 300, PT_BEZIERTO, 0, 2}, /* 8 */
264 {200, 300, PT_BEZIERTO, 0, 2}, /* 9 */
265 {200, 300, PT_BEZIERTO, 0, 2}, /* 10 */
266 {231, 260, PT_LINETO, 0, 0}, /* 11 */
267 {245, 235, PT_BEZIERTO, 0, 0}, /* 12 */
268 {271, 220, PT_BEZIERTO, 0, 0}, /* 13 */
269 {300, 220, PT_BEZIERTO, 0, 0}, /* 14 */
270 {344, 220, PT_BEZIERTO, 0, 0}, /* 15 */
271 {380, 256, PT_BEZIERTO, 0, 0}, /* 16 */
272 {380, 300, PT_BEZIERTO, 0, 0}, /* 17 */
273 {380, 314, PT_BEZIERTO, 0, 0}, /* 18 */
274 {376, 328, PT_BEZIERTO, 0, 0}, /* 19 */
275 {369, 340, PT_BEZIERTO | PT_CLOSEFIGURE, 0, 0}}; /* 20 */
277 static void test_anglearc(void)
281 if (!AngleArc(hdc, 300, 300, 100, 45.0, 135.0) &&
282 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
284 /* AngleArc is only available on Win2k and later */
285 win_skip("AngleArc is not available\n");
288 AngleArc(hdc, 300, 300, 80, 150.0, -180.0);
292 ok_path(hdc, "anglearc_path", anglearc_path, sizeof(anglearc_path)/sizeof(path_test_t), 1);
297 static const path_test_t polydraw_path[] = {
298 {0, 0, PT_MOVETO, 0, 0}, /*0*/
299 {10, 10, PT_LINETO, 0, 0}, /*1*/
300 {10, 15, PT_LINETO | PT_CLOSEFIGURE, 0, 0}, /*2*/
301 {100, 100, PT_MOVETO, 0, 0}, /*3*/
302 {95, 95, PT_LINETO, 0, 0}, /*4*/
303 {10, 10, PT_LINETO, 0, 0}, /*5*/
304 {10, 15, PT_LINETO | PT_CLOSEFIGURE, 0, 0}, /*6*/
305 {100, 100, PT_MOVETO, 0, 0}, /*7*/
306 {15, 15, PT_LINETO, 0, 0}, /*8*/
307 {25, 25, PT_MOVETO, 0, 0}, /*9*/
308 {25, 30, PT_LINETO, 0, 0}, /*10*/
309 {100, 100, PT_MOVETO, 0, 0}, /*11*/
310 {30, 30, PT_BEZIERTO, 0, 0}, /*12*/
311 {30, 35, PT_BEZIERTO, 0, 0}, /*13*/
312 {35, 35, PT_BEZIERTO, 0, 0}, /*14*/
313 {35, 40, PT_LINETO, 0, 0}, /*15*/
314 {40, 40, PT_MOVETO, 0, 0}, /*16*/
315 {40, 45, PT_LINETO, 0, 0}, /*17*/
316 {35, 40, PT_MOVETO, 0, 0}, /*18*/
317 {45, 50, PT_LINETO, 0, 0}, /*19*/
318 {35, 40, PT_MOVETO, 0, 0}, /*20*/
319 {50, 55, PT_LINETO, 0, 0}, /*21*/
320 {45, 50, PT_LINETO, 0, 0}, /*22*/
321 {35, 40, PT_MOVETO, 0, 0}, /*23*/
322 {60, 60, PT_LINETO, 0, 0}, /*24*/
323 {60, 65, PT_MOVETO, 0, 0}, /*25*/
324 {65, 65, PT_LINETO, 0, 0} /*26*/
327 static POINT polydraw_pts[] = {
329 {15, 15}, {15, 20}, {20, 20}, {20, 25},
331 {30, 30}, {30, 35}, {35, 35}, {35, 40},
332 {40, 40}, {40, 45}, {45, 45},
334 {50, 55}, {45, 50}, {55, 60},
335 {60, 60}, {60, 65}, {65, 65}};
337 static BYTE polydraw_tps[] =
338 {PT_LINETO, PT_CLOSEFIGURE | PT_LINETO, /* 2 */
339 PT_LINETO, PT_BEZIERTO, PT_LINETO, PT_LINETO, /* 6 */
340 PT_MOVETO, PT_LINETO, /* 8 */
341 PT_BEZIERTO, PT_BEZIERTO, PT_BEZIERTO, PT_LINETO, /* 12 */
342 PT_MOVETO, PT_LINETO, PT_CLOSEFIGURE, /* 15 */
343 PT_LINETO, PT_MOVETO | PT_CLOSEFIGURE, /* 17 */
344 PT_LINETO, PT_LINETO, PT_MOVETO | PT_CLOSEFIGURE, /* 20 */
345 PT_LINETO, PT_MOVETO | PT_LINETO, PT_LINETO}; /* 23 */
347 static void test_polydraw(void)
353 /* closefigure with no previous moveto */
354 if (!(retb = PolyDraw(hdc, polydraw_pts, polydraw_tps, 2)) &&
355 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
357 /* PolyDraw is only available on Win2k and later */
358 win_skip("PolyDraw is not available\n");
363 MoveToEx(hdc, 100, 100, NULL);
365 /* closefigure with previous moveto */
366 retb = PolyDraw(hdc, polydraw_pts, polydraw_tps, 2);
368 /* bad bezier points */
369 retb = PolyDraw(hdc, &(polydraw_pts[2]), &(polydraw_tps[2]), 4);
371 retb = PolyDraw(hdc, &(polydraw_pts[6]), &(polydraw_tps[6]), 4);
373 /* good bezier points */
374 retb = PolyDraw(hdc, &(polydraw_pts[8]), &(polydraw_tps[8]), 4);
376 /* does lineto or bezierto take precedence? */
377 retb = PolyDraw(hdc, &(polydraw_pts[12]), &(polydraw_tps[12]), 4);
379 /* bad point type, has already moved cursor position */
380 retb = PolyDraw(hdc, &(polydraw_pts[15]), &(polydraw_tps[15]), 4);
382 /* bad point type, cursor position is moved, but back to its original spot */
383 retb = PolyDraw(hdc, &(polydraw_pts[17]), &(polydraw_tps[17]), 4);
385 /* does lineto or moveto take precedence? */
386 retb = PolyDraw(hdc, &(polydraw_pts[20]), &(polydraw_tps[20]), 3);
390 ok_path(hdc, "polydraw_path", polydraw_path, sizeof(polydraw_path)/sizeof(path_test_t), 0);
395 static void test_closefigure(void) {
397 int nSize, nSizeWitness;
401 MoveToEx(hdc, 95, 95, NULL);
405 retb = CloseFigure(hdc);
407 nSize = GetPath(hdc, NULL, NULL, 0);
412 MoveToEx(hdc, 95, 95, NULL);
417 nSizeWitness = GetPath(hdc, NULL, NULL, 0);
419 /* This test shows CloseFigure does not have to add a point at the end of the path */
420 ok(nSize == nSizeWitness, "Wrong number of points, no point should be added by CloseFigure\n");
425 static void WINAPI linedda_callback(INT x, INT y, LPARAM lparam)
427 POINT **pt = (POINT**)lparam;
428 ok((*pt)->x == x && (*pt)->y == y, "point mismatch expect(%d,%d) got(%d,%d)\n",
429 (*pt)->x, (*pt)->y, x, y);
435 static void test_linedda(void)
438 static const POINT array_10_20_20_40[] = {{10,20},{10,21},{11,22},{11,23},
439 {12,24},{12,25},{13,26},{13,27},
440 {14,28},{14,29},{15,30},{15,31},
441 {16,32},{16,33},{17,34},{17,35},
442 {18,36},{18,37},{19,38},{19,39},
444 static const POINT array_10_20_20_43[] = {{10,20},{10,21},{11,22},{11,23},
445 {12,24},{12,25},{13,26},{13,27},
446 {13,28},{14,29},{14,30},{15,31},
447 {15,32},{16,33},{16,34},{17,35},
448 {17,36},{17,37},{18,38},{18,39},
449 {19,40},{19,41},{20,42},{-1,-1}};
451 static const POINT array_10_20_10_20[] = {{-1,-1}};
452 static const POINT array_10_20_11_27[] = {{10,20},{10,21},{10,22},{10,23},
453 {11,24},{11,25},{11,26},{-1,-1}};
455 static const POINT array_20_43_10_20[] = {{20,43},{20,42},{19,41},{19,40},
456 {18,39},{18,38},{17,37},{17,36},
457 {17,35},{16,34},{16,33},{15,32},
458 {15,31},{14,30},{14,29},{13,28},
459 {13,27},{13,26},{12,25},{12,24},
460 {11,23},{11,22},{10,21},{-1,-1}};
462 static const POINT array_20_20_10_43[] = {{20,20},{20,21},{19,22},{19,23},
463 {18,24},{18,25},{17,26},{17,27},
464 {17,28},{16,29},{16,30},{15,31},
465 {15,32},{14,33},{14,34},{13,35},
466 {13,36},{13,37},{12,38},{12,39},
467 {11,40},{11,41},{10,42},{-1,-1}};
469 static const POINT array_20_20_43_10[] = {{20,20},{21,20},{22,19},{23,19},
470 {24,18},{25,18},{26,17},{27,17},
471 {28,17},{29,16},{30,16},{31,15},
472 {32,15},{33,14},{34,14},{35,13},
473 {36,13},{37,13},{38,12},{39,12},
474 {40,11},{41,11},{42,10},{-1,-1}};
477 pt = array_10_20_20_40;
478 LineDDA(10, 20, 20, 40, linedda_callback, (LPARAM)&pt);
479 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
481 pt = array_10_20_20_43;
482 LineDDA(10, 20, 20, 43, linedda_callback, (LPARAM)&pt);
483 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
485 pt = array_10_20_10_20;
486 LineDDA(10, 20, 10, 20, linedda_callback, (LPARAM)&pt);
487 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
489 pt = array_10_20_11_27;
490 LineDDA(10, 20, 11, 27, linedda_callback, (LPARAM)&pt);
491 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
493 pt = array_20_43_10_20;
494 LineDDA(20, 43, 10, 20, linedda_callback, (LPARAM)&pt);
495 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
497 pt = array_20_20_10_43;
498 LineDDA(20, 20, 10, 43, linedda_callback, (LPARAM)&pt);
499 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
501 pt = array_20_20_43_10;
502 LineDDA(20, 20, 43, 10, linedda_callback, (LPARAM)&pt);
503 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");