Branch data Line data Source code
1 : : /*
2 : : * Copyright 2008-2011 Colin Walters <walters@verbum.org>
3 : : * Copyright 2011 Laszlo Pandy <lpandy@src.gnome.org>
4 : : * Copyright 2011 Torsten Schönfeld <kaffeetisch@gmx.de>
5 : : * Copyright 2011, 2012 Pavel Holejsovsky <pavel.holejsovsky@gmail.com>
6 : : * Copyright 2013 Martin Pitt <martinpitt@gnome.org>
7 : : * Copyright 2014 Giovanni Campagna <gcampagna@src.gnome.org>
8 : : * Copyright 2018 Christoph Reiter
9 : : * Copyright 2019, 2024 Philip Chimento <philip.chimento@gmail.com>
10 : : * Copyright 2022 Emmanuele Bassi <ebassi@gnome.org>
11 : : * Copyright 2023 GNOME Foundation, Inc.
12 : : *
13 : : * SPDX-License-Identifier: LGPL-2.1-or-later
14 : : *
15 : : * This library is free software; you can redistribute it and/or
16 : : * modify it under the terms of the GNU Lesser General Public
17 : : * License as published by the Free Software Foundation; either
18 : : * version 2.1 of the License, or (at your option) any later version.
19 : : *
20 : : * This library is distributed in the hope that it will be useful,
21 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 : : * Lesser General Public License for more details.
24 : : *
25 : : * You should have received a copy of the GNU Lesser General
26 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
27 : : *
28 : : * Author: Philip Withnall <pwithnall@gnome.org>
29 : : */
30 : :
31 : : #include "config.h"
32 : :
33 : : #include "gio.h"
34 : : #include "girepository.h"
35 : : #include "glib.h"
36 : : #include "test-common.h"
37 : :
38 : : #if defined(G_OS_UNIX) && !defined(__APPLE__)
39 : : #include "gio/gdesktopappinfo.h"
40 : : #elif defined(G_OS_WIN32)
41 : : #include "gio/gwin32inputstream.h"
42 : : #endif
43 : :
44 : : static void
45 : 1 : test_repository_basic (RepositoryFixture *fx,
46 : : const void *unused)
47 : : {
48 : : const char * const * search_paths;
49 : 1 : char **namespaces = NULL;
50 : : size_t n_namespaces;
51 : : #if defined(G_OS_UNIX)
52 : 1 : const char *expected_namespaces[] = { "GLib", "GLibUnix", NULL };
53 : : #elif defined(G_OS_WIN32)
54 : : const char *expected_namespaces[] = { "GLib", "GLibWin32", NULL };
55 : : #else
56 : : const char *expected_namespaces[] = { "GLib", NULL };
57 : : #endif
58 : : char **versions;
59 : : size_t n_versions;
60 : 1 : const char *prefix = NULL;
61 : :
62 : 1 : g_test_summary ("Test basic opening of a repository and requiring a typelib");
63 : :
64 : 1 : versions = gi_repository_enumerate_versions (fx->repository, "SomeInvalidNamespace", &n_versions);
65 : 1 : g_assert_nonnull (versions);
66 : 1 : g_assert_cmpstrv (versions, ((char *[]){NULL}));
67 : 1 : g_assert_cmpuint (n_versions, ==, 0);
68 : 1 : g_clear_pointer (&versions, g_strfreev);
69 : :
70 : 1 : versions = gi_repository_enumerate_versions (fx->repository, "GLib", NULL);
71 : 1 : g_assert_nonnull (versions);
72 : 2 : g_assert_cmpstrv (versions, ((char *[]){"2.0", NULL}));
73 : 1 : g_clear_pointer (&versions, g_strfreev);
74 : :
75 : 1 : search_paths = gi_repository_get_search_path (fx->repository, NULL);
76 : 1 : g_assert_nonnull (search_paths);
77 : 1 : g_assert_cmpuint (g_strv_length ((char **) search_paths), >, 0);
78 : 1 : g_assert_cmpstr (search_paths[0], ==, fx->gobject_typelib_dir);
79 : :
80 : 1 : namespaces = gi_repository_get_loaded_namespaces (fx->repository, &n_namespaces);
81 : 3 : g_assert_cmpstrv (namespaces, expected_namespaces);
82 : 1 : g_assert_cmpuint (n_namespaces, ==, g_strv_length ((char **) expected_namespaces));
83 : 1 : g_strfreev (namespaces);
84 : :
85 : 1 : prefix = gi_repository_get_c_prefix (fx->repository, "GLib");
86 : 1 : g_assert_nonnull (prefix);
87 : 1 : g_assert_cmpstr (prefix, ==, "G");
88 : 1 : }
89 : :
90 : : static void
91 : 1 : test_repository_info (RepositoryFixture *fx,
92 : : const void *unused)
93 : : {
94 : 1 : GIBaseInfo *not_found_info = NULL;
95 : 1 : GIObjectInfo *object_info = NULL, *object_info_by_gtype = NULL;
96 : 1 : GISignalInfo *signal_info = NULL;
97 : 1 : GIFunctionInfo *method_info = NULL;
98 : : GType gtype;
99 : :
100 : 1 : g_test_summary ("Test retrieving some basic info blobs from a typelib");
101 : :
102 : 1 : not_found_info = gi_repository_find_by_name (fx->repository, "GObject", "ThisDoesNotExist");
103 : 1 : g_assert_null (not_found_info);
104 : :
105 : 1 : object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
106 : 1 : g_assert_nonnull (object_info);
107 : 1 : g_assert_true (GI_IS_OBJECT_INFO (object_info));
108 : 1 : g_assert_true (GI_IS_REGISTERED_TYPE_INFO (object_info));
109 : 1 : g_assert_true (GI_IS_BASE_INFO (object_info));
110 : :
111 : 1 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (object_info)), ==, "Object");
112 : 1 : g_assert_cmpstr (gi_base_info_get_namespace (GI_BASE_INFO (object_info)), ==, "GObject");
113 : :
114 : 1 : gtype = gi_registered_type_info_get_g_type (GI_REGISTERED_TYPE_INFO (object_info));
115 : 1 : g_assert_true (g_type_is_a (gtype, G_TYPE_OBJECT));
116 : :
117 : 1 : object_info_by_gtype = GI_OBJECT_INFO (gi_repository_find_by_gtype (fx->repository, G_TYPE_OBJECT));
118 : 1 : g_assert_nonnull (object_info);
119 : :
120 : 1 : signal_info = gi_object_info_find_signal (object_info, "does-not-exist");
121 : 1 : g_assert_null (signal_info);
122 : :
123 : 1 : signal_info = gi_object_info_find_signal (object_info, "notify");
124 : 1 : g_assert_nonnull (signal_info);
125 : 1 : g_assert_true (GI_IS_SIGNAL_INFO (signal_info));
126 : 1 : g_assert_true (GI_IS_CALLABLE_INFO (signal_info));
127 : 1 : g_assert_true (GI_IS_BASE_INFO (signal_info));
128 : :
129 : 1 : g_assert_cmpint (gi_signal_info_get_flags (signal_info), ==,
130 : : G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS | G_SIGNAL_ACTION);
131 : :
132 : 1 : g_assert_cmpuint (gi_object_info_get_n_methods (object_info), >, 2);
133 : :
134 : 1 : method_info = gi_object_info_find_method (object_info, "get_property");
135 : 1 : g_assert_nonnull (method_info);
136 : 1 : g_assert_true (GI_IS_FUNCTION_INFO (method_info));
137 : 1 : g_assert_true (GI_IS_CALLABLE_INFO (method_info));
138 : 1 : g_assert_true (GI_IS_BASE_INFO (method_info));
139 : :
140 : 1 : g_assert_true (gi_callable_info_is_method (GI_CALLABLE_INFO (method_info)));
141 : 1 : g_assert_cmpuint (gi_callable_info_get_n_args (GI_CALLABLE_INFO (method_info)), ==, 2);
142 : 1 : g_clear_pointer (&method_info, gi_base_info_unref);
143 : :
144 : 1 : method_info = gi_object_info_get_method (object_info,
145 : 1 : gi_object_info_get_n_methods (object_info) - 1);
146 : 1 : g_assert_true (gi_callable_info_is_method (GI_CALLABLE_INFO (method_info)));
147 : 1 : g_assert_cmpuint (gi_callable_info_get_n_args (GI_CALLABLE_INFO (method_info)), >, 0);
148 : 1 : g_clear_pointer (&method_info, gi_base_info_unref);
149 : :
150 : 1 : gi_base_info_unref (signal_info);
151 : 1 : gi_base_info_unref (object_info);
152 : 1 : gi_base_info_unref (object_info_by_gtype);
153 : 1 : }
154 : :
155 : : static void
156 : 1 : test_repository_dependencies (RepositoryFixture *fx,
157 : : const void *unused)
158 : : {
159 : 1 : GError *error = NULL;
160 : : char **dependencies;
161 : : size_t n_dependencies;
162 : :
163 : 1 : g_test_summary ("Test ensures namespace dependencies are correctly exposed");
164 : :
165 : 1 : dependencies = gi_repository_get_dependencies (fx->repository, "GObject", &n_dependencies);
166 : 1 : g_assert_cmpuint (g_strv_length (dependencies), ==, 1);
167 : 1 : g_assert_cmpuint (n_dependencies, ==, 1);
168 : 1 : g_assert_true (g_strv_contains ((const char **) dependencies, "GLib-2.0"));
169 : :
170 : 1 : g_clear_error (&error);
171 : 1 : g_clear_pointer (&dependencies, g_strfreev);
172 : 1 : }
173 : :
174 : : static void
175 : 1 : test_repository_base_info_clear (RepositoryFixture *fx,
176 : : const void *unused)
177 : : {
178 : 1 : GITypeInfo zeroed_type_info = { 0, };
179 : : GITypeInfo idempotent_type_info;
180 : 1 : GIObjectInfo *object_info = NULL;
181 : 1 : GIFunctionInfo *method_info = NULL;
182 : 1 : GIArgInfo *arg_info = NULL;
183 : :
184 : 1 : g_test_summary ("Test calling gi_base_info_clear() on a zero-filled struct");
185 : :
186 : : /* Load a valid #GITypeInfo onto the stack and clear it multiple times to
187 : : * check gi_base_info_clear() is idempotent after the first call. */
188 : 1 : object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
189 : 1 : g_assert_nonnull (object_info);
190 : 1 : method_info = gi_object_info_find_method (object_info, "get_property");
191 : 1 : g_assert_nonnull (method_info);
192 : 1 : arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (method_info), 0);
193 : 1 : g_assert_nonnull (arg_info);
194 : 1 : gi_arg_info_load_type_info (arg_info, &idempotent_type_info);
195 : :
196 : 1 : gi_base_info_clear (&idempotent_type_info);
197 : 1 : gi_base_info_clear (&idempotent_type_info);
198 : 1 : gi_base_info_clear (&idempotent_type_info);
199 : :
200 : 1 : g_clear_pointer (&arg_info, gi_base_info_unref);
201 : 1 : g_clear_pointer (&method_info, gi_base_info_unref);
202 : 1 : g_clear_pointer (&object_info, gi_base_info_unref);
203 : :
204 : : /* Try clearing a #GITypeInfo which has always been zero-filled on the stack. */
205 : 1 : gi_base_info_clear (&zeroed_type_info);
206 : 1 : gi_base_info_clear (&zeroed_type_info);
207 : 1 : gi_base_info_clear (&zeroed_type_info);
208 : 1 : }
209 : :
210 : : static void
211 : 1 : test_repository_arg_info (RepositoryFixture *fx,
212 : : const void *unused)
213 : : {
214 : 1 : GIObjectInfo *object_info = NULL;
215 : 1 : GIStructInfo *struct_info = NULL;
216 : 1 : GIFunctionInfo *method_info = NULL;
217 : 1 : GIArgInfo *arg_info = NULL;
218 : 1 : GITypeInfo *type_info = NULL;
219 : : GITypeInfo type_info_stack;
220 : : unsigned int idx;
221 : :
222 : 1 : g_test_summary ("Test retrieving GIArgInfos from a typelib");
223 : :
224 : : /* Test all the methods of GIArgInfo. Here we’re looking at the
225 : : * `const char *property_name` argument of g_object_get_property(). (The
226 : : * ‘self’ argument is not exposed through gi_callable_info_get_arg().) */
227 : 1 : object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
228 : 1 : g_assert_nonnull (object_info);
229 : :
230 : 1 : method_info = gi_object_info_find_method (object_info, "get_property");
231 : 1 : g_assert_nonnull (method_info);
232 : :
233 : 1 : arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (method_info), 0);
234 : 1 : g_assert_nonnull (arg_info);
235 : :
236 : 1 : g_assert_cmpint (gi_arg_info_get_direction (arg_info), ==, GI_DIRECTION_IN);
237 : 1 : g_assert_false (gi_arg_info_is_return_value (arg_info));
238 : 1 : g_assert_false (gi_arg_info_is_optional (arg_info));
239 : 1 : g_assert_false (gi_arg_info_is_caller_allocates (arg_info));
240 : 1 : g_assert_false (gi_arg_info_may_be_null (arg_info));
241 : 1 : g_assert_false (gi_arg_info_is_skip (arg_info));
242 : 1 : g_assert_cmpint (gi_arg_info_get_ownership_transfer (arg_info), ==, GI_TRANSFER_NOTHING);
243 : 1 : g_assert_cmpint (gi_arg_info_get_scope (arg_info), ==, GI_SCOPE_TYPE_INVALID);
244 : 1 : g_assert_false (gi_arg_info_get_closure_index (arg_info, NULL));
245 : 1 : g_assert_false (gi_arg_info_get_closure_index (arg_info, &idx));
246 : 1 : g_assert_cmpuint (idx, ==, 0);
247 : 1 : g_assert_false (gi_arg_info_get_destroy_index (arg_info, NULL));
248 : 1 : g_assert_false (gi_arg_info_get_destroy_index (arg_info, &idx));
249 : 1 : g_assert_cmpuint (idx, ==, 0);
250 : :
251 : 1 : type_info = gi_arg_info_get_type_info (arg_info);
252 : 1 : g_assert_nonnull (type_info);
253 : 1 : g_assert_true (gi_type_info_is_pointer (type_info));
254 : 1 : g_assert_cmpint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_UTF8);
255 : :
256 : 1 : gi_arg_info_load_type_info (arg_info, &type_info_stack);
257 : 1 : g_assert_true (gi_type_info_is_pointer (&type_info_stack) == gi_type_info_is_pointer (type_info));
258 : 1 : g_assert_cmpint (gi_type_info_get_tag (&type_info_stack), ==, gi_type_info_get_tag (type_info));
259 : :
260 : 1 : gi_base_info_clear (&type_info_stack);
261 : 1 : g_clear_pointer (&type_info, gi_base_info_unref);
262 : :
263 : 1 : g_clear_pointer (&arg_info, gi_base_info_unref);
264 : 1 : g_clear_pointer (&method_info, gi_base_info_unref);
265 : 1 : g_clear_pointer (&object_info, gi_base_info_unref);
266 : :
267 : : /* Test an (out) argument. Here it’s the `guint *n_properties` from
268 : : * g_object_class_list_properties(). */
269 : 1 : struct_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "ObjectClass"));
270 : 1 : g_assert_nonnull (struct_info);
271 : :
272 : 1 : method_info = gi_struct_info_find_method (struct_info, "list_properties");
273 : 1 : g_assert_nonnull (method_info);
274 : :
275 : 1 : arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (method_info), 0);
276 : 1 : g_assert_nonnull (arg_info);
277 : :
278 : 1 : g_assert_cmpint (gi_arg_info_get_direction (arg_info), ==, GI_DIRECTION_OUT);
279 : 1 : g_assert_false (gi_arg_info_is_optional (arg_info));
280 : 1 : g_assert_false (gi_arg_info_is_caller_allocates (arg_info));
281 : 1 : g_assert_cmpint (gi_arg_info_get_ownership_transfer (arg_info), ==, GI_TRANSFER_EVERYTHING);
282 : :
283 : 1 : g_clear_pointer (&arg_info, gi_base_info_unref);
284 : 1 : g_clear_pointer (&method_info, gi_base_info_unref);
285 : 1 : g_clear_pointer (&struct_info, gi_base_info_unref);
286 : 1 : }
287 : :
288 : : static void
289 : 1 : test_repository_callable_info (RepositoryFixture *fx,
290 : : const void *unused)
291 : : {
292 : 1 : GIObjectInfo *object_info = NULL;
293 : 1 : GIFunctionInfo *method_info = NULL;
294 : : GICallableInfo *callable_info;
295 : 1 : GITypeInfo *type_info = NULL;
296 : : GITypeInfo type_info_stack;
297 : 1 : GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
298 : : const char *name, *value;
299 : 1 : GIArgInfo *arg_info = NULL;
300 : : GIArgInfo arg_info_stack;
301 : :
302 : 1 : g_test_summary ("Test retrieving GICallableInfos from a typelib");
303 : :
304 : : /* Test all the methods of GICallableInfo. Here we’re looking at
305 : : * g_object_get_qdata(). */
306 : 1 : object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
307 : 1 : g_assert_nonnull (object_info);
308 : :
309 : 1 : method_info = gi_object_info_find_method (object_info, "get_qdata");
310 : 1 : g_assert_nonnull (method_info);
311 : :
312 : 1 : callable_info = GI_CALLABLE_INFO (method_info);
313 : :
314 : 1 : g_assert_true (gi_callable_info_is_method (callable_info));
315 : 1 : g_assert_false (gi_callable_info_can_throw_gerror (callable_info));
316 : :
317 : 1 : type_info = gi_callable_info_get_return_type (callable_info);
318 : 1 : g_assert_nonnull (type_info);
319 : 1 : g_assert_true (gi_type_info_is_pointer (type_info));
320 : 1 : g_assert_cmpint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_VOID);
321 : :
322 : 1 : gi_callable_info_load_return_type (callable_info, &type_info_stack);
323 : 1 : g_assert_true (gi_type_info_is_pointer (&type_info_stack) == gi_type_info_is_pointer (type_info));
324 : 1 : g_assert_cmpint (gi_type_info_get_tag (&type_info_stack), ==, gi_type_info_get_tag (type_info));
325 : :
326 : 1 : gi_base_info_clear (&type_info_stack);
327 : 1 : g_clear_pointer (&type_info, gi_base_info_unref);
328 : :
329 : : /* This method has no attributes */
330 : 1 : g_assert_false (gi_callable_info_iterate_return_attributes (callable_info, &iter, &name, &value));
331 : :
332 : 1 : g_assert_null (gi_callable_info_get_return_attribute (callable_info, "doesnt-exist"));
333 : :
334 : 1 : g_assert_false (gi_callable_info_get_caller_owns (callable_info));
335 : 1 : g_assert_true (gi_callable_info_may_return_null (callable_info));
336 : 1 : g_assert_false (gi_callable_info_skip_return (callable_info));
337 : :
338 : 1 : g_assert_cmpuint (gi_callable_info_get_n_args (callable_info), ==, 1);
339 : :
340 : 1 : arg_info = gi_callable_info_get_arg (callable_info, 0);
341 : 1 : g_assert_nonnull (arg_info);
342 : :
343 : 1 : gi_callable_info_load_arg (callable_info, 0, &arg_info_stack);
344 : 1 : g_assert_cmpint (gi_arg_info_get_direction (&arg_info_stack), ==, gi_arg_info_get_direction (arg_info));
345 : 1 : g_assert_true (gi_arg_info_may_be_null (&arg_info_stack) == gi_arg_info_may_be_null (arg_info));
346 : :
347 : 1 : gi_base_info_clear (&arg_info_stack);
348 : 1 : g_clear_pointer (&arg_info, gi_base_info_unref);
349 : :
350 : 1 : g_assert_cmpint (gi_callable_info_get_instance_ownership_transfer (callable_info), ==, GI_TRANSFER_NOTHING);
351 : :
352 : 1 : g_clear_pointer (&method_info, gi_base_info_unref);
353 : 1 : g_clear_pointer (&object_info, gi_base_info_unref);
354 : 1 : }
355 : :
356 : : static void
357 : 1 : test_repository_callback_info (RepositoryFixture *fx,
358 : : const void *unused)
359 : : {
360 : 1 : GICallbackInfo *callback_info = NULL;
361 : :
362 : 1 : g_test_summary ("Test retrieving GICallbackInfos from a typelib");
363 : :
364 : : /* Test all the methods of GICallbackInfo. This is simple, because there are none. */
365 : 1 : callback_info = GI_CALLBACK_INFO (gi_repository_find_by_name (fx->repository, "GObject", "ObjectFinalizeFunc"));
366 : 1 : g_assert_nonnull (callback_info);
367 : :
368 : 1 : g_clear_pointer (&callback_info, gi_base_info_unref);
369 : 1 : }
370 : :
371 : : static void
372 : 1 : test_repository_char_types (RepositoryFixture *fx,
373 : : const void *unused)
374 : : {
375 : : GIStructInfo *gvalue_info;
376 : : GIFunctionInfo *method_info;
377 : : GITypeInfo *type_info;
378 : :
379 : 1 : g_test_summary ("Test that signed and unsigned char GITypeInfo have GITypeTag of INT8 and UINT8 respectively");
380 : :
381 : 1 : gvalue_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Value"));
382 : 1 : g_assert_nonnull (gvalue_info);
383 : :
384 : : /* unsigned char */
385 : 1 : method_info = gi_struct_info_find_method (gvalue_info, "get_uchar");
386 : 1 : g_assert_nonnull (method_info);
387 : :
388 : 1 : type_info = gi_callable_info_get_return_type (GI_CALLABLE_INFO (method_info));
389 : 1 : g_assert_nonnull (type_info);
390 : 1 : g_assert_cmpuint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_UINT8);
391 : :
392 : 1 : g_clear_pointer (&type_info, gi_base_info_unref);
393 : 1 : g_clear_pointer (&method_info, gi_base_info_unref);
394 : :
395 : : /* signed char */
396 : 1 : method_info = gi_struct_info_find_method (gvalue_info, "get_schar");
397 : 1 : g_assert_nonnull (method_info);
398 : :
399 : 1 : type_info = gi_callable_info_get_return_type (GI_CALLABLE_INFO (method_info));
400 : 1 : g_assert_nonnull (type_info);
401 : 1 : g_assert_cmpuint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_INT8);
402 : :
403 : 1 : g_clear_pointer (&type_info, gi_base_info_unref);
404 : 1 : g_clear_pointer (&method_info, gi_base_info_unref);
405 : 1 : g_clear_pointer (&gvalue_info, gi_base_info_unref);
406 : 1 : }
407 : :
408 : : static void
409 : 1 : test_repository_constructor_return_type (RepositoryFixture *fx,
410 : : const void *unused)
411 : : {
412 : 1 : GIObjectInfo *object_info = NULL;
413 : 1 : GIFunctionInfo *constructor = NULL;
414 : 1 : GITypeInfo *return_type = NULL;
415 : 1 : GIBaseInfo *return_info = NULL;
416 : 1 : const char *class_name = NULL;
417 : 1 : const char *return_name = NULL;
418 : :
419 : 1 : g_test_summary ("Test the return type of a constructor, g_object_newv()");
420 : :
421 : 1 : object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
422 : 1 : g_assert_nonnull (object_info);
423 : :
424 : 1 : class_name = gi_registered_type_info_get_type_name (GI_REGISTERED_TYPE_INFO (object_info));
425 : 1 : g_assert_nonnull (class_name);
426 : :
427 : 1 : constructor = gi_object_info_find_method (object_info, "newv");
428 : 1 : g_assert_nonnull (constructor);
429 : :
430 : 1 : return_type = gi_callable_info_get_return_type (GI_CALLABLE_INFO (constructor));
431 : 1 : g_assert_nonnull (return_type);
432 : 1 : g_assert_cmpuint (gi_type_info_get_tag (return_type), ==, GI_TYPE_TAG_INTERFACE);
433 : :
434 : 1 : return_info = gi_type_info_get_interface (return_type);
435 : 1 : g_assert_nonnull (return_info);
436 : :
437 : 1 : return_name = gi_registered_type_info_get_type_name (GI_REGISTERED_TYPE_INFO (return_info));
438 : 1 : g_assert_nonnull (return_name);
439 : 1 : g_assert_cmpstr (class_name, ==, return_name);
440 : :
441 : 1 : g_clear_pointer (&return_info, gi_base_info_unref);
442 : 1 : g_clear_pointer (&return_type, gi_base_info_unref);
443 : 1 : g_clear_pointer (&constructor, gi_base_info_unref);
444 : 1 : g_clear_pointer (&object_info, gi_base_info_unref);
445 : 1 : }
446 : :
447 : : static void
448 : 1 : test_repository_enum_info_c_identifier (RepositoryFixture *fx,
449 : : const void *unused)
450 : : {
451 : 1 : GIBaseInfo *info = NULL;
452 : 1 : GIValueInfo *value_info = NULL;
453 : : unsigned n_infos, n_values, ix, jx;
454 : 1 : const char *c_identifier = NULL;
455 : :
456 : 1 : g_test_summary ("Test that every enum member has a C identifier");
457 : :
458 : 1 : n_infos = gi_repository_get_n_infos (fx->repository, "GLib");
459 : :
460 : 971 : for (ix = 0; ix < n_infos; ix++)
461 : : {
462 : 970 : info = gi_repository_get_info (fx->repository, "GLib", ix);
463 : :
464 : 970 : if (GI_IS_ENUM_INFO (info))
465 : : {
466 : 60 : n_values = gi_enum_info_get_n_values (GI_ENUM_INFO (info));
467 : 806 : for (jx = 0; jx < n_values; jx++)
468 : : {
469 : 746 : value_info = gi_enum_info_get_value (GI_ENUM_INFO (info), jx);
470 : 746 : c_identifier = gi_base_info_get_attribute (GI_BASE_INFO (value_info), "c:identifier");
471 : 746 : g_assert_nonnull (c_identifier);
472 : :
473 : 746 : g_clear_pointer (&value_info, gi_base_info_unref);
474 : : }
475 : : }
476 : :
477 : 970 : g_clear_pointer (&info, gi_base_info_unref);
478 : : }
479 : 1 : }
480 : :
481 : : static void
482 : 1 : test_repository_enum_info_static_methods (RepositoryFixture *fx,
483 : : const void *unused)
484 : : {
485 : 1 : GIEnumInfo *enum_info = NULL;
486 : : unsigned n_methods, ix;
487 : 1 : GIFunctionInfo *function_info = NULL;
488 : : GIFunctionInfoFlags flags;
489 : 1 : const char *symbol = NULL;
490 : :
491 : 1 : g_test_summary ("Test an enum with methods");
492 : :
493 : 1 : enum_info = GI_ENUM_INFO (gi_repository_find_by_name (fx->repository, "GLib", "UnicodeScript"));
494 : 1 : g_assert_nonnull (enum_info);
495 : :
496 : 1 : n_methods = gi_enum_info_get_n_methods (enum_info);
497 : 1 : g_assert_cmpuint (n_methods, >, 0);
498 : :
499 : 3 : for (ix = 0; ix < n_methods; ix++)
500 : : {
501 : 2 : function_info = gi_enum_info_get_method (enum_info, ix);
502 : 2 : g_assert_nonnull (function_info);
503 : :
504 : 2 : flags = gi_function_info_get_flags (function_info);
505 : 2 : g_assert_false (flags & GI_FUNCTION_IS_METHOD); /* must be static */
506 : :
507 : 2 : symbol = gi_function_info_get_symbol (function_info);
508 : 2 : g_assert_nonnull (symbol);
509 : 2 : g_assert_true (g_str_has_prefix (symbol, "g_unicode_script_"));
510 : :
511 : 2 : g_clear_pointer (&function_info, gi_base_info_unref);
512 : : }
513 : :
514 : 1 : g_clear_pointer (&enum_info, gi_base_info_unref);
515 : 1 : }
516 : :
517 : : static void
518 : 1 : test_repository_error_quark (RepositoryFixture *fx,
519 : : const void *unused)
520 : : {
521 : 1 : GIEnumInfo *error_info = NULL;
522 : :
523 : 1 : g_test_summary ("Test finding an error quark by error domain");
524 : :
525 : : /* Find a simple error domain. */
526 : 1 : error_info = gi_repository_find_by_error_domain (fx->repository, G_RESOLVER_ERROR);
527 : 1 : g_assert_nonnull (error_info);
528 : 1 : g_assert_true (GI_IS_ENUM_INFO (error_info));
529 : 1 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (error_info)), ==, "ResolverError");
530 : :
531 : 1 : g_clear_pointer (&error_info, gi_base_info_unref);
532 : :
533 : : /* Find again to check the caching. */
534 : 1 : error_info = gi_repository_find_by_error_domain (fx->repository, G_RESOLVER_ERROR);
535 : 1 : g_assert_nonnull (error_info);
536 : 1 : g_assert_true (GI_IS_ENUM_INFO (error_info));
537 : 1 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (error_info)), ==, "ResolverError");
538 : :
539 : 1 : g_clear_pointer (&error_info, gi_base_info_unref);
540 : :
541 : : /* Try and find an unknown error domain. */
542 : 1 : g_assert_null (gi_repository_find_by_error_domain (fx->repository, GI_REPOSITORY_ERROR));
543 : :
544 : : /* And check caching for unknown error domains. */
545 : 1 : g_assert_null (gi_repository_find_by_error_domain (fx->repository, GI_REPOSITORY_ERROR));
546 : :
547 : : /* It would be good to try and find one which will resolve in both Gio and
548 : : * GioUnix/GioWin32, but neither of the platform-specific GIRs actually define
549 : : * any error domains at the moment. */
550 : 1 : }
551 : :
552 : : static void
553 : 1 : test_repository_flags_info_c_identifier (RepositoryFixture *fx,
554 : : const void *unused)
555 : : {
556 : 1 : GIBaseInfo *info = NULL;
557 : 1 : GIValueInfo *value_info = NULL;
558 : : unsigned n_infos, n_values, ix, jx;
559 : 1 : const char *c_identifier = NULL;
560 : :
561 : 1 : g_test_summary ("Test that every flags member has a C identifier");
562 : :
563 : 1 : n_infos = gi_repository_get_n_infos (fx->repository, "GLib");
564 : :
565 : 971 : for (ix = 0; ix < n_infos; ix++)
566 : : {
567 : 970 : info = gi_repository_get_info (fx->repository, "GLib", ix);
568 : :
569 : 970 : if (GI_IS_FLAGS_INFO (info))
570 : : {
571 : 22 : n_values = gi_enum_info_get_n_values (GI_ENUM_INFO (info));
572 : 181 : for (jx = 0; jx < n_values; jx++)
573 : : {
574 : 159 : value_info = gi_enum_info_get_value (GI_ENUM_INFO (info), jx);
575 : 159 : c_identifier = gi_base_info_get_attribute (GI_BASE_INFO (value_info), "c:identifier");
576 : 159 : g_assert_nonnull (c_identifier);
577 : :
578 : 159 : g_clear_pointer (&value_info, gi_base_info_unref);
579 : : }
580 : : }
581 : :
582 : 970 : g_clear_pointer (&info, gi_base_info_unref);
583 : : }
584 : 1 : }
585 : :
586 : : static void
587 : 1 : test_repository_fundamental_ref_func (RepositoryFixture *fx,
588 : : const void *unused)
589 : : {
590 : : GIObjectInfo *info;
591 : :
592 : 1 : g_test_summary ("Test getting the ref func of a fundamental type");
593 : :
594 : 1 : info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "ParamSpec"));
595 : 1 : g_assert_nonnull (info);
596 : :
597 : 1 : g_assert_nonnull (gi_object_info_get_ref_function_pointer (info));
598 : :
599 : 1 : g_clear_pointer (&info, gi_base_info_unref);
600 : 1 : }
601 : :
602 : : static void
603 : 1 : test_repository_instance_method_ownership_transfer (RepositoryFixture *fx,
604 : : const void *unused)
605 : : {
606 : 1 : GIObjectInfo *class_info = NULL;
607 : 1 : GIFunctionInfo *func_info = NULL;
608 : : GITransfer transfer;
609 : :
610 : 1 : g_test_summary ("Test two methods of the same object having opposite ownership transfer of the instance parameter");
611 : :
612 : 1 : class_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "DBusMethodInvocation"));
613 : 1 : g_assert_nonnull (class_info);
614 : :
615 : 1 : func_info = gi_object_info_find_method (class_info, "get_connection");
616 : 1 : g_assert_nonnull (func_info);
617 : 1 : transfer = gi_callable_info_get_instance_ownership_transfer (GI_CALLABLE_INFO (func_info));
618 : 1 : g_assert_cmpint (GI_TRANSFER_NOTHING, ==, transfer);
619 : :
620 : 1 : g_clear_pointer (&func_info, gi_base_info_unref);
621 : :
622 : 1 : func_info = gi_object_info_find_method (class_info, "return_error_literal");
623 : 1 : g_assert_nonnull (func_info);
624 : 1 : transfer = gi_callable_info_get_instance_ownership_transfer (GI_CALLABLE_INFO (func_info));
625 : 1 : g_assert_cmpint (GI_TRANSFER_EVERYTHING, ==, transfer);
626 : :
627 : 1 : g_clear_pointer (&func_info, gi_base_info_unref);
628 : 1 : g_clear_pointer (&class_info, gi_base_info_unref);
629 : 1 : }
630 : :
631 : : static void
632 : 1 : test_repository_object_gtype_interfaces (RepositoryFixture *fx,
633 : : const void *unused)
634 : : {
635 : : GIInterfaceInfo **interfaces;
636 : : size_t n_interfaces, ix;
637 : : const char *name;
638 : 1 : gboolean found_initable = FALSE, found_async_initable = FALSE;
639 : :
640 : 1 : g_test_summary ("Test gi_repository_get_object_gtype_interfaces()");
641 : :
642 : 1 : gi_repository_get_object_gtype_interfaces (fx->repository, G_TYPE_DBUS_CONNECTION, &n_interfaces, &interfaces);
643 : :
644 : 1 : g_assert_cmpuint (n_interfaces, ==, 2);
645 : :
646 : 3 : for (ix = 0; ix < n_interfaces; ix++)
647 : : {
648 : 2 : name = gi_base_info_get_name (GI_BASE_INFO (*(interfaces + ix)));
649 : 2 : if (strcmp (name, "Initable") == 0)
650 : 1 : found_initable = TRUE;
651 : 1 : else if (strcmp (name, "AsyncInitable") == 0)
652 : 1 : found_async_initable = TRUE;
653 : : }
654 : :
655 : 1 : g_assert_true (found_initable);
656 : 1 : g_assert_true (found_async_initable);
657 : 1 : }
658 : :
659 : : static void
660 : 1 : test_repository_signal_info_with_array_length_arg (RepositoryFixture *fx,
661 : : const void *unused)
662 : : {
663 : 1 : GIObjectInfo *gsettings_info = NULL;
664 : 1 : GISignalInfo *sig_info = NULL;
665 : 1 : GIArgInfo *arg_info = NULL;
666 : 1 : GITypeInfo *type_info = NULL;
667 : : unsigned length_ix;
668 : :
669 : 1 : g_test_summary ("Test finding the associated array length argument of an array parameter of a signal");
670 : :
671 : 1 : gsettings_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "Settings"));
672 : 1 : g_assert_nonnull (gsettings_info);
673 : :
674 : 1 : sig_info = gi_object_info_find_signal (gsettings_info, "change-event");
675 : 1 : g_assert_nonnull (sig_info);
676 : :
677 : 1 : g_assert_cmpuint (gi_callable_info_get_n_args (GI_CALLABLE_INFO (sig_info)), ==, 2);
678 : :
679 : : /* verify array argument */
680 : 1 : arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (sig_info), 0);
681 : 1 : g_assert_nonnull (arg_info);
682 : 1 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (arg_info)), ==, "keys");
683 : :
684 : 1 : type_info = gi_arg_info_get_type_info (arg_info);
685 : 1 : g_assert_nonnull (type_info);
686 : 1 : g_assert_cmpint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_ARRAY);
687 : 1 : g_assert_cmpint (gi_type_info_get_array_type (type_info), ==, GI_ARRAY_TYPE_C);
688 : 1 : g_assert_false (gi_type_info_is_zero_terminated (type_info));
689 : 1 : gboolean ok = gi_type_info_get_array_length_index (type_info, &length_ix);
690 : 1 : g_assert_true (ok);
691 : 1 : g_assert_cmpuint (length_ix, ==, 1);
692 : :
693 : 1 : g_clear_pointer (&arg_info, gi_base_info_unref);
694 : 1 : g_clear_pointer (&type_info, gi_base_info_unref);
695 : :
696 : : /* verify array length argument */
697 : 1 : arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (sig_info), 1);
698 : 1 : g_assert_nonnull (arg_info);
699 : 1 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (arg_info)), ==, "n_keys");
700 : :
701 : 1 : g_clear_pointer (&arg_info, gi_base_info_unref);
702 : 1 : g_clear_pointer (&type_info, gi_base_info_unref);
703 : 1 : g_clear_pointer (&sig_info, gi_base_info_unref);
704 : 1 : g_clear_pointer (&gsettings_info, gi_base_info_unref);
705 : 1 : }
706 : :
707 : : static void
708 : 1 : test_repository_type_info_name (RepositoryFixture *fx,
709 : : const void *unused)
710 : : {
711 : 1 : GIInterfaceInfo *interface_info = NULL;
712 : : GIVFuncInfo *vfunc;
713 : : GITypeInfo *typeinfo;
714 : :
715 : 1 : g_test_summary ("Test that gi_base_info_get_name() returns null for GITypeInfo");
716 : 1 : g_test_bug ("https://gitlab.gnome.org/GNOME/gobject-introspection/issues/96");
717 : :
718 : 1 : interface_info = GI_INTERFACE_INFO (gi_repository_find_by_name (fx->repository, "Gio", "File"));
719 : 1 : g_assert_nonnull (interface_info);
720 : 1 : vfunc = gi_interface_info_find_vfunc (interface_info, "read_async");
721 : 1 : g_assert_nonnull (vfunc);
722 : :
723 : 1 : typeinfo = gi_callable_info_get_return_type (GI_CALLABLE_INFO (vfunc));
724 : 1 : g_assert_nonnull (typeinfo);
725 : :
726 : 1 : g_assert_null (gi_base_info_get_name (GI_BASE_INFO (typeinfo)));
727 : :
728 : 1 : g_clear_pointer (&interface_info, gi_base_info_unref);
729 : 1 : g_clear_pointer (&vfunc, gi_base_info_unref);
730 : 1 : g_clear_pointer (&typeinfo, gi_base_info_unref);
731 : 1 : }
732 : :
733 : : static void
734 : 1 : test_repository_vfunc_info_with_no_invoker (RepositoryFixture *fx,
735 : : const void *unused)
736 : : {
737 : 1 : GIObjectInfo *object_info = NULL;
738 : 1 : GIVFuncInfo *vfunc_info = NULL;
739 : 1 : GIFunctionInfo *invoker_info = NULL;
740 : :
741 : 1 : g_test_summary ("Test vfunc with no known invoker on object, such as GObject.dispose");
742 : :
743 : 1 : object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Object"));
744 : 1 : g_assert_nonnull (object_info);
745 : :
746 : 1 : vfunc_info = gi_object_info_find_vfunc (object_info, "dispose");
747 : 1 : g_assert_nonnull (vfunc_info);
748 : :
749 : 1 : invoker_info = gi_vfunc_info_get_invoker (vfunc_info);
750 : 1 : g_assert_null (invoker_info);
751 : :
752 : 1 : g_clear_pointer (&object_info, gi_base_info_unref);
753 : 1 : g_clear_pointer (&vfunc_info, gi_base_info_unref);
754 : 1 : }
755 : :
756 : : static void
757 : 1 : test_repository_vfunc_info_with_invoker_on_interface (RepositoryFixture *fx,
758 : : const void *unused)
759 : : {
760 : 1 : GIInterfaceInfo *interface_info = NULL;
761 : 1 : GIVFuncInfo *vfunc_info = NULL;
762 : 1 : GIFunctionInfo *invoker_info = NULL;
763 : :
764 : 1 : g_test_summary ("Test vfunc with invoker on interface, such as GFile.read_async");
765 : :
766 : 1 : interface_info = GI_INTERFACE_INFO (gi_repository_find_by_name (fx->repository, "Gio", "File"));
767 : 1 : g_assert_nonnull (interface_info);
768 : :
769 : 1 : vfunc_info = gi_interface_info_find_vfunc (interface_info, "read_async");
770 : 1 : g_assert_nonnull (vfunc_info);
771 : :
772 : 1 : invoker_info = gi_vfunc_info_get_invoker (vfunc_info);
773 : 1 : g_assert_nonnull (invoker_info);
774 : :
775 : 1 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (invoker_info)), ==, "read_async");
776 : :
777 : 1 : g_clear_pointer (&interface_info, gi_base_info_unref);
778 : 1 : g_clear_pointer (&vfunc_info, gi_base_info_unref);
779 : 1 : g_clear_pointer (&invoker_info, gi_base_info_unref);
780 : 1 : }
781 : :
782 : : static void
783 : 1 : test_repository_vfunc_info_with_invoker_on_object (RepositoryFixture *fx,
784 : : const void *unused)
785 : : {
786 : 1 : GIObjectInfo *object_info = NULL;
787 : 1 : GIVFuncInfo *vfunc_info = NULL;
788 : 1 : GIFunctionInfo *invoker_info = NULL;
789 : :
790 : 1 : g_test_summary ("Test vfunc with invoker on object, such as GAppLaunchContext.get_display");
791 : :
792 : 1 : object_info = GI_OBJECT_INFO (gi_repository_find_by_name (fx->repository, "Gio", "AppLaunchContext"));
793 : 1 : g_assert_nonnull (object_info);
794 : :
795 : 1 : vfunc_info = gi_object_info_find_vfunc (object_info, "get_display");
796 : 1 : g_assert_nonnull (vfunc_info);
797 : :
798 : 1 : invoker_info = gi_vfunc_info_get_invoker (vfunc_info);
799 : 1 : g_assert_nonnull (invoker_info);
800 : 1 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (invoker_info)), ==, "get_display");
801 : :
802 : : /* And let's be sure we can find the method directly */
803 : 1 : g_clear_pointer (&invoker_info, gi_base_info_unref);
804 : :
805 : 1 : invoker_info = gi_object_info_find_method (object_info, "get_display");
806 : 1 : g_assert_nonnull (invoker_info);
807 : 1 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (invoker_info)), ==, "get_display");
808 : :
809 : 1 : g_clear_pointer (&object_info, gi_base_info_unref);
810 : 1 : g_clear_pointer (&vfunc_info, gi_base_info_unref);
811 : 1 : g_clear_pointer (&invoker_info, gi_base_info_unref);
812 : 1 : }
813 : :
814 : : static void
815 : 1 : test_repository_find_by_gtype (RepositoryFixture *fx,
816 : : const void *unused)
817 : : {
818 : 1 : GIObjectInfo *object_info = NULL;
819 : :
820 : 1 : g_test_summary ("Test finding a GType");
821 : :
822 : 1 : object_info = (GIObjectInfo *) gi_repository_find_by_gtype (fx->repository, G_TYPE_OBJECT);
823 : 1 : g_assert_nonnull (object_info);
824 : 1 : g_assert_true (GI_IS_OBJECT_INFO (object_info));
825 : 1 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (object_info)), ==, "Object");
826 : :
827 : 1 : g_clear_pointer (&object_info, gi_base_info_unref);
828 : :
829 : : /* Find it again; this time it should hit the cache. */
830 : 1 : object_info = (GIObjectInfo *) gi_repository_find_by_gtype (fx->repository, G_TYPE_OBJECT);
831 : 1 : g_assert_nonnull (object_info);
832 : 1 : g_assert_true (GI_IS_OBJECT_INFO (object_info));
833 : 1 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (object_info)), ==, "Object");
834 : :
835 : 1 : g_clear_pointer (&object_info, gi_base_info_unref);
836 : :
837 : : /* Try and find an unknown GType. */
838 : 1 : g_assert_null (gi_repository_find_by_gtype (fx->repository, GI_TYPE_BASE_INFO));
839 : :
840 : : /* And check caching for unknown GTypes. */
841 : 1 : g_assert_null (gi_repository_find_by_gtype (fx->repository, GI_TYPE_BASE_INFO));
842 : :
843 : : /* Now try and find one which will resolve in both Gio and GioUnix/GioWin32.
844 : : * The longest-named typelib should be returned. */
845 : : {
846 : : GType platform_specific_type;
847 : : const char *expected_name, *expected_namespace;
848 : :
849 : : #if defined(G_OS_UNIX) && !(__APPLE__)
850 : 1 : platform_specific_type = G_TYPE_DESKTOP_APP_INFO;
851 : 1 : expected_name = "DesktopAppInfo";
852 : 1 : expected_namespace = "GioUnix";
853 : : #elif defined(G_OS_WIN32)
854 : : platform_specific_type = G_TYPE_WIN32_INPUT_STREAM;
855 : : expected_name = "InputStream";
856 : : expected_namespace = "GioWin32";
857 : : #else
858 : : platform_specific_type = G_TYPE_INVALID;
859 : : expected_name = NULL;
860 : : expected_namespace = NULL;
861 : : #endif
862 : :
863 : 1 : if (expected_name != NULL)
864 : : {
865 : 1 : object_info = (GIObjectInfo *) gi_repository_find_by_gtype (fx->repository, platform_specific_type);
866 : 1 : g_assert_nonnull (object_info);
867 : 1 : g_assert_true (GI_IS_OBJECT_INFO (object_info));
868 : 1 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (object_info)), ==, expected_name);
869 : 1 : g_assert_cmpstr (gi_base_info_get_namespace (GI_BASE_INFO (object_info)), ==, expected_namespace);
870 : 1 : g_clear_pointer (&object_info, gi_base_info_unref);
871 : : }
872 : : }
873 : 1 : }
874 : :
875 : : static void
876 : 1 : test_repository_loaded_namespaces (RepositoryFixture *fx,
877 : : const void *unused)
878 : : {
879 : : char **namespaces;
880 : : size_t n_namespaces;
881 : :
882 : : /* These should be in alphabetical order */
883 : : #if defined(G_OS_UNIX)
884 : 1 : const char *expected_namespaces[] = { "GLib", "GModule", "GObject", "Gio", "GioUnix", NULL };
885 : : #elif defined(G_OS_WIN32)
886 : : const char *expected_namespaces[] = { "GLib", "GModule", "GObject", "Gio", "GioWin32", NULL };
887 : : #else
888 : : const char *expected_namespaces[] = { "GLib", "GModule", "GObject", "Gio", NULL };
889 : : #endif
890 : :
891 : 1 : g_test_summary ("Test listing loaded namespaces");
892 : :
893 : 1 : namespaces = gi_repository_get_loaded_namespaces (fx->repository, &n_namespaces);
894 : 6 : g_assert_cmpstrv (namespaces, expected_namespaces);
895 : 1 : g_assert_cmpuint (n_namespaces, ==, g_strv_length ((char **) expected_namespaces));
896 : 1 : g_strfreev (namespaces);
897 : :
898 : : /* Test again but without passing `n_namespaces`. */
899 : 1 : namespaces = gi_repository_get_loaded_namespaces (fx->repository, NULL);
900 : 6 : g_assert_cmpstrv (namespaces, expected_namespaces);
901 : 1 : g_strfreev (namespaces);
902 : 1 : }
903 : :
904 : : static void
905 : 1 : test_repository_dup_default (void)
906 : : {
907 : 1 : GIRepository *repository1 = gi_repository_dup_default ();
908 : 1 : GIRepository *repository2 = gi_repository_dup_default ();
909 : :
910 : 1 : g_assert_nonnull (repository1);
911 : 1 : g_assert_nonnull (repository2);
912 : 1 : g_assert_true (repository1 == repository2);
913 : :
914 : 1 : g_clear_object (&repository1);
915 : 1 : g_clear_object (&repository2);
916 : 1 : }
917 : :
918 : : int
919 : 1 : main (int argc,
920 : : char *argv[])
921 : : {
922 : 1 : repository_init (&argc, &argv);
923 : :
924 : 1 : ADD_REPOSITORY_TEST ("/repository/basic", test_repository_basic, &typelib_load_spec_glib);
925 : 1 : ADD_REPOSITORY_TEST ("/repository/info", test_repository_info, &typelib_load_spec_gobject);
926 : 1 : ADD_REPOSITORY_TEST ("/repository/dependencies", test_repository_dependencies, &typelib_load_spec_gobject);
927 : 1 : ADD_REPOSITORY_TEST ("/repository/base-info/clear", test_repository_base_info_clear, &typelib_load_spec_gobject);
928 : 1 : ADD_REPOSITORY_TEST ("/repository/arg-info", test_repository_arg_info, &typelib_load_spec_gobject);
929 : 1 : ADD_REPOSITORY_TEST ("/repository/callable-info", test_repository_callable_info, &typelib_load_spec_gobject);
930 : 1 : ADD_REPOSITORY_TEST ("/repository/callback-info", test_repository_callback_info, &typelib_load_spec_gobject);
931 : 1 : ADD_REPOSITORY_TEST ("/repository/char-types", test_repository_char_types, &typelib_load_spec_gobject);
932 : 1 : ADD_REPOSITORY_TEST ("/repository/constructor-return-type", test_repository_constructor_return_type, &typelib_load_spec_gobject);
933 : 1 : ADD_REPOSITORY_TEST ("/repository/enum-info-c-identifier", test_repository_enum_info_c_identifier, &typelib_load_spec_glib);
934 : 1 : ADD_REPOSITORY_TEST ("/repository/enum-info-static-methods", test_repository_enum_info_static_methods, &typelib_load_spec_glib);
935 : 1 : ADD_REPOSITORY_TEST ("/repository/error-quark", test_repository_error_quark, &typelib_load_spec_gio);
936 : 1 : ADD_REPOSITORY_TEST ("/repository/flags-info-c-identifier", test_repository_flags_info_c_identifier, &typelib_load_spec_gobject);
937 : 1 : ADD_REPOSITORY_TEST ("/repository/fundamental-ref-func", test_repository_fundamental_ref_func, &typelib_load_spec_gobject);
938 : 1 : ADD_REPOSITORY_TEST ("/repository/instance-method-ownership-transfer", test_repository_instance_method_ownership_transfer, &typelib_load_spec_gio);
939 : 1 : ADD_REPOSITORY_TEST ("/repository/object-gtype-interfaces", test_repository_object_gtype_interfaces, &typelib_load_spec_gio);
940 : 1 : ADD_REPOSITORY_TEST ("/repository/signal-info-with-array-length-arg", test_repository_signal_info_with_array_length_arg, &typelib_load_spec_gio);
941 : 1 : ADD_REPOSITORY_TEST ("/repository/type-info-name", test_repository_type_info_name, &typelib_load_spec_gio);
942 : 1 : ADD_REPOSITORY_TEST ("/repository/vfunc-info-with-no-invoker", test_repository_vfunc_info_with_no_invoker, &typelib_load_spec_gobject);
943 : 1 : ADD_REPOSITORY_TEST ("/repository/vfunc-info-with-invoker-on-interface", test_repository_vfunc_info_with_invoker_on_interface, &typelib_load_spec_gio);
944 : 1 : ADD_REPOSITORY_TEST ("/repository/vfunc-info-with-invoker-on-object", test_repository_vfunc_info_with_invoker_on_object, &typelib_load_spec_gio);
945 : 1 : ADD_REPOSITORY_TEST ("/repository/find-by-gtype", test_repository_find_by_gtype, &typelib_load_spec_gio);
946 : 1 : ADD_REPOSITORY_TEST ("/repository/loaded-namespaces", test_repository_loaded_namespaces, &typelib_load_spec_gio);
947 : 1 : g_test_add_func ("/repository/dup_default", test_repository_dup_default);
948 : :
949 : 1 : return g_test_run ();
950 : : }
|