1 /* Main wrapper for TreeModel test suite.
2 * Copyright (C) 2011 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, see <http://www.gnu.org/licenses/>.
20 #include "treemodel.h"
26 gtk_test_init (&argc, &argv, NULL);
28 g_test_bug_base ("http://bugzilla.gnome.org/");
30 register_list_store_tests ();
31 register_tree_store_tests ();
32 register_model_ref_count_tests ();
33 register_sort_model_tests ();
34 register_filter_model_tests ();
44 signal_name_to_string (SignalName signal)
49 return "row-inserted";
57 case ROW_HAS_CHILD_TOGGLED:
58 return "row-has-child-toggled";
61 return "rows-reordered";
76 /* For rows-reordered */
84 signal_new (SignalName signal, GtkTreePath *path)
88 s = g_new0 (Signal, 1);
90 s->path = gtk_tree_path_copy (path);
97 signal_new_with_order (SignalName signal, GtkTreePath *path,
98 int *new_order, int len)
100 Signal *s = signal_new (signal, path);
102 s->new_order = new_order;
109 signal_free (Signal *s)
112 gtk_tree_path_free (s->path);
118 struct _SignalMonitor
121 GtkTreeModel *client;
122 gulong signal_ids[LAST_SIGNAL];
127 signal_monitor_generic_handler (SignalMonitor *m,
136 if (g_queue_is_empty (m->queue))
140 path_str = gtk_tree_path_to_string (path);
141 g_error ("Signal queue empty, got signal %s path %s\n",
142 signal_name_to_string (signal), path_str);
145 g_assert_not_reached ();
148 if (m->client != model)
150 g_error ("Model mismatch; expected %p, got %p\n",
152 g_assert_not_reached ();
155 s = g_queue_peek_tail (m->queue);
158 /* For debugging: output signals that are coming in. Leaks memory. */
159 g_print ("signal=%s path=%s\n", signal_name_to_string (signal),
160 gtk_tree_path_to_string (path));
163 if (s->signal != signal ||
164 (gtk_tree_path_get_depth (s->path) == 0 &&
165 gtk_tree_path_get_depth (path) != 0) ||
166 (gtk_tree_path_get_depth (s->path) != 0 &&
167 gtk_tree_path_compare (s->path, path) != 0))
169 gchar *path_str, *s_path_str;
171 s_path_str = gtk_tree_path_to_string (s->path);
172 path_str = gtk_tree_path_to_string (path);
174 g_error ("Signals don't match; expected signal %s path %s, got signal %s path %s\n",
175 signal_name_to_string (s->signal), s_path_str,
176 signal_name_to_string (signal), path_str);
181 g_assert_not_reached ();
184 if (signal == ROWS_REORDERED && s->new_order != NULL)
188 g_assert (new_order != NULL);
190 len = gtk_tree_model_iter_n_children (model, iter);
191 g_assert (s->len == len);
193 for (i = 0; i < len; i++)
194 g_assert (s->new_order[i] == new_order[i]);
197 s = g_queue_pop_tail (m->queue);
203 signal_monitor_row_inserted (GtkTreeModel *model,
208 signal_monitor_generic_handler (data, ROW_INSERTED,
209 model, iter, path, NULL);
213 signal_monitor_row_deleted (GtkTreeModel *model,
217 signal_monitor_generic_handler (data, ROW_DELETED,
218 model, NULL, path, NULL);
222 signal_monitor_row_changed (GtkTreeModel *model,
227 signal_monitor_generic_handler (data, ROW_CHANGED,
228 model, iter, path, NULL);
232 signal_monitor_row_has_child_toggled (GtkTreeModel *model,
237 signal_monitor_generic_handler (data, ROW_HAS_CHILD_TOGGLED,
238 model, iter, path, NULL);
242 signal_monitor_rows_reordered (GtkTreeModel *model,
248 signal_monitor_generic_handler (data, ROWS_REORDERED,
249 model, iter, path, new_order);
253 signal_monitor_new (GtkTreeModel *client)
257 m = g_new0 (SignalMonitor, 1);
258 m->client = g_object_ref (client);
259 m->queue = g_queue_new ();
261 m->signal_ids[ROW_INSERTED] = g_signal_connect (client,
263 G_CALLBACK (signal_monitor_row_inserted),
265 m->signal_ids[ROW_DELETED] = g_signal_connect (client,
267 G_CALLBACK (signal_monitor_row_deleted),
269 m->signal_ids[ROW_CHANGED] = g_signal_connect (client,
271 G_CALLBACK (signal_monitor_row_changed),
273 m->signal_ids[ROW_HAS_CHILD_TOGGLED] = g_signal_connect (client,
274 "row-has-child-toggled",
275 G_CALLBACK (signal_monitor_row_has_child_toggled),
277 m->signal_ids[ROWS_REORDERED] = g_signal_connect (client,
279 G_CALLBACK (signal_monitor_rows_reordered),
286 signal_monitor_free (SignalMonitor *m)
290 for (i = 0; i < LAST_SIGNAL; i++)
291 g_signal_handler_disconnect (m->client, m->signal_ids[i]);
293 g_object_unref (m->client);
296 g_queue_free (m->queue);
302 signal_monitor_assert_is_empty (SignalMonitor *m)
304 g_assert (g_queue_is_empty (m->queue));
308 signal_monitor_append_signal_path (SignalMonitor *m,
314 s = signal_new (signal, path);
315 g_queue_push_head (m->queue, s);
319 signal_monitor_append_signal_reordered (SignalMonitor *m,
327 s = signal_new_with_order (signal, path, new_order, len);
328 g_queue_push_head (m->queue, s);
332 signal_monitor_append_signal (SignalMonitor *m,
334 const gchar *path_string)
339 path = gtk_tree_path_new_from_string (path_string);
341 s = signal_new (signal, path);
342 g_queue_push_head (m->queue, s);
344 gtk_tree_path_free (path);