2 * Copyright © 2011 Codethink Limited
3 * Copyright © 2011 Google, Inc.
5 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
25 * Codethink Author(s): Ryan Lortie
26 * Google Author(s): Behdad Esfahbod
31 /* Unit tests for hb-unicode.h */
42 /* Check all properties */
44 /* Some of the following tables where adapted from glib/glib/tests/utf8-misc.c.
45 * The license is compatible. */
48 hb_codepoint_t unicode;
52 static const test_pair_t combining_class_tests[] =
54 { 0x111111, (unsigned int) 0 },
56 { 0x0020, (unsigned int) 0 },
57 { 0x0334, (unsigned int) 1 },
58 { 0x093C, (unsigned int) 7 },
59 { 0x3099, (unsigned int) 8 },
60 { 0x094D, (unsigned int) 9 },
61 { 0x05B0, (unsigned int) 10 },
62 { 0x05B1, (unsigned int) 11 },
63 { 0x05B2, (unsigned int) 12 },
64 { 0x05B3, (unsigned int) 13 },
65 { 0x05B4, (unsigned int) 14 },
66 { 0x05B5, (unsigned int) 15 },
67 { 0x05B6, (unsigned int) 16 },
68 { 0x05B7, (unsigned int) 17 },
69 { 0x05B8, (unsigned int) 18 },
70 { 0x05B9, (unsigned int) 19 },
71 { 0x05BB, (unsigned int) 20 },
72 { 0x05BC, (unsigned int) 21 },
73 { 0x05BD, (unsigned int) 22 },
74 { 0x05BF, (unsigned int) 23 },
75 { 0x05C1, (unsigned int) 24 },
76 { 0x05C2, (unsigned int) 25 },
77 { 0xFB1E, (unsigned int) 26 },
78 { 0x064B, (unsigned int) 27 },
79 { 0x064C, (unsigned int) 28 },
80 { 0x064D, (unsigned int) 29 },
82 { 0x05AE, (unsigned int) 228 },
83 { 0x0300, (unsigned int) 230 },
84 { 0x302C, (unsigned int) 232 },
85 { 0x0362, (unsigned int) 233 },
86 { 0x0360, (unsigned int) 234 },
87 { 0x1DCD, (unsigned int) 234 },
88 { 0x0345, (unsigned int) 240 },
90 static const test_pair_t combining_class_tests_more[] =
92 /* Unicode-5.2 character additions */
93 { 0xA8E0, (unsigned int) 230 },
95 /* Unicode-6.0 character additions */
96 { 0x135D, (unsigned int) 230 },
99 static const test_pair_t eastasian_width_tests[] =
101 { 0x111111, (unsigned int) 1 },
104 { 0x0000, (unsigned int) 1 },
105 { 0x0483, (unsigned int) 1 },
106 { 0x0641, (unsigned int) 1 },
107 { 0xFFFC, (unsigned int) 1 },
108 { 0x10000, (unsigned int) 1 },
109 { 0xE0001, (unsigned int) 1 },
112 { 0x0020, (unsigned int) 1 },
113 { 0x0041, (unsigned int) 1 },
114 { 0x27E6, (unsigned int) 1 },
117 { 0x20A9, (unsigned int) 1 },
118 { 0xFF61, (unsigned int) 1 },
119 { 0xFF69, (unsigned int) 1 },
120 { 0xFFEE, (unsigned int) 1 },
123 { 0x00A1, (unsigned int) 1 },
124 { 0x00D8, (unsigned int) 1 },
125 { 0x02DD, (unsigned int) 1 },
126 { 0xE0100, (unsigned int) 1 },
127 { 0x100000, (unsigned int) 1 },
130 { 0x3000, (unsigned int) 2 },
131 { 0xFF60, (unsigned int) 2 },
134 { 0x2329, (unsigned int) 2 },
135 { 0x3001, (unsigned int) 2 },
136 { 0xFE69, (unsigned int) 2 },
137 { 0x30000, (unsigned int) 2 },
138 { 0x3FFFD, (unsigned int) 2 },
140 static const test_pair_t eastasian_width_tests_more[] =
142 /* Default Wide blocks */
143 { 0x4DBF, (unsigned int) 2 },
144 { 0x9FFF, (unsigned int) 2 },
145 { 0xFAFF, (unsigned int) 2 },
146 { 0x2A6DF, (unsigned int) 2 },
147 { 0x2B73F, (unsigned int) 2 },
148 { 0x2B81F, (unsigned int) 2 },
149 { 0x2FA1F, (unsigned int) 2 },
151 /* Uniode-5.2 character additions */
153 { 0x115F, (unsigned int) 2 },
155 /* Uniode-6.0 character additions */
157 { 0x2B740, (unsigned int) 2 },
158 { 0x1B000, (unsigned int) 2 },
161 static const test_pair_t general_category_tests[] =
163 { 0x111111, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED },
165 { 0x000D, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CONTROL },
166 { 0x200E, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_FORMAT },
167 { 0x0378, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED },
168 { 0xE000, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_PRIVATE_USE },
169 { 0xD800, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_SURROGATE },
170 { 0x0061, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER },
171 { 0x02B0, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER },
172 { 0x3400, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
173 { 0x01C5, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER },
174 { 0xFF21, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER },
175 { 0x0903, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_COMBINING_MARK },
176 { 0x20DD, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK },
177 { 0xA806, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK },
178 { 0xFF10, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER },
179 { 0x16EE, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_LETTER_NUMBER },
180 { 0x17F0, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_NUMBER },
181 { 0x005F, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION },
182 { 0x058A, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION },
183 { 0x0F3B, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION },
184 { 0x2019, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION },
185 { 0x2018, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION },
186 { 0x2016, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION },
187 { 0x0F3A, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION },
188 { 0x20A0, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL },
189 { 0x309B, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL },
190 { 0xFB29, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL },
191 { 0x00A6, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
192 { 0x2028, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_LINE_SEPARATOR },
193 { 0x2029, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_PARAGRAPH_SEPARATOR },
194 { 0x202F, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR }
196 static const test_pair_t general_category_tests_more[] =
198 /* Unicode-5.2 character additions */
199 { 0x1F131, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
201 /* Unicode-6.0 character additions */
202 { 0x0620, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
205 static const test_pair_t mirroring_tests[] =
207 { 0x111111, (unsigned int) 0x111111 },
209 /* Some characters that do NOT mirror */
210 { 0x0020, (unsigned int) 0x0020 },
211 { 0x0041, (unsigned int) 0x0041 },
212 { 0x00F0, (unsigned int) 0x00F0 },
213 { 0x27CC, (unsigned int) 0x27CC },
214 { 0xE01EF, (unsigned int) 0xE01EF },
215 { 0x1D7C3, (unsigned int) 0x1D7C3 },
216 { 0x100000, (unsigned int) 0x100000 },
218 /* Some characters that do mirror */
219 { 0x0029, (unsigned int) 0x0028 },
220 { 0x0028, (unsigned int) 0x0029 },
221 { 0x003E, (unsigned int) 0x003C },
222 { 0x003C, (unsigned int) 0x003E },
223 { 0x005D, (unsigned int) 0x005B },
224 { 0x005B, (unsigned int) 0x005D },
225 { 0x007D, (unsigned int) 0x007B },
226 { 0x007B, (unsigned int) 0x007D },
227 { 0x00BB, (unsigned int) 0x00AB },
228 { 0x00AB, (unsigned int) 0x00BB },
229 { 0x226B, (unsigned int) 0x226A },
230 { 0x226A, (unsigned int) 0x226B },
231 { 0x22F1, (unsigned int) 0x22F0 },
232 { 0x22F0, (unsigned int) 0x22F1 },
233 { 0xFF60, (unsigned int) 0xFF5F },
234 { 0xFF5F, (unsigned int) 0xFF60 },
235 { 0xFF63, (unsigned int) 0xFF62 },
236 { 0xFF62, (unsigned int) 0xFF63 },
238 static const test_pair_t mirroring_tests_more[] =
240 /* No new mirroring characters have been encoded in recent Unicode versions. */
241 { 0xFFFF, (unsigned int) 0xFFFF },
244 static const test_pair_t script_tests[] =
246 { 0x111111, (unsigned int) HB_SCRIPT_UNKNOWN },
248 { 0x002A, (unsigned int) HB_SCRIPT_COMMON },
249 { 0x0670, (unsigned int) HB_SCRIPT_INHERITED },
250 { 0x060D, (unsigned int) HB_SCRIPT_ARABIC },
251 { 0x0559, (unsigned int) HB_SCRIPT_ARMENIAN },
252 { 0x09CD, (unsigned int) HB_SCRIPT_BENGALI },
253 { 0x31B6, (unsigned int) HB_SCRIPT_BOPOMOFO },
254 { 0x13A2, (unsigned int) HB_SCRIPT_CHEROKEE },
255 { 0x2CFD, (unsigned int) HB_SCRIPT_COPTIC },
256 { 0x0482, (unsigned int) HB_SCRIPT_CYRILLIC },
257 { 0x10401, (unsigned int) HB_SCRIPT_DESERET },
258 { 0x094D, (unsigned int) HB_SCRIPT_DEVANAGARI },
259 { 0x1258, (unsigned int) HB_SCRIPT_ETHIOPIC },
260 { 0x10FC, (unsigned int) HB_SCRIPT_GEORGIAN },
261 { 0x10341, (unsigned int) HB_SCRIPT_GOTHIC },
262 { 0x0375, (unsigned int) HB_SCRIPT_GREEK },
263 { 0x0A83, (unsigned int) HB_SCRIPT_GUJARATI },
264 { 0x0A3C, (unsigned int) HB_SCRIPT_GURMUKHI },
265 { 0x3005, (unsigned int) HB_SCRIPT_HAN },
266 { 0x1100, (unsigned int) HB_SCRIPT_HANGUL },
267 { 0x05BF, (unsigned int) HB_SCRIPT_HEBREW },
268 { 0x309F, (unsigned int) HB_SCRIPT_HIRAGANA },
269 { 0x0CBC, (unsigned int) HB_SCRIPT_KANNADA },
270 { 0x30FF, (unsigned int) HB_SCRIPT_KATAKANA },
271 { 0x17DD, (unsigned int) HB_SCRIPT_KHMER },
272 { 0x0EDD, (unsigned int) HB_SCRIPT_LAO },
273 { 0x0061, (unsigned int) HB_SCRIPT_LATIN },
274 { 0x0D3D, (unsigned int) HB_SCRIPT_MALAYALAM },
275 { 0x1843, (unsigned int) HB_SCRIPT_MONGOLIAN },
276 { 0x1031, (unsigned int) HB_SCRIPT_MYANMAR },
277 { 0x169C, (unsigned int) HB_SCRIPT_OGHAM },
278 { 0x10322, (unsigned int) HB_SCRIPT_OLD_ITALIC },
279 { 0x0B3C, (unsigned int) HB_SCRIPT_ORIYA },
280 { 0x16EF, (unsigned int) HB_SCRIPT_RUNIC },
281 { 0x0DBD, (unsigned int) HB_SCRIPT_SINHALA },
282 { 0x0711, (unsigned int) HB_SCRIPT_SYRIAC },
283 { 0x0B82, (unsigned int) HB_SCRIPT_TAMIL },
284 { 0x0C03, (unsigned int) HB_SCRIPT_TELUGU },
285 { 0x07B1, (unsigned int) HB_SCRIPT_THAANA },
286 { 0x0E31, (unsigned int) HB_SCRIPT_THAI },
287 { 0x0FD4, (unsigned int) HB_SCRIPT_TIBETAN },
288 { 0x1401, (unsigned int) HB_SCRIPT_CANADIAN_ABORIGINAL },
289 { 0xA015, (unsigned int) HB_SCRIPT_YI },
290 { 0x1700, (unsigned int) HB_SCRIPT_TAGALOG },
291 { 0x1720, (unsigned int) HB_SCRIPT_HANUNOO },
292 { 0x1740, (unsigned int) HB_SCRIPT_BUHID },
293 { 0x1760, (unsigned int) HB_SCRIPT_TAGBANWA },
295 /* Unicode-4.0 additions */
296 { 0x2800, (unsigned int) HB_SCRIPT_BRAILLE },
297 { 0x10808, (unsigned int) HB_SCRIPT_CYPRIOT },
298 { 0x1932, (unsigned int) HB_SCRIPT_LIMBU },
299 { 0x10480, (unsigned int) HB_SCRIPT_OSMANYA },
300 { 0x10450, (unsigned int) HB_SCRIPT_SHAVIAN },
301 { 0x10000, (unsigned int) HB_SCRIPT_LINEAR_B },
302 { 0x1950, (unsigned int) HB_SCRIPT_TAI_LE },
303 { 0x1039F, (unsigned int) HB_SCRIPT_UGARITIC },
305 /* Unicode-4.1 additions */
306 { 0x1980, (unsigned int) HB_SCRIPT_NEW_TAI_LUE },
307 { 0x1A1F, (unsigned int) HB_SCRIPT_BUGINESE },
308 { 0x2C00, (unsigned int) HB_SCRIPT_GLAGOLITIC },
309 { 0x2D6F, (unsigned int) HB_SCRIPT_TIFINAGH },
310 { 0xA800, (unsigned int) HB_SCRIPT_SYLOTI_NAGRI },
311 { 0x103D0, (unsigned int) HB_SCRIPT_OLD_PERSIAN },
312 { 0x10A3F, (unsigned int) HB_SCRIPT_KHAROSHTHI },
314 /* Unicode-5.0 additions */
315 { 0x0378, (unsigned int) HB_SCRIPT_UNKNOWN },
316 { 0x1B04, (unsigned int) HB_SCRIPT_BALINESE },
317 { 0x12000, (unsigned int) HB_SCRIPT_CUNEIFORM },
318 { 0x10900, (unsigned int) HB_SCRIPT_PHOENICIAN },
319 { 0xA840, (unsigned int) HB_SCRIPT_PHAGS_PA },
320 { 0x07C0, (unsigned int) HB_SCRIPT_NKO },
322 /* Unicode-5.1 additions */
323 { 0xA900, (unsigned int) HB_SCRIPT_KAYAH_LI },
324 { 0x1C00, (unsigned int) HB_SCRIPT_LEPCHA },
325 { 0xA930, (unsigned int) HB_SCRIPT_REJANG },
326 { 0x1B80, (unsigned int) HB_SCRIPT_SUNDANESE },
327 { 0xA880, (unsigned int) HB_SCRIPT_SAURASHTRA },
328 { 0xAA00, (unsigned int) HB_SCRIPT_CHAM },
329 { 0x1C50, (unsigned int) HB_SCRIPT_OL_CHIKI },
330 { 0xA500, (unsigned int) HB_SCRIPT_VAI },
331 { 0x102A0, (unsigned int) HB_SCRIPT_CARIAN },
332 { 0x10280, (unsigned int) HB_SCRIPT_LYCIAN },
333 { 0x1093F, (unsigned int) HB_SCRIPT_LYDIAN },
335 static const test_pair_t script_tests_more[] =
337 /* Unicode-5.2 additions */
338 { 0x10B00, (unsigned int) HB_SCRIPT_AVESTAN },
339 { 0xA6A0, (unsigned int) HB_SCRIPT_BAMUM },
340 { 0x13000, (unsigned int) HB_SCRIPT_EGYPTIAN_HIEROGLYPHS },
341 { 0x10840, (unsigned int) HB_SCRIPT_IMPERIAL_ARAMAIC },
342 { 0x10B60, (unsigned int) HB_SCRIPT_INSCRIPTIONAL_PAHLAVI },
343 { 0x10B40, (unsigned int) HB_SCRIPT_INSCRIPTIONAL_PARTHIAN },
344 { 0xA980, (unsigned int) HB_SCRIPT_JAVANESE },
345 { 0x11082, (unsigned int) HB_SCRIPT_KAITHI },
346 { 0xA4D0, (unsigned int) HB_SCRIPT_LISU },
347 { 0xABE5, (unsigned int) HB_SCRIPT_MEETEI_MAYEK },
348 { 0x10A60, (unsigned int) HB_SCRIPT_OLD_SOUTH_ARABIAN },
349 { 0x10C00, (unsigned int) HB_SCRIPT_OLD_TURKIC },
350 { 0x0800, (unsigned int) HB_SCRIPT_SAMARITAN },
351 { 0x1A20, (unsigned int) HB_SCRIPT_TAI_THAM },
352 { 0xAA80, (unsigned int) HB_SCRIPT_TAI_VIET },
354 /* Unicode-6.0 additions */
355 { 0x1BC0, (unsigned int) HB_SCRIPT_BATAK },
356 { 0x11000, (unsigned int) HB_SCRIPT_BRAHMI },
357 { 0x0840, (unsigned int) HB_SCRIPT_MANDAIC },
359 /* Unicode-5.2 character additions */
360 { 0x1CED, (unsigned int) HB_SCRIPT_INHERITED },
361 { 0x1400, (unsigned int) HB_SCRIPT_CANADIAN_ABORIGINAL },
365 typedef unsigned int (*get_func_t) (hb_unicode_funcs_t *ufuncs,
366 hb_codepoint_t unicode,
368 typedef unsigned int (*func_setter_func_t) (hb_unicode_funcs_t *ufuncs,
371 hb_destroy_func_t destroy);
372 typedef unsigned int (*getter_func_t) (hb_unicode_funcs_t *ufuncs,
373 hb_codepoint_t unicode);
377 func_setter_func_t func_setter;
378 getter_func_t getter;
379 const test_pair_t *tests;
380 unsigned int num_tests;
381 const test_pair_t *tests_more;
382 unsigned int num_tests_more;
383 unsigned int default_value;
386 #define RETURNS_UNICODE_ITSELF ((unsigned int) -1)
388 #define PROPERTY(name, DEFAULT) \
391 (func_setter_func_t) hb_unicode_funcs_set_##name##_func, \
392 (getter_func_t) hb_unicode_get_##name, \
394 G_N_ELEMENTS (name##_tests), \
396 G_N_ELEMENTS (name##_tests_more), \
399 static const property_t properties[] =
401 PROPERTY (combining_class, 0),
402 PROPERTY (eastasian_width, 1),
403 PROPERTY (general_category, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER),
404 PROPERTY (mirroring, RETURNS_UNICODE_ITSELF),
405 PROPERTY (script, (unsigned int) HB_SCRIPT_UNKNOWN),
410 test_unicode_properties (gconstpointer user_data)
412 hb_unicode_funcs_t *uf = (hb_unicode_funcs_t *) user_data;
415 g_assert (hb_unicode_funcs_is_immutable (uf));
417 for (i = 0; i < G_N_ELEMENTS (properties); i++) {
418 const property_t *p = &properties[i];
419 const test_pair_t *tests;
422 for (j = 0; j < p->num_tests; j++)
423 g_assert_cmpint (p->getter (uf, tests[j].unicode), ==, tests[j].value);
427 static hb_codepoint_t
428 default_value (hb_codepoint_t default_value, hb_codepoint_t unicode)
430 return default_value == RETURNS_UNICODE_ITSELF ? unicode : default_value;
434 test_unicode_properties_nil (void)
436 hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
439 g_assert (!hb_unicode_funcs_is_immutable (uf));
441 for (i = 0; i < G_N_ELEMENTS (properties); i++) {
442 const property_t *p = &properties[i];
443 const test_pair_t *tests;
446 for (j = 0; j < p->num_tests; j++)
447 g_assert_cmpint (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode));
450 hb_unicode_funcs_destroy (uf);
453 #define MAGIC0 0x12345678
454 #define MAGIC1 0x76543210
465 data_fixture_init (data_fixture_t *f, gconstpointer user_data)
467 f->data[0].value = MAGIC0;
468 f->data[1].value = MAGIC1;
471 data_fixture_finish (data_fixture_t *f, gconstpointer user_data)
475 static void free_up (void *p)
477 data_t *data = (data_t *) p;
479 g_assert (data->value == MAGIC0 || data->value == MAGIC1);
480 g_assert (data->freed == FALSE);
485 simple_get_script (hb_unicode_funcs_t *ufuncs,
486 hb_codepoint_t codepoint,
489 data_t *data = (data_t *) user_data;
491 g_assert (hb_unicode_funcs_get_parent (ufuncs) == NULL);
492 g_assert (data->value == MAGIC0);
493 g_assert (data->freed == FALSE);
495 if ('a' <= codepoint && codepoint <= 'z')
496 return HB_SCRIPT_LATIN;
498 return HB_SCRIPT_UNKNOWN;
502 a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
503 hb_codepoint_t codepoint,
506 data_t *data = (data_t *) user_data;
508 g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL);
509 g_assert (data->value == MAGIC1);
510 g_assert (data->freed == FALSE);
512 if (codepoint == 'a') {
513 return HB_SCRIPT_ARABIC;
515 hb_unicode_funcs_t *parent = hb_unicode_funcs_get_parent (ufuncs);
517 return hb_unicode_get_script (parent, codepoint);
522 test_unicode_custom (data_fixture_t *f, gconstpointer user_data)
524 hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
526 hb_unicode_funcs_set_script_func (uf, simple_get_script,
527 &f->data[0], free_up);
529 g_assert_cmpint (hb_unicode_get_script (uf, 'a'), ==, HB_SCRIPT_LATIN);
530 g_assert_cmpint (hb_unicode_get_script (uf, '0'), ==, HB_SCRIPT_UNKNOWN);
532 g_assert (!hb_unicode_funcs_is_immutable (uf));
533 hb_unicode_funcs_make_immutable (uf);
534 g_assert (hb_unicode_funcs_is_immutable (uf));
536 /* Since uf is immutable now, the following setter should do nothing. */
537 hb_unicode_funcs_set_script_func (uf, a_is_for_arabic_get_script,
538 &f->data[1], free_up);
540 g_assert (!f->data[0].freed && !f->data[1].freed);
541 hb_unicode_funcs_destroy (uf);
542 g_assert (f->data[0].freed && !f->data[1].freed);
546 test_unicode_subclassing_nil (data_fixture_t *f, gconstpointer user_data)
548 hb_unicode_funcs_t *uf, *aa;
550 uf = hb_unicode_funcs_create (NULL);
552 aa = hb_unicode_funcs_create (uf);
554 hb_unicode_funcs_destroy (uf);
556 hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
557 &f->data[1], free_up);
559 g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
560 g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_UNKNOWN);
562 g_assert (!f->data[0].freed && !f->data[1].freed);
563 hb_unicode_funcs_destroy (aa);
564 g_assert (!f->data[0].freed && f->data[1].freed);
568 test_unicode_subclassing_default (data_fixture_t *f, gconstpointer user_data)
570 hb_unicode_funcs_t *uf, *aa;
572 uf = hb_unicode_funcs_get_default ();
573 aa = hb_unicode_funcs_create (uf);
575 hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
576 &f->data[1], free_up);
578 g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
579 g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
581 g_assert (!f->data[0].freed && !f->data[1].freed);
582 hb_unicode_funcs_destroy (aa);
583 g_assert (!f->data[0].freed && f->data[1].freed);
587 test_unicode_subclassing_deep (data_fixture_t *f, gconstpointer user_data)
589 hb_unicode_funcs_t *uf, *aa;
591 uf = hb_unicode_funcs_create (NULL);
593 hb_unicode_funcs_set_script_func (uf, simple_get_script,
594 &f->data[0], free_up);
596 aa = hb_unicode_funcs_create (uf);
598 hb_unicode_funcs_destroy (uf);
600 /* make sure the 'uf' didn't get freed, since 'aa' holds a ref */
601 g_assert (!f->data[0].freed);
603 hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
604 &f->data[1], free_up);
606 g_assert_cmpint (hb_unicode_get_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
607 g_assert_cmpint (hb_unicode_get_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
608 g_assert_cmpint (hb_unicode_get_script (aa, '0'), ==, HB_SCRIPT_UNKNOWN);
610 g_assert (!f->data[0].freed && !f->data[1].freed);
611 hb_unicode_funcs_destroy (aa);
612 g_assert (f->data[0].freed && f->data[1].freed);
617 main (int argc, char **argv)
619 hb_test_init (&argc, &argv);
621 hb_test_add (test_unicode_properties_nil);
623 hb_test_add_data_flavor (hb_unicode_funcs_get_default (), "default", test_unicode_properties);
625 hb_test_add_data_flavor (hb_glib_get_unicode_funcs (), "glib", test_unicode_properties);
628 hb_test_add_data_flavor (hb_icu_get_unicode_funcs (), "icu", test_unicode_properties);
631 hb_test_add_fixture (data_fixture, NULL, test_unicode_custom);
632 hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_nil);
633 hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_default);
634 hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_deep);
636 /* XXX test icu ufuncs */
637 /* XXX test _more tests (warn?) */
638 /* XXX test chainup */
639 /* XXX test glib & icu two-way script conversion */
641 return hb_test_run ();