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 /* This file tests types defined in hb-common.h */
34 /* We already ASSERT_STATIC these in hb-private.h, but anyway */
35 g_assert_cmpint (sizeof (int8_t), ==, 1);
36 g_assert_cmpint (sizeof (uint8_t), ==, 1);
37 g_assert_cmpint (sizeof (int16_t), ==, 2);
38 g_assert_cmpint (sizeof (uint16_t), ==, 2);
39 g_assert_cmpint (sizeof (int32_t), ==, 4);
40 g_assert_cmpint (sizeof (uint32_t), ==, 4);
41 g_assert_cmpint (sizeof (int64_t), ==, 8);
42 g_assert_cmpint (sizeof (uint64_t), ==, 8);
44 g_assert_cmpint (sizeof (hb_codepoint_t), ==, 4);
45 g_assert_cmpint (sizeof (hb_position_t), ==, 4);
46 g_assert_cmpint (sizeof (hb_mask_t), ==, 4);
47 g_assert_cmpint (sizeof (hb_var_int_t), ==, 4);
51 test_types_direction (void)
53 g_assert_cmpint ((signed) HB_DIRECTION_INVALID, ==, -1);
54 g_assert_cmpint (HB_DIRECTION_LTR, ==, 0);
56 g_assert (HB_DIRECTION_IS_HORIZONTAL (HB_DIRECTION_LTR));
57 g_assert (HB_DIRECTION_IS_HORIZONTAL (HB_DIRECTION_RTL));
58 g_assert (!HB_DIRECTION_IS_HORIZONTAL (HB_DIRECTION_TTB));
59 g_assert (!HB_DIRECTION_IS_HORIZONTAL (HB_DIRECTION_BTT));
61 g_assert (!HB_DIRECTION_IS_VERTICAL (HB_DIRECTION_LTR));
62 g_assert (!HB_DIRECTION_IS_VERTICAL (HB_DIRECTION_RTL));
63 g_assert (HB_DIRECTION_IS_VERTICAL (HB_DIRECTION_TTB));
64 g_assert (HB_DIRECTION_IS_VERTICAL (HB_DIRECTION_BTT));
66 g_assert (HB_DIRECTION_IS_FORWARD (HB_DIRECTION_LTR));
67 g_assert (HB_DIRECTION_IS_FORWARD (HB_DIRECTION_TTB));
68 g_assert (!HB_DIRECTION_IS_FORWARD (HB_DIRECTION_RTL));
69 g_assert (!HB_DIRECTION_IS_FORWARD (HB_DIRECTION_BTT));
71 g_assert (!HB_DIRECTION_IS_BACKWARD (HB_DIRECTION_LTR));
72 g_assert (!HB_DIRECTION_IS_BACKWARD (HB_DIRECTION_TTB));
73 g_assert (HB_DIRECTION_IS_BACKWARD (HB_DIRECTION_RTL));
74 g_assert (HB_DIRECTION_IS_BACKWARD (HB_DIRECTION_BTT));
76 g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_LTR), ==, HB_DIRECTION_RTL);
77 g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_RTL), ==, HB_DIRECTION_LTR);
78 g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_TTB), ==, HB_DIRECTION_BTT);
79 g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_BTT), ==, HB_DIRECTION_TTB);
81 g_assert_cmpint (HB_DIRECTION_INVALID, ==, hb_direction_from_string (NULL));
82 g_assert_cmpint (HB_DIRECTION_INVALID, ==, hb_direction_from_string (""));
83 g_assert_cmpint (HB_DIRECTION_INVALID, ==, hb_direction_from_string ("x"));
84 g_assert_cmpint (HB_DIRECTION_RTL, ==, hb_direction_from_string ("r"));
85 g_assert_cmpint (HB_DIRECTION_RTL, ==, hb_direction_from_string ("rtl"));
86 g_assert_cmpint (HB_DIRECTION_RTL, ==, hb_direction_from_string ("RtL"));
87 g_assert_cmpint (HB_DIRECTION_RTL, ==, hb_direction_from_string ("right-to-left"));
88 g_assert_cmpint (HB_DIRECTION_TTB, ==, hb_direction_from_string ("ttb"));
94 g_assert_cmphex (HB_TAG_NONE, ==, 0);
96 g_assert_cmphex (HB_TAG ('a','B','c','D'), ==, 0x61426344);
98 g_assert_cmphex (hb_tag_from_string ("aBcDe"), ==, 0x61426344);
99 g_assert_cmphex (hb_tag_from_string ("aBcD"), ==, 0x61426344);
100 g_assert_cmphex (hb_tag_from_string ("aBc"), ==, 0x61426320);
101 g_assert_cmphex (hb_tag_from_string ("aB"), ==, 0x61422020);
102 g_assert_cmphex (hb_tag_from_string ("a"), ==, 0x61202020);
104 g_assert_cmphex (hb_tag_from_string (""), ==, HB_TAG_NONE);
105 g_assert_cmphex (hb_tag_from_string (NULL), ==, HB_TAG_NONE);
109 test_types_script (void)
111 hb_tag_t arab = HB_TAG_CHAR4 ("arab");
112 hb_tag_t Arab = HB_TAG_CHAR4 ("Arab");
113 hb_tag_t ARAB = HB_TAG_CHAR4 ("ARAB");
115 hb_tag_t wWyZ = HB_TAG_CHAR4 ("wWyZ");
116 hb_tag_t Wwyz = HB_TAG_CHAR4 ("Wwyz");
118 hb_tag_t x123 = HB_TAG_CHAR4 ("x123");
120 g_assert_cmpint (HB_SCRIPT_INVALID, ==, (hb_script_t) HB_TAG_NONE);
121 g_assert_cmphex (HB_SCRIPT_ARABIC, !=, HB_SCRIPT_LATIN);
123 g_assert_cmphex (HB_SCRIPT_INVALID, ==, hb_script_from_string (NULL));
124 g_assert_cmphex (HB_SCRIPT_INVALID, ==, hb_script_from_string (""));
125 g_assert_cmphex (HB_SCRIPT_UNKNOWN, ==, hb_script_from_string ("x"));
127 g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_string ("arab"));
128 g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_string ("Arab"));
129 g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_string ("ARAB"));
131 g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_iso15924_tag (arab));
132 g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_iso15924_tag (Arab));
133 g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_iso15924_tag (ARAB));
135 /* Arbitrary tags that look like may be valid ISO 15924 should be preserved. */
136 g_assert_cmphex (HB_SCRIPT_UNKNOWN, !=, hb_script_from_string ("wWyZ"));
137 g_assert_cmphex (HB_SCRIPT_UNKNOWN, !=, hb_script_from_iso15924_tag (wWyZ));
138 /* Otherwise, UNKNOWN should be returned. */
139 g_assert_cmphex (HB_SCRIPT_UNKNOWN, ==, hb_script_from_string ("x123"));
140 g_assert_cmphex (HB_SCRIPT_UNKNOWN, ==, hb_script_from_iso15924_tag (x123));
142 g_assert_cmphex (hb_script_to_iso15924_tag (HB_SCRIPT_ARABIC), ==, Arab);
143 g_assert_cmphex (hb_script_to_iso15924_tag (hb_script_from_iso15924_tag (wWyZ)), ==, Wwyz);
145 g_assert_cmpint (hb_script_get_horizontal_direction (HB_SCRIPT_LATIN), ==, HB_DIRECTION_LTR);
146 g_assert_cmpint (hb_script_get_horizontal_direction (HB_SCRIPT_ARABIC), ==, HB_DIRECTION_RTL);
147 g_assert_cmpint (hb_script_get_horizontal_direction (hb_script_from_iso15924_tag (wWyZ)), ==, HB_DIRECTION_LTR);
151 test_types_language (void)
153 hb_language_t fa = hb_language_from_string ("fa");
154 hb_language_t fa_IR = hb_language_from_string ("fa_IR");
155 hb_language_t fa_ir = hb_language_from_string ("fa-ir");
156 hb_language_t en = hb_language_from_string ("en");
158 g_assert (fa != NULL);
159 g_assert (fa_IR != NULL);
160 g_assert (fa_IR == fa_ir);
162 g_assert (en != NULL);
166 g_assert (en == hb_language_from_string ("en"));
167 g_assert (en == hb_language_from_string ("eN"));
169 g_assert (NULL == hb_language_from_string (NULL));
170 g_assert (NULL == hb_language_from_string (""));
174 main (int argc, char **argv)
176 g_test_init (&argc, &argv, NULL);
178 g_test_add_func ("/types/int", test_types_int);
179 g_test_add_func ("/types/direction", test_types_direction);
180 g_test_add_func ("/types/tag", test_types_tag);
181 g_test_add_func ("/types/script", test_types_script);
182 g_test_add_func ("/types/language", test_types_language);