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.
23 #include <gtk/gtkunixprint.h>
26 check_property (const char *output,
30 GValue default_value = G_VALUE_INIT;
33 if (g_param_value_defaults (pspec, value))
36 g_value_init (&default_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
37 g_param_value_set_default (pspec, &default_value);
39 v = g_strdup_value_contents (value);
40 dv = g_strdup_value_contents (&default_value);
42 msg = g_strdup_printf ("%s %s.%s: %s != %s\n",
44 g_type_name (pspec->owner_type),
47 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
53 g_value_unset (&default_value);
57 test_type (gconstpointer data)
65 type = * (GType *) data;
67 if (!G_TYPE_IS_CLASSED (type))
70 if (G_TYPE_IS_ABSTRACT (type))
73 if (!g_type_is_a (type, G_TYPE_OBJECT))
76 /* These can't be freely constructed/destroyed */
77 if (g_type_is_a (type, GTK_TYPE_PRINT_JOB) ||
78 g_type_is_a (type, GTK_TYPE_APPLICATION) ||
79 g_type_is_a (type, GDK_TYPE_PIXBUF_LOADER) ||
80 g_type_is_a (type, gdk_pixbuf_simple_anim_iter_get_type ()))
83 klass = g_type_class_ref (type);
85 if (g_type_is_a (type, GTK_TYPE_SETTINGS))
86 instance = g_object_ref (gtk_settings_get_default ());
87 else if (g_type_is_a (type, GDK_TYPE_WINDOW))
89 GdkWindowAttr attributes;
90 attributes.window_type = GDK_WINDOW_TEMP;
91 attributes.event_mask = 0;
92 attributes.width = 100;
93 attributes.height = 100;
94 instance = g_object_ref (gdk_window_new (NULL, &attributes, 0));
97 instance = g_object_new (type, NULL);
99 if (g_type_is_a (type, G_TYPE_INITIALLY_UNOWNED))
100 g_object_ref_sink (instance);
102 pspecs = g_object_class_list_properties (klass, &n_pspecs);
103 for (i = 0; i < n_pspecs; ++i)
105 GParamSpec *pspec = pspecs[i];
106 GValue value = G_VALUE_INIT;
108 if (pspec->owner_type != type)
111 if ((pspec->flags & G_PARAM_READABLE) == 0)
114 if (g_type_is_a (type, GDK_TYPE_DISPLAY_MANAGER) &&
115 (strcmp (pspec->name, "default-display") == 0))
118 if (g_type_is_a (type, GTK_TYPE_ABOUT_DIALOG) &&
119 (strcmp (pspec->name, "program-name") == 0))
122 /* These are set to the current date */
123 if (g_type_is_a (type, GTK_TYPE_CALENDAR) &&
124 (strcmp (pspec->name, "year") == 0 ||
125 strcmp (pspec->name, "month") == 0 ||
126 strcmp (pspec->name, "day") == 0))
129 if (g_type_is_a (type, GTK_TYPE_CELL_RENDERER_TEXT) &&
130 (strcmp (pspec->name, "background-gdk") == 0 ||
131 strcmp (pspec->name, "foreground-gdk") == 0 ||
132 strcmp (pspec->name, "font") == 0 ||
133 strcmp (pspec->name, "font-desc") == 0))
136 if (g_type_is_a (type, GTK_TYPE_CELL_VIEW) &&
137 (strcmp (pspec->name, "background-gdk") == 0 ||
138 strcmp (pspec->name, "foreground-gdk") == 0))
141 if (g_type_is_a (type, GTK_TYPE_COLOR_BUTTON) &&
142 strcmp (pspec->name, "color") == 0)
145 if (g_type_is_a (type, GTK_TYPE_COLOR_SELECTION) &&
146 strcmp (pspec->name, "current-color") == 0)
149 if (g_type_is_a (type, GTK_TYPE_COLOR_SELECTION_DIALOG) &&
150 (strcmp (pspec->name, "color-selection") == 0 ||
151 strcmp (pspec->name, "ok-button") == 0 ||
152 strcmp (pspec->name, "help-button") == 0 ||
153 strcmp (pspec->name, "cancel-button") == 0))
156 /* Default invisible char is determined at runtime */
157 if (g_type_is_a (type, GTK_TYPE_ENTRY) &&
158 (strcmp (pspec->name, "invisible-char") == 0 ||
159 strcmp (pspec->name, "buffer") == 0))
162 if (g_type_is_a (type, GTK_TYPE_FONT_SELECTION) &&
163 strcmp (pspec->name, "font") == 0)
166 if (g_type_is_a (type, GTK_TYPE_LAYOUT) &&
167 (strcmp (pspec->name, "hadjustment") == 0 ||
168 strcmp (pspec->name, "vadjustment") == 0))
171 if (g_type_is_a (type, GTK_TYPE_MESSAGE_DIALOG) &&
172 (strcmp (pspec->name, "image") == 0 ||
173 strcmp (pspec->name, "message-area") == 0))
176 if (g_type_is_a (type, GTK_TYPE_PANED) &&
177 strcmp (pspec->name, "max-position") == 0)
180 if (g_type_is_a (type, GTK_TYPE_PRINT_OPERATION) &&
181 strcmp (pspec->name, "job-name") == 0)
184 if (g_type_is_a (type, GTK_TYPE_PRINT_UNIX_DIALOG) &&
185 (strcmp (pspec->name, "page-setup") == 0 ||
186 strcmp (pspec->name, "print-settings") == 0))
189 if (g_type_is_a (type, GTK_TYPE_PROGRESS_BAR) &&
190 strcmp (pspec->name, "adjustment") == 0)
193 /* filename value depends on $HOME */
194 if (g_type_is_a (type, GTK_TYPE_RECENT_MANAGER) &&
195 (strcmp (pspec->name, "filename") == 0 ||
196 strcmp (pspec->name, "size") == 0))
199 if (g_type_is_a (type, GTK_TYPE_SCALE_BUTTON) &&
200 strcmp (pspec->name, "adjustment") == 0)
203 if (g_type_is_a (type, GTK_TYPE_SCROLLED_WINDOW) &&
204 (strcmp (pspec->name, "hadjustment") == 0 ||
205 strcmp (pspec->name, "vadjustment") == 0))
208 /* these defaults come from XResources */
209 if (g_type_is_a (type, GTK_TYPE_SETTINGS) &&
210 strncmp (pspec->name, "gtk-xft-", 8) == 0)
213 if (g_type_is_a (type, GTK_TYPE_SETTINGS) &&
214 (strcmp (pspec->name, "color-hash") == 0 ||
215 strcmp (pspec->name, "gtk-cursor-theme-name") == 0 ||
216 strcmp (pspec->name, "gtk-cursor-theme-size") == 0 ||
217 strcmp (pspec->name, "gtk-dnd-drag-threshold") == 0 ||
218 strcmp (pspec->name, "gtk-double-click-time") == 0 ||
219 strcmp (pspec->name, "gtk-fallback-icon-theme") == 0 ||
220 strcmp (pspec->name, "gtk-file-chooser-backend") == 0 ||
221 strcmp (pspec->name, "gtk-icon-theme-name") == 0 ||
222 strcmp (pspec->name, "gtk-im-module") == 0 ||
223 strcmp (pspec->name, "gtk-key-theme-name") == 0 ||
224 strcmp (pspec->name, "gtk-theme-name") == 0 ||
225 strcmp (pspec->name, "gtk-sound-theme-name") == 0 ||
226 strcmp (pspec->name, "gtk-enable-input-feedback-sounds") == 0 ||
227 strcmp (pspec->name, "gtk-enable-event-sounds") == 0))
230 if (g_type_is_a (type, GTK_TYPE_SPIN_BUTTON) &&
231 (strcmp (pspec->name, "adjustment") == 0))
234 if (g_type_is_a (type, GTK_TYPE_STATUS_ICON) &&
235 (strcmp (pspec->name, "size") == 0 ||
236 strcmp (pspec->name, "screen") == 0))
239 if (g_type_is_a (type, GTK_TYPE_TEXT_BUFFER) &&
240 (strcmp (pspec->name, "tag-table") == 0 ||
241 strcmp (pspec->name, "copy-target-list") == 0 ||
242 strcmp (pspec->name, "paste-target-list") == 0))
245 /* language depends on the current locale */
246 if (g_type_is_a (type, GTK_TYPE_TEXT_TAG) &&
247 (strcmp (pspec->name, "background-gdk") == 0 ||
248 strcmp (pspec->name, "foreground-gdk") == 0 ||
249 strcmp (pspec->name, "language") == 0 ||
250 strcmp (pspec->name, "font") == 0 ||
251 strcmp (pspec->name, "font-desc") == 0))
254 if (g_type_is_a (type, GTK_TYPE_TEXT_VIEW) &&
255 strcmp (pspec->name, "buffer") == 0)
258 if (g_type_is_a (type, GTK_TYPE_TOOL_ITEM_GROUP) &&
259 strcmp (pspec->name, "label-widget") == 0)
262 if (g_type_is_a (type, GTK_TYPE_TREE_VIEW) &&
263 (strcmp (pspec->name, "hadjustment") == 0 ||
264 strcmp (pspec->name, "vadjustment") == 0))
267 if (g_type_is_a (type, GTK_TYPE_VIEWPORT) &&
268 (strcmp (pspec->name, "hadjustment") == 0 ||
269 strcmp (pspec->name, "vadjustment") == 0))
272 if (g_type_is_a (type, GTK_TYPE_WIDGET) &&
273 (strcmp (pspec->name, "name") == 0 ||
274 strcmp (pspec->name, "screen") == 0 ||
275 strcmp (pspec->name, "style") == 0))
278 /* resize-grip-visible is determined at runtime */
279 if (g_type_is_a (type, GTK_TYPE_WINDOW) &&
280 (strcmp (pspec->name, "resize-grip-visible") == 0))
283 if (g_test_verbose ())
284 g_print ("Property %s.%s\n",
285 g_type_name (pspec->owner_type),
287 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
288 g_object_get_property (instance, pspec->name, &value);
289 check_property ("Property", pspec, &value);
290 g_value_unset (&value);
294 if (g_type_is_a (type, GTK_TYPE_WIDGET))
296 pspecs = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (klass), &n_pspecs);
298 for (i = 0; i < n_pspecs; ++i)
300 GParamSpec *pspec = pspecs[i];
301 GValue value = G_VALUE_INIT;
303 if (pspec->owner_type != type)
306 if ((pspec->flags & G_PARAM_READABLE) == 0)
309 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
310 gtk_widget_style_get_property (GTK_WIDGET (instance), pspec->name, &value);
311 check_property ("Style property", pspec, &value);
312 g_value_unset (&value);
318 if (g_type_is_a (type, GDK_TYPE_WINDOW))
319 gdk_window_destroy (GDK_WINDOW (instance));
321 g_object_unref (instance);
323 g_type_class_unref (klass);
326 extern void pixbuf_init (void);
329 main (int argc, char **argv)
334 gtk_test_init (&argc, &argv);
336 gtk_test_register_all_types();
338 otypes = gtk_test_list_all_types (NULL);
339 for (i = 0; otypes[i]; i++)
343 testname = g_strdup_printf ("/Default Values/%s",
344 g_type_name (otypes[i]));
345 g_test_add_data_func (testname,