summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-08 15:10:55 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-08-08 15:10:55 +0000
commit3b8231f36e9c4702b696f5031857502928f58cdf (patch)
tree99e852b9df435cd3520e6537069d3f456599dbd4 /tests
parent4d4d9e02892f6ed8496af5e2c6067d650eff3fd5 (diff)
parent46fd479568f98ad94e3e1b0d1935040706d7558c (diff)
downloadpango-3b8231f36e9c4702b696f5031857502928f58cdf.tar.gz
Merge branch 'bidi-revenge' into 'main'
Reimplement pango_layout_move_cursor_visually Closes #587, #585, and #157 See merge request GNOME/pango!389
Diffstat (limited to 'tests')
-rw-r--r--tests/layouts/valid-14.expected2
-rw-r--r--tests/layouts/valid-4.expected2
-rw-r--r--tests/test-bidi.c86
-rw-r--r--tests/test-layout.c9
4 files changed, 87 insertions, 12 deletions
diff --git a/tests/layouts/valid-14.expected b/tests/layouts/valid-14.expected
index 0ab5dcb8..5f15fa9f 100644
--- a/tests/layouts/valid-14.expected
+++ b/tests/layouts/valid-14.expected
@@ -17,7 +17,7 @@ range 0 2147483647
--- cursor positions
-0(0) 3(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 19(0) 17(0) 15(0) 21(0) 22(0) 24(0) 26(0) 28(0) 30(0) 31(0) 33(0) 35(0) 35(1) 38(0)
+0(0) 3(0) 6(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 19(0) 17(0) 15(0) 21(0) 22(0) 24(0) 26(0) 28(0) 30(0) 31(0) 33(0) 35(0) 35(1) 38(0)
--- lines
diff --git a/tests/layouts/valid-4.expected b/tests/layouts/valid-4.expected
index 49688492..f1c6934b 100644
--- a/tests/layouts/valid-4.expected
+++ b/tests/layouts/valid-4.expected
@@ -17,7 +17,7 @@ range 0 2147483647
--- cursor positions
-0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 26(0) 27(0) 28(0) 29(0) 30(0) 30(1) 33(0) 34(0) 35(0) 36(0) 37(0) 38(0) 39(0) 40(0) 41(0) 42(0) 43(0) 44(0) 45(0) 46(0) 47(0) 48(0) 49(0) 50(0) 51(0) 52(0) 53(0) 54(0) 55(0) 56(0) 57(0) 58(0) 59(0) 60(0) 61(0) 62(0) 62(1) 64(0) 65(0) 66(0) 67(0) 68(0) 69(0) 70(0) 71(0) 72(0) 73(0) 74(0) 75(0) 76(0) 77(0) 78(0) 79(0) 80(0) 81(0) 82(0) 83(0) 84(0) 85(0) 87(0) 89(0) 91(0) 92(0) 93(0) 94(0) 94(1) 97(0) 98(0) 100(0) 101(0) 102(0) 103(0) 104(0) 105(0) 106(0) 107(0) 108(0) 109(0) 110(0) 111(0) 112(0) 113(0) 114(0) 115(0) 116(0) 117(0) 118(0) 119(0) 120(0) 121(0) 122(0) 123(0) 123(1) 125(0) 126(0) 127(0) 128(0) 129(0) 130(0) 131(0) 132(0) 133(0) 134(0) 135(0) 136(0) 137(0) 138(0) 139(0) 140(0) 141(0) 142(0) 143(0) 144(0) 145(0) 146(0) 147(0) 148(0) 149(0) 150(0) 150(1) 152(0)
+0(0) 1(0) 2(0) 3(0) 4(0) 5(0) 6(0) 7(0) 8(0) 9(0) 10(0) 11(0) 12(0) 13(0) 14(0) 15(0) 16(0) 17(0) 18(0) 19(0) 20(0) 21(0) 22(0) 23(0) 24(0) 27(0) 28(0) 29(0) 30(0) 30(1) 33(0) 34(0) 35(0) 36(0) 37(0) 38(0) 39(0) 40(0) 41(0) 42(0) 43(0) 44(0) 45(0) 46(0) 47(0) 48(0) 49(0) 50(0) 51(0) 52(0) 53(0) 54(0) 55(0) 56(0) 57(0) 58(0) 59(0) 60(0) 61(0) 62(0) 62(1) 64(0) 65(0) 66(0) 67(0) 68(0) 69(0) 70(0) 71(0) 72(0) 73(0) 74(0) 75(0) 76(0) 77(0) 78(0) 79(0) 80(0) 81(0) 82(0) 83(0) 84(0) 85(0) 87(0) 89(0) 91(0) 92(0) 93(0) 94(0) 94(1) 97(0) 98(0) 101(0) 102(0) 103(0) 104(0) 105(0) 106(0) 107(0) 108(0) 109(0) 110(0) 111(0) 112(0) 113(0) 114(0) 115(0) 116(0) 117(0) 118(0) 119(0) 120(0) 121(0) 122(0) 123(0) 123(1) 125(0) 126(0) 127(0) 128(0) 129(0) 130(0) 131(0) 132(0) 133(0) 134(0) 135(0) 136(0) 137(0) 138(0) 139(0) 140(0) 141(0) 142(0) 143(0) 144(0) 145(0) 146(0) 147(0) 148(0) 149(0) 150(0) 150(1) 152(0)
--- lines
diff --git a/tests/test-bidi.c b/tests/test-bidi.c
index 672aa42f..35f2a39d 100644
--- a/tests/test-bidi.c
+++ b/tests/test-bidi.c
@@ -158,19 +158,21 @@ test_bidi_embedding_levels (void)
}
}
-/* Some basic tests for pango_layout_move_cursor_visually:
+/* Some basic tests for pango_layout_move_cursor_visually inside
+ * a single PangoLayoutLine:
* - check that we actually move the cursor in the right direction
* - check that we get through the line with at most n steps
* - check that we don't skip legitimate cursor positions
*/
static void
-test_move_cursor_visually (void)
+test_move_cursor_line (void)
{
const char *tests[] = {
"abc😂️def",
"abcאבגdef",
"אבabcב",
"aאב12b",
+ "pa­ra­graph", // soft hyphens
};
PangoLayout *layout;
gboolean fail = FALSE;
@@ -205,6 +207,7 @@ test_move_cursor_visually (void)
const char *p;
pango_layout_set_text (layout, tests[i], -1);
+
text = pango_layout_get_text (layout);
line = pango_layout_get_line_readonly (layout, 0);
@@ -267,7 +270,10 @@ test_move_cursor_visually (void)
while (trailing--)
index = g_utf8_next_char (text + index) - text;
- if (index < 0 || index > strlen (text))
+ g_assert (index == -1 || index == G_MAXINT ||
+ (0 <= index && index <= strlen (tests[i])));
+
+ if (index == -1 || index == G_MAXINT)
break;
pango_layout_get_cursor_pos (layout, index, &s_pos, &w_pos);
@@ -278,10 +284,10 @@ test_move_cursor_visually (void)
met_cursor[l] = TRUE;
}
- if ((params[j].direction > 0 && params[j].strong && old_s_pos.x > s_pos.x) ||
- (params[j].direction < 0 && params[j].strong && old_s_pos.x < s_pos.x) ||
- (params[j].direction > 0 && !params[j].strong && old_w_pos.x > w_pos.x) ||
- (params[j].direction < 0 && !params[j].strong && old_w_pos.x < w_pos.x))
+ if ((params[j].direction > 0 && params[j].strong && old_s_pos.x >= s_pos.x) ||
+ (params[j].direction < 0 && params[j].strong && old_s_pos.x <= s_pos.x) ||
+ (params[j].direction > 0 && !params[j].strong && old_w_pos.x >= w_pos.x) ||
+ (params[j].direction < 0 && !params[j].strong && old_w_pos.x <= w_pos.x))
{
if (g_test_verbose ())
g_print ("(wrong move)\t");
@@ -325,9 +331,70 @@ test_move_cursor_visually (void)
g_object_unref (layout);
if (fail)
- g_test_skip ("known to fail");
+ 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 },
+ { "你好 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[])
@@ -345,7 +412,8 @@ main (int argc, char *argv[])
g_test_add_func ("/bidi/type-for-unichar", test_bidi_type_for_unichar);
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-visually", test_move_cursor_visually);
+ 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 ();
}
diff --git a/tests/test-layout.c b/tests/test-layout.c
index f35d839e..e533618d 100644
--- a/tests/test-layout.c
+++ b/tests/test-layout.c
@@ -194,15 +194,22 @@ dump_directions (PangoLayout *layout, GString *string)
static void
dump_cursor_positions (PangoLayout *layout, GString *string)
{
+ const char *text;
int index, trailing;
+ text = pango_layout_get_text (layout);
+
index = 0;
trailing = 0;
while (index < G_MAXINT)
{
g_string_append_printf (string, "%d(%d) ", index, trailing);
- pango_layout_move_cursor_visually (layout, TRUE, index, trailing, 1, &index, &trailing);
+
+ while (trailing--)
+ index = g_utf8_next_char (text + index) - text;
+
+ pango_layout_move_cursor_visually (layout, TRUE, index, 0, 1, &index, &trailing);
}
g_string_append (string, "\n");