1
/*
2
 * Copyright © 2005 Keith Packard
3
 *
4
 * Permission to use, copy, modify, distribute, and sell this software and its
5
 * documentation for any purpose is hereby granted without fee, provided that
6
 * the above copyright notice appear in all copies and that both that
7
 * copyright notice and this permission notice appear in supporting
8
 * documentation, and that the name of Keith Packard not be used in
9
 * advertising or publicity pertaining to distribution of the software without
10
 * specific, written prior permission.  Keith Packard makes no
11
 * representations about the suitability of this software for any purpose.  It
12
 * is provided "as is" without express or implied warranty.
13
 *
14
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
 * PERFORMANCE OF THIS SOFTWARE.
21
 */
22

            
23
#include "cairo-test.h"
24

            
25
#define SIZE 10
26

            
27
static cairo_status_t
28
3
invalid_rel_move_to (cairo_surface_t *target)
29
{
30
    cairo_t *cr;
31
    cairo_status_t status;
32

            
33
3
    cr = cairo_create (target);
34
3
    cairo_rel_move_to (cr, SIZE, SIZE/2);
35
3
    status = cairo_status (cr);
36
3
    cairo_destroy (cr);
37

            
38
3
    return status;
39
}
40

            
41
static cairo_status_t
42
3
invalid_rel_line_to (cairo_surface_t *target)
43
{
44
    cairo_t *cr;
45
    cairo_status_t status;
46

            
47
3
    cr = cairo_create (target);
48
3
    cairo_rel_line_to (cr, -SIZE, SIZE/2);
49
3
    status = cairo_status (cr);
50
3
    cairo_destroy (cr);
51

            
52
3
    return status;
53
}
54

            
55
static cairo_status_t
56
3
invalid_rel_curve_to (cairo_surface_t *target)
57
{
58
    cairo_t *cr;
59
    cairo_status_t status;
60

            
61
3
    cr = cairo_create (target);
62
3
    cairo_rel_curve_to (cr,
63
			SIZE/2, -SIZE/2,
64
			SIZE*2/3, -SIZE/3,
65
			SIZE/2, -SIZE);
66
3
    status = cairo_status (cr);
67
3
    cairo_destroy (cr);
68

            
69
3
    return status;
70
}
71

            
72
static cairo_test_status_t
73
3
draw (cairo_t *cr, int width, int height)
74
{
75
3
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
76
    cairo_status_t status;
77
    cairo_test_status_t result;
78

            
79
    /* first test that a relative move without a current point fails... */
80
3
    status = invalid_rel_move_to (cairo_get_target (cr));
81
3
    if (status != CAIRO_STATUS_NO_CURRENT_POINT) {
82
	result = cairo_test_status_from_status (ctx, status);
83
	if (result == CAIRO_TEST_NO_MEMORY)
84
	    return result;
85

            
86
	cairo_test_log (ctx, "Error: invalid cairo_rel_move_to() did not raise NO_CURRENT_POINT\n");
87
	return result;
88
    }
89

            
90
3
    status = invalid_rel_line_to (cairo_get_target (cr));
91
3
    if (status != CAIRO_STATUS_NO_CURRENT_POINT) {
92
	result = cairo_test_status_from_status (ctx, status);
93
	if (result == CAIRO_TEST_NO_MEMORY)
94
	    return result;
95

            
96
	cairo_test_log (ctx, "Error: invalid cairo_rel_line_to() did not raise NO_CURRENT_POINT\n");
97
	return result;
98
    }
99

            
100
3
    status = invalid_rel_curve_to (cairo_get_target (cr));
101
3
    if (status != CAIRO_STATUS_NO_CURRENT_POINT) {
102
	result = cairo_test_status_from_status (ctx, status);
103
	if (result == CAIRO_TEST_NO_MEMORY)
104
	    return result;
105

            
106
	cairo_test_log (ctx, "Error: invalid cairo_rel_curve_to() did not raise NO_CURRENT_POINT\n");
107
	return result;
108
    }
109

            
110
3
    cairo_set_source_rgb (cr, 1, 1, 1);
111
3
    cairo_move_to (cr, 0, 0);
112
3
    cairo_rel_move_to (cr, SIZE, SIZE/2);
113
3
    cairo_rel_line_to (cr, -SIZE, SIZE/2);
114
3
    cairo_rel_curve_to (cr,
115
			SIZE/2, -SIZE/2,
116
			SIZE*2/3, -SIZE/3,
117
			SIZE/2, -SIZE);
118

            
119
3
    cairo_stroke (cr);
120

            
121
3
    return CAIRO_TEST_SUCCESS;
122
}
123

            
124
1
CAIRO_TEST (rel_path,
125
	    "Tests calls to various relative path functions",
126
	    "path", /* keywords */
127
	    NULL, /* requirements */
128
	    SIZE, SIZE,
129
	    NULL, draw)