918a42d0daf734068b11469c7d071714934f24c7
[profile/ivi/pygobject2.git] / tests / test-floating.c
1 /*
2  * test-floating.c - Source for TestFloatingWithSinkFunc and TestFloatingWithoutSinkFunc
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 /* TestFloatingWithSinkFunc */
23
24 G_DEFINE_TYPE(TestFloatingWithSinkFunc, test_floating_with_sink_func, G_TYPE_INITIALLY_UNOWNED)
25
26 static void
27 test_floating_with_sink_func_finalize (GObject *gobject)
28 {
29   TestFloatingWithSinkFunc *object = TEST_FLOATING_WITH_SINK_FUNC (gobject);
30
31   if (g_object_is_floating (object))
32     {
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().");
37     }
38   
39   G_OBJECT_CLASS (test_floating_with_sink_func_parent_class)->finalize (gobject);
40 }
41
42 static void
43 test_floating_with_sink_func_class_init (TestFloatingWithSinkFuncClass *klass)
44 {
45   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
46
47   gobject_class->finalize = test_floating_with_sink_func_finalize;
48 }
49
50 static void
51 test_floating_with_sink_func_init (TestFloatingWithSinkFunc *self)
52 {
53 }
54
55 void
56 sink_test_floating_with_sink_func (GObject *object)
57 {
58     if (g_object_is_floating(object)) {
59             g_object_ref_sink(object);
60     }
61 }
62
63 /* TestFloatingWithoutSinkFunc */
64
65 G_DEFINE_TYPE(TestFloatingWithoutSinkFunc, test_floating_without_sink_func, G_TYPE_INITIALLY_UNOWNED)
66
67 static void
68 test_floating_without_sink_func_finalize (GObject *gobject)
69 {
70   TestFloatingWithoutSinkFunc *object = TEST_FLOATING_WITHOUT_SINK_FUNC (gobject);
71
72   if (g_object_is_floating (object))
73     {
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().");
78     }
79
80   G_OBJECT_CLASS (test_floating_without_sink_func_parent_class)->finalize (gobject);
81 }
82
83 static void
84 test_floating_without_sink_func_class_init (TestFloatingWithoutSinkFuncClass *klass)
85 {
86   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
87
88   gobject_class->finalize = test_floating_without_sink_func_finalize;
89 }
90
91 static void
92 test_floating_without_sink_func_init (TestFloatingWithoutSinkFunc *self)
93 {
94 }
95