1
/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
2
/*
3
 * Copyright 2011 Red Hat Inc.
4
 *
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:
12
 *
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 *
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
23
 * SOFTWARE.
24
 *
25
 * Author: Benjamin Otte <otte@redhat.com>
26
 */
27

            
28
/*
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
32
 */
33

            
34
#include "cairo-test.h"
35

            
36
#include <math.h>
37

            
38
#define LINE_WIDTH 120
39
#define SIZE 100
40
#define RECT_SIZE 10
41

            
42
static cairo_test_status_t
43
18
draw (cairo_t *cr, int width, int height)
44
{
45
    /* fill with green so RGB and RGBA tests can share the ref image */
46
18
    cairo_set_source_rgb (cr, 0, 1, 0);
47
18
    cairo_paint (cr);
48

            
49
    /* red to see eventual bugs immediately */
50
18
    cairo_set_source_rgb (cr, 1, 0, 0);
51

            
52
    /* big line width */
53
18
    cairo_set_line_width (cr, LINE_WIDTH);
54

            
55
    /* rectangle that is smaller than the line width in center of image */
56
18
    cairo_rectangle (cr,
57
                     (SIZE - RECT_SIZE) / 2,
58
                     (SIZE - RECT_SIZE) / 2,
59
                     RECT_SIZE,
60
                     RECT_SIZE);
61

            
62
18
    cairo_stroke (cr);
63

            
64
18
    return CAIRO_TEST_SUCCESS;
65
}
66

            
67
/* and again slightly offset to trigger another path */
68
static cairo_test_status_t
69
3
draw_offset (cairo_t *cr, int width, int height)
70
{
71
3
    cairo_translate (cr, .5, .5);
72
3
    return draw (cr, width, height);
73
}
74

            
75
static cairo_test_status_t
76
3
draw_rotated (cairo_t *cr, int width, int height)
77
{
78
3
    cairo_translate (cr, SIZE/2, SIZE/2);
79
3
    cairo_rotate (cr, M_PI/4);
80
3
    cairo_translate (cr, -SIZE/2, -SIZE/2);
81

            
82
3
    return draw (cr, width, height);
83
}
84

            
85
static cairo_test_status_t
86
3
draw_flipped (cairo_t *cr, int width, int height)
87
{
88
3
    cairo_translate (cr, SIZE/2, SIZE/2);
89
3
    cairo_scale (cr, -1, 1);
90
3
    cairo_translate (cr, -SIZE/2, -SIZE/2);
91

            
92
3
    return draw (cr, width, height);
93
}
94

            
95
static cairo_test_status_t
96
3
draw_flopped (cairo_t *cr, int width, int height)
97
{
98
3
    cairo_translate (cr, SIZE/2, SIZE/2);
99
3
    cairo_scale (cr, 1, -1);
100
3
    cairo_translate (cr, -SIZE/2, -SIZE/2);
101

            
102
3
    return draw (cr, width, height);
103
}
104

            
105
static cairo_test_status_t
106
3
draw_dashed (cairo_t *cr, int width, int height)
107
{
108
3
    const double dashes[] = { 4 };
109
3
    cairo_set_dash (cr, dashes, 1, 0);
110
3
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
111
3
    return draw (cr, width, height);
112
}
113

            
114
1
CAIRO_TEST (line_width_large_overlap,
115
	    "Test overlapping lines due to large line width",
116
	    "stroke", /* keywords */
117
	    NULL, /* requirements */
118
	    SIZE, SIZE,
119
	    NULL, draw)
120
1
CAIRO_TEST (line_width_large_overlap_offset,
121
	    "Test overlapping lines due to large line width",
122
	    "stroke", /* keywords */
123
	    NULL, /* requirements */
124
	    SIZE, SIZE,
125
	    NULL, draw_offset)
126
1
CAIRO_TEST (line_width_large_overlap_rotated,
127
	    "Test overlapping lines due to large line width",
128
	    "stroke", /* keywords */
129
	    NULL, /* requirements */
130
	    SIZE, SIZE,
131
	    NULL, draw_rotated)
132
1
CAIRO_TEST (line_width_large_overlap_flipped,
133
	    "Test overlapping lines due to large line width",
134
	    "stroke", /* keywords */
135
	    NULL, /* requirements */
136
	    SIZE, SIZE,
137
	    NULL, draw_flipped)
138
1
CAIRO_TEST (line_width_large_overlap_flopped,
139
	    "Test overlapping lines due to large line width",
140
	    "stroke", /* keywords */
141
	    NULL, /* requirements */
142
	    SIZE, SIZE,
143
	    NULL, draw_flopped)
144
1
CAIRO_TEST (line_width_large_overlap_dashed,
145
	    "Test overlapping lines due to large line width",
146
	    "stroke", /* keywords */
147
	    NULL, /* requirements */
148
	    SIZE, SIZE,
149
	    NULL, draw_dashed)