[gtksourceview/wip/fix-line-shifting] testsuite: add unit test for GtkSourceView::move-lines
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/fix-line-shifting] testsuite: add unit test for GtkSourceView::move-lines
- Date: Wed, 29 Mar 2017 15:45:37 +0000 (UTC)
commit 99acf926a7dd77dea9cbcd1b25ac1a43cc3bb0f3
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Mar 29 17:15:40 2017 +0200
testsuite: add unit test for GtkSourceView::move-lines
https://bugzilla.gnome.org/show_bug.cgi?id=624963
testsuite/Makefile.am | 3 +
testsuite/test-view.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 124 insertions(+), 0 deletions(-)
---
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 55ede27..a467149 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -91,6 +91,9 @@ test_undo_manager_SOURCES = test-undo-manager.c
UNIT_TEST_PROGS += test-utils
test_utils_SOURCES = test-utils.c
+UNIT_TEST_PROGS += test-view
+test_view_SOURCES = test-view.c
+
TESTS_ENVIRONMENT = G_TEST_SRCDIR="$(abs_srcdir)"
TESTS = $(UNIT_TEST_PROGS)
noinst_PROGRAMS = $(UNIT_TEST_PROGS)
diff --git a/testsuite/test-view.c b/testsuite/test-view.c
new file mode 100644
index 0000000..d8f3c1d
--- /dev/null
+++ b/testsuite/test-view.c
@@ -0,0 +1,121 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/*
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2017 - Sébastien Wilmet
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtksourceview/gtksource.h>
+
+static gchar *
+get_text (GtkTextBuffer *buffer)
+{
+ GtkTextIter start;
+ GtkTextIter end;
+
+ gtk_text_buffer_get_bounds (buffer, &start, &end);
+ return gtk_text_buffer_get_text (buffer, &start, &end, TRUE);
+}
+
+static void
+test_move_lines (void)
+{
+ GtkSourceView *view;
+ GtkTextBuffer *buffer;
+ GtkTextIter start;
+ GtkTextIter end;
+ gchar *text;
+ gint i;
+
+ view = GTK_SOURCE_VIEW (gtk_source_view_new ());
+ g_object_ref_sink (view);
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+
+ /* Move down */
+ for (i = 0; i < 6; i++)
+ {
+ gtk_text_buffer_set_text (buffer,
+ "line1\n"
+ "line2\n"
+ "line3",
+ -1);
+
+ /* Place cursor or select range */
+ switch (i)
+ {
+ case 0:
+ gtk_text_buffer_get_iter_at_offset (buffer, &start, 0);
+ gtk_text_buffer_place_cursor (buffer, &start);
+ break;
+
+ case 1:
+ gtk_text_buffer_get_iter_at_offset (buffer, &start, 1);
+ gtk_text_buffer_place_cursor (buffer, &start);
+ break;
+
+ case 2:
+ gtk_text_buffer_get_iter_at_offset (buffer, &start, 5);
+ gtk_text_buffer_place_cursor (buffer, &start);
+ break;
+
+ case 3:
+ gtk_text_buffer_get_iter_at_offset (buffer, &start, 0);
+ gtk_text_buffer_get_iter_at_offset (buffer, &end, 5);
+ gtk_text_buffer_select_range (buffer, &start, &end);
+ break;
+
+ case 4:
+ gtk_text_buffer_get_iter_at_offset (buffer, &start, 0);
+ gtk_text_buffer_get_iter_at_offset (buffer, &end, 6);
+ gtk_text_buffer_select_range (buffer, &start, &end);
+ break;
+
+ case 5:
+ gtk_text_buffer_get_iter_at_offset (buffer, &start, 1);
+ gtk_text_buffer_get_iter_at_offset (buffer, &end, 3);
+ gtk_text_buffer_select_range (buffer, &start, &end);
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ g_signal_emit_by_name (view, "move-lines", FALSE, 1);
+ text = get_text (buffer);
+ g_assert_cmpstr (text, ==,
+ "line2\n"
+ "line1\n"
+ "line3");
+ g_free (text);
+
+ gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
+ g_assert_cmpint (gtk_text_iter_get_offset (&start), ==, 6);
+ g_assert_cmpint (gtk_text_iter_get_offset (&end), ==, 12);
+ }
+
+ g_object_unref (view);
+}
+
+int
+main (int argc, char **argv)
+{
+ gtk_test_init (&argc, &argv);
+
+ g_test_add_func ("/view/move-lines", test_move_lines);
+
+ return g_test_run();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]