gdi32: Handle ArcTo in paths as native.
[wine/multimedia.git] / dlls / gdi32 / tests / path.c
blobe567106453ee701ecabe2ad6681b0374e4d3cbb5
1 /*
2 * Unit test suite for paths
4 * Copyright 2007 Laurent Vromman
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.
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.
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
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <assert.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
28 #include "wine/test.h"
30 #include "winuser.h"
31 #include "winerror.h"
33 static void test_widenpath(void)
35 HDC hdc = GetDC(0);
36 HPEN greenPen, narrowPen;
37 HPEN oldPen;
38 POINT pnt[6];
39 INT nSize, ret;
40 DWORD error;
42 /* Create a pen to be used in WidenPath */
43 greenPen = CreatePen(PS_SOLID, 10, RGB(0,0,0));
44 oldPen = SelectObject(hdc, greenPen);
46 /* Prepare a path */
47 pnt[0].x = 100;
48 pnt[0].y = 0;
49 pnt[1].x = 200;
50 pnt[1].y = 0;
51 pnt[2].x = 300;
52 pnt[2].y = 100;
53 pnt[3].x = 300;
54 pnt[3].y = 200;
55 pnt[4].x = 200;
56 pnt[4].y = 300;
57 pnt[5].x = 100;
58 pnt[5].y = 300;
60 /* Set a polyline path */
61 BeginPath(hdc);
62 Polyline(hdc, pnt, 6);
63 EndPath(hdc);
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);
73 AbortPath(hdc);
75 /* Test WidenPath with an open path */
76 SetLastError(0xdeadbeef);
77 BeginPath(hdc);
78 ret = WidenPath(hdc);
79 error = GetLastError();
80 ok(ret == FALSE && GetLastError() == ERROR_CAN_NOT_COMPLETE, "WidenPath fails while widening an open path. Return value is %d, should be %d. Error is %08x, should be %08x\n", ret, FALSE, GetLastError(), ERROR_CAN_NOT_COMPLETE);
82 AbortPath(hdc);
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);
87 BeginPath(hdc);
88 Polyline(hdc, pnt, 6);
89 EndPath(hdc);
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);
93 ReleaseDC(0, hdc);
94 return;
98 * Tests for GDI drawing functions in paths
101 typedef struct
103 int x, y;
104 BYTE type;
106 /* How many extra entries before this one only on wine
107 * but not on native? */
108 int wine_only_entries_preceding;
110 /* Does this entry itself not match on wine? */
111 int todo;
112 } path_test_t;
114 /* Helper function to verify that the current path in the given DC matches the expected path.
116 * We use a "smart" matching algorithm that allows us to detect partial improvements
117 * in conformance. Specifically, two running indices are kept, one through the actual
118 * path and one through the expected path. The actual path index always increases,
119 * whereas, if the wine_entries_preceding field of the appropriate path_test_t element is
120 * non-zero, the expected path index does not increase for that many elements as long as
121 * there is no match. This allows us to todo_wine extra path elements that are present only
122 * in wine but not on native.
124 * Note that if expected_size is zero and the WINETEST_DEBUG environment variable is
125 * greater than 2, the trace() output is a C path_test_t array structure, useful for making
126 * new tests that use this function.
128 static void ok_path(HDC hdc, const path_test_t *expected, int expected_size, BOOL todo_size)
130 static const char *type_string[8] = { "Unknown (0)", "PT_CLOSEFIGURE", "PT_LINETO",
131 "PT_LINETO | PT_CLOSEFIGURE", "PT_BEZIERTO",
132 "PT_BEZIERTO | PT_CLOSEFIGURE", "PT_MOVETO", "PT_MOVETO | PT_CLOSEFIGURE"};
133 POINT *pnt = NULL;
134 BYTE *types = NULL;
135 int size, numskip,
136 idx, eidx = 0;
138 /* Get the path */
139 assert(hdc != 0);
140 size = GetPath(hdc, NULL, NULL, 0);
141 ok(size > 0, "GetPath returned size %d, last error %d\n", size, GetLastError());
142 if (size <= 0)
144 skip("Cannot perform path comparisons due to failure to retrieve path.\n");
145 return;
147 pnt = HeapAlloc(GetProcessHeap(), 0, size*sizeof(POINT));
148 assert(pnt != 0);
149 types = HeapAlloc(GetProcessHeap(), 0, size*sizeof(BYTE));
150 assert(types != 0);
151 size = GetPath(hdc, pnt, types, size);
152 assert(size > 0);
154 if (todo_size) todo_wine
155 ok(size == expected_size, "Path size %d does not match expected size %d\n", size, expected_size);
156 else
157 ok(size == expected_size, "Path size %d does not match expected size %d\n", size, expected_size);
159 if (expected_size) numskip = expected[eidx].wine_only_entries_preceding;
160 for (idx = 0; idx < size && eidx < expected_size; idx++)
162 /* We allow a few pixels fudge in matching X and Y coordinates to account for imprecision in
163 * floating point to integer conversion */
164 BOOL match = (types[idx] == expected[eidx].type) &&
165 (pnt[idx].x >= expected[eidx].x-1 && pnt[idx].x <= expected[eidx].x+1) &&
166 (pnt[idx].y >= expected[eidx].y-1 && pnt[idx].y <= expected[eidx].y+1);
168 if (winetest_debug > 2)
169 trace("{%d, %d, %s, 0, 0}, /* %d */\n", pnt[idx].x, pnt[idx].y, type_string[types[idx]], idx);
171 if (expected[eidx].todo || numskip) todo_wine
172 ok(match, "Expected #%d: %s (%d,%d) but got %s (%d,%d)\n", eidx,
173 type_string[expected[eidx].type], expected[eidx].x, expected[eidx].y,
174 type_string[types[idx]], pnt[idx].x, pnt[idx].y);
175 else
176 ok(match, "Expected #%d: %s (%d,%d) but got %s (%d,%d)\n", eidx,
177 type_string[expected[eidx].type], expected[eidx].x, expected[eidx].y,
178 type_string[types[idx]], pnt[idx].x, pnt[idx].y);
180 if (match || !numskip--)
181 numskip = expected[++eidx].wine_only_entries_preceding;
184 /* If we are debugging and the actual path is longer than the expected path, make
185 * sure to display the entire path */
186 if (winetest_debug > 2 && idx < size)
187 for (; idx < size; idx++)
188 trace("{%d, %d, %s, 0, 0}, /* %d */\n", pnt[idx].x, pnt[idx].y, type_string[types[idx]], idx);
190 HeapFree(GetProcessHeap(), 0, types);
191 HeapFree(GetProcessHeap(), 0, pnt);
194 static const path_test_t arcto_path[] = {
195 {0, 0, PT_MOVETO, 0, 0}, /* 0 */
196 {229, 215, PT_LINETO, 0, 0}, /* 1 */
197 {248, 205, PT_BEZIERTO, 0, 0}, /* 2 */
198 {273, 200, PT_BEZIERTO, 0, 0}, /* 3 */
199 {300, 200, PT_BEZIERTO, 0, 0}, /* 4 */
200 {355, 200, PT_BEZIERTO, 0, 0}, /* 5 */
201 {399, 222, PT_BEZIERTO, 0, 0}, /* 6 */
202 {399, 250, PT_BEZIERTO, 0, 0}, /* 7 */
203 {399, 263, PT_BEZIERTO, 0, 0}, /* 8 */
204 {389, 275, PT_BEZIERTO, 0, 0}, /* 9 */
205 {370, 285, PT_BEZIERTO, 0, 0}, /* 10 */
206 {363, 277, PT_LINETO, 0, 0}, /* 11 */
207 {380, 270, PT_BEZIERTO, 0, 0}, /* 12 */
208 {389, 260, PT_BEZIERTO, 0, 0}, /* 13 */
209 {389, 250, PT_BEZIERTO, 0, 0}, /* 14 */
210 {389, 228, PT_BEZIERTO, 0, 0}, /* 15 */
211 {349, 210, PT_BEZIERTO, 0, 0}, /* 16 */
212 {300, 210, PT_BEZIERTO, 0, 0}, /* 17 */
213 {276, 210, PT_BEZIERTO, 0, 0}, /* 18 */
214 {253, 214, PT_BEZIERTO, 0, 0}, /* 19 */
215 {236, 222, PT_BEZIERTO | PT_CLOSEFIGURE, 0, 0}}; /* 20 */
217 static void test_arcto(void)
219 HDC hdc = GetDC(0);
221 BeginPath(hdc);
222 SetArcDirection(hdc, AD_CLOCKWISE);
223 if (!ArcTo(hdc, 200, 200, 400, 300, 200, 200, 400, 300) &&
224 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
226 /* ArcTo is only available on Win2k and later */
227 skip("ArcTo is not available\n");
228 goto done;
230 SetArcDirection(hdc, AD_COUNTERCLOCKWISE);
231 ArcTo(hdc, 210, 210, 390, 290, 390, 290, 210, 210);
232 CloseFigure(hdc);
233 EndPath(hdc);
235 ok_path(hdc, arcto_path, sizeof(arcto_path)/sizeof(path_test_t), 0);
236 done:
237 ReleaseDC(0, hdc);
240 START_TEST(path)
242 test_widenpath();
243 test_arcto();