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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include "treemodel.h"
28 gtk_test_init (&argc, &argv, NULL);
30 g_test_bug_base ("http://bugzilla.gnome.org/");
32 register_list_store_tests ();
33 register_tree_store_tests ();
34 register_model_ref_count_tests ();
35 register_sort_model_tests ();
36 register_filter_model_tests ();
46 signal_name_to_string (SignalName signal)
51 return "row-inserted";
59 case ROW_HAS_CHILD_TOGGLED:
60 return "row-has-child-toggled";
63 return "rows-reordered";
78 /* For rows-reordered */
86 signal_new (SignalName signal, GtkTreePath *path)
90 s = g_new0 (Signal, 1);
92 s->path = gtk_tree_path_copy (path);
99 signal_new_with_order (SignalName signal, GtkTreePath *path,
100 int *new_order, int len)
102 Signal *s = signal_new (signal, path);
104 s->new_order = new_order;
111 signal_free (Signal *s)
114 gtk_tree_path_free (s->path);
120 struct _SignalMonitor
123 GtkTreeModel *client;
124 gulong signal_ids[LAST_SIGNAL];
129 signal_monitor_generic_handler (SignalMonitor *m,
138 if (g_queue_is_empty (m->queue))
142 path_str = gtk_tree_path_to_string (path);
143 g_error ("Signal queue empty, got signal %s path %s\n",
144 signal_name_to_string (signal), path_str);
147 g_assert_not_reached ();
150 if (m->client != model)
152 g_error ("Model mismatch; expected %p, got %p\n",
154 g_assert_not_reached ();
157 s = g_queue_peek_tail (m->queue);
160 /* For debugging: output signals that are coming in. Leaks memory. */
161 g_print ("signal=%s path=%s\n", signal_name_to_string (signal),
162 gtk_tree_path_to_string (path));
165 if (s->signal != signal ||
166 (gtk_tree_path_get_depth (s->path) == 0 &&
167 gtk_tree_path_get_depth (path) != 0) ||
168 (gtk_tree_path_get_depth (s->path) != 0 &&
169 gtk_tree_path_compare (s->path, path) != 0))
171 gchar *path_str, *s_path_str;
173 s_path_str = gtk_tree_path_to_string (s->path);
174 path_str = gtk_tree_path_to_string (path);
176 g_error ("Signals don't match; expected signal %s path %s, got signal %s path %s\n",
177 signal_name_to_string (s->signal), s_path_str,
178 signal_name_to_string (signal), path_str);
183 g_assert_not_reached ();
186 if (signal == ROWS_REORDERED && s->new_order != NULL)
190 g_assert (new_order != NULL);
192 len = gtk_tree_model_iter_n_children (model, iter);
193 g_assert (s->len == len);
195 for (i = 0; i < len; i++)
196 g_assert (s->new_order[i] == new_order[i]);
199 s = g_queue_pop_tail (m->queue);
205 signal_monitor_row_inserted (GtkTreeModel *model,
210 signal_monitor_generic_handler (data, ROW_INSERTED,
211 model, iter, path, NULL);
215 signal_monitor_row_deleted (GtkTreeModel *model,
219 signal_monitor_generic_handler (data, ROW_DELETED,
220 model, NULL, path, NULL);
224 signal_monitor_row_changed (GtkTreeModel *model,
229 signal_monitor_generic_handler (data, ROW_CHANGED,
230 model, iter, path, NULL);
234 signal_monitor_row_has_child_toggled (GtkTreeModel *model,
239 signal_monitor_generic_handler (data, ROW_HAS_CHILD_TOGGLED,
240 model, iter, path, NULL);
244 signal_monitor_rows_reordered (GtkTreeModel *model,
250 signal_monitor_generic_handler (data, ROWS_REORDERED,
251 model, iter, path, new_order);
255 signal_monitor_new (GtkTreeModel *client)
259 m = g_new0 (SignalMonitor, 1);
260 m->client = g_object_ref (client);
261 m->queue = g_queue_new ();
263 m->signal_ids[ROW_INSERTED] = g_signal_connect (client,
265 G_CALLBACK (signal_monitor_row_inserted),
267 m->signal_ids[ROW_DELETED] = g_signal_connect (client,
269 G_CALLBACK (signal_monitor_row_deleted),
271 m->signal_ids[ROW_CHANGED] = g_signal_connect (client,
273 G_CALLBACK (signal_monitor_row_changed),
275 m->signal_ids[ROW_HAS_CHILD_TOGGLED] = g_signal_connect (client,
276 "row-has-child-toggled",
277 G_CALLBACK (signal_monitor_row_has_child_toggled),
279 m->signal_ids[ROWS_REORDERED] = g_signal_connect (client,
281 G_CALLBACK (signal_monitor_rows_reordered),
288 signal_monitor_free (SignalMonitor *m)
292 for (i = 0; i < LAST_SIGNAL; i++)
293 g_signal_handler_disconnect (m->client, m->signal_ids[i]);
295 g_object_unref (m->client);
298 g_queue_free (m->queue);
304 signal_monitor_assert_is_empty (SignalMonitor *m)
306 g_assert (g_queue_is_empty (m->queue));
310 signal_monitor_append_signal_path (SignalMonitor *m,
316 s = signal_new (signal, path);
317 g_queue_push_head (m->queue, s);
321 signal_monitor_append_signal_reordered (SignalMonitor *m,
329 s = signal_new_with_order (signal, path, new_order, len);
330 g_queue_push_head (m->queue, s);
334 signal_monitor_append_signal (SignalMonitor *m,
336 const gchar *path_string)
341 path = gtk_tree_path_new_from_string (path_string);
343 s = signal_new (signal, path);
344 g_queue_push_head (m->queue, s);
346 gtk_tree_path_free (path);