Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 2 | * Copyright © 2011 Codethink Limited |
| 3 | * Copyright © 2011 Google, Inc. |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 4 | * |
| 5 | * This is part of HarfBuzz, a text shaping library. |
| 6 | * |
| 7 | * Permission is hereby granted, without written agreement and without |
| 8 | * license or royalty fees, to use, copy, modify, and distribute this |
| 9 | * software and its documentation for any purpose, provided that the |
| 10 | * above copyright notice and the following two paragraphs appear in |
| 11 | * all copies of this software. |
| 12 | * |
| 13 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 14 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 16 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 17 | * DAMAGE. |
| 18 | * |
| 19 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 20 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 22 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 23 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 24 | * |
| 25 | * Codethink Author(s): Ryan Lortie |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 26 | * Google Author(s): Behdad Esfahbod |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include "hb-test.h" |
| 30 | |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 31 | /* Unit tests for hb-unicode.h */ |
Behdad Esfahbod | 07e2277 | 2011-05-02 14:58:04 -0400 | [diff] [blame] | 32 | /* Unit tests for hb-glib.h */ |
| 33 | /* Unit tests for hb-icu.h */ |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 34 | |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 35 | |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 36 | #ifdef HAVE_GLIB |
| 37 | #include <hb-glib.h> |
| 38 | #endif |
| 39 | #ifdef HAVE_ICU |
| 40 | #include <hb-icu.h> |
| 41 | #endif |
| 42 | |
| 43 | |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 44 | /* Some useful stuff */ |
| 45 | |
| 46 | #define MAGIC0 0x12345678 |
| 47 | #define MAGIC1 0x76543210 |
| 48 | |
| 49 | typedef struct { |
| 50 | int value; |
| 51 | gboolean freed; |
| 52 | } data_t; |
| 53 | |
| 54 | static void free_up (void *p) |
| 55 | { |
| 56 | data_t *data = (data_t *) p; |
| 57 | |
| 58 | g_assert (data->value == MAGIC0 || data->value == MAGIC1); |
Behdad Esfahbod | f74d6c8 | 2011-05-02 19:52:32 -0400 | [diff] [blame] | 59 | g_assert (!data->freed); |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 60 | data->freed = TRUE; |
| 61 | } |
| 62 | |
| 63 | static hb_script_t |
| 64 | simple_get_script (hb_unicode_funcs_t *ufuncs, |
| 65 | hb_codepoint_t codepoint, |
| 66 | void *user_data) |
| 67 | { |
| 68 | data_t *data = (data_t *) user_data; |
| 69 | |
Behdad Esfahbod | c784c67 | 2011-05-02 15:59:57 -0400 | [diff] [blame] | 70 | g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL); |
Behdad Esfahbod | f74d6c8 | 2011-05-02 19:52:32 -0400 | [diff] [blame] | 71 | g_assert_cmphex (data->value, ==, MAGIC0); |
| 72 | g_assert (!data->freed); |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 73 | |
| 74 | if ('a' <= codepoint && codepoint <= 'z') |
| 75 | return HB_SCRIPT_LATIN; |
| 76 | else |
| 77 | return HB_SCRIPT_UNKNOWN; |
| 78 | } |
| 79 | |
| 80 | static hb_script_t |
| 81 | a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs, |
| 82 | hb_codepoint_t codepoint, |
| 83 | void *user_data) |
| 84 | { |
| 85 | data_t *data = (data_t *) user_data; |
| 86 | |
| 87 | g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL); |
Behdad Esfahbod | f74d6c8 | 2011-05-02 19:52:32 -0400 | [diff] [blame] | 88 | g_assert_cmphex (data->value, ==, MAGIC1); |
| 89 | g_assert (!data->freed); |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 90 | |
| 91 | if (codepoint == 'a') { |
| 92 | return HB_SCRIPT_ARABIC; |
| 93 | } else { |
| 94 | hb_unicode_funcs_t *parent = hb_unicode_funcs_get_parent (ufuncs); |
| 95 | |
Behdad Esfahbod | c464172 | 2011-07-07 23:47:19 -0400 | [diff] [blame] | 96 | return hb_unicode_script (parent, codepoint); |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
| 100 | |
| 101 | |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 102 | /* Check all properties */ |
| 103 | |
| 104 | /* Some of the following tables where adapted from glib/glib/tests/utf8-misc.c. |
| 105 | * The license is compatible. */ |
| 106 | |
| 107 | typedef struct { |
| 108 | hb_codepoint_t unicode; |
| 109 | unsigned int value; |
| 110 | } test_pair_t; |
| 111 | |
| 112 | static const test_pair_t combining_class_tests[] = |
| 113 | { |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 114 | { 0x0020, 0 }, |
| 115 | { 0x0334, 1 }, |
| 116 | { 0x093C, 7 }, |
| 117 | { 0x3099, 8 }, |
| 118 | { 0x094D, 9 }, |
| 119 | { 0x05B0, 10 }, |
| 120 | { 0x05B1, 11 }, |
| 121 | { 0x05B2, 12 }, |
| 122 | { 0x05B3, 13 }, |
| 123 | { 0x05B4, 14 }, |
| 124 | { 0x05B5, 15 }, |
| 125 | { 0x05B6, 16 }, |
| 126 | { 0x05B7, 17 }, |
| 127 | { 0x05B8, 18 }, |
| 128 | { 0x05B9, 19 }, |
| 129 | { 0x05BB, 20 }, |
| 130 | { 0x05BC, 21 }, |
| 131 | { 0x05BD, 22 }, |
| 132 | { 0x05BF, 23 }, |
| 133 | { 0x05C1, 24 }, |
| 134 | { 0x05C2, 25 }, |
| 135 | { 0xFB1E, 26 }, |
| 136 | { 0x064B, 27 }, |
| 137 | { 0x064C, 28 }, |
| 138 | { 0x064D, 29 }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 139 | /* ... */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 140 | { 0x05AE, 228 }, |
| 141 | { 0x0300, 230 }, |
| 142 | { 0x302C, 232 }, |
| 143 | { 0x0362, 233 }, |
| 144 | { 0x0360, 234 }, |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 145 | { 0x0345, 240 }, |
| 146 | |
| 147 | { 0x111111, 0 } |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 148 | }; |
| 149 | static const test_pair_t combining_class_tests_more[] = |
| 150 | { |
Behdad Esfahbod | 199abbd | 2011-08-02 13:59:47 -0400 | [diff] [blame] | 151 | /* Unicode-5.1 character additions */ |
| 152 | { 0x1DCD, 234 }, |
| 153 | |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 154 | /* Unicode-5.2 character additions */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 155 | { 0xA8E0, 230 }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 156 | |
| 157 | /* Unicode-6.0 character additions */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 158 | { 0x135D, 230 }, |
| 159 | |
| 160 | { 0x111111, 0 } |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 161 | }; |
| 162 | |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 163 | |
| 164 | static const test_pair_t general_category_tests[] = |
| 165 | { |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 166 | { 0x000D, HB_UNICODE_GENERAL_CATEGORY_CONTROL }, |
| 167 | { 0x200E, HB_UNICODE_GENERAL_CATEGORY_FORMAT }, |
| 168 | { 0x0378, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED }, |
| 169 | { 0xE000, HB_UNICODE_GENERAL_CATEGORY_PRIVATE_USE }, |
| 170 | { 0xD800, HB_UNICODE_GENERAL_CATEGORY_SURROGATE }, |
| 171 | { 0x0061, HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER }, |
| 172 | { 0x02B0, HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER }, |
| 173 | { 0x3400, HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER }, |
| 174 | { 0x01C5, HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER }, |
| 175 | { 0xFF21, HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER }, |
Behdad Esfahbod | ad903e6 | 2011-07-21 10:17:22 -0400 | [diff] [blame] | 176 | { 0x0903, HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK }, |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 177 | { 0x20DD, HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK }, |
| 178 | { 0xA806, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK }, |
| 179 | { 0xFF10, HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER }, |
| 180 | { 0x16EE, HB_UNICODE_GENERAL_CATEGORY_LETTER_NUMBER }, |
| 181 | { 0x17F0, HB_UNICODE_GENERAL_CATEGORY_OTHER_NUMBER }, |
| 182 | { 0x005F, HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION }, |
| 183 | { 0x058A, HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION }, |
| 184 | { 0x0F3B, HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION }, |
| 185 | { 0x2019, HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION }, |
| 186 | { 0x2018, HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION }, |
| 187 | { 0x2016, HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION }, |
| 188 | { 0x0F3A, HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION }, |
| 189 | { 0x20A0, HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL }, |
| 190 | { 0x309B, HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL }, |
| 191 | { 0xFB29, HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL }, |
| 192 | { 0x00A6, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL }, |
| 193 | { 0x2028, HB_UNICODE_GENERAL_CATEGORY_LINE_SEPARATOR }, |
| 194 | { 0x2029, HB_UNICODE_GENERAL_CATEGORY_PARAGRAPH_SEPARATOR }, |
| 195 | { 0x202F, HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 196 | |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 197 | { 0x111111, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED } |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 198 | }; |
| 199 | static const test_pair_t general_category_tests_more[] = |
| 200 | { |
| 201 | /* Unicode-5.2 character additions */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 202 | { 0x1F131, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 203 | |
| 204 | /* Unicode-6.0 character additions */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 205 | { 0x0620, HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER }, |
| 206 | |
| 207 | { 0x111111, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED } |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | static const test_pair_t mirroring_tests[] = |
| 211 | { |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 212 | /* Some characters that do NOT mirror */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 213 | { 0x0020, 0x0020 }, |
| 214 | { 0x0041, 0x0041 }, |
| 215 | { 0x00F0, 0x00F0 }, |
| 216 | { 0x27CC, 0x27CC }, |
| 217 | { 0xE01EF, 0xE01EF }, |
| 218 | { 0x1D7C3, 0x1D7C3 }, |
| 219 | { 0x100000, 0x100000 }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 220 | |
| 221 | /* Some characters that do mirror */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 222 | { 0x0029, 0x0028 }, |
| 223 | { 0x0028, 0x0029 }, |
| 224 | { 0x003E, 0x003C }, |
| 225 | { 0x003C, 0x003E }, |
| 226 | { 0x005D, 0x005B }, |
| 227 | { 0x005B, 0x005D }, |
| 228 | { 0x007D, 0x007B }, |
| 229 | { 0x007B, 0x007D }, |
| 230 | { 0x00BB, 0x00AB }, |
| 231 | { 0x00AB, 0x00BB }, |
| 232 | { 0x226B, 0x226A }, |
| 233 | { 0x226A, 0x226B }, |
| 234 | { 0x22F1, 0x22F0 }, |
| 235 | { 0x22F0, 0x22F1 }, |
| 236 | { 0xFF60, 0xFF5F }, |
| 237 | { 0xFF5F, 0xFF60 }, |
| 238 | { 0xFF63, 0xFF62 }, |
| 239 | { 0xFF62, 0xFF63 }, |
| 240 | |
| 241 | { 0x111111, 0x111111 }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 242 | }; |
| 243 | static const test_pair_t mirroring_tests_more[] = |
| 244 | { |
| 245 | /* No new mirroring characters have been encoded in recent Unicode versions. */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 246 | { 0x111111, 0x111111 } |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | static const test_pair_t script_tests[] = |
| 250 | { |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 251 | { 0x002A, HB_SCRIPT_COMMON }, |
| 252 | { 0x0670, HB_SCRIPT_INHERITED }, |
| 253 | { 0x060D, HB_SCRIPT_ARABIC }, |
| 254 | { 0x0559, HB_SCRIPT_ARMENIAN }, |
| 255 | { 0x09CD, HB_SCRIPT_BENGALI }, |
| 256 | { 0x31B6, HB_SCRIPT_BOPOMOFO }, |
| 257 | { 0x13A2, HB_SCRIPT_CHEROKEE }, |
| 258 | { 0x2CFD, HB_SCRIPT_COPTIC }, |
| 259 | { 0x0482, HB_SCRIPT_CYRILLIC }, |
| 260 | { 0x10401, HB_SCRIPT_DESERET }, |
| 261 | { 0x094D, HB_SCRIPT_DEVANAGARI }, |
| 262 | { 0x1258, HB_SCRIPT_ETHIOPIC }, |
| 263 | { 0x10FC, HB_SCRIPT_GEORGIAN }, |
| 264 | { 0x10341, HB_SCRIPT_GOTHIC }, |
| 265 | { 0x0375, HB_SCRIPT_GREEK }, |
| 266 | { 0x0A83, HB_SCRIPT_GUJARATI }, |
| 267 | { 0x0A3C, HB_SCRIPT_GURMUKHI }, |
| 268 | { 0x3005, HB_SCRIPT_HAN }, |
| 269 | { 0x1100, HB_SCRIPT_HANGUL }, |
| 270 | { 0x05BF, HB_SCRIPT_HEBREW }, |
| 271 | { 0x309F, HB_SCRIPT_HIRAGANA }, |
| 272 | { 0x0CBC, HB_SCRIPT_KANNADA }, |
| 273 | { 0x30FF, HB_SCRIPT_KATAKANA }, |
| 274 | { 0x17DD, HB_SCRIPT_KHMER }, |
| 275 | { 0x0EDD, HB_SCRIPT_LAO }, |
| 276 | { 0x0061, HB_SCRIPT_LATIN }, |
| 277 | { 0x0D3D, HB_SCRIPT_MALAYALAM }, |
| 278 | { 0x1843, HB_SCRIPT_MONGOLIAN }, |
| 279 | { 0x1031, HB_SCRIPT_MYANMAR }, |
| 280 | { 0x169C, HB_SCRIPT_OGHAM }, |
| 281 | { 0x10322, HB_SCRIPT_OLD_ITALIC }, |
| 282 | { 0x0B3C, HB_SCRIPT_ORIYA }, |
| 283 | { 0x16EF, HB_SCRIPT_RUNIC }, |
| 284 | { 0x0DBD, HB_SCRIPT_SINHALA }, |
| 285 | { 0x0711, HB_SCRIPT_SYRIAC }, |
| 286 | { 0x0B82, HB_SCRIPT_TAMIL }, |
| 287 | { 0x0C03, HB_SCRIPT_TELUGU }, |
| 288 | { 0x07B1, HB_SCRIPT_THAANA }, |
| 289 | { 0x0E31, HB_SCRIPT_THAI }, |
| 290 | { 0x0FD4, HB_SCRIPT_TIBETAN }, |
Behdad Esfahbod | 54e6f6c | 2013-08-09 14:34:54 -0400 | [diff] [blame] | 291 | { 0x1401, HB_SCRIPT_CANADIAN_SYLLABICS }, |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 292 | { 0xA015, HB_SCRIPT_YI }, |
| 293 | { 0x1700, HB_SCRIPT_TAGALOG }, |
| 294 | { 0x1720, HB_SCRIPT_HANUNOO }, |
| 295 | { 0x1740, HB_SCRIPT_BUHID }, |
| 296 | { 0x1760, HB_SCRIPT_TAGBANWA }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 297 | |
| 298 | /* Unicode-4.0 additions */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 299 | { 0x2800, HB_SCRIPT_BRAILLE }, |
| 300 | { 0x10808, HB_SCRIPT_CYPRIOT }, |
| 301 | { 0x1932, HB_SCRIPT_LIMBU }, |
| 302 | { 0x10480, HB_SCRIPT_OSMANYA }, |
| 303 | { 0x10450, HB_SCRIPT_SHAVIAN }, |
| 304 | { 0x10000, HB_SCRIPT_LINEAR_B }, |
| 305 | { 0x1950, HB_SCRIPT_TAI_LE }, |
| 306 | { 0x1039F, HB_SCRIPT_UGARITIC }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 307 | |
| 308 | /* Unicode-4.1 additions */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 309 | { 0x1980, HB_SCRIPT_NEW_TAI_LUE }, |
| 310 | { 0x1A1F, HB_SCRIPT_BUGINESE }, |
| 311 | { 0x2C00, HB_SCRIPT_GLAGOLITIC }, |
| 312 | { 0x2D6F, HB_SCRIPT_TIFINAGH }, |
| 313 | { 0xA800, HB_SCRIPT_SYLOTI_NAGRI }, |
| 314 | { 0x103D0, HB_SCRIPT_OLD_PERSIAN }, |
| 315 | { 0x10A3F, HB_SCRIPT_KHAROSHTHI }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 316 | |
| 317 | /* Unicode-5.0 additions */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 318 | { 0x0378, HB_SCRIPT_UNKNOWN }, |
| 319 | { 0x1B04, HB_SCRIPT_BALINESE }, |
| 320 | { 0x12000, HB_SCRIPT_CUNEIFORM }, |
| 321 | { 0x10900, HB_SCRIPT_PHOENICIAN }, |
| 322 | { 0xA840, HB_SCRIPT_PHAGS_PA }, |
| 323 | { 0x07C0, HB_SCRIPT_NKO }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 324 | |
| 325 | /* Unicode-5.1 additions */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 326 | { 0xA900, HB_SCRIPT_KAYAH_LI }, |
| 327 | { 0x1C00, HB_SCRIPT_LEPCHA }, |
| 328 | { 0xA930, HB_SCRIPT_REJANG }, |
| 329 | { 0x1B80, HB_SCRIPT_SUNDANESE }, |
| 330 | { 0xA880, HB_SCRIPT_SAURASHTRA }, |
| 331 | { 0xAA00, HB_SCRIPT_CHAM }, |
| 332 | { 0x1C50, HB_SCRIPT_OL_CHIKI }, |
| 333 | { 0xA500, HB_SCRIPT_VAI }, |
| 334 | { 0x102A0, HB_SCRIPT_CARIAN }, |
| 335 | { 0x10280, HB_SCRIPT_LYCIAN }, |
| 336 | { 0x1093F, HB_SCRIPT_LYDIAN }, |
| 337 | |
| 338 | { 0x111111, HB_SCRIPT_UNKNOWN } |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 339 | }; |
| 340 | static const test_pair_t script_tests_more[] = |
| 341 | { |
| 342 | /* Unicode-5.2 additions */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 343 | { 0x10B00, HB_SCRIPT_AVESTAN }, |
| 344 | { 0xA6A0, HB_SCRIPT_BAMUM }, |
| 345 | { 0x13000, HB_SCRIPT_EGYPTIAN_HIEROGLYPHS }, |
| 346 | { 0x10840, HB_SCRIPT_IMPERIAL_ARAMAIC }, |
| 347 | { 0x10B60, HB_SCRIPT_INSCRIPTIONAL_PAHLAVI }, |
| 348 | { 0x10B40, HB_SCRIPT_INSCRIPTIONAL_PARTHIAN }, |
| 349 | { 0xA980, HB_SCRIPT_JAVANESE }, |
| 350 | { 0x11082, HB_SCRIPT_KAITHI }, |
| 351 | { 0xA4D0, HB_SCRIPT_LISU }, |
| 352 | { 0xABE5, HB_SCRIPT_MEETEI_MAYEK }, |
| 353 | { 0x10A60, HB_SCRIPT_OLD_SOUTH_ARABIAN }, |
| 354 | { 0x10C00, HB_SCRIPT_OLD_TURKIC }, |
| 355 | { 0x0800, HB_SCRIPT_SAMARITAN }, |
| 356 | { 0x1A20, HB_SCRIPT_TAI_THAM }, |
| 357 | { 0xAA80, HB_SCRIPT_TAI_VIET }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 358 | |
| 359 | /* Unicode-6.0 additions */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 360 | { 0x1BC0, HB_SCRIPT_BATAK }, |
| 361 | { 0x11000, HB_SCRIPT_BRAHMI }, |
| 362 | { 0x0840, HB_SCRIPT_MANDAIC }, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 363 | |
| 364 | /* Unicode-5.2 character additions */ |
Behdad Esfahbod | 208c2c3 | 2011-05-01 20:04:01 -0400 | [diff] [blame] | 365 | { 0x1CED, HB_SCRIPT_INHERITED }, |
| 366 | { 0x1400, HB_SCRIPT_CANADIAN_ABORIGINAL }, |
| 367 | |
| 368 | { 0x111111, HB_SCRIPT_UNKNOWN } |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 369 | }; |
| 370 | |
| 371 | |
| 372 | typedef unsigned int (*get_func_t) (hb_unicode_funcs_t *ufuncs, |
| 373 | hb_codepoint_t unicode, |
| 374 | void *user_data); |
| 375 | typedef unsigned int (*func_setter_func_t) (hb_unicode_funcs_t *ufuncs, |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 376 | get_func_t func, |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 377 | void *user_data, |
| 378 | hb_destroy_func_t destroy); |
| 379 | typedef unsigned int (*getter_func_t) (hb_unicode_funcs_t *ufuncs, |
| 380 | hb_codepoint_t unicode); |
| 381 | |
| 382 | typedef struct { |
| 383 | const char *name; |
| 384 | func_setter_func_t func_setter; |
| 385 | getter_func_t getter; |
| 386 | const test_pair_t *tests; |
| 387 | unsigned int num_tests; |
| 388 | const test_pair_t *tests_more; |
| 389 | unsigned int num_tests_more; |
| 390 | unsigned int default_value; |
| 391 | } property_t; |
| 392 | |
| 393 | #define RETURNS_UNICODE_ITSELF ((unsigned int) -1) |
| 394 | |
| 395 | #define PROPERTY(name, DEFAULT) \ |
| 396 | { \ |
| 397 | #name, \ |
| 398 | (func_setter_func_t) hb_unicode_funcs_set_##name##_func, \ |
Behdad Esfahbod | c464172 | 2011-07-07 23:47:19 -0400 | [diff] [blame] | 399 | (getter_func_t) hb_unicode_##name, \ |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 400 | name##_tests, \ |
| 401 | G_N_ELEMENTS (name##_tests), \ |
| 402 | name##_tests_more, \ |
| 403 | G_N_ELEMENTS (name##_tests_more), \ |
| 404 | DEFAULT \ |
| 405 | } |
| 406 | static const property_t properties[] = |
| 407 | { |
| 408 | PROPERTY (combining_class, 0), |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 409 | PROPERTY (general_category, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER), |
| 410 | PROPERTY (mirroring, RETURNS_UNICODE_ITSELF), |
Behdad Esfahbod | cd361ec | 2011-05-02 16:54:05 -0400 | [diff] [blame] | 411 | PROPERTY (script, (unsigned int) HB_SCRIPT_UNKNOWN) |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 412 | }; |
| 413 | #undef PROPERTY |
| 414 | |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 415 | static void |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 416 | test_unicode_properties (gconstpointer user_data) |
| 417 | { |
| 418 | hb_unicode_funcs_t *uf = (hb_unicode_funcs_t *) user_data; |
| 419 | unsigned int i, j; |
Behdad Esfahbod | e74b5b3 | 2011-05-02 14:03:55 -0400 | [diff] [blame] | 420 | gboolean failed = TRUE; |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 421 | |
| 422 | g_assert (hb_unicode_funcs_is_immutable (uf)); |
Behdad Esfahbod | 7aa12eb | 2011-05-11 11:55:11 -0400 | [diff] [blame] | 423 | g_assert (hb_unicode_funcs_get_parent (uf)); |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 424 | |
| 425 | for (i = 0; i < G_N_ELEMENTS (properties); i++) { |
| 426 | const property_t *p = &properties[i]; |
| 427 | const test_pair_t *tests; |
| 428 | |
Behdad Esfahbod | e8e29c7 | 2011-05-02 12:06:18 -0400 | [diff] [blame] | 429 | g_test_message ("Testing property %s", p->name); |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 430 | tests = p->tests; |
Behdad Esfahbod | e8e29c7 | 2011-05-02 12:06:18 -0400 | [diff] [blame] | 431 | for (j = 0; j < p->num_tests; j++) { |
| 432 | g_test_message ("Test %s #%d: U+%04X", p->name, j, tests[j].unicode); |
| 433 | g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, tests[j].value); |
| 434 | } |
Behdad Esfahbod | e74b5b3 | 2011-05-02 14:03:55 -0400 | [diff] [blame] | 435 | /* These tests are from Unicode 5.2 onward and older glib/ICU |
| 436 | * don't get them right. Just warn instead of assert. */ |
| 437 | tests = p->tests_more; |
| 438 | for (j = 0; j < p->num_tests_more; j++) { |
| 439 | g_test_message ("Test %s more #%d: U+%04X", p->name, j, tests[j].unicode); |
| 440 | if (p->getter (uf, tests[j].unicode) != tests[j].value) { |
| 441 | g_test_message ("Soft fail: Received %x, expected %x", p->getter (uf, tests[j].unicode), tests[j].value); |
| 442 | failed = TRUE; |
| 443 | } |
| 444 | } |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 445 | } |
Behdad Esfahbod | e74b5b3 | 2011-05-02 14:03:55 -0400 | [diff] [blame] | 446 | |
| 447 | if (failed) |
Behdad Esfahbod | 07e2277 | 2011-05-02 14:58:04 -0400 | [diff] [blame] | 448 | g_test_message ("Some property tests failed. You probably have an old version of one of the libraries used."); |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | static hb_codepoint_t |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 452 | default_value (hb_codepoint_t _default_value, hb_codepoint_t unicode) |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 453 | { |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 454 | return _default_value == RETURNS_UNICODE_ITSELF ? unicode : _default_value; |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static void |
Behdad Esfahbod | 7cda659 | 2011-05-02 14:33:53 -0400 | [diff] [blame] | 458 | _test_unicode_properties_nil (hb_unicode_funcs_t *uf) |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 459 | { |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 460 | unsigned int i, j; |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 461 | |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 462 | for (i = 0; i < G_N_ELEMENTS (properties); i++) { |
| 463 | const property_t *p = &properties[i]; |
| 464 | const test_pair_t *tests; |
| 465 | |
Behdad Esfahbod | 819e9d9 | 2011-05-02 12:38:54 -0400 | [diff] [blame] | 466 | g_test_message ("Testing property %s", p->name); |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 467 | tests = p->tests; |
Behdad Esfahbod | 819e9d9 | 2011-05-02 12:38:54 -0400 | [diff] [blame] | 468 | for (j = 0; j < p->num_tests; j++) { |
| 469 | g_test_message ("Test %s #%d: U+%04X", p->name, j, tests[j].unicode); |
Behdad Esfahbod | e8e29c7 | 2011-05-02 12:06:18 -0400 | [diff] [blame] | 470 | g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode)); |
Behdad Esfahbod | 819e9d9 | 2011-05-02 12:38:54 -0400 | [diff] [blame] | 471 | } |
Behdad Esfahbod | e74b5b3 | 2011-05-02 14:03:55 -0400 | [diff] [blame] | 472 | tests = p->tests_more; |
| 473 | for (j = 0; j < p->num_tests_more; j++) { |
| 474 | g_test_message ("Test %s more #%d: U+%04X", p->name, j, tests[j].unicode); |
| 475 | g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode)); |
| 476 | } |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 477 | } |
Behdad Esfahbod | 7cda659 | 2011-05-02 14:33:53 -0400 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | static void |
| 481 | test_unicode_properties_nil (void) |
| 482 | { |
| 483 | hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL); |
| 484 | |
| 485 | g_assert (!hb_unicode_funcs_is_immutable (uf)); |
| 486 | _test_unicode_properties_nil (uf); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 487 | |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 488 | hb_unicode_funcs_destroy (uf); |
| 489 | } |
| 490 | |
Behdad Esfahbod | b8477e1 | 2011-05-11 21:12:44 -0400 | [diff] [blame] | 491 | static void |
| 492 | test_unicode_properties_empty (void) |
| 493 | { |
| 494 | hb_unicode_funcs_t *uf = hb_unicode_funcs_get_empty (); |
| 495 | |
Behdad Esfahbod | da603e8 | 2011-05-11 22:52:35 -0400 | [diff] [blame] | 496 | g_assert (uf); |
Behdad Esfahbod | b8477e1 | 2011-05-11 21:12:44 -0400 | [diff] [blame] | 497 | g_assert (hb_unicode_funcs_is_immutable (uf)); |
| 498 | _test_unicode_properties_nil (uf); |
| 499 | } |
| 500 | |
Behdad Esfahbod | 7cda659 | 2011-05-02 14:33:53 -0400 | [diff] [blame] | 501 | |
| 502 | static void |
| 503 | test_unicode_chainup (void) |
| 504 | { |
| 505 | hb_unicode_funcs_t *uf, *uf2; |
| 506 | |
| 507 | /* Chain-up to nil */ |
| 508 | |
| 509 | uf = hb_unicode_funcs_create (NULL); |
| 510 | g_assert (!hb_unicode_funcs_is_immutable (uf)); |
| 511 | |
| 512 | uf2 = hb_unicode_funcs_create (uf); |
| 513 | g_assert (hb_unicode_funcs_is_immutable (uf)); |
| 514 | hb_unicode_funcs_destroy (uf); |
| 515 | |
| 516 | g_assert (!hb_unicode_funcs_is_immutable (uf2)); |
| 517 | _test_unicode_properties_nil (uf2); |
| 518 | |
| 519 | hb_unicode_funcs_destroy (uf2); |
| 520 | |
| 521 | /* Chain-up to default */ |
| 522 | |
| 523 | uf = hb_unicode_funcs_create (hb_unicode_funcs_get_default ()); |
| 524 | g_assert (!hb_unicode_funcs_is_immutable (uf)); |
| 525 | |
| 526 | uf2 = hb_unicode_funcs_create (uf); |
| 527 | g_assert (hb_unicode_funcs_is_immutable (uf)); |
| 528 | hb_unicode_funcs_destroy (uf); |
| 529 | |
| 530 | g_assert (!hb_unicode_funcs_is_immutable (uf2)); |
| 531 | hb_unicode_funcs_make_immutable (uf2); |
| 532 | test_unicode_properties (uf2); |
| 533 | |
| 534 | hb_unicode_funcs_destroy (uf2); |
| 535 | |
| 536 | } |
| 537 | |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 538 | static void |
| 539 | test_unicode_setters (void) |
| 540 | { |
| 541 | hb_unicode_funcs_t *uf; |
| 542 | unsigned int i; |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 543 | |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 544 | /* This is cruel: we use script-returning functions to test all properties, |
| 545 | * but it works. */ |
| 546 | |
| 547 | for (i = 0; i < G_N_ELEMENTS (properties); i++) { |
| 548 | const property_t *p = &properties[i]; |
| 549 | data_t data[2] = {{MAGIC0, FALSE}, {MAGIC1, FALSE}}; |
| 550 | |
| 551 | g_test_message ("Testing property %s", p->name); |
| 552 | |
| 553 | uf = hb_unicode_funcs_create (NULL); |
| 554 | g_assert (!hb_unicode_funcs_is_immutable (uf)); |
| 555 | |
| 556 | p->func_setter (uf, (get_func_t) simple_get_script, &data[0], free_up); |
| 557 | |
| 558 | g_assert_cmphex (p->getter (uf, 'a'), ==, HB_SCRIPT_LATIN); |
| 559 | g_assert_cmphex (p->getter (uf, '0'), ==, HB_SCRIPT_UNKNOWN); |
| 560 | |
Behdad Esfahbod | 7aa12eb | 2011-05-11 11:55:11 -0400 | [diff] [blame] | 561 | p->func_setter (uf, (get_func_t) NULL, NULL, NULL); |
| 562 | g_assert (data[0].freed && !data[1].freed); |
| 563 | |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 564 | g_assert (!hb_unicode_funcs_is_immutable (uf)); |
| 565 | hb_unicode_funcs_make_immutable (uf); |
| 566 | g_assert (hb_unicode_funcs_is_immutable (uf)); |
| 567 | |
| 568 | /* Since uf is immutable now, the following setter should do nothing. */ |
| 569 | p->func_setter (uf, (get_func_t) a_is_for_arabic_get_script, &data[1], free_up); |
| 570 | |
Behdad Esfahbod | 7aa12eb | 2011-05-11 11:55:11 -0400 | [diff] [blame] | 571 | g_assert (data[0].freed && !data[1].freed); |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 572 | hb_unicode_funcs_destroy (uf); |
| 573 | g_assert (data[0].freed && !data[1].freed); |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
| 577 | |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 578 | |
| 579 | typedef struct { |
| 580 | data_t data[2]; |
| 581 | } data_fixture_t; |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 582 | |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 583 | static void |
Behdad Esfahbod | dcfcb95 | 2018-09-30 18:14:50 +0200 | [diff] [blame] | 584 | data_fixture_init (data_fixture_t *f, gconstpointer user_data HB_UNUSED) |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 585 | { |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 586 | f->data[0].value = MAGIC0; |
| 587 | f->data[1].value = MAGIC1; |
| 588 | } |
| 589 | static void |
Behdad Esfahbod | dcfcb95 | 2018-09-30 18:14:50 +0200 | [diff] [blame] | 590 | data_fixture_finish (data_fixture_t *f HB_UNUSED, gconstpointer user_data HB_UNUSED) |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 591 | { |
| 592 | } |
| 593 | |
Behdad Esfahbod | da96ee0 | 2011-04-29 12:17:09 -0400 | [diff] [blame] | 594 | static void |
Behdad Esfahbod | dcfcb95 | 2018-09-30 18:14:50 +0200 | [diff] [blame] | 595 | test_unicode_subclassing_nil (data_fixture_t *f, gconstpointer user_data HB_UNUSED) |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 596 | { |
Behdad Esfahbod | fb194b8 | 2011-04-20 02:00:47 -0400 | [diff] [blame] | 597 | hb_unicode_funcs_t *uf, *aa; |
| 598 | |
| 599 | uf = hb_unicode_funcs_create (NULL); |
Behdad Esfahbod | fb194b8 | 2011-04-20 02:00:47 -0400 | [diff] [blame] | 600 | |
| 601 | aa = hb_unicode_funcs_create (uf); |
Behdad Esfahbod | fb194b8 | 2011-04-20 02:00:47 -0400 | [diff] [blame] | 602 | |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 603 | hb_unicode_funcs_destroy (uf); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 604 | |
| 605 | hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script, |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 606 | &f->data[1], free_up); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 607 | |
Behdad Esfahbod | c464172 | 2011-07-07 23:47:19 -0400 | [diff] [blame] | 608 | g_assert_cmphex (hb_unicode_script (aa, 'a'), ==, HB_SCRIPT_ARABIC); |
| 609 | g_assert_cmphex (hb_unicode_script (aa, 'b'), ==, HB_SCRIPT_UNKNOWN); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 610 | |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 611 | g_assert (!f->data[0].freed && !f->data[1].freed); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 612 | hb_unicode_funcs_destroy (aa); |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 613 | g_assert (!f->data[0].freed && f->data[1].freed); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static void |
Behdad Esfahbod | dcfcb95 | 2018-09-30 18:14:50 +0200 | [diff] [blame] | 617 | test_unicode_subclassing_default (data_fixture_t *f, gconstpointer user_data HB_UNUSED) |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 618 | { |
Behdad Esfahbod | fb194b8 | 2011-04-20 02:00:47 -0400 | [diff] [blame] | 619 | hb_unicode_funcs_t *uf, *aa; |
| 620 | |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 621 | uf = hb_unicode_funcs_get_default (); |
Behdad Esfahbod | fb194b8 | 2011-04-20 02:00:47 -0400 | [diff] [blame] | 622 | aa = hb_unicode_funcs_create (uf); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 623 | |
| 624 | hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script, |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 625 | &f->data[1], free_up); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 626 | |
Behdad Esfahbod | c464172 | 2011-07-07 23:47:19 -0400 | [diff] [blame] | 627 | g_assert_cmphex (hb_unicode_script (aa, 'a'), ==, HB_SCRIPT_ARABIC); |
| 628 | g_assert_cmphex (hb_unicode_script (aa, 'b'), ==, HB_SCRIPT_LATIN); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 629 | |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 630 | g_assert (!f->data[0].freed && !f->data[1].freed); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 631 | hb_unicode_funcs_destroy (aa); |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 632 | g_assert (!f->data[0].freed && f->data[1].freed); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | static void |
Behdad Esfahbod | dcfcb95 | 2018-09-30 18:14:50 +0200 | [diff] [blame] | 636 | test_unicode_subclassing_deep (data_fixture_t *f, gconstpointer user_data HB_UNUSED) |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 637 | { |
Behdad Esfahbod | fb194b8 | 2011-04-20 02:00:47 -0400 | [diff] [blame] | 638 | hb_unicode_funcs_t *uf, *aa; |
| 639 | |
| 640 | uf = hb_unicode_funcs_create (NULL); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 641 | |
| 642 | hb_unicode_funcs_set_script_func (uf, simple_get_script, |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 643 | &f->data[0], free_up); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 644 | |
Behdad Esfahbod | fb194b8 | 2011-04-20 02:00:47 -0400 | [diff] [blame] | 645 | aa = hb_unicode_funcs_create (uf); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 646 | |
| 647 | hb_unicode_funcs_destroy (uf); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 648 | |
| 649 | /* make sure the 'uf' didn't get freed, since 'aa' holds a ref */ |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 650 | g_assert (!f->data[0].freed); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 651 | |
| 652 | hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script, |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 653 | &f->data[1], free_up); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 654 | |
Behdad Esfahbod | c464172 | 2011-07-07 23:47:19 -0400 | [diff] [blame] | 655 | g_assert_cmphex (hb_unicode_script (aa, 'a'), ==, HB_SCRIPT_ARABIC); |
| 656 | g_assert_cmphex (hb_unicode_script (aa, 'b'), ==, HB_SCRIPT_LATIN); |
| 657 | g_assert_cmphex (hb_unicode_script (aa, '0'), ==, HB_SCRIPT_UNKNOWN); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 658 | |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 659 | g_assert (!f->data[0].freed && !f->data[1].freed); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 660 | hb_unicode_funcs_destroy (aa); |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 661 | g_assert (f->data[0].freed && f->data[1].freed); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 662 | } |
| 663 | |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 664 | |
Behdad Esfahbod | 07e2277 | 2011-05-02 14:58:04 -0400 | [diff] [blame] | 665 | static hb_script_t |
| 666 | script_roundtrip_default (hb_script_t script) |
| 667 | { |
| 668 | return hb_script_from_iso15924_tag (hb_script_to_iso15924_tag (script)); |
| 669 | } |
| 670 | |
| 671 | #ifdef HAVE_GLIB |
| 672 | static hb_script_t |
| 673 | script_roundtrip_glib (hb_script_t script) |
| 674 | { |
| 675 | return hb_glib_script_to_script (hb_glib_script_from_script (script)); |
| 676 | } |
| 677 | #endif |
| 678 | |
| 679 | #ifdef HAVE_ICU |
| 680 | static hb_script_t |
| 681 | script_roundtrip_icu (hb_script_t script) |
| 682 | { |
| 683 | return hb_icu_script_to_script (hb_icu_script_from_script (script)); |
| 684 | } |
| 685 | #endif |
| 686 | |
| 687 | static void |
| 688 | test_unicode_script_roundtrip (gconstpointer user_data) |
| 689 | { |
| 690 | typedef hb_script_t (*roundtrip_func_t) (hb_script_t); |
| 691 | roundtrip_func_t roundtrip_func = (roundtrip_func_t) user_data; |
| 692 | unsigned int i; |
| 693 | gboolean failed = FALSE; |
| 694 | |
| 695 | for (i = 0; i < G_N_ELEMENTS (script_tests); i++) { |
| 696 | const test_pair_t *test = &script_tests[i]; |
| 697 | hb_script_t script = test->value; |
| 698 | |
| 699 | g_test_message ("Test script roundtrip #%d: %x", i, script); |
| 700 | g_assert_cmphex (script, ==, roundtrip_func (script)); |
| 701 | } |
| 702 | for (i = 0; i < G_N_ELEMENTS (script_tests_more); i++) { |
| 703 | const test_pair_t *test = &script_tests_more[i]; |
| 704 | hb_script_t script = test->value; |
| 705 | |
| 706 | g_test_message ("Test script roundtrip more #%d: %x", i, script); |
| 707 | if (script != roundtrip_func (script)) { |
| 708 | g_test_message ("Soft fail: Received %x, expected %x", roundtrip_func (script), script); |
| 709 | failed = TRUE; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | g_assert_cmphex (HB_SCRIPT_INVALID, ==, roundtrip_func (HB_SCRIPT_INVALID)); |
| 714 | |
| 715 | if (failed) |
| 716 | g_test_message ("Some script roundtrip tests failed. You probably have an old version of one of the libraries used."); |
| 717 | } |
| 718 | |
| 719 | |
Behdad Esfahbod | ffd4a43 | 2011-07-20 22:30:29 -0400 | [diff] [blame] | 720 | static void |
| 721 | test_unicode_normalization (gconstpointer user_data) |
| 722 | { |
| 723 | hb_unicode_funcs_t *uf = (hb_unicode_funcs_t *) user_data; |
| 724 | gunichar a, b, ab; |
| 725 | |
| 726 | |
| 727 | /* Test compose() */ |
| 728 | |
| 729 | /* Not composable */ |
| 730 | g_assert (!hb_unicode_compose (uf, 0x0041, 0x0042, &ab) && ab == 0); |
| 731 | g_assert (!hb_unicode_compose (uf, 0x0041, 0, &ab) && ab == 0); |
| 732 | g_assert (!hb_unicode_compose (uf, 0x0066, 0x0069, &ab) && ab == 0); |
| 733 | |
| 734 | /* Singletons should not compose */ |
| 735 | g_assert (!hb_unicode_compose (uf, 0x212B, 0, &ab) && ab == 0); |
| 736 | g_assert (!hb_unicode_compose (uf, 0x00C5, 0, &ab) && ab == 0); |
| 737 | g_assert (!hb_unicode_compose (uf, 0x2126, 0, &ab) && ab == 0); |
| 738 | g_assert (!hb_unicode_compose (uf, 0x03A9, 0, &ab) && ab == 0); |
| 739 | |
Behdad Esfahbod | 63c0ef4 | 2011-07-21 20:58:42 -0400 | [diff] [blame] | 740 | /* Non-starter pairs should not compose */ |
| 741 | g_assert (!hb_unicode_compose (uf, 0x0308, 0x0301, &ab) && ab == 0); /* !0x0344 */ |
| 742 | g_assert (!hb_unicode_compose (uf, 0x0F71, 0x0F72, &ab) && ab == 0); /* !0x0F73 */ |
| 743 | |
Behdad Esfahbod | ffd4a43 | 2011-07-20 22:30:29 -0400 | [diff] [blame] | 744 | /* Pairs */ |
| 745 | g_assert (hb_unicode_compose (uf, 0x0041, 0x030A, &ab) && ab == 0x00C5); |
| 746 | g_assert (hb_unicode_compose (uf, 0x006F, 0x0302, &ab) && ab == 0x00F4); |
| 747 | g_assert (hb_unicode_compose (uf, 0x1E63, 0x0307, &ab) && ab == 0x1E69); |
| 748 | g_assert (hb_unicode_compose (uf, 0x0073, 0x0323, &ab) && ab == 0x1E63); |
| 749 | g_assert (hb_unicode_compose (uf, 0x0064, 0x0307, &ab) && ab == 0x1E0B); |
| 750 | g_assert (hb_unicode_compose (uf, 0x0064, 0x0323, &ab) && ab == 0x1E0D); |
| 751 | |
| 752 | /* Hangul */ |
| 753 | g_assert (hb_unicode_compose (uf, 0xD4CC, 0x11B6, &ab) && ab == 0xD4DB); |
| 754 | g_assert (hb_unicode_compose (uf, 0x1111, 0x1171, &ab) && ab == 0xD4CC); |
| 755 | g_assert (hb_unicode_compose (uf, 0xCE20, 0x11B8, &ab) && ab == 0xCE31); |
| 756 | g_assert (hb_unicode_compose (uf, 0x110E, 0x1173, &ab) && ab == 0xCE20); |
| 757 | |
| 758 | |
| 759 | /* Test decompose() */ |
| 760 | |
| 761 | /* Not decomposable */ |
| 762 | g_assert (!hb_unicode_decompose (uf, 0x0041, &a, &b) && a == 0x0041 && b == 0); |
| 763 | g_assert (!hb_unicode_decompose (uf, 0xFB01, &a, &b) && a == 0xFB01 && b == 0); |
Behdad Esfahbod | 055fb24 | 2012-01-18 21:58:34 -0500 | [diff] [blame] | 764 | g_assert (!hb_unicode_decompose (uf, 0x1F1EF, &a, &b) && a == 0x1F1EF && b == 0); |
Behdad Esfahbod | ffd4a43 | 2011-07-20 22:30:29 -0400 | [diff] [blame] | 765 | |
| 766 | /* Singletons */ |
Behdad Esfahbod | ffd4a43 | 2011-07-20 22:30:29 -0400 | [diff] [blame] | 767 | g_assert (hb_unicode_decompose (uf, 0x212B, &a, &b) && a == 0x00C5 && b == 0); |
| 768 | g_assert (hb_unicode_decompose (uf, 0x2126, &a, &b) && a == 0x03A9 && b == 0); |
| 769 | |
Behdad Esfahbod | 63c0ef4 | 2011-07-21 20:58:42 -0400 | [diff] [blame] | 770 | /* Non-starter pairs decompose, but not compose */ |
| 771 | g_assert (hb_unicode_decompose (uf, 0x0344, &a, &b) && a == 0x0308 && b == 0x0301); |
| 772 | g_assert (hb_unicode_decompose (uf, 0x0F73, &a, &b) && a == 0x0F71 && b == 0x0F72); |
| 773 | |
Behdad Esfahbod | ffd4a43 | 2011-07-20 22:30:29 -0400 | [diff] [blame] | 774 | /* Pairs */ |
| 775 | g_assert (hb_unicode_decompose (uf, 0x00C5, &a, &b) && a == 0x0041 && b == 0x030A); |
| 776 | g_assert (hb_unicode_decompose (uf, 0x00F4, &a, &b) && a == 0x006F && b == 0x0302); |
| 777 | g_assert (hb_unicode_decompose (uf, 0x1E69, &a, &b) && a == 0x1E63 && b == 0x0307); |
| 778 | g_assert (hb_unicode_decompose (uf, 0x1E63, &a, &b) && a == 0x0073 && b == 0x0323); |
| 779 | g_assert (hb_unicode_decompose (uf, 0x1E0B, &a, &b) && a == 0x0064 && b == 0x0307); |
| 780 | g_assert (hb_unicode_decompose (uf, 0x1E0D, &a, &b) && a == 0x0064 && b == 0x0323); |
| 781 | |
| 782 | /* Hangul */ |
| 783 | g_assert (hb_unicode_decompose (uf, 0xD4DB, &a, &b) && a == 0xD4CC && b == 0x11B6); |
| 784 | g_assert (hb_unicode_decompose (uf, 0xD4CC, &a, &b) && a == 0x1111 && b == 0x1171); |
| 785 | g_assert (hb_unicode_decompose (uf, 0xCE31, &a, &b) && a == 0xCE20 && b == 0x11B8); |
| 786 | g_assert (hb_unicode_decompose (uf, 0xCE20, &a, &b) && a == 0x110E && b == 0x1173); |
Behdad Esfahbod | ffd4a43 | 2011-07-20 22:30:29 -0400 | [diff] [blame] | 787 | } |
| 788 | |
Behdad Esfahbod | c464172 | 2011-07-07 23:47:19 -0400 | [diff] [blame] | 789 | |
| 790 | |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 791 | int |
| 792 | main (int argc, char **argv) |
| 793 | { |
Behdad Esfahbod | aafe395 | 2011-04-28 17:10:44 -0400 | [diff] [blame] | 794 | hb_test_init (&argc, &argv); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 795 | |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 796 | hb_test_add (test_unicode_properties_nil); |
Behdad Esfahbod | b8477e1 | 2011-05-11 21:12:44 -0400 | [diff] [blame] | 797 | hb_test_add (test_unicode_properties_empty); |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 798 | |
Behdad Esfahbod | 07e2277 | 2011-05-02 14:58:04 -0400 | [diff] [blame] | 799 | hb_test_add_data_flavor (hb_unicode_funcs_get_default (), "default", test_unicode_properties); |
Behdad Esfahbod | ffd4a43 | 2011-07-20 22:30:29 -0400 | [diff] [blame] | 800 | hb_test_add_data_flavor (hb_unicode_funcs_get_default (), "default", test_unicode_normalization); |
Behdad Esfahbod | 07e2277 | 2011-05-02 14:58:04 -0400 | [diff] [blame] | 801 | hb_test_add_data_flavor ((gconstpointer) script_roundtrip_default, "default", test_unicode_script_roundtrip); |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 802 | #ifdef HAVE_GLIB |
Behdad Esfahbod | 07e2277 | 2011-05-02 14:58:04 -0400 | [diff] [blame] | 803 | hb_test_add_data_flavor (hb_glib_get_unicode_funcs (), "glib", test_unicode_properties); |
Behdad Esfahbod | ffd4a43 | 2011-07-20 22:30:29 -0400 | [diff] [blame] | 804 | hb_test_add_data_flavor (hb_glib_get_unicode_funcs (), "glib", test_unicode_normalization); |
Behdad Esfahbod | 07e2277 | 2011-05-02 14:58:04 -0400 | [diff] [blame] | 805 | hb_test_add_data_flavor ((gconstpointer) script_roundtrip_glib, "glib", test_unicode_script_roundtrip); |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 806 | #endif |
| 807 | #ifdef HAVE_ICU |
Behdad Esfahbod | 07e2277 | 2011-05-02 14:58:04 -0400 | [diff] [blame] | 808 | hb_test_add_data_flavor (hb_icu_get_unicode_funcs (), "icu", test_unicode_properties); |
Behdad Esfahbod | 498e1a9 | 2011-07-20 23:19:49 -0400 | [diff] [blame] | 809 | hb_test_add_data_flavor (hb_icu_get_unicode_funcs (), "icu", test_unicode_normalization); |
Behdad Esfahbod | 07e2277 | 2011-05-02 14:58:04 -0400 | [diff] [blame] | 810 | hb_test_add_data_flavor ((gconstpointer) script_roundtrip_icu, "icu", test_unicode_script_roundtrip); |
Behdad Esfahbod | 60833ef | 2011-04-29 16:49:57 -0400 | [diff] [blame] | 811 | #endif |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 812 | |
Behdad Esfahbod | 7cda659 | 2011-05-02 14:33:53 -0400 | [diff] [blame] | 813 | hb_test_add (test_unicode_chainup); |
| 814 | |
Behdad Esfahbod | 250c592 | 2011-05-02 14:21:30 -0400 | [diff] [blame] | 815 | hb_test_add (test_unicode_setters); |
| 816 | |
Behdad Esfahbod | 6af9cff | 2011-04-29 12:00:38 -0400 | [diff] [blame] | 817 | hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_nil); |
| 818 | hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_default); |
| 819 | hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_deep); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 820 | |
Behdad Esfahbod | aafe395 | 2011-04-28 17:10:44 -0400 | [diff] [blame] | 821 | return hb_test_run (); |
Ryan Lortie | 2fd0c57 | 2011-04-20 00:19:20 -0400 | [diff] [blame] | 822 | } |