Imported Upstream version 2.6.4
[platform/upstream/harfbuzz.git] / test / api / test-unicode.c
index 6195bb2..71a471d 100644 (file)
@@ -62,8 +62,8 @@ static void free_up (void *p)
 
 static hb_script_t
 simple_get_script (hb_unicode_funcs_t *ufuncs,
-                   hb_codepoint_t      codepoint,
-                   void               *user_data)
+                  hb_codepoint_t      codepoint,
+                  void               *user_data)
 {
   data_t *data = (data_t *) user_data;
 
@@ -79,8 +79,8 @@ simple_get_script (hb_unicode_funcs_t *ufuncs,
 
 static hb_script_t
 a_is_for_arabic_get_script (hb_unicode_funcs_t *ufuncs,
-                            hb_codepoint_t      codepoint,
-                            void               *user_data)
+                           hb_codepoint_t      codepoint,
+                           void               *user_data)
 {
   data_t *data = (data_t *) user_data;
 
@@ -157,6 +157,27 @@ static const test_pair_t combining_class_tests_more[] =
   /* Unicode-6.0 character additions */
   {   0x135D, 230 },
 
+  /* Unicode-6.1 character additions */
+  {   0xA674, 230 },
+
+  /* Unicode-7.0 character additions */
+  {   0x1AB0, 230 },
+
+  /* Unicode-8.0 character additions */
+  {   0xA69E, 230 },
+
+  /* Unicode-9.0 character additions */
+  {  0x1E000, 230 },
+
+  /* Unicode-10.0 character additions */
+  {   0x1DF6, 232 },
+
+  /* Unicode-11.0 character additions */
+  {   0x07FD, 220 },
+
+  /* Unicode-12.0 character additions */
+  {   0x0EBA,   9 },
+
   { 0x111111, 0 }
 };
 
@@ -204,6 +225,36 @@ static const test_pair_t general_category_tests_more[] =
   /* Unicode-6.0 character additions */
   {   0x0620, HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER },
 
+  /* Unicode-6.1 character additions */
+  {   0x058F, HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL },
+
+  /* Unicode-6.2 character additions */
+  {   0x20BA, HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL },
+
+  /* Unicode-6.3 character additions */
+  {   0x061C, HB_UNICODE_GENERAL_CATEGORY_FORMAT },
+
+  /* Unicode-7.0 character additions */
+  {   0x058D, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
+
+  /* Unicode-8.0 character additions */
+  {   0x08E3, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK },
+
+  /* Unicode-9.0 character additions */
+  {   0x08D4, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK },
+
+  /* Unicode-10.0 character additions */
+  {   0x09FD, HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION },
+
+  /* Unicode-11.0 character additions */
+  {   0x0560, HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER },
+
+  /* Unicode-12.0 character additions */
+  {   0x0C77, HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION },
+
+  /* Unicode-12.1 character additions */
+  {   0x32FF, HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL },
+
   { 0x111111, HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED }
 };
 
@@ -242,7 +293,12 @@ static const test_pair_t mirroring_tests[] =
 };
 static const test_pair_t mirroring_tests_more[] =
 {
-  /* No new mirroring characters have been encoded in recent Unicode versions. */
+  /* Unicode-6.1 character additions */
+  {   0x27CB, 0x27CD },
+
+  /* Unicode-11.0 character additions */
+  {   0x2BFE, 0x221F },
+
   { 0x111111, 0x111111 }
 };
 
@@ -342,8 +398,10 @@ static const test_pair_t script_tests_more[] =
   /* Unicode-5.2 additions */
   {  0x10B00, HB_SCRIPT_AVESTAN },
   {   0xA6A0, HB_SCRIPT_BAMUM },
+  {   0x1400, HB_SCRIPT_CANADIAN_ABORIGINAL },
   {  0x13000, HB_SCRIPT_EGYPTIAN_HIEROGLYPHS },
   {  0x10840, HB_SCRIPT_IMPERIAL_ARAMAIC },
