defaultvalue.c 16.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* Gtk+ default value tests
 * Copyright (C) 2007 Christian Persch
 *               2007 Johan Dahlin
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
Javier Jardón's avatar
Javier Jardón committed
16
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17
18
19
20
 */

#include <string.h>
#include <gtk/gtk.h>
21
#include <gtk/gtkunixprint.h>
22
23
24
25
26
27

static void
check_property (const char *output,
	        GParamSpec *pspec,
		GValue *value)
{
Javier Jardón's avatar
Javier Jardón committed
28
  GValue default_value = G_VALUE_INIT;
29
30
31
32
33
34
35
  char *v, *dv, *msg;

  if (g_param_value_defaults (pspec, value))
      return;

  g_value_init (&default_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
  g_param_value_set_default (pspec, &default_value);
Matthias Clasen's avatar
Matthias Clasen committed
36

37
38
  v = g_strdup_value_contents (value);
  dv = g_strdup_value_contents (&default_value);
Matthias Clasen's avatar
Matthias Clasen committed
39

40
41
42
43
44
45
46
47
  msg = g_strdup_printf ("%s %s.%s: %s != %s\n",
			 output,
			 g_type_name (pspec->owner_type),
			 pspec->name,
			 dv, v);
  g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
		       G_STRFUNC, msg);
  g_free (msg);
Matthias Clasen's avatar
Matthias Clasen committed
48

49
50
51
52
53
54
55
56
57
58
59
60
61
  g_free (v);
  g_free (dv);
  g_value_unset (&default_value);
}

static void
test_type (gconstpointer data)
{
  GObjectClass *klass;
  GObject *instance;
  GParamSpec **pspecs;
  guint n_pspecs, i;
  GType type;
Matthias Clasen's avatar
Matthias Clasen committed
62
  GdkDisplay *display;
63
64
65

  type = * (GType *) data;

Matthias Clasen's avatar
Matthias Clasen committed
66
67
  display = gdk_display_get_default ();

68
69
70
71
72
73
74
75
76
  if (!G_TYPE_IS_CLASSED (type))
    return;

  if (G_TYPE_IS_ABSTRACT (type))
    return;

  if (!g_type_is_a (type, G_TYPE_OBJECT))
    return;

Matthias Clasen's avatar
Matthias Clasen committed
77
  /* These can't be freely constructed/destroyed */
78
  if (g_type_is_a (type, GTK_TYPE_APPLICATION) ||
Johan Dahlin's avatar
Johan Dahlin committed
79
      g_type_is_a (type, GDK_TYPE_PIXBUF_LOADER) ||
80
      g_type_is_a (type, GTK_TYPE_LAYOUT_CHILD) ||
81
82
83
#ifdef G_OS_UNIX
      g_type_is_a (type, GTK_TYPE_PRINT_JOB) ||
#endif
Matthias Clasen's avatar
Matthias Clasen committed
84
85
      g_type_is_a (type, gdk_pixbuf_simple_anim_iter_get_type ()) ||
      g_str_equal (g_type_name (type), "GdkX11DeviceManagerXI2") ||
86
      g_str_equal (g_type_name (type), "GdkX11DeviceManagerCore") ||
Matthias Clasen's avatar
Matthias Clasen committed
87
      g_str_equal (g_type_name (type), "GdkX11Display") ||
88
89
      g_str_equal (g_type_name (type), "GdkX11Screen") ||
      g_str_equal (g_type_name (type), "GdkX11GLContext"))
Matthias Clasen's avatar
Matthias Clasen committed
90
91
    return;

92
93
94
95
96
  /* This throws a critical when the connection is dropped */
  if (g_type_is_a (type, GTK_TYPE_APP_CHOOSER_DIALOG))
    return;

  /* These leak their GDBusConnections */
97
  if (g_type_is_a (type, GTK_TYPE_FILE_CHOOSER_DIALOG) ||
98
      g_type_is_a (type, GTK_TYPE_FILE_CHOOSER_WIDGET) ||
99
      g_str_equal (g_type_name (type), "GtkPlacesSidebar"))
100
    return;
101
 
102
103
  if (g_type_is_a (type, GTK_TYPE_SHORTCUT_TRIGGER) ||
      g_type_is_a (type, GTK_TYPE_SHORTCUT_ACTION))
104
105
    return;

106
  klass = g_type_class_ref (type);
Matthias Clasen's avatar
Matthias Clasen committed
107

Matthias Clasen's avatar
Matthias Clasen committed
108
  if (g_type_is_a (type, GTK_TYPE_SETTINGS))
109
    instance = G_OBJECT (g_object_ref (gtk_settings_get_default ()));
110
  else if (g_type_is_a (type, GDK_TYPE_SURFACE))
Johan Dahlin's avatar
Johan Dahlin committed
111
    {
112
      instance = G_OBJECT (g_object_ref (gdk_surface_new_toplevel (display)));
Johan Dahlin's avatar
Johan Dahlin committed
113
    }
114
  else if (g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL) ||
Benjamin Otte's avatar
Benjamin Otte committed
115
           g_type_is_a (type, GTK_TYPE_NO_SELECTION) ||
Matthias Clasen's avatar
Matthias Clasen committed
116
117
           g_type_is_a (type, GTK_TYPE_SINGLE_SELECTION) ||
           g_type_is_a (type, GTK_TYPE_MULTI_SELECTION))
