]> Pileus Git - ~andy/gtk/blob - gtk/tests/gtktreemodelrefcount.h
Merge branch 'bgo593793-filechooser-recent-folders-master'
[~andy/gtk] / gtk / tests / gtktreemodelrefcount.h
1 /* gtktreemodelrefcount.h
2  * Copyright (C) 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 Library 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library 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 #ifndef __GTK_TREE_MODEL_REF_COUNT_H__
21 #define __GTK_TREE_MODEL_REF_COUNT_H__
22
23 #include <gtk/gtk.h>
24
25 G_BEGIN_DECLS
26
27 #define GTK_TYPE_TREE_MODEL_REF_COUNT              (gtk_tree_model_ref_count_get_type ())
28 #define GTK_TREE_MODEL_REF_COUNT(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TREE_MODEL_REF_COUNT, GtkTreeModelRefCount))
29 #define GTK_TREE_MODEL_REF_COUNT_CLASS(vtable)     (G_TYPE_CHECK_CLASS_CAST ((vtable), GTK_TYPE_TREE_MODEL_REF_COUNT, GtkTreeModelRefCountClass))
30 #define GTK_IS_TREE_MODEL_REF_COUNT(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TREE_MODEL_REF_COUNT))
31 #define GTK_IS_TREE_MODEL_REF_COUNT_CLASS(vtable)  (G_TYPE_CHECK_CLASS_TYPE ((vtable), GTK_TYPE_TREE_MODEL_REF_COUNT))
32 #define GTK_TREE_MODEL_REF_COUNT_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TREE_MODEL_REF_COUNT, GtkTreeModelRefCountClass))
33
34
35 typedef struct _GtkTreeModelRefCount        GtkTreeModelRefCount;
36 typedef struct _GtkTreeModelRefCountClass   GtkTreeModelRefCountClass;
37 typedef struct _GtkTreeModelRefCountPrivate GtkTreeModelRefCountPrivate;
38
39 struct _GtkTreeModelRefCount
40 {
41   GtkTreeStore parent;
42
43   /* < private > */
44   GtkTreeModelRefCountPrivate *priv;
45 };
46
47 struct _GtkTreeModelRefCountClass
48 {
49   GtkTreeStoreClass parent_class;
50 };
51
52
53 GType         gtk_tree_model_ref_count_get_type    (void) G_GNUC_CONST;
54 GtkTreeModel *gtk_tree_model_ref_count_new         (void);
55
56 void          gtk_tree_model_ref_count_dump        (GtkTreeModelRefCount *ref_model);
57 gboolean      gtk_tree_model_ref_count_check_level (GtkTreeModelRefCount *ref_model,
58                                                     GtkTreeIter          *parent,
59                                                     gint                  expected_ref_count,
60                                                     gboolean              recurse,
61                                                     gboolean              may_assert);
62 gboolean      gtk_tree_model_ref_count_check_node  (GtkTreeModelRefCount *ref_model,
63                                                     GtkTreeIter          *iter,
64                                                     gint                  expected_ref_count,
65                                                     gboolean              may_assert);
66
67 /* A couple of helpers for the tests.  Since this model will never be used
68  * outside of unit tests anyway, it is probably fine to have these here
69  * without namespacing.
70  */
71
72 static inline void
73 assert_entire_model_unreferenced (GtkTreeModelRefCount *ref_model)
74 {
75   gtk_tree_model_ref_count_check_level (ref_model, NULL, 0, TRUE, TRUE);
76 }
77
78 static inline void
79 assert_root_level_unreferenced (GtkTreeModelRefCount *ref_model)
80 {
81   gtk_tree_model_ref_count_check_level (ref_model, NULL, 0, FALSE, TRUE);
82 }
83
84 static inline void
85 assert_level_unreferenced (GtkTreeModelRefCount *ref_model,
86                            GtkTreeIter          *iter)
87 {
88   gtk_tree_model_ref_count_check_level (ref_model, iter, 0, FALSE, TRUE);
89 }
90
91 static inline void
92 assert_entire_model_referenced (GtkTreeModelRefCount *ref_model,
93                                 gint                  ref_count)
94 {
95   gtk_tree_model_ref_count_check_level (ref_model, NULL, ref_count, TRUE, TRUE);
96 }
97
98 static inline void
99 assert_not_entire_model_referenced (GtkTreeModelRefCount *ref_model,
100                                     gint                  ref_count)
101 {
102   g_assert_cmpint (gtk_tree_model_ref_count_check_level (ref_model, NULL,
103                                                          ref_count,
104                                                          TRUE, FALSE),
105                    ==, FALSE);
106 }
107
108 static inline void
109 assert_root_level_referenced (GtkTreeModelRefCount *ref_model,
110                               gint                  ref_count)
111 {
112   gtk_tree_model_ref_count_check_level (ref_model, NULL, ref_count,
113                                         FALSE, TRUE);
114 }
115
116 static inline void
117 assert_level_referenced (GtkTreeModelRefCount *ref_model,
118                          gint                  ref_count,
119                          GtkTreeIter          *iter)
120 {
121   gtk_tree_model_ref_count_check_level (ref_model, iter, ref_count,
122                                         FALSE, TRUE);
123 }
124
125 static inline void
126 assert_node_ref_count (GtkTreeModelRefCount *ref_model,
127                        GtkTreeIter          *iter,
128                        gint                  ref_count)
129 {
130   gtk_tree_model_ref_count_check_node (ref_model, iter, ref_count, TRUE);
131 }
132
133
134 #endif /* __GTK_TREE_MODEL_REF_COUNT_H__ */