diff options
Diffstat (limited to 'test/api/test-buffer.c')
-rw-r--r-- | test/api/test-buffer.c | 123 |
1 files changed, 112 insertions, 11 deletions
diff --git a/test/api/test-buffer.c b/test/api/test-buffer.c index ab818d0..17607f1 100644 --- a/test/api/test-buffer.c +++ b/test/api/test-buffer.c @@ -71,7 +71,7 @@ fixture_init (fixture_t *fixture, gconstpointer user_data) case BUFFER_ONE_BY_ONE: for (i = 1; i < G_N_ELEMENTS (utf32) - 1; i++) - hb_buffer_add (b, utf32[i], 1, i); + hb_buffer_add (b, utf32[i], i); break; case BUFFER_UTF32: @@ -127,8 +127,44 @@ test_buffer_properties (fixture_t *fixture, gconstpointer user_data) hb_buffer_set_language (b, hb_language_from_string ("fa", -1)); g_assert (hb_buffer_get_language (b) == hb_language_from_string ("Fa", -1)); + hb_buffer_set_flags (b, HB_BUFFER_FLAG_BOT); + g_assert (hb_buffer_get_flags (b) == HB_BUFFER_FLAG_BOT); - /* test reset clears properties */ + hb_buffer_set_replacement_codepoint (b, (unsigned int) -1); + g_assert (hb_buffer_get_replacement_codepoint (b) == (unsigned int) -1); + + + /* test clear_contents clears all these properties: */ + + hb_buffer_clear_contents (b); + + g_assert (hb_buffer_get_unicode_funcs (b) == ufuncs); + g_assert (hb_buffer_get_direction (b) == HB_DIRECTION_INVALID); + g_assert (hb_buffer_get_script (b) == HB_SCRIPT_INVALID); + g_assert (hb_buffer_get_language (b) == NULL); + + /* but not these: */ + + g_assert (hb_buffer_get_flags (b) != HB_BUFFER_FLAGS_DEFAULT); + g_assert (hb_buffer_get_replacement_codepoint (b) != HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT); + + + /* test reset clears all properties */ + + hb_buffer_set_direction (b, HB_DIRECTION_RTL); + g_assert (hb_buffer_get_direction (b) == HB_DIRECTION_RTL); + + hb_buffer_set_script (b, HB_SCRIPT_ARABIC); + g_assert (hb_buffer_get_script (b) == HB_SCRIPT_ARABIC); + + hb_buffer_set_language (b, hb_language_from_string ("fa", -1)); + g_assert (hb_buffer_get_language (b) == hb_language_from_string ("Fa", -1)); + + hb_buffer_set_flags (b, HB_BUFFER_FLAG_BOT); + g_assert (hb_buffer_get_flags (b) == HB_BUFFER_FLAG_BOT); + + hb_buffer_set_replacement_codepoint (b, (unsigned int) -1); + g_assert (hb_buffer_get_replacement_codepoint (b) == (unsigned int) -1); hb_buffer_reset (b); @@ -136,6 +172,8 @@ test_buffer_properties (fixture_t *fixture, gconstpointer user_data) g_assert (hb_buffer_get_direction (b) == HB_DIRECTION_INVALID); g_assert (hb_buffer_get_script (b) == HB_SCRIPT_INVALID); g_assert (hb_buffer_get_language (b) == NULL); + g_assert (hb_buffer_get_flags (b) == HB_BUFFER_FLAGS_DEFAULT); + g_assert (hb_buffer_get_replacement_codepoint (b) == HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT); } static void @@ -152,7 +190,7 @@ test_buffer_contents (fixture_t *fixture, gconstpointer user_data) } len = hb_buffer_get_length (b); - glyphs = hb_buffer_get_glyph_infos (b, NULL); /* test NULL */ + hb_buffer_get_glyph_infos (b, NULL); /* test NULL */ glyphs = hb_buffer_get_glyph_infos (b, &len2); g_assert_cmpint (len, ==, len2); g_assert_cmpint (len, ==, 5); @@ -264,7 +302,7 @@ test_buffer_positions (fixture_t *fixture, gconstpointer user_data) /* Without shaping, positions should all be zero */ len = hb_buffer_get_length (b); - positions = hb_buffer_get_glyph_positions (b, NULL); /* test NULL */ + hb_buffer_get_glyph_positions (b, NULL); /* test NULL */ positions = hb_buffer_get_glyph_positions (b, &len2); g_assert_cmpint (len, ==, len2); for (i = 0; i < len; i++) { @@ -345,6 +383,7 @@ test_buffer_utf8_conversion (void) unsigned int bytes, chars, i, j, len; b = hb_buffer_create (); + hb_buffer_set_replacement_codepoint (b, (hb_codepoint_t) -1); for (i = 0; i < G_N_ELEMENTS (utf8_conversion_tests); i++) { @@ -359,7 +398,7 @@ test_buffer_utf8_conversion (void) for (chars = 0; test->codepoints[chars]; chars++) ; - hb_buffer_reset (b); + hb_buffer_clear_contents (b); hb_buffer_add_utf8 (b, test->utf8, bytes, 1, bytes - 2); glyphs = hb_buffer_get_glyph_infos (b, &len); @@ -420,11 +459,15 @@ static const utf8_validity_test_t utf8_validity_tests[] = { { "\x7f", -1, 1, TRUE }, { "\xdf\xbf", -1, 2, TRUE }, { "\xef\xbf\xbf", -1, 0, TRUE }, - { "\xf7\xbf\xbf\xbf", -1, 0, TRUE }, + { "\xf4\x8f\xbf\xbf", -1, 0, TRUE }, + { "\xf4\x90\xbf\xbf", -1, 0, FALSE }, + { "\xf7\xbf\xbf\xbf", -1, 0, FALSE }, { "\xfb\xbf\xbf\xbf\xbf", -1, 0, FALSE }, { "\xfd\xbf\xbf\xbf\xbf\xbf", -1, 0, FALSE }, /* other boundary conditions */ { "\xed\x9f\xbf", -1, 3, TRUE }, + { "\xed\xa0\x80", -1, 0, FALSE }, + { "\xed\xbf\xbf", -1, 0, FALSE }, { "\xee\x80\x80", -1, 3, TRUE }, { "\xef\xbf\xbd", -1, 3, TRUE }, { "\xf4\x8f\xbf\xbf", -1, 0, TRUE }, @@ -581,8 +624,6 @@ static const utf8_validity_test_t utf8_validity_tests[] = { /* impossible bytes */ { "\x20\xfe\x20", -1, 1, FALSE }, { "\x20\xff\x20", -1, 1, FALSE }, -#if 0 - /* XXX fix these, or document that we don't detect them? */ /* overlong sequences */ { "\x20\xc0\xaf\x20", -1, 1, FALSE }, { "\x20\xe0\x80\xaf\x20", -1, 1, FALSE }, @@ -615,6 +656,7 @@ static const utf8_validity_test_t utf8_validity_tests[] = { { "\x20\xed\xae\x80\xed\xbf\xbf\x20", -1, 1, FALSE }, { "\x20\xed\xaf\xbf\xed\xb0\x80\x20", -1, 1, FALSE }, { "\x20\xed\xaf\xbf\xed\xbf\xbf\x20", -1, 1, FALSE }, +#if 0 /* We don't consider U+FFFE / U+FFFF and similar invalid. */ { "\x20\xef\xbf\xbe\x20", -1, 1, FALSE }, { "\x20\xef\xbf\xbf\x20", -1, 1, FALSE }, #endif @@ -628,6 +670,7 @@ test_buffer_utf8_validity (void) unsigned int i; b = hb_buffer_create (); + hb_buffer_set_replacement_codepoint (b, (hb_codepoint_t) -1); for (i = 0; i < G_N_ELEMENTS (utf8_validity_tests); i++) { @@ -646,7 +689,7 @@ test_buffer_utf8_validity (void) else segment_bytes = test->max_len; - hb_buffer_reset (b); + hb_buffer_clear_contents (b); hb_buffer_add_utf8 (b, test->utf8, text_bytes, 0, segment_bytes); glyphs = hb_buffer_get_glyph_infos (b, &len); @@ -675,7 +718,8 @@ static const utf16_conversion_test_t utf16_conversion_tests[] = { {{0x41, 0xD800, 0xDF02}, {-1}}, {{0x41, 0x61, 0xD800, 0xDF02}, {0x61, -1}}, {{0x41, 0xD800, 0x61, 0xDF02}, {-1, 0x61}}, - {{0x41, 0x61}, {}} + {{0x41, 0xDF00, 0x61}, {-1}}, + {{0x41, 0x61}, {0}} }; static void @@ -685,6 +729,7 @@ test_buffer_utf16_conversion (void) unsigned int i; b = hb_buffer_create (); + hb_buffer_set_replacement_codepoint (b, (hb_codepoint_t) -1); for (i = 0; i < G_N_ELEMENTS (utf16_conversion_tests); i++) { @@ -699,7 +744,7 @@ test_buffer_utf16_conversion (void) for (chars = 0; test->codepoints[chars]; chars++) ; - hb_buffer_reset (b); + hb_buffer_clear_contents (b); hb_buffer_add_utf16 (b, test->utf16, u_len, 1, u_len - 2); glyphs = hb_buffer_get_glyph_infos (b, &len); @@ -711,6 +756,61 @@ test_buffer_utf16_conversion (void) hb_buffer_destroy (b); } + +typedef struct { + const uint32_t utf32[8]; + const uint32_t codepoints[8]; +} utf32_conversion_test_t; + +/* note: we skip the first and last item from utf32 when adding to buffer */ +static const utf32_conversion_test_t utf32_conversion_tests[] = { + {{0x41, 0x004D, 0x0430, 0x4E8C, 0xD800, 0xDF02, 0x61} , {0x004D, 0x0430, 0x4E8C, -3, -3}}, + {{0x41, 0x004D, 0x0430, 0x4E8C, 0x10302, 0x61} , {0x004D, 0x0430, 0x4E8C, 0x10302}}, + {{0x41, 0xD800, 0xDF02, 0x61}, {-3, -3}}, + {{0x41, 0xD800, 0xDF02}, {-3}}, + {{0x41, 0x61, 0xD800, 0xDF02}, {0x61, -3}}, + {{0x41, 0xD800, 0x61, 0xDF02}, {-3, 0x61}}, + {{0x41, 0xDF00, 0x61}, {-3}}, + {{0x41, 0x10FFFF, 0x61}, {0x10FFFF}}, + {{0x41, 0x110000, 0x61}, {-3}}, + {{0x41, 0x61}, {0}} +}; + +static void +test_buffer_utf32_conversion (void) +{ + hb_buffer_t *b; + unsigned int i; + + b = hb_buffer_create (); + hb_buffer_set_replacement_codepoint (b, (hb_codepoint_t) -3); + + for (i = 0; i < G_N_ELEMENTS (utf32_conversion_tests); i++) + { + const utf32_conversion_test_t *test = &utf32_conversion_tests[i]; + unsigned int u_len, chars, j, len; + hb_glyph_info_t *glyphs; + + g_test_message ("UTF-32 test #%d", i); + + for (u_len = 0; test->utf32[u_len]; u_len++) + ; + for (chars = 0; test->codepoints[chars]; chars++) + ; + + hb_buffer_clear_contents (b); + hb_buffer_add_utf32 (b, test->utf32, u_len, 1, u_len - 2); + + glyphs = hb_buffer_get_glyph_infos (b, &len); + g_assert_cmpint (len, ==, chars); + for (j = 0; j < chars; j++) + g_assert_cmphex (glyphs[j].codepoint, ==, test->codepoints[j]); + } + + hb_buffer_destroy (b); +} + + static void test_empty (hb_buffer_t *b) { @@ -777,6 +877,7 @@ main (int argc, char **argv) hb_test_add (test_buffer_utf8_conversion); hb_test_add (test_buffer_utf8_validity); hb_test_add (test_buffer_utf16_conversion); + hb_test_add (test_buffer_utf32_conversion); hb_test_add (test_buffer_empty); return hb_test_run(); |