Benjamin Otte's avatar
Benjamin Otte committed
118
119
120
121
122
123
124
    {
      GListStore *list_store = g_list_store_new (G_TYPE_OBJECT);
      instance = g_object_new (type,
                               "model", list_store,
                               NULL);
      g_object_unref (list_store);
    }
125
126
127
128
129
130
  else if (g_type_is_a (type, GSK_TYPE_GL_SHADER))
    {
      GBytes *bytes = g_bytes_new_static ("", 0);
      instance = g_object_new (type, "source", bytes, NULL);
      g_bytes_unref (bytes);
    }
131
132
  else if (g_type_is_a (type, GDK_TYPE_CLIPBOARD) ||
           g_str_equal (g_type_name (type), "GdkX11Cursor"))
Matthias Clasen's avatar
Matthias Clasen committed
133
    instance = g_object_new (type, "display", display, NULL);
Matthias Clasen's avatar
Matthias Clasen committed
134
135
136
  else
    instance = g_object_new (type, NULL);

137
  if (g_type_is_a (type, G_TYPE_INITIALLY_UNOWNED))
Matthias Clasen's avatar
Matthias Clasen committed
138
    g_object_ref_sink (instance);
139
140
141
142
143

  pspecs = g_object_class_list_properties (klass, &n_pspecs);
  for (i = 0; i < n_pspecs; ++i)
    {
      GParamSpec *pspec = pspecs[i];
Javier Jardón's avatar
Javier Jardón committed
144
      GValue value = G_VALUE_INIT;
145
      gboolean check = TRUE;
Matthias Clasen's avatar
Matthias Clasen committed
146

147
148
149
150
151
152
      if (pspec->owner_type != type)
	continue;

      if ((pspec->flags & G_PARAM_READABLE) == 0)
	continue;

153
154
155
      /* This is set via class_init, and we have a11y tests to verify it */
      if (g_type_is_a (type, GTK_TYPE_ACCESSIBLE) &&
          strcmp (pspec->name, "accessible-role") == 0)
156
        check = FALSE;
157

Benjamin Otte's avatar
Benjamin Otte committed
158
159
160
      /* This is set via construct property */
      if (g_type_is_a (type, GTK_TYPE_BUILDER) &&
          strcmp (pspec->name, "scope") == 0)
161
        check = FALSE;
Benjamin Otte's avatar
Benjamin Otte committed
162

163
164
      if (g_type_is_a (type, GDK_TYPE_CLIPBOARD) &&
	  strcmp (pspec->name, "display") == 0)
165
	check = FALSE;
166
167
168

      /* These are set in init() */
      if ((g_type_is_a (type, GDK_TYPE_CLIPBOARD) ||
Benjamin Otte's avatar
Benjamin Otte committed
169
170
           g_type_is_a (type, GDK_TYPE_CONTENT_PROVIDER) ||
           g_type_is_a (type, GTK_TYPE_DROP_TARGET)) &&
171
	  strcmp (pspec->name, "formats") == 0)
172
	check = FALSE;
173
174
175

      if (g_type_is_a (type, GDK_TYPE_CONTENT_PROVIDER) &&
	  strcmp (pspec->name, "storable-formats") == 0)
176
	check = FALSE;
177

178
179
180
      /* set in the constructor */
      if (g_type_is_a (type, GSK_TYPE_GL_SHADER) &&
	  strcmp (pspec->name, "source") == 0)
181
	check = FALSE;
182

183
184
185
      /* This one has a special-purpose default value */
      if (g_type_is_a (type, GTK_TYPE_DIALOG) &&
	  (strcmp (pspec->name, "use-header-bar") == 0))
186
	check = FALSE;
187

188
      if (g_type_is_a (type, GTK_TYPE_ASSISTANT) &&
189
190
	  (strcmp (pspec->name, "use-header-bar") == 0 ||
           strcmp (pspec->name, "pages") == 0)) /* pages always gets a non-NULL value */
191
	check = FALSE;
192
193
194

      if (g_type_is_a (type, GTK_TYPE_STACK) &&
	  (strcmp (pspec->name, "pages") == 0)) /* pages always gets a non-NULL value */
195
	check = FALSE;
196

Matthias Clasen's avatar
Matthias Clasen committed
197
198
      if (g_type_is_a (type, GTK_TYPE_NOTEBOOK) &&
	  (strcmp (pspec->name, "pages") == 0)) /* pages always gets a non-NULL value */
199
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
200

201
202
      if (g_type_is_a (type, GTK_TYPE_COMBO_BOX) &&
          (strcmp (pspec->name, "child") == 0))
203
        check = FALSE;
204

205
206
      if (g_type_is_a (type, GTK_TYPE_POPOVER) &&
	  (strcmp (pspec->name, "pointing-to") == 0))
207
	check = FALSE;
208

Johan Dahlin's avatar
Johan Dahlin committed
209
210
      if (g_type_is_a (type, GDK_TYPE_DISPLAY_MANAGER) &&
	  (strcmp (pspec->name, "default-display") == 0))
211
	check = FALSE;
Johan Dahlin's avatar
Johan Dahlin committed
212

213
      if (g_type_is_a (type, GDK_TYPE_MONITOR) &&
214
          (strcmp (pspec->name, "geometry") == 0))
215
        check = FALSE;
216

217
218
      if (g_type_is_a (type, GTK_TYPE_ABOUT_DIALOG) &&
	  (strcmp (pspec->name, "program-name") == 0))
219
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
220

Matthias Clasen's avatar
Matthias Clasen committed
221
222
223
224
225
      /* These are set to the current date */
      if (g_type_is_a (type, GTK_TYPE_CALENDAR) &&
	  (strcmp (pspec->name, "year") == 0 ||
	   strcmp (pspec->name, "month") == 0 ||
	   strcmp (pspec->name, "day") == 0))
226
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
227

Matthias Clasen's avatar
Matthias Clasen committed
228
229
230
231
232
      if (g_type_is_a (type, GTK_TYPE_CELL_AREA_CONTEXT) &&
	  (strcmp (pspec->name, "minimum-width") == 0 ||
	   strcmp (pspec->name, "minimum-height") == 0 ||
	   strcmp (pspec->name, "natural-width") == 0 ||
	   strcmp (pspec->name, "natural-height") == 0))
233
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
234

Matthias Clasen's avatar
Matthias Clasen committed
235
236
237
      if (g_type_is_a (type, GTK_TYPE_CELL_RENDERER_TEXT) &&
	  (strcmp (pspec->name, "background-gdk") == 0 ||
	   strcmp (pspec->name, "foreground-gdk") == 0 ||
Matthias Clasen's avatar
Matthias Clasen committed
238
239
	   strcmp (pspec->name, "background-rgba") == 0 ||
	   strcmp (pspec->name, "foreground-rgba") == 0 ||
Matthias Clasen's avatar
Matthias Clasen committed
240
241
	   strcmp (pspec->name, "font") == 0 ||
	   strcmp (pspec->name, "font-desc") == 0))
242
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
243
244
245

      if (g_type_is_a (type, GTK_TYPE_CELL_VIEW) &&
	  (strcmp (pspec->name, "background-gdk") == 0 ||
Matthias Clasen's avatar
Matthias Clasen committed
246
247
248
249
250
	   strcmp (pspec->name, "foreground-gdk") == 0 ||
	   strcmp (pspec->name, "foreground-rgba") == 0 ||
	   strcmp (pspec->name, "background-rgba") == 0 ||
           strcmp (pspec->name, "cell-area") == 0 ||
           strcmp (pspec->name, "cell-area-context") == 0))
251
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
252
253

      if (g_type_is_a (type, GTK_TYPE_COLOR_BUTTON) &&
Matthias Clasen's avatar
Matthias Clasen committed
254
255
	  (strcmp (pspec->name, "color") == 0 ||
	   strcmp (pspec->name, "rgba") == 0))
256
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
257

258
      if (g_type_is_a (type, GTK_TYPE_COLUMN_VIEW) &&
Matthias Clasen's avatar
Matthias Clasen committed
259
260
          (strcmp (pspec->name, "columns") == 0 ||
	   strcmp (pspec->name, "sorter") == 0))
261
	check = FALSE;
262

Matthias Clasen's avatar
Matthias Clasen committed
263
264
265
266
267
G_GNUC_BEGIN_IGNORE_DEPRECATIONS

      if (g_type_is_a (type, GTK_TYPE_COMBO_BOX) &&
	  (strcmp (pspec->name, "cell-area") == 0 ||
           strcmp (pspec->name, "cell-area-context") == 0))
268
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
269
270
271

G_GNUC_END_IGNORE_DEPRECATIONS

272
273
274
      /* Default invisible char is determined at runtime,
       * and buffer gets created on-demand
       */
275
      if (g_type_is_a (type, GTK_TYPE_ENTRY) &&
276
277
	  (strcmp (pspec->name, "invisible-char") == 0 ||
           strcmp (pspec->name, "buffer") == 0))
278
	check = FALSE;
279

280
281
282
      if (g_type_is_a (type, GTK_TYPE_TEXT) &&
	  (strcmp (pspec->name, "invisible-char") == 0 ||
           strcmp (pspec->name, "buffer") == 0))
283
	check = FALSE;
284

Matthias Clasen's avatar
Matthias Clasen committed
285
286
287
288
289
G_GNUC_BEGIN_IGNORE_DEPRECATIONS

      if (g_type_is_a (type, GTK_TYPE_ENTRY_COMPLETION) &&
	  (strcmp (pspec->name, "cell-area") == 0 ||
           strcmp (pspec->name, "cell-area-context") == 0))
290
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
291

292
293
G_GNUC_END_IGNORE_DEPRECATIONS

294
      if ((g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL) ||
Benjamin Otte's avatar
Benjamin Otte committed
295
           g_type_is_a (type, GTK_TYPE_NO_SELECTION) ||
Matthias Clasen's avatar
Matthias Clasen committed
296
297
           g_type_is_a (type, GTK_TYPE_SINGLE_SELECTION) ||
           g_type_is_a (type, GTK_TYPE_MULTI_SELECTION)) &&
Benjamin Otte's avatar
Benjamin Otte committed
298
          strcmp (pspec->name, "model") == 0)
