[gtk+] tests: add clipboard set_with_data test



commit a3d0b8d7f4a5dfe12dde0e69c1ff816dfa457691
Author: Marc-André Lureau <marcandre lureau gmail com>
Date:   Fri May 16 20:42:28 2014 +0200

    tests: add clipboard set_with_data test
    
    https://bugzilla.gnome.org/show_bug.cgi?id=730183

 testsuite/gtk/clipboard.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/testsuite/gtk/clipboard.c b/testsuite/gtk/clipboard.c
index 83f1667..e665ff7 100644
--- a/testsuite/gtk/clipboard.c
+++ b/testsuite/gtk/clipboard.c
@@ -20,6 +20,7 @@
 #include <string.h>
 
 #define SOME_TEXT "Hello World"
+#define TARGET_TEXT "UTF8_STRING"
 
 static void
 test_text (void)
@@ -38,6 +39,42 @@ test_text (void)
   g_free (text);
 }
 
+static void
+test_with_data_get (GtkClipboard *clipboard,
+                    GtkSelectionData *selection_data,
+                    guint info,
+                    gpointer user_data_or_owner)
+{
+    gboolean success;
+
+    g_assert_cmpuint (info, ==, 42);
+
+    success = gtk_selection_data_set_text (selection_data, SOME_TEXT, -1);
+    g_assert (success);
+}
+
+static void
+test_with_data_got (GtkClipboard *clipboard,
+                    GtkSelectionData *selection_data,
+                    gpointer data)
+{
+    guchar *text;
+
+    text = gtk_selection_data_get_text (selection_data);
+    g_assert_cmpstr ((char*)text, ==, SOME_TEXT);
+    g_free (text);
+}
+
+static void
+test_with_data (void)
+{
+    GtkClipboard *clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (), 
GDK_SELECTION_CLIPBOARD);
+    GtkTargetEntry entries[] = { { .target = TARGET_TEXT, .info = 42 } };
+
+    gtk_clipboard_set_with_data (clipboard, entries, G_N_ELEMENTS(entries), test_with_data_get, NULL, NULL);
+    gtk_clipboard_request_contents (clipboard, gdk_atom_intern (TARGET_TEXT, FALSE), test_with_data_got, 
NULL);
+}
+
 int
 main (int   argc,
       char *argv[])
@@ -45,6 +82,7 @@ main (int   argc,
   gtk_test_init (&argc, &argv);
 
   g_test_add_func ("/clipboard/test_text", test_text);
+  g_test_add_func ("/clipboard/test_with_data", test_with_data);
 
   return g_test_run();
 }


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