1 /* Gtk+ default value tests
2 * Copyright (C) 2007 Christian Persch
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 #include <gtk/gtkunixprint.h>
24 check_property (const char *output,
28 GValue default_value = G_VALUE_INIT;
31 if (g_param_value_defaults (pspec, value))
34 g_value_init (&default_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
35 g_param_value_set_default (pspec, &default_value);
37 v = g_strdup_value_contents (value);
38 dv = g_strdup_value_contents (&default_value);
40 msg = g_strdup_printf ("%s %s.%s: %s != %s\n",
42 g_type_name (pspec->owner_type),
45 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
51 g_value_unset (&default_value);
55 test_type (gconstpointer data)
63 type = * (GType *) data;
65 if (!G_TYPE_IS_CLASSED (type))
68 if (G_TYPE_IS_ABSTRACT (type))
71 if (!g_type_is_a (type, G_TYPE_OBJECT))
74 /* These can't be freely constructed/destroyed */
75 if (g_type_is_a (type, GTK_TYPE_PRINT_JOB) ||
76 g_type_is_a (type, GTK_TYPE_APPLICATION) ||
77 g_type_is_a (type, GDK_TYPE_PIXBUF_LOADER) ||
78 g_type_is_a (type, gdk_pixbuf_simple_anim_iter_get_type ()))
81 klass = g_type_class_ref (type);
83 if (g_type_is_a (type, GTK_TYPE_SETTINGS))
84 instance = g_object_ref (gtk_settings_get_default ());
85 else if (g_type_is_a (type, GDK_TYPE_WINDOW))
87 GdkWindowAttr attributes;
88 attributes.window_type = GDK_WINDOW_TEMP;
89 attributes.event_mask = 0;
90 attributes.width = 100;
91 attributes.height = 100;
92 instance = g_object_ref (gdk_window_new (NULL, &attributes, 0));
95 instance = g_object_new (type, NULL);
97 if (g_type_is_a (type, G_TYPE_INITIALLY_UNOWNED))
98 g_object_ref_sink (instance);
100 pspecs = g_object_class_list_properties (klass, &n_pspecs);
101 for (i = 0; i < n_pspecs; ++i)
103 GParamSpec *pspec = pspecs[i];
104 GValue value = G_VALUE_INIT;
106 if (pspec->owner_type != type)
109 if ((pspec->flags & G_PARAM_READABLE) == 0)
112 if (g_type_is_a (type, GDK_TYPE_DISPLAY_MANAGER) &&
113 (strcmp (pspec->name, "default-display") == 0))
116 if (g_type_is_a (type, GTK_TYPE_ABOUT_DIALOG) &&
117 (strcmp (pspec->name, "program-name") == 0))
120 /* These are set to the current date */
121 if (g_type_is_a (type, GTK_TYPE_CALENDAR) &&
122 (strcmp (pspec->name, "year") == 0 ||
123 strcmp (pspec->name, "month") == 0 ||
124 strcmp (pspec->name, "day") == 0))
127 if (g_type_is_a (type, GTK_TYPE_CELL_RENDERER_TEXT) &&
128 (strcmp (pspec->name, "background-gdk") == 0 ||
129 strcmp (pspec->name, "foreground-gdk") == 0 ||
130 strcmp (pspec->name, "font") == 0 ||
131 strcmp (pspec->name, "font-desc") == 0))
134 if (g_type_is_a (type, GTK_TYPE_CELL_VIEW) &&
135 (strcmp (pspec->name, "background-gdk") == 0 ||
136 strcmp (pspec->name, "foreground-gdk") == 0))
139 if (g_type_is_a (type, GTK_TYPE_COLOR_BUTTON) &&
140 strcmp (pspec->name, "color") == 0)
143 if (g_type_is_a (type, GTK_TYPE_COLOR_SELECTION) &&
144 strcmp (pspec->name, "current-color") == 0)
147 if (g_type_is_a (type, GTK_TYPE_COLOR_SELECTION_DIALOG) &&
148 (strcmp (pspec->name, "color-selection") == 0 ||
149 strcmp (pspec->name, "ok-button") == 0 ||
150 strcmp (pspec->name, "help-button") == 0 ||
151 strcmp (pspec->name, "cancel-button") == 0))
154 /* Default invisible char is determined at runtime */
155 if (g_type_is_a (type, GTK_TYPE_ENTRY) &&
156 (strcmp (pspec->name, "invisible-char") == 0 ||
157 strcmp (pspec->name, "buffer") == 0))
160 if (g_type_is_a (type, GTK_TYPE_FONT_SELECTION) &&
161 strcmp (pspec->name, "font") == 0)
164 if (g_type_is_a (type, GTK_TYPE_LAYOUT) &&
165 (strcmp (pspec->name, "hadjustment") == 0 ||
166 strcmp (pspec->name, "vadjustment") == 0))
169 if (g_type_is_a (type, GTK_TYPE_MESSAGE_DIALOG) &&
170 (strcmp (pspec->name, "image") == 0 ||
171 strcmp (pspec->name, "message-area") == 0))
174 if (g_type_is_a (type, GTK_TYPE_PANED) &&
175 strcmp (pspec->name, "max-position") == 0)
178 if (g_type_is_a (type, GTK_TYPE_PRINT_OPERATION) &&
179 strcmp (pspec->name, "job-name") == 0)
182 if (g_type_is_a (type, GTK_TYPE_PRINT_UNIX_DIALOG) &&
183 (strcmp (pspec->name, "page-setup") == 0 ||
184 strcmp (pspec->name, "print-settings") == 0))
187 if (g_type_is_a (type, GTK_TYPE_PROGRESS_BAR) &&
188 strcmp (pspec->name, "adjustment") == 0)
191 /* filename value depends on $HOME */
192 if (g_type_is_a (type, GTK_TYPE_RECENT_MANAGER) &&
193 (strcmp (pspec->name, "filename") == 0 ||
194 strcmp (pspec->name, "size") == 0))
197 if (g_type_is_a (type, GTK_TYPE_SCALE_BUTTON) &&
198 strcmp (pspec->name, "adjustment") == 0)
201 if (g_type_is_a (type, GTK_TYPE_SCROLLED_WINDOW) &&
202 (strcmp (pspec->name, "hadjustment") == 0 ||
203 strcmp (pspec->name, "vadjustment") == 0))
206 /* these defaults come from XResources */
207 if (g_type_is_a (type, GTK_TYPE_SETTINGS) &&
208 strncmp (pspec->name, "gtk-xft-", 8) == 0)
211 if (g_type_is_a (type, GTK_TYPE_SETTINGS) &&
212 (strcmp (pspec->name, "color-hash") == 0 ||
213 strcmp (pspec->name, "gtk-cursor-theme-name") == 0 ||
214 strcmp (pspec->name, "gtk-cursor-theme-size") == 0 ||
215 strcmp (pspec->name, "gtk-dnd-drag-threshold") == 0 ||
216 strcmp (pspec->name, "gtk-double-click-time") == 0 ||
217 strcmp (pspec->name, "gtk-fallback-icon-theme") == 0 ||
218 strcmp (pspec->name, "gtk-file-chooser-backend") == 0 ||
219 strcmp (pspec->name, "gtk-icon-theme-name") == 0 ||
220 strcmp (pspec->name, "gtk-im-module") == 0 ||
221 strcmp (pspec->name, "gtk-key-theme-name") == 0 ||
222 strcmp (pspec->name, "gtk-theme-name") == 0 ||
223 strcmp (pspec->name, "gtk-sound-theme-name") == 0 ||
224 strcmp (pspec->name, "gtk-enable-input-feedback-sounds") == 0 ||
225 strcmp (pspec->name, "gtk-enable-event-sounds") == 0))
228 if (g_type_is_a (type, GTK_TYPE_SPIN_BUTTON) &&
229 (strcmp (pspec->name, "adjustment") == 0))
232 if (g_type_is_a (type, GTK_TYPE_STATUS_ICON) &&
233 (strcmp (pspec->name, "size") == 0 ||
234 strcmp (pspec->name, "screen") == 0))
237 if (g_type_is_a (type, GTK_TYPE_TEXT_BUFFER) &&
238 (strcmp (pspec->name, "tag-table") == 0 ||
239 strcmp (pspec->name, "copy-target-list") == 0 ||
240 strcmp (pspec->name, "paste-target-list") == 0))
243 /* language depends on the current locale */
244 if (g_type_is_a (type, GTK_TYPE_TEXT_TAG) &&
245 (strcmp (pspec->name, "background-gdk") == 0 ||
246 strcmp (pspec->name, "foreground-gdk") == 0 ||
247 strcmp (pspec->name, "language") == 0 ||
248 strcmp (pspec->name, "font") == 0 ||
249 strcmp (pspec->name, "font-desc") == 0))
252 if (g_type_is_a (type, GTK_TYPE_TEXT_VIEW) &&
253 strcmp (pspec->name, "buffer") == 0)
256 if (g_type_is_a (type, GTK_TYPE_TOOL_ITEM_GROUP) &&
257 strcmp (pspec->name, "label-widget") == 0)
260 if (g_type_is_a (type, GTK_TYPE_TREE_VIEW) &&
261 (strcmp (pspec->name, "hadjustment") == 0 ||
262 strcmp (pspec->name, "vadjustment") == 0))
265 if (g_type_is_a (type, GTK_TYPE_VIEWPORT) &&
266 (strcmp (pspec->name, "hadjustment") == 0 ||
267 strcmp (pspec->name, "vadjustment") == 0))
270 if (g_type_is_a (type, GTK_TYPE_WIDGET) &&
271 (strcmp (pspec->name, "name") == 0 ||
272 strcmp (pspec->name, "screen") == 0 ||
273 strcmp (pspec->name, "style") == 0))
276 /* resize-grip-visible is determined at runtime */
277 if (g_type_is_a (type, GTK_TYPE_WINDOW) &&
278 (strcmp (pspec->name, "resize-grip-visible") == 0))
281 if (g_test_verbose ())
282 g_print ("Property %s.%s\n",
283 g_type_name (pspec->owner_type),
285 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
286 g_object_get_property (instance, pspec->name, &value);
287 check_property ("Property", pspec, &value);
288 g_value_unset (&value);
292 if (g_type_is_a (type, GTK_TYPE_WIDGET))
294 pspecs = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (klass), &n_pspecs);
296 for (i = 0; i < n_pspecs; ++i)
298 GParamSpec *pspec = pspecs[i];
299 GValue value = G_VALUE_INIT;
301 if (pspec->owner_type != type)
304 if ((pspec->flags & G_PARAM_READABLE) == 0)
307 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
308 gtk_widget_style_get_property (GTK_WIDGET (instance), pspec->name, &value);
309 check_property ("Style property", pspec, &value);
310 g_value_unset (&value);
316 if (g_type_is_a (type, GDK_TYPE_WINDOW))
317 gdk_window_destroy (GDK_WINDOW (instance));
319 g_object_unref (instance);
321 g_type_class_unref (klass);
325 main (int argc, char **argv)
330 gtk_test_init (&argc, &argv);
331 gtk_test_register_all_types();
333 otypes = gtk_test_list_all_types (NULL);
334 for (i = 0; otypes[i]; i++)
338 testname = g_strdup_printf ("/Default Values/%s",
339 g_type_name (otypes[i]));
340 g_test_add_data_func (testname,