+  {   0x1CED, HB_SCRIPT_INHERITED },
   {  0x10B60, HB_SCRIPT_INSCRIPTIONAL_PAHLAVI },
   {  0x10B40, HB_SCRIPT_INSCRIPTIONAL_PARTHIAN },
   {   0xA980, HB_SCRIPT_JAVANESE },
@@ -361,9 +419,85 @@ static const test_pair_t script_tests_more[] =
   {  0x11000, HB_SCRIPT_BRAHMI },
   {   0x0840, HB_SCRIPT_MANDAIC },
 
-  /* Unicode-5.2 character additions */
-  {   0x1CED, HB_SCRIPT_INHERITED },
-  {   0x1400, HB_SCRIPT_CANADIAN_ABORIGINAL },
+  /* Unicode-6.1 additions */
+  {  0x10980, HB_SCRIPT_MEROITIC_HIEROGLYPHS },
+  {  0x109A0, HB_SCRIPT_MEROITIC_CURSIVE },
+  {  0x110D0, HB_SCRIPT_SORA_SOMPENG },
+  {  0x11100, HB_SCRIPT_CHAKMA },
+  {  0x11180, HB_SCRIPT_SHARADA },
+  {  0x11680, HB_SCRIPT_TAKRI },
+  {  0x16F00, HB_SCRIPT_MIAO },
+
+  /* Unicode-6.2 additions */
+  {   0x20BA, HB_SCRIPT_COMMON },
+
+  /* Unicode-6.3 additions */
+  {   0x2066, HB_SCRIPT_COMMON },
+
+  /* Unicode-7.0 additions */
+  {   0x10350, HB_SCRIPT_OLD_PERMIC },
+  {   0x10500, HB_SCRIPT_ELBASAN },
+  {   0x10530, HB_SCRIPT_CAUCASIAN_ALBANIAN },
+  {   0x10600, HB_SCRIPT_LINEAR_A },
+  {   0x10860, HB_SCRIPT_PALMYRENE },
+  {   0x10880, HB_SCRIPT_NABATAEAN },
+  {   0x10A80, HB_SCRIPT_OLD_NORTH_ARABIAN },
+  {   0x10AC0, HB_SCRIPT_MANICHAEAN },
+  {   0x10B80, HB_SCRIPT_PSALTER_PAHLAVI },
+  {   0x11150, HB_SCRIPT_MAHAJANI },
+  {   0x11200, HB_SCRIPT_KHOJKI },
+  {   0x112B0, HB_SCRIPT_KHUDAWADI },
+  {   0x11300, HB_SCRIPT_GRANTHA },
+  {   0x11480, HB_SCRIPT_TIRHUTA },
+  {   0x11580, HB_SCRIPT_SIDDHAM },
+  {   0x11600, HB_SCRIPT_MODI },
+  {   0x118A0, HB_SCRIPT_WARANG_CITI },
+  {   0x11AC0, HB_SCRIPT_PAU_CIN_HAU },
+  {   0x16A40, HB_SCRIPT_MRO },
+  {   0x16AD0, HB_SCRIPT_BASSA_VAH },
+  {   0x16B00, HB_SCRIPT_PAHAWH_HMONG },
+  {   0x1BC00, HB_SCRIPT_DUPLOYAN },
+  {   0x1E800, HB_SCRIPT_MENDE_KIKAKUI },
+
+  /* Unicode-8.0 additions */
+  {   0x108E0, HB_SCRIPT_HATRAN },
+  {   0x10C80, HB_SCRIPT_OLD_HUNGARIAN },
+  {   0x11280, HB_SCRIPT_MULTANI },
+  {   0x11700, HB_SCRIPT_AHOM },
+  {   0x14400, HB_SCRIPT_ANATOLIAN_HIEROGLYPHS },
+  {   0x1D800, HB_SCRIPT_SIGNWRITING },
+
+  /* Unicode-9.0 additions */
+  {   0x104B0, HB_SCRIPT_OSAGE },
+  {   0x11400, HB_SCRIPT_NEWA },
+  {   0x11C00, HB_SCRIPT_BHAIKSUKI },
+  {   0x11C70, HB_SCRIPT_MARCHEN },
+  {   0x17000, HB_SCRIPT_TANGUT },
+  {   0x1E900, HB_SCRIPT_ADLAM },
+
+  /* Unicode-10.0 additions */
+  {   0x11A00, HB_SCRIPT_ZANABAZAR_SQUARE },
+  {   0x11A50, HB_SCRIPT_SOYOMBO },
+  {   0x11D00, HB_SCRIPT_MASARAM_GONDI },
+  {   0x1B170, HB_SCRIPT_NUSHU },
+
+  /* Unicode-11.0 additions */
+  {   0x10D00, HB_SCRIPT_HANIFI_ROHINGYA },
+  {   0x10F00, HB_SCRIPT_OLD_SOGDIAN },
+  {   0x10F30, HB_SCRIPT_SOGDIAN },
+  {   0x11800, HB_SCRIPT_DOGRA },
+  {   0x11D60, HB_SCRIPT_GUNJALA_GONDI },
+  {   0x11EE0, HB_SCRIPT_MAKASAR },
+  {   0x16E40, HB_SCRIPT_MEDEFAIDRIN },
+
+  /* Unicode-12.0 additions */
+  {   0x10FE0, HB_SCRIPT_ELYMAIC },
+  {   0x119A0, HB_SCRIPT_NANDINAGARI },
+  {   0x1E100, HB_SCRIPT_NYIAKENG_PUACHUE_HMONG },
+  {   0x1E2C0, HB_SCRIPT_WANCHO },
+
+  /* Unicode-12.1 additions */
+  {   0x32FF, HB_SCRIPT_COMMON },
 
   { 0x111111, HB_SCRIPT_UNKNOWN }
 };
