Opensource Compliance Issue.
[platform/core/graphics/cairo.git] / test / toy-font-face.c
1 /*
2  * Copyright © 2005,2008 Red Hat, Inc.
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  * Red Hat, Inc. not be used in advertising or publicity pertaining to
10  * distribution of the software without specific, written prior
11  * permission. Red Hat, Inc. 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  * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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: Carl D. Worth <cworth@cworth.org>
24  *         Behdad Esfahbod <behdad@behdad.org>
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "cairo-test.h"
32
33 #include <cairo.h>
34 #include <assert.h>
35 #include <string.h>
36
37 #if   CAIRO_HAS_WIN32_FONT
38 #define CAIRO_FONT_FAMILY_DEFAULT "Arial"
39 #elif CAIRO_HAS_QUARTZ_FONT
40 #define CAIRO_FONT_FAMILY_DEFAULT "Helvetica"
41 #elif CAIRO_HAS_FT_FONT
42 #define CAIRO_FONT_FAMILY_DEFAULT ""
43 #else
44 #define CAIRO_FONT_FAMILY_DEFAULT "@cairo:"
45 #endif
46
47
48 static cairo_test_status_t
49 preamble (cairo_test_context_t *ctx)
50 {
51     cairo_t *cr;
52     cairo_surface_t *surface;
53     cairo_font_face_t *font_face;
54     cairo_status_t status;
55
56     surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 0, 0);
57     cr = cairo_create (surface);
58     cairo_surface_destroy (surface);
59
60     font_face = cairo_font_face_reference (cairo_get_font_face (cr));
61     assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
62     assert (cairo_toy_font_face_get_family (font_face) != NULL);
63     assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL);
64     assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL);
65     status = cairo_font_face_status(font_face);
66     cairo_font_face_destroy (font_face);
67
68     if (status)
69         return cairo_test_status_from_status (ctx, status);
70
71     cairo_select_font_face (cr,
72                             "bizarre",
73                             CAIRO_FONT_SLANT_OBLIQUE,
74                             CAIRO_FONT_WEIGHT_BOLD);
75     font_face = cairo_font_face_reference (cairo_get_font_face (cr));
76     assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
77     assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "bizarre"));
78     assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_OBLIQUE);
79     assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_BOLD);
80     status = cairo_font_face_status(font_face);
81     cairo_font_face_destroy (font_face);
82
83     if (status)
84         return cairo_test_status_from_status (ctx, status);
85
86     font_face = cairo_toy_font_face_create ("bozarre",
87                                             CAIRO_FONT_SLANT_OBLIQUE,
88                                             CAIRO_FONT_WEIGHT_BOLD);
89     assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
90     assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "bozarre"));
91     assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_OBLIQUE);
92     assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_BOLD);
93     status = cairo_font_face_status(font_face);
94     cairo_font_face_destroy (font_face);
95
96     if (status)
97         return cairo_test_status_from_status (ctx, status);
98
99     font_face = cairo_toy_font_face_create (NULL,
100                                             CAIRO_FONT_SLANT_OBLIQUE,
101                                             CAIRO_FONT_WEIGHT_BOLD);
102     assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
103     assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), CAIRO_FONT_FAMILY_DEFAULT));
104     assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL);
105     assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL);
106     assert (cairo_font_face_status(font_face) == CAIRO_STATUS_NULL_POINTER);
107     cairo_font_face_destroy (font_face);
108
109     font_face = cairo_toy_font_face_create ("\xff",
110                                             CAIRO_FONT_SLANT_OBLIQUE,
111                                             CAIRO_FONT_WEIGHT_BOLD);
112     assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
113     assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), CAIRO_FONT_FAMILY_DEFAULT));
114     assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL);
115     assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL);
116     assert (cairo_font_face_status(font_face) == CAIRO_STATUS_INVALID_STRING);
117     cairo_font_face_destroy (font_face);
118
119     font_face = cairo_toy_font_face_create ("sans",
120                                             -1,
121                                             CAIRO_FONT_WEIGHT_BOLD);
122     assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
123     assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), CAIRO_FONT_FAMILY_DEFAULT));
124     assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL);
125     assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL);
126     assert (cairo_font_face_status(font_face) == CAIRO_STATUS_INVALID_SLANT);
127     cairo_font_face_destroy (font_face);
128
129     font_face = cairo_toy_font_face_create ("sans",
130                                             CAIRO_FONT_SLANT_OBLIQUE,
131                                             -1);
132     assert (cairo_font_face_get_type (font_face) == CAIRO_FONT_TYPE_TOY);
133     assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), CAIRO_FONT_FAMILY_DEFAULT));
134     assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL);
135     assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL);
136     assert (cairo_font_face_status(font_face) == CAIRO_STATUS_INVALID_WEIGHT);
137     cairo_font_face_destroy (font_face);
138
139     cairo_destroy (cr);
140
141     return CAIRO_TEST_SUCCESS;
142 }
143
144 CAIRO_TEST (toy_font_face,
145             "Check the construction of 'toy' font faces",
146             "font, api", /* keywords */
147             NULL, /* requirements */
148             0, 0,
149             preamble, NULL)