1 /* Basic GtkTreeView unit tests.
2 * Copyright (C) 2009 Kristian Rietveld <kris@gtk.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 test_bug_546005 (void)
27 GtkTreePath *cursor_path;
28 GtkListStore *list_store;
31 /* Tests provided by Bjorn Lindqvist, Paul Pogonyshev */
32 view = gtk_tree_view_new ();
34 /* Invalid path on tree view without model */
35 path = gtk_tree_path_new_from_indices (1, -1);
36 gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
38 gtk_tree_path_free (path);
40 list_store = gtk_list_store_new (1, G_TYPE_STRING);
41 gtk_tree_view_set_model (GTK_TREE_VIEW (view),
42 GTK_TREE_MODEL (list_store));
44 /* Invalid path on tree view with empty model */
45 path = gtk_tree_path_new_from_indices (1, -1);
46 gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
48 gtk_tree_path_free (path);
51 gtk_list_store_insert_with_values (list_store, &iter, 0,
55 path = gtk_tree_path_new_from_indices (0, -1);
56 gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
59 gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &cursor_path, NULL);
60 //gtk_assert_cmptreepath (cursor_path, ==, path);
62 gtk_tree_path_free (path);
63 gtk_tree_path_free (cursor_path);
65 /* Invalid path on tree view with model */
66 path = gtk_tree_path_new_from_indices (1, -1);
67 gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path,
69 gtk_tree_path_free (path);
73 test_bug_539377 (void)
77 GtkListStore *list_store;
79 /* Test provided by Bjorn Lindqvist */
81 /* Non-realized view, no model */
82 view = gtk_tree_view_new ();
83 g_assert (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view), 10, 10, &path,
84 NULL, NULL, NULL) == FALSE);
85 g_assert (gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (view), 10, 10,
86 &path, NULL) == FALSE);
88 /* Non-realized view, with model */
89 list_store = gtk_list_store_new (1, G_TYPE_STRING);
90 gtk_tree_view_set_model (GTK_TREE_VIEW (view),
91 GTK_TREE_MODEL (list_store));
93 g_assert (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view), 10, 10, &path,
94 NULL, NULL, NULL) == FALSE);
95 g_assert (gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (view), 10, 10,
96 &path, NULL) == FALSE);
100 test_select_collapsed_row (void)
102 GtkTreeIter child, parent;
104 GtkTreeStore *tree_store;
105 GtkTreeSelection *selection;
108 /* Reported by Michael Natterer */
109 tree_store = gtk_tree_store_new (1, G_TYPE_STRING);
110 view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (tree_store));
112 gtk_tree_store_insert_with_values (tree_store, &parent, NULL, 0,
116 gtk_tree_store_insert_with_values (tree_store, &child, &parent, 0,
119 gtk_tree_store_insert_with_values (tree_store, &child, &parent, 0,
124 /* Try to select a child path. */
125 path = gtk_tree_path_new_from_indices (0, 1, -1);
126 gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, NULL, FALSE);
128 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
130 /* Check that the parent is not selected. */
131 gtk_tree_path_up (path);
132 g_return_if_fail (gtk_tree_selection_path_is_selected (selection, path) == FALSE);
134 /* Nothing should be selected at this point. */
135 g_return_if_fail (gtk_tree_selection_count_selected_rows (selection) == 0);
137 /* Check that selection really still works. */
138 gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, NULL, FALSE);
139 g_return_if_fail (gtk_tree_selection_path_is_selected (selection, path) == TRUE);
140 g_return_if_fail (gtk_tree_selection_count_selected_rows (selection) == 1);
142 /* Expand and select child node now. */
143 gtk_tree_path_append_index (path, 1);
144 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
146 gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, NULL, FALSE);
147 g_return_if_fail (gtk_tree_selection_path_is_selected (selection, path) == TRUE);
148 g_return_if_fail (gtk_tree_selection_count_selected_rows (selection) == 1);
150 gtk_tree_path_free (path);
157 gtk_test_init (&argc, &argv, NULL);
159 g_test_add_func ("/TreeView/cursor/bug-546005", test_bug_546005);
160 g_test_add_func ("/TreeView/cursor/bug-539377", test_bug_539377);
161 g_test_add_func ("/TreeView/cursor/select-collapsed_row",
162 test_select_collapsed_row);
164 return g_test_run ();