mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-27 17:52:58 +02:00
New function: g_clear_object()
By analogy to g_clear_error, takes a pass-by-reference GObject reference and, if non-%NULL, unrefs it and sets it equal to %NULL. Bug #620263.
This commit is contained in:
1
gobject/tests/.gitignore
vendored
1
gobject/tests/.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
binding
|
||||
dynamictests
|
||||
properties
|
||||
reference
|
||||
threadtests
|
||||
|
@@ -5,7 +5,7 @@ INCLUDES = -g $(gobject_INCLUDES) $(GLIB_DEBUG_FLAGS)
|
||||
noinst_PROGRAMS = $(TEST_PROGS)
|
||||
libgobject_LDADD = ../libgobject-2.0.la $(top_builddir)/gthread/libgthread-2.0.la $(top_builddir)/glib/libglib-2.0.la
|
||||
|
||||
TEST_PROGS += threadtests dynamictests binding properties
|
||||
TEST_PROGS += threadtests dynamictests binding properties reference
|
||||
threadtests_SOURCES = threadtests.c
|
||||
threadtests_LDADD = $(libgobject_LDADD)
|
||||
dynamictests_SOURCES = dynamictests.c
|
||||
@@ -14,3 +14,4 @@ binding_SOURCES = binding.c
|
||||
binding_LDADD = $(libgobject_LDADD)
|
||||
properties_SOURCES = properties.c
|
||||
properties_LDADD = $(libgobject_LDADD)
|
||||
reference_LDADD = $(libgobject_LDADD)
|
||||
|
35
gobject/tests/reference.c
Normal file
35
gobject/tests/reference.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <glib-object.h>
|
||||
|
||||
static void
|
||||
test_clear (void)
|
||||
{
|
||||
GObject *o = NULL;
|
||||
GObject *tmp;
|
||||
|
||||
g_clear_object (&o);
|
||||
g_assert (o == NULL);
|
||||
|
||||
tmp = g_object_new (G_TYPE_OBJECT, NULL);
|
||||
g_assert_cmpint (tmp->ref_count, ==, 1);
|
||||
o = g_object_ref (tmp);
|
||||
g_assert (o != NULL);
|
||||
|
||||
g_assert_cmpint (tmp->ref_count, ==, 2);
|
||||
g_clear_object (&o);
|
||||
g_assert_cmpint (tmp->ref_count, ==, 1);
|
||||
g_assert (o == NULL);
|
||||
|
||||
g_object_unref (tmp);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_type_init ();
|
||||
|
||||
g_test_add_func ("/object/clear", test_clear);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
Reference in New Issue
Block a user