forked from AuroraMiddleware/gtk
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.
This commit is contained in:
parent
a4514f993e
commit
531c7e535b
@ -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)
|
||||
|
81
gtk/tests/treeview.c
Normal file
81
gtk/tests/treeview.c
Normal file
@ -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 ();
|
||||
}
|
Loading…
Reference in New Issue
Block a user