[test/font] Test get_face() / get_parent()
[apps/home/video-player.git] / test / test-font.c
1 /*
2  * Copyright © 2011  Google, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
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.
11  *
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
16  * DAMAGE.
17  *
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.
23  *
24  * Google Author(s): Behdad Esfahbod
25  */
26
27 #include "hb-test.h"
28
29 /* Unit tests for hb-font.h */
30
31
32 static void
33 test_face_empty (void)
34 {
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));
38 }
39
40 static void
41 test_font_funcs_empty (void)
42 {
43   g_assert (hb_font_funcs_get_empty ());
44   g_assert (hb_font_funcs_is_immutable (hb_font_funcs_get_empty ()));
45 }
46
47 static void
48 test_font_empty (void)
49 {
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 ()));
55 }
56
57 static const char test_data[] = "test\0data";
58
59 static void
60 test_font_properties (void)
61 {
62   hb_blob_t *blob;
63   hb_face_t *face;
64   hb_font_t *font;
65   int x_scale, y_scale;
66   unsigned int x_ppem, y_ppem;
67
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);
73
74
75   g_assert (hb_font_get_face (font) == face);
76   g_assert (hb_font_get_parent (font) == NULL);
77
78
79   /* Check scale */
80
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);
92
93   hb_font_set_scale (font, 17, 19);
94
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);
99
100
101   /* Check ppem */
102
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);
114
115   hb_font_set_ppem (font, 17, 19);
116
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);
121
122
123   /* Check immutable */
124
125   g_assert (!hb_font_is_immutable (font));
126   hb_font_make_immutable (font);
127   g_assert (hb_font_is_immutable (font));
128
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);
134
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);
140
141
142   hb_font_destroy (font);
143 }
144
145 int
146 main (int argc, char **argv)
147 {
148   hb_test_init (&argc, &argv);
149
150   hb_test_add (test_face_empty);
151
152   hb_test_add (test_font_funcs_empty);
153
154   hb_test_add (test_font_empty);
155   hb_test_add (test_font_properties);
156
157   return hb_test_run();
158 }