299
        check = FALSE;
Benjamin Otte's avatar
Benjamin Otte committed
300

301
302
303
304
      if (g_type_is_a (type, GTK_TYPE_TREE_LIST_MODEL) &&
	  (strcmp (pspec->name, "item-type") == 0)) /* might be a treelistrow */
	check = FALSE;

305
306
307
      /* This is set in init() */
      if (g_type_is_a (type, GTK_TYPE_FONT_CHOOSER_WIDGET) &&
          strcmp (pspec->name, "tweak-action") == 0)
308
        check = FALSE;
309
310
311

G_GNUC_BEGIN_IGNORE_DEPRECATIONS

Matthias Clasen's avatar
Matthias Clasen committed
312
313
314
      if (g_type_is_a (type, GTK_TYPE_ICON_VIEW) &&
	  (strcmp (pspec->name, "cell-area") == 0 ||
           strcmp (pspec->name, "cell-area-context") == 0))
315
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
316
317
318

G_GNUC_END_IGNORE_DEPRECATIONS

Matthias Clasen's avatar
Matthias Clasen committed
319
      if (g_type_is_a (type, GTK_TYPE_MESSAGE_DIALOG) &&
320
321
          (strcmp (pspec->name, "image") == 0 ||
           strcmp (pspec->name, "message-area") == 0))
