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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #undef GTK_DISABLE_DEPRECATED
22 #define GTK_ENABLE_BROKEN
25 #include <gtk/gtkprintunixdialog.h>
28 check_property (const char *output,
32 GValue default_value = { 0, };
35 if (g_param_value_defaults (pspec, value))
38 g_value_init (&default_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
39 g_param_value_set_default (pspec, &default_value);
41 v = g_strdup_value_contents (value);
42 dv = g_strdup_value_contents (&default_value);
44 msg = g_strdup_printf ("%s %s.%s: %s != %s\n",
46 g_type_name (pspec->owner_type),
49 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
55 g_value_unset (&default_value);
59 test_type (gconstpointer data)
67 type = * (GType *) data;
69 if (!G_TYPE_IS_CLASSED (type))
72 if (G_TYPE_IS_ABSTRACT (type))
75 if (!g_type_is_a (type, G_TYPE_OBJECT))
78 /* These can't be freely constructed/destroyed */
79 if (g_type_is_a (type, GTK_TYPE_PRINT_JOB) ||
80 g_type_is_a (type, GDK_TYPE_PIXBUF_LOADER) ||
81 g_type_is_a (type, gdk_pixbuf_simple_anim_iter_get_type ()))
84 /* The gtk_arg compat wrappers can't set up default values */
85 if (g_type_is_a (type, GTK_TYPE_CLIST) ||
86 g_type_is_a (type, GTK_TYPE_CTREE) ||
87 g_type_is_a (type, GTK_TYPE_LIST) ||
88 g_type_is_a (type, GTK_TYPE_TIPS_QUERY))
91 klass = g_type_class_ref (type);
93 if (g_type_is_a (type, GTK_TYPE_SETTINGS))
94 instance = g_object_ref (gtk_settings_get_default ());
95 else if (g_type_is_a (type, GDK_TYPE_PANGO_RENDERER))
96 instance = g_object_ref (gdk_pango_renderer_get_default (gdk_screen_get_default ()));
97 else if (g_type_is_a (type, GDK_TYPE_PIXMAP))
98 instance = g_object_ref (gdk_pixmap_new (NULL, 1, 1, 1));
99 else if (g_type_is_a (type, GDK_TYPE_COLORMAP))
100 instance = g_object_ref (gdk_colormap_new (gdk_visual_get_best (), TRUE));
101 else if (g_type_is_a (type, GDK_TYPE_WINDOW))
103 GdkWindowAttr attributes;
104 attributes.window_type = GDK_WINDOW_TEMP;
105 instance = g_object_ref (gdk_window_new (NULL, &attributes, 0));
108 instance = g_object_new (type, NULL);
110 if (g_type_is_a (type, G_TYPE_INITIALLY_UNOWNED))
111 g_object_ref_sink (instance);
113 pspecs = g_object_class_list_properties (klass, &n_pspecs);
114 for (i = 0; i < n_pspecs; ++i)
116 GParamSpec *pspec = pspecs[i];
117 GValue value = { 0, };
119 if (pspec->owner_type != type)
122 if ((pspec->flags & G_PARAM_READABLE) == 0)
125 if (g_type_is_a (type, GDK_TYPE_DISPLAY_MANAGER) &&
126 (strcmp (pspec->name, "default-display") == 0))
129 if (g_type_is_a (type, GDK_TYPE_PANGO_RENDERER) &&
130 (strcmp (pspec->name, "screen") == 0))
133 if (g_type_is_a (type, GTK_TYPE_ABOUT_DIALOG) &&
134 (strcmp (pspec->name, "program-name") == 0))
137 /* These are set to the current date */
138 if (g_type_is_a (type, GTK_TYPE_CALENDAR) &&
139 (strcmp (pspec->name, "year") == 0 ||
140 strcmp (pspec->name, "month") == 0 ||
141 strcmp (pspec->name, "day") == 0))
144 if (g_type_is_a (type, GTK_TYPE_CELL_RENDERER_TEXT) &&
145 (strcmp (pspec->name, "background-gdk") == 0 ||
146 strcmp (pspec->name, "foreground-gdk") == 0 ||
147 strcmp (pspec->name, "font") == 0 ||
148 strcmp (pspec->name, "font-desc") == 0))
151 if (g_type_is_a (type, GTK_TYPE_CELL_VIEW) &&
152 (strcmp (pspec->name, "background-gdk") == 0 ||
153 strcmp (pspec->name, "foreground-gdk") == 0))
156 if (g_type_is_a (type, GTK_TYPE_COLOR_BUTTON) &&
157 strcmp (pspec->name, "color") == 0)
160 if (g_type_is_a (type, GTK_TYPE_COLOR_SELECTION) &&
161 strcmp (pspec->name, "current-color") == 0)
164 /* Gets set to the cwd */
165 if (g_type_is_a (type, GTK_TYPE_FILE_SELECTION) &&
166 strcmp (pspec->name, "filename") == 0)
169 if (g_type_is_a (type, GTK_TYPE_FONT_SELECTION) &&
170 strcmp (pspec->name, "font") == 0)
173 if (g_type_is_a (type, GTK_TYPE_LAYOUT) &&
174 (strcmp (pspec->name, "hadjustment") == 0 ||
175 strcmp (pspec->name, "vadjustment") == 0))
178 if (g_type_is_a (type, GTK_TYPE_MESSAGE_DIALOG) &&
179 strcmp (pspec->name, "image") == 0)
182 if (g_type_is_a (type, GTK_TYPE_PRINT_OPERATION) &&
183 strcmp (pspec->name, "job-name") == 0)
186 if (g_type_is_a (type, GTK_TYPE_PRINT_UNIX_DIALOG) &&
187 (strcmp (pspec->name, "page-setup") == 0 ||
188 strcmp (pspec->name, "print-settings") == 0))
191 if (g_type_is_a (type, GTK_TYPE_PROGRESS_BAR) &&
192 strcmp (pspec->name, "adjustment") == 0)
195 /* filename value depends on $HOME */
196 if (g_type_is_a (type, GTK_TYPE_RECENT_MANAGER) &&
197 (strcmp (pspec->name, "filename") == 0 ||
198 strcmp (pspec->name, "size") == 0))
201 if (g_type_is_a (type, GTK_TYPE_SCALE_BUTTON) &&
202 strcmp (pspec->name, "adjustment") == 0)
205 if (g_type_is_a (type, GTK_TYPE_SCROLLED_WINDOW) &&
206 (strcmp (pspec->name, "hadjustment") == 0 ||
207 strcmp (pspec->name, "vadjustment") == 0))
210 /* these defaults come from XResources */
211 if (g_type_is_a (type, GTK_TYPE_SETTINGS) &&
212 strncmp (pspec->name, "gtk-xft-", 8) == 0)
215 if (g_type_is_a (type, GTK_TYPE_SETTINGS) &&
216 (strcmp (pspec->name, "color-hash") == 0 ||
217 strcmp (pspec->name, "gtk-cursor-theme-name") == 0 ||
218 strcmp (pspec->name, "gtk-cursor-theme-size") == 0 ||
219 strcmp (pspec->name, "gtk-double-click-time") == 0 ||
220 strcmp (pspec->name, "gtk-file-chooser-backend") == 0 ||
221 strcmp (pspec->name, "gtk-icon-theme-name") == 0 ||
222 strcmp (pspec->name, "gtk-fallback-icon-theme") == 0 ||
223 strcmp (pspec->name, "gtk-key-theme-name") == 0 ||
224 strcmp (pspec->name, "gtk-theme-name") == 0))
227 if (g_type_is_a (type, GTK_TYPE_SPIN_BUTTON) &&
228 (strcmp (pspec->name, "adjustment") == 0))
231 if (g_type_is_a (type, GTK_TYPE_STATUS_ICON) &&
232 (strcmp (pspec->name, "size") == 0 ||
233 strcmp (pspec->name, "screen") == 0))
236 if (g_type_is_a (type, GTK_TYPE_TEXT_BUFFER) &&
237 (strcmp (pspec->name, "tag-table") == 0 ||
238 strcmp (pspec->name, "copy-target-list") == 0 ||
239 strcmp (pspec->name, "paste-target-list") == 0))
242 /* language depends on the current locale */
243 if (g_type_is_a (type, GTK_TYPE_TEXT_TAG) &&
244 (strcmp (pspec->name, "background-gdk") == 0 ||
245 strcmp (pspec->name, "foreground-gdk") == 0 ||
246 strcmp (pspec->name, "language") == 0 ||
247 strcmp (pspec->name, "font") == 0 ||
248 strcmp (pspec->name, "font-desc") == 0))
251 if (g_type_is_a (type, GTK_TYPE_TEXT) &&
252 (strcmp (pspec->name, "hadjustment") == 0 ||
253 strcmp (pspec->name, "vadjustment") == 0))
256 if (g_type_is_a (type, GTK_TYPE_TEXT_VIEW) &&
257 strcmp (pspec->name, "buffer") == 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 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
277 g_object_get_property (instance, pspec->name, &value);
278 check_property ("Property", pspec, &value);
279 g_value_unset (&value);
283 if (g_type_is_a (type, GTK_TYPE_WIDGET))
285 pspecs = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (klass), &n_pspecs);
287 for (i = 0; i < n_pspecs; ++i)
289 GParamSpec *pspec = pspecs[i];
290 GValue value = { 0, };
292 if (pspec->owner_type != type)
295 if ((pspec->flags & G_PARAM_READABLE) == 0)
298 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
299 gtk_widget_style_get_property (GTK_WIDGET (instance), pspec->name, &value);
300 check_property ("Style property", pspec, &value);
301 g_value_unset (&value);
307 if (g_type_is_a (type, GDK_TYPE_WINDOW))
308 gdk_window_destroy (GDK_WINDOW (instance));
310 g_object_unref (instance);
312 g_type_class_unref (klass);
315 extern void pixbuf_init (void);
318 main (int argc, char **argv)
323 gtk_test_init (&argc, &argv);
325 gtk_test_register_all_types();
327 otypes = gtk_test_list_all_types (NULL);
328 for (i = 0; otypes[i]; i++)
332 testname = g_strdup_printf ("/Default Values/%s",
333 g_type_name (otypes[i]));
334 g_test_add_data_func (testname,