Debian Codegraph @

tests/test-floating.c

raw
1 /*
2 * test-floating.c - Source for TestFloating
3 * Copyright (C) 2010 Collabora Ltd.
4 *
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.
9 *
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.
14 *
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
18 */
19
20 #include "test-floating.h"
21
22 /* TestFloating */
23
24 G_DEFINE_TYPE (TestFloating, test_floating, G_TYPE_INITIALLY_UNOWNED)
25
26 static void
27 test_floating_finalize (GObject *gobject)
28 {
29 TestFloating *object = TEST_FLOATING (gobject);
30
31 if (g_object_is_floating (object)) {
32 g_warning (
33 "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 "
36 "anyone\n"
37 "and must be removed without g_object_ref_sink().");
38 }
39
40 G_OBJECT_CLASS (test_floating_parent_class)->finalize (gobject);
41 }
42
43 static void
44 test_floating_class_init (TestFloatingClass *klass)
45 {
46 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
47
48 gobject_class->finalize = test_floating_finalize;
49 }
50
51 static void
52 test_floating_init (TestFloating *self)
53 {
54 }
55
56 /* TestOwnedByLibrary */
57
58 G_DEFINE_TYPE (TestOwnedByLibrary, test_owned_by_library, G_TYPE_OBJECT)
59
60 static GSList *obl_instance_list = NULL;
61
62 static void
63 test_owned_by_library_class_init (TestOwnedByLibraryClass *klass)
64 {
65 }
66
67 static void
68 test_owned_by_library_init (TestOwnedByLibrary *self)
69 {
70 g_object_ref (self);
71 obl_instance_list = g_slist_prepend (obl_instance_list, self);
72 }
73
74 void
75 test_owned_by_library_release (TestOwnedByLibrary *self)
76 {
77 obl_instance_list = g_slist_remove (obl_instance_list, self);
78 g_object_unref (self);
79 }
80
81 GSList *
82 test_owned_by_library_get_instance_list (void)
83 {
84 return obl_instance_list;
85 }
86
87 /* TestFloatingAndSunk
88 * This object is mimicking the GtkWindow behaviour, ie a GInitiallyUnowned subclass
89 * whose floating reference has already been sunk when g_object_new() returns it.
90 * The reference is already sunk because the instance is already owned by the instance
91 * list.
92 */
93
94 G_DEFINE_TYPE (TestFloatingAndSunk, test_floating_and_sunk,
95 G_TYPE_INITIALLY_UNOWNED)
96
97 static GSList *fas_instance_list = NULL;
98
99 static void
100 test_floating_and_sunk_class_init (TestFloatingAndSunkClass *klass)
101 {
102 }
103
104 static void
105 test_floating_and_sunk_init (TestFloatingAndSunk *self)
106 {
107 g_object_ref_sink (self);
108 fas_instance_list = g_slist_prepend (fas_instance_list, self);
109 }
110
111 void
112 test_floating_and_sunk_release (TestFloatingAndSunk *self)
113 {
114 fas_instance_list = g_slist_remove (fas_instance_list, self);
115 g_object_unref (self);
116 }
117
118 GSList *
119 test_floating_and_sunk_get_instance_list (void)
120 {
121 return fas_instance_list;
122 }