322
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
323

Matthias Clasen's avatar
Matthias Clasen committed
324
325
      if (g_type_is_a (type, GTK_TYPE_PANED) &&
	  strcmp (pspec->name, "max-position") == 0)
326
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
327

Matthias Clasen's avatar
Matthias Clasen committed
328
329
      if (g_type_is_a (type, GTK_TYPE_PRINT_OPERATION) &&
	  strcmp (pspec->name, "job-name") == 0)
330
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
331

332
#ifdef G_OS_UNIX
Matthias Clasen's avatar
Matthias Clasen committed
333
334
335
      if (g_type_is_a (type, GTK_TYPE_PRINT_UNIX_DIALOG) &&
	  (strcmp (pspec->name, "page-setup") == 0 ||
	   strcmp (pspec->name, "print-settings") == 0))
336
	check = FALSE;
337
#endif
Matthias Clasen's avatar
Matthias Clasen committed
338
339
340

      if (g_type_is_a (type, GTK_TYPE_PROGRESS_BAR) &&
          strcmp (pspec->name, "adjustment") == 0)
341
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
342
343
344

      /* filename value depends on $HOME */
      if (g_type_is_a (type, GTK_TYPE_RECENT_MANAGER) &&
345
346
          (strcmp (pspec->name, "filename") == 0 ||
	   strcmp (pspec->name, "size") == 0))
