223a027107b0357d4c1c68e61790f8d479693139
[reactos.git] / rostests / winetests / gdi32 / path.c
1 /*
2 * Unit test suite for paths
3 *
4 * Copyright 2007 Laurent Vromman
5 * Copyright 2007 Misha Koshelev
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <assert.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28
29 #include "wine/test.h"
30
31 #include "winuser.h"
32 #include "winerror.h"
33
34 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
35
36 static void test_path_state(void)
37 {
38 BYTE buffer[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
39 BITMAPINFO *bi = (BITMAPINFO *)buffer;
40 HDC hdc;
41 HBITMAP orig, dib;
42 void *bits;
43 BOOL ret;
44
45 hdc = CreateCompatibleDC( 0 );
46 memset( buffer, 0, sizeof(buffer) );
47 bi->bmiHeader.biSize = sizeof(bi->bmiHeader);
48 bi->bmiHeader.biHeight = 256;
49 bi->bmiHeader.biWidth = 256;
50 bi->bmiHeader.biBitCount = 32;
51 bi->bmiHeader.biPlanes = 1;
52 bi->bmiHeader.biCompression = BI_RGB;
53 dib = CreateDIBSection( 0, bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0 );
54 orig = SelectObject( hdc, dib );
55
56 BeginPath( hdc );
57 LineTo( hdc, 100, 100 );
58 ret = WidenPath( hdc );
59 ok( !ret, "WidenPath succeeded\n" );
60
61 /* selecting another bitmap doesn't affect the path */
62 SelectObject( hdc, orig );
63 ret = WidenPath( hdc );
64 ok( !ret, "WidenPath succeeded\n" );
65
66 SelectObject( hdc, dib );
67 ret = WidenPath( hdc );
68 ok( !ret, "WidenPath succeeded\n" );
69
70 ret = EndPath( hdc );
71 ok( ret, "EndPath failed error %u\n", GetLastError() );
72 ret = WidenPath( hdc );
73 ok( ret, "WidenPath failed error %u\n", GetLastError() );
74
75 SelectObject( hdc, orig );
76 ret = WidenPath( hdc );
77 ok( ret, "WidenPath failed error %u\n", GetLastError() );
78
79 BeginPath( hdc );
80 LineTo( hdc, 100, 100 );
81 ret = WidenPath( hdc );
82 ok( !ret, "WidenPath succeeded\n" );
83 SaveDC( hdc );
84 SelectObject( hdc, dib );
85 ret = EndPath( hdc );
86 ok( ret, "EndPath failed error %u\n", GetLastError() );
87 ret = WidenPath( hdc );
88 ok( ret, "WidenPath failed error %u\n", GetLastError() );
89
90 /* path should be open again after RestoreDC */
91 RestoreDC( hdc, -1 );
92 ret = WidenPath( hdc );
93 ok( !ret, "WidenPath succeeded\n" );
94 ret = EndPath( hdc );
95 ok( ret, "EndPath failed error %u\n", GetLastError() );
96
97 SaveDC( hdc );
98 BeginPath( hdc );
99 RestoreDC( hdc, -1 );
100 ret = WidenPath( hdc );
101 ok( ret, "WidenPath failed error %u\n", GetLastError() );
102
103 /* test all functions with no path at all */
104 AbortPath( hdc );
105 SetLastError( 0xdeadbeef );
106 ret = WidenPath( hdc );
107 ok( !ret, "WidenPath succeeded\n" );
108 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
109 "wrong error %u\n", GetLastError() );
110
111 SetLastError( 0xdeadbeef );
112 ret = FlattenPath( hdc );
113 ok( !ret, "FlattenPath succeeded\n" );
114 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
115 "wrong error %u\n", GetLastError() );
116
117 SetLastError( 0xdeadbeef );
118 ret = StrokePath( hdc );
119 ok( !ret, "StrokePath succeeded\n" );
120 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
121 "wrong error %u\n", GetLastError() );
122
123 SetLastError( 0xdeadbeef );
124 ret = FillPath( hdc );
125 ok( !ret, "FillPath succeeded\n" );
126 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
127 "wrong error %u\n", GetLastError() );
128
129 SetLastError( 0xdeadbeef );
130 ret = StrokeAndFillPath( hdc );
131 ok( !ret, "StrokeAndFillPath succeeded\n" );
132 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
133 "wrong error %u\n", GetLastError() );
134
135 SetLastError( 0xdeadbeef );
136 ret = SelectClipPath( hdc, RGN_OR );
137 ok( !ret, "SelectClipPath succeeded\n" );
138 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
139 "wrong error %u\n", GetLastError() );
140
141 SetLastError( 0xdeadbeef );
142 ret = EndPath( hdc );
143 ok( !ret, "SelectClipPath succeeded\n" );
144 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
145 "wrong error %u\n", GetLastError() );
146
147 SetLastError( 0xdeadbeef );
148 ret = CloseFigure( hdc );
149 ok( !ret, "CloseFigure succeeded\n" );
150 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
151 "wrong error %u\n", GetLastError() );
152
153 /* test all functions with an open path */
154 AbortPath( hdc );
155 BeginPath( hdc );
156 SetLastError( 0xdeadbeef );
157 ret = WidenPath( hdc );
158 ok( !ret, "WidenPath succeeded\n" );
159 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
160 "wrong error %u\n", GetLastError() );
161
162 AbortPath( hdc );
163 BeginPath( hdc );
164 SetLastError( 0xdeadbeef );
165 ret = FlattenPath( hdc );
166 ok( !ret, "FlattenPath succeeded\n" );
167 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
168 "wrong error %u\n", GetLastError() );
169
170 AbortPath( hdc );
171 BeginPath( hdc );
172 SetLastError( 0xdeadbeef );
173 ret = StrokePath( hdc );
174 ok( !ret, "StrokePath succeeded\n" );
175 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
176 "wrong error %u\n", GetLastError() );
177
178 AbortPath( hdc );
179 BeginPath( hdc );
180 SetLastError( 0xdeadbeef );
181 ret = FillPath( hdc );
182 ok( !ret, "FillPath succeeded\n" );
183 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
184 "wrong error %u\n", GetLastError() );
185
186 AbortPath( hdc );
187 BeginPath( hdc );
188 SetLastError( 0xdeadbeef );
189 ret = StrokeAndFillPath( hdc );
190 ok( !ret, "StrokeAndFillPath succeeded\n" );
191 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
192 "wrong error %u\n", GetLastError() );
193
194 AbortPath( hdc );
195 BeginPath( hdc );
196 Rectangle( hdc, 1, 1, 10, 10 ); /* region needs some contents */
197 SetLastError( 0xdeadbeef );
198 ret = SelectClipPath( hdc, RGN_OR );
199 ok( !ret, "SelectClipPath succeeded\n" );
200 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
201 "wrong error %u\n", GetLastError() );
202
203 AbortPath( hdc );
204 BeginPath( hdc );
205 ret = CloseFigure( hdc );
206 ok( ret, "CloseFigure failed\n" );
207
208 /* test all functions with a closed path */
209 AbortPath( hdc );
210 BeginPath( hdc );
211 EndPath( hdc );
212 ret = WidenPath( hdc );
213 ok( ret, "WidenPath failed\n" );
214
215 AbortPath( hdc );
216 BeginPath( hdc );
217 EndPath( hdc );
218 ret = FlattenPath( hdc );
219 ok( ret, "FlattenPath failed\n" );
220
221 AbortPath( hdc );
222 BeginPath( hdc );
223 EndPath( hdc );
224 ret = StrokePath( hdc );
225 ok( ret, "StrokePath failed\n" );
226
227 AbortPath( hdc );
228 BeginPath( hdc );
229 EndPath( hdc );
230 ret = FillPath( hdc );
231 ok( ret, "FillPath failed\n" );
232
233 AbortPath( hdc );
234 BeginPath( hdc );
235 EndPath( hdc );
236 ret = StrokeAndFillPath( hdc );
237 ok( ret, "StrokeAndFillPath failed\n" );
238
239 AbortPath( hdc );
240 BeginPath( hdc );
241 Rectangle( hdc, 1, 1, 10, 10 ); /* region needs some contents */
242 EndPath( hdc );
243 ret = SelectClipPath( hdc, RGN_OR );
244 ok( ret, "SelectClipPath failed\n" );
245
246 AbortPath( hdc );
247 BeginPath( hdc );
248 EndPath( hdc );
249 SetLastError( 0xdeadbeef );
250 ret = CloseFigure( hdc );
251 ok( !ret, "CloseFigure succeeded\n" );
252 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
253 "wrong error %u\n", GetLastError() );
254
255 AbortPath( hdc );
256 BeginPath( hdc );
257 EndPath( hdc );
258 SetLastError( 0xdeadbeef );
259 ret = EndPath( hdc );
260 ok( !ret, "SelectClipPath succeeded\n" );
261 ok( GetLastError() == ERROR_CAN_NOT_COMPLETE || broken(GetLastError() == 0xdeadbeef),
262 "wrong error %u\n", GetLastError() );
263
264 DeleteDC( hdc );
265 DeleteObject( dib );
266 }
267
268 static void test_widenpath(void)
269 {
270 HDC hdc = GetDC(0);
271 HPEN greenPen, narrowPen;
272 POINT pnt[6];
273 INT nSize;
274 BOOL ret;
275
276 /* Create a pen to be used in WidenPath */
277 greenPen = CreatePen(PS_SOLID, 10, RGB(0,0,0));
278 SelectObject(hdc, greenPen);
279
280 /* Prepare a path */
281 pnt[0].x = 100;
282 pnt[0].y = 0;
283 pnt[1].x = 200;
284 pnt[1].y = 0;
285 pnt[2].x = 300;
286 pnt[2].y = 100;
287 pnt[3].x = 300;
288 pnt[3].y = 200;
289 pnt[4].x = 200;
290 pnt[4].y = 300;
291 pnt[5].x = 100;
292 pnt[5].y = 300;
293
294 /* Set a polyline path */
295 BeginPath(hdc);
296 Polyline(hdc, pnt, 6);
297 EndPath(hdc);
298
299 /* Widen the polyline path */
300 ok(WidenPath(hdc), "WidenPath fails while widening a poyline path.\n");
301
302 /* Test if WidenPath seems to have done his job */
303 nSize = GetPath(hdc, NULL, NULL, 0);
304 ok(nSize != -1, "GetPath fails after calling WidenPath.\n");
305 ok(nSize > 6, "Path number of points is too low. Should be more than 6 but is %d\n", nSize);
306
307 AbortPath(hdc);
308
309 /* Test WidenPath with an open path (last error only set on Win2k and later) */
310 SetLastError(0xdeadbeef);
311 BeginPath(hdc);
312 ret = WidenPath(hdc);
313 ok(ret == FALSE && (GetLastError() == ERROR_CAN_NOT_COMPLETE || GetLastError() == 0xdeadbeef),
314 "WidenPath fails while widening an open path. Return value is %d, should be %d. Error is %u\n", ret, FALSE, GetLastError());
315
316 AbortPath(hdc);
317
318 /* Test when the pen width is equal to 1. The path should change too */
319 narrowPen = CreatePen(PS_SOLID, 1, RGB(0,0,0));
320 SelectObject(hdc, narrowPen);
321 BeginPath(hdc);
322 Polyline(hdc, pnt, 6);
323 EndPath(hdc);
324 ret = WidenPath(hdc);
325 ok(ret == TRUE, "WidenPath failed: %d\n", GetLastError());
326 nSize = GetPath(hdc, NULL, NULL, 0);
327 ok(nSize > 6, "WidenPath should compute a widened path with a 1px wide pen. Path length is %d, should be more than 6\n", nSize);
328
329 ReleaseDC(0, hdc);
330 return;
331 }
332
333 /*
334 * Tests for GDI drawing functions in paths
335 */
336
337 typedef struct
338 {
339 int x, y;
340 BYTE type;
341
342 /* How many extra entries before this one only on wine
343 * but not on native? */
344 int wine_only_entries_preceding;
345
346 /* 0 - This entry matches on wine.
347 * 1 - This entry corresponds to a single entry on wine that does not match the native entry.
348 * 2 - This entry is currently skipped on wine but present on native. */
349 int todo;
350 } path_test_t;
351
352 /* Helper function to verify that the current path in the given DC matches the expected path.
353 *
354 * We use a "smart" matching algorithm that allows us to detect partial improvements
355 * in conformance. Specifically, two running indices are kept, one through the actual
356 * path and one through the expected path. The actual path index increases unless there is
357 * no match and the todo field of the appropriate path_test_t element is 2. Similarly,
358 * if the wine_entries_preceding field of the appropriate path_test_t element is non-zero,
359 * the expected path index does not increase for that many elements as long as there
360 * is no match. This allows us to todo_wine extra path elements that are present only
361 * on wine but not on native and vice versa.
362 *
363 * Note that if expected_size is zero and the WINETEST_DEBUG environment variable is
364 * greater than 2, the trace() output is a C path_test_t array structure, useful for making
365 * new tests that use this function.
366 */
367 static void ok_path(HDC hdc, const char *path_name, const path_test_t *expected, int expected_size, BOOL todo_size)
368 {
369 static const char *type_string[8] = { "Unknown (0)", "PT_CLOSEFIGURE", "PT_LINETO",
370 "PT_LINETO | PT_CLOSEFIGURE", "PT_BEZIERTO",
371 "PT_BEZIERTO | PT_CLOSEFIGURE", "PT_MOVETO", "PT_MOVETO | PT_CLOSEFIGURE"};
372 POINT *pnt = NULL;
373 BYTE *types = NULL;
374 int size, numskip,
375 idx = 0, eidx = 0;
376
377 /* Get the path */
378 assert(hdc != 0);
379 size = GetPath(hdc, NULL, NULL, 0);
380 ok(size > 0, "GetPath returned size %d, last error %d\n", size, GetLastError());
381 if (size <= 0)
382 {
383 skip("Cannot perform path comparisons due to failure to retrieve path.\n");
384 return;
385 }
386 pnt = HeapAlloc(GetProcessHeap(), 0, size*sizeof(POINT));
387 assert(pnt != 0);
388 types = HeapAlloc(GetProcessHeap(), 0, size*sizeof(BYTE));
389 assert(types != 0);
390 size = GetPath(hdc, pnt, types, size);
391 assert(size > 0);
392
393 todo_wine_if (todo_size)
394 ok(size == expected_size, "Path size %d does not match expected size %d\n", size, expected_size);
395
396 if (winetest_debug > 2)
397 trace("static const path_test_t %s[] = {\n", path_name);
398
399 numskip = expected_size ? expected[eidx].wine_only_entries_preceding : 0;
400 while (idx < size && eidx < expected_size)
401 {
402 /* We allow a few pixels fudge in matching X and Y coordinates to account for imprecision in
403 * floating point to integer conversion */
404 BOOL match = (types[idx] == expected[eidx].type) &&
405 (pnt[idx].x >= expected[eidx].x-2 && pnt[idx].x <= expected[eidx].x+2) &&
406 (pnt[idx].y >= expected[eidx].y-2 && pnt[idx].y <= expected[eidx].y+2);
407
408 todo_wine_if (expected[eidx].todo || numskip)
409 ok(match, "Expected #%d: %s (%d,%d) but got %s (%d,%d)\n", eidx,
410 type_string[expected[eidx].type], expected[eidx].x, expected[eidx].y,
411 type_string[types[idx]], pnt[idx].x, pnt[idx].y);
412
413 if (match || expected[eidx].todo != 2)
414 {
415 if (winetest_debug > 2)
416 trace(" {%d, %d, %s, 0, 0}%s /* %d */\n", pnt[idx].x, pnt[idx].y,
417 type_string[types[idx]], idx < size-1 ? "," : "};", idx);
418 idx++;
419 }
420 if (match || !numskip--)
421 numskip = expected[++eidx].wine_only_entries_preceding;
422 }
423
424 /* If we are debugging and the actual path is longer than the expected path, make
425 * sure to display the entire path */
426 if (winetest_debug > 2 && idx < size)
427 for (; idx < size; idx++)
428 trace(" {%d, %d, %s, 0, 0}%s /* %d */\n", pnt[idx].x, pnt[idx].y,
429 type_string[types[idx]], idx < size-1 ? "," : "};", idx);
430
431 HeapFree(GetProcessHeap(), 0, types);
432 HeapFree(GetProcessHeap(), 0, pnt);
433 }
434
435 static const path_test_t arcto_path[] = {
436 {0, 0, PT_MOVETO, 0, 0}, /* 0 */
437 {229, 215, PT_LINETO, 0, 0}, /* 1 */
438 {248, 205, PT_BEZIERTO, 0, 0}, /* 2 */
439 {273, 200, PT_BEZIERTO, 0, 0}, /* 3 */
440 {300, 200, PT_BEZIERTO, 0, 0}, /* 4 */
441 {355, 200, PT_BEZIERTO, 0, 0}, /* 5 */
442 {399, 222, PT_BEZIERTO, 0, 0}, /* 6 */
443 {399, 250, PT_BEZIERTO, 0, 0}, /* 7 */
444 {399, 263, PT_BEZIERTO, 0, 0}, /* 8 */
445 {389, 275, PT_BEZIERTO, 0, 0}, /* 9 */
446 {370, 285, PT_BEZIERTO, 0, 0}, /* 10 */
447 {363, 277, PT_LINETO, 0, 0}, /* 11 */
448 {380, 270, PT_BEZIERTO, 0, 0}, /* 12 */
449 {389, 260, PT_BEZIERTO, 0, 0}, /* 13 */
450 {389, 250, PT_BEZIERTO, 0, 0}, /* 14 */
451 {389, 228, PT_BEZIERTO, 0, 0}, /* 15 */
452 {349, 210, PT_BEZIERTO, 0, 0}, /* 16 */
453 {300, 210, PT_BEZIERTO, 0, 0}, /* 17 */
454 {276, 210, PT_BEZIERTO, 0, 0}, /* 18 */
455 {253, 214, PT_BEZIERTO, 0, 0}, /* 19 */
456 {236, 222, PT_BEZIERTO | PT_CLOSEFIGURE, 0, 0}}; /* 20 */
457
458 static void test_arcto(void)
459 {
460 HDC hdc = GetDC(0);
461
462 BeginPath(hdc);
463 SetArcDirection(hdc, AD_CLOCKWISE);
464 if (!ArcTo(hdc, 200, 200, 400, 300, 200, 200, 400, 300) &&
465 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
466 {
467 /* ArcTo is only available on Win2k and later */
468 win_skip("ArcTo is not available\n");
469 goto done;
470 }
471 SetArcDirection(hdc, AD_COUNTERCLOCKWISE);
472 ArcTo(hdc, 210, 210, 390, 290, 390, 290, 210, 210);
473 CloseFigure(hdc);
474 EndPath(hdc);
475
476 ok_path(hdc, "arcto_path", arcto_path, sizeof(arcto_path)/sizeof(path_test_t), 0);
477 done:
478 ReleaseDC(0, hdc);
479 }
480
481 static const path_test_t anglearc_path[] = {
482 {0, 0, PT_MOVETO, 0, 0}, /* 0 */
483 {371, 229, PT_LINETO, 0, 0}, /* 1 */
484 {352, 211, PT_BEZIERTO, 0, 0}, /* 2 */
485 {327, 200, PT_BEZIERTO, 0, 0}, /* 3 */
486 {300, 200, PT_BEZIERTO, 0, 0}, /* 4 */
487 {245, 200, PT_BEZIERTO, 0, 0}, /* 5 */
488 {200, 245, PT_BEZIERTO, 0, 0}, /* 6 */
489 {200, 300, PT_BEZIERTO, 0, 0}, /* 7 */
490 {200, 300, PT_BEZIERTO, 0, 0}, /* 8 */
491 {200, 300, PT_BEZIERTO, 0, 0}, /* 9 */
492 {200, 300, PT_BEZIERTO, 0, 0}, /* 10 */
493 {231, 260, PT_LINETO, 0, 0}, /* 11 */
494 {245, 235, PT_BEZIERTO, 0, 0}, /* 12 */
495 {271, 220, PT_BEZIERTO, 0, 0}, /* 13 */
496 {300, 220, PT_BEZIERTO, 0, 0}, /* 14 */
497 {344, 220, PT_BEZIERTO, 0, 0}, /* 15 */
498 {380, 256, PT_BEZIERTO, 0, 0}, /* 16 */
499 {380, 300, PT_BEZIERTO, 0, 0}, /* 17 */
500 {380, 314, PT_BEZIERTO, 0, 0}, /* 18 */
501 {376, 328, PT_BEZIERTO, 0, 0}, /* 19 */
502 {369, 340, PT_BEZIERTO | PT_CLOSEFIGURE, 0, 0}}; /* 20 */
503
504 static void test_anglearc(void)
505 {
506 HDC hdc = GetDC(0);
507 BeginPath(hdc);
508 if (!AngleArc(hdc, 300, 300, 100, 45.0, 135.0) &&
509 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
510 {
511 /* AngleArc is only available on Win2k and later */
512 win_skip("AngleArc is not available\n");
513 goto done;
514 }
515 AngleArc(hdc, 300, 300, 80, 150.0, -180.0);
516 CloseFigure(hdc);
517 EndPath(hdc);
518
519 ok_path(hdc, "anglearc_path", anglearc_path, sizeof(anglearc_path)/sizeof(path_test_t), 0);
520 done:
521 ReleaseDC(0, hdc);
522 }
523
524 static const path_test_t polydraw_path[] = {
525 {0, 0, PT_MOVETO, 0, 0}, /*0*/
526 {10, 10, PT_LINETO, 0, 0}, /*1*/
527 {10, 15, PT_LINETO | PT_CLOSEFIGURE, 0, 0}, /*2*/
528 {100, 100, PT_MOVETO, 0, 0}, /*3*/
529 {95, 95, PT_LINETO, 0, 0}, /*4*/
530 {10, 10, PT_LINETO, 0, 0}, /*5*/
531 {10, 15, PT_LINETO | PT_CLOSEFIGURE, 0, 0}, /*6*/
532 {100, 100, PT_MOVETO, 0, 0}, /*7*/
533 {15, 15, PT_LINETO, 0, 0}, /*8*/
534 {25, 25, PT_MOVETO, 0, 0}, /*9*/
535 {25, 30, PT_LINETO, 0, 0}, /*10*/
536 {100, 100, PT_MOVETO, 0, 0}, /*11*/
537 {30, 30, PT_BEZIERTO, 0, 0}, /*12*/
538 {30, 35, PT_BEZIERTO, 0, 0}, /*13*/
539 {35, 35, PT_BEZIERTO, 0, 0}, /*14*/
540 {35, 40, PT_LINETO, 0, 0}, /*15*/
541 {40, 40, PT_MOVETO, 0, 0}, /*16*/
542 {40, 45, PT_LINETO, 0, 0}, /*17*/
543 {35, 40, PT_MOVETO, 0, 0}, /*18*/
544 {45, 50, PT_LINETO, 0, 0}, /*19*/
545 {35, 40, PT_MOVETO, 0, 0}, /*20*/
546 {50, 55, PT_LINETO, 0, 0}, /*21*/
547 {45, 50, PT_LINETO, 0, 0}, /*22*/
548 {35, 40, PT_MOVETO, 0, 0}, /*23*/
549 {60, 60, PT_LINETO, 0, 0}, /*24*/
550 {60, 65, PT_MOVETO, 0, 0}, /*25*/
551 {65, 65, PT_LINETO, 0, 0} /*26*/
552 };
553
554 static POINT polydraw_pts[] = {
555 {10, 10}, {10, 15},
556 {15, 15}, {15, 20}, {20, 20}, {20, 25},
557 {25, 25}, {25, 30},
558 {30, 30}, {30, 35}, {35, 35}, {35, 40},
559 {40, 40}, {40, 45}, {45, 45},
560 {45, 50}, {50, 50},
561 {50, 55}, {45, 50}, {55, 60},
562 {60, 60}, {60, 65}, {65, 65}};
563
564 static BYTE polydraw_tps[] =
565 {PT_LINETO, PT_CLOSEFIGURE | PT_LINETO, /* 2 */
566 PT_LINETO, PT_BEZIERTO, PT_LINETO, PT_LINETO, /* 6 */
567 PT_MOVETO, PT_LINETO, /* 8 */
568 PT_BEZIERTO, PT_BEZIERTO, PT_BEZIERTO, PT_LINETO, /* 12 */
569 PT_MOVETO, PT_LINETO, PT_CLOSEFIGURE, /* 15 */
570 PT_LINETO, PT_MOVETO | PT_CLOSEFIGURE, /* 17 */
571 PT_LINETO, PT_LINETO, PT_MOVETO | PT_CLOSEFIGURE, /* 20 */
572 PT_LINETO, PT_MOVETO | PT_LINETO, PT_LINETO}; /* 23 */
573
574 static void test_polydraw(void)
575 {
576 BOOL retb;
577 HDC hdc = GetDC(0);
578 BeginPath(hdc);
579
580 /* closefigure with no previous moveto */
581 if (!(retb = PolyDraw(hdc, polydraw_pts, polydraw_tps, 2)) &&
582 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
583 {
584 /* PolyDraw is only available on Win2k and later */
585 win_skip("PolyDraw is not available\n");
586 goto done;
587 }
588 expect(TRUE, retb);
589
590 MoveToEx(hdc, 100, 100, NULL);
591 LineTo(hdc, 95, 95);
592 /* closefigure with previous moveto */
593 retb = PolyDraw(hdc, polydraw_pts, polydraw_tps, 2);
594 expect(TRUE, retb);
595 /* bad bezier points */
596 retb = PolyDraw(hdc, &(polydraw_pts[2]), &(polydraw_tps[2]), 4);
597 expect(FALSE, retb);
598 retb = PolyDraw(hdc, &(polydraw_pts[6]), &(polydraw_tps[6]), 4);
599 expect(FALSE, retb);
600 /* good bezier points */
601 retb = PolyDraw(hdc, &(polydraw_pts[8]), &(polydraw_tps[8]), 4);
602 expect(TRUE, retb);
603 /* does lineto or bezierto take precedence? */
604 retb = PolyDraw(hdc, &(polydraw_pts[12]), &(polydraw_tps[12]), 4);
605 expect(FALSE, retb);
606 /* bad point type, has already moved cursor position */
607 retb = PolyDraw(hdc, &(polydraw_pts[15]), &(polydraw_tps[15]), 4);
608 expect(FALSE, retb);
609 /* bad point type, cursor position is moved, but back to its original spot */
610 retb = PolyDraw(hdc, &(polydraw_pts[17]), &(polydraw_tps[17]), 4);
611 expect(FALSE, retb);
612 /* does lineto or moveto take precedence? */
613 retb = PolyDraw(hdc, &(polydraw_pts[20]), &(polydraw_tps[20]), 3);
614 expect(TRUE, retb);
615
616 EndPath(hdc);
617 ok_path(hdc, "polydraw_path", polydraw_path, sizeof(polydraw_path)/sizeof(path_test_t), 0);
618 done:
619 ReleaseDC(0, hdc);
620 }
621
622 static void test_closefigure(void) {
623 int nSize, nSizeWitness;
624 HDC hdc = GetDC(0);
625
626 BeginPath(hdc);
627 MoveToEx(hdc, 95, 95, NULL);
628 LineTo(hdc, 95, 0);
629 LineTo(hdc, 0, 95);
630
631 CloseFigure(hdc);
632 EndPath(hdc);
633 nSize = GetPath(hdc, NULL, NULL, 0);
634
635 AbortPath(hdc);
636
637 BeginPath(hdc);
638 MoveToEx(hdc, 95, 95, NULL);
639 LineTo(hdc, 95, 0);
640 LineTo(hdc, 0, 95);
641
642 EndPath(hdc);
643 nSizeWitness = GetPath(hdc, NULL, NULL, 0);
644
645 /* This test shows CloseFigure does not have to add a point at the end of the path */
646 ok(nSize == nSizeWitness, "Wrong number of points, no point should be added by CloseFigure\n");
647
648 ReleaseDC(0, hdc);
649 }
650
651 static void WINAPI linedda_callback(INT x, INT y, LPARAM lparam)
652 {
653 POINT **pt = (POINT**)lparam;
654 ok((*pt)->x == x && (*pt)->y == y, "point mismatch expect(%d,%d) got(%d,%d)\n",
655 (*pt)->x, (*pt)->y, x, y);
656
657 (*pt)++;
658 return;
659 }
660
661 static void test_linedda(void)
662 {
663 const POINT *pt;
664 static const POINT array_10_20_20_40[] = {{10,20},{10,21},{11,22},{11,23},
665 {12,24},{12,25},{13,26},{13,27},
666 {14,28},{14,29},{15,30},{15,31},
667 {16,32},{16,33},{17,34},{17,35},
668 {18,36},{18,37},{19,38},{19,39},
669 {-1,-1}};
670 static const POINT array_10_20_20_43[] = {{10,20},{10,21},{11,22},{11,23},
671 {12,24},{12,25},{13,26},{13,27},
672 {13,28},{14,29},{14,30},{15,31},
673 {15,32},{16,33},{16,34},{17,35},
674 {17,36},{17,37},{18,38},{18,39},
675 {19,40},{19,41},{20,42},{-1,-1}};
676
677 static const POINT array_10_20_10_20[] = {{-1,-1}};
678 static const POINT array_10_20_11_27[] = {{10,20},{10,21},{10,22},{10,23},
679 {11,24},{11,25},{11,26},{-1,-1}};
680
681 static const POINT array_20_43_10_20[] = {{20,43},{20,42},{19,41},{19,40},
682 {18,39},{18,38},{17,37},{17,36},
683 {17,35},{16,34},{16,33},{15,32},
684 {15,31},{14,30},{14,29},{13,28},
685 {13,27},{13,26},{12,25},{12,24},
686 {11,23},{11,22},{10,21},{-1,-1}};
687
688 static const POINT array_20_20_10_43[] = {{20,20},{20,21},{19,22},{19,23},
689 {18,24},{18,25},{17,26},{17,27},
690 {17,28},{16,29},{16,30},{15,31},
691 {15,32},{14,33},{14,34},{13,35},
692 {13,36},{13,37},{12,38},{12,39},
693 {11,40},{11,41},{10,42},{-1,-1}};
694
695 static const POINT array_20_20_43_10[] = {{20,20},{21,20},{22,19},{23,19},
696 {24,18},{25,18},{26,17},{27,17},
697 {28,17},{29,16},{30,16},{31,15},
698 {32,15},{33,14},{34,14},{35,13},
699 {36,13},{37,13},{38,12},{39,12},
700 {40,11},{41,11},{42,10},{-1,-1}};
701
702
703 pt = array_10_20_20_40;
704 LineDDA(10, 20, 20, 40, linedda_callback, (LPARAM)&pt);
705 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
706
707 pt = array_10_20_20_43;
708 LineDDA(10, 20, 20, 43, linedda_callback, (LPARAM)&pt);
709 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
710
711 pt = array_10_20_10_20;
712 LineDDA(10, 20, 10, 20, linedda_callback, (LPARAM)&pt);
713 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
714
715 pt = array_10_20_11_27;
716 LineDDA(10, 20, 11, 27, linedda_callback, (LPARAM)&pt);
717 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
718
719 pt = array_20_43_10_20;
720 LineDDA(20, 43, 10, 20, linedda_callback, (LPARAM)&pt);
721 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
722
723 pt = array_20_20_10_43;
724 LineDDA(20, 20, 10, 43, linedda_callback, (LPARAM)&pt);
725 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
726
727 pt = array_20_20_43_10;
728 LineDDA(20, 20, 43, 10, linedda_callback, (LPARAM)&pt);
729 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
730 }
731
732 START_TEST(path)
733 {
734 test_path_state();
735 test_widenpath();
736 test_arcto();
737 test_anglearc();
738 test_polydraw();
739 test_closefigure();
740 test_linedda();
741 }