Update contrib.
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2001, 2003 Red Hat, Inc.
3 * Portions copyright (c) 2006-2009 Nokia Corporation. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #define G_LOG_DOMAIN "TestIfaceCheck"
23 #undef G_DISABLE_ASSERT
24 #undef G_DISABLE_CHECKS
25 #undef G_DISABLE_CAST_CHECKS
29 #include <glib-object.h>
31 #include "testcommon.h"
33 #include "mrt2_glib2_test.h"
34 #endif /*__SYMBIAN32__*/
36 /* This test tests g_type_add_interface_check_func(), which allows
37 * installing a post-initialization check function.
40 #define TEST_TYPE_IFACE (test_iface_get_type ())
41 #define TEST_IFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_TYPE_IFACE, TestIfaceClass))
42 typedef struct _TestIfaceClass TestIfaceClass;
44 struct _TestIfaceClass
46 GTypeInterface base_iface;
51 test_iface_base_init (TestIfaceClass *iface)
53 iface->history = g_string_new (iface->history ? iface->history->str : NULL);
56 static DEFINE_IFACE(TestIface, test_iface, test_iface_base_init, NULL)
61 #define TEST_TYPE_OBJECT1 (test_object1_get_type ())
62 typedef struct _GObject TestObject1;
63 typedef struct _GObjectClass TestObject1Class;
65 static DEFINE_TYPE_FULL (TestObject1, test_object1,
68 INTERFACE (NULL, TEST_TYPE_IFACE))
73 #define TEST_TYPE_OBJECT2 (test_object2_get_type ())
74 typedef struct _GObject TestObject2;
75 typedef struct _GObjectClass TestObject2Class;
77 static DEFINE_TYPE_FULL (TestObject2, test_object2,
80 INTERFACE (NULL, TEST_TYPE_IFACE))
85 #define TEST_TYPE_OBJECT3 (test_object3_get_type ())
86 typedef struct _GObject TestObject3;
87 typedef struct _GObjectClass TestObject3Class;
89 static DEFINE_TYPE_FULL (TestObject3, test_object3,
92 INTERFACE (NULL, TEST_TYPE_IFACE))
97 #define TEST_TYPE_OBJECT4 (test_object4_get_type ())
98 typedef struct _GObject TestObject4;
99 typedef struct _GObjectClass TestObject4Class;
102 static DEFINE_TYPE_FULL (TestObject4, test_object4,
107 check_func (gpointer check_data,
110 TestIfaceClass *iface = g_iface;
112 g_string_append (iface->history, check_data);
119 TestIfaceClass *iface;
124 g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
125 g_set_print_handler(mrtPrintHandler);
126 #endif /*__SYMBIAN32__*/
129 /* Basic check of interfaces added before class_init time
131 g_type_add_interface_check (string1, check_func);
133 object = g_object_new (TEST_TYPE_OBJECT1, NULL);
134 iface = TEST_IFACE_GET_CLASS (object);
135 g_assert (strcmp (iface->history->str, "A") == 0);
136 g_object_unref (object);
138 /* Add a second check function
140 g_type_add_interface_check (string2, check_func);
142 object = g_object_new (TEST_TYPE_OBJECT2, NULL);
143 iface = TEST_IFACE_GET_CLASS (object);
144 g_assert (strcmp (iface->history->str, "AB") == 0);
145 g_object_unref (object);
147 /* Remove the first check function
149 g_type_remove_interface_check (string1, check_func);
151 object = g_object_new (TEST_TYPE_OBJECT3, NULL);
152 iface = TEST_IFACE_GET_CLASS (object);
153 g_assert (strcmp (iface->history->str, "B") == 0);
154 g_object_unref (object);
156 /* Test interfaces added after class_init time
158 g_type_class_ref (TEST_TYPE_OBJECT4);
160 static GInterfaceInfo const iface = {
164 g_type_add_interface_static (TEST_TYPE_OBJECT4, TEST_TYPE_IFACE, &iface);
167 object = g_object_new (TEST_TYPE_OBJECT4, NULL);
168 iface = TEST_IFACE_GET_CLASS (object);
169 g_assert (strcmp (iface->history->str, "B") == 0);
170 g_object_unref (object);
172 testResultXml("ifacecheck");
173 #endif /*__SYMBIAN32__*/