[pango/wip/matthiasc/font-variations] Test attribute iterators
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/wip/matthiasc/font-variations] Test attribute iterators
- Date: Thu, 7 Sep 2017 11:50:57 +0000 (UTC)
commit b28dbcd85cc8edc63122cc5c332906b8e5f84087
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Sep 7 06:29:12 2017 -0400
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.
tests/markup-parse.c | 68 +++++++++++++++++++++++++++++++++++++--
tests/markups/valid-1.expected | 8 +++++
tests/markups/valid-2.expected | 8 +++++
tests/markups/valid-3.expected | 6 +++
tests/markups/valid-4.expected | 18 ++++++++++
tests/markups/valid-5.expected | 12 +++++++
tests/markups/valid-6.expected | 12 +++++++
tests/markups/valid-7.expected | 8 +++++
tests/markups/valid-8.expected | 12 +++++++
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 60288d8..e82c6db 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 acd5f1b..0954676 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 acd5f1b..0954676 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 f1030ea..1943fc3 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 eb46086..171e84e 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 d693523..ee3ae71 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 1886eb6..d5d6ea4 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 b9d8acf..d30d165 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 d78b720..de8eb6b 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 06936f9..7931e70 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]