summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2020-09-18 06:07:19 +0200
committerBenjamin Otte <otte@redhat.com>2020-09-18 06:10:03 +0200
commitcdf990617f42706f54057ec233fe39283b73d1ea (patch)
tree7c3389ae1a76a4ad0260f7c1b37bc1dd1808bbf1
parent57431a4afd720f2f1f19e926e81c8fffcff3fb2e (diff)
downloadgtk+-wip/otte/clipboard.tar.gz
testsuite: Add a basic test for remote clipboardswip/otte/clipboard
Unfortunately, Wayland doesn't allow access to the clipboard unless the display has focus, so no chance of testing it there. But it works elsewhere.
-rw-r--r--testsuite/gdk/clipboard.c126
1 files changed, 123 insertions, 3 deletions
diff --git a/testsuite/gdk/clipboard.c b/testsuite/gdk/clipboard.c
index 741899401f..81b81214f9 100644
--- a/testsuite/gdk/clipboard.c
+++ b/testsuite/gdk/clipboard.c
@@ -2,10 +2,46 @@
#include <gtk/gtk.h>
+#ifdef GDK_WINDOWING_WAYLAND
+#include "wayland/gdkwayland.h"
+#endif
+
static void
-text_received (GObject *source,
+value_received (GObject *source,
+ GAsyncResult *res,
+ gpointer data)
+{
+ GdkClipboard *clipboard = GDK_CLIPBOARD (source);
+ const GValue *value;
+ GValue *expected = data;
+ GError *error = NULL;
+
+ value = gdk_clipboard_read_value_finish (clipboard, res, &error);
+
+ g_assert_nonnull (value);
+ g_assert_no_error (error);
+
+ g_assert_cmpuint (G_VALUE_TYPE (value), ==, G_VALUE_TYPE (expected));
+
+ if (G_VALUE_TYPE (value) == G_TYPE_STRING)
+ {
+ g_assert_cmpstr (g_value_get_string (value), ==, g_value_get_string (expected));
+ }
+ else
+ {
+ /* Add a comparison for the missing type here */
+ g_assert_cmpuint (G_VALUE_TYPE (value), ==, G_TYPE_INVALID);
+ }
+
+ g_value_unset (expected);
+
+ g_main_context_wakeup (NULL);
+}
+
+static void
+text_received (GObject *source,
GAsyncResult *res,
- gpointer data)
+ gpointer data)
{
GdkClipboard *clipboard = GDK_CLIPBOARD (source);
gboolean *done = data;
@@ -70,14 +106,98 @@ test_clipboard_basic (void)
g_value_unset (&value);
}
+static void
+remote_clipboard_sync_changed_cb (GdkClipboard *clipboard,
+ gboolean *done)
+{
+ GdkContentFormats *formats = gdk_clipboard_get_formats (clipboard);
+
+ /* X11 needs to query formats first and reports empty until then */
+ if (gdk_content_formats_get_gtypes (formats, NULL) == NULL &&
+ gdk_content_formats_get_mime_types (formats, NULL) == NULL)
+ return;
+
+ *done = TRUE;
+}
+
+static void
+remote_clipboard_sync (GdkClipboard *clipboard)
+{
+ guint signal;
+ gboolean done;
+
+ done = FALSE;
+ signal = g_signal_connect (clipboard, "changed", G_CALLBACK (remote_clipboard_sync_changed_cb), &done);
+
+ while (!done)
+ g_main_context_iteration (NULL, TRUE);
+
+ g_signal_handler_disconnect (clipboard, signal);
+}
+
+static void
+test_remote_basic (gconstpointer data)
+{
+ GdkDisplay *display, *remote_display;
+ GdkClipboard *clipboard, *remote_clipboard;
+ GdkContentFormats *formats;
+ GValue value = G_VALUE_INIT;
+
+ display = gdk_display_get_default ();
+ clipboard = gdk_display_get_clipboard (display);
+ remote_display = GDK_DISPLAY (data);
+ remote_clipboard = gdk_display_get_clipboard (remote_display);
+
+ g_assert_true (gdk_clipboard_get_display (clipboard) == display);
+ g_assert_true (gdk_clipboard_get_display (remote_clipboard) == remote_display);
+
+ gdk_clipboard_set_text (clipboard, "testing, 1, 2");
+ remote_clipboard_sync (remote_clipboard);
+
+ g_assert_true (gdk_clipboard_is_local (clipboard));
+ g_assert_false (gdk_clipboard_is_local (remote_clipboard));
+ g_assert_null (gdk_clipboard_get_content (remote_clipboard));
+
+ formats = gdk_clipboard_get_formats (remote_clipboard);
+
+ g_assert_true (gdk_content_formats_contain_gtype (formats, G_TYPE_STRING));
+ g_assert_true (gdk_content_formats_contain_mime_type (formats, "text/plain"));
+
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_string (&value, "testing, 1, 2");
+ gdk_clipboard_read_value_async (remote_clipboard, G_TYPE_STRING, G_PRIORITY_DEFAULT, NULL, value_received, &value);
+ while (G_IS_VALUE (&value))
+ g_main_context_iteration (NULL, TRUE);
+
+ g_assert_null (gdk_clipboard_get_content (remote_clipboard));
+}
+
int
main (int argc, char *argv[])
{
+ GdkDisplay *remote_display;
+ int result;
+
g_test_init (&argc, &argv, NULL);
gtk_init ();
g_test_add_func ("/clipboard/basic", test_clipboard_basic);
- return g_test_run ();
+ remote_display = gdk_display_open (NULL);
+
+#ifdef GDK_WINDOWING_WAYLAND
+ if (!GDK_IS_WAYLAND_DISPLAY (remote_display))
+#else
+ if (true)
+#endif
+ {
+ g_test_add_data_func ("/clipboard/remote/basic", remote_display, test_remote_basic);
+ }
+
+ result = g_test_run ();
+
+ g_object_unref (remote_display);
+
+ return result;
}