diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-11-13 18:33:00 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-11-17 00:28:07 -0500 |
commit | c58dfbfa2f49aab45b9a26b782a7c35db3bae110 (patch) | |
tree | 61c5396b320e1a33355583378698cf81587c0e93 /tests | |
parent | 9278c4f0c59b550f9d4ff10219d8e6242baa081f (diff) | |
download | pango-c58dfbfa2f49aab45b9a26b782a7c35db3bae110.tar.gz |
Add pango_attr_list_to/from_string
Add an api to serialize PangoAttrList.
This will be useful in testing and debugging.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/meson.build | 1 | ||||
-rw-r--r-- | tests/testserialize.c | 86 |
2 files changed, 87 insertions, 0 deletions
diff --git a/tests/meson.build b/tests/meson.build index b5eda3e7..00741a14 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -53,6 +53,7 @@ if cairo_dep.found() [ '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', 'validate-log-attrs.c' ], [libpangocairo_dep, glib_dep, harfbuzz_dep ] ], + [ 'testserialize', [ 'testserialize.c' ], [ libpangocairo_dep ] ], ] if host_system != 'darwin' diff --git a/tests/testserialize.c b/tests/testserialize.c new file mode 100644 index 00000000..cb5b27fd --- /dev/null +++ b/tests/testserialize.c @@ -0,0 +1,86 @@ +/* Pango + * + * Copyright (C) 2021 Matthias Clasen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" +#include <glib.h> +#include <pango/pangocairo.h> + +static void +test_serialize_attr_list (void) +{ + const char *valid[] = { + "5 16 style italic", + "0 10 foreground red, 5 15 weight bold, 0 200 font-desc \"Sans Small-Caps 10\"", + "0 10 foreground red\n5 15 weight bold\n0 200 font-desc \"Sans Small-Caps 10\"", + " 0 10 fallback false,\n 5 15 weight semilight\n\n \n \n", + "0 100 font-desc \"Cantarell, Sans, Italic Ultra-Light 64\", 10 11 weight 100", + "0 -1 size 10", + "0 1 weight 700, 2 4 weight book", + "0 200 rise 100\n5 15 family Times\n10 11 size 10240\n11 100 fallback 0\n30 60 stretch 2\n", + "" + }; + const char *roundtripped[] = { + "5 16 style italic", + "0 10 foreground #ffff00000000\n5 15 weight bold\n0 200 font-desc \"Sans Small-Caps 10\"", + "0 10 foreground #ffff00000000\n5 15 weight bold\n0 200 font-desc \"Sans Small-Caps 10\"", + "0 10 fallback false\n5 15 weight semilight", + "0 100 font-desc \"Cantarell,Sans Ultra-Light Italic 64\"\n10 11 weight thin", + "0 4294967295 size 10", + "0 1 weight bold\n2 4 weight book", + "0 200 rise 100\n5 15 family Times\n10 11 size 10240\n11 100 fallback false\n30 60 stretch condensed", + "" + }; + const char *invalid[] = { + "not an attr list", + "0 -1 FOREGROUND xyz", + ",,bla.wewq", + }; + + for (int i = 0; i < G_N_ELEMENTS (valid); i++) + { + PangoAttrList *attrs; + char *str; + + attrs = pango_attr_list_from_string (valid[i]); + g_assert_nonnull (attrs); + str = pango_attr_list_to_string (attrs); + g_assert_cmpstr (str, ==, roundtripped[i]); + g_free (str); + pango_attr_list_unref (attrs); + } + + for (int i = 0; i < G_N_ELEMENTS (invalid); i++) + { + PangoAttrList *attrs; + + attrs = pango_attr_list_from_string (invalid[i]); + g_assert_null (attrs); + } +} + +int +main (int argc, char *argv[]) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/serialize/attr-list", test_serialize_attr_list); + + return g_test_run (); +} |