[gtk+] Start general GtkTreeView unit tests



commit 531c7e535bceb05ace097b9e9fdc4720e18b2252
Author: Kristian Rietveld <kris gtk org>
Date:   Thu Jul 30 13:54:30 2009 +0200

    Start general GtkTreeView unit tests
    
    Includes a test case for bug 546005 to start with, logic provided by
    Paul Pogonyshev and Bjorn Lindqvist.  In the future, we should maybe
    merge treeview-scrolling.c with this one to create one large monolithic
    tree view tester.

 gtk/tests/Makefile.am |    4 ++
 gtk/tests/treeview.c  |   81 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/gtk/tests/Makefile.am b/gtk/tests/Makefile.am
index 4c8ff1f..541cbc2 100644
--- a/gtk/tests/Makefile.am
+++ b/gtk/tests/Makefile.am
@@ -34,6 +34,10 @@ TEST_PROGS			+= treestore
 treestore_SOURCES		 = treestore.c
 treestore_LDADD			 = $(progs_ldadd)
 
+TEST_PROGS			+= treeview
+treeview_SOURCES		 = treeview.c
+treeview_LDADD			 = $(progs_ldadd)
+
 TEST_PROGS			+= treeview-scrolling
 treeview_scrolling_SOURCES	 = treeview-scrolling.c
 treeview_scrolling_LDADD	 = $(progs_ldadd)
diff --git a/gtk/tests/treeview.c b/gtk/tests/treeview.c
new file mode 100644
index 0000000..c64d7ba
--- /dev/null
+++ b/gtk/tests/treeview.c
@@ -0,0 +1,81 @@
+/* Basic GtkTreeView unit tests.
+ * Copyright (C) 2009  Kristian Rietveld  <kris gtk org>
+ *
+ * This library 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 of the License, or (at your option) any later version.
+ *
+ * This library 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gtk/gtk.h>
+
+static void
+test_bug_546005 (void)
+{
+  GtkTreeIter iter;
+  GtkTreePath *path;
+  GtkTreePath *cursor_path;
+  GtkListStore *list_store;
+  GtkWidget *view;
+
+  /* Tests provided by Bjorn Lindqvist, Paul Pogonyshev */
+  view = gtk_tree_view_new ();
+
+  /* Invalid path on tree view without model */
+  path = gtk_tree_path_new_from_indices (1, -1);
+  gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
+                            NULL, FALSE);
+  gtk_tree_path_free (path);
+
+  list_store = gtk_list_store_new (1, G_TYPE_STRING);
+  gtk_tree_view_set_model (GTK_TREE_VIEW (view),
+                           GTK_TREE_MODEL (list_store));
+
+  /* Invalid path on tree view with empty model */
+  path = gtk_tree_path_new_from_indices (1, -1);
+  gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
+                            NULL, FALSE);
+  gtk_tree_path_free (path);
+
+  /* Valid path */
+  gtk_list_store_insert_with_values (list_store, &iter, 0,
+                                     0, "hi",
+                                     -1);
+
+  path = gtk_tree_path_new_from_indices (0, -1);
+  gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
+                            NULL, FALSE);
+
+  gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &cursor_path, NULL);
+  g_assert (gtk_tree_path_compare (cursor_path, path) == 0);
+
+  gtk_tree_path_free (path);
+  gtk_tree_path_free (cursor_path);
+
+  /* Invalid path on tree view with model */
+  path = gtk_tree_path_new_from_indices (1, -1);
+  gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
+                            NULL, FALSE);
+  gtk_tree_path_free (path);
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+  gtk_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/TreeView/cursor/bug-546005", test_bug_546005);
+
+  return g_test_run ();
+}



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