|
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. |
|
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 #ifdef __SYMBIAN32__ |
|
36 #include <gobject_global.h> |
|
37 #include "mrt2_glib2_test.h" |
|
38 #endif //__SYMBIAN32__ |
|
39 static void |
|
40 test_param_spec_char (void) |
|
41 { |
|
42 GParamSpec *pspec; |
|
43 GValue value = { 0, }; |
|
44 gboolean modified; |
|
45 |
|
46 pspec = g_param_spec_char ("char", "nick", "blurb", |
|
47 20, 40, 30, G_PARAM_READWRITE); |
|
48 |
|
49 g_assert (strcmp (g_param_spec_get_name (pspec), "char") == 0); |
|
50 g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0); |
|
51 g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0); |
|
52 |
|
53 g_value_init (&value, G_TYPE_CHAR); |
|
54 g_value_set_char (&value, 30); |
|
55 |
|
56 g_assert (g_param_value_defaults (pspec, &value)); |
|
57 |
|
58 g_value_set_char (&value, 0); |
|
59 modified = g_param_value_validate (pspec, &value); |
|
60 g_assert (modified && g_value_get_char (&value) == 20); |
|
61 |
|
62 g_value_set_char (&value, 20); |
|
63 modified = g_param_value_validate (pspec, &value); |
|
64 g_assert (!modified && g_value_get_char (&value) == 20); |
|
65 |
|
66 g_value_set_char (&value, 40); |
|
67 modified = g_param_value_validate (pspec, &value); |
|
68 g_assert (!modified && g_value_get_char (&value) == 40); |
|
69 |
|
70 g_value_set_char (&value, 60); |
|
71 modified = g_param_value_validate (pspec, &value); |
|
72 g_assert (modified && g_value_get_char (&value) == 40); |
|
73 |
|
74 g_param_spec_unref (pspec); |
|
75 } |
|
76 |
|
77 static void |
|
78 test_param_spec_string (void) |
|
79 { |
|
80 GParamSpec *pspec; |
|
81 GValue value = { 0, }; |
|
82 gboolean modified; |
|
83 |
|
84 pspec = g_param_spec_string ("string", "nick", "blurb", |
|
85 NULL, G_PARAM_READWRITE); |
|
86 g_value_init (&value, G_TYPE_STRING); |
|
87 |
|
88 g_value_set_string (&value, "foobar"); |
|
89 modified = g_param_value_validate (pspec, &value); |
|
90 g_assert (!modified); |
|
91 |
|
92 g_value_set_string (&value, ""); |
|
93 modified = g_param_value_validate (pspec, &value); |
|
94 g_assert (!modified && g_value_get_string (&value) != NULL); |
|
95 |
|
96 /* test ensure_non_null */ |
|
97 |
|
98 G_PARAM_SPEC_STRING (pspec)->ensure_non_null = TRUE; |
|
99 |
|
100 g_value_set_string (&value, NULL); |
|
101 modified = g_param_value_validate (pspec, &value); |
|
102 g_assert (modified && g_value_get_string (&value) != NULL); |
|
103 |
|
104 G_PARAM_SPEC_STRING (pspec)->ensure_non_null = FALSE; |
|
105 |
|
106 /* test null_fold_if_empty */ |
|
107 |
|
108 G_PARAM_SPEC_STRING (pspec)->null_fold_if_empty = TRUE; |
|
109 |
|
110 g_value_set_string (&value, ""); |
|
111 modified = g_param_value_validate (pspec, &value); |
|
112 g_assert (modified && g_value_get_string (&value) == NULL); |
|
113 |
|
114 g_value_set_static_string (&value, ""); |
|
115 modified = g_param_value_validate (pspec, &value); |
|
116 g_assert (modified && g_value_get_string (&value) == NULL); |
|
117 |
|
118 G_PARAM_SPEC_STRING (pspec)->null_fold_if_empty = FALSE; |
|
119 |
|
120 /* test cset_first */ |
|
121 |
|
122 G_PARAM_SPEC_STRING (pspec)->cset_first = g_strdup ("abc"); |
|
123 G_PARAM_SPEC_STRING (pspec)->substitutor = '-'; |
|
124 |
|
125 g_value_set_string (&value, "ABC"); |
|
126 modified = g_param_value_validate (pspec, &value); |
|
127 g_assert (modified && g_value_get_string (&value)[0] == '-'); |
|
128 |
|
129 g_value_set_static_string (&value, "ABC"); |
|
130 modified = g_param_value_validate (pspec, &value); |
|
131 g_assert (modified && g_value_get_string (&value)[0] == '-'); |
|
132 |
|
133 /* test cset_nth */ |
|
134 |
|
135 G_PARAM_SPEC_STRING (pspec)->cset_nth = g_strdup ("abc"); |
|
136 |
|
137 g_value_set_string (&value, "aBC"); |
|
138 modified = g_param_value_validate (pspec, &value); |
|
139 g_assert (modified && g_value_get_string (&value)[1] == '-'); |
|
140 |
|
141 g_value_set_static_string (&value, "aBC"); |
|
142 modified = g_param_value_validate (pspec, &value); |
|
143 g_assert (modified && g_value_get_string (&value)[1] == '-'); |
|
144 |
|
145 g_value_unset (&value); |
|
146 g_param_spec_unref (pspec); |
|
147 } |
|
148 |
|
149 static void |
|
150 test_param_spec_override (void) |
|
151 { |
|
152 GParamSpec *ospec, *pspec; |
|
153 GValue value = { 0, }; |
|
154 gboolean modified; |
|
155 |
|
156 ospec = g_param_spec_char ("char", "nick", "blurb", |
|
157 20, 40, 30, G_PARAM_READWRITE); |
|
158 |
|
159 pspec = g_param_spec_override ("override", ospec); |
|
160 |
|
161 g_assert (strcmp (g_param_spec_get_name (pspec), "override") == 0); |
|
162 g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0); |
|
163 g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0); |
|
164 |
|
165 g_value_init (&value, G_TYPE_CHAR); |
|
166 g_value_set_char (&value, 30); |
|
167 |
|
168 g_assert (g_param_value_defaults (pspec, &value)); |
|
169 |
|
170 g_value_set_char (&value, 0); |
|
171 modified = g_param_value_validate (pspec, &value); |
|
172 g_assert (modified && g_value_get_char (&value) == 20); |
|
173 |
|
174 g_value_set_char (&value, 20); |
|
175 modified = g_param_value_validate (pspec, &value); |
|
176 g_assert (!modified && g_value_get_char (&value) == 20); |
|
177 |
|
178 g_value_set_char (&value, 40); |
|
179 modified = g_param_value_validate (pspec, &value); |
|
180 g_assert (!modified && g_value_get_char (&value) == 40); |
|
181 |
|
182 g_value_set_char (&value, 60); |
|
183 modified = g_param_value_validate (pspec, &value); |
|
184 g_assert (modified && g_value_get_char (&value) == 40); |
|
185 |
|
186 g_param_spec_unref (pspec); |
|
187 } |
|
188 |
|
189 static void |
|
190 test_param_spec_gtype (void) |
|
191 { |
|
192 GParamSpec *pspec; |
|
193 GValue value = { 0, }; |
|
194 gboolean modified; |
|
195 |
|
196 pspec = g_param_spec_gtype ("gtype", "nick", "blurb", |
|
197 G_TYPE_PARAM, G_PARAM_READWRITE); |
|
198 |
|
199 g_value_init (&value, G_TYPE_GTYPE); |
|
200 g_value_set_gtype (&value, G_TYPE_PARAM); |
|
201 |
|
202 g_assert (g_param_value_defaults (pspec, &value)); |
|
203 |
|
204 g_value_set_gtype (&value, G_TYPE_INT); |
|
205 modified = g_param_value_validate (pspec, &value); |
|
206 g_assert (modified && g_value_get_gtype (&value) == G_TYPE_PARAM); |
|
207 |
|
208 g_value_set_gtype (&value, G_TYPE_PARAM_INT); |
|
209 modified = g_param_value_validate (pspec, &value); |
|
210 g_assert (!modified && g_value_get_gtype (&value) == G_TYPE_PARAM_INT); |
|
211 } |
|
212 |
|
213 int |
|
214 main (int argc, char *argv[]) |
|
215 { |
|
216 #ifdef __SYMBIAN32__ |
|
217 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); |
|
218 g_set_print_handler(mrtPrintHandler); |
|
219 #endif /*__SYMBIAN32__*/ |
|
220 g_type_init (); |
|
221 |
|
222 test_param_spec_char (); |
|
223 test_param_spec_string (); |
|
224 test_param_spec_override (); |
|
225 test_param_spec_gtype (); |
|
226 |
|
227 #ifdef __SYMBIAN32__ |
|
228 testResultXml("paramspec-test"); |
|
229 #endif /*__SYMBIAN32__*/ |
|
230 return 0; |
|
231 } |