@@ -413,7 +547,7 @@ static const property_t properties[] =
 #undef PROPERTY
 
 static void
-test_unicode_properties (gconstpointer user_data)
+test_unicode_properties (gconstpointer user_data, hb_bool_t lenient)
 {
   hb_unicode_funcs_t *uf = (hb_unicode_funcs_t *) user_data;
   unsigned int i, j;
@@ -437,16 +571,30 @@ test_unicode_properties (gconstpointer user_data)
     tests = p->tests_more;
     for (j = 0; j < p->num_tests_more; j++) {
       g_test_message ("Test %s more #%d: U+%04X", p->name, j, tests[j].unicode);
-      if (p->getter (uf, tests[j].unicode) != tests[j].value) {
-       g_test_message ("Soft fail: Received %x, expected %x", p->getter (uf, tests[j].unicode), tests[j].value);
-        failed = TRUE;
+      if (lenient) {
+       if (p->getter (uf, tests[j].unicode) != tests[j].value) {
+         g_test_message ("Soft fail: Received %x, expected %x", p->getter (uf, tests[j].unicode), tests[j].value);
+         failed = TRUE;
+       }
       }
+      else
+       g_assert_cmphex (p->getter (uf, tests[j].unicode), ==, tests[j].value);
     }
   }
 
   if (failed)
     g_test_message ("Some property tests failed.  You probably have an old version of one of the libraries used.");
 }
+static void
+test_unicode_properties_lenient (gconstpointer user_data)
+{
+  test_unicode_properties (user_data, TRUE);
+}
+static void
+test_unicode_properties_strict (gconstpointer user_data)
+{
+  test_unicode_properties (user_data, FALSE);
+}
 
 static hb_codepoint_t
 default_value (hb_codepoint_t _default_value, hb_codepoint_t unicode)
@@ -529,7 +677,7 @@ test_unicode_chainup (void)
 
   g_assert (!hb_unicode_funcs_is_immutable (uf2));
   hb_unicode_funcs_make_immutable (uf2);
-  test_unicode_properties (uf2);
+  test_unicode_properties_strict (uf2);
 
   hb_unicode_funcs_destroy (uf2);
 
