sl@0: /* GLIB - Library of useful routines for C programming sl@0: * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald sl@0: * Portions copyright (c) 2006-2009 Nokia Corporation. All rights reserved. sl@0: * This library is free software; you can redistribute it and/or sl@0: * modify it under the terms of the GNU Lesser General Public sl@0: * License as published by the Free Software Foundation; either sl@0: * version 2 of the License, or (at your option) any later version. sl@0: * sl@0: * This library is distributed in the hope that it will be useful, sl@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of sl@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU sl@0: * Lesser General Public License for more details. sl@0: * sl@0: * You should have received a copy of the GNU Lesser General Public sl@0: * License along with this library; if not, write to the sl@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, sl@0: * Boston, MA 02111-1307, USA. sl@0: */ sl@0: sl@0: /* sl@0: * Modified by the GLib Team and others 1997-2000. See the AUTHORS sl@0: * file for a list of people on the GLib Team. See the ChangeLog sl@0: * files for a list of changes. These files are distributed with sl@0: * GLib at ftp://ftp.gtk.org/pub/gtk/. sl@0: */ sl@0: sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include "gobject/gvaluecollector.h" sl@0: #ifdef __SYMBIAN32__ sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*__SYMBIAN32__*/ sl@0: sl@0: static void sl@0: test_enum_transformation (void) sl@0: { sl@0: GType type; sl@0: GValue orig = { 0, }; sl@0: GValue xform = { 0, }; sl@0: GEnumValue values[] = { {0,"0","0"}, {1,"1","1"}}; sl@0: sl@0: type = g_enum_register_static ("TestEnum", values); sl@0: sl@0: g_value_init (&orig, type); sl@0: g_value_set_enum (&orig, 1); sl@0: sl@0: memset (&xform, 0, sizeof (GValue)); sl@0: g_value_init (&xform, G_TYPE_CHAR); sl@0: g_value_transform (&orig, &xform); sl@0: g_assert (g_value_get_char (&xform) == 1); sl@0: sl@0: memset (&xform, 0, sizeof (GValue)); sl@0: g_value_init (&xform, G_TYPE_UCHAR); sl@0: g_value_transform (&orig, &xform); sl@0: g_assert (g_value_get_uchar (&xform) == 1); sl@0: sl@0: memset (&xform, 0, sizeof (GValue)); sl@0: g_value_init (&xform, G_TYPE_INT); sl@0: g_value_transform (&orig, &xform); sl@0: g_assert (g_value_get_int (&xform) == 1); sl@0: sl@0: memset (&xform, 0, sizeof (GValue)); sl@0: g_value_init (&xform, G_TYPE_UINT); sl@0: g_value_transform (&orig, &xform); sl@0: g_assert (g_value_get_uint (&xform) == 1); sl@0: sl@0: memset (&xform, 0, sizeof (GValue)); sl@0: g_value_init (&xform, G_TYPE_LONG); sl@0: g_value_transform (&orig, &xform); sl@0: g_assert (g_value_get_long (&xform) == 1); sl@0: sl@0: memset (&xform, 0, sizeof (GValue)); sl@0: g_value_init (&xform, G_TYPE_ULONG); sl@0: g_value_transform (&orig, &xform); sl@0: g_assert (g_value_get_ulong (&xform) == 1); sl@0: sl@0: memset (&xform, 0, sizeof (GValue)); sl@0: g_value_init (&xform, G_TYPE_INT64); sl@0: g_value_transform (&orig, &xform); sl@0: g_assert (g_value_get_int64 (&xform) == 1); sl@0: sl@0: memset (&xform, 0, sizeof (GValue)); sl@0: g_value_init (&xform, G_TYPE_UINT64); sl@0: g_value_transform (&orig, &xform); sl@0: g_assert (g_value_get_uint64 (&xform) == 1); sl@0: } sl@0: sl@0: sl@0: static void sl@0: test_gtype_value (void) sl@0: { sl@0: GType type; sl@0: GValue value = { 0, }; sl@0: GValue copy = { 0, }; sl@0: sl@0: g_value_init (&value, G_TYPE_GTYPE); sl@0: sl@0: g_value_set_gtype (&value, G_TYPE_BOXED); sl@0: type = g_value_get_gtype (&value); sl@0: g_assert (type == G_TYPE_BOXED); sl@0: sl@0: g_value_init (©, G_TYPE_GTYPE); sl@0: g_value_copy (&value, ©); sl@0: type = g_value_get_gtype (©); sl@0: g_assert (type == G_TYPE_BOXED); sl@0: } sl@0: sl@0: static gchar * sl@0: collect (GValue *value, ...) sl@0: { sl@0: gchar *error; sl@0: va_list var_args; sl@0: sl@0: error = NULL; sl@0: sl@0: va_start (var_args, value); sl@0: G_VALUE_COLLECT (value, var_args, 0, &error); sl@0: va_end (var_args); sl@0: sl@0: return error; sl@0: } sl@0: sl@0: static gchar * sl@0: lcopy (GValue *value, ...) sl@0: { sl@0: gchar *error; sl@0: va_list var_args; sl@0: sl@0: error = NULL; sl@0: sl@0: va_start (var_args, value); sl@0: G_VALUE_LCOPY (value, var_args, 0, &error); sl@0: va_end (var_args); sl@0: sl@0: return error; sl@0: } sl@0: sl@0: static void sl@0: test_collection (void) sl@0: { sl@0: GValue value = { 0, }; sl@0: gchar *error; sl@0: sl@0: g_value_init (&value, G_TYPE_CHAR); sl@0: error = collect (&value, 'c'); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_char (&value) == 'c'); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_UCHAR); sl@0: error = collect (&value, 129); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_uchar (&value) == 129); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_BOOLEAN); sl@0: error = collect (&value, TRUE); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_boolean (&value) == TRUE); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_INT); sl@0: error = collect (&value, G_MAXINT); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_int (&value) == G_MAXINT); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_UINT); sl@0: error = collect (&value, G_MAXUINT); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_uint (&value) == G_MAXUINT); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_LONG); sl@0: error = collect (&value, G_MAXLONG); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_long (&value) == G_MAXLONG); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_ULONG); sl@0: error = collect (&value, G_MAXULONG); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_ulong (&value) == G_MAXULONG); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_INT64); sl@0: error = collect (&value, G_MAXINT64); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_int64 (&value) == G_MAXINT64); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_UINT64); sl@0: error = collect (&value, G_MAXUINT64); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_uint64 (&value) == G_MAXUINT64); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_FLOAT); sl@0: error = collect (&value, G_MAXFLOAT); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_float (&value) == G_MAXFLOAT); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_DOUBLE); sl@0: error = collect (&value, G_MAXDOUBLE); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_double (&value) == G_MAXDOUBLE); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_STRING); sl@0: error = collect (&value, "string ?"); sl@0: g_assert (error == NULL); sl@0: g_assert (strcmp (g_value_get_string (&value), "string ?") == 0); sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_GTYPE); sl@0: error = collect (&value, G_TYPE_BOXED); sl@0: g_assert (error == NULL); sl@0: g_assert (g_value_get_gtype (&value) == G_TYPE_BOXED); sl@0: } sl@0: sl@0: static void sl@0: test_copying (void) sl@0: { sl@0: GValue value = { 0, }; sl@0: gchar *error; sl@0: sl@0: { sl@0: gchar c = 0; sl@0: sl@0: g_value_init (&value, G_TYPE_CHAR); sl@0: g_value_set_char (&value, 'c'); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (c == 'c'); sl@0: } sl@0: sl@0: { sl@0: guchar c = 0; sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_UCHAR); sl@0: g_value_set_uchar (&value, 129); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (c == 129); sl@0: } sl@0: sl@0: { sl@0: gint c = 0; sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_INT); sl@0: g_value_set_int (&value, G_MAXINT); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (c == G_MAXINT); sl@0: } sl@0: sl@0: { sl@0: guint c = 0; sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_UINT); sl@0: g_value_set_uint (&value, G_MAXUINT); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (c == G_MAXUINT); sl@0: } sl@0: sl@0: { sl@0: glong c = 0; sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_LONG); sl@0: g_value_set_long (&value, G_MAXLONG); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (c == G_MAXLONG); sl@0: } sl@0: sl@0: { sl@0: gulong c = 0; sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_ULONG); sl@0: g_value_set_ulong (&value, G_MAXULONG); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (c == G_MAXULONG); sl@0: } sl@0: sl@0: { sl@0: gint64 c = 0; sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_INT64); sl@0: g_value_set_int64 (&value, G_MAXINT64); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (c == G_MAXINT64); sl@0: } sl@0: sl@0: { sl@0: guint64 c = 0; sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_UINT64); sl@0: g_value_set_uint64 (&value, G_MAXUINT64); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (c == G_MAXUINT64); sl@0: } sl@0: sl@0: { sl@0: gfloat c = 0; sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_FLOAT); sl@0: g_value_set_float (&value, G_MAXFLOAT); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (c == G_MAXFLOAT); sl@0: } sl@0: sl@0: { sl@0: gdouble c = 0; sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_DOUBLE); sl@0: g_value_set_double (&value, G_MAXDOUBLE); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (c == G_MAXDOUBLE); sl@0: } sl@0: sl@0: { sl@0: gchar *c = NULL; sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_STRING); sl@0: g_value_set_string (&value, "string ?"); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (strcmp (c, "string ?") == 0); sl@0: } sl@0: sl@0: { sl@0: GType c = G_TYPE_NONE; sl@0: sl@0: g_value_unset (&value); sl@0: g_value_init (&value, G_TYPE_GTYPE); sl@0: g_value_set_gtype (&value, G_TYPE_BOXED); sl@0: error = lcopy (&value, &c); sl@0: g_assert (error == NULL); sl@0: g_assert (c == G_TYPE_BOXED); sl@0: } sl@0: } sl@0: sl@0: sl@0: int sl@0: main (int argc, char *argv[]) sl@0: { sl@0: #ifdef __SYMBIAN32__ sl@0: sl@0: 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: g_set_print_handler(mrtPrintHandler); sl@0: #endif /*__SYMBIAN32__*/ sl@0: g_type_init (); sl@0: sl@0: test_enum_transformation (); sl@0: test_gtype_value (); sl@0: test_collection (); sl@0: test_copying (); sl@0: #if __SYMBIAN32__ sl@0: testResultXml("gvalue-test"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: return 0; sl@0: }