forked from AuroraMiddleware/gtk
treemodelrefcount: make it possible to assert within check functions
This commit is contained in:
parent
88dd6372b0
commit
07d99d26b2
@ -217,7 +217,8 @@ gtk_tree_model_ref_count_dump (GtkTreeModelRefCount *ref_model)
|
|||||||
static gboolean
|
static gboolean
|
||||||
check_iter (GtkTreeModelRefCount *ref_model,
|
check_iter (GtkTreeModelRefCount *ref_model,
|
||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
gint expected_ref_count)
|
gint expected_ref_count,
|
||||||
|
gboolean may_assert)
|
||||||
{
|
{
|
||||||
NodeInfo *info;
|
NodeInfo *info;
|
||||||
|
|
||||||
@ -227,9 +228,16 @@ check_iter (GtkTreeModelRefCount *ref_model,
|
|||||||
if (expected_ref_count == 0)
|
if (expected_ref_count == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
else
|
else
|
||||||
return FALSE;
|
{
|
||||||
|
if (may_assert)
|
||||||
|
g_error ("Expected ref count %d, but node has never been referenced.\n", expected_ref_count);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (may_assert)
|
||||||
|
g_assert_cmpint (expected_ref_count, ==, info->ref_count);
|
||||||
|
|
||||||
return expected_ref_count == info->ref_count;
|
return expected_ref_count == info->ref_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,7 +245,8 @@ gboolean
|
|||||||
gtk_tree_model_ref_count_check_level (GtkTreeModelRefCount *ref_model,
|
gtk_tree_model_ref_count_check_level (GtkTreeModelRefCount *ref_model,
|
||||||
GtkTreeIter *parent,
|
GtkTreeIter *parent,
|
||||||
gint expected_ref_count,
|
gint expected_ref_count,
|
||||||
gboolean recurse)
|
gboolean recurse,
|
||||||
|
gboolean may_assert)
|
||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
|
||||||
@ -247,7 +256,7 @@ gtk_tree_model_ref_count_check_level (GtkTreeModelRefCount *ref_model,
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!check_iter (ref_model, &iter, expected_ref_count))
|
if (!check_iter (ref_model, &iter, expected_ref_count, may_assert))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (recurse &&
|
if (recurse &&
|
||||||
@ -255,7 +264,7 @@ gtk_tree_model_ref_count_check_level (GtkTreeModelRefCount *ref_model,
|
|||||||
{
|
{
|
||||||
if (!gtk_tree_model_ref_count_check_level (ref_model, &iter,
|
if (!gtk_tree_model_ref_count_check_level (ref_model, &iter,
|
||||||
expected_ref_count,
|
expected_ref_count,
|
||||||
recurse))
|
recurse, may_assert))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,7 +276,8 @@ gtk_tree_model_ref_count_check_level (GtkTreeModelRefCount *ref_model,
|
|||||||
gboolean
|
gboolean
|
||||||
gtk_tree_model_ref_count_check_node (GtkTreeModelRefCount *ref_model,
|
gtk_tree_model_ref_count_check_node (GtkTreeModelRefCount *ref_model,
|
||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
gint expected_ref_count)
|
gint expected_ref_count,
|
||||||
|
gboolean may_assert)
|
||||||
{
|
{
|
||||||
return check_iter (ref_model, iter, expected_ref_count);
|
return check_iter (ref_model, iter, expected_ref_count, may_assert);
|
||||||
}
|
}
|
||||||
|
@ -57,10 +57,12 @@ void gtk_tree_model_ref_count_dump (GtkTreeModelRefCount *ref_mo
|
|||||||
gboolean gtk_tree_model_ref_count_check_level (GtkTreeModelRefCount *ref_model,
|
gboolean gtk_tree_model_ref_count_check_level (GtkTreeModelRefCount *ref_model,
|
||||||
GtkTreeIter *parent,
|
GtkTreeIter *parent,
|
||||||
gint expected_ref_count,
|
gint expected_ref_count,
|
||||||
gboolean recurse);
|
gboolean recurse,
|
||||||
|
gboolean may_assert);
|
||||||
gboolean gtk_tree_model_ref_count_check_node (GtkTreeModelRefCount *ref_model,
|
gboolean gtk_tree_model_ref_count_check_node (GtkTreeModelRefCount *ref_model,
|
||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
gint expected_ref_count);
|
gint expected_ref_count,
|
||||||
|
gboolean may_assert);
|
||||||
|
|
||||||
/* A couple of helpers for the tests. Since this model will never be used
|
/* A couple of helpers for the tests. Since this model will never be used
|
||||||
* outside of unit tests anyway, it is probably fine to have these here
|
* outside of unit tests anyway, it is probably fine to have these here
|
||||||
@ -70,35 +72,27 @@ gboolean gtk_tree_model_ref_count_check_node (GtkTreeModelRefCount *ref_mo
|
|||||||
static inline void
|
static inline void
|
||||||
assert_entire_model_unreferenced (GtkTreeModelRefCount *ref_model)
|
assert_entire_model_unreferenced (GtkTreeModelRefCount *ref_model)
|
||||||
{
|
{
|
||||||
g_assert_cmpint (gtk_tree_model_ref_count_check_level (ref_model, NULL, 0,
|
gtk_tree_model_ref_count_check_level (ref_model, NULL, 0, TRUE, TRUE);
|
||||||
TRUE),
|
|
||||||
==, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
assert_root_level_unreferenced (GtkTreeModelRefCount *ref_model)
|
assert_root_level_unreferenced (GtkTreeModelRefCount *ref_model)
|
||||||
{
|
{
|
||||||
g_assert_cmpint (gtk_tree_model_ref_count_check_level (ref_model, NULL, 0,
|
gtk_tree_model_ref_count_check_level (ref_model, NULL, 0, FALSE, TRUE);
|
||||||
FALSE),
|
|
||||||
==, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
assert_level_unreferenced (GtkTreeModelRefCount *ref_model,
|
assert_level_unreferenced (GtkTreeModelRefCount *ref_model,
|
||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
g_assert_cmpint (gtk_tree_model_ref_count_check_level (ref_model, iter,
|
gtk_tree_model_ref_count_check_level (ref_model, iter, 0, FALSE, TRUE);
|
||||||
0, FALSE),
|
|
||||||
==, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
assert_entire_model_referenced (GtkTreeModelRefCount *ref_model,
|
assert_entire_model_referenced (GtkTreeModelRefCount *ref_model,
|
||||||
gint ref_count)
|
gint ref_count)
|
||||||
{
|
{
|
||||||
g_assert_cmpint (gtk_tree_model_ref_count_check_level (ref_model, NULL,
|
gtk_tree_model_ref_count_check_level (ref_model, NULL, ref_count, TRUE, TRUE);
|
||||||
ref_count, TRUE),
|
|
||||||
==, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
@ -106,7 +100,8 @@ assert_not_entire_model_referenced (GtkTreeModelRefCount *ref_model,
|
|||||||
gint ref_count)
|
gint ref_count)
|
||||||
{
|
{
|
||||||
g_assert_cmpint (gtk_tree_model_ref_count_check_level (ref_model, NULL,
|
g_assert_cmpint (gtk_tree_model_ref_count_check_level (ref_model, NULL,
|
||||||
ref_count, TRUE),
|
ref_count,
|
||||||
|
TRUE, FALSE),
|
||||||
==, FALSE);
|
==, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,9 +109,8 @@ static inline void
|
|||||||
assert_root_level_referenced (GtkTreeModelRefCount *ref_model,
|
assert_root_level_referenced (GtkTreeModelRefCount *ref_model,
|
||||||
gint ref_count)
|
gint ref_count)
|
||||||
{
|
{
|
||||||
g_assert_cmpint (gtk_tree_model_ref_count_check_level (ref_model, NULL,
|
gtk_tree_model_ref_count_check_level (ref_model, NULL, ref_count,
|
||||||
ref_count, FALSE),
|
FALSE, TRUE);
|
||||||
==, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
@ -124,9 +118,8 @@ assert_level_referenced (GtkTreeModelRefCount *ref_model,
|
|||||||
gint ref_count,
|
gint ref_count,
|
||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
g_assert_cmpint (gtk_tree_model_ref_count_check_level (ref_model, iter,
|
gtk_tree_model_ref_count_check_level (ref_model, iter, ref_count,
|
||||||
ref_count, FALSE),
|
FALSE, TRUE);
|
||||||
==, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
@ -134,9 +127,7 @@ assert_node_ref_count (GtkTreeModelRefCount *ref_model,
|
|||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
gint ref_count)
|
gint ref_count)
|
||||||
{
|
{
|
||||||
g_assert_cmpint (gtk_tree_model_ref_count_check_node (ref_model, iter,
|
gtk_tree_model_ref_count_check_node (ref_model, iter, ref_count, TRUE);
|
||||||
ref_count),
|
|
||||||
==, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user