From d53e5123b6fa797495af4f0cb5ceb69074278d8f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 4 Aug 2021 18:07:40 -0400 Subject: Add a test for pango_layout_get_cursor_pos This checks that we get split cursors in some cases where we expect it. One of the cases was broken until the previous commit. --- tests/testmisc.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/testmisc.c b/tests/testmisc.c index c305a168..54566f78 100644 --- a/tests/testmisc.c +++ b/tests/testmisc.c @@ -329,6 +329,42 @@ test_get_cursor_crash (void) g_object_unref (context); } +/* Test that get_cursor returns split cursors in the + * expected situations. In particular, this was broken + * at the end of the string here. + */ +static void +test_get_cursor (void) +{ + const char *text = "abאב"; + PangoContext *context; + PangoLayout *layout; + PangoRectangle strong, weak; + + context = pango_font_map_create_context (pango_cairo_font_map_get_default ()); + + layout = pango_layout_new (context); + pango_layout_set_text (layout, text, -1); + + pango_layout_get_cursor_pos (layout, 0, &strong, &weak); + g_assert_cmpint (strong.x, ==, weak.x); + + pango_layout_get_cursor_pos (layout, 1, &strong, &weak); + g_assert_cmpint (strong.x, ==, weak.x); + + pango_layout_get_cursor_pos (layout, 2, &strong, &weak); + g_assert_cmpint (strong.x, !=, weak.x); + + pango_layout_get_cursor_pos (layout, 4, &strong, &weak); + g_assert_cmpint (strong.x, ==, weak.x); + + pango_layout_get_cursor_pos (layout, 6, &strong, &weak); + g_assert_cmpint (strong.x, !=, weak.x); + + g_object_unref (layout); + g_object_unref (context); +} + int main (int argc, char *argv[]) { @@ -349,6 +385,7 @@ main (int argc, char *argv[]) g_test_add_func ("/layout/fallback-shape", test_fallback_shape); g_test_add_func ("/language/to-tag", test_language_to_tag); g_test_add_func ("/bidi/get-cursor-crash", test_get_cursor_crash); + g_test_add_func ("/bidi/get-cursor", test_get_cursor); return g_test_run (); } -- cgit v1.2.1