summaryrefslogtreecommitdiff
path: root/testsuite/gtk/textbuffer.c
diff options
context:
space:
mode:
authorSébastien Wilmet <swilmet@gnome.org>2013-09-15 00:28:33 +0200
committerSébastien Wilmet <swilmet@gnome.org>2013-09-16 09:48:24 +0200
commit7e8bd7c43dcf4fa725b22a46fba2d2f755216c32 (patch)
tree9ef5daf8bac38fec97fbce453f4b3c40cdce2302 /testsuite/gtk/textbuffer.c
parent8e916815bbfcf943eb427c3721db0529654ac0ce (diff)
downloadgtk+-7e8bd7c43dcf4fa725b22a46fba2d2f755216c32.tar.gz
textbuffer: add unit tests for the clipboard
It tests gtk_text_buffer_paste_clipboard(), gtk_text_buffer_copy_clipboard() and gtk_text_buffer_cut_clipboard() in various situations, including when GtkTextTags are applied to the selection. The last test didn't pass. https://bugzilla.gnome.org/show_bug.cgi?id=339539
Diffstat (limited to 'testsuite/gtk/textbuffer.c')
-rw-r--r--testsuite/gtk/textbuffer.c92
1 files changed, 91 insertions, 1 deletions
diff --git a/testsuite/gtk/textbuffer.c b/testsuite/gtk/textbuffer.c
index e26a5ddfa8..50f50acaca 100644
--- a/testsuite/gtk/textbuffer.c
+++ b/testsuite/gtk/textbuffer.c
@@ -1319,6 +1319,95 @@ test_tag (void)
g_object_unref (buffer);
}
+static void
+check_buffer_contents (GtkTextBuffer *buffer,
+ const gchar *contents)
+{
+ GtkTextIter start;
+ GtkTextIter end;
+ gchar *buffer_contents;
+
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ buffer_contents = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+ g_assert_cmpstr (buffer_contents, ==, contents);
+}
+
+static void
+test_clipboard (void)
+{
+ GtkClipboard *clipboard;
+ GtkTextBuffer *buffer;
+ GtkTextIter start;
+ GtkTextIter end;
+ GtkTextTag *tag;
+
+ clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+
+ buffer = gtk_text_buffer_new (NULL);
+ gtk_text_buffer_set_text (buffer, "abcdef", -1);
+
+ /* Simple cut & paste */
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ gtk_text_buffer_get_iter_at_offset (buffer, &end, 3);
+ gtk_text_buffer_select_range (buffer, &start, &end);
+
+ gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
+ check_buffer_contents (buffer, "def");
+
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ gtk_text_buffer_paste_clipboard (buffer, clipboard, &end, TRUE);
+ check_buffer_contents (buffer, "defabc");
+
+ /* Simple copy & paste */
+ gtk_text_buffer_get_iter_at_offset (buffer, &start, 3);
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ gtk_text_buffer_select_range (buffer, &start, &end);
+ gtk_text_buffer_copy_clipboard (buffer, clipboard);
+
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ gtk_text_buffer_paste_clipboard (buffer, clipboard, &start, TRUE);
+ check_buffer_contents (buffer, "abcdefabc");
+
+ /* Replace the selection when pasting */
+ gtk_text_buffer_set_text (buffer, "abcdef", -1);
+
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ gtk_text_buffer_get_iter_at_offset (buffer, &end, 3);
+ gtk_text_buffer_select_range (buffer, &start, &end);
+ gtk_text_buffer_copy_clipboard (buffer, clipboard);
+
+ gtk_text_buffer_get_iter_at_offset (buffer, &start, 3);
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ gtk_text_buffer_select_range (buffer, &start, &end);
+ gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
+ check_buffer_contents (buffer, "abcabc");
+
+ /* Copy & paste text with tags.
+ * See https://bugzilla.gnome.org/show_bug.cgi?id=339539
+ */
+ gtk_text_buffer_set_text (buffer, "abcdef", -1);
+
+ tag = gtk_text_buffer_create_tag (buffer, NULL, NULL);
+
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ gtk_text_buffer_get_iter_at_offset (buffer, &end, 4);
+ gtk_text_buffer_apply_tag (buffer, tag, &start, &end);
+
+ gtk_text_buffer_get_iter_at_offset (buffer, &start, 3);
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ gtk_text_buffer_select_range (buffer, &start, &end);
+ gtk_text_buffer_copy_clipboard (buffer, clipboard);
+ gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
+ check_buffer_contents (buffer, "abcdef");
+
+ gtk_text_buffer_get_iter_at_offset (buffer, &start, 3);
+ g_assert (gtk_text_iter_forward_to_tag_toggle (&start, tag));
+ g_assert_cmpint (4, ==, gtk_text_iter_get_offset (&start));
+
+ g_object_unref (buffer);
+}
+
int
main (int argc, char** argv)
{
@@ -1336,6 +1425,7 @@ main (int argc, char** argv)
g_test_add_func ("/TextBuffer/Get and Set", test_get_set);
g_test_add_func ("/TextBuffer/Fill and Empty", test_fill_empty);
g_test_add_func ("/TextBuffer/Tag", test_tag);
-
+ g_test_add_func ("/TextBuffer/Clipboard", test_clipboard);
+
return g_test_run();
}