[gtk/content_format_parse-tests] Add tests for gdk_content_formats_parse
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/content_format_parse-tests] Add tests for gdk_content_formats_parse
- Date: Mon, 26 Jul 2021 19:58:51 +0000 (UTC)
commit 5cb7e60c7304a62f81b34f10f86d08cffc8ad229
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jul 26 15:54:12 2021 -0400
Add tests for gdk_content_formats_parse
Add a test that checks we can roundtrip things through
gdk_content_formats_parse and gdk_content_formats_to_string.
testsuite/gdk/contentformats.c | 46 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
---
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,5 +1,50 @@
#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)
{
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]