|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
3 * |
|
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. |
|
8 * |
|
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. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public |
|
15 * 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. |
|
18 * |
|
19 * Description: |
|
20 * |
|
21 */ |
|
22 |
|
23 #include <unistd.h> |
|
24 #include <glib.h> |
|
25 #include <glib-object.h> |
|
26 |
|
27 #include <stdio.h> |
|
28 #ifdef SYMBIAN |
|
29 #include "mrt2_glib2_test.h" |
|
30 #endif /*SYMBIAN*/ |
|
31 |
|
32 |
|
33 #define G_TYPE_TEST (g_test_get_type ()) |
|
34 #define G_TEST(test) (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest)) |
|
35 #define G_IS_TEST(test) (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST)) |
|
36 #define G_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass)) |
|
37 #define G_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST)) |
|
38 #define G_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass)) |
|
39 |
|
40 enum { |
|
41 PROP_0, |
|
42 PROP_DUMMY |
|
43 }; |
|
44 |
|
45 typedef struct _GTest GTest; |
|
46 typedef struct _GTestClass GTestClass; |
|
47 |
|
48 struct _GTest |
|
49 { |
|
50 GObject object; |
|
51 |
|
52 gint dummy; |
|
53 }; |
|
54 |
|
55 struct _GTestClass |
|
56 { |
|
57 GObjectClass parent_class; |
|
58 }; |
|
59 |
|
60 static GType g_test_get_type (void); |
|
61 |
|
62 static void g_test_class_init (GTestClass * klass); |
|
63 static void g_test_init (GTest * test); |
|
64 static void g_test_dispose (GObject * object); |
|
65 static void g_test_get_property (GObject *object, |
|
66 guint prop_id, |
|
67 GValue *value, |
|
68 GParamSpec *pspec); |
|
69 static void g_test_set_property (GObject *object, |
|
70 guint prop_id, |
|
71 const GValue *value, |
|
72 GParamSpec *pspec); |
|
73 |
|
74 static GObjectClass *parent_class = NULL; |
|
75 |
|
76 static GType |
|
77 g_test_get_type (void) |
|
78 { |
|
79 static GType test_type = 0; |
|
80 |
|
81 if (!test_type) { |
|
82 static const GTypeInfo test_info = { |
|
83 sizeof (GTestClass), |
|
84 NULL, |
|
85 NULL, |
|
86 (GClassInitFunc) g_test_class_init, |
|
87 NULL, |
|
88 NULL, |
|
89 sizeof (GTest), |
|
90 0, |
|
91 (GInstanceInitFunc) g_test_init, |
|
92 NULL |
|
93 }; |
|
94 |
|
95 test_type = g_type_register_static (G_TYPE_OBJECT, "GTest", |
|
96 &test_info, 0); |
|
97 if(!test_type) |
|
98 { |
|
99 g_print("properties2.c : g_type_register_static is failed @ line : %d",__LINE__); |
|
100 g_assert(FALSE && "properties"); |
|
101 } |
|
102 } |
|
103 return test_type; |
|
104 } |
|
105 |
|
106 static void |
|
107 g_test_class_init (GTestClass * klass) |
|
108 { |
|
109 GObjectClass *gobject_class; |
|
110 GParamSpec *gparam_spec; |
|
111 |
|
112 gobject_class = (GObjectClass *) klass; |
|
113 |
|
114 parent_class = g_type_class_ref (G_TYPE_OBJECT); |
|
115 if(!parent_class) |
|
116 { |
|
117 g_print("properties2.c : g_tupe_class_ref failed @ line : %d",__LINE__); |
|
118 g_assert(FALSE && "properties"); |
|
119 } |
|
120 |
|
121 |
|
122 |
|
123 gobject_class->dispose = g_test_dispose; |
|
124 gobject_class->get_property = g_test_get_property; |
|
125 gobject_class->set_property = g_test_set_property; |
|
126 |
|
127 g_object_class_install_property (gobject_class, |
|
128 PROP_DUMMY, |
|
129 g_param_spec_int ("dummy", |
|
130 NULL, |
|
131 NULL, |
|
132 0, G_MAXINT, 0, |
|
133 G_PARAM_READWRITE)); |
|
134 |
|
135 } |
|
136 |
|
137 static void |
|
138 g_test_init (GTest * test) |
|
139 { |
|
140 //g_print ("init %p\n", test); |
|
141 } |
|
142 |
|
143 static void |
|
144 g_test_dispose (GObject * object) |
|
145 { |
|
146 GTest *test; |
|
147 |
|
148 test = G_TEST (object); |
|
149 |
|
150 g_print ("dispose %p!\n", object); |
|
151 |
|
152 G_OBJECT_CLASS (parent_class)->dispose (object); |
|
153 } |
|
154 |
|
155 static void |
|
156 g_test_get_property (GObject *object, |
|
157 guint prop_id, |
|
158 GValue *value, |
|
159 GParamSpec *pspec) |
|
160 { |
|
161 GTest *test; |
|
162 |
|
163 test = G_TEST (object); |
|
164 |
|
165 switch (prop_id) |
|
166 { |
|
167 case PROP_DUMMY: |
|
168 g_value_set_int (value, test->dummy); |
|
169 break; |
|
170 default: |
|
171 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|
172 break; |
|
173 } |
|
174 } |
|
175 |
|
176 static void |
|
177 g_test_set_property (GObject *object, |
|
178 guint prop_id, |
|
179 const GValue *value, |
|
180 GParamSpec *pspec) |
|
181 { |
|
182 GTest *test; |
|
183 |
|
184 test = G_TEST (object); |
|
185 |
|
186 switch (prop_id) |
|
187 { |
|
188 case PROP_DUMMY: |
|
189 test->dummy = g_value_get_int (value); |
|
190 break; |
|
191 default: |
|
192 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
|
193 break; |
|
194 } |
|
195 } |
|
196 |
|
197 static gint count = 0; |
|
198 |
|
199 |
|
200 static void |
|
201 g_test_do_property (GTest * test) |
|
202 { |
|
203 gint returnvalue, passedvalue=4; |
|
204 GValue value1 = { 0, }; |
|
205 GValue value2 = { 0, }; |
|
206 |
|
207 g_value_init(&value1,G_TYPE_INT); |
|
208 g_value_init(&value2,G_TYPE_INT); |
|
209 |
|
210 g_value_set_int(&value1, passedvalue); |
|
211 |
|
212 |
|
213 g_object_set_property (G_OBJECT(G_TEST(test)), "dummy", &value1); |
|
214 g_object_get_property (G_OBJECT(G_TEST(test)), "dummy",&value2); |
|
215 |
|
216 returnvalue = g_value_get_int(&value2); |
|
217 g_assert(returnvalue == passedvalue); |
|
218 |
|
219 } |
|
220 |
|
221 |
|
222 void test_float_sink() |
|
223 { |
|
224 GTest *test; |
|
225 GObject* obj; |
|
226 test = g_object_new (G_TYPE_TEST, NULL); |
|
227 obj = G_OBJECT(test); |
|
228 g_object_force_floating(obj); |
|
229 g_assert(g_object_is_floating(obj)); |
|
230 g_object_ref_sink(obj); |
|
231 g_object_unref(obj); |
|
232 } |
|
233 |
|
234 |
|
235 int |
|
236 main (int argc, char **argv) |
|
237 { |
|
238 gint i; |
|
239 gint handle_id = 0; |
|
240 GTest *test; |
|
241 |
|
242 #ifdef SYMBIAN |
|
243 |
|
244 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); |
|
245 g_set_print_handler(mrtPrintHandler); |
|
246 #endif /*SYMBIAN*/ |
|
247 |
|
248 |
|
249 g_type_init (); |
|
250 |
|
251 test = g_object_new (G_TYPE_TEST, NULL); |
|
252 if(!test) |
|
253 { |
|
254 g_print("object_get_property.c : g_object_new is failed @ line : %d",__LINE__); |
|
255 g_assert(FALSE && "properties"); |
|
256 } |
|
257 |
|
258 g_test_do_property (test); |
|
259 test_float_sink(); |
|
260 |
|
261 |
|
262 //g_assert (count == test->dummy); |
|
263 #ifdef SYMBIAN |
|
264 testResultXml("object_extra_tests"); |
|
265 #endif /* EMULATOR */ |
|
266 |
|
267 return 0; |
|
268 } |