functions: revert the function init order to make pylint happy again. See #217
[pygobject.git] / tests / test-floating.c
blob18e4a4690978e79f7daf1d5c418934256dc598b2
1 /*
2 * test-floating.c - Source for TestFloating
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 /* TestFloating */
24 G_DEFINE_TYPE(TestFloating, test_floating, G_TYPE_INITIALLY_UNOWNED)
26 static void
27 test_floating_finalize (GObject *gobject)
29 TestFloating *object = TEST_FLOATING (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 without g_object_ref_sink().");
39 G_OBJECT_CLASS (test_floating_parent_class)->finalize (gobject);
42 static void
43 test_floating_class_init (TestFloatingClass *klass)
45 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
47 gobject_class->finalize = test_floating_finalize;
50 static void
51 test_floating_init (TestFloating *self)
55 /* TestOwnedByLibrary */
57 G_DEFINE_TYPE(TestOwnedByLibrary, test_owned_by_library, G_TYPE_OBJECT)
59 static GSList *obl_instance_list = NULL;
61 static void
62 test_owned_by_library_class_init (TestOwnedByLibraryClass *klass)
66 static void
67 test_owned_by_library_init (TestOwnedByLibrary *self)
69 g_object_ref (self);
70 obl_instance_list = g_slist_prepend (obl_instance_list, self);
73 void
74 test_owned_by_library_release (TestOwnedByLibrary *self)
76 obl_instance_list = g_slist_remove (obl_instance_list, self);
77 g_object_unref (self);
80 GSList *
81 test_owned_by_library_get_instance_list (void)
83 return obl_instance_list;
86 /* TestFloatingAndSunk
87 * This object is mimicking the GtkWindow behaviour, ie a GInitiallyUnowned subclass
88 * whose floating reference has already been sunk when g_object_new() returns it.
89 * The reference is already sunk because the instance is already owned by the instance
90 * list.
93 G_DEFINE_TYPE(TestFloatingAndSunk, test_floating_and_sunk, G_TYPE_INITIALLY_UNOWNED)
95 static GSList *fas_instance_list = NULL;
97 static void
98 test_floating_and_sunk_class_init (TestFloatingAndSunkClass *klass)
102 static void
103 test_floating_and_sunk_init (TestFloatingAndSunk *self)
105 g_object_ref_sink (self);
106 fas_instance_list = g_slist_prepend (fas_instance_list, self);
109 void
110 test_floating_and_sunk_release (TestFloatingAndSunk *self)
112 fas_instance_list = g_slist_remove (fas_instance_list, self);
113 g_object_unref (self);
116 GSList *
117 test_floating_and_sunk_get_instance_list (void)
119 return fas_instance_list;