@@ -603,7 +751,7 @@ test_unicode_subclassing_nil (data_fixture_t *f, gconstpointer user_data HB_UNUS
   hb_unicode_funcs_destroy (uf);
 
   hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
-                                    &f->data[1], free_up);
+                                   &f->data[1], free_up);
 
   g_assert_cmphex (hb_unicode_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
   g_assert_cmphex (hb_unicode_script (aa, 'b'), ==, HB_SCRIPT_UNKNOWN);
@@ -622,7 +770,7 @@ test_unicode_subclassing_default (data_fixture_t *f, gconstpointer user_data HB_
   aa = hb_unicode_funcs_create (uf);
 
   hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
-                                    &f->data[1], free_up);
+                                   &f->data[1], free_up);
 
   g_assert_cmphex (hb_unicode_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
   g_assert_cmphex (hb_unicode_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
@@ -640,7 +788,7 @@ test_unicode_subclassing_deep (data_fixture_t *f, gconstpointer user_data HB_UNU
   uf = hb_unicode_funcs_create (NULL);
 
   hb_unicode_funcs_set_script_func (uf, simple_get_script,
-                                    &f->data[0], free_up);
+                                   &f->data[0], free_up);
 
   aa = hb_unicode_funcs_create (uf);
 
@@ -650,7 +798,7 @@ test_unicode_subclassing_deep (data_fixture_t *f, gconstpointer user_data HB_UNU
   g_assert (!f->data[0].freed);
 
   hb_unicode_funcs_set_script_func (aa, a_is_for_arabic_get_script,
-                                    &f->data[1], free_up);
+                                   &f->data[1], free_up);
 
   g_assert_cmphex (hb_unicode_script (aa, 'a'), ==, HB_SCRIPT_ARABIC);
   g_assert_cmphex (hb_unicode_script (aa, 'b'), ==, HB_SCRIPT_LATIN);
@@ -755,6 +903,10 @@ test_unicode_normalization (gconstpointer user_data)
   g_assert (hb_unicode_compose (uf, 0xCE20, 0x11B8, &ab) && ab == 0xCE31);
   g_assert (hb_unicode_compose (uf, 0x110E, 0x1173, &ab) && ab == 0xCE20);
 
+  g_assert (!hb_unicode_compose (uf, 0xAC00, 0x11A7, &ab));
+  g_assert (hb_unicode_compose (uf, 0xAC00, 0x11A8, &ab) && ab == 0xAC01);
+  g_assert (!hb_unicode_compose (uf, 0xAC01, 0x11A8, &ab));
+
 
   /* Test decompose() */
 
@@ -796,16 +948,16 @@ main (int argc, char **argv)
   hb_test_add (test_unicode_properties_nil);
   hb_test_add (test_unicode_properties_empty);
 
-  hb_test_add_data_flavor (hb_unicode_funcs_get_default (),          "default", test_unicode_properties);
+  hb_test_add_data_flavor (hb_unicode_funcs_get_default (),          "default", test_unicode_properties_strict);
   hb_test_add_data_flavor (hb_unicode_funcs_get_default (),          "default", test_unicode_normalization);
   hb_test_add_data_flavor ((gconstpointer) script_roundtrip_default, "default", test_unicode_script_roundtrip);
 #ifdef HAVE_GLIB
-  hb_test_add_data_flavor (hb_glib_get_unicode_funcs (),             "glib",    test_unicode_properties);
+  hb_test_add_data_flavor (hb_glib_get_unicode_funcs (),             "glib",    test_unicode_properties_lenient);
   hb_test_add_data_flavor (hb_glib_get_unicode_funcs (),             "glib",    test_unicode_normalization);
   hb_test_add_data_flavor ((gconstpointer) script_roundtrip_glib,    "glib",    test_unicode_script_roundtrip);
 #endif
 #ifdef HAVE_ICU
-  hb_test_add_data_flavor (hb_icu_get_unicode_funcs (),              "icu",     test_unicode_properties);
+  hb_test_add_data_flavor (hb_icu_get_unicode_funcs (),              "icu",     test_unicode_properties_lenient);
   hb_test_add_data_flavor (hb_icu_get_unicode_funcs (),              "icu",     test_unicode_normalization);
   hb_test_add_data_flavor ((gconstpointer) script_roundtrip_icu,     "icu",     test_unicode_script_roundtrip);
 #endif