1 /* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
3 * Copyright 2011 Red Hat Inc.
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Author: Benjamin Otte <otte@redhat.com>
29 * Test case taken from the WebKit test suite, failure originally reported
30 * by Zan Dobersek <zandobersek@gmail.com>. WebKit test is
31 * LayoutTests/canvas/philip/tests/2d.path.rect.selfintersect.html
34 #include "cairo-test.h"
38 #define LINE_WIDTH 120
42 static cairo_test_status_t
43 draw (cairo_t *cr, int width, int height)
45 /* fill with green so RGB and RGBA tests can share the ref image */
46 cairo_set_source_rgb (cr, 0, 1, 0);
49 /* red to see eventual bugs immediately */
50 cairo_set_source_rgb (cr, 1, 0, 0);
53 cairo_set_line_width (cr, LINE_WIDTH);
55 /* rectangle that is smaller than the line width in center of image */
57 (SIZE - RECT_SIZE) / 2,
58 (SIZE - RECT_SIZE) / 2,
64 return CAIRO_TEST_SUCCESS;
67 /* and again slightly offset to trigger another path */
68 static cairo_test_status_t
69 draw_offset (cairo_t *cr, int width, int height)
71 cairo_translate (cr, .5, .5);
72 return draw (cr, width, height);
75 static cairo_test_status_t
76 draw_rotated (cairo_t *cr, int width, int height)
78 cairo_translate (cr, SIZE/2, SIZE/2);
79 cairo_rotate (cr, M_PI/4);
80 cairo_translate (cr, -SIZE/2, -SIZE/2);
82 return draw (cr, width, height);
85 static cairo_test_status_t
86 draw_flipped (cairo_t *cr, int width, int height)
88 cairo_translate (cr, SIZE/2, SIZE/2);
89 cairo_scale (cr, -1, 1);
90 cairo_translate (cr, -SIZE/2, -SIZE/2);
92 return draw (cr, width, height);
95 static cairo_test_status_t
96 draw_flopped (cairo_t *cr, int width, int height)
98 cairo_translate (cr, SIZE/2, SIZE/2);
99 cairo_scale (cr, 1, -1);
100 cairo_translate (cr, -SIZE/2, -SIZE/2);
102 return draw (cr, width, height);
105 static cairo_test_status_t
106 draw_dashed (cairo_t *cr, int width, int height)
108 const double dashes[] = { 4 };
109 cairo_set_dash (cr, dashes, 1, 0);
110 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
111 return draw (cr, width, height);
114 CAIRO_TEST (line_width_large_overlap,
115 "Test overlapping lines due to large line width",
116 "stroke", /* keywords */
117 NULL, /* requirements */
120 CAIRO_TEST (line_width_large_overlap_offset,
121 "Test overlapping lines due to large line width",
122 "stroke", /* keywords */
123 NULL, /* requirements */
126 CAIRO_TEST (line_width_large_overlap_rotated,
127 "Test overlapping lines due to large line width",
128 "stroke", /* keywords */
129 NULL, /* requirements */
132 CAIRO_TEST (line_width_large_overlap_flipped,
133 "Test overlapping lines due to large line width",
134 "stroke", /* keywords */
135 NULL, /* requirements */
138 CAIRO_TEST (line_width_large_overlap_flopped,
139 "Test overlapping lines due to large line width",
140 "stroke", /* keywords */
141 NULL, /* requirements */
144 CAIRO_TEST (line_width_large_overlap_dashed,
145 "Test overlapping lines due to large line width",
146 "stroke", /* keywords */
147 NULL, /* requirements */