[pango/bidi-revenge: 2/2] Add a multi-line test




commit 076eb34ffa6ff5141946493dbc10894101ccb041
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Aug 6 12:53:35 2021 -0400

    Add a multi-line test
    
    Test the line end handling of
    pango_layout_move_cursor_visually.

 tests/test-bidi.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
---
diff --git a/tests/test-bidi.c b/tests/test-bidi.c
index 724310c0..719ef588 100644
--- a/tests/test-bidi.c
+++ b/tests/test-bidi.c
@@ -334,6 +334,64 @@ 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 ac­tual­ly have multiple lines, unlike all the other wannabe äöü pa­ra­graph 
tests in this ugh test-case. Grow some lines!\n", 188 },
+  };
+  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 +409,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 ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]