2 * Copyright © 2011 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Behdad Esfahbod
29 /* Unit tests for hb-font.h */
33 test_face_empty (void)
35 g_assert (hb_face_get_empty ());
36 g_assert (hb_face_get_empty () == hb_face_create (hb_blob_get_empty (), 0));
37 g_assert (hb_face_get_empty () == hb_face_create (NULL, 0));
39 g_assert (hb_face_reference_table (hb_face_get_empty (), HB_TAG('h','e','a','d')) == hb_blob_get_empty ());
43 free_up (void *user_data)
45 int *freed = (int *) user_data;
53 get_table (hb_face_t *face, hb_tag_t tag, void *user_data)
55 return hb_blob_get_empty ();
59 test_face_fortables (void)
64 face = hb_face_create_for_tables (get_table, &freed, free_up);
67 hb_face_destroy (face);
73 test_fontfuncs_empty (void)
75 g_assert (hb_font_funcs_get_empty ());
76 g_assert (hb_font_funcs_is_immutable (hb_font_funcs_get_empty ()));
80 test_font_empty (void)
82 g_assert (hb_font_get_empty ());
83 g_assert (hb_font_get_empty () == hb_font_create (hb_face_get_empty ()));
84 g_assert (hb_font_get_empty () == hb_font_create (NULL));
85 g_assert (hb_font_get_empty () == hb_font_create_sub_font (NULL));
86 g_assert (hb_font_is_immutable (hb_font_get_empty ()));
88 g_assert (hb_font_get_face (hb_font_get_empty ()) == hb_face_get_empty ());
89 g_assert (hb_font_get_parent (hb_font_get_empty ()) == NULL);
92 static const char test_data[] = "test\0data";
95 test_font_properties (void)
101 int x_scale, y_scale;
102 unsigned int x_ppem, y_ppem;
104 blob = hb_blob_create (test_data, sizeof (test_data), HB_MEMORY_MODE_READONLY, NULL, NULL);
105 face = hb_face_create (blob, 0);
106 hb_blob_destroy (blob);
107 font = hb_font_create (face);
108 hb_face_destroy (face);
111 g_assert (hb_font_get_face (font) == face);
112 g_assert (hb_font_get_parent (font) == NULL);
117 hb_font_get_scale (font, NULL, NULL);
118 x_scale = y_scale = 13;
119 hb_font_get_scale (font, &x_scale, NULL);
120 g_assert_cmpint (x_scale, ==, 0);
121 x_scale = y_scale = 13;
122 hb_font_get_scale (font, NULL, &y_scale);
123 g_assert_cmpint (y_scale, ==, 0);
124 x_scale = y_scale = 13;
125 hb_font_get_scale (font, &x_scale, &y_scale);
126 g_assert_cmpint (x_scale, ==, 0);
127 g_assert_cmpint (y_scale, ==, 0);
129 hb_font_set_scale (font, 17, 19);
131 x_scale = y_scale = 13;
132 hb_font_get_scale (font, &x_scale, &y_scale);
133 g_assert_cmpint (x_scale, ==, 17);
134 g_assert_cmpint (y_scale, ==, 19);
139 hb_font_get_ppem (font, NULL, NULL);
140 x_ppem = y_ppem = 13;
141 hb_font_get_ppem (font, &x_ppem, NULL);
142 g_assert_cmpint (x_ppem, ==, 0);
143 x_ppem = y_ppem = 13;
144 hb_font_get_ppem (font, NULL, &y_ppem);
145 g_assert_cmpint (y_ppem, ==, 0);
146 x_ppem = y_ppem = 13;
147 hb_font_get_ppem (font, &x_ppem, &y_ppem);
148 g_assert_cmpint (x_ppem, ==, 0);
149 g_assert_cmpint (y_ppem, ==, 0);
151 hb_font_set_ppem (font, 17, 19);
153 x_ppem = y_ppem = 13;
154 hb_font_get_ppem (font, &x_ppem, &y_ppem);
155 g_assert_cmpint (x_ppem, ==, 17);
156 g_assert_cmpint (y_ppem, ==, 19);
159 /* Check immutable */
161 g_assert (!hb_font_is_immutable (font));
162 hb_font_make_immutable (font);
163 g_assert (hb_font_is_immutable (font));
165 hb_font_set_scale (font, 10, 12);
166 x_scale = y_scale = 13;
167 hb_font_get_scale (font, &x_scale, &y_scale);
168 g_assert_cmpint (x_scale, ==, 17);
169 g_assert_cmpint (y_scale, ==, 19);
171 hb_font_set_ppem (font, 10, 12);
172 x_ppem = y_ppem = 13;
173 hb_font_get_ppem (font, &x_ppem, &y_ppem);
174 g_assert_cmpint (x_ppem, ==, 17);
175 g_assert_cmpint (y_ppem, ==, 19);
179 subfont = hb_font_create_sub_font (font);
180 hb_font_destroy (font);
182 g_assert (hb_font_get_parent (subfont) == font);
183 g_assert (hb_font_get_face (subfont) == face);
186 x_scale = y_scale = 13;
187 hb_font_get_scale (subfont, &x_scale, &y_scale);
188 g_assert_cmpint (x_scale, ==, 17);
189 g_assert_cmpint (y_scale, ==, 19);
190 hb_font_set_scale (subfont, 10, 12);
191 x_scale = y_scale = 13;
192 hb_font_get_scale (subfont, &x_scale, &y_scale);
193 g_assert_cmpint (x_scale, ==, 10);
194 g_assert_cmpint (y_scale, ==, 12);
195 x_scale = y_scale = 13;
196 hb_font_get_scale (font, &x_scale, &y_scale);
197 g_assert_cmpint (x_scale, ==, 17);
198 g_assert_cmpint (y_scale, ==, 19);
201 x_ppem = y_ppem = 13;
202 hb_font_get_ppem (subfont, &x_ppem, &y_ppem);
203 g_assert_cmpint (x_ppem, ==, 17);
204 g_assert_cmpint (y_ppem, ==, 19);
205 hb_font_set_ppem (subfont, 10, 12);
206 x_ppem = y_ppem = 13;
207 hb_font_get_ppem (subfont, &x_ppem, &y_ppem);
208 g_assert_cmpint (x_ppem, ==, 10);
209 g_assert_cmpint (y_ppem, ==, 12);
210 x_ppem = y_ppem = 13;
211 hb_font_get_ppem (font, &x_ppem, &y_ppem);
212 g_assert_cmpint (x_ppem, ==, 17);
213 g_assert_cmpint (y_ppem, ==, 19);
215 hb_font_destroy (subfont);
219 main (int argc, char **argv)
221 hb_test_init (&argc, &argv);
223 hb_test_add (test_face_empty);
224 hb_test_add (test_face_fortables);
226 hb_test_add (test_fontfuncs_empty);
228 hb_test_add (test_font_empty);
229 hb_test_add (test_font_properties);
236 return hb_test_run();