Update contrib.
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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 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.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
27 #undef G_DISABLE_ASSERT
33 #include <glib-object.h>
34 #include "gobject/gvaluecollector.h"
36 #include "mrt2_glib2_test.h"
37 #endif /*__SYMBIAN32__*/
40 test_enum_transformation (void)
44 GValue xform = { 0, };
45 GEnumValue values[] = { {0,"0","0"}, {1,"1","1"}};
47 type = g_enum_register_static ("TestEnum", values);
49 g_value_init (&orig, type);
50 g_value_set_enum (&orig, 1);
52 memset (&xform, 0, sizeof (GValue));
53 g_value_init (&xform, G_TYPE_CHAR);
54 g_value_transform (&orig, &xform);
55 g_assert (g_value_get_char (&xform) == 1);
57 memset (&xform, 0, sizeof (GValue));
58 g_value_init (&xform, G_TYPE_UCHAR);
59 g_value_transform (&orig, &xform);
60 g_assert (g_value_get_uchar (&xform) == 1);
62 memset (&xform, 0, sizeof (GValue));
63 g_value_init (&xform, G_TYPE_INT);
64 g_value_transform (&orig, &xform);
65 g_assert (g_value_get_int (&xform) == 1);
67 memset (&xform, 0, sizeof (GValue));
68 g_value_init (&xform, G_TYPE_UINT);
69 g_value_transform (&orig, &xform);
70 g_assert (g_value_get_uint (&xform) == 1);
72 memset (&xform, 0, sizeof (GValue));
73 g_value_init (&xform, G_TYPE_LONG);
74 g_value_transform (&orig, &xform);
75 g_assert (g_value_get_long (&xform) == 1);
77 memset (&xform, 0, sizeof (GValue));
78 g_value_init (&xform, G_TYPE_ULONG);
79 g_value_transform (&orig, &xform);
80 g_assert (g_value_get_ulong (&xform) == 1);
82 memset (&xform, 0, sizeof (GValue));
83 g_value_init (&xform, G_TYPE_INT64);
84 g_value_transform (&orig, &xform);
85 g_assert (g_value_get_int64 (&xform) == 1);
87 memset (&xform, 0, sizeof (GValue));
88 g_value_init (&xform, G_TYPE_UINT64);
89 g_value_transform (&orig, &xform);
90 g_assert (g_value_get_uint64 (&xform) == 1);
95 test_gtype_value (void)
98 GValue value = { 0, };
101 g_value_init (&value, G_TYPE_GTYPE);
103 g_value_set_gtype (&value, G_TYPE_BOXED);
104 type = g_value_get_gtype (&value);
105 g_assert (type == G_TYPE_BOXED);
107 g_value_init (©, G_TYPE_GTYPE);
108 g_value_copy (&value, ©);
109 type = g_value_get_gtype (©);
110 g_assert (type == G_TYPE_BOXED);
114 collect (GValue *value, ...)
121 va_start (var_args, value);
122 G_VALUE_COLLECT (value, var_args, 0, &error);
129 lcopy (GValue *value, ...)
136 va_start (var_args, value);
137 G_VALUE_LCOPY (value, var_args, 0, &error);
144 test_collection (void)
146 GValue value = { 0, };
149 g_value_init (&value, G_TYPE_CHAR);
150 error = collect (&value, 'c');
151 g_assert (error == NULL);
152 g_assert (g_value_get_char (&value) == 'c');
154 g_value_unset (&value);
155 g_value_init (&value, G_TYPE_UCHAR);
156 error = collect (&value, 129);
157 g_assert (error == NULL);
158 g_assert (g_value_get_uchar (&value) == 129);
160 g_value_unset (&value);
161 g_value_init (&value, G_TYPE_BOOLEAN);
162 error = collect (&value, TRUE);
163 g_assert (error == NULL);
164 g_assert (g_value_get_boolean (&value) == TRUE);
166 g_value_unset (&value);
167 g_value_init (&value, G_TYPE_INT);
168 error = collect (&value, G_MAXINT);
169 g_assert (error == NULL);
170 g_assert (g_value_get_int (&value) == G_MAXINT);
172 g_value_unset (&value);
173 g_value_init (&value, G_TYPE_UINT);
174 error = collect (&value, G_MAXUINT);
175 g_assert (error == NULL);
176 g_assert (g_value_get_uint (&value) == G_MAXUINT);
178 g_value_unset (&value);
179 g_value_init (&value, G_TYPE_LONG);
180 error = collect (&value, G_MAXLONG);
181 g_assert (error == NULL);
182 g_assert (g_value_get_long (&value) == G_MAXLONG);
184 g_value_unset (&value);
185 g_value_init (&value, G_TYPE_ULONG);
186 error = collect (&value, G_MAXULONG);
187 g_assert (error == NULL);
188 g_assert (g_value_get_ulong (&value) == G_MAXULONG);
190 g_value_unset (&value);
191 g_value_init (&value, G_TYPE_INT64);
192 error = collect (&value, G_MAXINT64);
193 g_assert (error == NULL);
194 g_assert (g_value_get_int64 (&value) == G_MAXINT64);
196 g_value_unset (&value);
197 g_value_init (&value, G_TYPE_UINT64);
198 error = collect (&value, G_MAXUINT64);
199 g_assert (error == NULL);
200 g_assert (g_value_get_uint64 (&value) == G_MAXUINT64);
202 g_value_unset (&value);
203 g_value_init (&value, G_TYPE_FLOAT);
204 error = collect (&value, G_MAXFLOAT);
205 g_assert (error == NULL);
206 g_assert (g_value_get_float (&value) == G_MAXFLOAT);
208 g_value_unset (&value);
209 g_value_init (&value, G_TYPE_DOUBLE);
210 error = collect (&value, G_MAXDOUBLE);
211 g_assert (error == NULL);
212 g_assert (g_value_get_double (&value) == G_MAXDOUBLE);
214 g_value_unset (&value);
215 g_value_init (&value, G_TYPE_STRING);
216 error = collect (&value, "string ?");
217 g_assert (error == NULL);
218 g_assert (strcmp (g_value_get_string (&value), "string ?") == 0);
220 g_value_unset (&value);
221 g_value_init (&value, G_TYPE_GTYPE);
222 error = collect (&value, G_TYPE_BOXED);
223 g_assert (error == NULL);
224 g_assert (g_value_get_gtype (&value) == G_TYPE_BOXED);
230 GValue value = { 0, };
236 g_value_init (&value, G_TYPE_CHAR);
237 g_value_set_char (&value, 'c');
238 error = lcopy (&value, &c);
239 g_assert (error == NULL);
246 g_value_unset (&value);
247 g_value_init (&value, G_TYPE_UCHAR);
248 g_value_set_uchar (&value, 129);
249 error = lcopy (&value, &c);
250 g_assert (error == NULL);
257 g_value_unset (&value);
258 g_value_init (&value, G_TYPE_INT);
259 g_value_set_int (&value, G_MAXINT);
260 error = lcopy (&value, &c);
261 g_assert (error == NULL);
262 g_assert (c == G_MAXINT);
268 g_value_unset (&value);
269 g_value_init (&value, G_TYPE_UINT);
270 g_value_set_uint (&value, G_MAXUINT);
271 error = lcopy (&value, &c);
272 g_assert (error == NULL);
273 g_assert (c == G_MAXUINT);
279 g_value_unset (&value);
280 g_value_init (&value, G_TYPE_LONG);
281 g_value_set_long (&value, G_MAXLONG);
282 error = lcopy (&value, &c);
283 g_assert (error == NULL);
284 g_assert (c == G_MAXLONG);
290 g_value_unset (&value);
291 g_value_init (&value, G_TYPE_ULONG);
292 g_value_set_ulong (&value, G_MAXULONG);
293 error = lcopy (&value, &c);
294 g_assert (error == NULL);
295 g_assert (c == G_MAXULONG);
301 g_value_unset (&value);
302 g_value_init (&value, G_TYPE_INT64);
303 g_value_set_int64 (&value, G_MAXINT64);
304 error = lcopy (&value, &c);
305 g_assert (error == NULL);
306 g_assert (c == G_MAXINT64);
312 g_value_unset (&value);
313 g_value_init (&value, G_TYPE_UINT64);
314 g_value_set_uint64 (&value, G_MAXUINT64);
315 error = lcopy (&value, &c);
316 g_assert (error == NULL);
317 g_assert (c == G_MAXUINT64);
323 g_value_unset (&value);
324 g_value_init (&value, G_TYPE_FLOAT);
325 g_value_set_float (&value, G_MAXFLOAT);
326 error = lcopy (&value, &c);
327 g_assert (error == NULL);
328 g_assert (c == G_MAXFLOAT);
334 g_value_unset (&value);
335 g_value_init (&value, G_TYPE_DOUBLE);
336 g_value_set_double (&value, G_MAXDOUBLE);
337 error = lcopy (&value, &c);
338 g_assert (error == NULL);
339 g_assert (c == G_MAXDOUBLE);
345 g_value_unset (&value);
346 g_value_init (&value, G_TYPE_STRING);
347 g_value_set_string (&value, "string ?");
348 error = lcopy (&value, &c);
349 g_assert (error == NULL);
350 g_assert (strcmp (c, "string ?") == 0);
354 GType c = G_TYPE_NONE;
356 g_value_unset (&value);
357 g_value_init (&value, G_TYPE_GTYPE);
358 g_value_set_gtype (&value, G_TYPE_BOXED);
359 error = lcopy (&value, &c);
360 g_assert (error == NULL);
361 g_assert (c == G_TYPE_BOXED);
367 main (int argc, char *argv[])
371 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);
372 g_set_print_handler(mrtPrintHandler);
373 #endif /*__SYMBIAN32__*/
376 test_enum_transformation ();
381 testResultXml("gvalue-test");
382 #endif /* EMULATOR */