diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-08-06 12:53:35 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-08-08 10:52:23 -0400 |
commit | c4529d66c93fa45fe4df9653bea5fe64d5905e7a (patch) | |
tree | 831a29fe2936e11c71b32735ffb9abd512a83c13 | |
parent | e4af060a99ad16db0e764c13e2cad78e612bd063 (diff) | |
download | pango-c4529d66c93fa45fe4df9653bea5fe64d5905e7a.tar.gz |
Add multi-line tests for move-cursor
Test the line end handling of
pango_layout_move_cursor_visually.
-rw-r--r-- | tests/test-bidi.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/test-bidi.c b/tests/test-bidi.c index cfd6b288..35f2a39d 100644 --- a/tests/test-bidi.c +++ b/tests/test-bidi.c @@ -334,6 +334,68 @@ test_move_cursor_line (void) g_test_fail (); } +static void +test_move_cursor_para (void) +{ + struct { + const char *text; + int width; + } tests[] = { + { "This paragraph should actually have multiple lines, unlike all the other wannabe äöü paragraph tests in this ugh test-case. Grow some lines!\n", 188 }, + { "你好 Hello שלום Γειά σας", 40 }, + { "你好 Hello שלום Γειά σας", 60 }, + { "你好 Hello שלום Γειά σας", 80 }, + { "line 1
line 2
line 3\nline 4\r\nline 5", -1 }, // various separators + }; + PangoLayout *layout; + PangoRectangle pos, old_pos; + int index; + int trailing; + const char *text; + + layout = pango_layout_new (context); + + for (int i = 0; i < G_N_ELEMENTS (tests); i++) + { + pango_layout_set_text (layout, tests[i].text, -1); + text = pango_layout_get_text (layout); + if (tests[i].width > 0) + pango_layout_set_width (layout, tests[i].width * PANGO_SCALE); + else + pango_layout_set_width (layout, -1); + + index = 0; + pango_layout_get_cursor_pos (layout, index, &pos, NULL); + + while (index < G_MAXINT) + { + old_pos = pos; + + pango_layout_move_cursor_visually (layout, TRUE, + index, 0, + 1, + &index, &trailing); + while (trailing--) + index = g_utf8_next_char (text + index) - text; + + g_assert (index == -1 || index == G_MAXINT || + (0 <= index && index <= strlen (tests[i].text))); + + if (index == -1 || index == G_MAXINT) + break; + + if (index >= strlen (tests[i].text) - 1) + break; + + pango_layout_get_cursor_pos (layout, index, &pos, NULL); + g_assert_true (pos.y > old_pos.y || + (pos.y == old_pos.y && pos.x > old_pos.x)); + } + } + + g_object_unref (layout); +} + int main (int argc, char *argv[]) { @@ -351,6 +413,7 @@ main (int argc, char *argv[]) g_test_add_func ("/bidi/unichar-direction", test_unichar_direction); g_test_add_func ("/bidi/embedding-levels", test_bidi_embedding_levels); g_test_add_func ("/bidi/move-cursor-line", test_move_cursor_line); + g_test_add_func ("/bidi/move-cursor-para", test_move_cursor_para); return g_test_run (); } |