Update contrib.
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). 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>
36 #include "mrt2_glib2_test.h"
37 #include <gobject_global.h>
41 test_param_spec_char (void)
44 GValue value = { 0, };
47 pspec = g_param_spec_char ("char", "nick", "blurb",
48 20, 40, 30, G_PARAM_READWRITE);
50 //g_param_spec_ref_force_floating(pspec);
51 //g_assert(g_param_spec_is_floating(pspec));
52 g_param_spec_ref_sink(pspec);
54 g_assert (strcmp (g_param_spec_get_name (pspec), "char") == 0);
55 g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0);
56 g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0);
58 g_value_init (&value, G_TYPE_CHAR);
59 g_value_set_char (&value, 30);
61 g_assert (g_param_value_defaults (pspec, &value));
63 g_value_set_char (&value, 0);
64 modified = g_param_value_validate (pspec, &value);
65 g_assert (modified && g_value_get_char (&value) == 20);
67 g_value_set_char (&value, 20);
68 modified = g_param_value_validate (pspec, &value);
69 g_assert (!modified && g_value_get_char (&value) == 20);
71 g_value_set_char (&value, 40);
72 modified = g_param_value_validate (pspec, &value);
73 g_assert (!modified && g_value_get_char (&value) == 40);
75 g_value_set_char (&value, 60);
76 modified = g_param_value_validate (pspec, &value);
77 g_assert (modified && g_value_get_char (&value) == 40);
79 g_param_spec_unref (pspec);
83 test_param_spec_override (void)
85 GParamSpec *ospec, *pspec;
86 GValue value = { 0, };
89 ospec = g_param_spec_char ("char", "nick", "blurb",
90 20, 40, 30, G_PARAM_READWRITE);
92 pspec = g_param_spec_override ("override", ospec);
94 g_assert (strcmp (g_param_spec_get_name (pspec), "override") == 0);
95 g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0);
96 g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0);
98 g_value_init (&value, G_TYPE_CHAR);
99 g_value_set_char (&value, 30);
101 g_assert (g_param_value_defaults (pspec, &value));
103 g_value_set_char (&value, 0);
104 modified = g_param_value_validate (pspec, &value);
105 g_assert (modified && g_value_get_char (&value) == 20);
107 g_value_set_char (&value, 20);
108 modified = g_param_value_validate (pspec, &value);
109 g_assert (!modified && g_value_get_char (&value) == 20);
111 g_value_set_char (&value, 40);
112 modified = g_param_value_validate (pspec, &value);
113 g_assert (!modified && g_value_get_char (&value) == 40);
115 g_value_set_char (&value, 60);
116 modified = g_param_value_validate (pspec, &value);
117 g_assert (modified && g_value_get_char (&value) == 40);
119 g_param_spec_unref (pspec);
123 test_param_spec_gtype (void)
126 GValue value = { 0, };
129 pspec = g_param_spec_gtype ("gtype", "nick", "blurb",
130 G_TYPE_PARAM, G_PARAM_READWRITE);
132 g_value_init (&value, G_TYPE_GTYPE);
133 g_value_set_gtype (&value, G_TYPE_PARAM);
135 g_assert (g_param_value_defaults (pspec, &value));
137 g_value_set_gtype (&value, G_TYPE_INT);
138 modified = g_param_value_validate (pspec, &value);
139 g_assert (modified && g_value_get_gtype (&value) == G_TYPE_PARAM);
141 g_value_set_gtype (&value, G_TYPE_PARAM_INT);
142 modified = g_param_value_validate (pspec, &value);
143 g_assert (!modified && g_value_get_gtype (&value) == G_TYPE_PARAM_INT);
147 main (int argc, char *argv[])
150 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);
151 g_set_print_handler(mrtPrintHandler);
155 test_param_spec_char ();
156 test_param_spec_override ();
157 test_param_spec_gtype ();
160 testResultXml("paramspec-test");