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/gtkunixprint.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 attributes.event_mask = 0;
106 attributes.width = 100;
107 attributes.height = 100;
108 instance = g_object_ref (gdk_window_new (NULL, &attributes, 0));
111 instance = g_object_new (type, NULL);
113 if (g_type_is_a (type, G_TYPE_INITIALLY_UNOWNED))
114 g_object_ref_sink (instance);
116 pspecs = g_object_class_list_properties (klass, &n_pspecs);
117 for (i = 0; i < n_pspecs; ++i)
119 GParamSpec *pspec = pspecs[i];
120 GValue value = { 0, };
122 if (pspec->owner_type != type)
125 if ((pspec->flags & G_PARAM_READABLE) == 0)
128 if (g_type_is_a (type, GDK_TYPE_DISPLAY_MANAGER) &&
129 (strcmp (pspec->name, "default-display") == 0))
132 if (g_type_is_a (type, GDK_TYPE_PANGO_RENDERER) &&
133 (strcmp (pspec->name, "screen") == 0))
136 if (g_type_is_a (type, GTK_TYPE_ABOUT_DIALOG) &&
137 (strcmp (pspec->name, "program-name") == 0))
140 /* These are set to the current date */
141 if (g_type_is_a (type, GTK_TYPE_CALENDAR) &&
142 (strcmp (pspec->name, "year") == 0 ||
143 strcmp (pspec->name, "month") == 0 ||
144 strcmp (pspec->name, "day") == 0))
147 if (g_type_is_a (type, GTK_TYPE_CELL_RENDERER_TEXT) &&
148 (strcmp (pspec->name, "background-gdk") == 0 ||
149 strcmp (pspec->name, "foreground-gdk") == 0 ||
150 strcmp (pspec->name, "font") == 0 ||
151 strcmp (pspec->name, "font-desc") == 0))
154 if (g_type_is_a (type, GTK_TYPE_CELL_VIEW) &&
155 (strcmp (pspec->name, "background-gdk") == 0 ||
156 strcmp (pspec->name, "foreground-gdk") == 0))
159 if (g_type_is_a (type, GTK_TYPE_COLOR_BUTTON) &&
160 strcmp (pspec->name, "color") == 0)
163 if (g_type_is_a (type, GTK_TYPE_COLOR_SELECTION) &&
164 strcmp (pspec->name, "current-color") == 0)
167 if (g_type_is_a (type, GTK_TYPE_COLOR_SELECTION_DIALOG) &&
168 (strcmp (pspec->name, "color-selection") == 0 ||
169 strcmp (pspec->name, "ok-button") == 0 ||
170 strcmp (pspec->name, "help-button") == 0 ||
171 strcmp (pspec->name, "cancel-button") == 0))
174 /* Default invisible char is determined at runtime */
175 if (g_type_is_a (type, GTK_TYPE_ENTRY) &&
176 strcmp (pspec->name, "invisible-char") == 0 ||
177 strcmp (pspec->name, "buffer") == 0)
180 /* Gets set to the cwd */
181 if (g_type_is_a (type, GTK_TYPE_FILE_SELECTION) &&
182 strcmp (pspec->name, "filename") == 0)
185 if (g_type_is_a (type, GTK_TYPE_FONT_SELECTION) &&
186 strcmp (pspec->name, "font") == 0)
189 if (g_type_is_a (type, GTK_TYPE_LAYOUT) &&
190 (strcmp (pspec->name, "hadjustment") == 0 ||
191 strcmp (pspec->name, "vadjustment") == 0))
194 if (g_type_is_a (type, GTK_TYPE_MESSAGE_DIALOG) &&
195 strcmp (pspec->name, "image") == 0)
198 if (g_type_is_a (type, GTK_TYPE_PRINT_OPERATION) &&
199 strcmp (pspec->name, "job-name") == 0)
202 if (g_type_is_a (type, GTK_TYPE_PRINT_UNIX_DIALOG) &&
203 (strcmp (pspec->name, "page-setup") == 0 ||
204 strcmp (pspec->name, "print-settings") == 0))
207 if (g_type_is_a (type, GTK_TYPE_PROGRESS_BAR) &&
208 strcmp (pspec->name, "adjustment") == 0)
211 /* filename value depends on $HOME */
212 if (g_type_is_a (type, GTK_TYPE_RECENT_MANAGER) &&
213 (strcmp (pspec->name, "filename") == 0 ||
214 strcmp (pspec->name, "size") == 0))
217 if (g_type_is_a (type, GTK_TYPE_SCALE_BUTTON) &&
218 strcmp (pspec->name, "adjustment") == 0)
221 if (g_type_is_a (type, GTK_TYPE_SCROLLED_WINDOW) &&
222 (strcmp (pspec->name, "hadjustment") == 0 ||
223 strcmp (pspec->name, "vadjustment") == 0))
226 /* these defaults come from XResources */
227 if (g_type_is_a (type, GTK_TYPE_SETTINGS) &&
228 strncmp (pspec->name, "gtk-xft-", 8) == 0)
231 if (g_type_is_a (type, GTK_TYPE_SETTINGS) &&
232 (strcmp (pspec->name, "color-hash") == 0 ||
233 strcmp (pspec->name, "gtk-cursor-theme-name") == 0 ||
234 strcmp (pspec->name, "gtk-cursor-theme-size") == 0 ||
235 strcmp (pspec->name, "gtk-dnd-drag-threshold") == 0 ||
236 strcmp (pspec->name, "gtk-double-click-time") == 0 ||
237 strcmp (pspec->name, "gtk-fallback-icon-theme") == 0 ||
238 strcmp (pspec->name, "gtk-file-chooser-backend") == 0 ||
239 strcmp (pspec->name, "gtk-icon-theme-name") == 0 ||
240 strcmp (pspec->name, "gtk-im-module") == 0 ||
241 strcmp (pspec->name, "gtk-key-theme-name") == 0 ||
242 strcmp (pspec->name, "gtk-theme-name") == 0))
245 if (g_type_is_a (type, GTK_TYPE_SPIN_BUTTON) &&
246 (strcmp (pspec->name, "adjustment") == 0))
249 if (g_type_is_a (type, GTK_TYPE_STATUS_ICON) &&
250 (strcmp (pspec->name, "size") == 0 ||
251 strcmp (pspec->name, "screen") == 0))
254 if (g_type_is_a (type, GTK_TYPE_TEXT_BUFFER) &&
255 (strcmp (pspec->name, "tag-table") == 0 ||
256 strcmp (pspec->name, "copy-target-list") == 0 ||
257 strcmp (pspec->name, "paste-target-list") == 0))
260 /* language depends on the current locale */
261 if (g_type_is_a (type, GTK_TYPE_TEXT_TAG) &&
262 (strcmp (pspec->name, "background-gdk") == 0 ||
263 strcmp (pspec->name, "foreground-gdk") == 0 ||
264 strcmp (pspec->name, "language") == 0 ||
265 strcmp (pspec->name, "font") == 0 ||
266 strcmp (pspec->name, "font-desc") == 0))
269 if (g_type_is_a (type, GTK_TYPE_TEXT) &&
270 (strcmp (pspec->name, "hadjustment") == 0 ||
271 strcmp (pspec->name, "vadjustment") == 0))
274 if (g_type_is_a (type, GTK_TYPE_TEXT_VIEW) &&
275 strcmp (pspec->name, "buffer") == 0)
278 if (g_type_is_a (type, GTK_TYPE_TREE_VIEW) &&
279 (strcmp (pspec->name, "hadjustment") == 0 ||
280 strcmp (pspec->name, "vadjustment") == 0))
283 if (g_type_is_a (type, GTK_TYPE_VIEWPORT) &&
284 (strcmp (pspec->name, "hadjustment") == 0 ||
285 strcmp (pspec->name, "vadjustment") == 0))
288 if (g_type_is_a (type, GTK_TYPE_WIDGET) &&
289 (strcmp (pspec->name, "name") == 0 ||
290 strcmp (pspec->name, "screen") == 0 ||
291 strcmp (pspec->name, "style") == 0))
294 if (g_test_verbose ())
295 g_print ("Property %s.%s\n",
296 g_type_name (pspec->owner_type),
298 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
299 g_object_get_property (instance, pspec->name, &value);
300 check_property ("Property", pspec, &value);
301 g_value_unset (&value);
305 if (g_type_is_a (type, GTK_TYPE_WIDGET))
307 pspecs = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (klass), &n_pspecs);
309 for (i = 0; i < n_pspecs; ++i)
311 GParamSpec *pspec = pspecs[i];
312 GValue value = { 0, };
314 if (pspec->owner_type != type)
317 if ((pspec->flags & G_PARAM_READABLE) == 0)
320 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
321 gtk_widget_style_get_property (GTK_WIDGET (instance), pspec->name, &value);
322 check_property ("Style property", pspec, &value);
323 g_value_unset (&value);
329 if (g_type_is_a (type, GDK_TYPE_WINDOW))
330 gdk_window_destroy (GDK_WINDOW (instance));
332 g_object_unref (instance);
334 g_type_class_unref (klass);
337 extern void pixbuf_init (void);
340 main (int argc, char **argv)
345 gtk_test_init (&argc, &argv);
347 gtk_test_register_all_types();
349 otypes = gtk_test_list_all_types (NULL);
350 for (i = 0; otypes[i]; i++)
354 testname = g_strdup_printf ("/Default Values/%s",
355 g_type_name (otypes[i]));
356 g_test_add_data_func (testname,