nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* GIO default value tests |
2 | * Copyright (C) 2013 Red Hat, Inc. |
||
3 | * |
||
4 | * This library is free software; you can redistribute it and/or |
||
5 | * modify it under the terms of the GNU Library General Public |
||
6 | * License as published by the Free Software Foundation; either |
||
7 | * version 2 of the License, or (at your option) any later version. |
||
8 | * |
||
9 | * This library is distributed in the hope that it will be useful, |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||
12 | * Library General Public License for more details. |
||
13 | * |
||
14 | * You should have received a copy of the GNU Library General Public |
||
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
||
16 | */ |
||
17 | |||
18 | #include <string.h> |
||
19 | #include <gio/gio.h> |
||
20 | |||
21 | static void |
||
22 | check_property (const char *output, |
||
23 | GParamSpec *pspec, |
||
24 | GValue *value) |
||
25 | { |
||
26 | GValue default_value = G_VALUE_INIT; |
||
27 | char *v, *dv, *msg; |
||
28 | |||
29 | if (g_param_value_defaults (pspec, value)) |
||
30 | return; |
||
31 | |||
32 | g_value_init (&default_value, G_PARAM_SPEC_VALUE_TYPE (pspec)); |
||
33 | g_param_value_set_default (pspec, &default_value); |
||
34 | |||
35 | v = g_strdup_value_contents (value); |
||
36 | dv = g_strdup_value_contents (&default_value); |
||
37 | |||
38 | msg = g_strdup_printf ("%s %s.%s: %s != %s\n", |
||
39 | output, |
||
40 | g_type_name (pspec->owner_type), |
||
41 | pspec->name, |
||
42 | dv, v); |
||
43 | g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); |
||
44 | g_free (msg); |
||
45 | |||
46 | g_free (v); |
||
47 | g_free (dv); |
||
48 | g_value_unset (&default_value); |
||
49 | } |
||
50 | |||
51 | static void |
||
52 | test_type (gconstpointer data) |
||
53 | { |
||
54 | GObjectClass *klass; |
||
55 | GObject *instance; |
||
56 | GParamSpec **pspecs; |
||
57 | guint n_pspecs, i; |
||
58 | GType type; |
||
59 | |||
60 | type = * (GType *) data; |
||
61 | |||
62 | if (g_type_is_a (type, G_TYPE_APP_INFO_MONITOR)) |
||
63 | { |
||
64 | g_test_skip ("singleton"); |
||
65 | return; |
||
66 | } |
||
67 | |||
68 | if (g_type_is_a (type, G_TYPE_BINDING) || |
||
69 | g_type_is_a (type, G_TYPE_BUFFERED_INPUT_STREAM) || |
||
70 | g_type_is_a (type, G_TYPE_BUFFERED_OUTPUT_STREAM) || |
||
71 | g_type_is_a (type, G_TYPE_CHARSET_CONVERTER) || |
||
72 | g_type_is_a (type, G_TYPE_DBUS_ACTION_GROUP) || |
||
73 | g_type_is_a (type, G_TYPE_DBUS_CONNECTION) || |
||
74 | g_type_is_a (type, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT) || |
||
75 | g_type_is_a (type, G_TYPE_DBUS_OBJECT_MANAGER_SERVER) || |
||
76 | g_type_is_a (type, G_TYPE_DBUS_PROXY) || |
||
77 | g_type_is_a (type, G_TYPE_DBUS_SERVER) || |
||
78 | g_type_is_a (type, G_TYPE_FILTER_OUTPUT_STREAM) || |
||
79 | g_type_is_a (type, G_TYPE_FILTER_INPUT_STREAM) || |
||
80 | g_type_is_a (type, G_TYPE_INET_ADDRESS) || |
||
81 | g_type_is_a (type, G_TYPE_INET_SOCKET_ADDRESS) || |
||
82 | g_type_is_a (type, G_TYPE_PROPERTY_ACTION) || |
||
83 | g_type_is_a (type, G_TYPE_SETTINGS) || |
||
84 | g_type_is_a (type, G_TYPE_SOCKET_CONNECTION) || |
||
85 | g_type_is_a (type, G_TYPE_SIMPLE_IO_STREAM) || |
||
86 | g_type_is_a (type, G_TYPE_THEMED_ICON) || |
||
87 | FALSE) |
||
88 | { |
||
89 | g_test_skip ("mandatory construct params"); |
||
90 | return; |
||
91 | } |
||
92 | |||
93 | if (g_type_is_a (type, G_TYPE_DBUS_MENU_MODEL) || |
||
94 | g_type_is_a (type, G_TYPE_DBUS_METHOD_INVOCATION)) |
||
95 | { |
||
96 | g_test_skip ("crash in finalize"); |
||
97 | return; |
||
98 | } |
||
99 | |||
100 | if (g_type_is_a (type, G_TYPE_FILE_ENUMERATOR) || |
||
101 | g_type_is_a (type, G_TYPE_FILE_IO_STREAM)) |
||
102 | { |
||
103 | g_test_skip ("should be abstract"); |
||
104 | return; |
||
105 | } |
||
106 | |||
107 | klass = g_type_class_ref (type); |
||
108 | instance = g_object_new (type, NULL); |
||
109 | |||
110 | if (G_IS_INITABLE (instance) && |
||
111 | !g_initable_init (G_INITABLE (instance), NULL, NULL)) |
||
112 | { |
||
113 | g_test_skip ("initialization failed"); |
||
114 | g_object_unref (instance); |
||
115 | g_type_class_unref (klass); |
||
116 | return; |
||
117 | } |
||
118 | |||
119 | if (g_type_is_a (type, G_TYPE_INITIALLY_UNOWNED)) |
||
120 | g_object_ref_sink (instance); |
||
121 | |||
122 | pspecs = g_object_class_list_properties (klass, &n_pspecs); |
||
123 | for (i = 0; i < n_pspecs; ++i) |
||
124 | { |
||
125 | GParamSpec *pspec = pspecs[i]; |
||
126 | GValue value = G_VALUE_INIT; |
||
127 | |||
128 | if (pspec->owner_type != type) |
||
129 | continue; |
||
130 | |||
131 | if ((pspec->flags & G_PARAM_READABLE) == 0) |
||
132 | continue; |
||
133 | |||
134 | if (g_type_is_a (type, G_TYPE_APPLICATION) && |
||
135 | (strcmp (pspec->name, "is-remote") == 0)) |
||
136 | { |
||
137 | g_test_message ("skipping GApplication:is-remote"); |
||
138 | continue; |
||
139 | } |
||
140 | |||
141 | if (g_type_is_a (type, G_TYPE_PROXY_ADDRESS_ENUMERATOR) && |
||
142 | (strcmp (pspec->name, "proxy-resolver") == 0)) |
||
143 | { |
||
144 | g_test_message ("skipping GProxyAddressEnumerator:proxy-resolver"); |
||
145 | continue; |
||
146 | } |
||
147 | |||
148 | if (g_type_is_a (type, G_TYPE_SOCKET_CLIENT) && |
||
149 | (strcmp (pspec->name, "proxy-resolver") == 0)) |
||
150 | { |
||
151 | g_test_message ("skipping GSocketClient:proxy-resolver"); |
||
152 | continue; |
||
153 | } |
||
154 | |||
155 | if (g_test_verbose ()) |
||
156 | g_printerr ("Property %s.%s\n", g_type_name (pspec->owner_type), pspec->name); |
||
157 | g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec)); |
||
158 | g_object_get_property (instance, pspec->name, &value); |
||
159 | check_property ("Property", pspec, &value); |
||
160 | g_value_unset (&value); |
||
161 | } |
||
162 | g_free (pspecs); |
||
163 | g_object_unref (instance); |
||
164 | g_type_class_unref (klass); |
||
165 | } |
||
166 | |||
167 | static GType *all_registered_types; |
||
168 | |||
169 | static const GType * |
||
170 | list_all_types (void) |
||
171 | { |
||
172 | if (!all_registered_types) |
||
173 | { |
||
174 | GType *tp; |
||
175 | all_registered_types = g_new0 (GType, 1000); |
||
176 | tp = all_registered_types; |
||
177 | #include "giotypefuncs.c" |
||
178 | *tp = 0; |
||
179 | } |
||
180 | |||
181 | return all_registered_types; |
||
182 | } |
||
183 | |||
184 | int |
||
185 | main (int argc, char **argv) |
||
186 | { |
||
187 | const GType *otypes; |
||
188 | guint i; |
||
189 | GTestDBus *bus; |
||
190 | gint result; |
||
191 | |||
192 | g_setenv ("GIO_USE_VFS", "local", TRUE); |
||
193 | g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); |
||
194 | |||
195 | g_test_init (&argc, &argv, NULL); |
||
196 | |||
197 | /* Create one test bus for all tests, as we have a lot of very small |
||
198 | * and quick tests. |
||
199 | */ |
||
200 | bus = g_test_dbus_new (G_TEST_DBUS_NONE); |
||
201 | g_test_dbus_up (bus); |
||
202 | |||
203 | otypes = list_all_types (); |
||
204 | for (i = 0; otypes[i]; i++) |
||
205 | { |
||
206 | gchar *testname; |
||
207 | |||
208 | if (!G_TYPE_IS_CLASSED (otypes[i])) |
||
209 | continue; |
||
210 | |||
211 | if (G_TYPE_IS_ABSTRACT (otypes[i])) |
||
212 | continue; |
||
213 | |||
214 | if (!g_type_is_a (otypes[i], G_TYPE_OBJECT)) |
||
215 | continue; |
||
216 | |||
217 | testname = g_strdup_printf ("/Default Values/%s", |
||
218 | g_type_name (otypes[i])); |
||
219 | g_test_add_data_func (testname, &otypes[i], test_type); |
||
220 | g_free (testname); |
||
221 | } |
||
222 | |||
223 | result = g_test_run (); |
||
224 | |||
225 | g_test_dbus_down (bus); |
||
226 | g_object_unref (bus); |
||
227 | |||
228 | return result; |
||
229 | } |