Tizen 2.0 Release
[framework/graphics/cairo.git] / test / degenerate-path.c
1 /*
2  * Copyright © 2006 Jeff Muizelaar
3  *
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without
6  * fee, provided that the above copyright notice appear in all copies
7  * and that both that copyright notice and this permission notice
8  * appear in supporting documentation, and that the name of
9  * Jeff Muizelaar not be used in advertising or publicity pertaining to
10  * distribution of the software without specific, written prior
11  * permission. Jeff Muizelaar makes no representations about the
12  * suitability of this software for any purpose.  It is provided "as
13  * is" without express or implied warranty.
14  *
15  * JEFF MUIZELAAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL JEFF MUIZELAAR BE LIABLE FOR ANY SPECIAL,
18  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Author: Jeff Muizelaar <jeff@infidigm.net>
24  */
25
26 #include "cairo-test.h"
27
28 #define PAD 3.0
29 #define LINE_WIDTH 6.0
30
31 static cairo_test_status_t
32 draw (cairo_t *cr, int width, int height)
33 {
34     const cairo_line_cap_t cap[] = { CAIRO_LINE_CAP_ROUND, CAIRO_LINE_CAP_SQUARE, CAIRO_LINE_CAP_BUTT };
35     size_t i;
36     double dash[] = {2, 2};
37     double dash_long[] = {6, 6};
38
39     cairo_set_source_rgb (cr, 1, 0, 0);
40
41     for (i = 0; i < ARRAY_LENGTH (cap); i++) {
42         cairo_save (cr);
43
44         cairo_set_line_cap (cr, cap[i]);
45
46         /* simple degenerate paths */
47         cairo_set_line_width (cr, LINE_WIDTH);
48         cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
49         cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
50         cairo_stroke (cr);
51
52         cairo_translate (cr, 0, 3*PAD);
53         cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
54         cairo_close_path (cr);
55         cairo_stroke (cr);
56
57         /* degenerate paths starting with dash on */
58         cairo_set_dash (cr, dash, 2, 0.);
59
60         cairo_translate (cr, 0, 3*PAD);
61         cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
62         cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
63         cairo_stroke (cr);
64
65         cairo_translate (cr, 0, 3*PAD);
66         cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
67         cairo_close_path (cr);
68         cairo_stroke (cr);
69
70         /* degenerate paths starting with dash off */
71         /* these should not draw anything */
72         cairo_set_dash (cr, dash, 2, 2.);
73
74         cairo_translate (cr, 0, 3*PAD);
75         cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
76         cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
77         cairo_stroke (cr);
78
79         cairo_translate (cr, 0, 3*PAD);
80         cairo_move_to (cr, LINE_WIDTH, LINE_WIDTH);
81         cairo_close_path (cr);
82         cairo_stroke (cr);
83
84         /* this should draw a single degenerate sub-path
85          * at the end of the path */
86         cairo_set_dash (cr, dash_long, 2, 6.);
87
88         cairo_translate (cr, 0, 3*PAD);
89         cairo_move_to (cr, LINE_WIDTH + 6.0, LINE_WIDTH);
90         cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
91         cairo_stroke (cr);
92
93         /* this should draw a single degenerate sub-path
94          * at the end of the path. The difference between this
95          * and the above is that this ends with a degenerate sub-path*/
96         cairo_set_dash (cr, dash_long, 2, 6.);
97
98         cairo_translate (cr, 0, 3*PAD);
99         cairo_move_to (cr, LINE_WIDTH + 6.0, LINE_WIDTH);
100         cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
101         cairo_line_to (cr, LINE_WIDTH, LINE_WIDTH);
102         cairo_stroke (cr);
103
104         cairo_restore (cr);
105
106         cairo_translate (cr, PAD+LINE_WIDTH+PAD, 0);
107     }
108     return CAIRO_TEST_SUCCESS;
109 }
110
111 CAIRO_TEST (degenerate_path,
112             "Tests the behaviour of degenerate paths with different cap types",
113             "degenerate", /* keywords */
114             NULL, /* requirements */
115             3*(PAD+LINE_WIDTH+PAD), 8*(LINE_WIDTH+PAD) + PAD,
116             NULL, draw)