1
/*
2
 * Copyright © 2016 Adrian Johnson
3
 *
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use, copy,
8
 * modify, merge, publish, distribute, sublicense, and/or sell copies
9
 * of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be
13
 * included in all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 *
24
 * Authors:
25
 *	Adrian Johnson <ajohnson@redneon.com>
26
 */
27

            
28
#include "cairo-test.h"
29

            
30
/* Check cairo_recording_surface_ink_extents() returns correct extents. */
31

            
32

            
33
static cairo_test_status_t
34
4
check_extents (cairo_test_context_t *cr,
35
	       cairo_surface_t *recording_surface,
36
	       const char * func_name,
37
	       double expected_x, double expected_y, double expected_w, double expected_h)
38
{
39
    double x, y, w, h;
40
4
    cairo_recording_surface_ink_extents (recording_surface, &x, &y, &w, &h);
41
4
    if (x != expected_x ||
42
4
	y != expected_y ||
43
4
	w != expected_w ||
44
4
	h != expected_h)
45
    {
46
	cairo_test_log (cr,
47
			"%s: x: %f, y: %f, w: %f, h: %f\n"
48
			"    expected: x: %f, y: %f, w: %f, h: %f\n",
49
			func_name,
50
			x, y, w, h,
51
			expected_x, expected_y,
52
			expected_w, expected_h);
53
       return CAIRO_TEST_ERROR;
54
    }
55
4
    return CAIRO_TEST_SUCCESS;
56
}
57

            
58
static cairo_test_status_t
59
1
unbounded_fill (cairo_test_context_t *test_cr)
60
{
61
    cairo_test_status_t status;
62
    cairo_surface_t *surface;
63
    cairo_t *cr;
64

            
65
1
    surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, NULL);
66
1
    cr = cairo_create (surface);
67

            
68
1
    cairo_rectangle (cr, -300, -150, 900, 600);
69
1
    cairo_fill (cr);
70

            
71
1
    cairo_destroy(cr);
72

            
73
1
    status = check_extents (test_cr, surface,  __func__,
74
			    -300, -150, 900, 600);
75
1
    cairo_surface_destroy (surface);
76
1
    return status;
77
}
78

            
79
static cairo_test_status_t
80
1
bounded_fill (cairo_test_context_t *test_cr)
81
{
82
    cairo_test_status_t status;
83
    cairo_surface_t *surface;
84
    cairo_t *cr;
85
1
    cairo_rectangle_t extents = { -150, -100, 300, 200 };
86

            
87
1
    surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, &extents);
88
1
    cr = cairo_create (surface);
89

            
90
1
    cairo_rectangle (cr, -300, -300, 650, 600);
91
1
    cairo_fill (cr);
92

            
93
1
    cairo_destroy(cr);
94

            
95
1
    status = check_extents (test_cr, surface,  __func__,
96
			    -150, -100, 300, 200);
97
1
    cairo_surface_destroy (surface);
98
1
    return status;
99
}
100

            
101
static cairo_test_status_t
102
1
unbounded_paint (cairo_test_context_t *test_cr)
103
{
104
    cairo_test_status_t status;
105
    cairo_surface_t *surface;
106
    cairo_t *cr;
107

            
108
1
    surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, NULL);
109
1
    cr = cairo_create (surface);
110

            
111
1
    cairo_paint (cr);
112

            
113
1
    cairo_destroy(cr);
114

            
115
1
    status = check_extents (test_cr, surface,  __func__,
116
			    -(1 << 23), -(1 << 23), -1, -1);
117
1
    cairo_surface_destroy (surface);
118
1
    return status;
119
}
120

            
121
static cairo_test_status_t
122
1
bounded_paint (cairo_test_context_t *test_cr)
123
{
124
    cairo_test_status_t status;
125
    cairo_surface_t *surface;
126
    cairo_t *cr;
127
1
    cairo_rectangle_t extents = { -150, -100, 300, 200 };
128

            
129
1
    surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, &extents);
130
1
    cr = cairo_create (surface);
131

            
132
1
    cairo_paint (cr);
133

            
134
1
    cairo_destroy(cr);
135

            
136
1
    status = check_extents (test_cr, surface,  __func__,
137
			    -150, -100, 300, 200);
138
1
    cairo_surface_destroy (surface);
139
1
    return status;
140
}
141

            
142
static cairo_test_status_t
143
1
preamble (cairo_test_context_t *cr)
144
{
145
    cairo_test_status_t status;
146

            
147
1
    status = unbounded_fill (cr);
148
1
    if (status != CAIRO_TEST_SUCCESS)
149
	return status;
150

            
151
1
    status = bounded_fill (cr);
152
1
    if (status != CAIRO_TEST_SUCCESS)
153
	return status;
154

            
155
1
    status = unbounded_paint (cr);
156
1
    if (status != CAIRO_TEST_SUCCESS)
157
	return status;
158

            
159
1
    status = bounded_paint (cr);
160
1
    if (status != CAIRO_TEST_SUCCESS)
161
	return status;
162

            
163
1
    return CAIRO_TEST_SUCCESS;
164
}
165

            
166

            
167
1
CAIRO_TEST (recording_ink_extents,
168
	    "Test cairo_recording_surface_ink_extents()",
169
	    "api,recording,extents", /* keywords */
170
	    NULL, /* requirements */
171
	    0, 0,
172
	    preamble, NULL)