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 = { 0, };
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_PANGO_RENDERER))
88 instance = g_object_ref (gdk_pango_renderer_get_default (gdk_screen_get_default ()));
89 else if (g_type_is_a (type, GDK_TYPE_PIXMAP))
90 instance = g_object_ref (gdk_pixmap_new (NULL, 1, 1, 1));
91 else if (g_type_is_a (type, GDK_TYPE_COLORMAP))
92 instance = g_object_ref (gdk_colormap_new (gdk_visual_get_best (), TRUE));
93 else if (g_type_is_a (type, GDK_TYPE_WINDOW))
95 GdkWindowAttr attributes;
96 attributes.window_type = GDK_WINDOW_TEMP;
97 attributes.event_mask = 0;
98 attributes.width = 100;
99 attributes.height = 100;
100 instance = g_object_ref (gdk_window_new (NULL, &attributes, 0));
103 instance = g_object_new (type, NULL);
105 if (g_type_is_a (type, G_TYPE_INITIALLY_UNOWNED))
106 g_object_ref_sink (instance);
108 pspecs = g_object_class_list_properties (klass, &n_pspecs);
109 for (i = 0; i < n_pspecs; ++i)
111 GParamSpec *pspec = pspecs[i];
112 GValue value = { 0, };
114 if (pspec->owner_type != type)
117 if ((pspec->flags & G_PARAM_READABLE) == 0)
120 if (g_type_is_a (type, GDK_TYPE_DISPLAY_MANAGER) &&
121 (strcmp (pspec->name, "default-display") == 0))
124 if (g_type_is_a (type, GDK_TYPE_PANGO_RENDERER) &&
125 (strcmp (pspec->name, "screen") == 0))
128 if (g_type_is_a (type, GTK_TYPE_ABOUT_DIALOG) &&
129 (strcmp (pspec->name, "program-name") == 0))
132 /* These are set to the current date */
133 if (g_type_is_a (type, GTK_TYPE_CALENDAR) &&
134 (strcmp (pspec->name, "year") == 0 ||
135 strcmp (pspec->name, "month") == 0 ||
136 strcmp (pspec->name, "day") == 0))
139 if (g_type_is_a (type, GTK_TYPE_CELL_RENDERER_TEXT) &&
140 (strcmp (pspec->name, "background-gdk") == 0 ||
141 strcmp (pspec->name, "foreground-gdk") == 0 ||
142 strcmp (pspec->name, "font") == 0 ||
143 strcmp (pspec->name, "font-desc") == 0))
146 if (g_type_is_a (type, GTK_TYPE_CELL_VIEW) &&
147 (strcmp (pspec->name, "background-gdk") == 0 ||
148 strcmp (pspec->name, "foreground-gdk") == 0))
151 if (g_type_is_a (type, GTK_TYPE_COLOR_BUTTON) &&
152 strcmp (pspec->name, "color") == 0)
155 if (g_type_is_a (type, GTK_TYPE_COLOR_SELECTION) &&
156 strcmp (pspec->name, "current-color") == 0)
159 if (g_type_is_a (type, GTK_TYPE_COLOR_SELECTION_DIALOG) &&
160 (strcmp (pspec->name, "color-selection") == 0 ||
161 strcmp (pspec->name, "ok-button") == 0 ||
162 strcmp (pspec->name, "help-button") == 0 ||
163 strcmp (pspec->name, "cancel-button") == 0))
166 /* Default invisible char is determined at runtime */
167 if (g_type_is_a (type, GTK_TYPE_ENTRY) &&
168 (strcmp (pspec->name, "invisible-char") == 0 ||
169 strcmp (pspec->name, "buffer") == 0))
172 if (g_type_is_a (type, GTK_TYPE_FONT_SELECTION) &&
173 strcmp (pspec->name, "font") == 0)
176 if (g_type_is_a (type, GTK_TYPE_LAYOUT) &&
177 (strcmp (pspec->name, "hadjustment") == 0 ||
178 strcmp (pspec->name, "vadjustment") == 0))
181 if (g_type_is_a (type, GTK_TYPE_MESSAGE_DIALOG) &&
182 (strcmp (pspec->name, "image") == 0 ||
183 strcmp (pspec->name, "message-area") == 0))
186 if (g_type_is_a (type, GTK_TYPE_PANED) &&
187 strcmp (pspec->name, "max-position") == 0)
190 if (g_type_is_a (type, GTK_TYPE_PRINT_OPERATION) &&
191 strcmp (pspec->name, "job-name") == 0)
194 if (g_type_is_a (type, GTK_TYPE_PRINT_UNIX_DIALOG) &&
195 (strcmp (pspec->name, "page-setup") == 0 ||
196 strcmp (pspec->name, "print-settings") == 0))
199 if (g_type_is_a (type, GTK_TYPE_PROGRESS_BAR) &&
200 strcmp (pspec->name, "adjustment") == 0)
203 /* filename value depends on $HOME */
204 if (g_type_is_a (type, GTK_TYPE_RECENT_MANAGER) &&
205 (strcmp (pspec->name, "filename") == 0 ||
206 strcmp (pspec->name, "size") == 0))
209 if (g_type_is_a (type, GTK_TYPE_SCALE_BUTTON) &&
210 strcmp (pspec->name, "adjustment") == 0)
213 if (g_type_is_a (type, GTK_TYPE_SCROLLED_WINDOW) &&
214 (strcmp (pspec->name, "hadjustment") == 0 ||
215 strcmp (pspec->name, "vadjustment") == 0))
218 /* these defaults come from XResources */
219 if (g_type_is_a (type, GTK_TYPE_SETTINGS) &&
220 strncmp (pspec->name, "gtk-xft-", 8) == 0)
223 if (g_type_is_a (type, GTK_TYPE_SETTINGS) &&
224 (strcmp (pspec->name, "color-hash") == 0 ||
225 strcmp (pspec->name, "gtk-cursor-theme-name") == 0 ||
226 strcmp (pspec->name, "gtk-cursor-theme-size") == 0 ||
227 strcmp (pspec->name, "gtk-dnd-drag-threshold") == 0 ||
228 strcmp (pspec->name, "gtk-double-click-time") == 0 ||
229 strcmp (pspec->name, "gtk-fallback-icon-theme") == 0 ||
230 strcmp (pspec->name, "gtk-file-chooser-backend") == 0 ||
231 strcmp (pspec->name, "gtk-icon-theme-name") == 0 ||
232 strcmp (pspec->name, "gtk-im-module") == 0 ||
233 strcmp (pspec->name, "gtk-key-theme-name") == 0 ||
234 strcmp (pspec->name, "gtk-theme-name") == 0 ||
235 strcmp (pspec->name, "gtk-sound-theme-name") == 0 ||
236 strcmp (pspec->name, "gtk-enable-input-feedback-sounds") == 0 ||
237 strcmp (pspec->name, "gtk-enable-event-sounds") == 0))
240 if (g_type_is_a (type, GTK_TYPE_SPIN_BUTTON) &&
241 (strcmp (pspec->name, "adjustment") == 0))
244 if (g_type_is_a (type, GTK_TYPE_STATUS_ICON) &&
245 (strcmp (pspec->name, "size") == 0 ||
246 strcmp (pspec->name, "screen") == 0))
249 if (g_type_is_a (type, GTK_TYPE_TEXT_BUFFER) &&
250 (strcmp (pspec->name, "tag-table") == 0 ||
251 strcmp (pspec->name, "copy-target-list") == 0 ||
252 strcmp (pspec->name, "paste-target-list") == 0))
255 /* language depends on the current locale */
256 if (g_type_is_a (type, GTK_TYPE_TEXT_TAG) &&
257 (strcmp (pspec->name, "background-gdk") == 0 ||
258 strcmp (pspec->name, "foreground-gdk") == 0 ||
259 strcmp (pspec->name, "language") == 0 ||
260 strcmp (pspec->name, "font") == 0 ||
261 strcmp (pspec->name, "font-desc") == 0))
264 if (g_type_is_a (type, GTK_TYPE_TEXT_VIEW) &&
265 strcmp (pspec->name, "buffer") == 0)
268 if (g_type_is_a (type, GTK_TYPE_TOOL_ITEM_GROUP) &&
269 strcmp (pspec->name, "label-widget") == 0)
272 if (g_type_is_a (type, GTK_TYPE_TREE_VIEW) &&
273 (strcmp (pspec->name, "hadjustment") == 0 ||
274 strcmp (pspec->name, "vadjustment") == 0))
277 if (g_type_is_a (type, GTK_TYPE_VIEWPORT) &&
278 (strcmp (pspec->name, "hadjustment") == 0 ||
279 strcmp (pspec->name, "vadjustment") == 0))
282 if (g_type_is_a (type, GTK_TYPE_WIDGET) &&
283 (strcmp (pspec->name, "name") == 0 ||
284 strcmp (pspec->name, "screen") == 0 ||
285 strcmp (pspec->name, "style") == 0))
288 if (g_test_verbose ())
289 g_print ("Property %s.%s\n",
290 g_type_name (pspec->owner_type),
292 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
293 g_object_get_property (instance, pspec->name, &value);
294 check_property ("Property", pspec, &value);
295 g_value_unset (&value);
299 if (g_type_is_a (type, GTK_TYPE_WIDGET))
301 pspecs = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (klass), &n_pspecs);
303 for (i = 0; i < n_pspecs; ++i)
305 GParamSpec *pspec = pspecs[i];
306 GValue value = { 0, };
308 if (pspec->owner_type != type)
311 if ((pspec->flags & G_PARAM_READABLE) == 0)
314 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
315 gtk_widget_style_get_property (GTK_WIDGET (instance), pspec->name, &value);
316 check_property ("Style property", pspec, &value);
317 g_value_unset (&value);
323 if (g_type_is_a (type, GDK_TYPE_WINDOW))
324 gdk_window_destroy (GDK_WINDOW (instance));
326 g_object_unref (instance);
328 g_type_class_unref (klass);
331 extern void pixbuf_init (void);
334 main (int argc, char **argv)
339 gtk_test_init (&argc, &argv);
341 gtk_test_register_all_types();
343 otypes = gtk_test_list_all_types (NULL);
344 for (i = 0; otypes[i]; i++)
348 testname = g_strdup_printf ("/Default Values/%s",
349 g_type_name (otypes[i]));
350 g_test_add_data_func (testname,