summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-07-26 15:54:12 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-07-26 15:55:34 -0400
commit5cb7e60c7304a62f81b34f10f86d08cffc8ad229 (patch)
treeb56c9efde35594d4510d67d860ad7f5dcfa719df
parentf9194042f4b629522cdcdfae674ece6f89837ee2 (diff)
downloadgtk+-content_format_parse-tests.tar.gz
Add tests for gdk_content_formats_parsecontent_format_parse-tests
Add a test that checks we can roundtrip things through gdk_content_formats_parse and gdk_content_formats_to_string.
-rw-r--r--testsuite/gdk/contentformats.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/testsuite/gdk/contentformats.c b/testsuite/gdk/contentformats.c
index 0a1faf87fe..3a429f0e9b 100644
--- a/testsuite/gdk/contentformats.c
+++ b/testsuite/gdk/contentformats.c
@@ -1,6 +1,51 @@
#include <gdk/gdk.h>
static void
+test_contentformats_parse (void)
+{
+ struct {
+ const char *test;
+ const char *output;
+ } tests[] = {
+ { "", "" },
+ { "text/plain;charset=utf8", "text/plain;charset=utf8" },
+ { "text/plain GdkRGBA", "GdkRGBA text/plain" },
+ { "text/plain\nGdkRGBA", "GdkRGBA text/plain" },
+ { "text/plain\t\nGdkRGBA", "GdkRGBA text/plain" },
+ { "UUU", NULL },
+ { "GdkFileList", "GdkFileList" },
+ };
+
+ for (int i = 0; i < G_N_ELEMENTS (tests); i++)
+ {
+ GdkContentFormats *formats;
+ char *s;
+
+ formats = gdk_content_formats_parse (tests[i].test);
+ if (tests[i].output == NULL)
+ {
+ g_assert_null (formats);
+ continue;
+ }
+
+ s = gdk_content_formats_to_string (formats);
+
+ g_assert_cmpstr (s, ==, tests[i].output);
+
+ gdk_content_formats_unref (formats);
+ g_free (s);
+
+ formats = gdk_content_formats_parse (tests[i].output);
+ s = gdk_content_formats_to_string (formats);
+
+ g_assert_cmpstr (s, ==, tests[i].output);
+
+ gdk_content_formats_unref (formats);
+ g_free (s);
+ }
+}
+
+static void
test_contentformats_types (void)
{
GdkContentFormats *formats;
@@ -63,6 +108,7 @@ main (int argc, char *argv[])
g_type_ensure (GDK_TYPE_RGBA);
g_type_ensure (GDK_TYPE_FILE_LIST);
+ g_test_add_func ("/contentformats/parse", test_contentformats_parse);
g_test_add_func ("/contentformats/types", test_contentformats_types);
g_test_add_func ("/contentformats/union", test_contentformats_union);