1 /* GtkTreeModel ref counting tests
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.
20 #include "gtktreemodelrefcount.h"
21 #include "treemodel.h"
23 /* And the tests themselves */
26 test_list_no_reference (void)
30 GtkTreeModelRefCount *ref_model;
32 model = gtk_tree_model_ref_count_new ();
33 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
35 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
36 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
37 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
38 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
39 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
41 assert_root_level_unreferenced (ref_model);
43 g_object_unref (ref_model);
47 test_list_reference_during_creation (void)
51 GtkTreeModelRefCount *ref_model;
54 model = gtk_tree_model_ref_count_new ();
55 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
56 tree_view = gtk_tree_view_new_with_model (model);
58 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
59 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
60 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
61 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
62 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
64 assert_root_level_referenced (ref_model, 1);
66 gtk_widget_destroy (tree_view);
68 assert_root_level_unreferenced (ref_model);
70 g_object_unref (ref_model);
74 test_list_reference_after_creation (void)
78 GtkTreeModelRefCount *ref_model;
81 model = gtk_tree_model_ref_count_new ();
82 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
84 assert_root_level_unreferenced (ref_model);
86 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
87 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
88 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
89 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
90 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
92 tree_view = gtk_tree_view_new_with_model (model);
94 assert_root_level_referenced (ref_model, 1);
96 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
97 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
99 assert_root_level_referenced (ref_model, 1);
101 gtk_widget_destroy (tree_view);
103 assert_root_level_unreferenced (ref_model);
105 g_object_unref (ref_model);
109 test_list_reference_reordered (void)
111 GtkTreeIter iter1, iter2, iter3, iter4, iter5;
113 GtkTreeModelRefCount *ref_model;
114 GtkWidget *tree_view;
116 model = gtk_tree_model_ref_count_new ();
117 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
119 assert_root_level_unreferenced (ref_model);
121 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
122 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
123 gtk_tree_store_append (GTK_TREE_STORE (model), &iter3, NULL);
124 gtk_tree_store_append (GTK_TREE_STORE (model), &iter4, NULL);
125 gtk_tree_store_append (GTK_TREE_STORE (model), &iter5, NULL);
127 tree_view = gtk_tree_view_new_with_model (model);
129 assert_root_level_referenced (ref_model, 1);
131 gtk_tree_store_move_after (GTK_TREE_STORE (model),
134 assert_root_level_referenced (ref_model, 1);
136 gtk_tree_store_move_after (GTK_TREE_STORE (model),
139 assert_root_level_referenced (ref_model, 1);
141 gtk_widget_destroy (tree_view);
143 assert_root_level_unreferenced (ref_model);
145 g_object_unref (ref_model);
150 test_tree_no_reference (void)
152 GtkTreeIter iter, child;
154 GtkTreeModelRefCount *ref_model;
156 model = gtk_tree_model_ref_count_new ();
157 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
159 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
160 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
161 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
162 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
163 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
164 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
165 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
166 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
167 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
168 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
169 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
171 assert_entire_model_unreferenced (ref_model);
173 g_object_unref (ref_model);
177 test_tree_reference_during_creation (void)
179 GtkTreeIter iter, child;
181 GtkTreeModelRefCount *ref_model;
182 GtkWidget *tree_view;
184 model = gtk_tree_model_ref_count_new ();
185 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
186 tree_view = gtk_tree_view_new_with_model (model);
188 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
189 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
190 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
191 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
192 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
193 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
194 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
195 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
196 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
197 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
198 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
200 assert_root_level_referenced (ref_model, 1);
201 assert_not_entire_model_referenced (ref_model, 1);
202 assert_level_unreferenced (ref_model, &child);
204 gtk_widget_destroy (tree_view);
206 assert_entire_model_unreferenced (ref_model);
208 g_object_unref (ref_model);
212 test_tree_reference_after_creation (void)
214 GtkTreeIter iter, child;
216 GtkTreeModelRefCount *ref_model;
217 GtkWidget *tree_view;
219 model = gtk_tree_model_ref_count_new ();
220 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
222 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
223 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
224 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
225 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
226 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
227 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
228 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
229 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
230 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
231 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
232 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
234 assert_entire_model_unreferenced (ref_model);
236 tree_view = gtk_tree_view_new_with_model (model);
238 assert_root_level_referenced (ref_model, 1);
239 assert_not_entire_model_referenced (ref_model, 1);
240 assert_level_unreferenced (ref_model, &child);
242 gtk_widget_destroy (tree_view);
244 assert_entire_model_unreferenced (ref_model);
246 g_object_unref (ref_model);
250 test_tree_reference_reordered (void)
253 GtkTreeIter iter1, iter2, iter3, iter4, iter5;
255 GtkTreeModelRefCount *ref_model;
256 GtkWidget *tree_view;
258 model = gtk_tree_model_ref_count_new ();
259 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
261 assert_root_level_unreferenced (ref_model);
263 gtk_tree_store_append (GTK_TREE_STORE (model), &parent, NULL);
264 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, &parent);
265 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, &parent);
266 gtk_tree_store_append (GTK_TREE_STORE (model), &iter3, &parent);
267 gtk_tree_store_append (GTK_TREE_STORE (model), &iter4, &parent);
268 gtk_tree_store_append (GTK_TREE_STORE (model), &iter5, &parent);
270 tree_view = gtk_tree_view_new_with_model (model);
271 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
273 assert_entire_model_referenced (ref_model, 1);
275 gtk_tree_store_move_after (GTK_TREE_STORE (model),
278 assert_entire_model_referenced (ref_model, 1);
280 gtk_tree_store_move_after (GTK_TREE_STORE (model),
283 assert_entire_model_referenced (ref_model, 1);
285 gtk_widget_destroy (tree_view);
287 assert_entire_model_unreferenced (ref_model);
289 g_object_unref (ref_model);
293 test_tree_reference_expand_all (void)
295 GtkTreeIter iter, child;
297 GtkTreeModelRefCount *ref_model;
298 GtkWidget *tree_view;
300 model = gtk_tree_model_ref_count_new ();
301 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
303 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
304 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
305 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
306 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
307 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
308 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
309 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
310 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
311 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
312 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
313 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
315 assert_entire_model_unreferenced (ref_model);
317 tree_view = gtk_tree_view_new_with_model (model);
319 assert_root_level_referenced (ref_model, 1);
320 assert_not_entire_model_referenced (ref_model, 1);
321 assert_level_unreferenced (ref_model, &child);
323 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
325 assert_entire_model_referenced (ref_model, 1);
327 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
328 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
329 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
331 assert_root_level_referenced (ref_model, 1);
332 assert_not_entire_model_referenced (ref_model, 1);
333 assert_level_unreferenced (ref_model, &child);
335 gtk_widget_destroy (tree_view);
337 assert_entire_model_unreferenced (ref_model);
339 g_object_unref (ref_model);
343 test_tree_reference_collapse_all (void)
345 GtkTreeIter iter, child;
347 GtkTreeModelRefCount *ref_model;
348 GtkWidget *tree_view;
350 model = gtk_tree_model_ref_count_new ();
351 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
353 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
354 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
355 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
356 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
357 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
358 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
359 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
360 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
361 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
362 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
363 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
365 assert_entire_model_unreferenced (ref_model);
367 tree_view = gtk_tree_view_new_with_model (model);
368 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
370 assert_entire_model_referenced (ref_model, 1);
372 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
374 assert_root_level_referenced (ref_model, 1);
375 assert_not_entire_model_referenced (ref_model, 1);
376 assert_level_unreferenced (ref_model, &child);
378 gtk_widget_destroy (tree_view);
380 assert_entire_model_unreferenced (ref_model);
382 g_object_unref (ref_model);
386 test_tree_reference_expand_collapse (void)
388 GtkTreeIter parent1, parent2, child;
389 GtkTreePath *path1, *path2;
391 GtkTreeModelRefCount *ref_model;
392 GtkWidget *tree_view;
394 model = gtk_tree_model_ref_count_new ();
395 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
396 tree_view = gtk_tree_view_new_with_model (model);
398 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, NULL);
399 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &parent1);
400 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &parent1);
401 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, NULL);
402 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, NULL);
403 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &parent2);
404 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &parent2);
406 path1 = gtk_tree_model_get_path (model, &parent1);
407 path2 = gtk_tree_model_get_path (model, &parent2);
409 assert_level_unreferenced (ref_model, &parent1);
410 assert_level_unreferenced (ref_model, &parent2);
412 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path1, FALSE);
414 assert_level_referenced (ref_model, 1, &parent1);
415 assert_level_unreferenced (ref_model, &parent2);
417 gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path1);
419 assert_level_unreferenced (ref_model, &parent1);
420 assert_level_unreferenced (ref_model, &parent2);
422 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path2, FALSE);
424 assert_level_unreferenced (ref_model, &parent1);
425 assert_level_referenced (ref_model, 1, &parent2);
427 gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path2);
429 assert_level_unreferenced (ref_model, &parent1);
430 assert_level_unreferenced (ref_model, &parent2);
432 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path2, FALSE);
434 assert_level_unreferenced (ref_model, &parent1);
435 assert_level_referenced (ref_model, 1, &parent2);
437 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path1, FALSE);
439 assert_level_referenced (ref_model, 1, &parent1);
440 assert_level_referenced (ref_model, 1, &parent2);
442 gtk_tree_path_free (path1);
443 gtk_tree_path_free (path2);
445 gtk_widget_destroy (tree_view);
446 g_object_unref (ref_model);
450 test_row_reference_list (void)
452 GtkTreeIter iter0, iter1, iter2;
455 GtkTreeModelRefCount *ref_model;
456 GtkTreeRowReference *row_ref;
457 GtkWidget *tree_view;
459 model = gtk_tree_model_ref_count_new ();
460 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
462 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
463 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
464 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
466 assert_root_level_unreferenced (ref_model);
468 /* create and remove a row ref and check reference counts */
469 path = gtk_tree_path_new_from_indices (1, -1);
470 row_ref = gtk_tree_row_reference_new (model, path);
472 assert_node_ref_count (ref_model, &iter0, 0);
473 assert_node_ref_count (ref_model, &iter1, 1);
474 assert_node_ref_count (ref_model, &iter2, 0);
476 gtk_tree_row_reference_free (row_ref);
478 assert_root_level_unreferenced (ref_model);
480 /* the same, but then also with a tree view monitoring the model */
481 tree_view = gtk_tree_view_new_with_model (model);
483 assert_root_level_referenced (ref_model, 1);
485 row_ref = gtk_tree_row_reference_new (model, path);
487 assert_node_ref_count (ref_model, &iter0, 1);
488 assert_node_ref_count (ref_model, &iter1, 2);
489 assert_node_ref_count (ref_model, &iter2, 1);
491 gtk_widget_destroy (tree_view);
493 assert_node_ref_count (ref_model, &iter0, 0);
494 assert_node_ref_count (ref_model, &iter1, 1);
495 assert_node_ref_count (ref_model, &iter2, 0);
497 gtk_tree_row_reference_free (row_ref);
499 assert_root_level_unreferenced (ref_model);
501 gtk_tree_path_free (path);
503 g_object_unref (ref_model);
507 test_row_reference_list_remove (void)
509 GtkTreeIter iter0, iter1, iter2;
512 GtkTreeModelRefCount *ref_model;
513 GtkTreeRowReference *row_ref;
515 model = gtk_tree_model_ref_count_new ();
516 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
518 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
519 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
520 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
522 assert_root_level_unreferenced (ref_model);
524 /* test creating the row reference and then removing the node */
525 path = gtk_tree_path_new_from_indices (1, -1);
526 row_ref = gtk_tree_row_reference_new (model, path);
528 assert_node_ref_count (ref_model, &iter0, 0);
529 assert_node_ref_count (ref_model, &iter1, 1);
530 assert_node_ref_count (ref_model, &iter2, 0);
532 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter1);
534 assert_root_level_unreferenced (ref_model);
536 gtk_tree_row_reference_free (row_ref);
538 assert_root_level_unreferenced (ref_model);
540 /* test creating a row ref, removing another node and then removing
543 row_ref = gtk_tree_row_reference_new (model, path);
545 assert_node_ref_count (ref_model, &iter0, 0);
546 assert_node_ref_count (ref_model, &iter2, 1);
548 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter0);
550 assert_root_level_referenced (ref_model, 1);
552 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter2);
554 g_assert (!gtk_tree_model_get_iter_first (model, &iter0));
556 gtk_tree_row_reference_free (row_ref);
558 gtk_tree_path_free (path);
560 g_object_unref (ref_model);
564 test_row_reference_tree (void)
566 GtkTreeIter iter0, iter1, iter2;
567 GtkTreeIter child0, child1, child2;
568 GtkTreeIter grandchild0, grandchild1, grandchild2;
571 GtkTreeModelRefCount *ref_model;
572 GtkTreeRowReference *row_ref, *row_ref1;
573 GtkWidget *tree_view;
575 model = gtk_tree_model_ref_count_new ();
576 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
578 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
579 gtk_tree_store_append (GTK_TREE_STORE (model), &child0, &iter0);
580 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild0, &child0);
581 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
582 gtk_tree_store_append (GTK_TREE_STORE (model), &child1, &iter1);
583 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild1, &child1);
584 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
585 gtk_tree_store_append (GTK_TREE_STORE (model), &child2, &iter2);
586 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild2, &child2);
588 assert_entire_model_unreferenced (ref_model);
590 /* create and remove a row ref and check reference counts */
591 path = gtk_tree_path_new_from_indices (1, 0, 0, -1);
592 row_ref = gtk_tree_row_reference_new (model, path);
593 gtk_tree_path_free (path);
595 assert_node_ref_count (ref_model, &iter0, 0);
596 assert_node_ref_count (ref_model, &child0, 0);
597 assert_node_ref_count (ref_model, &grandchild0, 0);
598 assert_node_ref_count (ref_model, &iter1, 1);
599 assert_node_ref_count (ref_model, &child1, 1);
600 assert_node_ref_count (ref_model, &grandchild1, 1);
601 assert_node_ref_count (ref_model, &iter2, 0);
602 assert_node_ref_count (ref_model, &child2, 0);
603 assert_node_ref_count (ref_model, &grandchild2, 0);
605 gtk_tree_row_reference_free (row_ref);
607 assert_entire_model_unreferenced (ref_model);
609 /* again, with path 1:1 */
610 path = gtk_tree_path_new_from_indices (1, 0, -1);
611 row_ref = gtk_tree_row_reference_new (model, path);
612 gtk_tree_path_free (path);
614 assert_node_ref_count (ref_model, &iter0, 0);
615 assert_node_ref_count (ref_model, &child0, 0);
616 assert_node_ref_count (ref_model, &grandchild0, 0);
617 assert_node_ref_count (ref_model, &iter1, 1);
618 assert_node_ref_count (ref_model, &child1, 1);
619 assert_node_ref_count (ref_model, &grandchild1, 0);
620 assert_node_ref_count (ref_model, &iter2, 0);
621 assert_node_ref_count (ref_model, &child2, 0);
622 assert_node_ref_count (ref_model, &grandchild2, 0);
624 gtk_tree_row_reference_free (row_ref);
626 assert_entire_model_unreferenced (ref_model);
628 /* both row refs existent at once and also with a tree view monitoring
631 tree_view = gtk_tree_view_new_with_model (model);
633 assert_root_level_referenced (ref_model, 1);
635 path = gtk_tree_path_new_from_indices (1, 0, 0, -1);
636 row_ref = gtk_tree_row_reference_new (model, path);
637 gtk_tree_path_free (path);
639 assert_node_ref_count (ref_model, &iter0, 1);
640 assert_node_ref_count (ref_model, &child0, 0);
641 assert_node_ref_count (ref_model, &grandchild0, 0);
642 assert_node_ref_count (ref_model, &iter1, 2);
643 assert_node_ref_count (ref_model, &child1, 1);
644 assert_node_ref_count (ref_model, &grandchild1, 1);
645 assert_node_ref_count (ref_model, &iter2, 1);
646 assert_node_ref_count (ref_model, &child2, 0);
647 assert_node_ref_count (ref_model, &grandchild2, 0);
649 path = gtk_tree_path_new_from_indices (1, 0, -1);
650 row_ref1 = gtk_tree_row_reference_new (model, path);
651 gtk_tree_path_free (path);
653 assert_node_ref_count (ref_model, &iter0, 1);
654 assert_node_ref_count (ref_model, &child0, 0);
655 assert_node_ref_count (ref_model, &grandchild0, 0);
656 assert_node_ref_count (ref_model, &iter1, 3);
657 assert_node_ref_count (ref_model, &child1, 2);
658 assert_node_ref_count (ref_model, &grandchild1, 1);
659 assert_node_ref_count (ref_model, &iter2, 1);
660 assert_node_ref_count (ref_model, &child2, 0);
661 assert_node_ref_count (ref_model, &grandchild2, 0);
663 gtk_tree_row_reference_free (row_ref);
665 assert_node_ref_count (ref_model, &iter0, 1);
666 assert_node_ref_count (ref_model, &child0, 0);
667 assert_node_ref_count (ref_model, &grandchild0, 0);
668 assert_node_ref_count (ref_model, &iter1, 2);
669 assert_node_ref_count (ref_model, &child1, 1);
670 assert_node_ref_count (ref_model, &grandchild1, 0);
671 assert_node_ref_count (ref_model, &iter2, 1);
672 assert_node_ref_count (ref_model, &child2, 0);
673 assert_node_ref_count (ref_model, &grandchild2, 0);
675 gtk_widget_destroy (tree_view);
677 assert_node_ref_count (ref_model, &iter0, 0);
678 assert_node_ref_count (ref_model, &child0, 0);
679 assert_node_ref_count (ref_model, &grandchild0, 0);
680 assert_node_ref_count (ref_model, &iter1, 1);
681 assert_node_ref_count (ref_model, &child1, 1);
682 assert_node_ref_count (ref_model, &grandchild1, 0);
683 assert_node_ref_count (ref_model, &iter2, 0);
684 assert_node_ref_count (ref_model, &child2, 0);
685 assert_node_ref_count (ref_model, &grandchild2, 0);
687 gtk_tree_row_reference_free (row_ref1);
689 assert_root_level_unreferenced (ref_model);
691 g_object_unref (ref_model);
695 test_row_reference_tree_remove (void)
697 GtkTreeIter iter0, iter1, iter2;
698 GtkTreeIter child0, child1, child2;
699 GtkTreeIter grandchild0, grandchild1, grandchild2;
702 GtkTreeModelRefCount *ref_model;
703 GtkTreeRowReference *row_ref, *row_ref1, *row_ref2;
705 model = gtk_tree_model_ref_count_new ();
706 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
708 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
709 gtk_tree_store_append (GTK_TREE_STORE (model), &child0, &iter0);
710 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild0, &child0);
711 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
712 gtk_tree_store_append (GTK_TREE_STORE (model), &child1, &iter1);
713 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild1, &child1);
714 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
715 gtk_tree_store_append (GTK_TREE_STORE (model), &child2, &iter2);
716 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild2, &child2);
718 assert_entire_model_unreferenced (ref_model);
720 path = gtk_tree_path_new_from_indices (1, 0, 0, -1);
721 row_ref = gtk_tree_row_reference_new (model, path);
722 gtk_tree_path_free (path);
724 path = gtk_tree_path_new_from_indices (2, 0, -1);
725 row_ref1 = gtk_tree_row_reference_new (model, path);
726 gtk_tree_path_free (path);
728 path = gtk_tree_path_new_from_indices (2, -1);
729 row_ref2 = gtk_tree_row_reference_new (model, path);
730 gtk_tree_path_free (path);
732 assert_node_ref_count (ref_model, &iter0, 0);
733 assert_node_ref_count (ref_model, &child0, 0);
734 assert_node_ref_count (ref_model, &grandchild0, 0);
735 assert_node_ref_count (ref_model, &iter1, 1);
736 assert_node_ref_count (ref_model, &child1, 1);
737 assert_node_ref_count (ref_model, &grandchild1, 1);
738 assert_node_ref_count (ref_model, &iter2, 2);
739 assert_node_ref_count (ref_model, &child2, 1);
740 assert_node_ref_count (ref_model, &grandchild2, 0);
742 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandchild1);
744 assert_node_ref_count (ref_model, &iter0, 0);
745 assert_node_ref_count (ref_model, &child0, 0);
746 assert_node_ref_count (ref_model, &grandchild0, 0);
747 assert_node_ref_count (ref_model, &iter1, 0);
748 assert_node_ref_count (ref_model, &child1, 0);
749 assert_node_ref_count (ref_model, &iter2, 2);
750 assert_node_ref_count (ref_model, &child2, 1);
751 assert_node_ref_count (ref_model, &grandchild2, 0);
753 gtk_tree_store_remove (GTK_TREE_STORE (model), &child2);
755 assert_node_ref_count (ref_model, &iter0, 0);
756 assert_node_ref_count (ref_model, &child0, 0);
757 assert_node_ref_count (ref_model, &grandchild0, 0);
758 assert_node_ref_count (ref_model, &iter1, 0);
759 assert_node_ref_count (ref_model, &child1, 0);
760 assert_node_ref_count (ref_model, &iter2, 1);
762 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter2);
764 assert_entire_model_unreferenced (ref_model);
766 gtk_tree_row_reference_free (row_ref);
767 gtk_tree_row_reference_free (row_ref1);
768 gtk_tree_row_reference_free (row_ref2);
770 g_object_unref (ref_model);
774 test_row_reference_tree_remove_ancestor (void)
776 GtkTreeIter iter0, iter1, iter2;
777 GtkTreeIter child0, child1, child2;
778 GtkTreeIter grandchild0, grandchild1, grandchild2;
781 GtkTreeModelRefCount *ref_model;
782 GtkTreeRowReference *row_ref, *row_ref1;
784 model = gtk_tree_model_ref_count_new ();
785 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
787 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
788 gtk_tree_store_append (GTK_TREE_STORE (model), &child0, &iter0);
789 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild0, &child0);
790 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
791 gtk_tree_store_append (GTK_TREE_STORE (model), &child1, &iter1);
792 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild1, &child1);
793 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
794 gtk_tree_store_append (GTK_TREE_STORE (model), &child2, &iter2);
795 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild2, &child2);
797 assert_entire_model_unreferenced (ref_model);
799 path = gtk_tree_path_new_from_indices (1, 0, 0, -1);
800 row_ref = gtk_tree_row_reference_new (model, path);
801 gtk_tree_path_free (path);
803 path = gtk_tree_path_new_from_indices (2, 0, -1);
804 row_ref1 = gtk_tree_row_reference_new (model, path);
805 gtk_tree_path_free (path);
807 assert_node_ref_count (ref_model, &iter0, 0);
808 assert_node_ref_count (ref_model, &child0, 0);
809 assert_node_ref_count (ref_model, &grandchild0, 0);
810 assert_node_ref_count (ref_model, &iter1, 1);
811 assert_node_ref_count (ref_model, &child1, 1);
812 assert_node_ref_count (ref_model, &grandchild1, 1);
813 assert_node_ref_count (ref_model, &iter2, 1);
814 assert_node_ref_count (ref_model, &child2, 1);
815 assert_node_ref_count (ref_model, &grandchild2, 0);
817 gtk_tree_store_remove (GTK_TREE_STORE (model), &child1);
819 assert_node_ref_count (ref_model, &iter0, 0);
820 assert_node_ref_count (ref_model, &child0, 0);
821 assert_node_ref_count (ref_model, &grandchild0, 0);
822 assert_node_ref_count (ref_model, &iter1, 0);
823 assert_node_ref_count (ref_model, &iter2, 1);
824 assert_node_ref_count (ref_model, &child2, 1);
825 assert_node_ref_count (ref_model, &grandchild2, 0);
827 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter2);
829 assert_entire_model_unreferenced (ref_model);
831 gtk_tree_row_reference_free (row_ref);
832 gtk_tree_row_reference_free (row_ref1);
834 g_object_unref (ref_model);
838 test_row_reference_tree_expand (void)
840 GtkTreeIter iter0, iter1, iter2;
841 GtkTreeIter child0, child1, child2;
842 GtkTreeIter grandchild0, grandchild1, grandchild2;
845 GtkTreeModelRefCount *ref_model;
846 GtkTreeRowReference *row_ref, *row_ref1, *row_ref2;
847 GtkWidget *tree_view;
849 model = gtk_tree_model_ref_count_new ();
850 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
851 tree_view = gtk_tree_view_new_with_model (model);
853 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
854 gtk_tree_store_append (GTK_TREE_STORE (model), &child0, &iter0);
855 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild0, &child0);
856 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
857 gtk_tree_store_append (GTK_TREE_STORE (model), &child1, &iter1);
858 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild1, &child1);
859 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
860 gtk_tree_store_append (GTK_TREE_STORE (model), &child2, &iter2);
861 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild2, &child2);
863 assert_root_level_referenced (ref_model, 1);
865 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
867 assert_entire_model_referenced (ref_model, 1);
869 path = gtk_tree_path_new_from_indices (1, 0, 0, -1);
870 row_ref = gtk_tree_row_reference_new (model, path);
871 gtk_tree_path_free (path);
873 path = gtk_tree_path_new_from_indices (2, 0, -1);
874 row_ref1 = gtk_tree_row_reference_new (model, path);
875 gtk_tree_path_free (path);
877 path = gtk_tree_path_new_from_indices (2, -1);
878 row_ref2 = gtk_tree_row_reference_new (model, path);
879 gtk_tree_path_free (path);
881 assert_node_ref_count (ref_model, &iter0, 1);
882 assert_node_ref_count (ref_model, &child0, 1);
883 assert_node_ref_count (ref_model, &grandchild0, 1);
884 assert_node_ref_count (ref_model, &iter1, 2);
885 assert_node_ref_count (ref_model, &child1, 2);
886 assert_node_ref_count (ref_model, &grandchild1, 2);
887 assert_node_ref_count (ref_model, &iter2, 3);
888 assert_node_ref_count (ref_model, &child2, 2);
889 assert_node_ref_count (ref_model, &grandchild2, 1);
891 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandchild1);
893 assert_node_ref_count (ref_model, &iter0, 1);
894 assert_node_ref_count (ref_model, &child0, 1);
895 assert_node_ref_count (ref_model, &grandchild0, 1);
896 assert_node_ref_count (ref_model, &iter1, 1);
897 assert_node_ref_count (ref_model, &child1, 1);
898 assert_node_ref_count (ref_model, &iter2, 3);
899 assert_node_ref_count (ref_model, &child2, 2);
900 assert_node_ref_count (ref_model, &grandchild2, 1);
902 gtk_tree_store_remove (GTK_TREE_STORE (model), &child2);
904 assert_node_ref_count (ref_model, &iter0, 1);
905 assert_node_ref_count (ref_model, &child0, 1);
906 assert_node_ref_count (ref_model, &grandchild0, 1);
907 assert_node_ref_count (ref_model, &iter1, 1);
908 assert_node_ref_count (ref_model, &child1, 1);
909 assert_node_ref_count (ref_model, &iter2, 2);
911 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
913 assert_node_ref_count (ref_model, &iter0, 1);
914 assert_node_ref_count (ref_model, &child0, 0);
915 assert_node_ref_count (ref_model, &grandchild0, 0);
916 assert_node_ref_count (ref_model, &iter1, 1);
917 assert_node_ref_count (ref_model, &child1, 0);
918 assert_node_ref_count (ref_model, &iter2, 2);
920 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter2);
922 assert_node_ref_count (ref_model, &iter0, 1);
923 assert_node_ref_count (ref_model, &child0, 0);
924 assert_node_ref_count (ref_model, &grandchild0, 0);
925 assert_node_ref_count (ref_model, &iter1, 1);
926 assert_node_ref_count (ref_model, &child1, 0);
928 gtk_tree_row_reference_free (row_ref);
929 gtk_tree_row_reference_free (row_ref1);
930 gtk_tree_row_reference_free (row_ref2);
932 gtk_widget_destroy (tree_view);
933 g_object_unref (ref_model);
937 register_model_ref_count_tests (void)
939 /* lists (though based on GtkTreeStore) */
940 g_test_add_func ("/TreeModel/ref-count/list/no-reference",
941 test_list_no_reference);
942 g_test_add_func ("/TreeModel/ref-count/list/reference-during-creation",
943 test_list_reference_during_creation);
944 g_test_add_func ("/TreeModel/ref-count/list/reference-after-creation",
945 test_list_reference_after_creation);
946 g_test_add_func ("/TreeModel/ref-count/list/reference-reordered",
947 test_list_reference_reordered);
950 g_test_add_func ("/TreeModel/ref-count/tree/no-reference",
951 test_tree_no_reference);
952 g_test_add_func ("/TreeModel/ref-count/tree/reference-during-creation",
953 test_tree_reference_during_creation);
954 g_test_add_func ("/TreeModel/ref-count/tree/reference-after-creation",
955 test_tree_reference_after_creation);
956 g_test_add_func ("/TreeModel/ref-count/tree/expand-all",
957 test_tree_reference_expand_all);
958 g_test_add_func ("/TreeModel/ref-count/tree/collapse-all",
959 test_tree_reference_collapse_all);
960 g_test_add_func ("/TreeModel/ref-count/tree/expand-collapse",
961 test_tree_reference_expand_collapse);
962 g_test_add_func ("/TreeModel/ref-count/tree/reference-reordered",
963 test_tree_reference_reordered);
966 g_test_add_func ("/TreeModel/ref-count/row-reference/list",
967 test_row_reference_list);
968 g_test_add_func ("/TreeModel/ref-count/row-reference/list-remove",
969 test_row_reference_list_remove);
970 g_test_add_func ("/TreeModel/ref-count/row-reference/tree",
971 test_row_reference_tree);
972 g_test_add_func ("/TreeModel/ref-count/row-reference/tree-remove",
973 test_row_reference_tree_remove);
974 g_test_add_func ("/TreeModel/ref-count/row-reference/tree-remove-ancestor",
975 test_row_reference_tree_remove_ancestor);
976 g_test_add_func ("/TreeModel/ref-count/row-reference/tree-expand",
977 test_row_reference_tree_expand);