sl@0
|
1 |
/* GObject - GLib Type, Object, Parameter and Signal Library
|
sl@0
|
2 |
* Copyright (C) 2001, 2003 Red Hat, Inc.
|
sl@0
|
3 |
*
|
sl@0
|
4 |
* This library is free software; you can redistribute it and/or
|
sl@0
|
5 |
* modify it under the terms of the GNU Lesser General Public
|
sl@0
|
6 |
* License as published by the Free Software Foundation; either
|
sl@0
|
7 |
* version 2 of the License, or (at your option) any later version.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* This library is distributed in the hope that it will be useful,
|
sl@0
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
sl@0
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
sl@0
|
12 |
* Lesser General Public License for more details.
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* You should have received a copy of the GNU Lesser General
|
sl@0
|
15 |
* Public License along with this library; if not, write to the
|
sl@0
|
16 |
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
sl@0
|
17 |
* Boston, MA 02111-1307, USA.
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
#undef G_LOG_DOMAIN
|
sl@0
|
21 |
//#define G_LOG_DOMAIN "TestIfaceProperties"
|
sl@0
|
22 |
|
sl@0
|
23 |
#undef G_DISABLE_ASSERT
|
sl@0
|
24 |
#undef G_DISABLE_CHECKS
|
sl@0
|
25 |
#undef G_DISABLE_CAST_CHECKS
|
sl@0
|
26 |
|
sl@0
|
27 |
|
sl@0
|
28 |
#include <string.h>
|
sl@0
|
29 |
#include <glib-object.h>
|
sl@0
|
30 |
|
sl@0
|
31 |
#include <gobject_global.h>
|
sl@0
|
32 |
|
sl@0
|
33 |
#include "testcommon.h"
|
sl@0
|
34 |
|
sl@0
|
35 |
#ifdef SYMBIAN
|
sl@0
|
36 |
#include "mrt2_glib2_test.h"
|
sl@0
|
37 |
#endif /*SYMBIAN*/
|
sl@0
|
38 |
|
sl@0
|
39 |
|
sl@0
|
40 |
#include <glib_global.h>
|
sl@0
|
41 |
static guint foo_signal_id = 0; //Amarjeet
|
sl@0
|
42 |
|
sl@0
|
43 |
enum {
|
sl@0
|
44 |
MAMAN_BAR_CONSTRUCT_NAME = 1,
|
sl@0
|
45 |
MAMAN_BAR_PAPA_NUMBER,
|
sl@0
|
46 |
};
|
sl@0
|
47 |
|
sl@0
|
48 |
|
sl@0
|
49 |
/* This test tests interface properties, implementing interface
|
sl@0
|
50 |
* properties and #GParamSpecOverride.
|
sl@0
|
51 |
*
|
sl@0
|
52 |
* Four properties are tested:
|
sl@0
|
53 |
*
|
sl@0
|
54 |
* prop1: Defined in TestIface, Implemented in BaseObject with a GParamSpecOverride
|
sl@0
|
55 |
* prop2: Defined in TestIface, Implemented in BaseObject with a new property
|
sl@0
|
56 |
* prop3: Defined in TestIface, Implemented in BaseObject, Overridden in DerivedObject
|
sl@0
|
57 |
* prop4: Defined in BaseObject, Overridden in DerivedObject
|
sl@0
|
58 |
*/
|
sl@0
|
59 |
|
sl@0
|
60 |
static GType base_object_get_type ();
|
sl@0
|
61 |
static GType derived_object_get_type ();
|
sl@0
|
62 |
|
sl@0
|
63 |
enum {
|
sl@0
|
64 |
BASE_PROP_0,
|
sl@0
|
65 |
BASE_PROP1,
|
sl@0
|
66 |
BASE_PROP2,
|
sl@0
|
67 |
BASE_PROP3,
|
sl@0
|
68 |
BASE_PROP4
|
sl@0
|
69 |
};
|
sl@0
|
70 |
|
sl@0
|
71 |
enum {
|
sl@0
|
72 |
DERIVED_PROP_0,
|
sl@0
|
73 |
DERIVED_PROP3,
|
sl@0
|
74 |
DERIVED_PROP4
|
sl@0
|
75 |
};
|
sl@0
|
76 |
|
sl@0
|
77 |
/*
|
sl@0
|
78 |
* BaseObject, a parent class for DerivedObject
|
sl@0
|
79 |
*/
|
sl@0
|
80 |
#define BASE_TYPE_OBJECT (base_object_get_type ())
|
sl@0
|
81 |
#define BASE_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BASE_TYPE_OBJECT, BaseObject))
|
sl@0
|
82 |
typedef struct _BaseObject BaseObject;
|
sl@0
|
83 |
typedef struct _BaseObjectClass BaseObjectClass;
|
sl@0
|
84 |
|
sl@0
|
85 |
struct _BaseObject
|
sl@0
|
86 |
{
|
sl@0
|
87 |
GObject parent_instance;
|
sl@0
|
88 |
|
sl@0
|
89 |
gint val1;
|
sl@0
|
90 |
gint val2;
|
sl@0
|
91 |
gint val3;
|
sl@0
|
92 |
gint val4;
|
sl@0
|
93 |
};
|
sl@0
|
94 |
struct _BaseObjectClass
|
sl@0
|
95 |
{
|
sl@0
|
96 |
GObjectClass parent_class;
|
sl@0
|
97 |
};
|
sl@0
|
98 |
|
sl@0
|
99 |
GObjectClass *base_parent_class;
|
sl@0
|
100 |
|
sl@0
|
101 |
/*
|
sl@0
|
102 |
* DerivedObject, the child class of DerivedObject
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
#define DERIVED_TYPE_OBJECT (derived_object_get_type ())
|
sl@0
|
105 |
typedef struct _DerivedObject DerivedObject;
|
sl@0
|
106 |
typedef struct _DerivedObjectClass DerivedObjectClass;
|
sl@0
|
107 |
|
sl@0
|
108 |
struct _DerivedObject
|
sl@0
|
109 |
{
|
sl@0
|
110 |
BaseObject parent_instance;
|
sl@0
|
111 |
};
|
sl@0
|
112 |
struct _DerivedObjectClass
|
sl@0
|
113 |
{
|
sl@0
|
114 |
BaseObjectClass parent_class;
|
sl@0
|
115 |
};
|
sl@0
|
116 |
|
sl@0
|
117 |
/*
|
sl@0
|
118 |
* The interface
|
sl@0
|
119 |
*/
|
sl@0
|
120 |
typedef struct _TestIfaceClass TestIfaceClass;
|
sl@0
|
121 |
|
sl@0
|
122 |
struct _TestIfaceClass
|
sl@0
|
123 |
{
|
sl@0
|
124 |
GTypeInterface base_iface;
|
sl@0
|
125 |
};
|
sl@0
|
126 |
|
sl@0
|
127 |
#define TEST_TYPE_IFACE (test_iface_get_type ())
|
sl@0
|
128 |
|
sl@0
|
129 |
/* The paramspecs installed on our interface
|
sl@0
|
130 |
*/
|
sl@0
|
131 |
static GParamSpec *iface_spec1, *iface_spec2, *iface_spec3;
|
sl@0
|
132 |
|
sl@0
|
133 |
/* The paramspecs inherited by our derived object
|
sl@0
|
134 |
*/
|
sl@0
|
135 |
static GParamSpec *inherited_spec1, *inherited_spec2, *inherited_spec3, *inherited_spec4;
|
sl@0
|
136 |
|
sl@0
|
137 |
|
sl@0
|
138 |
|
sl@0
|
139 |
static void
|
sl@0
|
140 |
test_iface_default_init (TestIfaceClass *iface_vtable)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
inherited_spec1 = iface_spec1 = g_param_spec_int ("prop1",
|
sl@0
|
143 |
"Prop1",
|
sl@0
|
144 |
"Property 1",
|
sl@0
|
145 |
G_MININT, /* min */
|
sl@0
|
146 |
0xFFFF, /* max */
|
sl@0
|
147 |
42, /* default */
|
sl@0
|
148 |
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
sl@0
|
149 |
g_object_interface_install_property (iface_vtable, iface_spec1);
|
sl@0
|
150 |
|
sl@0
|
151 |
iface_spec2 = g_param_spec_int ("prop2",
|
sl@0
|
152 |
"Prop2",
|
sl@0
|
153 |
"Property 2",
|
sl@0
|
154 |
G_MININT, /* min */
|
sl@0
|
155 |
G_MAXINT, /* max */
|
sl@0
|
156 |
0, /* default */
|
sl@0
|
157 |
G_PARAM_WRITABLE);
|
sl@0
|
158 |
g_object_interface_install_property (iface_vtable, iface_spec2);
|
sl@0
|
159 |
|
sl@0
|
160 |
inherited_spec3 = iface_spec3 = g_param_spec_int ("prop3",
|
sl@0
|
161 |
"Prop3",
|
sl@0
|
162 |
"Property 3",
|
sl@0
|
163 |
G_MININT, /* min */
|
sl@0
|
164 |
G_MAXINT, /* max */
|
sl@0
|
165 |
0, /* default */
|
sl@0
|
166 |
G_PARAM_READWRITE);
|
sl@0
|
167 |
g_object_interface_install_property (iface_vtable, iface_spec3);
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
static DEFINE_IFACE (TestIface, test_iface, NULL, test_iface_default_init)
|
sl@0
|
171 |
|
sl@0
|
172 |
|
sl@0
|
173 |
static GObject*
|
sl@0
|
174 |
base_object_constructor (GType type,
|
sl@0
|
175 |
guint n_construct_properties,
|
sl@0
|
176 |
GObjectConstructParam *construct_properties)
|
sl@0
|
177 |
{
|
sl@0
|
178 |
/* The constructor is the one place where a GParamSpecOverride is visible
|
sl@0
|
179 |
* to the outside world, so we do a bunch of checks here
|
sl@0
|
180 |
*/
|
sl@0
|
181 |
GValue value1 = { 0, };
|
sl@0
|
182 |
GValue value2 = { 0, };
|
sl@0
|
183 |
GParamSpec *pspec;
|
sl@0
|
184 |
|
sl@0
|
185 |
g_assert (n_construct_properties == 1);
|
sl@0
|
186 |
|
sl@0
|
187 |
pspec = construct_properties->pspec;
|
sl@0
|
188 |
|
sl@0
|
189 |
/* Check we got the param spec we expected
|
sl@0
|
190 |
*/
|
sl@0
|
191 |
g_assert (G_IS_PARAM_SPEC_OVERRIDE (pspec));
|
sl@0
|
192 |
g_assert (pspec->param_id == BASE_PROP1);
|
sl@0
|
193 |
g_assert (strcmp (g_param_spec_get_name (pspec), "prop1") == 0);
|
sl@0
|
194 |
g_assert (g_param_spec_get_redirect_target (pspec) == iface_spec1);
|
sl@0
|
195 |
|
sl@0
|
196 |
/* Test redirection of the nick and blurb to the redirect target
|
sl@0
|
197 |
*/
|
sl@0
|
198 |
g_assert (strcmp (g_param_spec_get_nick (pspec), "Prop1") == 0);
|
sl@0
|
199 |
g_assert (strcmp (g_param_spec_get_blurb (pspec), "Property 1") == 0);
|
sl@0
|
200 |
|
sl@0
|
201 |
/* Test forwarding of the various GParamSpec methods to the redirect target
|
sl@0
|
202 |
*/
|
sl@0
|
203 |
g_value_init (&value1, G_TYPE_INT);
|
sl@0
|
204 |
g_value_init (&value2, G_TYPE_INT);
|
sl@0
|
205 |
|
sl@0
|
206 |
g_param_value_set_default (pspec, &value1);
|
sl@0
|
207 |
g_assert (g_value_get_int (&value1) == 42);
|
sl@0
|
208 |
|
sl@0
|
209 |
g_value_reset (&value1);
|
sl@0
|
210 |
g_value_set_int (&value1, 0x10000);
|
sl@0
|
211 |
g_assert (g_param_value_validate (pspec, &value1));
|
sl@0
|
212 |
g_assert (g_value_get_int (&value1) == 0xFFFF);
|
sl@0
|
213 |
g_assert (!g_param_value_validate (pspec, &value1));
|
sl@0
|
214 |
|
sl@0
|
215 |
g_value_reset (&value1);
|
sl@0
|
216 |
g_value_set_int (&value1, 1);
|
sl@0
|
217 |
g_value_set_int (&value2, 2);
|
sl@0
|
218 |
g_assert (g_param_values_cmp (pspec, &value1, &value2) < 0);
|
sl@0
|
219 |
g_assert (g_param_values_cmp (pspec, &value2, &value1) > 0);
|
sl@0
|
220 |
|
sl@0
|
221 |
g_value_unset (&value1);
|
sl@0
|
222 |
g_value_unset (&value2);
|
sl@0
|
223 |
|
sl@0
|
224 |
return base_parent_class->constructor (type,
|
sl@0
|
225 |
n_construct_properties,
|
sl@0
|
226 |
construct_properties);
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
static void
|
sl@0
|
230 |
base_object_set_property (GObject *object,
|
sl@0
|
231 |
guint prop_id,
|
sl@0
|
232 |
const GValue *value,
|
sl@0
|
233 |
GParamSpec *pspec)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
BaseObject *base_object = BASE_OBJECT (object);
|
sl@0
|
236 |
|
sl@0
|
237 |
switch (prop_id)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
case BASE_PROP1:
|
sl@0
|
240 |
g_assert (pspec == inherited_spec1);
|
sl@0
|
241 |
base_object->val1 = g_value_get_int (value);
|
sl@0
|
242 |
break;
|
sl@0
|
243 |
case BASE_PROP2:
|
sl@0
|
244 |
g_assert (pspec == inherited_spec2);
|
sl@0
|
245 |
base_object->val2 = g_value_get_int (value);
|
sl@0
|
246 |
break;
|
sl@0
|
247 |
case BASE_PROP3:
|
sl@0
|
248 |
g_assert_not_reached ();
|
sl@0
|
249 |
break;
|
sl@0
|
250 |
case BASE_PROP4:
|
sl@0
|
251 |
g_assert_not_reached ();
|
sl@0
|
252 |
break;
|
sl@0
|
253 |
default:
|
sl@0
|
254 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
sl@0
|
255 |
break;
|
sl@0
|
256 |
}
|
sl@0
|
257 |
}
|
sl@0
|
258 |
|
sl@0
|
259 |
static void
|
sl@0
|
260 |
base_object_get_property (GObject *object,
|
sl@0
|
261 |
guint prop_id,
|
sl@0
|
262 |
GValue *value,
|
sl@0
|
263 |
GParamSpec *pspec)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
BaseObject *base_object = BASE_OBJECT (object);
|
sl@0
|
266 |
|
sl@0
|
267 |
switch (prop_id)
|
sl@0
|
268 |
{
|
sl@0
|
269 |
case BASE_PROP1:
|
sl@0
|
270 |
g_assert (pspec == inherited_spec1);
|
sl@0
|
271 |
g_value_set_int (value, base_object->val1);
|
sl@0
|
272 |
break;
|
sl@0
|
273 |
case BASE_PROP2:
|
sl@0
|
274 |
g_assert (pspec == inherited_spec2);
|
sl@0
|
275 |
g_value_set_int (value, base_object->val2);
|
sl@0
|
276 |
break;
|
sl@0
|
277 |
case BASE_PROP3:
|
sl@0
|
278 |
g_assert_not_reached ();
|
sl@0
|
279 |
break;
|
sl@0
|
280 |
case BASE_PROP4:
|
sl@0
|
281 |
g_assert_not_reached ();
|
sl@0
|
282 |
break;
|
sl@0
|
283 |
default:
|
sl@0
|
284 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
sl@0
|
285 |
break;
|
sl@0
|
286 |
}
|
sl@0
|
287 |
}
|
sl@0
|
288 |
|
sl@0
|
289 |
static void
|
sl@0
|
290 |
base_object_notify (GObject *object,
|
sl@0
|
291 |
GParamSpec *pspec)
|
sl@0
|
292 |
{
|
sl@0
|
293 |
/* The property passed to notify is the redirect target, not the
|
sl@0
|
294 |
* GParamSpecOverride
|
sl@0
|
295 |
*/
|
sl@0
|
296 |
g_assert (pspec == inherited_spec1 ||
|
sl@0
|
297 |
pspec == inherited_spec2 ||
|
sl@0
|
298 |
pspec == inherited_spec3 ||
|
sl@0
|
299 |
pspec == inherited_spec4);
|
sl@0
|
300 |
}
|
sl@0
|
301 |
|
sl@0
|
302 |
static void
|
sl@0
|
303 |
base_object_class_init (BaseObjectClass *class)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
sl@0
|
306 |
|
sl@0
|
307 |
base_parent_class= g_type_class_peek_parent (class);
|
sl@0
|
308 |
|
sl@0
|
309 |
object_class->constructor = base_object_constructor;
|
sl@0
|
310 |
object_class->set_property = base_object_set_property;
|
sl@0
|
311 |
object_class->get_property = base_object_get_property;
|
sl@0
|
312 |
object_class->notify = base_object_notify;
|
sl@0
|
313 |
|
sl@0
|
314 |
g_object_class_override_property (object_class, BASE_PROP1, "prop1");
|
sl@0
|
315 |
|
sl@0
|
316 |
/* We override this one using a real property, not GParamSpecOverride
|
sl@0
|
317 |
* We change the flags from READONLY to READWRITE to show that we
|
sl@0
|
318 |
* can make the flags less restrictive
|
sl@0
|
319 |
*/
|
sl@0
|
320 |
inherited_spec2 = g_param_spec_int ("prop2",
|
sl@0
|
321 |
"Prop2",
|
sl@0
|
322 |
"Property 2",
|
sl@0
|
323 |
G_MININT, /* min */
|
sl@0
|
324 |
G_MAXINT, /* max */
|
sl@0
|
325 |
0, /* default */
|
sl@0
|
326 |
G_PARAM_READWRITE);
|
sl@0
|
327 |
g_object_class_install_property (object_class, BASE_PROP2, inherited_spec2);
|
sl@0
|
328 |
|
sl@0
|
329 |
g_object_class_override_property (object_class, BASE_PROP3, "prop3");
|
sl@0
|
330 |
|
sl@0
|
331 |
inherited_spec4 = g_param_spec_int ("prop4",
|
sl@0
|
332 |
"Prop4",
|
sl@0
|
333 |
"Property 4",
|
sl@0
|
334 |
G_MININT, /* min */
|
sl@0
|
335 |
G_MAXINT, /* max */
|
sl@0
|
336 |
0, /* default */
|
sl@0
|
337 |
G_PARAM_READWRITE);
|
sl@0
|
338 |
g_object_class_install_property (object_class, BASE_PROP4, inherited_spec4);
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
static void
|
sl@0
|
342 |
base_object_init (BaseObject *base_object)
|
sl@0
|
343 |
{
|
sl@0
|
344 |
base_object->val1 = 42;
|
sl@0
|
345 |
}
|
sl@0
|
346 |
|
sl@0
|
347 |
static DEFINE_TYPE_FULL (BaseObject, base_object,
|
sl@0
|
348 |
base_object_class_init, NULL, base_object_init,
|
sl@0
|
349 |
G_TYPE_OBJECT,
|
sl@0
|
350 |
INTERFACE (NULL, TEST_TYPE_IFACE))
|
sl@0
|
351 |
|
sl@0
|
352 |
static void
|
sl@0
|
353 |
derived_object_set_property (GObject *object,
|
sl@0
|
354 |
guint prop_id,
|
sl@0
|
355 |
const GValue *value,
|
sl@0
|
356 |
GParamSpec *pspec)
|
sl@0
|
357 |
{
|
sl@0
|
358 |
BaseObject *base_object = BASE_OBJECT (object);
|
sl@0
|
359 |
|
sl@0
|
360 |
switch (prop_id)
|
sl@0
|
361 |
{
|
sl@0
|
362 |
case DERIVED_PROP3:
|
sl@0
|
363 |
g_assert (pspec == inherited_spec3);
|
sl@0
|
364 |
base_object->val3 = g_value_get_int (value);
|
sl@0
|
365 |
break;
|
sl@0
|
366 |
case DERIVED_PROP4:
|
sl@0
|
367 |
g_assert (pspec == inherited_spec4);
|
sl@0
|
368 |
base_object->val4 = g_value_get_int (value);
|
sl@0
|
369 |
break;
|
sl@0
|
370 |
default:
|
sl@0
|
371 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
sl@0
|
372 |
break;
|
sl@0
|
373 |
}
|
sl@0
|
374 |
}
|
sl@0
|
375 |
|
sl@0
|
376 |
static void
|
sl@0
|
377 |
derived_object_get_property (GObject *object,
|
sl@0
|
378 |
guint prop_id,
|
sl@0
|
379 |
GValue *value,
|
sl@0
|
380 |
GParamSpec *pspec)
|
sl@0
|
381 |
{
|
sl@0
|
382 |
BaseObject *base_object = BASE_OBJECT (object);
|
sl@0
|
383 |
|
sl@0
|
384 |
switch (prop_id)
|
sl@0
|
385 |
{
|
sl@0
|
386 |
case DERIVED_PROP3:
|
sl@0
|
387 |
g_assert (pspec == inherited_spec3);
|
sl@0
|
388 |
g_value_set_int (value, base_object->val3);
|
sl@0
|
389 |
break;
|
sl@0
|
390 |
case DERIVED_PROP4:
|
sl@0
|
391 |
g_assert (pspec == inherited_spec4);
|
sl@0
|
392 |
g_value_set_int (value, base_object->val4);
|
sl@0
|
393 |
break;
|
sl@0
|
394 |
default:
|
sl@0
|
395 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
sl@0
|
396 |
break;
|
sl@0
|
397 |
}
|
sl@0
|
398 |
}
|
sl@0
|
399 |
|
sl@0
|
400 |
static void
|
sl@0
|
401 |
derived_object_class_init (DerivedObjectClass *class)
|
sl@0
|
402 |
{
|
sl@0
|
403 |
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
sl@0
|
404 |
|
sl@0
|
405 |
object_class->set_property = derived_object_set_property;
|
sl@0
|
406 |
object_class->get_property = derived_object_get_property;
|
sl@0
|
407 |
|
sl@0
|
408 |
/* Overriding a property that is itself overridding an interface property */
|
sl@0
|
409 |
g_object_class_override_property (object_class, DERIVED_PROP3, "prop3");
|
sl@0
|
410 |
|
sl@0
|
411 |
/* Overriding a property not from an interface */
|
sl@0
|
412 |
g_object_class_override_property (object_class, DERIVED_PROP4, "prop4");
|
sl@0
|
413 |
}
|
sl@0
|
414 |
|
sl@0
|
415 |
static DEFINE_TYPE (DerivedObject, derived_object,
|
sl@0
|
416 |
derived_object_class_init, NULL, NULL,
|
sl@0
|
417 |
BASE_TYPE_OBJECT)
|
sl@0
|
418 |
|
sl@0
|
419 |
/* Helper function for testing ...list_properties()
|
sl@0
|
420 |
*/
|
sl@0
|
421 |
static void
|
sl@0
|
422 |
assert_in_properties (GParamSpec *param_spec,
|
sl@0
|
423 |
GParamSpec **properties,
|
sl@0
|
424 |
gint n_properties)
|
sl@0
|
425 |
{
|
sl@0
|
426 |
gint i;
|
sl@0
|
427 |
gboolean found = FALSE;
|
sl@0
|
428 |
|
sl@0
|
429 |
for (i = 0; i < n_properties; i++)
|
sl@0
|
430 |
{
|
sl@0
|
431 |
if (properties[i] == param_spec)
|
sl@0
|
432 |
found = TRUE;
|
sl@0
|
433 |
}
|
sl@0
|
434 |
|
sl@0
|
435 |
g_assert (found);
|
sl@0
|
436 |
}
|
sl@0
|
437 |
/**** Dummy function which does nothing *******/
|
sl@0
|
438 |
gboolean MyFunc (gpointer cache_data,
|
sl@0
|
439 |
GTypeClass *g_class)
|
sl@0
|
440 |
{
|
sl@0
|
441 |
return FALSE;
|
sl@0
|
442 |
};
|
sl@0
|
443 |
|
sl@0
|
444 |
void MyFunc1 (gpointer data,
|
sl@0
|
445 |
GClosure *closure)
|
sl@0
|
446 |
{
|
sl@0
|
447 |
return ;
|
sl@0
|
448 |
}
|
sl@0
|
449 |
|
sl@0
|
450 |
|
sl@0
|
451 |
|
sl@0
|
452 |
int
|
sl@0
|
453 |
main (gint argc,
|
sl@0
|
454 |
gchar *argv[])
|
sl@0
|
455 |
{
|
sl@0
|
456 |
GObject *object, *object1;
|
sl@0
|
457 |
GObjectClass *object_class;
|
sl@0
|
458 |
GParamSpec **properties;
|
sl@0
|
459 |
gpointer p ="Data",p1 = "Data1",ret;
|
sl@0
|
460 |
gchar *str;
|
sl@0
|
461 |
GValue val;
|
sl@0
|
462 |
GParamSpec* paramSpec;
|
sl@0
|
463 |
GParamFlags flags;
|
sl@0
|
464 |
GDestroyNotify destroy;
|
sl@0
|
465 |
gpointer wkPtr= "Weak Pointer";
|
sl@0
|
466 |
GType t;
|
sl@0
|
467 |
GTypeQuery query;
|
sl@0
|
468 |
GTypeClassCacheFunc cache_func = MyFunc;
|
sl@0
|
469 |
GTypeModule module;
|
sl@0
|
470 |
GEnumClass *type_class;
|
sl@0
|
471 |
GEnumValue enum_ret;
|
sl@0
|
472 |
GCallback callback_func;
|
sl@0
|
473 |
GClosure *closure_ret;
|
sl@0
|
474 |
gpointer notify_data= "Notify";
|
sl@0
|
475 |
gpointer notify_data1;
|
sl@0
|
476 |
GClosureNotify notify_func;
|
sl@0
|
477 |
gpointer pre_marshal_data = "MarshalData";
|
sl@0
|
478 |
GClosureNotify pre_marshal_notify;
|
sl@0
|
479 |
gpointer post_marshal_data = "PostMarshal";
|
sl@0
|
480 |
GClosureNotify post_marshal_notify = MyFunc1;
|
sl@0
|
481 |
GFlagsClass *flags_class;
|
sl@0
|
482 |
GFlagsValue* flagValue;
|
sl@0
|
483 |
GTypeModule *module1;
|
sl@0
|
484 |
GSource source;
|
sl@0
|
485 |
gpointer marshal_data;
|
sl@0
|
486 |
gpointer invocation_hint;
|
sl@0
|
487 |
GClosure closure;
|
sl@0
|
488 |
GObject *bar;
|
sl@0
|
489 |
GValue val1 = {0,};
|
sl@0
|
490 |
gpointer user_data= "name";
|
sl@0
|
491 |
GValue args[2];
|
sl@0
|
492 |
GObject *object_set;
|
sl@0
|
493 |
const GEnumValue static_values;
|
sl@0
|
494 |
static const GFlagsValue const_static_values[] = {
|
sl@0
|
495 |
{ G_IO_IN, "G_IO_IN", "in" },
|
sl@0
|
496 |
{ G_IO_OUT, "G_IO_OUT", "out" },
|
sl@0
|
497 |
{ G_IO_PRI, "G_IO_PRI", "pri" },
|
sl@0
|
498 |
{ G_IO_ERR, "G_IO_ERR", "err" },
|
sl@0
|
499 |
{ G_IO_HUP, "G_IO_HUP", "hup" },
|
sl@0
|
500 |
{ G_IO_NVAL, "G_IO_NVAL", "nval" },
|
sl@0
|
501 |
{ 0, NULL, NULL }
|
sl@0
|
502 |
};
|
sl@0
|
503 |
|
sl@0
|
504 |
guint n_properties;
|
sl@0
|
505 |
|
sl@0
|
506 |
gint val2, val3, val4;
|
sl@0
|
507 |
GQuark detail;
|
sl@0
|
508 |
GSignalEmissionHook hook_func;
|
sl@0
|
509 |
gpointer hook_data;
|
sl@0
|
510 |
GDestroyNotify data_destroy;
|
sl@0
|
511 |
|
sl@0
|
512 |
GValue orig = { 0, };
|
sl@0
|
513 |
GValue xform = { 0, };
|
sl@0
|
514 |
GEnumValue values[] = { {0,"0","0"}, {1,"1","1"}};
|
sl@0
|
515 |
|
sl@0
|
516 |
#ifdef SYMBIAN
|
sl@0
|
517 |
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);
|
sl@0
|
518 |
#endif /*SYMBIAN*/
|
sl@0
|
519 |
|
sl@0
|
520 |
g_log_set_always_fatal (g_log_set_always_fatal (G_LOG_FATAL_MASK) |
|
sl@0
|
521 |
G_LOG_LEVEL_WARNING |
|
sl@0
|
522 |
G_LOG_LEVEL_CRITICAL);
|
sl@0
|
523 |
g_type_init ();
|
sl@0
|
524 |
|
sl@0
|
525 |
object = g_object_new (DERIVED_TYPE_OBJECT, NULL);
|
sl@0
|
526 |
|
sl@0
|
527 |
/* Test setting and getting the properties
|
sl@0
|
528 |
*/
|
sl@0
|
529 |
|
sl@0
|
530 |
|
sl@0
|
531 |
memset (&xform, 0, sizeof (GValue));
|
sl@0
|
532 |
g_value_init (&xform, G_TYPE_CHAR);
|
sl@0
|
533 |
|
sl@0
|
534 |
g_object_set_data(object , "Key",p);
|
sl@0
|
535 |
ret = g_object_get_data(object , "Key");
|
sl@0
|
536 |
str = (gchar *)ret;
|
sl@0
|
537 |
g_assert (!strcmp(str , "Data"));
|
sl@0
|
538 |
|
sl@0
|
539 |
g_object_set_data_full (object, "Key1", p1, destroy);
|
sl@0
|
540 |
ret = g_object_get_data(object , "Key1");
|
sl@0
|
541 |
str = (gchar *)ret;
|
sl@0
|
542 |
g_assert (!strcmp(str , "Data1"));
|
sl@0
|
543 |
|
sl@0
|
544 |
g_object_set_qdata (object, 1, p1);
|
sl@0
|
545 |
|
sl@0
|
546 |
g_object_set_qdata_full (object, 1, p1, destroy);
|
sl@0
|
547 |
|
sl@0
|
548 |
ret = g_object_get_qdata (object, 1);
|
sl@0
|
549 |
|
sl@0
|
550 |
str = (gchar *)ret;
|
sl@0
|
551 |
|
sl@0
|
552 |
g_assert (!strcmp(str , "Data1"));
|
sl@0
|
553 |
|
sl@0
|
554 |
ret = g_object_steal_data (object , "Key1");
|
sl@0
|
555 |
|
sl@0
|
556 |
str = (gchar *)ret;
|
sl@0
|
557 |
|
sl@0
|
558 |
g_assert (!strcmp(str , "Data1"));
|
sl@0
|
559 |
|
sl@0
|
560 |
ret = g_object_steal_qdata (object , 1);
|
sl@0
|
561 |
|
sl@0
|
562 |
str = (gchar *)ret;
|
sl@0
|
563 |
|
sl@0
|
564 |
g_assert (!strcmp(str , "Data1"));
|
sl@0
|
565 |
|
sl@0
|
566 |
g_object_run_dispose(object);
|
sl@0
|
567 |
|
sl@0
|
568 |
g_object_add_weak_pointer (object, wkPtr);
|
sl@0
|
569 |
|
sl@0
|
570 |
g_object_remove_weak_pointer(object, wkPtr);
|
sl@0
|
571 |
|
sl@0
|
572 |
g_assert (g_type_qname (G_TYPE_INTERFACE) == 5);
|
sl@0
|
573 |
|
sl@0
|
574 |
g_type_query (G_TYPE_OBJECT, &query);
|
sl@0
|
575 |
|
sl@0
|
576 |
g_assert (query.type == 80);
|
sl@0
|
577 |
|
sl@0
|
578 |
g_type_set_qdata (G_TYPE_OBJECT ,1 , wkPtr);
|
sl@0
|
579 |
|
sl@0
|
580 |
ret = g_type_get_qdata (G_TYPE_OBJECT ,1);
|
sl@0
|
581 |
|
sl@0
|
582 |
str = (gchar *)ret;
|
sl@0
|
583 |
|
sl@0
|
584 |
g_assert (!strcmp(str , "Weak Pointer"));
|
sl@0
|
585 |
|
sl@0
|
586 |
g_type_add_class_cache_func (wkPtr, cache_func);
|
sl@0
|
587 |
|
sl@0
|
588 |
g_type_remove_class_cache_func (wkPtr, cache_func);
|
sl@0
|
589 |
|
sl@0
|
590 |
g_assert (g_type_next_base (G_TYPE_OBJECT, G_TYPE_INT) == 0);
|
sl@0
|
591 |
|
sl@0
|
592 |
type_class = g_type_class_ref (G_TYPE_ENUM);
|
sl@0
|
593 |
|
sl@0
|
594 |
g_assert (g_enum_get_value_by_nick (G_ENUM_CLASS (type_class),"Nick") == NULL) ;
|
sl@0
|
595 |
|
sl@0
|
596 |
g_assert ((g_enum_register_static ("Name", &enum_ret)) != 0);
|
sl@0
|
597 |
|
sl@0
|
598 |
g_assert((g_cclosure_new_object((GCallback)MyFunc1, object)) != NULL);
|
sl@0
|
599 |
|
sl@0
|
600 |
closure_ret = g_closure_new_object(sizeof(GClosure),object);
|
sl@0
|
601 |
|
sl@0
|
602 |
g_assert((g_closure_new_object(sizeof(GClosure),object)) != NULL);
|
sl@0
|
603 |
|
sl@0
|
604 |
g_closure_add_finalize_notifier (closure_ret, notify_data, MyFunc1);
|
sl@0
|
605 |
|
sl@0
|
606 |
g_closure_remove_finalize_notifier (closure_ret, notify_data, MyFunc1);
|
sl@0
|
607 |
|
sl@0
|
608 |
closure_ret->n_guards = 0; //Changed the structure to pass the below api.
|
sl@0
|
609 |
|
sl@0
|
610 |
g_closure_add_marshal_guards (closure_ret, pre_marshal_data, MyFunc1, post_marshal_data, MyFunc1);
|
sl@0
|
611 |
|
sl@0
|
612 |
g_assert(g_pointer_type_register_static ("G_TYPE_OBJECT") != 0);
|
sl@0
|
613 |
|
sl@0
|
614 |
paramSpec = g_param_spec_boolean("String1", "Hello", "World", FALSE, flags);
|
sl@0
|
615 |
|
sl@0
|
616 |
g_assert( !strcmp(paramSpec->name , "String1"));
|
sl@0
|
617 |
|
sl@0
|
618 |
flags_class = g_type_class_ref(G_TYPE_FLAGS);
|
sl@0
|
619 |
|
sl@0
|
620 |
flagValue = g_flags_get_value_by_name (flags_class, "Name");
|
sl@0
|
621 |
|
sl@0
|
622 |
g_assert (flagValue == NULL);
|
sl@0
|
623 |
|
sl@0
|
624 |
flagValue = g_flags_get_value_by_nick (flags_class, "Name");
|
sl@0
|
625 |
|
sl@0
|
626 |
g_assert (flagValue == NULL);
|
sl@0
|
627 |
|
sl@0
|
628 |
object1 = g_object_new (DERIVED_TYPE_OBJECT, NULL);
|
sl@0
|
629 |
|
sl@0
|
630 |
t = g_flags_register_static ("GIOCondition", const_static_values);
|
sl@0
|
631 |
|
sl@0
|
632 |
g_assert (t != 0);
|
sl@0
|
633 |
|
sl@0
|
634 |
ret = g_object_connect (object1, NULL);
|
sl@0
|
635 |
|
sl@0
|
636 |
g_assert (ret != NULL);
|
sl@0
|
637 |
|
sl@0
|
638 |
g_object_disconnect(object1, NULL);
|
sl@0
|
639 |
|
sl@0
|
640 |
paramSpec = g_param_spec_uchar ("papa-number",
|
sl@0
|
641 |
"Papa",
|
sl@0
|
642 |
"Set/Get papa's number",
|
sl@0
|
643 |
0 /* minimum value */,
|
sl@0
|
644 |
10 /* maximum value */,
|
sl@0
|
645 |
2 /* default value */,
|
sl@0
|
646 |
G_PARAM_READWRITE);
|
sl@0
|
647 |
|
sl@0
|
648 |
object_set = G_OBJECT (NULL);
|
sl@0
|
649 |
|
sl@0
|
650 |
g_value_init (&val1, paramSpec->value_type);
|
sl@0
|
651 |
|
sl@0
|
652 |
#if SYMBIAN
|
sl@0
|
653 |
testResultXml("g_test2");
|
sl@0
|
654 |
#endif /* EMULATOR */
|
sl@0
|
655 |
|
sl@0
|
656 |
return 0;
|
sl@0
|
657 |
}
|