2 * test-floating.c - Source for TestFloatingWithSinkFunc and TestFloatingWithoutSinkFunc
3 * Copyright (C) 2010 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "test-floating.h"
22 /* TestFloatingWithSinkFunc */
24 G_DEFINE_TYPE(TestFloatingWithSinkFunc, test_floating_with_sink_func, G_TYPE_INITIALLY_UNOWNED)
27 test_floating_with_sink_func_finalize (GObject *gobject)
29 TestFloatingWithSinkFunc *object = TEST_FLOATING_WITH_SINK_FUNC (gobject);
31 if (g_object_is_floating (object))
33 g_warning ("A floating object was finalized. This means that someone\n"
34 "called g_object_unref() on an object that had only a floating\n"
35 "reference; the initial floating reference is not owned by anyone\n"
36 "and must be removed with g_object_ref_sink().");
39 G_OBJECT_CLASS (test_floating_with_sink_func_parent_class)->finalize (gobject);
43 test_floating_with_sink_func_class_init (TestFloatingWithSinkFuncClass *klass)
45 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
47 gobject_class->finalize = test_floating_with_sink_func_finalize;
51 test_floating_with_sink_func_init (TestFloatingWithSinkFunc *self)
56 sink_test_floating_with_sink_func (GObject *object)
58 if (g_object_is_floating(object)) {
59 g_object_ref_sink(object);
63 /* TestFloatingWithoutSinkFunc */
65 G_DEFINE_TYPE(TestFloatingWithoutSinkFunc, test_floating_without_sink_func, G_TYPE_INITIALLY_UNOWNED)
68 test_floating_without_sink_func_finalize (GObject *gobject)
70 TestFloatingWithoutSinkFunc *object = TEST_FLOATING_WITHOUT_SINK_FUNC (gobject);
72 if (g_object_is_floating (object))
74 g_warning ("A floating object was finalized. This means that someone\n"
75 "called g_object_unref() on an object that had only a floating\n"
76 "reference; the initial floating reference is not owned by anyone\n"
77 "and must be removed without g_object_ref_sink().");
80 G_OBJECT_CLASS (test_floating_without_sink_func_parent_class)->finalize (gobject);
84 test_floating_without_sink_func_class_init (TestFloatingWithoutSinkFuncClass *klass)
86 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
88 gobject_class->finalize = test_floating_without_sink_func_finalize;
92 test_floating_without_sink_func_init (TestFloatingWithoutSinkFunc *self)
96 /* TestOwnedByLibrary */
98 G_DEFINE_TYPE(TestOwnedByLibrary, test_owned_by_library, G_TYPE_OBJECT)
100 static GSList *obl_instance_list = NULL;
103 test_owned_by_library_class_init (TestOwnedByLibraryClass *klass)
108 test_owned_by_library_init (TestOwnedByLibrary *self)
111 obl_instance_list = g_slist_prepend (obl_instance_list, self);
115 test_owned_by_library_release (TestOwnedByLibrary *self)
117 obl_instance_list = g_slist_remove (obl_instance_list, self);
118 g_object_unref (self);
122 test_owned_by_library_get_instance_list (void)
124 return obl_instance_list;
127 /* TestFloatingAndSunk
128 * This object is mimicking the GtkWindow behaviour, ie a GInitiallyUnowned subclass
129 * whose floating reference has already been sunk when g_object_new() returns it.
130 * The reference is already sunk because the instance is already owned by the instance
134 G_DEFINE_TYPE(TestFloatingAndSunk, test_floating_and_sunk, G_TYPE_INITIALLY_UNOWNED)
136 static GSList *fas_instance_list = NULL;
139 test_floating_and_sunk_class_init (TestFloatingAndSunkClass *klass)
144 test_floating_and_sunk_init (TestFloatingAndSunk *self)
146 g_object_ref_sink (self);
147 fas_instance_list = g_slist_prepend (fas_instance_list, self);
151 test_floating_and_sunk_release (TestFloatingAndSunk *self)
153 fas_instance_list = g_slist_remove (fas_instance_list, self);
154 g_object_unref (self);
158 test_floating_and_sunk_get_instance_list (void)
160 return fas_instance_list;