summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-10 15:18:28 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-08-10 15:18:28 +0000
commit9cf396093dc5eb2f850565ccd7258d64112809d7 (patch)
treefe274319b2b4db780168834096e51f1c54709a72
parentd0613077ea250701197a58db86e2ca636846fcb2 (diff)
parent66efd0c6f163feb65e0ad7c685e3507873ed77fb (diff)
downloadpango-9cf396093dc5eb2f850565ccd7258d64112809d7.tar.gz
Merge branch 'more-tests' into 'main'
Remove some check from test-layout Closes #576 See merge request GNOME/pango!404
-rw-r--r--tests/test-layout.c22
-rw-r--r--tests/testmisc.c53
2 files changed, 55 insertions, 20 deletions
diff --git a/tests/test-layout.c b/tests/test-layout.c
index e533618d..f142228b 100644
--- a/tests/test-layout.c
+++ b/tests/test-layout.c
@@ -479,8 +479,8 @@ test_file (const char *filename, GString *string)
g_assert_cmpint (pango_layout_get_character_count (layout), ==, g_utf8_strlen (pango_layout_get_text (layout), -1));
- /* Some checks on extents - we have to be careful here, since we
- * don't want to depend on font metrics.
+ /* Some checks on extents - we have to be careful here,
+ * since we don't want to depend on font metrics.
*/
pango_layout_get_size (layout, &width, &height);
pango_layout_get_extents (layout, &ink_rect, &logical_rect);
@@ -501,15 +501,12 @@ test_file (const char *filename, GString *string)
for (l = lines; l; l = l->next)
{
PangoLayoutLine *line = l->data;
- int line_height, line_width;
+ int line_width;
int line_x;
PangoRectangle line_ink, line_logical;
PangoRectangle line_ink1, line_logical1;
gboolean done;
- pango_layout_line_get_height (line, &line_height);
- g_assert_cmpint (line_height, <=, height);
-
pango_layout_line_get_extents (line, &line_ink, &line_logical);
line_x = line_logical.x;
line_width = line_logical.width;
@@ -535,7 +532,7 @@ test_file (const char *filename, GString *string)
while (!done && pango_layout_iter_get_line_readonly (iter) == line)
{
int prev_index, index, next_index;
- int x, index2, trailing;
+ int x;
int *ranges;
int n_ranges;
gboolean found_range;
@@ -548,20 +545,9 @@ test_file (const char *filename, GString *string)
done = TRUE;
pango_layout_line_index_to_x (line, index, 0, &x);
- pango_layout_line_x_to_index (line, x, &index2, &trailing);
-
-#if 0
- /* FIXME: why doesn't this hold true? */
- g_assert_cmpint (index2, ==, index);
- g_assert_cmpint (trailing, ==, 0);
-#endif
-
g_assert_cmpint (0, <=, x);
g_assert_cmpint (x, <=, line_width);
- g_assert_cmpint (line->start_index, <=, index2);
- g_assert_cmpint (index2, <=, line->start_index + line->length);
-
if (!run)
break;
diff --git a/tests/testmisc.c b/tests/testmisc.c
index d8275aad..8ebfec80 100644
--- a/tests/testmisc.c
+++ b/tests/testmisc.c
@@ -370,6 +370,54 @@ test_get_cursor (void)
g_object_unref (context);
}
+static void
+test_index_to_x (void)
+{
+ PangoContext *context;
+ const char *tests[] = {
+ "ac­ual­ly", // soft hyphen
+ "ac​ual​ly", // zero-width space
+ };
+
+ context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
+
+ for (int i = 0; i < G_N_ELEMENTS (tests); i++)
+ {
+ PangoLayout *layout;
+ const char *text;
+ const char *p;
+
+ layout = pango_layout_new (context);
+ pango_layout_set_text (layout, tests[i], -1);
+ text = pango_layout_get_text (layout);
+
+ for (p = text; *p; p = g_utf8_next_char (p))
+ {
+ int index = p - text;
+ int l;
+ PangoLayoutLine *line;
+ int x;
+ int index2, trailing;
+ gunichar ch;
+
+ ch = g_utf8_get_char (p);
+
+ pango_layout_index_to_line_x (layout, index, FALSE, &l, NULL);
+ line = pango_layout_get_line (layout, l);
+ g_assert_nonnull (line);
+
+ pango_layout_line_index_to_x (line, index, 0, &x);
+ pango_layout_line_x_to_index (line, x, &index2, &trailing);
+ if (!pango_is_zero_width (ch))
+ g_assert_cmpint (index, ==, index2);
+ }
+
+ g_object_unref (layout);
+ }
+
+ g_object_unref (context);
+}
+
int
main (int argc, char *argv[])
{
@@ -382,8 +430,8 @@ main (int argc, char *argv[])
g_test_add_func ("/language/emoji-crash", test_language_emoji_crash);
g_test_add_func ("/layout/line-height", test_line_height);
g_test_add_func ("/attr-list/update", test_attr_list_update);
- g_test_add_func ("/version-info", test_version_info);
- g_test_add_func ("/is-zerowidth", test_is_zero_width);
+ g_test_add_func ("/misc/version-info", test_version_info);
+ g_test_add_func ("/misc/is-zerowidth", test_is_zero_width);
g_test_add_func ("/gravity/to-rotation", test_gravity_to_rotation);
g_test_add_func ("/gravity/from-matrix", test_gravity_from_matrix);
g_test_add_func ("/gravity/for-script", test_gravity_for_script);
@@ -393,6 +441,7 @@ main (int argc, char *argv[])
#endif
g_test_add_func ("/bidi/get-cursor-crash", test_get_cursor_crash);
g_test_add_func ("/bidi/get-cursor", test_get_cursor);
+ g_test_add_func ("/layout/index-to-x", test_index_to_x);
return g_test_run ();
}