1
/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
2
/*
3
 * Copyright © 2005 Red Hat, Inc.
4
 *
5
 * Permission to use, copy, modify, distribute, and sell this software
6
 * and its documentation for any purpose is hereby granted without
7
 * fee, provided that the above copyright notice appear in all copies
8
 * and that both that copyright notice and this permission notice
9
 * appear in supporting documentation, and that the name of
10
 * Red Hat, Inc. not be used in advertising or publicity pertaining to
11
 * distribution of the software without specific, written prior
12
 * permission. Red Hat, Inc. makes no representations about the
13
 * suitability of this software for any purpose.  It is provided "as
14
 * is" without express or implied warranty.
15
 *
16
 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18
 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
19
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
22
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
 *
24
 * Author: Carl D. Worth <cworth@cworth.org>
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
typedef struct {
30
    cairo_operator_t op;
31
    double tolerance;
32
    cairo_fill_rule_t fill_rule;
33
    double line_width;
34
    cairo_line_cap_t line_cap;
35
    cairo_line_join_t line_join;
36
    double miter_limit;
37
    cairo_matrix_t matrix;
38
    double dash[5];
39
    double dash_offset;
40
} settings_t;
41

            
42
/* Two sets of settings, no defaults */
43
static const settings_t settings[] = {
44
    {
45
	CAIRO_OPERATOR_IN,
46
	2.0,
47
	CAIRO_FILL_RULE_EVEN_ODD,
48
	7.7,
49
	CAIRO_LINE_CAP_SQUARE,
50
	CAIRO_LINE_JOIN_ROUND,
51
	3.14,
52
	{2.0, 0.0, 0.0, 2.0, 5.0, 5.0},
53
	{0.1, 0.2, 0.3, 0.4, 0.5},
54
	2.0
55
    },
56
    {
57
	CAIRO_OPERATOR_ATOP,
58
	5.25,
59
	CAIRO_FILL_RULE_WINDING,
60
	2.17,
61
	CAIRO_LINE_CAP_ROUND,
62
	CAIRO_LINE_JOIN_BEVEL,
63
	1000.0,
64
	{-3.0, 1.0, 1.0, -3.0, -4, -4},
65
	{1.0, 2.0, 3.0, 4.0, 5.0},
66
	3.0
67
    }
68
};
69

            
70
static void
71
6
settings_set (cairo_t *cr, const settings_t *settings)
72
{
73
6
    cairo_set_operator (cr, settings->op);
74
6
    cairo_set_tolerance (cr, settings->tolerance);
75
6
    cairo_set_fill_rule (cr, settings->fill_rule);
76
6
    cairo_set_line_width (cr, settings->line_width);
77
6
    cairo_set_line_cap (cr, settings->line_cap);
78
6
    cairo_set_line_join (cr, settings->line_join);
79
6
    cairo_set_miter_limit (cr, settings->miter_limit);
80
6
    cairo_set_matrix (cr, &settings->matrix);
81
6
    cairo_set_dash (cr, settings->dash, 5, settings->dash_offset);
82
6
}
83

            
84
static int
85
6
settings_get (cairo_t *cr, settings_t *settings)
86
{
87
    int count;
88

            
89
6
    settings->op = cairo_get_operator (cr);
90
6
    settings->tolerance = cairo_get_tolerance (cr);
91
6
    settings->fill_rule = cairo_get_fill_rule (cr);
92
6
    settings->line_width = cairo_get_line_width (cr);
93
6
    settings->line_cap = cairo_get_line_cap (cr);
94
6
    settings->line_join = cairo_get_line_join (cr);
95
6
    settings->miter_limit = cairo_get_miter_limit (cr);
96
6
    cairo_get_matrix (cr, &settings->matrix);
97

            
98
6
    count = cairo_get_dash_count (cr);
99
6
    if (count != 5)
100
	return -1;
101

            
102
6
    cairo_get_dash (cr, settings->dash, &settings->dash_offset);
103

            
104
6
    return 0;
105
}
106

            
107
static int
108
6
settings_equal (const settings_t *a, const settings_t *b)
109
{
110
12
    return (a->op == b->op &&
111
6
	    a->tolerance == b->tolerance &&
112
6
	    a->fill_rule == b->fill_rule &&
113
6
	    a->line_width == b->line_width &&
114
6
	    a->line_cap == b->line_cap &&
115
6
	    a->line_join == b->line_join &&
116
6
	    a->miter_limit == b->miter_limit &&
117
6
	    a->matrix.xx == b->matrix.xx &&
118
6
	    a->matrix.xy == b->matrix.xy &&
119
6
	    a->matrix.x0 == b->matrix.x0 &&
120
6
	    a->matrix.yx == b->matrix.yx &&
121
6
	    a->matrix.yy == b->matrix.yy &&
122
6
	    a->matrix.y0 == b->matrix.y0 &&
123
18
	    memcmp(a->dash, b->dash, sizeof(a->dash)) == 0 &&
124
6
	    a->dash_offset == b->dash_offset);
125
}
126

            
127
static cairo_test_status_t
128
3
draw (cairo_t *cr, int width, int height)
129
{
130
    settings_t check;
131

            
132
3
    settings_set (cr, &settings[0]);
133

            
134
3
    cairo_save (cr);
135
    {
136
3
	settings_set (cr, &settings[1]);
137
3
	if (settings_get (cr, &check))
138
	    return CAIRO_TEST_FAILURE;
139

            
140
3
	if (!settings_equal (&settings[1], &check))
141
	    return CAIRO_TEST_FAILURE;
142
    }
143
3
    cairo_restore (cr);
144

            
145
3
    if (settings_get (cr, &check))
146
	return CAIRO_TEST_FAILURE;
147

            
148
3
    if (!settings_equal (&settings[0], &check))
149
	return CAIRO_TEST_FAILURE;
150

            
151
3
    return CAIRO_TEST_SUCCESS;
152
}
153

            
154
1
CAIRO_TEST (get_and_set,
155
	    "Tests calls to the most trivial cairo_get and cairo_set functions",
156
	    "api", /* keywords */
157
	    NULL, /* requirements */
158
	    0, 0,
159
	    NULL, draw)