347
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
348
349
350

      if (g_type_is_a (type, GTK_TYPE_SCALE_BUTTON) &&
          strcmp (pspec->name, "adjustment") == 0)
351
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
352
353
354
355

      if (g_type_is_a (type, GTK_TYPE_SCROLLED_WINDOW) &&
	  (strcmp (pspec->name, "hadjustment") == 0 ||
           strcmp (pspec->name, "vadjustment") == 0))
356
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
357

Matthias Clasen's avatar
Matthias Clasen committed
358
      if (g_type_is_a (type, GTK_TYPE_SETTINGS))
359
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
360

361
      if (g_type_is_a (type, GTK_TYPE_SHORTCUT) &&
362
363
	  (strcmp (pspec->name, "action") == 0 ||
           strcmp (pspec->name, "trigger") == 0))
364
        check = FALSE;
365

Matthias Clasen's avatar
Matthias Clasen committed
366
367
      if (g_type_is_a (type, GTK_TYPE_SPIN_BUTTON) &&
          (strcmp (pspec->name, "adjustment") == 0))
368
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
369

Matthias Clasen's avatar
Matthias Clasen committed
370
      if (g_type_is_a (type, GTK_TYPE_STYLE_CONTEXT) &&
371
           strcmp (pspec->name, "display") == 0)
