1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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>
36 test_param_spec_char (void)
39 GValue value = { 0, };
42 pspec = g_param_spec_char ("char", "nick", "blurb",
43 20, 40, 30, G_PARAM_READWRITE);
45 g_assert (strcmp (g_param_spec_get_name (pspec), "char") == 0);
46 g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0);
47 g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0);
49 g_value_init (&value, G_TYPE_CHAR);
50 g_value_set_char (&value, 30);
52 g_assert (g_param_value_defaults (pspec, &value));
54 g_value_set_char (&value, 0);
55 modified = g_param_value_validate (pspec, &value);
56 g_assert (modified && g_value_get_char (&value) == 20);
58 g_value_set_char (&value, 20);
59 modified = g_param_value_validate (pspec, &value);
60 g_assert (!modified && g_value_get_char (&value) == 20);
62 g_value_set_char (&value, 40);
63 modified = g_param_value_validate (pspec, &value);
64 g_assert (!modified && g_value_get_char (&value) == 40);
66 g_value_set_char (&value, 60);
67 modified = g_param_value_validate (pspec, &value);
68 g_assert (modified && g_value_get_char (&value) == 40);
70 g_param_spec_unref (pspec);
74 test_param_spec_override (void)
76 GParamSpec *ospec, *pspec;
77 GValue value = { 0, };
80 ospec = g_param_spec_char ("char", "nick", "blurb",
81 20, 40, 30, G_PARAM_READWRITE);
83 pspec = g_param_spec_override ("override", ospec);
85 g_assert (strcmp (g_param_spec_get_name (pspec), "override") == 0);
86 g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0);
87 g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0);
89 g_value_init (&value, G_TYPE_CHAR);
90 g_value_set_char (&value, 30);
92 g_assert (g_param_value_defaults (pspec, &value));
94 g_value_set_char (&value, 0);
95 modified = g_param_value_validate (pspec, &value);
96 g_assert (modified && g_value_get_char (&value) == 20);
98 g_value_set_char (&value, 20);
99 modified = g_param_value_validate (pspec, &value);
100 g_assert (!modified && g_value_get_char (&value) == 20);
102 g_value_set_char (&value, 40);
103 modified = g_param_value_validate (pspec, &value);
104 g_assert (!modified && g_value_get_char (&value) == 40);
106 g_value_set_char (&value, 60);
107 modified = g_param_value_validate (pspec, &value);
108 g_assert (modified && g_value_get_char (&value) == 40);
110 g_param_spec_unref (pspec);
114 test_param_spec_gtype (void)
117 GValue value = { 0, };
120 pspec = g_param_spec_gtype ("gtype", "nick", "blurb",
121 G_TYPE_PARAM, G_PARAM_READWRITE);
123 g_value_init (&value, G_TYPE_GTYPE);
124 g_value_set_gtype (&value, G_TYPE_NONE);
126 g_assert (g_param_value_defaults (pspec, &value));
128 g_value_set_gtype (&value, G_TYPE_INT);
129 modified = g_param_value_validate (pspec, &value);
130 g_assert (modified && g_value_get_gtype (&value) == G_TYPE_NONE);
132 g_value_set_gtype (&value, G_TYPE_PARAM_INT);
133 modified = g_param_value_validate (pspec, &value);
134 g_assert (!modified && g_value_get_gtype (&value) == G_TYPE_PARAM_INT);
138 main (int argc, char *argv[])
142 test_param_spec_char ();
143 test_param_spec_override ();
144 test_param_spec_gtype ();