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, see <http://www.gnu.org/licenses/>.
18 #include "gtktreemodelrefcount.h"
19 #include "treemodel.h"
21 /* And the tests themselves */
24 test_list_no_reference (void)
28 GtkTreeModelRefCount *ref_model;
30 model = gtk_tree_model_ref_count_new ();
31 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
33 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
34 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
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);
39 assert_root_level_unreferenced (ref_model);
41 g_object_unref (ref_model);
45 test_list_reference_during_creation (void)
49 GtkTreeModelRefCount *ref_model;
52 model = gtk_tree_model_ref_count_new ();
53 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
54 tree_view = gtk_tree_view_new_with_model (model);
56 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
57 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
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);
62 assert_root_level_referenced (ref_model, 1);
64 gtk_widget_destroy (tree_view);
66 assert_root_level_unreferenced (ref_model);
68 g_object_unref (ref_model);
72 test_list_reference_after_creation (void)
76 GtkTreeModelRefCount *ref_model;
79 model = gtk_tree_model_ref_count_new ();
80 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
82 assert_root_level_unreferenced (ref_model);
84 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
85 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
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);
90 tree_view = gtk_tree_view_new_with_model (model);
92 assert_root_level_referenced (ref_model, 1);
94 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
95 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
97 assert_root_level_referenced (ref_model, 1);
99 gtk_widget_destroy (tree_view);
101 assert_root_level_unreferenced (ref_model);
103 g_object_unref (ref_model);
107 test_list_reference_reordered (void)
109 GtkTreeIter iter1, iter2, iter3, iter4, iter5;
111 GtkTreeModelRefCount *ref_model;
112 GtkWidget *tree_view;
114 model = gtk_tree_model_ref_count_new ();
115 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
117 assert_root_level_unreferenced (ref_model);
119 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
120 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
121 gtk_tree_store_append (GTK_TREE_STORE (model), &iter3, NULL);
122 gtk_tree_store_append (GTK_TREE_STORE (model), &iter4, NULL);
123 gtk_tree_store_append (GTK_TREE_STORE (model), &iter5, NULL);
125 tree_view = gtk_tree_view_new_with_model (model);
127 assert_root_level_referenced (ref_model, 1);
129 gtk_tree_store_move_after (GTK_TREE_STORE (model),
132 assert_root_level_referenced (ref_model, 1);
134 gtk_tree_store_move_after (GTK_TREE_STORE (model),
137 assert_root_level_referenced (ref_model, 1);
139 gtk_widget_destroy (tree_view);
141 assert_root_level_unreferenced (ref_model);
143 g_object_unref (ref_model);
148 test_tree_no_reference (void)
150 GtkTreeIter iter, child;
152 GtkTreeModelRefCount *ref_model;
154 model = gtk_tree_model_ref_count_new ();
155 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
157 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
158 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
159 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
160 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
161 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
162 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
163 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
164 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
165 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
166 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
167 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
169 assert_entire_model_unreferenced (ref_model);
171 g_object_unref (ref_model);
175 test_tree_reference_during_creation (void)
177 GtkTreeIter iter, child;
179 GtkTreeModelRefCount *ref_model;
180 GtkWidget *tree_view;
182 model = gtk_tree_model_ref_count_new ();
183 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
184 tree_view = gtk_tree_view_new_with_model (model);
186 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
187 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
188 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
189 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
190 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
191 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
192 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
193 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
194 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
195 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
196 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
198 assert_root_level_referenced (ref_model, 1);
199 assert_not_entire_model_referenced (ref_model, 1);
200 assert_level_unreferenced (ref_model, &child);
202 gtk_widget_destroy (tree_view);
204 assert_entire_model_unreferenced (ref_model);
206 g_object_unref (ref_model);
210 test_tree_reference_after_creation (void)
212 GtkTreeIter iter, child;
214 GtkTreeModelRefCount *ref_model;
215 GtkWidget *tree_view;
217 model = gtk_tree_model_ref_count_new ();
218 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
220 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
221 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
222 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
223 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
224 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
225 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
226 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
227 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
228 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
229 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
230 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
232 assert_entire_model_unreferenced (ref_model);
234 tree_view = gtk_tree_view_new_with_model (model);
236 assert_root_level_referenced (ref_model, 1);
237 assert_not_entire_model_referenced (ref_model, 1);
238 assert_level_unreferenced (ref_model, &child);
240 gtk_widget_destroy (tree_view);
242 assert_entire_model_unreferenced (ref_model);
244 g_object_unref (ref_model);
248 test_tree_reference_reordered (void)
251 GtkTreeIter iter1, iter2, iter3, iter4, iter5;
253 GtkTreeModelRefCount *ref_model;
254 GtkWidget *tree_view;
256 model = gtk_tree_model_ref_count_new ();
257 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
259 assert_root_level_unreferenced (ref_model);
261 gtk_tree_store_append (GTK_TREE_STORE (model), &parent, NULL);
262 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, &parent);
263 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, &parent);
264 gtk_tree_store_append (GTK_TREE_STORE (model), &iter3, &parent);
265 gtk_tree_store_append (GTK_TREE_STORE (model), &iter4, &parent);
266 gtk_tree_store_append (GTK_TREE_STORE (model), &iter5, &parent);
268 tree_view = gtk_tree_view_new_with_model (model);
269 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
271 assert_entire_model_referenced (ref_model, 1);
273 gtk_tree_store_move_after (GTK_TREE_STORE (model),
276 assert_entire_model_referenced (ref_model, 1);
278 gtk_tree_store_move_after (GTK_TREE_STORE (model),
281 assert_entire_model_referenced (ref_model, 1);
283 gtk_widget_destroy (tree_view);
285 assert_entire_model_unreferenced (ref_model);
287 g_object_unref (ref_model);
291 test_tree_reference_expand_all (void)
293 GtkTreeIter iter, child;
295 GtkTreeModelRefCount *ref_model;
296 GtkWidget *tree_view;
298 model = gtk_tree_model_ref_count_new ();
299 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
301 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
302 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
303 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
304 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
305 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
306 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
307 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
308 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
309 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
310 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
311 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
313 assert_entire_model_unreferenced (ref_model);
315 tree_view = gtk_tree_view_new_with_model (model);
317 assert_root_level_referenced (ref_model, 1);
318 assert_not_entire_model_referenced (ref_model, 1);
319 assert_level_unreferenced (ref_model, &child);
321 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
323 assert_entire_model_referenced (ref_model, 1);
325 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
326 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
327 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
329 assert_root_level_referenced (ref_model, 1);
330 assert_not_entire_model_referenced (ref_model, 1);
331 assert_level_unreferenced (ref_model, &child);
333 gtk_widget_destroy (tree_view);
335 assert_entire_model_unreferenced (ref_model);
337 g_object_unref (ref_model);
341 test_tree_reference_collapse_all (void)
343 GtkTreeIter iter, child;
345 GtkTreeModelRefCount *ref_model;
346 GtkWidget *tree_view;
348 model = gtk_tree_model_ref_count_new ();
349 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
351 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
352 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
353 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
354 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
355 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
356 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
357 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
358 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
359 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
360 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
361 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter);
363 assert_entire_model_unreferenced (ref_model);
365 tree_view = gtk_tree_view_new_with_model (model);
366 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
368 assert_entire_model_referenced (ref_model, 1);
370 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
372 assert_root_level_referenced (ref_model, 1);
373 assert_not_entire_model_referenced (ref_model, 1);
374 assert_level_unreferenced (ref_model, &child);
376 gtk_widget_destroy (tree_view);
378 assert_entire_model_unreferenced (ref_model);
380 g_object_unref (ref_model);
384 test_tree_reference_expand_collapse (void)
386 GtkTreeIter parent1, parent2, child;
387 GtkTreePath *path1, *path2;
389 GtkTreeModelRefCount *ref_model;
390 GtkWidget *tree_view;
392 model = gtk_tree_model_ref_count_new ();
393 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
394 tree_view = gtk_tree_view_new_with_model (model);
396 gtk_tree_store_append (GTK_TREE_STORE (model), &parent1, NULL);
397 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &parent1);
398 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &parent1);
399 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, NULL);
400 gtk_tree_store_append (GTK_TREE_STORE (model), &parent2, NULL);
401 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &parent2);
402 gtk_tree_store_append (GTK_TREE_STORE (model), &child, &parent2);
404 path1 = gtk_tree_model_get_path (model, &parent1);
405 path2 = gtk_tree_model_get_path (model, &parent2);
407 assert_level_unreferenced (ref_model, &parent1);
408 assert_level_unreferenced (ref_model, &parent2);
410 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path1, FALSE);
412 assert_level_referenced (ref_model, 1, &parent1);
413 assert_level_unreferenced (ref_model, &parent2);
415 gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path1);
417 assert_level_unreferenced (ref_model, &parent1);
418 assert_level_unreferenced (ref_model, &parent2);
420 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path2, FALSE);
422 assert_level_unreferenced (ref_model, &parent1);
423 assert_level_referenced (ref_model, 1, &parent2);
425 gtk_tree_view_collapse_row (GTK_TREE_VIEW (tree_view), path2);
427 assert_level_unreferenced (ref_model, &parent1);
428 assert_level_unreferenced (ref_model, &parent2);
430 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path2, FALSE);
432 assert_level_unreferenced (ref_model, &parent1);
433 assert_level_referenced (ref_model, 1, &parent2);
435 gtk_tree_view_expand_row (GTK_TREE_VIEW (tree_view), path1, FALSE);
437 assert_level_referenced (ref_model, 1, &parent1);
438 assert_level_referenced (ref_model, 1, &parent2);
440 gtk_tree_path_free (path1);
441 gtk_tree_path_free (path2);
443 gtk_widget_destroy (tree_view);
444 g_object_unref (ref_model);
448 test_row_reference_list (void)
450 GtkTreeIter iter0, iter1, iter2;
453 GtkTreeModelRefCount *ref_model;
454 GtkTreeRowReference *row_ref;
455 GtkWidget *tree_view;
457 model = gtk_tree_model_ref_count_new ();
458 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
460 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
461 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
462 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
464 assert_root_level_unreferenced (ref_model);
466 /* create and remove a row ref and check reference counts */
467 path = gtk_tree_path_new_from_indices (1, -1);
468 row_ref = gtk_tree_row_reference_new (model, path);
470 assert_node_ref_count (ref_model, &iter0, 0);
471 assert_node_ref_count (ref_model, &iter1, 1);
472 assert_node_ref_count (ref_model, &iter2, 0);
474 gtk_tree_row_reference_free (row_ref);
476 assert_root_level_unreferenced (ref_model);
478 /* the same, but then also with a tree view monitoring the model */
479 tree_view = gtk_tree_view_new_with_model (model);
481 assert_root_level_referenced (ref_model, 1);
483 row_ref = gtk_tree_row_reference_new (model, path);
485 assert_node_ref_count (ref_model, &iter0, 1);
486 assert_node_ref_count (ref_model, &iter1, 2);
487 assert_node_ref_count (ref_model, &iter2, 1);
489 gtk_widget_destroy (tree_view);
491 assert_node_ref_count (ref_model, &iter0, 0);
492 assert_node_ref_count (ref_model, &iter1, 1);
493 assert_node_ref_count (ref_model, &iter2, 0);
495 gtk_tree_row_reference_free (row_ref);
497 assert_root_level_unreferenced (ref_model);
499 gtk_tree_path_free (path);
501 g_object_unref (ref_model);
505 test_row_reference_list_remove (void)
507 GtkTreeIter iter0, iter1, iter2;
510 GtkTreeModelRefCount *ref_model;
511 GtkTreeRowReference *row_ref;
513 model = gtk_tree_model_ref_count_new ();
514 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
516 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
517 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
518 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
520 assert_root_level_unreferenced (ref_model);
522 /* test creating the row reference and then removing the node */
523 path = gtk_tree_path_new_from_indices (1, -1);
524 row_ref = gtk_tree_row_reference_new (model, path);
526 assert_node_ref_count (ref_model, &iter0, 0);
527 assert_node_ref_count (ref_model, &iter1, 1);
528 assert_node_ref_count (ref_model, &iter2, 0);
530 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter1);
532 assert_root_level_unreferenced (ref_model);
534 gtk_tree_row_reference_free (row_ref);
536 assert_root_level_unreferenced (ref_model);
538 /* test creating a row ref, removing another node and then removing
541 row_ref = gtk_tree_row_reference_new (model, path);
543 assert_node_ref_count (ref_model, &iter0, 0);
544 assert_node_ref_count (ref_model, &iter2, 1);
546 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter0);
548 assert_root_level_referenced (ref_model, 1);
550 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter2);
552 g_assert (!gtk_tree_model_get_iter_first (model, &iter0));
554 gtk_tree_row_reference_free (row_ref);
556 gtk_tree_path_free (path);
558 g_object_unref (ref_model);
562 test_row_reference_tree (void)
564 GtkTreeIter iter0, iter1, iter2;
565 GtkTreeIter child0, child1, child2;
566 GtkTreeIter grandchild0, grandchild1, grandchild2;
569 GtkTreeModelRefCount *ref_model;
570 GtkTreeRowReference *row_ref, *row_ref1;
571 GtkWidget *tree_view;
573 model = gtk_tree_model_ref_count_new ();
574 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
576 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
577 gtk_tree_store_append (GTK_TREE_STORE (model), &child0, &iter0);
578 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild0, &child0);
579 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
580 gtk_tree_store_append (GTK_TREE_STORE (model), &child1, &iter1);
581 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild1, &child1);
582 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
583 gtk_tree_store_append (GTK_TREE_STORE (model), &child2, &iter2);
584 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild2, &child2);
586 assert_entire_model_unreferenced (ref_model);
588 /* create and remove a row ref and check reference counts */
589 path = gtk_tree_path_new_from_indices (1, 0, 0, -1);
590 row_ref = gtk_tree_row_reference_new (model, path);
591 gtk_tree_path_free (path);
593 assert_node_ref_count (ref_model, &iter0, 0);
594 assert_node_ref_count (ref_model, &child0, 0);
595 assert_node_ref_count (ref_model, &grandchild0, 0);
596 assert_node_ref_count (ref_model, &iter1, 1);
597 assert_node_ref_count (ref_model, &child1, 1);
598 assert_node_ref_count (ref_model, &grandchild1, 1);
599 assert_node_ref_count (ref_model, &iter2, 0);
600 assert_node_ref_count (ref_model, &child2, 0);
601 assert_node_ref_count (ref_model, &grandchild2, 0);
603 gtk_tree_row_reference_free (row_ref);
605 assert_entire_model_unreferenced (ref_model);
607 /* again, with path 1:1 */
608 path = gtk_tree_path_new_from_indices (1, 0, -1);
609 row_ref = gtk_tree_row_reference_new (model, path);
610 gtk_tree_path_free (path);
612 assert_node_ref_count (ref_model, &iter0, 0);
613 assert_node_ref_count (ref_model, &child0, 0);
614 assert_node_ref_count (ref_model, &grandchild0, 0);
615 assert_node_ref_count (ref_model, &iter1, 1);
616 assert_node_ref_count (ref_model, &child1, 1);
617 assert_node_ref_count (ref_model, &grandchild1, 0);
618 assert_node_ref_count (ref_model, &iter2, 0);
619 assert_node_ref_count (ref_model, &child2, 0);
620 assert_node_ref_count (ref_model, &grandchild2, 0);
622 gtk_tree_row_reference_free (row_ref);
624 assert_entire_model_unreferenced (ref_model);
626 /* both row refs existent at once and also with a tree view monitoring
629 tree_view = gtk_tree_view_new_with_model (model);
631 assert_root_level_referenced (ref_model, 1);
633 path = gtk_tree_path_new_from_indices (1, 0, 0, -1);
634 row_ref = gtk_tree_row_reference_new (model, path);
635 gtk_tree_path_free (path);
637 assert_node_ref_count (ref_model, &iter0, 1);
638 assert_node_ref_count (ref_model, &child0, 0);
639 assert_node_ref_count (ref_model, &grandchild0, 0);
640 assert_node_ref_count (ref_model, &iter1, 2);
641 assert_node_ref_count (ref_model, &child1, 1);
642 assert_node_ref_count (ref_model, &grandchild1, 1);
643 assert_node_ref_count (ref_model, &iter2, 1);
644 assert_node_ref_count (ref_model, &child2, 0);
645 assert_node_ref_count (ref_model, &grandchild2, 0);
647 path = gtk_tree_path_new_from_indices (1, 0, -1);
648 row_ref1 = gtk_tree_row_reference_new (model, path);
649 gtk_tree_path_free (path);
651 assert_node_ref_count (ref_model, &iter0, 1);
652 assert_node_ref_count (ref_model, &child0, 0);
653 assert_node_ref_count (ref_model, &grandchild0, 0);
654 assert_node_ref_count (ref_model, &iter1, 3);
655 assert_node_ref_count (ref_model, &child1, 2);
656 assert_node_ref_count (ref_model, &grandchild1, 1);
657 assert_node_ref_count (ref_model, &iter2, 1);
658 assert_node_ref_count (ref_model, &child2, 0);
659 assert_node_ref_count (ref_model, &grandchild2, 0);
661 gtk_tree_row_reference_free (row_ref);
663 assert_node_ref_count (ref_model, &iter0, 1);
664 assert_node_ref_count (ref_model, &child0, 0);
665 assert_node_ref_count (ref_model, &grandchild0, 0);
666 assert_node_ref_count (ref_model, &iter1, 2);
667 assert_node_ref_count (ref_model, &child1, 1);
668 assert_node_ref_count (ref_model, &grandchild1, 0);
669 assert_node_ref_count (ref_model, &iter2, 1);
670 assert_node_ref_count (ref_model, &child2, 0);
671 assert_node_ref_count (ref_model, &grandchild2, 0);
673 gtk_widget_destroy (tree_view);
675 assert_node_ref_count (ref_model, &iter0, 0);
676 assert_node_ref_count (ref_model, &child0, 0);
677 assert_node_ref_count (ref_model, &grandchild0, 0);
678 assert_node_ref_count (ref_model, &iter1, 1);
679 assert_node_ref_count (ref_model, &child1, 1);
680 assert_node_ref_count (ref_model, &grandchild1, 0);
681 assert_node_ref_count (ref_model, &iter2, 0);
682 assert_node_ref_count (ref_model, &child2, 0);
683 assert_node_ref_count (ref_model, &grandchild2, 0);
685 gtk_tree_row_reference_free (row_ref1);
687 assert_root_level_unreferenced (ref_model);
689 g_object_unref (ref_model);
693 test_row_reference_tree_remove (void)
695 GtkTreeIter iter0, iter1, iter2;
696 GtkTreeIter child0, child1, child2;
697 GtkTreeIter grandchild0, grandchild1, grandchild2;
700 GtkTreeModelRefCount *ref_model;
701 GtkTreeRowReference *row_ref, *row_ref1, *row_ref2;
703 model = gtk_tree_model_ref_count_new ();
704 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
706 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
707 gtk_tree_store_append (GTK_TREE_STORE (model), &child0, &iter0);
708 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild0, &child0);
709 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
710 gtk_tree_store_append (GTK_TREE_STORE (model), &child1, &iter1);
711 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild1, &child1);
712 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
713 gtk_tree_store_append (GTK_TREE_STORE (model), &child2, &iter2);
714 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild2, &child2);
716 assert_entire_model_unreferenced (ref_model);
718 path = gtk_tree_path_new_from_indices (1, 0, 0, -1);
719 row_ref = gtk_tree_row_reference_new (model, path);
720 gtk_tree_path_free (path);
722 path = gtk_tree_path_new_from_indices (2, 0, -1);
723 row_ref1 = gtk_tree_row_reference_new (model, path);
724 gtk_tree_path_free (path);
726 path = gtk_tree_path_new_from_indices (2, -1);
727 row_ref2 = gtk_tree_row_reference_new (model, path);
728 gtk_tree_path_free (path);
730 assert_node_ref_count (ref_model, &iter0, 0);
731 assert_node_ref_count (ref_model, &child0, 0);
732 assert_node_ref_count (ref_model, &grandchild0, 0);
733 assert_node_ref_count (ref_model, &iter1, 1);
734 assert_node_ref_count (ref_model, &child1, 1);
735 assert_node_ref_count (ref_model, &grandchild1, 1);
736 assert_node_ref_count (ref_model, &iter2, 2);
737 assert_node_ref_count (ref_model, &child2, 1);
738 assert_node_ref_count (ref_model, &grandchild2, 0);
740 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandchild1);
742 assert_node_ref_count (ref_model, &iter0, 0);
743 assert_node_ref_count (ref_model, &child0, 0);
744 assert_node_ref_count (ref_model, &grandchild0, 0);
745 assert_node_ref_count (ref_model, &iter1, 0);
746 assert_node_ref_count (ref_model, &child1, 0);
747 assert_node_ref_count (ref_model, &iter2, 2);
748 assert_node_ref_count (ref_model, &child2, 1);
749 assert_node_ref_count (ref_model, &grandchild2, 0);
751 gtk_tree_store_remove (GTK_TREE_STORE (model), &child2);
753 assert_node_ref_count (ref_model, &iter0, 0);
754 assert_node_ref_count (ref_model, &child0, 0);
755 assert_node_ref_count (ref_model, &grandchild0, 0);
756 assert_node_ref_count (ref_model, &iter1, 0);
757 assert_node_ref_count (ref_model, &child1, 0);
758 assert_node_ref_count (ref_model, &iter2, 1);
760 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter2);
762 assert_entire_model_unreferenced (ref_model);
764 gtk_tree_row_reference_free (row_ref);
765 gtk_tree_row_reference_free (row_ref1);
766 gtk_tree_row_reference_free (row_ref2);
768 g_object_unref (ref_model);
772 test_row_reference_tree_remove_ancestor (void)
774 GtkTreeIter iter0, iter1, iter2;
775 GtkTreeIter child0, child1, child2;
776 GtkTreeIter grandchild0, grandchild1, grandchild2;
779 GtkTreeModelRefCount *ref_model;
780 GtkTreeRowReference *row_ref, *row_ref1;
782 model = gtk_tree_model_ref_count_new ();
783 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
785 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
786 gtk_tree_store_append (GTK_TREE_STORE (model), &child0, &iter0);
787 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild0, &child0);
788 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
789 gtk_tree_store_append (GTK_TREE_STORE (model), &child1, &iter1);
790 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild1, &child1);
791 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
792 gtk_tree_store_append (GTK_TREE_STORE (model), &child2, &iter2);
793 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild2, &child2);
795 assert_entire_model_unreferenced (ref_model);
797 path = gtk_tree_path_new_from_indices (1, 0, 0, -1);
798 row_ref = gtk_tree_row_reference_new (model, path);
799 gtk_tree_path_free (path);
801 path = gtk_tree_path_new_from_indices (2, 0, -1);
802 row_ref1 = gtk_tree_row_reference_new (model, path);
803 gtk_tree_path_free (path);
805 assert_node_ref_count (ref_model, &iter0, 0);
806 assert_node_ref_count (ref_model, &child0, 0);
807 assert_node_ref_count (ref_model, &grandchild0, 0);
808 assert_node_ref_count (ref_model, &iter1, 1);
809 assert_node_ref_count (ref_model, &child1, 1);
810 assert_node_ref_count (ref_model, &grandchild1, 1);
811 assert_node_ref_count (ref_model, &iter2, 1);
812 assert_node_ref_count (ref_model, &child2, 1);
813 assert_node_ref_count (ref_model, &grandchild2, 0);
815 gtk_tree_store_remove (GTK_TREE_STORE (model), &child1);
817 assert_node_ref_count (ref_model, &iter0, 0);
818 assert_node_ref_count (ref_model, &child0, 0);
819 assert_node_ref_count (ref_model, &grandchild0, 0);
820 assert_node_ref_count (ref_model, &iter1, 0);
821 assert_node_ref_count (ref_model, &iter2, 1);
822 assert_node_ref_count (ref_model, &child2, 1);
823 assert_node_ref_count (ref_model, &grandchild2, 0);
825 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter2);
827 assert_entire_model_unreferenced (ref_model);
829 gtk_tree_row_reference_free (row_ref);
830 gtk_tree_row_reference_free (row_ref1);
832 g_object_unref (ref_model);
836 test_row_reference_tree_expand (void)
838 GtkTreeIter iter0, iter1, iter2;
839 GtkTreeIter child0, child1, child2;
840 GtkTreeIter grandchild0, grandchild1, grandchild2;
843 GtkTreeModelRefCount *ref_model;
844 GtkTreeRowReference *row_ref, *row_ref1, *row_ref2;
845 GtkWidget *tree_view;
847 model = gtk_tree_model_ref_count_new ();
848 ref_model = GTK_TREE_MODEL_REF_COUNT (model);
849 tree_view = gtk_tree_view_new_with_model (model);
851 gtk_tree_store_append (GTK_TREE_STORE (model), &iter0, NULL);
852 gtk_tree_store_append (GTK_TREE_STORE (model), &child0, &iter0);
853 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild0, &child0);
854 gtk_tree_store_append (GTK_TREE_STORE (model), &iter1, NULL);
855 gtk_tree_store_append (GTK_TREE_STORE (model), &child1, &iter1);
856 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild1, &child1);
857 gtk_tree_store_append (GTK_TREE_STORE (model), &iter2, NULL);
858 gtk_tree_store_append (GTK_TREE_STORE (model), &child2, &iter2);
859 gtk_tree_store_append (GTK_TREE_STORE (model), &grandchild2, &child2);
861 assert_root_level_referenced (ref_model, 1);
863 gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
865 assert_entire_model_referenced (ref_model, 1);
867 path = gtk_tree_path_new_from_indices (1, 0, 0, -1);
868 row_ref = gtk_tree_row_reference_new (model, path);
869 gtk_tree_path_free (path);
871 path = gtk_tree_path_new_from_indices (2, 0, -1);
872 row_ref1 = gtk_tree_row_reference_new (model, path);
873 gtk_tree_path_free (path);
875 path = gtk_tree_path_new_from_indices (2, -1);
876 row_ref2 = gtk_tree_row_reference_new (model, path);
877 gtk_tree_path_free (path);
879 assert_node_ref_count (ref_model, &iter0, 1);
880 assert_node_ref_count (ref_model, &child0, 1);
881 assert_node_ref_count (ref_model, &grandchild0, 1);
882 assert_node_ref_count (ref_model, &iter1, 2);
883 assert_node_ref_count (ref_model, &child1, 2);
884 assert_node_ref_count (ref_model, &grandchild1, 2);
885 assert_node_ref_count (ref_model, &iter2, 3);
886 assert_node_ref_count (ref_model, &child2, 2);
887 assert_node_ref_count (ref_model, &grandchild2, 1);
889 gtk_tree_store_remove (GTK_TREE_STORE (model), &grandchild1);
891 assert_node_ref_count (ref_model, &iter0, 1);
892 assert_node_ref_count (ref_model, &child0, 1);
893 assert_node_ref_count (ref_model, &grandchild0, 1);
894 assert_node_ref_count (ref_model, &iter1, 1);
895 assert_node_ref_count (ref_model, &child1, 1);
896 assert_node_ref_count (ref_model, &iter2, 3);
897 assert_node_ref_count (ref_model, &child2, 2);
898 assert_node_ref_count (ref_model, &grandchild2, 1);
900 gtk_tree_store_remove (GTK_TREE_STORE (model), &child2);
902 assert_node_ref_count (ref_model, &iter0, 1);
903 assert_node_ref_count (ref_model, &child0, 1);
904 assert_node_ref_count (ref_model, &grandchild0, 1);
905 assert_node_ref_count (ref_model, &iter1, 1);
906 assert_node_ref_count (ref_model, &child1, 1);
907 assert_node_ref_count (ref_model, &iter2, 2);
909 gtk_tree_view_collapse_all (GTK_TREE_VIEW (tree_view));
911 assert_node_ref_count (ref_model, &iter0, 1);
912 assert_node_ref_count (ref_model, &child0, 0);
913 assert_node_ref_count (ref_model, &grandchild0, 0);
914 assert_node_ref_count (ref_model, &iter1, 1);
915 assert_node_ref_count (ref_model, &child1, 0);
916 assert_node_ref_count (ref_model, &iter2, 2);
918 gtk_tree_store_remove (GTK_TREE_STORE (model), &iter2);
920 assert_node_ref_count (ref_model, &iter0, 1);
921 assert_node_ref_count (ref_model, &child0, 0);
922 assert_node_ref_count (ref_model, &grandchild0, 0);
923 assert_node_ref_count (ref_model, &iter1, 1);
924 assert_node_ref_count (ref_model, &child1, 0);
926 gtk_tree_row_reference_free (row_ref);
927 gtk_tree_row_reference_free (row_ref1);
928 gtk_tree_row_reference_free (row_ref2);
930 gtk_widget_destroy (tree_view);
931 g_object_unref (ref_model);
935 register_model_ref_count_tests (void)
937 /* lists (though based on GtkTreeStore) */
938 g_test_add_func ("/TreeModel/ref-count/list/no-reference",
939 test_list_no_reference);
940 g_test_add_func ("/TreeModel/ref-count/list/reference-during-creation",
941 test_list_reference_during_creation);
942 g_test_add_func ("/TreeModel/ref-count/list/reference-after-creation",
943 test_list_reference_after_creation);
944 g_test_add_func ("/TreeModel/ref-count/list/reference-reordered",
945 test_list_reference_reordered);
948 g_test_add_func ("/TreeModel/ref-count/tree/no-reference",
949 test_tree_no_reference);
950 g_test_add_func ("/TreeModel/ref-count/tree/reference-during-creation",
951 test_tree_reference_during_creation);
952 g_test_add_func ("/TreeModel/ref-count/tree/reference-after-creation",
953 test_tree_reference_after_creation);
954 g_test_add_func ("/TreeModel/ref-count/tree/expand-all",
955 test_tree_reference_expand_all);
956 g_test_add_func ("/TreeModel/ref-count/tree/collapse-all",
957 test_tree_reference_collapse_all);
958 g_test_add_func ("/TreeModel/ref-count/tree/expand-collapse",
959 test_tree_reference_expand_collapse);
960 g_test_add_func ("/TreeModel/ref-count/tree/reference-reordered",
961 test_tree_reference_reordered);
964 g_test_add_func ("/TreeModel/ref-count/row-reference/list",
965 test_row_reference_list);
966 g_test_add_func ("/TreeModel/ref-count/row-reference/list-remove",
967 test_row_reference_list_remove);
968 g_test_add_func ("/TreeModel/ref-count/row-reference/tree",
969 test_row_reference_tree);
970 g_test_add_func ("/TreeModel/ref-count/row-reference/tree-remove",
971 test_row_reference_tree_remove);
972 g_test_add_func ("/TreeModel/ref-count/row-reference/tree-remove-ancestor",
973 test_row_reference_tree_remove_ancestor);
974 g_test_add_func ("/TreeModel/ref-count/row-reference/tree-expand",
975 test_row_reference_tree_expand);