[gtksourceview/wip/search] search: unit tests



commit cf908e9605a3ea4231fcfe1a68d15d497a289d41
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jun 22 13:56:41 2013 +0200

    search: unit tests
    
    Doesn't pass, there is an infinite loop.

 tests/Makefile.am   |    8 +++++
 tests/test-search.c |   85 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ab64112..7a55e7d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -132,6 +132,14 @@ test_undo_manager_LDADD =                                  \
        $(DEP_LIBS)                                             \
        $(TESTS_LIBS)
 
+UNIT_TEST_PROGS += test-search
+test_search_SOURCES = test-search.c
+test_search_LDADD =                                                    \
+       $(top_builddir)/gtksourceview/libgtksourceview-3.0.la           \
+       $(top_builddir)/gtksourceview/libgtksourceview-private.la       \
+       $(DEP_LIBS)                                                     \
+       $(TESTS_LIBS)
+
 python_tests =                 \
        test-completion.py      \
        test-widget.py
diff --git a/tests/test-search.c b/tests/test-search.c
new file mode 100644
index 0000000..20851b7
--- /dev/null
+++ b/tests/test-search.c
@@ -0,0 +1,85 @@
+/*
+ * test-search.c
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2013 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksource.h>
+#include "gtksourceview/gtksourcesearch.h"
+
+static void
+flush_queue (void)
+{
+       while (gtk_events_pending ())
+       {
+               gtk_main_iteration ();
+       }
+}
+
+/* Without insertion or deletion of text in the buffer afterwards. */
+static void
+test_occurrences_count_simple (void)
+{
+       GtkSourceBuffer *buffer = gtk_source_buffer_new (NULL);
+       GtkTextIter iter;
+       guint occurrences_count;
+
+       gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
+       gtk_text_buffer_insert (GTK_TEXT_BUFFER (buffer), &iter, "Some foo\nSome bar\n", -1);
+       flush_queue ();
+
+       occurrences_count = gtk_source_buffer_get_search_occurrences_count (buffer);
+       g_assert_cmpuint (occurrences_count, ==, 0);
+
+       gtk_source_buffer_set_search_text (buffer, "world");
+       flush_queue ();
+
+       occurrences_count = gtk_source_buffer_get_search_occurrences_count (buffer);
+       g_assert_cmpuint (occurrences_count, ==, 0);
+
+       gtk_source_buffer_set_search_text (buffer, "Some");
+       flush_queue ();
+
+       occurrences_count = gtk_source_buffer_get_search_occurrences_count (buffer);
+       g_assert_cmpuint (occurrences_count, ==, 2);
+
+       gtk_source_buffer_set_search_text (buffer, "foo");
+       flush_queue ();
+
+       occurrences_count = gtk_source_buffer_get_search_occurrences_count (buffer);
+       g_assert_cmpuint (occurrences_count, ==, 1);
+
+       gtk_source_buffer_set_search_text (buffer, "world");
+       flush_queue ();
+
+       occurrences_count = gtk_source_buffer_get_search_occurrences_count (buffer);
+       g_assert_cmpuint (occurrences_count, ==, 0);
+
+       g_object_unref (buffer);
+}
+
+int
+main (int argc, char **argv)
+{
+       gtk_test_init (&argc, &argv);
+
+       g_test_add_func ("/Search/occurrences-count/simple", test_occurrences_count_simple);
+
+       return g_test_run ();
+}


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