diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/layouts/valid-6.expected | 25 | ||||
-rw-r--r-- | tests/layouts/valid-6.markup | 2 | ||||
-rw-r--r-- | tests/meson.build | 10 | ||||
-rw-r--r-- | tests/test-break.c | 57 | ||||
-rw-r--r-- | tests/test-common.c | 12 | ||||
-rw-r--r-- | tests/test-itemize.c | 5 | ||||
-rw-r--r-- | tests/test-layout.c | 16 | ||||
-rw-r--r-- | tests/testattributes.c | 208 | ||||
-rw-r--r-- | tests/testboundaries_ucd.c | 3 | ||||
-rw-r--r-- | tests/testcolor.c | 114 | ||||
-rw-r--r-- | tests/testmisc.c | 35 |
11 files changed, 423 insertions, 64 deletions
diff --git a/tests/layouts/valid-6.expected b/tests/layouts/valid-6.expected new file mode 100644 index 00000000..b8f90c34 --- /dev/null +++ b/tests/layouts/valid-6.expected @@ -0,0 +1,25 @@ + 0️⃣ Keycap Digit Zero + +--- parameters + +wrapped: 0 +ellipsized: 0 +lines: 2 + +--- attributes + +range 0 2147483647 + +--- lines + +i=1, index=0, paragraph-start=1, dir=ltr ' 0️⃣ Keycap Digit Zero +' +i=2, index=27, paragraph-start=1, dir=ltr '' + +--- runs + +i=1, index=0, chars=1, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, ' ' +i=2, index=1, chars=3, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, '0️⃣' +i=3, index=8, chars=18, level=0, gravity=south, flags=0, font=OMITTED, script=latin, language=en-us, ' Keycap Digit Zero' +i=4, index=26, no run, line end +i=5, index=27, no run, line end diff --git a/tests/layouts/valid-6.markup b/tests/layouts/valid-6.markup new file mode 100644 index 00000000..92c53e28 --- /dev/null +++ b/tests/layouts/valid-6.markup @@ -0,0 +1,2 @@ + + 0️⃣ Keycap Digit Zero diff --git a/tests/meson.build b/tests/meson.build index 234fbf63..6e10e2b7 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -20,11 +20,7 @@ tests = [ [ 'testboundaries' ], [ 'testboundaries_ucd' ], [ 'testcolor' ], - [ 'testmisc', [ 'testmisc.c' ], [ libpangocairo_dep ] ], - [ 'testscript' ], - [ 'test-harfbuzz', [ 'test-harfbuzz.c' ], [ libpangocairo_dep ] ], - [ 'cxx-test', [ 'cxx-test.cpp' ], [ libpangocairo_dep ] ], - [ 'test-break', [ 'test-break.c', 'test-common.c' ], [libpangocairo_dep ] ], + [ 'testscript' ] ] if build_pangoft2 @@ -45,6 +41,10 @@ if cairo_dep.found() [ 'test-shape', [ 'test-shape.c', 'test-common.c' ], [ libpangocairo_dep ] ], [ 'test-font', [ 'test-font.c' ], [ libpangocairo_dep ] ], [ 'testattributes', [ 'testattributes.c', 'test-common.c' ], [ libpangocairo_dep ] ], + [ 'testmisc', [ 'testmisc.c' ], [ libpangocairo_dep, glib_dep, harfbuzz_dep ] ], + [ 'cxx-test', [ 'cxx-test.cpp' ], [ libpangocairo_dep, gobject_dep, harfbuzz_dep ] ], + [ 'test-harfbuzz', [ 'test-harfbuzz.c' ], [ libpangocairo_dep, gobject_dep, harfbuzz_dep ] ], + [ 'test-break', [ 'test-break.c', 'test-common.c' ], [libpangocairo_dep, glib_dep, harfbuzz_dep ] ] ] if pango_cairo_backends.contains('png') diff --git a/tests/test-break.c b/tests/test-break.c index df9b78e2..c4359643 100644 --- a/tests/test-break.c +++ b/tests/test-break.c @@ -34,7 +34,7 @@ static PangoContext *context; -static void +static gboolean test_file (const gchar *filename, GString *string) { gchar *contents; @@ -62,7 +62,6 @@ test_file (const gchar *filename, GString *string) length = strlen (test); len = g_utf8_strlen (test, -1) + 1; - attrs = g_new (PangoLogAttr, len); pango_parse_markup (test, -1, 0, &attributes, &text, NULL, &error); g_assert_no_error (error); @@ -73,9 +72,17 @@ test_file (const gchar *filename, GString *string) if (pango_layout_get_unknown_glyphs_count (layout) > 0) { +#if 0 + // See https://github.com/mesonbuild/meson/issues/7515 char *msg = g_strdup_printf ("Missing glyphs - skipping %s. Maybe fonts are missing?", filename); g_test_skip (msg); g_free (msg); +#endif + g_free (contents); + g_object_unref (layout); + pango_attr_list_unref (attributes); + g_free (text); + return FALSE; } pango_layout_get_log_attrs (layout, &attrs, &len); @@ -221,7 +228,10 @@ test_file (const gchar *filename, GString *string) g_object_unref (layout); g_free (attrs); g_free (contents); + g_free (text); pango_attr_list_unref (attributes); + + return TRUE; } static gchar * @@ -249,26 +259,36 @@ test_break (gconstpointer d) GString *dump; gchar *diff; - const char *old_locale = setlocale (LC_ALL, NULL); + char *old_locale = g_strdup (setlocale (LC_ALL, NULL)); setlocale (LC_ALL, "en_US.utf8"); if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL) { +#if 0 + // See https://github.com/mesonbuild/meson/issues/7515 char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping break %s", filename); g_test_skip (msg); g_free (msg); +#endif + g_free (old_locale); return; } - expected_file = get_expected_filename (filename); - dump = g_string_sized_new (0); - test_file (filename, dump); + if (!test_file (filename, dump)) + { + g_free (old_locale); + g_string_free (dump, TRUE); + return; + } + + expected_file = get_expected_filename (filename); diff = diff_with_file (expected_file, dump->str, dump->len, &error); g_assert_no_error (error); setlocale (LC_ALL, old_locale); + g_free (old_locale); if (diff && diff[0]) { @@ -284,9 +304,9 @@ test_break (gconstpointer d) g_test_fail (); g_strfreev (lines); - g_free (diff); } + g_free (diff); g_string_free (dump, TRUE); g_free (expected_file); } @@ -308,11 +328,26 @@ main (int argc, char *argv[]) /* allow to easily generate expected output for new test cases */ if (argc > 1) { - GString *string; + if (strcmp (argv[1], "--help") == 0) + { + g_print ("test-break uses the following symbols for log attrs\n\n"); + g_print ("Breaks: Words:\n" + " L - mandatory break b - word boundary\n" + " l - line break s - word start\n" + " c - char break e - word end\n" + "\n" + "Whitespace: Sentences:\n" + " x - expandable space s - sentence start\n" + " w - whitespace e - sentence end\n"); + } + else + { + GString *string; - string = g_string_sized_new (0); - test_file (argv[1], string); - g_test_message ("%s", string->str); + string = g_string_sized_new (0); + test_file (argv[1], string); + g_print ("%s", string->str); + } return 0; } diff --git a/tests/test-common.c b/tests/test-common.c index 786973f1..60ecb7e1 100644 --- a/tests/test-common.c +++ b/tests/test-common.c @@ -125,14 +125,22 @@ print_attribute (PangoAttribute *attr, GString *string) g_string_append_printf (string, "%d", ((PangoAttrInt *)attr)->value); break; case PANGO_ATTR_FONT_DESC: - g_string_append_printf (string, "%s", pango_font_description_to_string (((PangoAttrFontDesc *)attr)->desc)); + { + char *text = pango_font_description_to_string (((PangoAttrFontDesc *)attr)->desc); + g_string_append_printf (string, "%s", text); + g_free (text); + } break; case PANGO_ATTR_FOREGROUND: case PANGO_ATTR_BACKGROUND: case PANGO_ATTR_UNDERLINE_COLOR: case PANGO_ATTR_OVERLINE_COLOR: case PANGO_ATTR_STRIKETHROUGH_COLOR: - g_string_append_printf (string, "%s", pango_color_to_string (&((PangoAttrColor *)attr)->color)); + { + char *text = pango_color_to_string (&((PangoAttrColor *)attr)->color); + g_string_append_printf (string, "%s", text); + g_free (text); + } break; case PANGO_ATTR_SHAPE: g_string_append_printf (string, "shape"); diff --git a/tests/test-itemize.c b/tests/test-itemize.c index 3c58e18f..b22f3c2f 100644 --- a/tests/test-itemize.c +++ b/tests/test-itemize.c @@ -241,9 +241,12 @@ test_itemize (gconstpointer d) setlocale (LC_ALL, "en_US.utf8"); if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL) { +#if 0 + // See https://github.com/mesonbuild/meson/issues/7515 char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping itemization %s", filename); g_test_skip (msg); g_free (msg); +#endif return; } @@ -274,9 +277,9 @@ test_itemize (gconstpointer d) g_test_fail (); g_strfreev (lines); - g_free (diff); } + g_free (diff); g_string_free (dump, TRUE); g_free (expected_file); } diff --git a/tests/test-layout.c b/tests/test-layout.c index 52617ce6..a5b6d279 100644 --- a/tests/test-layout.c +++ b/tests/test-layout.c @@ -238,6 +238,9 @@ test_file (const gchar *filename, GString *string) PangoWrapMode wrap = PANGO_WRAP_WORD; PangoFontDescription *desc; + if (context == NULL) + context = pango_font_map_create_context (pango_cairo_font_map_get_default ()); + g_file_get_contents (filename, &contents, &length, &error); g_assert_no_error (error); @@ -308,9 +311,12 @@ test_layout (gconstpointer d) setlocale (LC_ALL, "en_US.utf8"); if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL) { +#if 0 + // See https://github.com/mesonbuild/meson/issues/7515 char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping layout %s", filename); g_test_skip (msg); g_free (msg); +#endif return; } @@ -341,9 +347,9 @@ test_layout (gconstpointer d) g_test_fail (); g_strfreev (lines); - g_free (diff); } + g_free (diff); g_string_free (dump, TRUE); g_free (expected_file); } @@ -356,13 +362,13 @@ main (int argc, char *argv[]) const gchar *name; gchar *path; - g_test_init (&argc, &argv, NULL); - /* allow to easily generate expected output for new test cases */ - if (argc > 1) + if (argc > 1 && argv[1][0] != '-') { GString *string; + setlocale (LC_ALL, "en_US.utf8"); + string = g_string_sized_new (0); test_file (argv[1], string); g_test_message ("%s", string->str); @@ -370,6 +376,8 @@ main (int argc, char *argv[]) return 0; } + g_test_init (&argc, &argv, NULL); + path = g_test_build_filename (G_TEST_DIST, "layouts", NULL); dir = g_dir_open (path, 0, &error); g_free (path); diff --git a/tests/testattributes.c b/tests/testattributes.c index d6c8c87c..6131f38c 100644 --- a/tests/testattributes.c +++ b/tests/testattributes.c @@ -99,7 +99,12 @@ assert_attributes (GSList *attrs, s = g_string_new (""); print_attributes (attrs, s); - g_assert_cmpstr (s->str, ==, expected); + if (strcmp (s->str, expected) != 0) + { + g_print ("-----\nattribute list mismatch\nexpected:\n%s-----\nreceived:\n%s-----\n", + expected, s->str); + g_assert_not_reached (); + } g_string_free (s, TRUE); } @@ -298,6 +303,41 @@ test_list_splice (void) pango_attr_list_unref (base); } +/* Test that empty lists work in pango_attr_list_splice */ +static void +test_list_splice2 (void) +{ + PangoAttrList *list; + PangoAttrList *other; + PangoAttribute *attr; + + list = pango_attr_list_new (); + other = pango_attr_list_new (); + + pango_attr_list_splice (list, other, 11, 5); + + g_assert_null (pango_attr_list_get_attributes (list)); + + attr = pango_attr_size_new (10); + attr->start_index = 0; + attr->end_index = -1; + pango_attr_list_insert (other, attr); + + pango_attr_list_splice (list, other, 11, 5); + + assert_attr_list (list, "[11,-1]size=10\n"); + + pango_attr_list_unref (other); + other = pango_attr_list_new (); + + pango_attr_list_splice (list, other, 11, 5); + + assert_attr_list (list, "[11,-1]size=10\n"); + + pango_attr_list_unref (other); + pango_attr_list_unref (list); +} + static gboolean never_true (PangoAttribute *attribute, gpointer user_data) { @@ -618,6 +658,20 @@ test_list_update (void) pango_attr_list_unref (list); } +/* Test that empty lists work in pango_attr_list_update */ +static void +test_list_update2 (void) +{ + PangoAttrList *list; + + list = pango_attr_list_new (); + pango_attr_list_update (list, 8, 10, 20); + + g_assert_null (pango_attr_list_get_attributes (list)); + + pango_attr_list_unref (list); +} + static void test_list_equal (void) { @@ -830,6 +884,154 @@ test_merge (void) pango_attr_list_unref (list2); } +/* reproduce what the links example in gtk4-demo does + * with the colored Google link + */ +static void +test_merge2 (void) +{ + PangoAttrList *list; + PangoAttribute *attr; + + list = pango_attr_list_new (); + attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); + attr->start_index = 0; + attr->end_index = 10; + pango_attr_list_insert (list, attr); + attr = pango_attr_foreground_new (0, 0, 0xffff); + attr->start_index = 0; + attr->end_index = 10; + pango_attr_list_insert (list, attr); + + assert_attr_list (list, "[0,10]underline=1\n" + "[0,10]foreground=#00000000ffff\n"); + + attr = pango_attr_foreground_new (0xffff, 0, 0); + attr->start_index = 2; + attr->end_index = 3; + + pango_attr_list_change (list, attr); + + assert_attr_list (list, "[0,10]underline=1\n" + "[0,2]foreground=#00000000ffff\n" + "[2,3]foreground=#ffff00000000\n" + "[3,10]foreground=#00000000ffff\n"); + + attr = pango_attr_foreground_new (0, 0xffff, 0); + attr->start_index = 3; + attr->end_index = 4; + + pango_attr_list_change (list, attr); + + assert_attr_list (list, "[0,10]underline=1\n" + "[0,2]foreground=#00000000ffff\n" + "[2,3]foreground=#ffff00000000\n" + "[3,4]foreground=#0000ffff0000\n" + "[4,10]foreground=#00000000ffff\n"); + + attr = pango_attr_foreground_new (0, 0, 0xffff); + attr->start_index = 4; + attr->end_index = 5; + + pango_attr_list_change (list, attr); + + assert_attr_list (list, "[0,10]underline=1\n" + "[0,2]foreground=#00000000ffff\n" + "[2,3]foreground=#ffff00000000\n" + "[3,4]foreground=#0000ffff0000\n" + "[4,10]foreground=#00000000ffff\n"); + + pango_attr_list_unref (list); +} + +/* This only prints rise, size and scale, which are the + * only relevant attributes in the test that uses this + * function. + */ +static void +print_tags_for_attributes (PangoAttrIterator *iter, + GString *s) +{ + PangoAttribute *attr; + + attr = pango_attr_iterator_get (iter, PANGO_ATTR_RISE); + if (attr) + g_string_append_printf (s, "[%d, %d]rise=%d\n", + attr->start_index, attr->end_index, + ((PangoAttrInt*)attr)->value); + + attr = pango_attr_iterator_get (iter, PANGO_ATTR_SIZE); + if (attr) + g_string_append_printf (s, "[%d, %d]size=%d\n", + attr->start_index, attr->end_index, + ((PangoAttrInt*)attr)->value); + + attr = pango_attr_iterator_get (iter, PANGO_ATTR_SCALE); + if (attr) + g_string_append_printf (s, "[%d, %d]scale=%f\n", + attr->start_index, attr->end_index, + ((PangoAttrFloat*)attr)->value); +} + +static void +test_iter_epsilon_zero (void) +{ + const char *markup = "𝜀<span rise=\"-6000\" size=\"x-small\" font_desc=\"italic\">0</span> = 𝜔<span rise=\"8000\" size=\"smaller\">𝜔<span rise=\"14000\" size=\"smaller\">𝜔<span rise=\"20000\">.<span rise=\"23000\">.<span rise=\"26000\">.</span></span></span></span></span>"; + PangoAttrList *attributes; + PangoAttrIterator *attr; + char *text; + GError *error = NULL; + GString *s; + + s = g_string_new (""); + + pango_parse_markup (markup, -1, 0, &attributes, &text, NULL, &error); + g_assert_no_error (error); + g_assert_cmpstr (text, ==, "𝜀0 = 𝜔𝜔𝜔..."); + + attr = pango_attr_list_get_iterator (attributes); + do + { + int start, end; + + pango_attr_iterator_range (attr, &start, &end); + + g_string_append_printf (s, "range: [%d, %d]\n", start, end); + + print_tags_for_attributes (attr, s); + } + while (pango_attr_iterator_next (attr)); + + g_assert_cmpstr (s->str, ==, + "range: [0, 4]\n" + "range: [4, 5]\n" + "[4, 5]rise=-6000\n" + "[4, 5]scale=0.694444\n" + "range: [5, 12]\n" + "range: [12, 16]\n" + "[12, 23]rise=8000\n" + "[12, 23]scale=0.833333\n" + "range: [16, 20]\n" + "[16, 23]rise=14000\n" + "[16, 23]scale=0.694444\n" + "range: [20, 21]\n" + "[20, 23]rise=20000\n" + "[16, 23]scale=0.694444\n" + "range: [21, 22]\n" + "[21, 23]rise=23000\n" + "[16, 23]scale=0.694444\n" + "range: [22, 23]\n" + "[22, 23]rise=26000\n" + "[16, 23]scale=0.694444\n" + "range: [23, 2147483647]\n"); + + g_free (text); + pango_attr_list_unref (attributes); + pango_attr_iterator_destroy (attr); + + g_string_free (s, TRUE); +} + int main (int argc, char *argv[]) { @@ -840,15 +1042,19 @@ main (int argc, char *argv[]) g_test_add_func ("/attributes/list/basic", test_list); g_test_add_func ("/attributes/list/change", test_list_change); g_test_add_func ("/attributes/list/splice", test_list_splice); + g_test_add_func ("/attributes/list/splice2", test_list_splice2); g_test_add_func ("/attributes/list/filter", test_list_filter); g_test_add_func ("/attributes/list/update", test_list_update); + g_test_add_func ("/attributes/list/update2", test_list_update2); g_test_add_func ("/attributes/list/equal", test_list_equal); g_test_add_func ("/attributes/list/insert", test_insert); g_test_add_func ("/attributes/list/merge", test_merge); + g_test_add_func ("/attributes/list/merge2", test_merge2); g_test_add_func ("/attributes/iter/basic", test_iter); g_test_add_func ("/attributes/iter/get", test_iter_get); g_test_add_func ("/attributes/iter/get_font", test_iter_get_font); g_test_add_func ("/attributes/iter/get_attrs", test_iter_get_attrs); + g_test_add_func ("/attributes/iter/epsilon_zero", test_iter_epsilon_zero); return g_test_run (); } diff --git a/tests/testboundaries_ucd.c b/tests/testboundaries_ucd.c index f77abdcd..1f0276e6 100644 --- a/tests/testboundaries_ucd.c +++ b/tests/testboundaries_ucd.c @@ -232,7 +232,9 @@ do_test (const gchar *filename, channel = g_io_channel_new_file (filename, "r", &error); if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { +#if 0 g_test_skip ("Test file not found"); +#endif return; } @@ -298,6 +300,7 @@ do_test (const gchar *filename, } g_free (string); g_free (expected_attrs); + g_free (line); i++; } diff --git a/tests/testcolor.c b/tests/testcolor.c index 36f2dbf3..62bbe4bf 100644 --- a/tests/testcolor.c +++ b/tests/testcolor.c @@ -25,57 +25,92 @@ typedef struct _ColorSpec { const gchar *spec; gboolean valid; + int color_or_alpha; guint16 red; guint16 green; guint16 blue; + guint16 alpha; } ColorSpec; -static gboolean test_one_color (ColorSpec *spec) +#define COLOR 1 +#define ALPHA 2 +#define BOTH 3 + +static void +test_one_color (ColorSpec *spec) { PangoColor color; gboolean accepted; + guint16 alpha; - accepted = pango_color_parse (&color, spec->spec); + if (spec->color_or_alpha & COLOR) + { + accepted = pango_color_parse (&color, spec->spec); - if (accepted == spec->valid && - (!accepted || - (color.red == spec->red && - color.green == spec->green && - color.blue == spec->blue))) - return TRUE; - else - return FALSE; -} + if (!spec->valid) + { + g_assert_false (accepted); + } + else + { + g_assert_true (accepted); + g_assert_cmpuint (color.red, ==, spec->red); + g_assert_cmpuint (color.green, ==, spec->green); + g_assert_cmpuint (color.blue, ==, spec->blue); + } + } + if (spec->color_or_alpha & ALPHA) + { + accepted = pango_color_parse_with_alpha (&color, &alpha, spec->spec); + + if (!spec->valid) + { + g_assert_false (accepted); + } + else + { + g_assert_true (accepted); + g_assert_cmpuint (color.red, ==, spec->red); + g_assert_cmpuint (color.green, ==, spec->green); + g_assert_cmpuint (color.blue, ==, spec->blue); + g_assert_cmpuint (alpha, ==, spec->alpha); + } + } +} ColorSpec specs [] = { - { "#abc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#aabbcc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#aaabbbccc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#100100100", 1, 0x1001, 0x1001, 0x1001 }, - { "#aaaabbbbcccc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#fff", 1, 0xffff, 0xffff, 0xffff }, - { "#ffffff", 1, 0xffff, 0xffff, 0xffff }, - { "#fffffffff", 1, 0xffff, 0xffff, 0xffff }, - { "#ffffffffffff", 1, 0xffff, 0xffff, 0xffff }, - { "#000", 1, 0x0000, 0x0000, 0x0000 }, - { "#000000", 1, 0x0000, 0x0000, 0x0000 }, - { "#000000000", 1, 0x0000, 0x0000, 0x0000 }, - { "#000000000000", 1, 0x0000, 0x0000, 0x0000 }, - { "#AAAABBBBCCCC", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#aa bb cc ", 0, 0, 0, 0 }, - { "#aa bb ccc", 0, 0, 0, 0 }, - { "#ab", 0, 0, 0, 0 }, - { "#aabb", 0, 0, 0, 0 }, - { "#aaabb", 0, 0, 0, 0 }, - { "aaabb", 0, 0, 0, 0 }, - { "", 0, 0, 0, 0 }, - { "#", 0, 0, 0, 0 }, - { "##fff", 0, 0, 0, 0 }, - { "#0000ff+", 0, 0, 0, 0 }, - { "#0000f+", 0, 0, 0, 0 }, - { "#0x00x10x2", 0, 0, 0, 0 }, - { NULL, 0, 0, 0, 0 } + { "#abc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#aabbcc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#aaabbbccc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#100100100", 1, BOTH, 0x1001, 0x1001, 0x1001, 0xffff }, + { "#aaaabbbbcccc", 1, COLOR, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#fff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#ffffff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#fffffffff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#ffffffffffff", 1, COLOR, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#000000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#000000000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#000000000000", 1, COLOR, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#AAAABBBBCCCC", 1, COLOR, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#aa bb cc ", 0, BOTH, 0, 0, 0, 0 }, + { "#aa bb ccc", 0, BOTH, 0, 0, 0, 0 }, + { "#ab", 0, BOTH, 0, 0, 0, 0 }, + { "#aabb", 0, COLOR, 0, 0, 0, 0 }, + { "#aaabb", 0, BOTH, 0, 0, 0, 0 }, + { "aaabb", 0, BOTH, 0, 0, 0, 0 }, + { "", 0, BOTH, 0, 0, 0, 0 }, + { "#", 0, BOTH, 0, 0, 0, 0 }, + { "##fff", 0, BOTH, 0, 0, 0, 0 }, + { "#0000ff+", 0, BOTH, 0, 0, 0, 0 }, + { "#0000f+", 0, BOTH, 0, 0, 0, 0 }, + { "#0x00x10x2", 0, BOTH, 0, 0, 0, 0 }, + { "#abcd", 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd }, + { "#aabbccdd", 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd }, + { "#aaaabbbbccccdddd", + 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd }, + { NULL, 0, BOTH, 0, 0, 0, 0 } }; static void @@ -84,8 +119,7 @@ test_color (void) ColorSpec *spec; for (spec = specs; spec->spec; spec++) - g_assert (test_one_color (spec)); - + test_one_color (spec); } int diff --git a/tests/testmisc.c b/tests/testmisc.c index f5583cab..2f6c148b 100644 --- a/tests/testmisc.c +++ b/tests/testmisc.c @@ -54,6 +54,39 @@ test_itemize_empty_crash (void) g_object_unref (context); } +/* Test that pango_layout_set_text (layout, "short", 200) + * does not lead to a crash. (pidgin does this) + */ +static void +test_short_string_crash (void) +{ + PangoContext *context; + PangoLayout *layout; + int width, height; + + context = pango_font_map_create_context (pango_cairo_font_map_get_default ()); + layout = pango_layout_new (context); + pango_layout_set_text (layout, "short text", 200); + pango_layout_get_pixel_size (layout, &width, &height); + + g_object_unref (layout); + g_object_unref (context); +} + +static void +test_language_emoji_crash (void) +{ + PangoLanguage *lang; + const PangoScript *scripts; + int num; + + lang = pango_language_from_string ("und-zsye"); + scripts = pango_language_get_scripts (lang, &num); + + g_assert (num >= 0); + g_assert (scripts == NULL || num > 0); +} + int main (int argc, char *argv[]) { @@ -61,6 +94,8 @@ main (int argc, char *argv[]) g_test_add_func ("/layout/shape-tab-crash", test_shape_tab_crash); g_test_add_func ("/layout/itemize-empty-crash", test_itemize_empty_crash); + g_test_add_func ("/layout/short-string-crash", test_short_string_crash); + g_test_add_func ("/language/emoji-crash", test_language_emoji_crash); return g_test_run (); } |