diff options
author | Matthias Clasen <mclasen@redhat.com> | 2017-09-07 06:29:12 -0400 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2018-01-03 12:41:46 +0000 |
commit | 95c2aaaa9a1f0167e832a3d31700ae51e519fff4 (patch) | |
tree | 1dedcaf4f0a515b200c8a1fc795c27a5a5a55592 /tests | |
parent | 53c483cb115cb33c72ccf320366af3f76716178a (diff) | |
download | pango-95c2aaaa9a1f0167e832a3d31700ae51e519fff4.tar.gz |
Test attribute iterators
Add a quick test for iterating through attribute lists
that piggy-backs on the markup tests - we already have
attribute lists and a place for expected results here.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/markup-parse.c | 68 | ||||
-rw-r--r-- | tests/markups/valid-1.expected | 8 | ||||
-rw-r--r-- | tests/markups/valid-2.expected | 8 | ||||
-rw-r--r-- | tests/markups/valid-3.expected | 6 | ||||
-rw-r--r-- | tests/markups/valid-4.expected | 18 | ||||
-rw-r--r-- | tests/markups/valid-5.expected | 12 | ||||
-rw-r--r-- | tests/markups/valid-6.expected | 12 | ||||
-rw-r--r-- | tests/markups/valid-7.expected | 8 | ||||
-rw-r--r-- | tests/markups/valid-8.expected | 12 | ||||
-rw-r--r-- | tests/markups/valid-9.expected | 6 |
10 files changed, 154 insertions, 4 deletions
diff --git a/tests/markup-parse.c b/tests/markup-parse.c index 60288d8f..e82c6db5 100644 --- a/tests/markup-parse.c +++ b/tests/markup-parse.c @@ -21,6 +21,7 @@ #include <glib.h> #include <string.h> +#include <unistd.h> #include <locale.h> #include <pango/pangocairo.h> @@ -144,7 +145,12 @@ test_file (const gchar *filename, GString *string) GError *error = NULL; gchar *text; PangoAttrList *attrs; + PangoAttrIterator *iter; + PangoFontDescription *desc; + PangoLanguage *lang; gboolean ret; + char *str; + int start, end; if (!g_file_get_contents (filename, &contents, &length, &error)) { @@ -162,7 +168,19 @@ test_file (const gchar *filename, GString *string) g_string_append (string, text); g_string_append (string, "\n\n---\n\n"); attr_list_dump (attrs, string); + g_string_append (string, "\n\n---\n\n"); + desc = pango_font_description_new (); + iter = pango_attr_list_get_iterator (attrs); + do { + pango_attr_iterator_range (iter, &start, &end); + pango_attr_iterator_get_font (iter, desc, &lang, NULL); + str = pango_font_description_to_string (desc); + g_string_append_printf (string, "[%d:%d] %s %s\n", start, end, (char *)lang, str); + g_free (str); + } while (pango_attr_iterator_next (iter)); + pango_attr_iterator_destroy (iter); pango_attr_list_unref (attrs); + pango_font_description_free (desc); g_free (text); } else @@ -188,14 +206,51 @@ get_expected_filename (const gchar *filename) return expected; } +static char * +diff_with_file (const char *file1, + GString *string, + GError **error) +{ + const char *command[] = { "diff", "-u", file1, NULL, NULL }; + char *diff, *tmpfile; + int fd; + + diff = NULL; + + /* write the text buffer to a temporary file */ + fd = g_file_open_tmp (NULL, &tmpfile, error); + if (fd < 0) + return NULL; + + if (write (fd, string->str, string->len) != (int) string->len) + { + close (fd); + g_set_error (error, + G_FILE_ERROR, G_FILE_ERROR_FAILED, + "Could not write data to temporary file '%s'", tmpfile); + goto done; + } + close (fd); + command[3] = tmpfile; + + /* run diff command */ + g_spawn_sync (NULL, (char **)command, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &diff, NULL, NULL, error); + +done: + unlink (tmpfile); + g_free (tmpfile); + + return diff; +} + static void test_parse (gconstpointer d) { const gchar *filename = d; gchar *expected_file; - gchar *expected; GError *error = NULL; GString *string; + char *diff; expected_file = get_expected_filename (filename); @@ -203,10 +258,15 @@ test_parse (gconstpointer d) test_file (filename, string); - g_file_get_contents (expected_file, &expected, NULL, &error); + diff = diff_with_file (expected_file, string, &error); g_assert_no_error (error); - g_assert_cmpstr (string->str, ==, expected); - g_free (expected); + + if (diff && diff[0]) + { + g_test_message ("Resulting output doesn't match reference:\n%s", diff); + g_test_fail (); + } + g_free (diff); g_string_free (string, TRUE); diff --git a/tests/markups/valid-1.expected b/tests/markups/valid-1.expected index acd5f1b6..09546763 100644 --- a/tests/markups/valid-1.expected +++ b/tests/markups/valid-1.expected @@ -10,3 +10,11 @@ range 9 13 range 13 17 [13 17] style 2 range 17 2147483647 + + +--- + +[0:9] (null) Normal 0 +[9:13] (null) Normal 0 +[13:17] (null) Italic 0 +[17:2147483647] (null) Italic 0 diff --git a/tests/markups/valid-2.expected b/tests/markups/valid-2.expected index acd5f1b6..09546763 100644 --- a/tests/markups/valid-2.expected +++ b/tests/markups/valid-2.expected @@ -10,3 +10,11 @@ range 9 13 range 13 17 [13 17] style 2 range 17 2147483647 + + +--- + +[0:9] (null) Normal 0 +[9:13] (null) Normal 0 +[13:17] (null) Italic 0 +[17:2147483647] (null) Italic 0 diff --git a/tests/markups/valid-3.expected b/tests/markups/valid-3.expected index f1030ea7..1943fc37 100644 --- a/tests/markups/valid-3.expected +++ b/tests/markups/valid-3.expected @@ -16,3 +16,9 @@ range 0 13 [0 13] fallback 0 [0 13] language de range 13 2147483647 + + +--- + +[0:13] de Sans Italic 12 +[13:2147483647] (null) Sans Italic 12 diff --git a/tests/markups/valid-4.expected b/tests/markups/valid-4.expected index eb46086e..171e84e1 100644 --- a/tests/markups/valid-4.expected +++ b/tests/markups/valid-4.expected @@ -36,3 +36,21 @@ range 45 54 [42 54] family Monospace [45 54] underline 1 range 54 2147483647 + + +--- + +[0:5] (null) Bold +[5:8] (null) Bold 0 +[8:9] (null) Bold 0 +[9:15] (null) Bold Italic 0 +[15:16] (null) Bold Italic 0 +[16:29] (null) Bold Italic 0 +[29:32] (null) Bold Italic 0 +[32:33] (null) Bold Italic 0 +[33:38] (null) Bold Italic 0 +[38:41] (null) Bold Italic 0 +[41:42] (null) Bold Italic 0 +[42:45] (null) Monospace Bold Italic 0 +[45:54] (null) Monospace Bold Italic 0 +[54:2147483647] (null) Monospace Bold Italic 0 diff --git a/tests/markups/valid-5.expected b/tests/markups/valid-5.expected index d693523c..ee3ae71e 100644 --- a/tests/markups/valid-5.expected +++ b/tests/markups/valid-5.expected @@ -18,3 +18,15 @@ range 14 15 range 15 19 [15 19] foreground #222233334444 range 19 2147483647 + + +--- + +[0:4] (null) Normal +[4:5] (null) Normal +[5:9] (null) Normal +[9:10] (null) Normal +[10:14] (null) Normal +[14:15] (null) Normal +[15:19] (null) Normal +[19:2147483647] (null) Normal diff --git a/tests/markups/valid-6.expected b/tests/markups/valid-6.expected index 1886eb68..d5d6ea45 100644 --- a/tests/markups/valid-6.expected +++ b/tests/markups/valid-6.expected @@ -21,3 +21,15 @@ range 15 19 [15 19] foreground #222233334444 [15 19] foreground-alpha 5555 range 19 2147483647 + + +--- + +[0:4] (null) Normal +[4:5] (null) Normal +[5:9] (null) Normal +[9:10] (null) Normal +[10:14] (null) Normal +[14:15] (null) Normal +[15:19] (null) Normal +[19:2147483647] (null) Normal diff --git a/tests/markups/valid-7.expected b/tests/markups/valid-7.expected index b9d8acf6..d30d165d 100644 --- a/tests/markups/valid-7.expected +++ b/tests/markups/valid-7.expected @@ -10,3 +10,11 @@ range 4 5 range 5 9 [5 9] strikethrough-color #222233334444 range 9 2147483647 + + +--- + +[0:4] (null) Normal +[4:5] (null) Normal +[5:9] (null) Normal +[9:2147483647] (null) Normal diff --git a/tests/markups/valid-8.expected b/tests/markups/valid-8.expected index d78b7201..de8eb6b8 100644 --- a/tests/markups/valid-8.expected +++ b/tests/markups/valid-8.expected @@ -22,3 +22,15 @@ range 15 19 [15 19] background #00000000ffff [15 19] background-alpha 547a range 19 2147483647 + + +--- + +[0:4] (null) Normal +[4:5] (null) Normal +[5:9] (null) Normal +[9:10] (null) Normal +[10:14] (null) Normal +[14:15] (null) Normal +[15:19] (null) Normal +[19:2147483647] (null) Normal diff --git a/tests/markups/valid-9.expected b/tests/markups/valid-9.expected index 06936f9f..7931e705 100644 --- a/tests/markups/valid-9.expected +++ b/tests/markups/valid-9.expected @@ -6,3 +6,9 @@ Blue text range 0 9 [0 9] font-features kern 0, dlig, lnum 1, -pnum range 9 2147483647 + + +--- + +[0:9] (null) Normal +[9:2147483647] (null) Normal |