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));
41 test_font_funcs_empty (void)
43 g_assert (hb_font_funcs_get_empty ());
44 g_assert (hb_font_funcs_is_immutable (hb_font_funcs_get_empty ()));
48 test_font_empty (void)
50 g_assert (hb_font_get_empty ());
51 g_assert (hb_font_get_empty () == hb_font_create (hb_face_get_empty ()));
52 g_assert (hb_font_get_empty () == hb_font_create (NULL));
53 g_assert (hb_font_get_empty () == hb_font_create_sub_font (NULL));
54 g_assert (hb_font_is_immutable (hb_font_get_empty ()));
57 static const char test_data[] = "test\0data";
60 test_font_properties (void)
66 unsigned int x_ppem, y_ppem;
68 blob = hb_blob_create (test_data, sizeof (test_data), HB_MEMORY_MODE_READONLY, NULL, NULL);
69 face = hb_face_create (blob, 0);
70 hb_blob_destroy (blob);
71 font = hb_font_create (face);
72 hb_face_destroy (face);
75 g_assert (hb_font_get_face (font) == face);
76 g_assert (hb_font_get_parent (font) == NULL);
81 hb_font_get_scale (font, NULL, NULL);
82 x_scale = y_scale = 13;
83 hb_font_get_scale (font, &x_scale, NULL);
84 g_assert_cmpint (x_scale, ==, 0);
85 x_scale = y_scale = 13;
86 hb_font_get_scale (font, NULL, &y_scale);
87 g_assert_cmpint (y_scale, ==, 0);
88 x_scale = y_scale = 13;
89 hb_font_get_scale (font, &x_scale, &y_scale);
90 g_assert_cmpint (x_scale, ==, 0);
91 g_assert_cmpint (y_scale, ==, 0);
93 hb_font_set_scale (font, 17, 19);
95 x_scale = y_scale = 13;
96 hb_font_get_scale (font, &x_scale, &y_scale);
97 g_assert_cmpint (x_scale, ==, 17);
98 g_assert_cmpint (y_scale, ==, 19);
103 hb_font_get_ppem (font, NULL, NULL);
104 x_ppem = y_ppem = 13;
105 hb_font_get_ppem (font, &x_ppem, NULL);
106 g_assert_cmpint (x_ppem, ==, 0);
107 x_ppem = y_ppem = 13;
108 hb_font_get_ppem (font, NULL, &y_ppem);
109 g_assert_cmpint (y_ppem, ==, 0);
110 x_ppem = y_ppem = 13;
111 hb_font_get_ppem (font, &x_ppem, &y_ppem);
112 g_assert_cmpint (x_ppem, ==, 0);
113 g_assert_cmpint (y_ppem, ==, 0);
115 hb_font_set_ppem (font, 17, 19);
117 x_ppem = y_ppem = 13;
118 hb_font_get_ppem (font, &x_ppem, &y_ppem);
119 g_assert_cmpint (x_ppem, ==, 17);
120 g_assert_cmpint (y_ppem, ==, 19);
123 /* Check immutable */
125 g_assert (!hb_font_is_immutable (font));
126 hb_font_make_immutable (font);
127 g_assert (hb_font_is_immutable (font));
129 hb_font_set_scale (font, 10, 12);
130 x_scale = y_scale = 13;
131 hb_font_get_scale (font, &x_scale, &y_scale);
132 g_assert_cmpint (x_scale, ==, 17);
133 g_assert_cmpint (y_scale, ==, 19);
135 hb_font_set_ppem (font, 10, 12);
136 x_ppem = y_ppem = 13;
137 hb_font_get_ppem (font, &x_ppem, &y_ppem);
138 g_assert_cmpint (x_ppem, ==, 17);
139 g_assert_cmpint (y_ppem, ==, 19);
142 hb_font_destroy (font);
146 main (int argc, char **argv)
148 hb_test_init (&argc, &argv);
150 hb_test_add (test_face_empty);
152 hb_test_add (test_font_funcs_empty);
154 hb_test_add (test_font_empty);
155 hb_test_add (test_font_properties);
157 return hb_test_run();