Upload Tizen2.0 source
[framework/graphics/cairo.git] / test / font-options.c
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 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     default_options = cairo_font_options_create ();
42     assert (cairo_font_options_status (default_options) == CAIRO_STATUS_SUCCESS);
43     nil_options = cairo_font_options_copy (NULL);
44     assert (cairo_font_options_status (nil_options) == CAIRO_STATUS_NO_MEMORY);
45
46     assert (cairo_font_options_equal (default_options, default_options));
47     assert (! cairo_font_options_equal (default_options, nil_options));
48     assert (! cairo_font_options_equal (NULL, nil_options));
49     assert (! cairo_font_options_equal (nil_options, nil_options));
50     assert (! cairo_font_options_equal (default_options, NULL));
51     assert (! cairo_font_options_equal (NULL, default_options));
52
53     assert (cairo_font_options_hash (default_options) == cairo_font_options_hash (nil_options));
54     assert (cairo_font_options_hash (NULL) == cairo_font_options_hash (nil_options));
55     assert (cairo_font_options_hash (default_options) == cairo_font_options_hash (NULL));
56
57     cairo_font_options_merge (NULL, NULL);
58     cairo_font_options_merge (default_options, NULL);
59     cairo_font_options_merge (default_options, nil_options);
60
61     cairo_font_options_set_antialias (NULL, CAIRO_ANTIALIAS_DEFAULT);
62     cairo_font_options_get_antialias (NULL);
63     assert (cairo_font_options_get_antialias (default_options) == CAIRO_ANTIALIAS_DEFAULT);
64
65     cairo_font_options_set_subpixel_order (NULL, CAIRO_SUBPIXEL_ORDER_DEFAULT);
66     cairo_font_options_get_subpixel_order (NULL);
67     assert (cairo_font_options_get_subpixel_order (default_options) == CAIRO_SUBPIXEL_ORDER_DEFAULT);
68
69     cairo_font_options_set_hint_style (NULL, CAIRO_HINT_STYLE_DEFAULT);
70     cairo_font_options_get_hint_style (NULL);
71     assert (cairo_font_options_get_hint_style (default_options) == CAIRO_HINT_STYLE_DEFAULT);
72
73     cairo_font_options_set_hint_metrics (NULL, CAIRO_HINT_METRICS_DEFAULT);
74     cairo_font_options_get_hint_metrics (NULL);
75     assert (cairo_font_options_get_hint_metrics (default_options) == CAIRO_HINT_METRICS_DEFAULT);
76
77     cairo_font_options_destroy (NULL);
78     cairo_font_options_destroy (default_options);
79     cairo_font_options_destroy (nil_options);
80
81
82     /* Now try creating fonts with NULLs */
83     surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 0, 0);
84     cr = cairo_create (surface);
85     cairo_surface_destroy (surface);
86
87     cairo_matrix_init_identity (&identity);
88     scaled_font = cairo_scaled_font_create (cairo_get_font_face (cr),
89                                             &identity, &identity,
90                                             NULL);
91     assert (cairo_scaled_font_status (scaled_font) == CAIRO_STATUS_NULL_POINTER);
92     cairo_scaled_font_get_font_options (scaled_font, NULL);
93     cairo_scaled_font_destroy (scaled_font);
94
95     assert (cairo_status (cr) == CAIRO_STATUS_SUCCESS);
96     cairo_get_font_options (cr, NULL);
97     cairo_set_font_options (cr, NULL);
98     assert (cairo_status (cr) == CAIRO_STATUS_NULL_POINTER);
99
100     cairo_destroy (cr);
101
102     return CAIRO_TEST_SUCCESS;
103 }
104
105 CAIRO_TEST (font_options,
106             "Check setters and getters on cairo_font_options_t.",
107             "font, api", /* keywords */
108             NULL, /* requirements */
109             0, 0,
110             preamble, NULL)