[gtk/contentformat-tests] Add tests for GdkContentFormats




commit f9194042f4b629522cdcdfae674ece6f89837ee2
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jul 26 15:53:12 2021 -0400

    Add tests for GdkContentFormats
    
    This isn't super-extensive yet, but its a start.

 testsuite/gdk/contentformats.c | 70 ++++++++++++++++++++++++++++++++++++++++++
 testsuite/gdk/meson.build      |  1 +
 2 files changed, 71 insertions(+)
---
diff --git a/testsuite/gdk/contentformats.c b/testsuite/gdk/contentformats.c
new file mode 100644
index 0000000000..0a1faf87fe
--- /dev/null
+++ b/testsuite/gdk/contentformats.c
@@ -0,0 +1,70 @@
+#include <gdk/gdk.h>
+
+static void
+test_contentformats_types (void)
+{
+  GdkContentFormats *formats;
+  const char *const *mimetypes;
+  gsize n_types;
+  const GType *gtypes;
+
+  formats = gdk_content_formats_parse ("text/plain GdkFileList application/x-color GdkRGBA");
+
+  g_assert_nonnull (formats);
+
+  mimetypes = gdk_content_formats_get_mime_types (formats, &n_types);
+  g_assert_true (n_types == 2);
+  g_assert_cmpstr (mimetypes[0], ==, "text/plain");
+  g_assert_cmpstr (mimetypes[1], ==, "application/x-color");
+
+  gtypes = gdk_content_formats_get_gtypes (formats, &n_types);
+  g_assert_true (n_types == 2);
+  g_assert_true (gtypes[0] == GDK_TYPE_FILE_LIST);
+  g_assert_true (gtypes[1] == GDK_TYPE_RGBA);
+
+  gdk_content_formats_unref (formats);
+}
+
+static void
+test_contentformats_union (void)
+{
+  GdkContentFormats *formats;
+  GdkContentFormats *formats2;
+  const char *const *mimetypes;
+  gsize n_types;
+  const GType *gtypes;
+
+  formats = gdk_content_formats_parse ("text/plain application/x-color");
+  formats2 = gdk_content_formats_parse ("GdkFileList GdkRGBA");
+
+  formats = gdk_content_formats_union (formats, formats2);
+
+  g_assert_nonnull (formats);
+
+  mimetypes = gdk_content_formats_get_mime_types (formats, &n_types);
+  g_assert_true (n_types == 2);
+  g_assert_cmpstr (mimetypes[0], ==, "text/plain");
+  g_assert_cmpstr (mimetypes[1], ==, "application/x-color");
+
+  gtypes = gdk_content_formats_get_gtypes (formats, &n_types);
+  g_assert_true (n_types == 2);
+  g_assert_true (gtypes[0] == GDK_TYPE_FILE_LIST);
+  g_assert_true (gtypes[1] == GDK_TYPE_RGBA);
+
+  gdk_content_formats_unref (formats2);
+  gdk_content_formats_unref (formats);
+}
+
+int
+main (int argc, char *argv[])
+{
+  (g_test_init) (&argc, &argv, NULL);
+
+  g_type_ensure (GDK_TYPE_RGBA);
+  g_type_ensure (GDK_TYPE_FILE_LIST);
+
+  g_test_add_func ("/contentformats/types", test_contentformats_types);
+  g_test_add_func ("/contentformats/union", test_contentformats_union);
+
+  return g_test_run ();
+}
diff --git a/testsuite/gdk/meson.build b/testsuite/gdk/meson.build
index 50bfd0b5d0..5e62e98775 100644
--- a/testsuite/gdk/meson.build
+++ b/testsuite/gdk/meson.build
@@ -13,6 +13,7 @@ tests = [
   'array',
   'cairo',
   'clipboard',
+  'contentformats',
   'contentserializer',
   'cursor',
   'display',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]