372
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
373

Matthias Clasen's avatar
Matthias Clasen committed
374
375
376
377
      if (g_type_is_a (type, GTK_TYPE_TEXT_BUFFER) &&
          (strcmp (pspec->name, "tag-table") == 0 ||
           strcmp (pspec->name, "copy-target-list") == 0 ||
           strcmp (pspec->name, "paste-target-list") == 0))
378
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
379
380
381
382
383
384
385
386

      /* language depends on the current locale */
      if (g_type_is_a (type, GTK_TYPE_TEXT_TAG) &&
          (strcmp (pspec->name, "background-gdk") == 0 ||
           strcmp (pspec->name, "foreground-gdk") == 0 ||
	   strcmp (pspec->name, "language") == 0 ||
	   strcmp (pspec->name, "font") == 0 ||
	   strcmp (pspec->name, "font-desc") == 0))
387
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
388
389
390

      if (g_type_is_a (type, GTK_TYPE_TEXT_VIEW) &&
          strcmp (pspec->name, "buffer") == 0)
391
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
392
393
394
395

      if (g_type_is_a (type, GTK_TYPE_TREE_VIEW) &&
	  (strcmp (pspec->name, "hadjustment") == 0 ||
           strcmp (pspec->name, "vadjustment") == 0))
396
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
397

Matthias Clasen's avatar
Matthias Clasen committed
398
399
400
      if (g_type_is_a (type, GTK_TYPE_TREE_VIEW_COLUMN) &&
	  (strcmp (pspec->name, "cell-area") == 0 ||
           strcmp (pspec->name, "cell-area-context") == 0))
401
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
402

Matthias Clasen's avatar
Matthias Clasen committed
403
404
405
      if (g_type_is_a (type, GTK_TYPE_VIEWPORT) &&
	  (strcmp (pspec->name, "hadjustment") == 0 ||
           strcmp (pspec->name, "vadjustment") == 0))
406
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
407

Johan Dahlin's avatar
Johan Dahlin committed
408
      if (g_type_is_a (type, GTK_TYPE_WIDGET) &&
409
          (strcmp (pspec->name, "name") == 0 ||
410
	   strcmp (pspec->name, "display") == 0 ||
Johan Dahlin's avatar
Johan Dahlin committed
411
	   strcmp (pspec->name, "style") == 0))
412
	check = FALSE;
Johan Dahlin's avatar
Johan Dahlin committed
413

414
415
      /* resize-grip-visible is determined at runtime */
      if (g_type_is_a (type, GTK_TYPE_WINDOW) &&
Matthias Clasen's avatar
Matthias Clasen committed
416
          strcmp (pspec->name, "resize-grip-visible") == 0)
417
        check = FALSE;
418

419
      /* show-desktop depends on desktop environment */
420
      if (g_str_equal (g_type_name (type), "GtkPlacesSidebar") &&
421
          strcmp (pspec->name, "show-desktop") == 0)
422
        check = FALSE;
423

Timm Bäder's avatar
Timm Bäder committed
424
425
426
427
      /* GtkRange constructs an adjustment on its own if NULL is set and
       * the property is a CONSTRUCT one, so the returned value is never NULL. */
      if (g_type_is_a (type, GTK_TYPE_RANGE) &&
          strcmp (pspec->name, "adjustment") == 0)
428
        check = FALSE;
Timm Bäder's avatar
Timm Bäder committed
429
430
431
432

      /* ... and GtkScrollbar wraps that property. */
      if (g_type_is_a (type, GTK_TYPE_SCROLLBAR) &&
          strcmp (pspec->name, "adjustment") == 0)
433
        check = FALSE;
Timm Bäder's avatar
Timm Bäder committed
434

Matthias Clasen's avatar
Matthias Clasen committed
435
436
      if (g_type_is_a (type, GTK_TYPE_DROP_DOWN) &&
          strcmp (pspec->name, "factory") == 0)
