[pango/serializer2: 4/4] Make test-layout use layout serialization
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/serializer2: 4/4] Make test-layout use layout serialization
- Date: Thu, 18 Nov 2021 14:18:16 +0000 (UTC)
commit 07f71d0f7f29bb33b5ac48a931cde112658d9f26
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Nov 17 20:56:25 2021 -0500
Make test-layout use layout serialization
Now that we have this api, lets use it for
our tests.
tests/layouts/valid-1.layout | 20 +++
tests/layouts/valid-1.markup | 2 -
tests/layouts/valid-10.layout | 8 ++
tests/layouts/valid-10.markup | 2 -
tests/layouts/valid-11.layout | 42 ++++++
tests/layouts/valid-11.markup | 2 -
tests/layouts/valid-12.layout | 15 +++
tests/layouts/valid-12.markup | 2 -
tests/layouts/valid-13.layout | 16 +++
tests/layouts/valid-13.markup | 2 -
tests/layouts/valid-14.layout | 8 ++
tests/layouts/valid-14.markup | 2 -
tests/layouts/valid-15.layout | 8 ++
tests/layouts/valid-15.markup | 2 -
tests/layouts/valid-16.layout | 9 ++
tests/layouts/valid-16.markup | 2 -
tests/layouts/valid-17.layout | 7 +
tests/layouts/valid-17.markup | 2 -
tests/layouts/valid-18.layout | 11 ++
tests/layouts/valid-18.markup | 2 -
tests/layouts/valid-19.layout | 5 +
tests/layouts/valid-19.markup | 2 -
tests/layouts/valid-2.layout | 18 +++
tests/layouts/valid-2.markup | 2 -
tests/layouts/valid-20.layout | 22 ++++
tests/layouts/valid-20.markup | 2 -
tests/layouts/valid-21.expected | 36 ------
tests/layouts/valid-21.markup | 2 -
tests/layouts/valid-22.layout | 84 ++++++++++++
tests/layouts/valid-22.markup | 2 -
tests/layouts/valid-3.layout | 5 +
tests/layouts/valid-3.markup | 2 -
tests/layouts/valid-4.layout | 6 +
tests/layouts/valid-4.markup | 2 -
tests/layouts/valid-5.layout | 13 ++
tests/layouts/valid-5.markup | 3 -
tests/layouts/valid-6.layout | 5 +
tests/layouts/valid-6.markup | 2 -
tests/layouts/valid-7.layout | 21 +++
tests/layouts/valid-7.markup | 2 -
tests/layouts/valid-8.layout | 8 ++
tests/layouts/valid-8.markup | 2 -
tests/layouts/valid-9.layout | 12 ++
tests/layouts/valid-9.markup | 2 -
tests/test-layout.c | 277 +++-------------------------------------
tests/testserialize.c | 87 ++++++++-----
46 files changed, 416 insertions(+), 372 deletions(-)
---
diff --git a/tests/layouts/valid-1.layout b/tests/layouts/valid-1.layout
new file mode 100644
index 00000000..9289830b
--- /dev/null
+++ b/tests/layouts/valid-1.layout
@@ -0,0 +1,20 @@
+{
+ "text" : "This is a test of the automatic emergency brake!\n",
+ "attributes" : [
+ {
+ "start" : 22,
+ "end" : 41,
+ "type" : "foreground",
+ "value" : "#00000000ffff"
+ },
+ {
+ "start" : 22,
+ "end" : 41,
+ "type" : "underline",
+ "value" : "single"
+ }
+ ],
+ "font" : "Cantarell 11",
+ "ellipsize" : "end",
+ "width" : 225280
+}
diff --git a/tests/layouts/valid-10.layout b/tests/layouts/valid-10.layout
new file mode 100644
index 00000000..0d36a38d
--- /dev/null
+++ b/tests/layouts/valid-10.layout
@@ -0,0 +1,8 @@
+{
+ "text" : "Hello שלום Γειά σας\n",
+ "attributes" : [],
+ "font" : "Cantarell 11",
+ "justify" : true,
+ "ellipsize" : "end",
+ "width" : 102400
+}
diff --git a/tests/layouts/valid-11.layout b/tests/layouts/valid-11.layout
new file mode 100644
index 00000000..a044cc53
--- /dev/null
+++ b/tests/layouts/valid-11.layout
@@ -0,0 +1,42 @@
+{
+ "text" : "double low error\n",
+ "attributes" : [
+ {
+ "end" : 6,
+ "type" : "underline",
+ "value" : "double"
+ },
+ {
+ "end" : 6,
+ "type" : "overline",
+ "value" : "single"
+ },
+ {
+ "start" : 7,
+ "end" : 10,
+ "type" : "underline",
+ "value" : "low"
+ },
+ {
+ "start" : 7,
+ "end" : 10,
+ "type" : "strikethrough",
+ "value" : true
+ },
+ {
+ "start" : 11,
+ "end" : 16,
+ "type" : "underline",
+ "value" : "error"
+ },
+ {
+ "start" : 11,
+ "end" : 16,
+ "type" : "rise",
+ "value" : 1024
+ }
+ ],
+ "font" : "Cantarell 11",
+ "wrap" : "char",
+ "width" : 225280
+}
diff --git a/tests/layouts/valid-12.layout b/tests/layouts/valid-12.layout
new file mode 100644
index 00000000..1c9fa227
--- /dev/null
+++ b/tests/layouts/valid-12.layout
@@ -0,0 +1,15 @@
+{
+ "text" : "a b c d
e f g h\n",
+ "attributes" : [],
+ "font" : "Cantarell 11",
+ "tabs" : {
+ "positions-in-pixels" : true,
+ "positions" : [
+ 0,
+ 50,
+ 100,
+ 150,
+ 200
+ ]
+ }
+}
diff --git a/tests/layouts/valid-13.layout b/tests/layouts/valid-13.layout
new file mode 100644
index 00000000..a9f10f86
--- /dev/null
+++ b/tests/layouts/valid-13.layout
@@ -0,0 +1,16 @@
+{
+ "text" : "a b c d
e f g h\n",
+ "attributes" : [],
+ "font" : "Cantarell 11",
+ "tabs" : {
+ "positions-in-pixels" : true,
+ "positions" : [
+ 0,
+ 50,
+ 100,
+ 150,
+ 200
+ ]
+ },
+ "single-paragraph" : true
+}
diff --git a/tests/layouts/valid-14.layout b/tests/layouts/valid-14.layout
new file mode 100644
index 00000000..116cc94f
--- /dev/null
+++ b/tests/layouts/valid-14.layout
@@ -0,0 +1,8 @@
+{
+ "text" : "你好 Hello שלום Γειά σας\n",
+ "attributes" : [],
+ "font" : "Cantarell 11",
+ "ellipsize" : "start",
+ "width" : 161792,
+ "line-spacing" : 1.5
+}
diff --git a/tests/layouts/valid-15.layout b/tests/layouts/valid-15.layout
new file mode 100644
index 00000000..9f584ba6
--- /dev/null
+++ b/tests/layouts/valid-15.layout
@@ -0,0 +1,8 @@
+{
+ "text" : "Lets see if this text is long enough to wrap due to height limitations. It might, or it might
not.\n",
+ "attributes" : [],
+ "font" : "Cantarell 11",
+ "ellipsize" : "end",
+ "width" : 153600,
+ "height" : 40960
+}
diff --git a/tests/layouts/valid-16.layout b/tests/layouts/valid-16.layout
new file mode 100644
index 00000000..e2a82d96
--- /dev/null
+++ b/tests/layouts/valid-16.layout
@@ -0,0 +1,9 @@
+{
+ "text" : "Lets see if this text is long enough to wrap due to height limitations. It might, or it might
not.\n",
+ "attributes" : [],
+ "font" : "Cantarell 11",
+ "wrap" : "word-char",
+ "ellipsize" : "end",
+ "width" : 153600,
+ "height" : -2
+}
diff --git a/tests/layouts/valid-17.layout b/tests/layouts/valid-17.layout
new file mode 100644
index 00000000..062cc241
--- /dev/null
+++ b/tests/layouts/valid-17.layout
@@ -0,0 +1,7 @@
+{
+ "text" : "some|bla|bla|bla\n",
+ "attributes" : [],
+ "font" : "Cantarell 11",
+ "justify" : true,
+ "width" : 102400
+}
diff --git a/tests/layouts/valid-18.layout b/tests/layouts/valid-18.layout
new file mode 100644
index 00000000..85e9a7d1
--- /dev/null
+++ b/tests/layouts/valid-18.layout
@@ -0,0 +1,11 @@
+{
+ "text" : "some line breaks
and miscellaneous ignorables\n",
+ "attributes" : [
+ {
+ "end" : 57,
+ "type" : "show",
+ "value" : 7
+ }
+ ],
+ "font" : "Cantarell 11"
+}
diff --git a/tests/layouts/valid-19.layout b/tests/layouts/valid-19.layout
new file mode 100644
index 00000000..32ad1283
--- /dev/null
+++ b/tests/layouts/valid-19.layout
@@ -0,0 +1,5 @@
+{
+ "text" : " a⃠ 😊︎ 😊️ 🇩🇪 ✊ ✋🏾 0 # 🏴 ©\n",
+ "attributes" : [],
+ "font" : "Cantarell 11"
+}
diff --git a/tests/layouts/valid-2.layout b/tests/layouts/valid-2.layout
new file mode 100644
index 00000000..303b2b67
--- /dev/null
+++ b/tests/layouts/valid-2.layout
@@ -0,0 +1,18 @@
+{
+ "text" : "test the blue drink after dinner\n",
+ "attributes" : [
+ {
+ "start" : 9,
+ "end" : 13,
+ "type" : "style",
+ "value" : "italic"
+ },
+ {
+ "start" : 20,
+ "end" : 25,
+ "type" : "underline",
+ "value" : "single"
+ }
+ ],
+ "font" : "Cantarell 11"
+}
diff --git a/tests/layouts/valid-20.layout b/tests/layouts/valid-20.layout
new file mode 100644
index 00000000..bde84b6f
--- /dev/null
+++ b/tests/layouts/valid-20.layout
@@ -0,0 +1,22 @@
+{
+ "text" : "abcdef\n",
+ "attributes" : [
+ {
+ "end" : 3,
+ "type" : "gravity",
+ "value" : "east"
+ },
+ {
+ "end" : 3,
+ "type" : "gravity-hint",
+ "value" : "strong"
+ },
+ {
+ "start" : 3,
+ "end" : 6,
+ "type" : "gravity",
+ "value" : "south"
+ }
+ ],
+ "font" : "Cantarell 11"
+}
diff --git a/tests/layouts/valid-22.layout b/tests/layouts/valid-22.layout
new file mode 100644
index 00000000..be57d26a
--- /dev/null
+++ b/tests/layouts/valid-22.layout
@@ -0,0 +1,84 @@
+{
+ "text" : "e0 = ooo...\n",
+ "attributes" : [
+ {
+ "start" : 1,
+ "end" : 2,
+ "type" : "font-desc",
+ "value" : "Italic"
+ },
+ {
+ "start" : 1,
+ "end" : 2,
+ "type" : "font-scale",
+ "value" : "subscript"
+ },
+ {
+ "start" : 1,
+ "end" : 2,
+ "type" : "baseline-shift",
+ "value" : "subscript"
+ },
+ {
+ "start" : 6,
+ "end" : 11,
+ "type" : "font-scale",
+ "value" : "superscript"
+ },
+ {
+ "start" : 6,
+ "end" : 11,
+ "type" : "baseline-shift",
+ "value" : "superscript"
+ },
+ {
+ "start" : 7,
+ "end" : 11,
+ "type" : "font-scale",
+ "value" : "superscript"
+ },
+ {
+ "start" : 7,
+ "end" : 11,
+ "type" : "baseline-shift",
+ "value" : "superscript"
+ },
+ {
+ "start" : 8,
+ "end" : 11,
+ "type" : "font-scale",
+ "value" : "superscript"
+ },
+ {
+ "start" : 8,
+ "end" : 11,
+ "type" : "baseline-shift",
+ "value" : "superscript"
+ },
+ {
+ "start" : 9,
+ "end" : 11,
+ "type" : "font-scale",
+ "value" : "superscript"
+ },
+ {
+ "start" : 9,
+ "end" : 11,
+ "type" : "baseline-shift",
+ "value" : "superscript"
+ },
+ {
+ "start" : 10,
+ "end" : 11,
+ "type" : "font-scale",
+ "value" : "superscript"
+ },
+ {
+ "start" : 10,
+ "end" : 11,
+ "type" : "baseline-shift",
+ "value" : "superscript"
+ }
+ ],
+ "font" : "Cantarell 11"
+}
diff --git a/tests/layouts/valid-3.layout b/tests/layouts/valid-3.layout
new file mode 100644
index 00000000..ef1b1917
--- /dev/null
+++ b/tests/layouts/valid-3.layout
@@ -0,0 +1,5 @@
+{
+ "text" : "ABC😀️D\n",
+ "attributes" : [],
+ "font" : "Cantarell 11"
+}
diff --git a/tests/layouts/valid-4.layout b/tests/layouts/valid-4.layout
new file mode 100644
index 00000000..5504107d
--- /dev/null
+++ b/tests/layouts/valid-4.layout
@@ -0,0 +1,6 @@
+{
+ "text" : "This paragraph should actually have multiple lines, unlike all the other wannabe äöü
paragraph tests in this ugh test-case. Grow some lines!\n",
+ "attributes" : [],
+ "font" : "Cantarell 11",
+ "width" : 198656
+}
diff --git a/tests/layouts/valid-5.layout b/tests/layouts/valid-5.layout
new file mode 100644
index 00000000..e5e96b9a
--- /dev/null
+++ b/tests/layouts/valid-5.layout
@@ -0,0 +1,13 @@
+{
+ "text" : "A test with multiple paragraphs and with no-break attributes, which might trigger a crash.\nIf
it doesn't the fix has worked.\n",
+ "attributes" : [
+ {
+ "start" : 21,
+ "end" : 31,
+ "type" : "font-features",
+ "value" : "tnum=1"
+ }
+ ],
+ "font" : "Cantarell 11",
+ "width" : 194560
+}
diff --git a/tests/layouts/valid-6.layout b/tests/layouts/valid-6.layout
new file mode 100644
index 00000000..4423d068
--- /dev/null
+++ b/tests/layouts/valid-6.layout
@@ -0,0 +1,5 @@
+{
+ "text" : " 0️⃣ Keycap Digit Zero\n",
+ "attributes" : [],
+ "font" : "Cantarell 11"
+}
diff --git a/tests/layouts/valid-7.layout b/tests/layouts/valid-7.layout
new file mode 100644
index 00000000..b49484c6
--- /dev/null
+++ b/tests/layouts/valid-7.layout
@@ -0,0 +1,21 @@
+{
+ "text" : "This is a test of the automatic emergency brake!\n",
+ "attributes" : [
+ {
+ "start" : 22,
+ "end" : 41,
+ "type" : "foreground",
+ "value" : "#00000000ffff"
+ },
+ {
+ "start" : 22,
+ "end" : 41,
+ "type" : "underline",
+ "value" : "single"
+ }
+ ],
+ "font" : "Cantarell 11",
+ "ellipsize" : "middle",
+ "width" : 204800,
+ "indent" : 51200
+}
diff --git a/tests/layouts/valid-8.layout b/tests/layouts/valid-8.layout
new file mode 100644
index 00000000..063ec370
--- /dev/null
+++ b/tests/layouts/valid-8.layout
@@ -0,0 +1,8 @@
+{
+ "text" : "Hello שלום Γειά σας\n",
+ "attributes" : [],
+ "font" : "Cantarell 11",
+ "auto-dir" : false,
+ "alignment" : "center",
+ "spacing" : 51200
+}
diff --git a/tests/layouts/valid-9.layout b/tests/layouts/valid-9.layout
new file mode 100644
index 00000000..e3dfa57b
--- /dev/null
+++ b/tests/layouts/valid-9.layout
@@ -0,0 +1,12 @@
+{
+ "text" : "Hello שלום Γειά σας\n",
+ "attributes" : [
+ {
+ "end" : 30,
+ "type" : "letter-spacing",
+ "value" : 8888
+ }
+ ],
+ "font" : "Cantarell 11",
+ "width" : 102400
+}
diff --git a/tests/test-layout.c b/tests/test-layout.c
index cd60450e..7415efe7 100644
--- a/tests/test-layout.c
+++ b/tests/test-layout.c
@@ -219,176 +219,14 @@ dump_cursor_positions (PangoLayout *layout, GString *string)
g_string_append (string, "\n");
}
-typedef struct {
- int width;
- int height;
- int indent;
- int spacing;
- float line_spacing;
- PangoEllipsizeMode ellipsize;
- PangoWrapMode wrap;
- PangoAlignment alignment;
- gboolean justify;
- gboolean auto_dir;
- gboolean single_paragraph;
- PangoTabArray *tabs;
- PangoGravity gravity;
-} LayoutParams;
-
-static void
-init_params (LayoutParams *params)
-{
- params->width = -1;
- params->height = -1;
- params->indent = 0;
- params->spacing = 0;
- params->line_spacing = 0.0;
- params->ellipsize = PANGO_ELLIPSIZE_NONE;
- params->wrap = PANGO_WRAP_WORD;
- params->alignment = PANGO_ALIGN_LEFT;
- params->justify = FALSE;
- params->auto_dir = TRUE;
- params->single_paragraph = FALSE;
- params->tabs = NULL;
- params->gravity = PANGO_GRAVITY_AUTO;
-}
-
-static void
-parse_params (const char *str,
- LayoutParams *params)
-{
- char **strings;
- int i;
- GEnumClass *eclass;
- GEnumValue *ev;
-
- strings = g_strsplit (str, ",", -1);
- for (i = 0; strings[i]; i++)
- {
- char **str2 = g_strsplit (strings[i], "=", -1);
- if (strcmp (str2[0], "width") == 0)
- {
- params->width = (int) g_ascii_strtoll (str2[1], NULL, 10);
- }
- else if (strcmp (str2[0], "height") == 0)
- {
- params->height = (int) g_ascii_strtoll (str2[1], NULL, 10);
- }
- else if (strcmp (str2[0], "indent") == 0)
- {
- params->indent = (int) g_ascii_strtoll (str2[1], NULL, 10);
- }
- else if (strcmp (str2[0], "spacing") == 0)
- {
- params->spacing = (int) g_ascii_strtoll (str2[1], NULL, 10);
- }
- else if (strcmp (str2[0], "line_spacing") == 0)
- {
- params->line_spacing = (float) g_ascii_strtod (str2[1], NULL);
- }
- else if (strcmp (str2[0], "ellipsize") == 0)
- {
- eclass = g_type_class_ref (PANGO_TYPE_ELLIPSIZE_MODE);
- ev = g_enum_get_value_by_name (eclass, str2[1]);
- if (!ev)
- ev = g_enum_get_value_by_nick (eclass, str2[1]);
- if (ev)
- params->ellipsize = ev->value;
- g_type_class_unref (eclass);
- }
- else if (strcmp (str2[0], "wrap") == 0)
- {
- eclass = g_type_class_ref (PANGO_TYPE_WRAP_MODE);
- ev = g_enum_get_value_by_name (eclass, str2[1]);
- if (!ev)
- ev = g_enum_get_value_by_nick (eclass, str2[1]);
- if (ev)
- params->wrap = ev->value;
- g_type_class_unref (eclass);
- }
- else if (strcmp (str2[0], "alignment") == 0)
- {
- eclass = g_type_class_ref (PANGO_TYPE_ALIGNMENT);
- ev = g_enum_get_value_by_name (eclass, str2[1]);
- if (!ev)
- ev = g_enum_get_value_by_nick (eclass, str2[1]);
- if (ev)
- params->alignment = ev->value;
- g_type_class_unref (eclass);
- }
- else if (strcmp (str2[0], "justify") == 0)
- {
- params->justify = g_str_equal (str2[1], "true");
- }
- else if (strcmp (str2[0], "auto_dir") == 0)
- {
- params->auto_dir = g_str_equal (str2[1], "true");
- }
- else if (strcmp (str2[0], "single_paragraph") == 0)
- {
- params->single_paragraph = g_str_equal (str2[1], "true");
- }
- else if (strcmp (str2[0], "tabs") == 0)
- {
- char **str3 = g_strsplit (strings[i], " ", -1);
- params->tabs = pango_tab_array_new (g_strv_length (str3), TRUE);
- for (int j = 0; str3[j]; j++)
- {
- int tab = (int) g_ascii_strtoll (str3[j], NULL, 10);
- pango_tab_array_set_tab (params->tabs, j, PANGO_TAB_LEFT, tab);
- }
- g_strfreev (str3);
- }
- else if (strcmp (str2[0], "gravity") == 0)
- {
- eclass = g_type_class_ref (PANGO_TYPE_GRAVITY);
- ev = g_enum_get_value_by_name (eclass, str2[1]);
- if (!ev)
- ev = g_enum_get_value_by_nick (eclass, str2[1]);
- if (ev)
- params->gravity = ev->value;
- g_type_class_unref (eclass);
- }
-
- g_strfreev (str2);
- }
- g_strfreev (strings);
-}
-
-#define assert_layout_changed(layout) \
- g_assert_cmpuint (pango_layout_get_serial (layout), !=, serial); \
- serial = pango_layout_get_serial (layout);
-
-#define assert_rectangle_equal(r1, r2) \
- g_assert_true((r1)->x == (r2)->x && \
- (r1)->y == (r2)->y && \
- (r1)->width == (r2)->width && \
- (r1)->height == (r2)->height)
-
-#define assert_rectangle_contained(r1, r2) \
- g_assert_true ((r1)->x >= (r2)->x && \
- (r1)->y >= (r2)->y && \
- (r1)->x + (r1)->width <= (r2)->x + (r2)->width && \
- (r1)->y + (r1)->height <= (r2)->y + (r2)->height)
-
-#define assert_rectangle_size_contained(r1, r2) \
- g_assert_true ((r1)->width <= (r2)->width && \
- (r1)->height <= (r2)->height)
-
static void
test_file (const char *filename, GString *string)
{
char *contents;
- char *markup;
gsize length;
+ GBytes *bytes;
GError *error = NULL;
PangoLayout *layout;
- char *p;
- LayoutParams params;
- PangoFontDescription *desc;
- const PangoFontDescription *desc2;
- guint serial;
- PangoTabArray *tabs;
if (context == NULL)
context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
@@ -396,85 +234,12 @@ test_file (const char *filename, GString *string)
g_file_get_contents (filename, &contents, &length, &error);
g_assert_no_error (error);
- p = strchr (contents, '\n');
- g_assert (p);
- markup = p + 1;
- *p = '\0';
- length = strlen (markup);
-
- init_params (¶ms);
-
- layout = pango_layout_new (context);
-
- serial = pango_layout_get_serial (layout);
- g_assert_cmpuint (serial, !=, 0);
-
- /* Check initial values */
- g_assert_cmpint (pango_layout_get_width (layout), ==, params.width);
- g_assert_cmpint (pango_layout_get_height (layout), ==, params.height);
- g_assert_cmpint (pango_layout_get_indent (layout), ==, params.indent);
- g_assert_cmpint (pango_layout_get_spacing (layout), ==, params.spacing);
- g_assert_cmpfloat (pango_layout_get_line_spacing (layout), ==, params.line_spacing);
- g_assert_cmpint (pango_layout_get_ellipsize (layout), ==, params.ellipsize);
- g_assert_cmpint (pango_layout_get_wrap (layout), ==, params.wrap);
- g_assert_cmpint (pango_layout_get_alignment (layout), ==, params.alignment);
- g_assert_cmpint (pango_layout_get_justify (layout), ==, params.justify);
- g_assert_cmpint (pango_layout_get_auto_dir (layout), ==, params.auto_dir);
- g_assert_cmpint (pango_layout_get_single_paragraph_mode (layout), ==, params.single_paragraph);
-
- g_assert_cmpstr (pango_layout_get_text (layout), ==, "");
- g_assert_null (pango_layout_get_attributes (layout));
- g_assert_null (pango_layout_get_tabs (layout));
- g_assert_null (pango_layout_get_font_description (layout));
- g_assert_cmpint (pango_layout_is_ellipsized (layout), ==, FALSE);
- g_assert_cmpint (pango_layout_is_wrapped (layout), ==, FALSE);
-
- desc = pango_font_description_from_string ("Cantarell 11");
- pango_layout_set_font_description (layout, desc);
- desc2 = pango_layout_get_font_description (layout);
- g_assert_true (pango_font_description_equal (desc, desc2));
- pango_font_description_free (desc);
- assert_layout_changed (layout);
-
- pango_layout_set_markup (layout, markup, length);
- assert_layout_changed (layout);
-
- parse_params (contents, ¶ms);
-
- pango_context_set_base_gravity (context, params.gravity);
-
- pango_layout_set_width (layout, params.width > 0 ? params.width * PANGO_SCALE : -1);
- pango_layout_set_height (layout, params.height > 0 ? params.height * PANGO_SCALE : params.height);
- pango_layout_set_indent (layout, params.indent * PANGO_SCALE);
- pango_layout_set_spacing (layout, params.spacing * PANGO_SCALE);
- pango_layout_set_line_spacing (layout, params.line_spacing);
- pango_layout_set_ellipsize (layout, params.ellipsize);
- pango_layout_set_wrap (layout, params.wrap);
- pango_layout_set_alignment (layout, params.alignment);
- pango_layout_set_justify (layout, params.justify);
- pango_layout_set_auto_dir (layout, params.auto_dir);
- pango_layout_set_single_paragraph_mode (layout, params.single_paragraph);
- pango_layout_set_tabs (layout, params.tabs);
-
- /* Check the values we set */
- g_assert_cmpint (pango_layout_get_width (layout), ==, params.width > 0 ? params.width * PANGO_SCALE : -1);
- g_assert_cmpint (pango_layout_get_height (layout), ==, params.height > 0 ? params.height * PANGO_SCALE :
params.height);
- g_assert_cmpint (pango_layout_get_indent (layout), ==, params.indent * PANGO_SCALE);
- g_assert_cmpint (pango_layout_get_spacing (layout), ==, params.spacing * PANGO_SCALE);
- g_assert_cmpfloat (pango_layout_get_line_spacing (layout), ==, params.line_spacing);
- g_assert_cmpint (pango_layout_get_ellipsize (layout), ==, params.ellipsize);
- g_assert_cmpint (pango_layout_get_wrap (layout), ==, params.wrap);
- g_assert_cmpint (pango_layout_get_alignment (layout), ==, params.alignment);
- g_assert_cmpint (pango_layout_get_justify (layout), ==, params.justify);
- g_assert_cmpint (pango_layout_get_auto_dir (layout), ==, params.auto_dir);
- g_assert_cmpint (pango_layout_get_single_paragraph_mode (layout), ==, params.single_paragraph);
-
- tabs = pango_layout_get_tabs (layout);
- g_assert_true ((tabs == NULL) == (params.tabs == NULL));
- if (tabs)
- pango_tab_array_free (tabs);
-
- g_assert_cmpint (pango_layout_get_character_count (layout), ==, g_utf8_strlen (pango_layout_get_text
(layout), -1));
+ bytes = g_bytes_new_take (contents, length);
+
+ layout = pango_layout_deserialize (context, bytes, &error);
+ g_assert_no_error (error);
+
+ g_bytes_unref (bytes);
/* generate the dumps */
g_string_append (string, pango_layout_get_text (layout));
@@ -484,13 +249,11 @@ test_file (const char *filename, GString *string)
g_string_append_printf (string, "wrapped: %d\n", pango_layout_is_wrapped (layout));
g_string_append_printf (string, "ellipsized: %d\n", pango_layout_is_ellipsized (layout));
g_string_append_printf (string, "lines: %d\n", pango_layout_get_line_count (layout));
- if (params.width > 0)
+ if (pango_layout_get_width (layout) > 0)
g_string_append_printf (string, "width: %d\n", pango_layout_get_width (layout));
-
- if (params.height > 0)
+ if (pango_layout_get_height (layout) > 0)
g_string_append_printf (string, "height: %d\n", pango_layout_get_height (layout));
-
- if (params.indent != 0)
+ if (pango_layout_get_indent (layout) != 0)
g_string_append_printf (string, "indent: %d\n", pango_layout_get_indent (layout));
g_string_append (string, "\n--- attributes\n\n");
@@ -509,19 +272,15 @@ test_file (const char *filename, GString *string)
dump_runs (layout, string);
g_object_unref (layout);
- g_free (contents);
-
- if (params.tabs)
- pango_tab_array_free (params.tabs);
}
static gchar *
-get_expected_filename (const gchar *filename)
+get_expected_filename (const char *filename)
{
- gchar *f, *p, *expected;
+ char *f, *p, *expected;
f = g_strdup (filename);
- p = strstr (f, ".markup");
+ p = strstr (f, ".layout");
if (p)
*p = 0;
expected = g_strconcat (f, ".expected", NULL);
@@ -534,11 +293,11 @@ get_expected_filename (const gchar *filename)
static void
test_layout (gconstpointer d)
{
- const gchar *filename = d;
- gchar *expected_file;
+ const char *filename = d;
+ char *expected_file;
GError *error = NULL;
GString *dump;
- gchar *diff;
+ char *diff;
PangoFontFamily **families;
int n_families;
gboolean found_cantarell;
@@ -616,7 +375,7 @@ main (int argc, char *argv[])
GDir *dir;
GError *error = NULL;
const gchar *name;
- gchar *path;
+ char *path;
GOptionContext *option_context;
GOptionEntry entries[] = {
{ "show-fonts", '0', 0, G_OPTION_ARG_NONE, &opt_show_font, "Print font names in dumps", NULL },
@@ -659,7 +418,7 @@ main (int argc, char *argv[])
g_assert_no_error (error);
while ((name = g_dir_read_name (dir)) != NULL)
{
- if (!strstr (name, "markup"))
+ if (!g_str_has_suffix (name, ".layout"))
continue;
path = g_strdup_printf ("/layout/%s", name);
diff --git a/tests/testserialize.c b/tests/testserialize.c
index 35c83504..884f010d 100644
--- a/tests/testserialize.c
+++ b/tests/testserialize.c
@@ -242,43 +242,66 @@ test_serialize_layout_valid (void)
static void
test_serialize_layout_invalid (void)
{
- const char *test1 =
- "{\n"
- " \"attributes\" : [\n"
- " {\n"
- " \"type\" : \"caramba\"\n"
- " }\n"
- " ]\n"
- "}";
-
- const char *test2 =
- "{\n"
- " \"attributes\" : [\n"
- " {\n"
- " \"type\" : \"weight\"\n"
- " }\n"
- " ]\n"
- "}";
+ struct {
+ const char *json;
+ int expected_error;
+ } test[] = {
+ {
+ "{\n"
+ " \"attributes\" : [\n"
+ " {\n"
+ " \"type\" : \"caramba\"\n"
+ " }\n"
+ " ]\n"
+ "}",
+ PANGO_LAYOUT_SERIALIZE_INVALID_VALUE
+ },
+ {
+ "{\n"
+ " \"attributes\" : [\n"
+ " {\n"
+ " \"type\" : \"weight\"\n"
+ " }\n"
+ " ]\n"
+ "}",
+ PANGO_LAYOUT_SERIALIZE_MISSING_VALUE
+ },
+ {
+ "{\n"
+ " \"attributes\" : [\n"
+ " {\n"
+ " \"type\" : \"alignment\",\n"
+ " \"value\" : \"nonsense\"\n"
+ " }\n"
+ " ]\n"
+ "}",
+ PANGO_LAYOUT_SERIALIZE_INVALID_VALUE
+ },
+ {
+ "{\n"
+ " \"alignment\" : \"nonsense\"\n"
+ "}",
+ PANGO_LAYOUT_SERIALIZE_INVALID_VALUE
+ }
+ };
PangoContext *context;
- GBytes *bytes;
- PangoLayout *layout;
- GError *error = NULL;
context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
- bytes = g_bytes_new_static (test1, -1);
- layout = pango_layout_deserialize (context, bytes, &error);
- g_assert_null (layout);
- g_assert_error (error, PANGO_LAYOUT_SERIALIZE_ERROR, PANGO_LAYOUT_SERIALIZE_INVALID_VALUE);
- g_bytes_unref (bytes);
- g_clear_error (&error);
-
- bytes = g_bytes_new_static (test2, -1);
- layout = pango_layout_deserialize (context, bytes, &error);
- g_assert_null (layout);
- g_assert_error (error, PANGO_LAYOUT_SERIALIZE_ERROR, PANGO_LAYOUT_SERIALIZE_MISSING_VALUE);
- g_bytes_unref (bytes);
+ for (int i = 0; i < G_N_ELEMENTS (test); i++)
+ {
+ GBytes *bytes;
+ PangoLayout *layout;
+ GError *error = NULL;
+
+ bytes = g_bytes_new_static (test[i].json, -1);
+ layout = pango_layout_deserialize (context, bytes, &error);
+ g_assert_null (layout);
+ g_assert_error (error, PANGO_LAYOUT_SERIALIZE_ERROR, test[i].expected_error);
+ g_bytes_unref (bytes);
+ g_clear_error (&error);
+ }
g_object_unref (context);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]