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 */
32 /* Unit tests for hb-glib.h */
33 /* Unit tests for hb-icu.h */
44 /* Some useful stuff */
46 #define MAGIC0 0x12345678
47 #define MAGIC1 0x76543210
54 static void free_up (void *p)
56 data_t *data = (data_t *) p;
58 g_assert (data->value == MAGIC0 || data->value == MAGIC1);
59 g_assert (!data->freed);
64 simple_get_script (hb_unicode_funcs_t *ufuncs,
65 hb_codepoint_t codepoint,
68 data_t *data = (data_t *) user_data;
70 g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL);
71 g_assert_cmphex (data->value, ==, MAGIC0);
72 g_assert (!data->freed);
74 if ('a' <= codepoint && codepoint <= 'z')
75 return HB_SCRIPT_LATIN;
77 return HB_SCRIPT_UNKNOWN;
81 a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
82 hb_codepoint_t codepoint,
85 data_t *data = (data_t *) user_data;
87 g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL);
88 g_assert_cmphex (data->value, ==, MAGIC1);
89 g_assert (!data->freed);
91 if (codepoint == 'a') {
92 return HB_SCRIPT_ARABIC;
94 hb_unicode_funcs_t *parent = hb_unicode_funcs_get_parent (ufuncs);
96 return hb_unicode_script (parent, codepoint);
102 /* Check all properties */
104 /* Some of the following tables where adapted from glib/glib/tests/utf8-misc.c.
105 * The license is compatible. */
108 hb_codepoint_t unicode;
112 static const test_pair_t combining_class_tests[] =
149 static const test_pair_t combining_class_tests_more[] =
151 /* Unicode-5.1 character additions */
154 /* Unicode-5.2 character additions */
157 /* Unicode-6.0 character additions */
160 /* Unicode-6.1 character additions */
163 /* Unicode-7.0 character additions */
166 /* Unicode-8.0 character additions */
169 /* Unicode-9.0 character additions */
172 /* Unicode-10.0 character additions */
175 /* Unicode-11.0 character additions */
178 /* Unicode-12.0 character additions */
185 static const test_pair_t general_category_tests[] =
187 { 0x000D, HB_UNICODE_GENERAL_CATEGORY_CONTROL },
188 { 0x200E, HB_UNICODE_GENERAL_CATEGORY_FORMAT },
189 { 0x0378, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED },
190 { 0xE000, HB_UNICODE_GENERAL_CATEGORY_PRIVATE_USE },
191 { 0xD800, HB_UNICODE_GENERAL_CATEGORY_SURROGATE },
192 { 0x0061, HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER },
193 { 0x02B0, HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER },
194 { 0x3400, HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
195 { 0x01C5, HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER },
196 { 0xFF21, HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER },
197 { 0x0903, HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK },
198 { 0x20DD, HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK },
199 { 0xA806, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK },
200 { 0xFF10, HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER },
201 { 0x16EE, HB_UNICODE_GENERAL_CATEGORY_LETTER_NUMBER },
202 { 0x17F0, HB_UNICODE_GENERAL_CATEGORY_OTHER_NUMBER },
203 { 0x005F, HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION },
204 { 0x058A, HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION },
205 { 0x0F3B, HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION },
206 { 0x2019, HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION },
207 { 0x2018, HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION },
208 { 0x2016, HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION },
209 { 0x0F3A, HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION },
210 { 0x20A0, HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL },
211 { 0x309B, HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL },
212 { 0xFB29, HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL },
213 { 0x00A6, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
214 { 0x2028, HB_UNICODE_GENERAL_CATEGORY_LINE_SEPARATOR },
215 { 0x2029, HB_UNICODE_GENERAL_CATEGORY_PARAGRAPH_SEPARATOR },
216 { 0x202F, HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR },
218 { 0x111111, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED }
220 static const test_pair_t general_category_tests_more[] =
222 /* Unicode-5.2 character additions */
223 { 0x1F131, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
225 /* Unicode-6.0 character additions */
226 { 0x0620, HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
228 /* Unicode-6.1 character additions */
229 { 0x058F, HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL },
231 /* Unicode-6.2 character additions */
232 { 0x20BA, HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL },
234 /* Unicode-6.3 character additions */
235 { 0x061C, HB_UNICODE_GENERAL_CATEGORY_FORMAT },
237 /* Unicode-7.0 character additions */
238 { 0x058D, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
240 /* Unicode-8.0 character additions */
241 { 0x08E3, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK },
243 /* Unicode-9.0 character additions */
244 { 0x08D4, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK },
246 /* Unicode-10.0 character additions */
247 { 0x09FD, HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION },
249 /* Unicode-11.0 character additions */
250 { 0x0560, HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER },
252 /* Unicode-12.0 character additions */
253 { 0x0C77, HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION },
255 /* Unicode-12.1 character additions */
256 { 0x32FF, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
258 { 0x111111, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED }
261 static const test_pair_t mirroring_tests[] =
263 /* Some characters that do NOT mirror */
268 { 0xE01EF, 0xE01EF },
269 { 0x1D7C3, 0x1D7C3 },
270 { 0x100000, 0x100000 },
272 /* Some characters that do mirror */
292 { 0x111111, 0x111111 },
294 static const test_pair_t mirroring_tests_more[] =
296 /* Unicode-6.1 character additions */
299 /* Unicode-11.0 character additions */
302 { 0x111111, 0x111111 }
305 static const test_pair_t script_tests[] =
307 { 0x002A, HB_SCRIPT_COMMON },
308 { 0x0670, HB_SCRIPT_INHERITED },
309 { 0x060D, HB_SCRIPT_ARABIC },
310 { 0x0559, HB_SCRIPT_ARMENIAN },
311 { 0x09CD, HB_SCRIPT_BENGALI },
312 { 0x31B6, HB_SCRIPT_BOPOMOFO },
313 { 0x13A2, HB_SCRIPT_CHEROKEE },
314 { 0x2CFD, HB_SCRIPT_COPTIC },
315 { 0x0482, HB_SCRIPT_CYRILLIC },
316 { 0x10401, HB_SCRIPT_DESERET },
317 { 0x094D, HB_SCRIPT_DEVANAGARI },
318 { 0x1258, HB_SCRIPT_ETHIOPIC },
319 { 0x10FC, HB_SCRIPT_GEORGIAN },
320 { 0x10341, HB_SCRIPT_GOTHIC },
321 { 0x0375, HB_SCRIPT_GREEK },
322 { 0x0A83, HB_SCRIPT_GUJARATI },
323 { 0x0A3C, HB_SCRIPT_GURMUKHI },
324 { 0x3005, HB_SCRIPT_HAN },
325 { 0x1100, HB_SCRIPT_HANGUL },
326 { 0x05BF, HB_SCRIPT_HEBREW },
327 { 0x309F, HB_SCRIPT_HIRAGANA },
328 { 0x0CBC, HB_SCRIPT_KANNADA },
329 { 0x30FF, HB_SCRIPT_KATAKANA },
330 { 0x17DD, HB_SCRIPT_KHMER },
331 { 0x0EDD, HB_SCRIPT_LAO },
332 { 0x0061, HB_SCRIPT_LATIN },
333 { 0x0D3D, HB_SCRIPT_MALAYALAM },
334 { 0x1843, HB_SCRIPT_MONGOLIAN },
335 { 0x1031, HB_SCRIPT_MYANMAR },
336 { 0x169C, HB_SCRIPT_OGHAM },
337 { 0x10322, HB_SCRIPT_OLD_ITALIC },
338 { 0x0B3C, HB_SCRIPT_ORIYA },
339 { 0x16EF, HB_SCRIPT_RUNIC },
340 { 0x0DBD, HB_SCRIPT_SINHALA },
341 { 0x0711, HB_SCRIPT_SYRIAC },
342 { 0x0B82, HB_SCRIPT_TAMIL },
343 { 0x0C03, HB_SCRIPT_TELUGU },
344 { 0x07B1, HB_SCRIPT_THAANA },
345 { 0x0E31, HB_SCRIPT_THAI },
346 { 0x0FD4, HB_SCRIPT_TIBETAN },
347 { 0x1401, HB_SCRIPT_CANADIAN_SYLLABICS },
348 { 0xA015, HB_SCRIPT_YI },
349 { 0x1700, HB_SCRIPT_TAGALOG },
350 { 0x1720, HB_SCRIPT_HANUNOO },
351 { 0x1740, HB_SCRIPT_BUHID },
352 { 0x1760, HB_SCRIPT_TAGBANWA },
354 /* Unicode-4.0 additions */
355 { 0x2800, HB_SCRIPT_BRAILLE },
356 { 0x10808, HB_SCRIPT_CYPRIOT },
357 { 0x1932, HB_SCRIPT_LIMBU },
358 { 0x10480, HB_SCRIPT_OSMANYA },
359 { 0x10450, HB_SCRIPT_SHAVIAN },
360 { 0x10000, HB_SCRIPT_LINEAR_B },
361 { 0x1950, HB_SCRIPT_TAI_LE },
362 { 0x1039F, HB_SCRIPT_UGARITIC },
364 /* Unicode-4.1 additions */
365 { 0x1980, HB_SCRIPT_NEW_TAI_LUE },
366 { 0x1A1F, HB_SCRIPT_BUGINESE },
367 { 0x2C00, HB_SCRIPT_GLAGOLITIC },
368 { 0x2D6F, HB_SCRIPT_TIFINAGH },
369 { 0xA800, HB_SCRIPT_SYLOTI_NAGRI },
370 { 0x103D0, HB_SCRIPT_OLD_PERSIAN },
371 { 0x10A3F, HB_SCRIPT_KHAROSHTHI },
373 /* Unicode-5.0 additions */
374 { 0x0378, HB_SCRIPT_UNKNOWN },
375 { 0x1B04, HB_SCRIPT_BALINESE },
376 { 0x12000, HB_SCRIPT_CUNEIFORM },
377 { 0x10900, HB_SCRIPT_PHOENICIAN },
378 { 0xA840, HB_SCRIPT_PHAGS_PA },
379 { 0x07C0, HB_SCRIPT_NKO },
381 /* Unicode-5.1 additions */
382 { 0xA900, HB_SCRIPT_KAYAH_LI },
383 { 0x1C00, HB_SCRIPT_LEPCHA },
384 { 0xA930, HB_SCRIPT_REJANG },
385 { 0x1B80, HB_SCRIPT_SUNDANESE },
386 { 0xA880, HB_SCRIPT_SAURASHTRA },
387 { 0xAA00, HB_SCRIPT_CHAM },
388 { 0x1C50, HB_SCRIPT_OL_CHIKI },
389 { 0xA500, HB_SCRIPT_VAI },
390 { 0x102A0, HB_SCRIPT_CARIAN },
391 { 0x10280, HB_SCRIPT_LYCIAN },
392 { 0x1093F, HB_SCRIPT_LYDIAN },
394 { 0x111111, HB_SCRIPT_UNKNOWN }
396 static const test_pair_t script_tests_more[] =
398 /* Unicode-5.2 additions */
399 { 0x10B00, HB_SCRIPT_AVESTAN },
400 { 0xA6A0, HB_SCRIPT_BAMUM },
401 { 0x1400, HB_SCRIPT_CANADIAN_ABORIGINAL },
402 { 0x13000, HB_SCRIPT_EGYPTIAN_HIEROGLYPHS },
403 { 0x10840, HB_SCRIPT_IMPERIAL_ARAMAIC },
404 { 0x1CED, HB_SCRIPT_INHERITED },
405 { 0x10B60, HB_SCRIPT_INSCRIPTIONAL_PAHLAVI },
406 { 0x10B40, HB_SCRIPT_INSCRIPTIONAL_PARTHIAN },
407 { 0xA980, HB_SCRIPT_JAVANESE },
408 { 0x11082, HB_SCRIPT_KAITHI },
409 { 0xA4D0, HB_SCRIPT_LISU },
410 { 0xABE5, HB_SCRIPT_MEETEI_MAYEK },
411 { 0x10A60, HB_SCRIPT_OLD_SOUTH_ARABIAN },
412 { 0x10C00, HB_SCRIPT_OLD_TURKIC },
413 { 0x0800, HB_SCRIPT_SAMARITAN },
414 { 0x1A20, HB_SCRIPT_TAI_THAM },
415 { 0xAA80, HB_SCRIPT_TAI_VIET },
417 /* Unicode-6.0 additions */
418 { 0x1BC0, HB_SCRIPT_BATAK },
419 { 0x11000, HB_SCRIPT_BRAHMI },
420 { 0x0840, HB_SCRIPT_MANDAIC },
422 /* Unicode-6.1 additions */
423 { 0x10980, HB_SCRIPT_MEROITIC_HIEROGLYPHS },
424 { 0x109A0, HB_SCRIPT_MEROITIC_CURSIVE },
425 { 0x110D0, HB_SCRIPT_SORA_SOMPENG },
426 { 0x11100, HB_SCRIPT_CHAKMA },
427 { 0x11180, HB_SCRIPT_SHARADA },
428 { 0x11680, HB_SCRIPT_TAKRI },
429 { 0x16F00, HB_SCRIPT_MIAO },
431 /* Unicode-6.2 additions */
432 { 0x20BA, HB_SCRIPT_COMMON },
434 /* Unicode-6.3 additions */
435 { 0x2066, HB_SCRIPT_COMMON },
437 /* Unicode-7.0 additions */
438 { 0x10350, HB_SCRIPT_OLD_PERMIC },
439 { 0x10500, HB_SCRIPT_ELBASAN },
440 { 0x10530, HB_SCRIPT_CAUCASIAN_ALBANIAN },
441 { 0x10600, HB_SCRIPT_LINEAR_A },
442 { 0x10860, HB_SCRIPT_PALMYRENE },
443 { 0x10880, HB_SCRIPT_NABATAEAN },
444 { 0x10A80, HB_SCRIPT_OLD_NORTH_ARABIAN },
445 { 0x10AC0, HB_SCRIPT_MANICHAEAN },
446 { 0x10B80, HB_SCRIPT_PSALTER_PAHLAVI },
447 { 0x11150, HB_SCRIPT_MAHAJANI },
448 { 0x11200, HB_SCRIPT_KHOJKI },
449 { 0x112B0, HB_SCRIPT_KHUDAWADI },
450 { 0x11300, HB_SCRIPT_GRANTHA },
451 { 0x11480, HB_SCRIPT_TIRHUTA },
452 { 0x11580, HB_SCRIPT_SIDDHAM },
453 { 0x11600, HB_SCRIPT_MODI },
454 { 0x118A0, HB_SCRIPT_WARANG_CITI },
455 { 0x11AC0, HB_SCRIPT_PAU_CIN_HAU },
456 { 0x16A40, HB_SCRIPT_MRO },
457 { 0x16AD0, HB_SCRIPT_BASSA_VAH },
458 { 0x16B00, HB_SCRIPT_PAHAWH_HMONG },
459 { 0x1BC00, HB_SCRIPT_DUPLOYAN },
460 { 0x1E800, HB_SCRIPT_MENDE_KIKAKUI },
462 /* Unicode-8.0 additions */
463 { 0x108E0, HB_SCRIPT_HATRAN },
464 { 0x10C80, HB_SCRIPT_OLD_HUNGARIAN },
465 { 0x11280, HB_SCRIPT_MULTANI },
466 { 0x11700, HB_SCRIPT_AHOM },
467 { 0x14400, HB_SCRIPT_ANATOLIAN_HIEROGLYPHS },
468 { 0x1D800, HB_SCRIPT_SIGNWRITING },
470 /* Unicode-9.0 additions */
471 { 0x104B0, HB_SCRIPT_OSAGE },
472 { 0x11400, HB_SCRIPT_NEWA },
473 { 0x11C00, HB_SCRIPT_BHAIKSUKI },
474 { 0x11C70, HB_SCRIPT_MARCHEN },
475 { 0x17000, HB_SCRIPT_TANGUT },
476 { 0x1E900, HB_SCRIPT_ADLAM },
478 /* Unicode-10.0 additions */
479 { 0x11A00, HB_SCRIPT_ZANABAZAR_SQUARE },
480 { 0x11A50, HB_SCRIPT_SOYOMBO },
481 { 0x11D00, HB_SCRIPT_MASARAM_GONDI },
482 { 0x1B170, HB_SCRIPT_NUSHU },
484 /* Unicode-11.0 additions */
485 { 0x10D00, HB_SCRIPT_HANIFI_ROHINGYA },
486 { 0x10F00, HB_SCRIPT_OLD_SOGDIAN },
487 { 0x10F30, HB_SCRIPT_SOGDIAN },
488 { 0x11800, HB_SCRIPT_DOGRA },
489 { 0x11D60, HB_SCRIPT_GUNJALA_GONDI },
490 { 0x11EE0, HB_SCRIPT_MAKASAR },
491 { 0x16E40, HB_SCRIPT_MEDEFAIDRIN },
493 /* Unicode-12.0 additions */
494 { 0x10FE0, HB_SCRIPT_ELYMAIC },
495 { 0x119A0, HB_SCRIPT_NANDINAGARI },
496 { 0x1E100, HB_SCRIPT_NYIAKENG_PUACHUE_HMONG },
497 { 0x1E2C0, HB_SCRIPT_WANCHO },
499 /* Unicode-12.1 additions */
500 { 0x32FF, HB_SCRIPT_COMMON },
502 { 0x111111, HB_SCRIPT_UNKNOWN }
506 typedef unsigned int (*get_func_t) (hb_unicode_funcs_t *ufuncs,
507 hb_codepoint_t unicode,
509 typedef unsigned int (*func_setter_func_t) (hb_unicode_funcs_t *ufuncs,
512 hb_destroy_func_t destroy);
513 typedef unsigned int (*getter_func_t) (hb_unicode_funcs_t *ufuncs,
514 hb_codepoint_t unicode);
518 func_setter_func_t func_setter;
519 getter_func_t getter;
520 const test_pair_t *tests;
521 unsigned int num_tests;
522 const test_pair_t *tests_more;
523 unsigned int num_tests_more;
524 unsigned int default_value;
527 #define RETURNS_UNICODE_ITSELF ((unsigned int) -1)
529 #define PROPERTY(name, DEFAULT) \
532 (func_setter_func_t) hb_unicode_funcs_set_##name##_func, \
533 (getter_func_t) hb_unicode_##name, \
535 G_N_ELEMENTS (name##_tests), \
537 G_N_ELEMENTS (name##_tests_more), \
540 static const property_t properties[] =
542 PROPERTY (combining_class, 0),
543 PROPERTY (general_category, (unsigned int) HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER),
544 PROPERTY (mirroring, RETURNS_UNICODE_ITSELF),
545 PROPERTY (script, (unsigned int) HB_SCRIPT_UNKNOWN)
550 test_unicode_properties (gconstpointer user_data, hb_bool_t lenient)
552 hb_unicode_funcs_t *uf = (hb_unicode_funcs_t *) user_data;
554 gboolean failed = TRUE;
556 g_assert (hb_unicode_funcs_is_immutable (uf));
557 g_assert (hb_unicode_funcs_get_parent (uf));
559 for (i = 0; i < G_N_ELEMENTS (properties); i++) {
560 const property_t *p = &properties[i];
561 const test_pair_t *tests;
563 g_test_message ("Testing property %s", p->name);
565 for (j = 0; j < p->num_tests; j++) {
566 g_test_message ("Test %s #%d: U+%04X", p->name, j, tests[j].unicode);
567 g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, tests[j].value);
569 /* These tests are from Unicode 5.2 onward and older glib/ICU
570 * don't get them right. Just warn instead of assert. */
571 tests = p->tests_more;
572 for (j = 0; j < p->num_tests_more; j++) {
573 g_test_message ("Test %s more #%d: U+%04X", p->name, j, tests[j].unicode);
575 if (p->getter (uf, tests[j].unicode) != tests[j].value) {
576 g_test_message ("Soft fail: Received %x, expected %x", p->getter (uf, tests[j].unicode), tests[j].value);
581 g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, tests[j].value);
586 g_test_message ("Some property tests failed. You probably have an old version of one of the libraries used.");
589 test_unicode_properties_lenient (gconstpointer user_data)
591 test_unicode_properties (user_data, TRUE);
594 test_unicode_properties_strict (gconstpointer user_data)
596 test_unicode_properties (user_data, FALSE);
599 static hb_codepoint_t
600 default_value (hb_codepoint_t _default_value, hb_codepoint_t unicode)
602 return _default_value == RETURNS_UNICODE_ITSELF ? unicode : _default_value;
606 _test_unicode_properties_nil (hb_unicode_funcs_t *uf)
610 for (i = 0; i < G_N_ELEMENTS (properties); i++) {
611 const property_t *p = &properties[i];
612 const test_pair_t *tests;
614 g_test_message ("Testing property %s", p->name);
616 for (j = 0; j < p->num_tests; j++) {
617 g_test_message ("Test %s #%d: U+%04X", p->name, j, tests[j].unicode);
618 g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode));
620 tests = p->tests_more;
621 for (j = 0; j < p->num_tests_more; j++) {
622 g_test_message ("Test %s more #%d: U+%04X", p->name, j, tests[j].unicode);
623 g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, default_value (p->default_value, tests[j].unicode));
629 test_unicode_properties_nil (void)
631 hb_unicode_funcs_t *uf = hb_unicode_funcs_create (NULL);
633 g_assert (!hb_unicode_funcs_is_immutable (uf));
634 _test_unicode_properties_nil (uf);
636 hb_unicode_funcs_destroy (uf);
640 test_unicode_properties_empty (void)
642 hb_unicode_funcs_t *uf = hb_unicode_funcs_get_empty ();
645 g_assert (hb_unicode_funcs_is_immutable (uf));
646 _test_unicode_properties_nil (uf);
651 test_unicode_chainup (void)
653 hb_unicode_funcs_t *uf, *uf2;
655 /* Chain-up to nil */
657 uf = hb_unicode_funcs_create (NULL);
658 g_assert (!hb_unicode_funcs_is_immutable (uf));
660 uf2 = hb_unicode_funcs_create (uf);
661 g_assert (hb_unicode_funcs_is_immutable (uf));
662 hb_unicode_funcs_destroy (uf);
664 g_assert (!hb_unicode_funcs_is_immutable (uf2));
665 _test_unicode_properties_nil (uf2);
667 hb_unicode_funcs_destroy (uf2);
669 /* Chain-up to default */
671 uf = hb_unicode_funcs_create (hb_unicode_funcs_get_default ());
672 g_assert (!hb_unicode_funcs_is_immutable (uf));
674 uf2 = hb_unicode_funcs_create (uf);
675 g_assert (hb_unicode_funcs_is_immutable (uf));
676 hb_unicode_funcs_destroy (uf);
678 g_assert (!hb_unicode_funcs_is_immutable (uf2));
679 hb_unicode_funcs_make_immutable (uf2);
680 test_unicode_properties_strict (uf2);
682 hb_unicode_funcs_destroy (uf2);
687 test_unicode_setters (void)
689 hb_unicode_funcs_t *uf;
692 /* This is cruel: we use script-returning functions to test all properties,
695 for (i = 0; i < G_N_ELEMENTS (properties); i++) {
696 const property_t *p = &properties[i];
697 data_t data[2] = {{MAGIC0, FALSE}, {MAGIC1, FALSE}};
699 g_test_message ("Testing property %s", p->name);
701 uf = hb_unicode_funcs_create (NULL);
702 g_assert (!hb_unicode_funcs_is_immutable (uf));
704 p->func_setter (uf, (get_func_t) simple_get_script, &data[0], free_up);
706 g_assert_cmphex (p->getter (uf, 'a'), ==, HB_SCRIPT_LATIN);
707 g_assert_cmphex (p->getter (uf, '0'), ==, HB_SCRIPT_UNKNOWN);
709 p->func_setter (uf, (get_func_t) NULL, NULL, NULL);
710 g_assert (data[0].freed && !data[1].freed);
712 g_assert (!hb_unicode_funcs_is_immutable (uf));
713 hb_unicode_funcs_make_immutable (uf);
714 g_assert (hb_unicode_funcs_is_immutable (uf));
716 /* Since uf is immutable now, the following setter should do nothing. */
717 p->func_setter (uf, (get_func_t) a_is_for_arabic_get_script, &data[1], free_up);
719 g_assert (data[0].freed && !data[1].freed);
720 hb_unicode_funcs_destroy (uf);
721 g_assert (data[0].freed && !data[1].freed);
732 data_fixture_init (data_fixture_t *f, gconstpointer user_data HB_UNUSED)
734 f->data[0].value = MAGIC0;
735 f->data[1].value = MAGIC1;
738 data_fixture_finish (data_fixture_t *f HB_UNUSED, gconstpointer user_data HB_UNUSED)
743 test_unicode_subclassing_nil (data_fixture_t *f, gconstpointer user_data HB_UNUSED)
745 hb_unicode_funcs_t *uf, *aa;
747 uf = hb_unicode_funcs_create (NULL);
749 aa = hb_unicode_funcs_create (uf);
751 hb_unicode_funcs_destroy (uf);
753 hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
754 &f->data[1], free_up);
756 g_assert_cmphex (hb_unicode_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
757 g_assert_cmphex (hb_unicode_script (aa, 'b'), ==, HB_SCRIPT_UNKNOWN);
759 g_assert (!f->data[0].freed && !f->data[1].freed);
760 hb_unicode_funcs_destroy (aa);
761 g_assert (!f->data[0].freed && f->data[1].freed);
765 test_unicode_subclassing_default (data_fixture_t *f, gconstpointer user_data HB_UNUSED)
767 hb_unicode_funcs_t *uf, *aa;
769 uf = hb_unicode_funcs_get_default ();
770 aa = hb_unicode_funcs_create (uf);
772 hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
773 &f->data[1], free_up);
775 g_assert_cmphex (hb_unicode_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
776 g_assert_cmphex (hb_unicode_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
778 g_assert (!f->data[0].freed && !f->data[1].freed);
779 hb_unicode_funcs_destroy (aa);
780 g_assert (!f->data[0].freed && f->data[1].freed);
784 test_unicode_subclassing_deep (data_fixture_t *f, gconstpointer user_data HB_UNUSED)
786 hb_unicode_funcs_t *uf, *aa;
788 uf = hb_unicode_funcs_create (NULL);
790 hb_unicode_funcs_set_script_func (uf, simple_get_script,
791 &f->data[0], free_up);
793 aa = hb_unicode_funcs_create (uf);
795 hb_unicode_funcs_destroy (uf);
797 /* make sure the 'uf' didn't get freed, since 'aa' holds a ref */
798 g_assert (!f->data[0].freed);
800 hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
801 &f->data[1], free_up);
803 g_assert_cmphex (hb_unicode_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
804 g_assert_cmphex (hb_unicode_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
805 g_assert_cmphex (hb_unicode_script (aa, '0'), ==, HB_SCRIPT_UNKNOWN);
807 g_assert (!f->data[0].freed && !f->data[1].freed);
808 hb_unicode_funcs_destroy (aa);
809 g_assert (f->data[0].freed && f->data[1].freed);
814 script_roundtrip_default (hb_script_t script)
816 return hb_script_from_iso15924_tag (hb_script_to_iso15924_tag (script));
821 script_roundtrip_glib (hb_script_t script)
823 return hb_glib_script_to_script (hb_glib_script_from_script (script));
829 script_roundtrip_icu (hb_script_t script)
831 return hb_icu_script_to_script (hb_icu_script_from_script (script));
836 test_unicode_script_roundtrip (gconstpointer user_data)
838 typedef hb_script_t (*roundtrip_func_t) (hb_script_t);
839 roundtrip_func_t roundtrip_func = (roundtrip_func_t) user_data;
841 gboolean failed = FALSE;
843 for (i = 0; i < G_N_ELEMENTS (script_tests); i++) {
844 const test_pair_t *test = &script_tests[i];
845 hb_script_t script = test->value;
847 g_test_message ("Test script roundtrip #%d: %x", i, script);
848 g_assert_cmphex (script, ==, roundtrip_func (script));
850 for (i = 0; i < G_N_ELEMENTS (script_tests_more); i++) {
851 const test_pair_t *test = &script_tests_more[i];
852 hb_script_t script = test->value;
854 g_test_message ("Test script roundtrip more #%d: %x", i, script);
855 if (script != roundtrip_func (script)) {
856 g_test_message ("Soft fail: Received %x, expected %x", roundtrip_func (script), script);
861 g_assert_cmphex (HB_SCRIPT_INVALID, ==, roundtrip_func (HB_SCRIPT_INVALID));
864 g_test_message ("Some script roundtrip tests failed. You probably have an old version of one of the libraries used.");
869 test_unicode_normalization (gconstpointer user_data)
871 hb_unicode_funcs_t *uf = (hb_unicode_funcs_t *) user_data;
878 g_assert (!hb_unicode_compose (uf, 0x0041, 0x0042, &ab) && ab == 0);
879 g_assert (!hb_unicode_compose (uf, 0x0041, 0, &ab) && ab == 0);
880 g_assert (!hb_unicode_compose (uf, 0x0066, 0x0069, &ab) && ab == 0);
882 /* Singletons should not compose */
883 g_assert (!hb_unicode_compose (uf, 0x212B, 0, &ab) && ab == 0);
884 g_assert (!hb_unicode_compose (uf, 0x00C5, 0, &ab) && ab == 0);
885 g_assert (!hb_unicode_compose (uf, 0x2126, 0, &ab) && ab == 0);
886 g_assert (!hb_unicode_compose (uf, 0x03A9, 0, &ab) && ab == 0);
888 /* Non-starter pairs should not compose */
889 g_assert (!hb_unicode_compose (uf, 0x0308, 0x0301, &ab) && ab == 0); /* !0x0344 */
890 g_assert (!hb_unicode_compose (uf, 0x0F71, 0x0F72, &ab) && ab == 0); /* !0x0F73 */
893 g_assert (hb_unicode_compose (uf, 0x0041, 0x030A, &ab) && ab == 0x00C5);
894 g_assert (hb_unicode_compose (uf, 0x006F, 0x0302, &ab) && ab == 0x00F4);
895 g_assert (hb_unicode_compose (uf, 0x1E63, 0x0307, &ab) && ab == 0x1E69);
896 g_assert (hb_unicode_compose (uf, 0x0073, 0x0323, &ab) && ab == 0x1E63);
897 g_assert (hb_unicode_compose (uf, 0x0064, 0x0307, &ab) && ab == 0x1E0B);
898 g_assert (hb_unicode_compose (uf, 0x0064, 0x0323, &ab) && ab == 0x1E0D);
901 g_assert (hb_unicode_compose (uf, 0xD4CC, 0x11B6, &ab) && ab == 0xD4DB);
902 g_assert (hb_unicode_compose (uf, 0x1111, 0x1171, &ab) && ab == 0xD4CC);
903 g_assert (hb_unicode_compose (uf, 0xCE20, 0x11B8, &ab) && ab == 0xCE31);
904 g_assert (hb_unicode_compose (uf, 0x110E, 0x1173, &ab) && ab == 0xCE20);
906 g_assert (!hb_unicode_compose (uf, 0xAC00, 0x11A7, &ab));
907 g_assert (hb_unicode_compose (uf, 0xAC00, 0x11A8, &ab) && ab == 0xAC01);
908 g_assert (!hb_unicode_compose (uf, 0xAC01, 0x11A8, &ab));
911 /* Test decompose() */
913 /* Not decomposable */
914 g_assert (!hb_unicode_decompose (uf, 0x0041, &a, &b) && a == 0x0041 && b == 0);
915 g_assert (!hb_unicode_decompose (uf, 0xFB01, &a, &b) && a == 0xFB01 && b == 0);
916 g_assert (!hb_unicode_decompose (uf, 0x1F1EF, &a, &b) && a == 0x1F1EF && b == 0);
919 g_assert (hb_unicode_decompose (uf, 0x212B, &a, &b) && a == 0x00C5 && b == 0);
920 g_assert (hb_unicode_decompose (uf, 0x2126, &a, &b) && a == 0x03A9 && b == 0);
922 /* Non-starter pairs decompose, but not compose */
923 g_assert (hb_unicode_decompose (uf, 0x0344, &a, &b) && a == 0x0308 && b == 0x0301);
924 g_assert (hb_unicode_decompose (uf, 0x0F73, &a, &b) && a == 0x0F71 && b == 0x0F72);
927 g_assert (hb_unicode_decompose (uf, 0x00C5, &a, &b) && a == 0x0041 && b == 0x030A);
928 g_assert (hb_unicode_decompose (uf, 0x00F4, &a, &b) && a == 0x006F && b == 0x0302);
929 g_assert (hb_unicode_decompose (uf, 0x1E69, &a, &b) && a == 0x1E63 && b == 0x0307);
930 g_assert (hb_unicode_decompose (uf, 0x1E63, &a, &b) && a == 0x0073 && b == 0x0323);
931 g_assert (hb_unicode_decompose (uf, 0x1E0B, &a, &b) && a == 0x0064 && b == 0x0307);
932 g_assert (hb_unicode_decompose (uf, 0x1E0D, &a, &b) && a == 0x0064 && b == 0x0323);
935 g_assert (hb_unicode_decompose (uf, 0xD4DB, &a, &b) && a == 0xD4CC && b == 0x11B6);
936 g_assert (hb_unicode_decompose (uf, 0xD4CC, &a, &b) && a == 0x1111 && b == 0x1171);
937 g_assert (hb_unicode_decompose (uf, 0xCE31, &a, &b) && a == 0xCE20 && b == 0x11B8);
938 g_assert (hb_unicode_decompose (uf, 0xCE20, &a, &b) && a == 0x110E && b == 0x1173);
944 main (int argc, char **argv)
946 hb_test_init (&argc, &argv);
948 hb_test_add (test_unicode_properties_nil);
949 hb_test_add (test_unicode_properties_empty);
951 hb_test_add_data_flavor (hb_unicode_funcs_get_default (), "default", test_unicode_properties_strict);
952 hb_test_add_data_flavor (hb_unicode_funcs_get_default (), "default", test_unicode_normalization);
953 hb_test_add_data_flavor ((gconstpointer) script_roundtrip_default, "default", test_unicode_script_roundtrip);
955 hb_test_add_data_flavor (hb_glib_get_unicode_funcs (), "glib", test_unicode_properties_lenient);
956 hb_test_add_data_flavor (hb_glib_get_unicode_funcs (), "glib", test_unicode_normalization);
957 hb_test_add_data_flavor ((gconstpointer) script_roundtrip_glib, "glib", test_unicode_script_roundtrip);
960 hb_test_add_data_flavor (hb_icu_get_unicode_funcs (), "icu", test_unicode_properties_lenient);
961 hb_test_add_data_flavor (hb_icu_get_unicode_funcs (), "icu", test_unicode_normalization);
962 hb_test_add_data_flavor ((gconstpointer) script_roundtrip_icu, "icu", test_unicode_script_roundtrip);
965 hb_test_add (test_unicode_chainup);
967 hb_test_add (test_unicode_setters);
969 hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_nil);
970 hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_default);
971 hb_test_add_fixture (data_fixture, NULL, test_unicode_subclassing_deep);
973 return hb_test_run ();