Upload Tizen2.0 source
[framework/graphics/cairo.git] / test / close-path-current-point.c
1 /*
2  * Copyright © 2009 Nis Martensen
3  *
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without fee,
6  * provided that the above copyright notice appear in all copies and
7  * that both that copyright notice and this permission notice appear in
8  * supporting documentation, and that the name of the copyright holder
9  * not be used in advertising or publicity pertaining to distribution of
10  * the software without specific, written prior permission. The
11  * copyright holder makes no representations about the suitability of
12  * this software for any purpose. It is provided "as is" without
13  * express or implied warranty.
14  *
15  * THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
18  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Author: Nis Martensen <nis.martensen@web.de>
24  */
25
26 #include "cairo-test.h"
27
28 #define SIZE 20
29
30 static cairo_test_status_t
31 draw (cairo_t *cr, int width, int height)
32 {
33     /* We draw in the default black, so paint white first. */
34     cairo_save (cr);
35     cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
36     cairo_paint (cr);
37     cairo_restore (cr);
38
39     /* subpath starts with cairo_move_to */
40     cairo_new_sub_path (cr);
41     cairo_move_to (cr, SIZE, SIZE);
42     cairo_rel_line_to (cr, SIZE, 0);
43     cairo_rel_line_to (cr, 0, SIZE);
44     cairo_close_path (cr);
45     cairo_rel_line_to (cr, 0.5 * SIZE, SIZE);
46
47     /* subpath starts with cairo_line_to */
48     cairo_new_sub_path (cr);
49     cairo_line_to (cr, SIZE, 3 * SIZE);
50     cairo_rel_line_to (cr, SIZE, 0);
51     cairo_rel_line_to (cr, 0, SIZE);
52     cairo_close_path (cr);
53     cairo_rel_line_to (cr, 0, SIZE);
54
55     /* subpath starts with cairo_curve_to */
56     cairo_new_sub_path (cr);
57     cairo_curve_to (cr,
58                     SIZE, 5 * SIZE,
59                     1.5 * SIZE, 6 * SIZE,
60                     2 * SIZE, 5 * SIZE);
61     cairo_rel_line_to (cr, 0, SIZE);
62     cairo_close_path (cr);
63     cairo_rel_line_to (cr, -0.5 * SIZE, SIZE);
64
65     /* subpath starts with cairo_arc */
66     cairo_new_sub_path (cr);
67     cairo_arc (cr,
68                1.5 * SIZE, 7 * SIZE,
69                0.5 * SIZE,
70                M_PI, 2 * M_PI);
71     cairo_rel_line_to (cr, 0, SIZE);
72     cairo_close_path (cr);
73     cairo_rel_line_to (cr, -0.7 * SIZE, 0.7 * SIZE);
74
75     /* subpath starts with cairo_arc_negative */
76     cairo_new_sub_path (cr);
77     cairo_arc_negative (cr,
78                         1.5 * SIZE, 9 * SIZE,
79                         0.5 * SIZE,
80                         M_PI, 2 * M_PI);
81     cairo_rel_line_to (cr, 0, SIZE);
82     cairo_close_path (cr);
83     cairo_rel_line_to (cr, -0.8 * SIZE, 0.3 * SIZE);
84
85     cairo_stroke (cr);
86
87     return CAIRO_TEST_SUCCESS;
88 }
89
90 CAIRO_TEST (close_path_current_point,
91             "Test some corner cases related to cairo path operations and the current point",
92             "path", /* keywords */
93             NULL, /* requirements */
94             3 * SIZE, 11 * SIZE,
95             NULL, draw)