defaultvalue.c 16.5 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
      /* This is set in init() */
      if (g_type_is_a (type, GTK_TYPE_FONT_CHOOSER_WIDGET) &&
          strcmp (pspec->name, "tweak-action") == 0)
304
        check = FALSE;
305
306
307

G_GNUC_BEGIN_IGNORE_DEPRECATIONS

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

G_GNUC_END_IGNORE_DEPRECATIONS

Matthias Clasen's avatar
Matthias Clasen committed
315
      if (g_type_is_a (type, GTK_TYPE_MESSAGE_DIALOG) &&
316
317
          (strcmp (pspec->name, "image") == 0 ||
           strcmp (pspec->name, "message-area") == 0))
318
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
319

Matthias Clasen's avatar
Matthias Clasen committed
320
321
      if (g_type_is_a (type, GTK_TYPE_PANED) &&
	  strcmp (pspec->name, "max-position") == 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_PRINT_OPERATION) &&
	  strcmp (pspec->name, "job-name") == 0)
326
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
327

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

      if (g_type_is_a (type, GTK_TYPE_PROGRESS_BAR) &&
          strcmp (pspec->name, "adjustment") == 0)
337
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
338
339
340

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

      if (g_type_is_a (type, GTK_TYPE_SCALE_BUTTON) &&
          strcmp (pspec->name, "adjustment") == 0)
347
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
348
349
350
351

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

Matthias Clasen's avatar
Matthias Clasen committed
354
      if (g_type_is_a (type, GTK_TYPE_SETTINGS))
355
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
356

357
      if (g_type_is_a (type, GTK_TYPE_SHORTCUT) &&
358
359
	  (strcmp (pspec->name, "action") == 0 ||
           strcmp (pspec->name, "trigger") == 0))
360
        check = FALSE;
361

Matthias Clasen's avatar
Matthias Clasen committed
362
363
      if (g_type_is_a (type, GTK_TYPE_SPIN_BUTTON) &&
          (strcmp (pspec->name, "adjustment") == 0))
364
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
365

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

Matthias Clasen's avatar
Matthias Clasen committed
370
371
372
373
      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))
374
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
375
376
377
378
379
380
381
382

      /* 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))
383
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
384
385
386

      if (g_type_is_a (type, GTK_TYPE_TEXT_VIEW) &&
          strcmp (pspec->name, "buffer") == 0)
387
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
388
389
390
391

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

Matthias Clasen's avatar
Matthias Clasen committed
394
395
396
      if (g_type_is_a (type, GTK_TYPE_TREE_VIEW_COLUMN) &&
	  (strcmp (pspec->name, "cell-area") == 0 ||
           strcmp (pspec->name, "cell-area-context") == 0))
397
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
398

Matthias Clasen's avatar
Matthias Clasen committed
399
400
401
      if (g_type_is_a (type, GTK_TYPE_VIEWPORT) &&
	  (strcmp (pspec->name, "hadjustment") == 0 ||
           strcmp (pspec->name, "vadjustment") == 0))
402
	check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
403

Johan Dahlin's avatar
Johan Dahlin committed
404
      if (g_type_is_a (type, GTK_TYPE_WIDGET) &&
405
          (strcmp (pspec->name, "name") == 0 ||
406
	   strcmp (pspec->name, "display") == 0 ||
Johan Dahlin's avatar
Johan Dahlin committed
407
	   strcmp (pspec->name, "style") == 0))
408
	check = FALSE;
Johan Dahlin's avatar
Johan Dahlin committed
409

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

415
      /* show-desktop depends on desktop environment */
416
      if (g_str_equal (g_type_name (type), "GtkPlacesSidebar") &&
417
          strcmp (pspec->name, "show-desktop") == 0)
418
        check = FALSE;
419

Timm Bäder's avatar
Timm Bäder committed
420
421
422
423
      /* 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)
424
        check = FALSE;
Timm Bäder's avatar
Timm Bäder committed
425
426
427
428

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

Matthias Clasen's avatar
Matthias Clasen committed
431
432
      if (g_type_is_a (type, GTK_TYPE_DROP_DOWN) &&
          strcmp (pspec->name, "factory") == 0)
433
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
434

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

Matthias Clasen's avatar
Matthias Clasen committed
440
441
      /* All the icontheme properties depend on the environment */
      if (g_type_is_a (type, GTK_TYPE_ICON_THEME))
442
        check = FALSE;
Matthias Clasen's avatar
Matthias Clasen committed
443

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

452
453
      g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
      g_object_get_property (instance, pspec->name, &value);
454
455
      if (check)
        check_property ("Property", pspec, &value);
456
457
      g_value_unset (&value);
    }
458
  g_free (pspecs);
459

460
461
  if (g_type_is_a (type, GDK_TYPE_SURFACE))
    gdk_surface_destroy (GDK_SURFACE (instance));
Johan Dahlin's avatar
Johan Dahlin committed
462
463
  else
    g_object_unref (instance);
Matthias Clasen's avatar
Matthias Clasen committed
464

465
466
467
  g_type_class_unref (klass);
}

468
469
470
471
472
473
474
475
476
477
478
479
480
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;
}

481
482
483
int
main (int argc, char **argv)
{
484
  const GType *otypes;
485
  guint i;
486
  const char *display, *x_r_d;
487

Yuri Chornoivan's avatar
Yuri Chornoivan committed
488
  /* These must be set before gtk_test_init */
489
490
  g_setenv ("GIO_USE_VFS", "local", TRUE);
  g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
491
  g_setenv ("G_ENABLE_DIAGNOSTIC", "0", TRUE);
492

493
494
495
  /* 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
496

497
498
499
500
501
  if (display)
    g_setenv ("DISPLAY", display, TRUE);
  if (x_r_d)
    g_setenv ("XDG_RUNTIME_DIR", x_r_d, TRUE);

502
503
  g_test_log_set_fatal_handler (dbind_warning_handler, NULL);

504
505
506
  gtk_test_init (&argc, &argv);
  gtk_test_register_all_types();

507
508
  otypes = gtk_test_list_all_types (NULL);
  for (i = 0; otypes[i]; i++)
509
    {
Benjamin Otte's avatar
Benjamin Otte committed
510
      char *testname;
Matthias Clasen's avatar
Matthias Clasen committed
511

Matthias Clasen's avatar
Matthias Clasen committed
512
513
514
      if (otypes[i] == GTK_TYPE_FILE_CHOOSER_NATIVE)
        continue;

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

Matthias Clasen's avatar
Matthias Clasen committed
523
  return g_test_run();
524
}