437
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
438

Matthias Clasen's avatar
Matthias Clasen committed
439
440
441
      if (g_type_is_a (type, GTK_TYPE_BOOKMARK_LIST) &&
          (strcmp (pspec->name, "filename") == 0 ||
           strcmp (pspec->name, "loading") == 0))
442
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
443

Matthias Clasen's avatar
Matthias Clasen committed
444
445
      /* All the icontheme properties depend on the environment */
      if (g_type_is_a (type, GTK_TYPE_ICON_THEME))
446
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
447

Matthias Clasen's avatar
Matthias Clasen committed
448
      if (g_test_verbose ())
449
        {
450
          g_print ("Property %s:%s%s\n",
451
                   g_type_name (pspec->owner_type),
452
453
                   pspec->name,
                   check ? "" : " (no check)");
454
455
        }

456
457
      g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
      g_object_get_property (instance, pspec->name, &value);
458
459
      if (check)
        check_property ("Property", pspec, &value);
460
461
      g_value_unset (&value);
    }
462
  g_free (pspecs);
463

464
465
  if (g_type_is_a (type, GDK_TYPE_SURFACE))
    gdk_surface_destroy (GDK_SURFACE (instance));
Johan Dahlin's avatar
Johan Dahlin committed
466
467
  else
    g_object_unref (instance);
Matthias Clasen's avatar
Matthias Clasen committed
468

469
470
471
  g_type_class_unref (klass);
}

472
473
474
475
476
477
478
479
480
481
482
483
484
static gboolean
dbind_warning_handler (const char     *log_domain,
                       GLogLevelFlags  log_level,
                       const char     *message,
                       gpointer        user_data)
{
  if (strcmp (log_domain, "dbind") == 0 &&
      log_level == (G_LOG_LEVEL_WARNING|G_LOG_FLAG_FATAL))
    return FALSE;

  return TRUE;
}

485
486
487
int
main (int argc, char **argv)
{
488
  const GType *otypes;
489
  guint i;
490
  const char *display, *x_r_d;
491

Yuri Chornoivan's avatar
Yuri Chornoivan committed
492
  /* These must be set before gtk_test_init */
493
494
  g_setenv ("GIO_USE_VFS", "local", TRUE);
  g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
495
  g_setenv ("G_ENABLE_DIAGNOSTIC", "0", TRUE);
496

497
498
499
  /* g_test_dbus_up() helpfully clears these, so we have to re-set it */
  display = g_getenv ("DISPLAY");
  x_r_d = g_getenv ("XDG_RUNTIME_DIR");
Matthias Clasen's avatar
Matthias Clasen committed
500

501
502
503
504
505
  if (display)
    g_setenv ("DISPLAY", display, TRUE);
  if (x_r_d)
    g_setenv ("XDG_RUNTIME_DIR", x_r_d, TRUE);

506
507
  g_test_log_set_fatal_handler (dbind_warning_handler, NULL);

508
509
510
  gtk_test_init (&argc, &argv);
  gtk_test_register_all_types();

511
512
  otypes = gtk_test_list_all_types (NULL);
  for (i = 0; otypes[i]; i++)
513
    {
Benjamin Otte's avatar
Benjamin Otte committed
514
      char *testname;
Matthias Clasen's avatar
Matthias Clasen committed
515

Matthias Clasen's avatar
Matthias Clasen committed
516
517
518
      if (otypes[i] == GTK_TYPE_FILE_CHOOSER_NATIVE)
        continue;

519
      testname = g_strdup_printf ("/Default Values/%s",
520
				  g_type_name (otypes[i]));
521
      g_test_add_data_func (testname,
522
                            &otypes[i],
523
524
525
			    test_type);
      g_free (testname);
    }
Matthias Clasen's avatar
Matthias Clasen committed
526

Matthias Clasen's avatar
Matthias Clasen committed
527
  return g_test_run();
528
}