Debian Codegraph @

testsuite/gtk/clipboard.c

raw
1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2013 Benjamin Otte <[email protected]>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <gtk/gtk.h>
19
20 #include <string.h>
21
22 #define SOME_TEXT "Hello World"
23 #define TARGET_TEXT "UTF8_STRING"
24
25 static void
26 test_text (void)
27 {
28 GtkClipboard *clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (), GDK_SELECTION_CLIPBOARD);
29 char *text;
30
31 gtk_clipboard_set_text (clipboard, SOME_TEXT, -1);
32 text = gtk_clipboard_wait_for_text (clipboard);
33 g_assert_cmpstr (text, ==, SOME_TEXT);
34 g_free (text);
35
36 gtk_clipboard_set_text (clipboard, SOME_TEXT SOME_TEXT, strlen (SOME_TEXT));
37 text = gtk_clipboard_wait_for_text (clipboard);
38 g_assert_cmpstr (text, ==, SOME_TEXT);
39 g_free (text);
40 }
41
42 static void
43 test_with_data_get (GtkClipboard *clipboard,
44 GtkSelectionData *selection_data,
45 guint info,
46 gpointer user_data_or_owner)
47 {
48 gboolean success;
49
50 g_assert_cmpuint (info, ==, 42);
51
52 success = gtk_selection_data_set_text (selection_data, SOME_TEXT, -1);
53 g_assert (success);
54 }
55
56 static void
57 test_with_data_got (GtkClipboard *clipboard,
58 GtkSelectionData *selection_data,
59 gpointer data)
60 {
61 guchar *text;
62
63 text = gtk_selection_data_get_text (selection_data);
64 g_assert_cmpstr ((char*)text, ==, SOME_TEXT);
65 g_free (text);
66 }
67
68 static void
69 test_with_data (void)
70 {
71 GtkClipboard *clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (), GDK_SELECTION_CLIPBOARD);
72 GtkTargetEntry entries[] = { { .target = TARGET_TEXT, .info = 42 } };
73
74 gtk_clipboard_set_with_data (clipboard, entries, G_N_ELEMENTS(entries), test_with_data_get, NULL, NULL);
75 gtk_clipboard_request_contents (clipboard, gdk_atom_intern (TARGET_TEXT, FALSE), test_with_data_got, NULL);
76 }
77
78 int
79 main (int argc,
80 char *argv[])
81 {
82 gtk_test_init (&argc, &argv);
83
84 g_test_add_func ("/clipboard/test_text", test_text);
85 g_test_add_func ("/clipboard/test_with_data", test_with_data);
86
87 return g_test_run();
88 }