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