]> Pileus Git - ~andy/gtk/blob - gtk/tests/sortmodel.c
Add bug base and bug numbers to tree model unit tests
[~andy/gtk] / gtk / tests / sortmodel.c
1 /* Extensive GtkTreeModelSort tests.
2  * Copyright (C) 2009,2011  Kristian Rietveld  <kris@gtk.org>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include <gtk/gtk.h>
21
22 #include "treemodel.h"
23
24 static void
25 specific_bug_300089 (void)
26 {
27   /* Test case for GNOME Bugzilla bug 300089.  Written by
28    * Matthias Clasen.
29    */
30   GtkTreeModel *sort_model, *child_model;
31   GtkTreePath *path;
32   GtkTreeIter iter, iter2, sort_iter;
33
34   g_test_bug ("300089");
35
36   child_model = GTK_TREE_MODEL (gtk_tree_store_new (1, G_TYPE_STRING));
37
38   gtk_tree_store_append (GTK_TREE_STORE (child_model), &iter, NULL);
39   gtk_tree_store_set (GTK_TREE_STORE (child_model), &iter, 0, "A", -1);
40   gtk_tree_store_append (GTK_TREE_STORE (child_model), &iter, NULL);
41   gtk_tree_store_set (GTK_TREE_STORE (child_model), &iter, 0, "B", -1);
42
43   gtk_tree_store_append (GTK_TREE_STORE (child_model), &iter2, &iter);
44   gtk_tree_store_set (GTK_TREE_STORE (child_model), &iter2, 0, "D", -1);
45   gtk_tree_store_append (GTK_TREE_STORE (child_model), &iter2, &iter);
46   gtk_tree_store_set (GTK_TREE_STORE (child_model), &iter2, 0, "E", -1);
47
48   gtk_tree_store_append (GTK_TREE_STORE (child_model), &iter, NULL);
49   gtk_tree_store_set (GTK_TREE_STORE (child_model), &iter, 0, "C", -1);
50
51
52   sort_model = GTK_TREE_MODEL (gtk_tree_model_sort_new_with_model (child_model));
53   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model),
54                                         0, GTK_SORT_ASCENDING);
55
56   path = gtk_tree_path_new_from_indices (1, 1, -1);
57
58   /* make sure a level is constructed */ 
59   gtk_tree_model_get_iter (sort_model, &sort_iter, path);
60
61   /* change the "E" row in a way that causes it to change position */ 
62   gtk_tree_model_get_iter (child_model, &iter, path);
63   gtk_tree_store_set (GTK_TREE_STORE (child_model), &iter, 0, "A", -1);
64 }
65
66 static void
67 specific_bug_364946 (void)
68 {
69   /* This is a test case for GNOME Bugzilla bug 364946.  It was written
70    * by Andreas Koehler.
71    */
72   GtkTreeStore *store;
73   GtkTreeIter a, aa, aaa, aab, iter;
74   GtkTreeModel *s_model;
75
76   g_test_bug ("364946");
77
78   store = gtk_tree_store_new (1, G_TYPE_STRING);
79
80   gtk_tree_store_append (store, &a, NULL);
81   gtk_tree_store_set (store, &a, 0, "0", -1);
82
83   gtk_tree_store_append (store, &aa, &a);
84   gtk_tree_store_set (store, &aa, 0, "0:0", -1);
85
86   gtk_tree_store_append (store, &aaa, &aa);
87   gtk_tree_store_set (store, &aaa, 0, "0:0:0", -1);
88
89   gtk_tree_store_append (store, &aab, &aa);
90   gtk_tree_store_set (store, &aab, 0, "0:0:1", -1);
91
92   s_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
93   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (s_model), 0,
94                                         GTK_SORT_ASCENDING);
95
96   gtk_tree_model_get_iter_from_string (s_model, &iter, "0:0:0");
97
98   gtk_tree_store_set (store, &aaa, 0, "0:0:0", -1);
99   gtk_tree_store_remove (store, &aaa);
100   gtk_tree_store_remove (store, &aab);
101
102   gtk_tree_model_sort_clear_cache (GTK_TREE_MODEL_SORT (s_model));
103 }
104
105 /* main */
106
107 void
108 register_sort_model_tests (void)
109 {
110   g_test_add_func ("/TreeModelSort/specific/bug-300089",
111                    specific_bug_300089);
112   g_test_add_func ("/TreeModelSort/specific/bug-364946",
113                    specific_bug_364946);
114 }