[gtksourceview/wip/search: 2/2] Really basic test program for the search and replace



commit d610f90f0cf124eae5b2c9db1fe62fcda7d2f477
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Jun 14 22:44:22 2013 +0200

    Really basic test program for the search and replace

 tests/Makefile.am               |   25 +++++++++--
 tests/test-search.c             |   81 ++++++++++++++++++++++++++++++++++
 tests/test-search.gresource.xml |    6 +++
 tests/test-search.ui            |   91 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 198 insertions(+), 5 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ef30933..fc7a3f5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -13,12 +13,16 @@ AM_CPPFLAGS =                               \
 noinst_PROGRAMS = $(TEST_PROGS) $(UNIT_TEST_PROGS)
 TESTS = $(UNIT_TEST_PROGS)
 
-BUILT_SOURCES = \
-       test-completion-resources.c
+BUILT_SOURCES =                                \
+       test-completion-resources.c     \
+       test-search-resources.c
 
 test-completion-resources.c: test-completion.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) 
--generate-dependencies $(srcdir)/test-completion.gresource.xml)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(srcdir)/test-completion.gresource.xml
 
+test-search-resources.c: test-search.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies 
$(srcdir)/test-search.gresource.xml)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(srcdir)/test-search.gresource.xml
+
 TEST_PROGS = test-widget
 test_widget_SOURCES = test-widget.c
 test_widget_LDADD =                    \
@@ -27,14 +31,23 @@ test_widget_LDADD =                         \
        $(TESTS_LIBS)
 
 TEST_PROGS += test-completion
-test_completion_SOURCES =      \
-       $(BUILT_SOURCES)        \
-       test-completion.c
+test_completion_SOURCES =              \
+       test-completion.c               \
+       test-completion-resources.c
 test_completion_LDADD =                \
        $(top_builddir)/gtksourceview/libgtksourceview-3.0.la \
        $(DEP_LIBS)                     \
        $(TESTS_LIBS)
 
+TEST_PROGS += test-search
+test_search_SOURCES =          \
+       test-search.c           \
+       test-search-resources.c
+test_search_LDADD =                                            \
+       $(top_builddir)/gtksourceview/libgtksourceview-3.0.la   \
+       $(DEP_LIBS)                                             \
+       $(TESTS_LIBS)
+
 UNIT_TEST_PROGS = test-languagemanager
 test_languagemanager_SOURCES =         \
        test-languagemanager.c
@@ -129,6 +142,8 @@ EXTRA_DIST =                                \
        styles/classic.xml              \
        test-completion.gresource.xml   \
        test-completion.ui              \
+       test-search.gresource.xml       \
+       test-search.ui                  \
        $(python_tests)
 
 -include $(top_srcdir)/git.mk
diff --git a/tests/test-search.c b/tests/test-search.c
new file mode 100644
index 0000000..7115889
--- /dev/null
+++ b/tests/test-search.c
@@ -0,0 +1,81 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ * 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>
+
+static void
+create_window (void)
+{
+       GtkBuilder *builder;
+       GError *error = NULL;
+       GtkWindow *window;
+       GtkSourceView *source_view;
+       GtkSourceBuffer *source_buffer;
+       GtkSearchEntry *search_entry;
+
+       builder = gtk_builder_new ();
+
+       gtk_builder_add_from_resource (builder,
+                                      "/org/gnome/gtksourceview/tests/ui/test-search.ui",
+                                      &error);
+
+       if (error != NULL)
+       {
+               g_error ("Impossible to load test-search.ui: %s", error->message);
+       }
+
+       window = GTK_WINDOW (gtk_builder_get_object (builder, "window"));
+       source_view = GTK_SOURCE_VIEW (gtk_builder_get_object (builder, "source_view"));
+       search_entry = GTK_SEARCH_ENTRY (gtk_builder_get_object (builder, "search_entry"));
+
+       /* Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=643732:
+        * "Source view is created with a GtkTextBuffer instead of GtkSourceBuffer"
+        */
+       source_buffer = gtk_source_buffer_new (NULL);
+
+       gtk_text_view_set_buffer (GTK_TEXT_VIEW (source_view),
+                                 GTK_TEXT_BUFFER (source_buffer));
+
+       g_object_unref (source_buffer);
+
+       g_signal_connect (window,
+                         "destroy",
+                         G_CALLBACK (gtk_main_quit),
+                         NULL);
+
+       g_object_bind_property (search_entry, "text",
+                               source_buffer, "search-string",
+                               G_BINDING_DEFAULT);
+
+       g_object_unref (builder);
+}
+
+int
+main (int argc, char *argv[])
+{
+       gtk_init (&argc, &argv);
+
+       create_window ();
+
+       gtk_main ();
+       return 0;
+}
diff --git a/tests/test-search.gresource.xml b/tests/test-search.gresource.xml
new file mode 100644
index 0000000..8cfee5b
--- /dev/null
+++ b/tests/test-search.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/gtksourceview/tests/ui">
+    <file preprocess="xml-stripblanks">test-search.ui</file>
+  </gresource>
+</gresources>
diff --git a/tests/test-search.ui b/tests/test-search.ui
new file mode 100644
index 0000000..3154231
--- /dev/null
+++ b/tests/test-search.ui
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.6 -->
+  <!-- interface-requires gtksourceview 3.0 -->
+  <object class="GtkWindow" id="window">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkGrid" id="grid1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="border_width">6</property>
+        <property name="row_spacing">6</property>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow1">
+            <property name="width_request">500</property>
+            <property name="height_request">300</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="shadow_type">in</property>
+            <child>
+              <object class="GtkSourceView" id="source_view">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="has_tooltip">True</property>
+                <property name="hexpand">True</property>
+                <property name="vexpand">True</property>
+                <property name="left_margin">2</property>
+                <property name="right_margin">2</property>
+                <property name="tab_width">4</property>
+                <property name="auto_indent">True</property>
+                <property name="indent_on_tab">False</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="column_spacing">6</property>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label">Search:</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSearchEntry" id="search_entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="primary_icon_name">edit-find-symbolic</property>
+                <property name="primary_icon_activatable">False</property>
+                <property name="primary_icon_sensitive">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>


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