0b350bc9886b0c0e4364bf3d23106fb7af949729
[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 if (todo_size) todo_wine
394 ok(size == expected_size, "Path size %d does not match expected size %d\n", size, expected_size);
395 else
396 ok(size == expected_size, "Path size %d does not match expected size %d\n", size, expected_size);
397
398 if (winetest_debug > 2)
399 trace("static const path_test_t %s[] = {\n", path_name);
400
401 numskip = expected_size ? expected[eidx].wine_only_entries_preceding : 0;
402 while (idx < size && eidx < expected_size)
403 {
404 /* We allow a few pixels fudge in matching X and Y coordinates to account for imprecision in
405 * floating point to integer conversion */
406 BOOL match = (types[idx] == expected[eidx].type) &&
407 (pnt[idx].x >= expected[eidx].x-2 && pnt[idx].x <= expected[eidx].x+2) &&
408 (pnt[idx].y >= expected[eidx].y-2 && pnt[idx].y <= expected[eidx].y+2);
409
410 if (expected[eidx].todo || numskip) todo_wine
411 ok(match, "Expected #%d: %s (%d,%d) but got %s (%d,%d)\n", eidx,
412 type_string[expected[eidx].type], expected[eidx].x, expected[eidx].y,
413 type_string[types[idx]], pnt[idx].x, pnt[idx].y);
414 else
415 ok(match, "Expected #%d: %s (%d,%d) but got %s (%d,%d)\n", eidx,
416 type_string[expected[eidx].type], expected[eidx].x, expected[eidx].y,
417 type_string[types[idx]], pnt[idx].x, pnt[idx].y);
418
419 if (match || expected[eidx].todo != 2)
420 {
421 if (winetest_debug > 2)
422 trace(" {%d, %d, %s, 0, 0}%s /* %d */\n", pnt[idx].x, pnt[idx].y,
423 type_string[types[idx]], idx < size-1 ? "," : "};", idx);
424 idx++;
425 }
426 if (match || !numskip--)
427 numskip = expected[++eidx].wine_only_entries_preceding;
428 }
429
430 /* If we are debugging and the actual path is longer than the expected path, make
431 * sure to display the entire path */
432 if (winetest_debug > 2 && idx < size)
433 for (; idx < size; idx++)
434 trace(" {%d, %d, %s, 0, 0}%s /* %d */\n", pnt[idx].x, pnt[idx].y,
435 type_string[types[idx]], idx < size-1 ? "," : "};", idx);
436
437 HeapFree(GetProcessHeap(), 0, types);
438 HeapFree(GetProcessHeap(), 0, pnt);
439 }
440
441 static const path_test_t arcto_path[] = {
442 {0, 0, PT_MOVETO, 0, 0}, /* 0 */
443 {229, 215, PT_LINETO, 0, 0}, /* 1 */
444 {248, 205, PT_BEZIERTO, 0, 0}, /* 2 */
445 {273, 200, PT_BEZIERTO, 0, 0}, /* 3 */
446 {300, 200, PT_BEZIERTO, 0, 0}, /* 4 */
447 {355, 200, PT_BEZIERTO, 0, 0}, /* 5 */
448 {399, 222, PT_BEZIERTO, 0, 0}, /* 6 */
449 {399, 250, PT_BEZIERTO, 0, 0}, /* 7 */
450 {399, 263, PT_BEZIERTO, 0, 0}, /* 8 */
451 {389, 275, PT_BEZIERTO, 0, 0}, /* 9 */
452 {370, 285, PT_BEZIERTO, 0, 0}, /* 10 */
453 {363, 277, PT_LINETO, 0, 0}, /* 11 */
454 {380, 270, PT_BEZIERTO, 0, 0}, /* 12 */
455 {389, 260, PT_BEZIERTO, 0, 0}, /* 13 */
456 {389, 250, PT_BEZIERTO, 0, 0}, /* 14 */
457 {389, 228, PT_BEZIERTO, 0, 0}, /* 15 */
458 {349, 210, PT_BEZIERTO, 0, 0}, /* 16 */
459 {300, 210, PT_BEZIERTO, 0, 0}, /* 17 */
460 {276, 210, PT_BEZIERTO, 0, 0}, /* 18 */
461 {253, 214, PT_BEZIERTO, 0, 0}, /* 19 */
462 {236, 222, PT_BEZIERTO | PT_CLOSEFIGURE, 0, 0}}; /* 20 */
463
464 static void test_arcto(void)
465 {
466 HDC hdc = GetDC(0);
467
468 BeginPath(hdc);
469 SetArcDirection(hdc, AD_CLOCKWISE);
470 if (!ArcTo(hdc, 200, 200, 400, 300, 200, 200, 400, 300) &&
471 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
472 {
473 /* ArcTo is only available on Win2k and later */
474 win_skip("ArcTo is not available\n");
475 goto done;
476 }
477 SetArcDirection(hdc, AD_COUNTERCLOCKWISE);
478 ArcTo(hdc, 210, 210, 390, 290, 390, 290, 210, 210);
479 CloseFigure(hdc);
480 EndPath(hdc);
481
482 ok_path(hdc, "arcto_path", arcto_path, sizeof(arcto_path)/sizeof(path_test_t), 0);
483 done:
484 ReleaseDC(0, hdc);
485 }
486
487 static const path_test_t anglearc_path[] = {
488 {0, 0, PT_MOVETO, 0, 0}, /* 0 */
489 {371, 229, PT_LINETO, 0, 0}, /* 1 */
490 {352, 211, PT_BEZIERTO, 0, 0}, /* 2 */
491 {327, 200, PT_BEZIERTO, 0, 0}, /* 3 */
492 {300, 200, PT_BEZIERTO, 0, 0}, /* 4 */
493 {245, 200, PT_BEZIERTO, 0, 0}, /* 5 */
494 {200, 245, PT_BEZIERTO, 0, 0}, /* 6 */
495 {200, 300, PT_BEZIERTO, 0, 0}, /* 7 */
496 {200, 300, PT_BEZIERTO, 0, 0}, /* 8 */
497 {200, 300, PT_BEZIERTO, 0, 0}, /* 9 */
498 {200, 300, PT_BEZIERTO, 0, 0}, /* 10 */
499 {231, 260, PT_LINETO, 0, 0}, /* 11 */
500 {245, 235, PT_BEZIERTO, 0, 0}, /* 12 */
501 {271, 220, PT_BEZIERTO, 0, 0}, /* 13 */
502 {300, 220, PT_BEZIERTO, 0, 0}, /* 14 */
503 {344, 220, PT_BEZIERTO, 0, 0}, /* 15 */
504 {380, 256, PT_BEZIERTO, 0, 0}, /* 16 */
505 {380, 300, PT_BEZIERTO, 0, 0}, /* 17 */
506 {380, 314, PT_BEZIERTO, 0, 0}, /* 18 */
507 {376, 328, PT_BEZIERTO, 0, 0}, /* 19 */
508 {369, 340, PT_BEZIERTO | PT_CLOSEFIGURE, 0, 0}}; /* 20 */
509
510 static void test_anglearc(void)
511 {
512 HDC hdc = GetDC(0);
513 BeginPath(hdc);
514 if (!AngleArc(hdc, 300, 300, 100, 45.0, 135.0) &&
515 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
516 {
517 /* AngleArc is only available on Win2k and later */
518 win_skip("AngleArc is not available\n");
519 goto done;
520 }
521 AngleArc(hdc, 300, 300, 80, 150.0, -180.0);
522 CloseFigure(hdc);
523 EndPath(hdc);
524
525 ok_path(hdc, "anglearc_path", anglearc_path, sizeof(anglearc_path)/sizeof(path_test_t), 0);
526 done:
527 ReleaseDC(0, hdc);
528 }
529
530 static const path_test_t polydraw_path[] = {
531 {0, 0, PT_MOVETO, 0, 0}, /*0*/
532 {10, 10, PT_LINETO, 0, 0}, /*1*/
533 {10, 15, PT_LINETO | PT_CLOSEFIGURE, 0, 0}, /*2*/
534 {100, 100, PT_MOVETO, 0, 0}, /*3*/
535 {95, 95, PT_LINETO, 0, 0}, /*4*/
536 {10, 10, PT_LINETO, 0, 0}, /*5*/
537 {10, 15, PT_LINETO | PT_CLOSEFIGURE, 0, 0}, /*6*/
538 {100, 100, PT_MOVETO, 0, 0}, /*7*/
539 {15, 15, PT_LINETO, 0, 0}, /*8*/
540 {25, 25, PT_MOVETO, 0, 0}, /*9*/
541 {25, 30, PT_LINETO, 0, 0}, /*10*/
542 {100, 100, PT_MOVETO, 0, 0}, /*11*/
543 {30, 30, PT_BEZIERTO, 0, 0}, /*12*/
544 {30, 35, PT_BEZIERTO, 0, 0}, /*13*/
545 {35, 35, PT_BEZIERTO, 0, 0}, /*14*/
546 {35, 40, PT_LINETO, 0, 0}, /*15*/
547 {40, 40, PT_MOVETO, 0, 0}, /*16*/
548 {40, 45, PT_LINETO, 0, 0}, /*17*/
549 {35, 40, PT_MOVETO, 0, 0}, /*18*/
550 {45, 50, PT_LINETO, 0, 0}, /*19*/
551 {35, 40, PT_MOVETO, 0, 0}, /*20*/
552 {50, 55, PT_LINETO, 0, 0}, /*21*/
553 {45, 50, PT_LINETO, 0, 0}, /*22*/
554 {35, 40, PT_MOVETO, 0, 0}, /*23*/
555 {60, 60, PT_LINETO, 0, 0}, /*24*/
556 {60, 65, PT_MOVETO, 0, 0}, /*25*/
557 {65, 65, PT_LINETO, 0, 0} /*26*/
558 };
559
560 static POINT polydraw_pts[] = {
561 {10, 10}, {10, 15},
562 {15, 15}, {15, 20}, {20, 20}, {20, 25},
563 {25, 25}, {25, 30},
564 {30, 30}, {30, 35}, {35, 35}, {35, 40},
565 {40, 40}, {40, 45}, {45, 45},
566 {45, 50}, {50, 50},
567 {50, 55}, {45, 50}, {55, 60},
568 {60, 60}, {60, 65}, {65, 65}};
569
570 static BYTE polydraw_tps[] =
571 {PT_LINETO, PT_CLOSEFIGURE | PT_LINETO, /* 2 */
572 PT_LINETO, PT_BEZIERTO, PT_LINETO, PT_LINETO, /* 6 */
573 PT_MOVETO, PT_LINETO, /* 8 */
574 PT_BEZIERTO, PT_BEZIERTO, PT_BEZIERTO, PT_LINETO, /* 12 */
575 PT_MOVETO, PT_LINETO, PT_CLOSEFIGURE, /* 15 */
576 PT_LINETO, PT_MOVETO | PT_CLOSEFIGURE, /* 17 */
577 PT_LINETO, PT_LINETO, PT_MOVETO | PT_CLOSEFIGURE, /* 20 */
578 PT_LINETO, PT_MOVETO | PT_LINETO, PT_LINETO}; /* 23 */
579
580 static void test_polydraw(void)
581 {
582 BOOL retb;
583 HDC hdc = GetDC(0);
584 BeginPath(hdc);
585
586 /* closefigure with no previous moveto */
587 if (!(retb = PolyDraw(hdc, polydraw_pts, polydraw_tps, 2)) &&
588 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
589 {
590 /* PolyDraw is only available on Win2k and later */
591 win_skip("PolyDraw is not available\n");
592 goto done;
593 }
594 expect(TRUE, retb);
595
596 MoveToEx(hdc, 100, 100, NULL);
597 LineTo(hdc, 95, 95);
598 /* closefigure with previous moveto */
599 retb = PolyDraw(hdc, polydraw_pts, polydraw_tps, 2);
600 expect(TRUE, retb);
601 /* bad bezier points */
602 retb = PolyDraw(hdc, &(polydraw_pts[2]), &(polydraw_tps[2]), 4);
603 expect(FALSE, retb);
604 retb = PolyDraw(hdc, &(polydraw_pts[6]), &(polydraw_tps[6]), 4);
605 expect(FALSE, retb);
606 /* good bezier points */
607 retb = PolyDraw(hdc, &(polydraw_pts[8]), &(polydraw_tps[8]), 4);
608 expect(TRUE, retb);
609 /* does lineto or bezierto take precedence? */
610 retb = PolyDraw(hdc, &(polydraw_pts[12]), &(polydraw_tps[12]), 4);
611 expect(FALSE, retb);
612 /* bad point type, has already moved cursor position */
613 retb = PolyDraw(hdc, &(polydraw_pts[15]), &(polydraw_tps[15]), 4);
614 expect(FALSE, retb);
615 /* bad point type, cursor position is moved, but back to its original spot */
616 retb = PolyDraw(hdc, &(polydraw_pts[17]), &(polydraw_tps[17]), 4);
617 expect(FALSE, retb);
618 /* does lineto or moveto take precedence? */
619 retb = PolyDraw(hdc, &(polydraw_pts[20]), &(polydraw_tps[20]), 3);
620 expect(TRUE, retb);
621
622 EndPath(hdc);
623 ok_path(hdc, "polydraw_path", polydraw_path, sizeof(polydraw_path)/sizeof(path_test_t), 0);
624 done:
625 ReleaseDC(0, hdc);
626 }
627
628 static void test_closefigure(void) {
629 int nSize, nSizeWitness;
630 HDC hdc = GetDC(0);
631
632 BeginPath(hdc);
633 MoveToEx(hdc, 95, 95, NULL);
634 LineTo(hdc, 95, 0);
635 LineTo(hdc, 0, 95);
636
637 CloseFigure(hdc);
638 EndPath(hdc);
639 nSize = GetPath(hdc, NULL, NULL, 0);
640
641 AbortPath(hdc);
642
643 BeginPath(hdc);
644 MoveToEx(hdc, 95, 95, NULL);
645 LineTo(hdc, 95, 0);
646 LineTo(hdc, 0, 95);
647
648 EndPath(hdc);
649 nSizeWitness = GetPath(hdc, NULL, NULL, 0);
650
651 /* This test shows CloseFigure does not have to add a point at the end of the path */
652 ok(nSize == nSizeWitness, "Wrong number of points, no point should be added by CloseFigure\n");
653
654 ReleaseDC(0, hdc);
655 }
656
657 static void WINAPI linedda_callback(INT x, INT y, LPARAM lparam)
658 {
659 POINT **pt = (POINT**)lparam;
660 ok((*pt)->x == x && (*pt)->y == y, "point mismatch expect(%d,%d) got(%d,%d)\n",
661 (*pt)->x, (*pt)->y, x, y);
662
663 (*pt)++;
664 return;
665 }
666
667 static void test_linedda(void)
668 {
669 const POINT *pt;
670 static const POINT array_10_20_20_40[] = {{10,20},{10,21},{11,22},{11,23},
671 {12,24},{12,25},{13,26},{13,27},
672 {14,28},{14,29},{15,30},{15,31},
673 {16,32},{16,33},{17,34},{17,35},
674 {18,36},{18,37},{19,38},{19,39},
675 {-1,-1}};
676 static const POINT array_10_20_20_43[] = {{10,20},{10,21},{11,22},{11,23},
677 {12,24},{12,25},{13,26},{13,27},
678 {13,28},{14,29},{14,30},{15,31},
679 {15,32},{16,33},{16,34},{17,35},
680 {17,36},{17,37},{18,38},{18,39},
681 {19,40},{19,41},{20,42},{-1,-1}};
682
683 static const POINT array_10_20_10_20[] = {{-1,-1}};
684 static const POINT array_10_20_11_27[] = {{10,20},{10,21},{10,22},{10,23},
685 {11,24},{11,25},{11,26},{-1,-1}};
686
687 static const POINT array_20_43_10_20[] = {{20,43},{20,42},{19,41},{19,40},
688 {18,39},{18,38},{17,37},{17,36},
689 {17,35},{16,34},{16,33},{15,32},
690 {15,31},{14,30},{14,29},{13,28},
691 {13,27},{13,26},{12,25},{12,24},
692 {11,23},{11,22},{10,21},{-1,-1}};
693
694 static const POINT array_20_20_10_43[] = {{20,20},{20,21},{19,22},{19,23},
695 {18,24},{18,25},{17,26},{17,27},
696 {17,28},{16,29},{16,30},{15,31},
697 {15,32},{14,33},{14,34},{13,35},
698 {13,36},{13,37},{12,38},{12,39},
699 {11,40},{11,41},{10,42},{-1,-1}};
700
701 static const POINT array_20_20_43_10[] = {{20,20},{21,20},{22,19},{23,19},
702 {24,18},{25,18},{26,17},{27,17},
703 {28,17},{29,16},{30,16},{31,15},
704 {32,15},{33,14},{34,14},{35,13},
705 {36,13},{37,13},{38,12},{39,12},
706 {40,11},{41,11},{42,10},{-1,-1}};
707
708
709 pt = array_10_20_20_40;
710 LineDDA(10, 20, 20, 40, linedda_callback, (LPARAM)&pt);
711 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
712
713 pt = array_10_20_20_43;
714 LineDDA(10, 20, 20, 43, linedda_callback, (LPARAM)&pt);
715 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
716
717 pt = array_10_20_10_20;
718 LineDDA(10, 20, 10, 20, linedda_callback, (LPARAM)&pt);
719 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
720
721 pt = array_10_20_11_27;
722 LineDDA(10, 20, 11, 27, linedda_callback, (LPARAM)&pt);
723 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
724
725 pt = array_20_43_10_20;
726 LineDDA(20, 43, 10, 20, linedda_callback, (LPARAM)&pt);
727 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
728
729 pt = array_20_20_10_43;
730 LineDDA(20, 20, 10, 43, linedda_callback, (LPARAM)&pt);
731 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
732
733 pt = array_20_20_43_10;
734 LineDDA(20, 20, 43, 10, linedda_callback, (LPARAM)&pt);
735 ok(pt->x == -1 && pt->y == -1, "didn't find terminator\n");
736 }
737
738 START_TEST(path)
739 {
740 test_path_state();
741 test_widenpath();
742 test_arcto();
743 test_anglearc();
744 test_polydraw();
745 test_closefigure();
746 test_linedda();
747 }