1 /* GIO default value tests
2 * Copyright (C) 2013 Red Hat, Inc.
4 * SPDX-License-Identifier: LGPL-2.1-or-later
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library; if not, see <http://www.gnu.org/licenses/>.
26 #include <gio/gosxappinfo.h>
30 check_property (const char *output,
34 GValue default_value = G_VALUE_INIT;
37 if (g_param_value_defaults (pspec, value))
40 g_param_value_set_default (pspec, &default_value);
42 v = g_strdup_value_contents (value);
43 dv = g_strdup_value_contents (&default_value);
45 msg = g_strdup_printf ("%s %s.%s: %s != %s\n",
47 g_type_name (pspec->owner_type),
50 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
55 g_value_unset (&default_value);
59 test_type (gconstpointer data)
67 type = * (GType *) data;
69 if (g_type_is_a (type, G_TYPE_APP_INFO_MONITOR))
71 g_test_skip ("singleton");
75 if (g_type_is_a (type, G_TYPE_BINDING) ||
76 g_type_is_a (type, G_TYPE_BUFFERED_INPUT_STREAM) ||
77 g_type_is_a (type, G_TYPE_BUFFERED_OUTPUT_STREAM) ||
78 g_type_is_a (type, G_TYPE_CHARSET_CONVERTER) ||
79 g_type_is_a (type, G_TYPE_DBUS_ACTION_GROUP) ||
80 g_type_is_a (type, G_TYPE_DBUS_CONNECTION) ||
81 g_type_is_a (type, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT) ||
82 g_type_is_a (type, G_TYPE_DBUS_OBJECT_MANAGER_SERVER) ||
83 g_type_is_a (type, G_TYPE_DBUS_PROXY) ||
84 g_type_is_a (type, G_TYPE_DBUS_SERVER) ||
85 g_type_is_a (type, G_TYPE_FILTER_OUTPUT_STREAM) ||
86 g_type_is_a (type, G_TYPE_FILTER_INPUT_STREAM) ||
87 g_type_is_a (type, G_TYPE_INET_ADDRESS) ||
88 g_type_is_a (type, G_TYPE_INET_SOCKET_ADDRESS) ||
89 g_type_is_a (type, G_TYPE_PROPERTY_ACTION) ||
90 g_type_is_a (type, G_TYPE_SETTINGS) ||
91 g_type_is_a (type, G_TYPE_SOCKET_CONNECTION) ||
92 g_type_is_a (type, G_TYPE_SIMPLE_IO_STREAM) ||
93 g_type_is_a (type, G_TYPE_THEMED_ICON) ||
96 g_test_skip ("mandatory construct params");
100 if (g_type_is_a (type, G_TYPE_DBUS_MENU_MODEL) ||
101 g_type_is_a (type, G_TYPE_DBUS_METHOD_INVOCATION))
103 g_test_skip ("crash in finalize");
107 if (g_type_is_a (type, G_TYPE_FILE_ENUMERATOR) ||
108 g_type_is_a (type, G_TYPE_FILE_IO_STREAM))
110 g_test_skip ("should be abstract");
114 klass = g_type_class_ref (type);
115 instance = g_object_new (type, NULL);
117 if (G_IS_INITABLE (instance) &&
118 !g_initable_init (G_INITABLE (instance), NULL, NULL))
120 g_test_skip ("initialization failed");
121 g_object_unref (instance);
122 g_type_class_unref (klass);
126 if (g_type_is_a (type, G_TYPE_INITIALLY_UNOWNED))
127 g_object_ref_sink (instance);
129 pspecs = g_object_class_list_properties (klass, &n_pspecs);
130 for (i = 0; i < n_pspecs; ++i)
132 GParamSpec *pspec = pspecs[i];
133 GValue value = G_VALUE_INIT;
135 if (pspec->owner_type != type)
138 if ((pspec->flags & G_PARAM_READABLE) == 0)
141 if (g_type_is_a (type, G_TYPE_APPLICATION) &&
142 (strcmp (pspec->name, "is-remote") == 0))
144 g_test_message ("skipping GApplication:is-remote");
148 if (g_type_is_a (type, G_TYPE_PROXY_ADDRESS_ENUMERATOR) &&
149 (strcmp (pspec->name, "proxy-resolver") == 0))
151 g_test_message ("skipping GProxyAddressEnumerator:proxy-resolver");
155 if (g_type_is_a (type, G_TYPE_SOCKET_CLIENT) &&
156 (strcmp (pspec->name, "proxy-resolver") == 0))
158 g_test_message ("skipping GSocketClient:proxy-resolver");
162 if (g_test_verbose ())
163 g_printerr ("Property %s.%s\n", g_type_name (pspec->owner_type), pspec->name);
164 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
165 g_object_get_property (instance, pspec->name, &value);
166 check_property ("Property", pspec, &value);
167 g_value_unset (&value);
170 g_object_unref (instance);
171 g_type_class_unref (klass);
174 static GType *all_registered_types;
177 list_all_types (void)
179 if (!all_registered_types)
182 all_registered_types = g_new0 (GType, 1000);
183 tp = all_registered_types;
184 #include "giotypefuncs.inc"
188 return all_registered_types;
192 main (int argc, char **argv)
199 g_setenv ("GIO_USE_VFS", "local", TRUE);
200 g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
202 /* Disable deprecation warnings when we poke at deprecated properties */
203 g_setenv ("G_ENABLE_DIAGNOSTIC", "0", TRUE);
205 g_test_init (&argc, &argv, NULL);
207 /* Create one test bus for all tests, as we have a lot of very small
210 bus = g_test_dbus_new (G_TEST_DBUS_NONE);
211 g_test_dbus_up (bus);
213 otypes = list_all_types ();
214 for (i = 0; otypes[i]; i++)
218 if (!G_TYPE_IS_CLASSED (otypes[i]))
221 if (G_TYPE_IS_ABSTRACT (otypes[i]))
224 if (!g_type_is_a (otypes[i], G_TYPE_OBJECT))
227 testname = g_strdup_printf ("/Default Values/%s",
228 g_type_name (otypes[i]));
229 g_test_add_data_func (testname, &otypes[i], test_type);
233 result = g_test_run ();
235 g_test_dbus_down (bus);
236 g_object_unref (bus);