1
/*
2
 * Copyright © 2006 Red Hat, Inc.
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
 * Author: Carl D. Worth <cworth@cworth.org>
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
#ifdef HAVE_UNISTD_H
30
#include <unistd.h>
31
#endif
32

            
33
#define WIDTH 800
34
#define HEIGHT 400
35

            
36
typedef enum {
37
    WM_NEW_PATH,
38
    WM_MOVE_TO,
39
    WM_LINE_TO,
40
    WM_HLINE_TO,
41
    WM_VLINE_TO,
42
    WM_REL_LINE_TO,
43
    WM_END
44
} wm_type_t;
45

            
46
typedef struct _wm_element {
47
    wm_type_t type;
48
    double x;
49
    double y;
50
} wm_element_t;
51

            
52
#include "world-map.h"
53

            
54
enum {
55
    STROKE = 1,
56
    FILL = 2,
57
};
58

            
59
static cairo_test_status_t
60
9
draw_world_map (cairo_t *cr, int width, int height, int mode)
61
{
62
    const wm_element_t *e;
63
    double cx, cy;
64

            
65
9
    cairo_set_line_width (cr, 0.2);
66

            
67
9
    cairo_set_source_rgb (cr, .68, .85, .90); /* lightblue */
68
9
    cairo_rectangle (cr, 0, 0, 800, 400);
69
9
    cairo_fill (cr);
70

            
71
9
    e = &countries[0];
72
    while (1) {
73
283419
	switch (e->type) {
74
1494
	case WM_NEW_PATH:
75
	case WM_END:
76
1494
	    if (mode & FILL) {
77
996
		cairo_set_source_rgb (cr, .75, .75, .75); /* silver */
78
996
		cairo_fill_preserve (cr);
79
	    }
80
1494
	    if (mode & STROKE) {
81
996
		cairo_set_source_rgb (cr, .50, .50, .50); /* gray */
82
996
		cairo_stroke (cr);
83
	    }
84
1494
	    cairo_new_path (cr);
85
1494
	    cairo_move_to (cr, e->x, e->y);
86
1494
	    break;
87
936
	case WM_MOVE_TO:
88
936
	    cairo_close_path (cr);
89
936
	    cairo_move_to (cr, e->x, e->y);
90
936
	    break;
91
648
	case WM_LINE_TO:
92
648
	    cairo_line_to (cr, e->x, e->y);
93
648
	    break;
94
63
	case WM_HLINE_TO:
95
63
	    cairo_get_current_point (cr, &cx, &cy);
96
63
	    cairo_line_to (cr, e->x, cy);
97
63
	    break;
98
36
	case WM_VLINE_TO:
99
36
	    cairo_get_current_point (cr, &cx, &cy);
100
36
	    cairo_line_to (cr, cx, e->y);
101
36
	    break;
102
280242
	case WM_REL_LINE_TO:
103
280242
	    cairo_rel_line_to (cr, e->x, e->y);
104
280242
	    break;
105
	}
106
283419
	if (e->type == WM_END)
107
9
	    break;
108
283410
	e++;
109
    }
110

            
111
9
    cairo_new_path (cr);
112

            
113
9
    return CAIRO_TEST_SUCCESS;
114
}
115

            
116
static cairo_test_status_t
117
3
draw_world_map_stroke (cairo_t *cr, int width, int height)
118
{
119
3
    return draw_world_map (cr, width, height, STROKE);
120
}
121

            
122
static cairo_test_status_t
123
3
draw_world_map_fill (cairo_t *cr, int width, int height)
124
{
125
3
    return draw_world_map (cr, width, height, FILL);
126
}
127

            
128
static cairo_test_status_t
129
3
draw_world_map_both (cairo_t *cr, int width, int height)
130
{
131
3
    return draw_world_map (cr, width, height, FILL | STROKE);
132
}
133

            
134
1
CAIRO_TEST (world_map,
135
	    "Tests a complex drawing (part of the performance suite)",
136
	    "fill, stroke", /* keywords */
137
	    NULL, /* requirements */
138
	    WIDTH, HEIGHT,
139
	    NULL, draw_world_map_both)
140
1
CAIRO_TEST (world_map_stroke,
141
	    "Tests a complex drawing (part of the performance suite)",
142
	    "stroke", /* keywords */
143
	    NULL, /* requirements */
144
	    WIDTH, HEIGHT,
145
	    NULL, draw_world_map_stroke)
146
1
CAIRO_TEST (world_map_fill,
147
	    "Tests a complex drawing (part of the performance suite)",
148
	    "fill", /* keywords */
149
	    NULL, /* requirements */
150
	    WIDTH, HEIGHT,
151
	    NULL, draw_world_map_fill)