Add it here.
[platform/upstream/glib.git] / tests / gobject / gvalue-test.c
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
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
20 /*
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/. 
25  */
26
27 #undef G_DISABLE_ASSERT
28 #undef G_LOG_DOMAIN
29
30 #include <string.h>
31
32 #include <glib.h>
33 #include <glib-object.h>
34
35 static void
36 test_enum_transformation (void)
37
38   GType type; 
39   GValue orig = { 0, };
40   GValue xform = { 0, }; 
41   GEnumValue values[] = { {0,"0","0"}, {1,"1","1"}}; 
42   
43  type = g_enum_register_static ("TestEnum", values); 
44   
45  g_value_init (&orig, type); 
46  g_value_set_enum (&orig, 1); 
47
48  memset (&xform, 0, sizeof (GValue));
49  g_value_init (&xform, G_TYPE_CHAR); 
50  g_value_transform (&orig, &xform); 
51  g_assert (g_value_get_char (&xform) == 1);
52
53  memset (&xform, 0, sizeof (GValue));
54  g_value_init (&xform, G_TYPE_UCHAR); 
55  g_value_transform (&orig, &xform); 
56  g_assert (g_value_get_uchar (&xform) == 1);
57
58  memset (&xform, 0, sizeof (GValue));
59  g_value_init (&xform, G_TYPE_INT); 
60  g_value_transform (&orig, &xform); 
61  g_assert (g_value_get_int (&xform) == 1);
62
63  memset (&xform, 0, sizeof (GValue));
64  g_value_init (&xform, G_TYPE_UINT); 
65  g_value_transform (&orig, &xform); 
66  g_assert (g_value_get_uint (&xform) == 1);
67
68  memset (&xform, 0, sizeof (GValue));
69  g_value_init (&xform, G_TYPE_LONG); 
70  g_value_transform (&orig, &xform); 
71  g_assert (g_value_get_long (&xform) == 1);
72
73  memset (&xform, 0, sizeof (GValue));
74  g_value_init (&xform, G_TYPE_ULONG); 
75  g_value_transform (&orig, &xform); 
76  g_assert (g_value_get_ulong (&xform) == 1);
77
78  memset (&xform, 0, sizeof (GValue));
79  g_value_init (&xform, G_TYPE_INT64); 
80  g_value_transform (&orig, &xform); 
81  g_assert (g_value_get_int64 (&xform) == 1);
82
83  memset (&xform, 0, sizeof (GValue));
84  g_value_init (&xform, G_TYPE_UINT64); 
85  g_value_transform (&orig, &xform); 
86  g_assert (g_value_get_uint64 (&xform) == 1);
87 }
88
89 int
90 main (int argc, char *argv[])
91 {
92   g_type_init (); 
93   
94   test_enum_transformation ();
95
96   return 0;
97 }