diff options
author | Ross Burton <ross.burton@intel.com> | 2019-03-04 13:17:01 +0000 |
---|---|---|
committer | Ross Burton <ross.burton@intel.com> | 2019-03-25 14:15:52 +0000 |
commit | fa1c76a58ba9f9ba44462cad877c21db1eeaedd2 (patch) | |
tree | b8475e0f2d0e0014b9128b562381df4707b62575 /tests/markup-parse.c | |
parent | 806bcfb8f2e854740180ea5a39ae7ebdd58c5906 (diff) | |
download | pango-fa1c76a58ba9f9ba44462cad877c21db1eeaedd2.tar.gz |
markup-parse: don't duplicate code
Use the functions in test-common.c instead of replicating them.
Diffstat (limited to 'tests/markup-parse.c')
-rw-r--r-- | tests/markup-parse.c | 153 |
1 files changed, 3 insertions, 150 deletions
diff --git a/tests/markup-parse.c b/tests/markup-parse.c index 633f3e89..dff0ccc4 100644 --- a/tests/markup-parse.c +++ b/tests/markup-parse.c @@ -31,117 +31,7 @@ #include <locale.h> #include <pango/pangocairo.h> - -static void -print_attr (PangoAttribute *attr, GString *string) -{ - g_string_append_printf (string, "[%d %d] ", attr->start_index, attr->end_index); - switch (attr->klass->type) - { - case PANGO_ATTR_LANGUAGE: - g_string_append_printf (string,"language %s\n", pango_language_to_string (((PangoAttrLanguage *)attr)->value)); - break; - case PANGO_ATTR_FAMILY: - g_string_append_printf (string,"family %s\n", ((PangoAttrString *)attr)->value); - break; - case PANGO_ATTR_STYLE: - g_string_append_printf (string,"style %d\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_WEIGHT: - g_string_append_printf (string,"weight %d\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_VARIANT: - g_string_append_printf (string,"variant %d\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_STRETCH: - g_string_append_printf (string,"stretch %d\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_SIZE: - g_string_append_printf (string,"size %d\n", ((PangoAttrSize *)attr)->size); - break; - case PANGO_ATTR_FONT_DESC: - g_string_append_printf (string,"font %s\n", pango_font_description_to_string (((PangoAttrFontDesc *)attr)->desc)); - break; - case PANGO_ATTR_FOREGROUND: - g_string_append_printf (string,"foreground %s\n", pango_color_to_string (&((PangoAttrColor *)attr)->color)); - break; - case PANGO_ATTR_BACKGROUND: - g_string_append_printf (string,"background %s\n", pango_color_to_string (&((PangoAttrColor *)attr)->color)); - break; - case PANGO_ATTR_UNDERLINE: - g_string_append_printf (string,"underline %d\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_STRIKETHROUGH: - g_string_append_printf (string,"strikethrough %d\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_RISE: - g_string_append_printf (string,"rise %d\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_SHAPE: - g_string_append_printf (string,"shape\n"); - break; - case PANGO_ATTR_SCALE: - g_string_append_printf (string,"scale %f\n", ((PangoAttrFloat *)attr)->value); - break; - case PANGO_ATTR_FALLBACK: - g_string_append_printf (string,"fallback %d\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_LETTER_SPACING: - g_string_append_printf (string,"letter-spacing %d\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_UNDERLINE_COLOR: - g_string_append_printf (string,"underline-color %s\n", pango_color_to_string (&((PangoAttrColor *)attr)->color)); - break; - case PANGO_ATTR_STRIKETHROUGH_COLOR: - g_string_append_printf (string,"strikethrough-color %s\n", pango_color_to_string (&((PangoAttrColor *)attr)->color)); - break; - case PANGO_ATTR_ABSOLUTE_SIZE: - g_string_append_printf (string,"absolute-size %d\n", ((PangoAttrSize *)attr)->size); - break; - case PANGO_ATTR_GRAVITY: - g_string_append_printf (string,"gravity %d\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_GRAVITY_HINT: - g_string_append_printf (string,"gravity-hint %d\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_FONT_FEATURES: - g_string_append_printf (string,"font-features %s\n", ((PangoAttrString *)attr)->value); - break; - case PANGO_ATTR_FOREGROUND_ALPHA: - g_string_append_printf (string,"foreground-alpha %04x\n", ((PangoAttrInt *)attr)->value); - break; - case PANGO_ATTR_BACKGROUND_ALPHA: - g_string_append_printf (string,"background-alpha %04x\n", ((PangoAttrInt *)attr)->value); - break; - default: - g_assert_not_reached (); - break; - } -} - -static void -attr_list_dump (PangoAttrList *attrs, GString *string) -{ - PangoAttrIterator *iter; - - iter = pango_attr_list_get_iterator (attrs); - do { - gint start, end; - GSList *list, *l; - - pango_attr_iterator_range (iter, &start, &end); - g_string_append_printf (string, "range %d %d\n", start, end); - list = pango_attr_iterator_get_attrs (iter); - for (l = list; l; l = l->next) - { - PangoAttribute *attr = l->data; - print_attr (attr, string); - } - g_slist_free_full (list, (GDestroyNotify)pango_attribute_destroy); - } while (pango_attr_iterator_next (iter)); - - pango_attr_iterator_destroy (iter); -} +#include "test-common.h" static void test_file (const gchar *filename, GString *string) @@ -173,7 +63,7 @@ test_file (const gchar *filename, GString *string) g_assert_no_error (error); g_string_append (string, text); g_string_append (string, "\n\n---\n\n"); - attr_list_dump (attrs, string); + print_attr_list (attrs, string); g_string_append (string, "\n\n---\n\n"); desc = pango_font_description_new (); iter = pango_attr_list_get_iterator (attrs); @@ -212,43 +102,6 @@ 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) { @@ -264,7 +117,7 @@ test_parse (gconstpointer d) test_file (filename, string); - diff = diff_with_file (expected_file, string, &error); + diff = diff_with_file (expected_file, string->str, string->len, &error); g_assert_no_error (error); if (diff && diff[0]) |