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

            
26
#include "cairo-test.h"
27

            
28
#include <assert.h>
29

            
30
static cairo_test_status_t
31
1
preamble (cairo_test_context_t *ctx)
32
{
33
    cairo_font_options_t *default_options;
34
    cairo_font_options_t *nil_options;
35
    cairo_surface_t *surface;
36
    cairo_matrix_t identity;
37
    cairo_t *cr;
38
    cairo_scaled_font_t *scaled_font;
39

            
40
    /* first check NULL handling of cairo_font_options_t */
41
1
    default_options = cairo_font_options_create ();
42
1
    assert (cairo_font_options_status (default_options) == CAIRO_STATUS_SUCCESS);
43
1
    nil_options = cairo_font_options_copy (NULL);
44
1
    assert (cairo_font_options_status (nil_options) == CAIRO_STATUS_NO_MEMORY);
45

            
46
1
    assert (cairo_font_options_equal (default_options, default_options));
47
1
    assert (! cairo_font_options_equal (default_options, nil_options));
48
1
    assert (! cairo_font_options_equal (NULL, nil_options));
49
1
    assert (! cairo_font_options_equal (nil_options, nil_options));
50
1
    assert (! cairo_font_options_equal (default_options, NULL));
51
1
    assert (! cairo_font_options_equal (NULL, default_options));
52

            
53
1
    assert (cairo_font_options_hash (default_options) == cairo_font_options_hash (nil_options));
54
1
    assert (cairo_font_options_hash (NULL) == cairo_font_options_hash (nil_options));
55
1
    assert (cairo_font_options_hash (default_options) == cairo_font_options_hash (NULL));
56

            
57
1
    cairo_font_options_merge (NULL, NULL);
58
1
    cairo_font_options_merge (default_options, NULL);
59
1
    cairo_font_options_merge (default_options, nil_options);
60

            
61
1
    cairo_font_options_set_antialias (NULL, CAIRO_ANTIALIAS_DEFAULT);
62
1
    cairo_font_options_get_antialias (NULL);
63
1
    assert (cairo_font_options_get_antialias (default_options) == CAIRO_ANTIALIAS_DEFAULT);
64

            
65
1
    cairo_font_options_set_subpixel_order (NULL, CAIRO_SUBPIXEL_ORDER_DEFAULT);
66
1
    cairo_font_options_get_subpixel_order (NULL);
67
1
    assert (cairo_font_options_get_subpixel_order (default_options) == CAIRO_SUBPIXEL_ORDER_DEFAULT);
68

            
69
1
    cairo_font_options_set_hint_style (NULL, CAIRO_HINT_STYLE_DEFAULT);
70
1
    cairo_font_options_get_hint_style (NULL);
71
1
    assert (cairo_font_options_get_hint_style (default_options) == CAIRO_HINT_STYLE_DEFAULT);
72

            
73
1
    cairo_font_options_set_hint_metrics (NULL, CAIRO_HINT_METRICS_DEFAULT);
74
1
    cairo_font_options_get_hint_metrics (NULL);
75
1
    assert (cairo_font_options_get_hint_metrics (default_options) == CAIRO_HINT_METRICS_DEFAULT);
76

            
77
1
    cairo_font_options_set_color_palette (NULL, CAIRO_COLOR_PALETTE_DEFAULT);
78
1
    cairo_font_options_get_color_palette (NULL);
79
1
    assert (cairo_font_options_get_color_palette (default_options) == CAIRO_COLOR_PALETTE_DEFAULT);
80

            
81
1
    cairo_font_options_destroy (NULL);
82
1
    cairo_font_options_destroy (default_options);
83
1
    cairo_font_options_destroy (nil_options);
84

            
85

            
86
    /* Now try creating fonts with NULLs */
87
1
    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 0, 0);
88
1
    cr = cairo_create (surface);
89
1
    cairo_surface_destroy (surface);
90

            
91
1
    cairo_matrix_init_identity (&identity);
92
1
    scaled_font = cairo_scaled_font_create (cairo_get_font_face (cr),
93
	                                    &identity, &identity,
94
					    NULL);
95
1
    assert (cairo_scaled_font_status (scaled_font) == CAIRO_STATUS_NULL_POINTER);
96
1
    cairo_scaled_font_get_font_options (scaled_font, NULL);
97
1
    cairo_scaled_font_destroy (scaled_font);
98

            
99
1
    assert (cairo_status (cr) == CAIRO_STATUS_SUCCESS);
100
1
    cairo_get_font_options (cr, NULL);
101
1
    cairo_set_font_options (cr, NULL);
102
1
    assert (cairo_status (cr) == CAIRO_STATUS_NULL_POINTER);
103

            
104
1
    cairo_destroy (cr);
105

            
106
1
    return CAIRO_TEST_SUCCESS;
107
}
108

            
109
1
CAIRO_TEST (font_options,
110
	    "Check setters and getters on cairo_font_options_t.",
111
	    "font, api", /* keywords */
112
	    NULL, /* requirements */
113
	    0, 0,
114
	    preamble, NULL)