Branch data Line data Source code
1 : : /*
2 : : * Copyright 2014 Simon Feltman <sfeltman@gnome.org>
3 : : *
4 : : * SPDX-License-Identifier: LGPL-2.1-or-later
5 : : *
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.
10 : : *
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.
15 : : *
16 : : * You should have received a copy of the GNU Lesser General
17 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 : : */
19 : :
20 : : #include "config.h"
21 : :
22 : : #include "girepository.h"
23 : : #include "test-common.h"
24 : :
25 : : static void
26 : 1 : test_field_iterators (RepositoryFixture *fx,
27 : : const void *unused)
28 : : {
29 : 1 : GIStructInfo *class_info = NULL;
30 : 1 : GIFieldInfo *field_info = NULL;
31 : : unsigned ix;
32 : :
33 : 1 : g_test_summary ("Test iterating through a struct's fields with gi_struct_info_get_field()");
34 : :
35 : 1 : class_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "ObjectClass"));
36 : 1 : g_assert_nonnull (class_info);
37 : :
38 : 16 : for (ix = 0; ix < gi_struct_info_get_n_fields (class_info); ix++)
39 : : {
40 : 15 : const char *field_name = NULL;
41 : 15 : GIFieldInfo *found = NULL;
42 : :
43 : 15 : field_info = gi_struct_info_get_field (class_info, ix);
44 : 15 : g_assert_nonnull (field_info);
45 : :
46 : 15 : field_name = gi_base_info_get_name (GI_BASE_INFO (field_info));
47 : 15 : g_assert_nonnull (field_name);
48 : :
49 : 15 : found = gi_struct_info_find_field (class_info, field_name);
50 : 15 : g_assert_nonnull (found);
51 : 15 : g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (found)), ==, field_name);
52 : :
53 : 15 : g_clear_pointer (&found, gi_base_info_unref);
54 : 15 : g_clear_pointer (&field_info, gi_base_info_unref);
55 : : }
56 : :
57 : 1 : field_info = gi_struct_info_find_field (class_info, "not_a_real_field_name");
58 : 1 : g_assert_null (field_info);
59 : :
60 : 1 : g_clear_pointer (&class_info, gi_base_info_unref);
61 : 1 : }
62 : :
63 : : static void
64 : 1 : test_size_of_gvalue (RepositoryFixture *fx,
65 : : const void *unused)
66 : : {
67 : : GIStructInfo *struct_info;
68 : :
69 : 1 : g_test_summary ("Test that gi_struct_info_get_size() reports the correct sizeof GValue");
70 : :
71 : 1 : struct_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "Value"));
72 : 1 : g_assert_nonnull (struct_info);
73 : :
74 : 1 : g_assert_cmpuint (gi_struct_info_get_size (struct_info), ==, sizeof (GValue));
75 : :
76 : 1 : g_clear_pointer (&struct_info, gi_base_info_unref);
77 : 1 : }
78 : :
79 : : static void
80 : 1 : test_is_pointer_for_struct_method_arg (RepositoryFixture *fx,
81 : : const void *unused)
82 : : {
83 : 1 : GIStructInfo *variant_info = NULL;
84 : 1 : GIFunctionInfo *equal_info = NULL;
85 : 1 : GIArgInfo *arg_info = NULL;
86 : 1 : GITypeInfo *type_info = NULL;
87 : :
88 : 1 : g_test_summary ("Test that a struct method reports the correct type with gi_type_info_is_pointer()");
89 : :
90 : 1 : variant_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "GLib", "Variant"));
91 : 1 : g_assert_nonnull (variant_info);
92 : :
93 : 1 : equal_info = gi_struct_info_find_method (variant_info, "equal");
94 : 1 : g_assert_nonnull (equal_info);
95 : :
96 : 1 : arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (equal_info), 0);
97 : 1 : g_assert_nonnull (arg_info);
98 : :
99 : 1 : type_info = gi_arg_info_get_type_info (arg_info);
100 : 1 : g_assert_nonnull (type_info);
101 : 1 : g_assert_true (gi_type_info_is_pointer (type_info));
102 : :
103 : 1 : g_clear_pointer (&type_info, gi_base_info_unref);
104 : 1 : g_clear_pointer (&arg_info, gi_base_info_unref);
105 : 1 : g_clear_pointer (&equal_info, gi_base_info_unref);
106 : 1 : g_clear_pointer (&variant_info, gi_base_info_unref);
107 : 1 : }
108 : :
109 : : static void
110 : 1 : test_boxed (RepositoryFixture *fx,
111 : : const void *unused)
112 : : {
113 : 1 : GIStructInfo *struct_info = NULL;
114 : :
115 : 1 : g_test_summary ("Test that a boxed struct is recognised as such");
116 : :
117 : 1 : struct_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "BookmarkFile"));
118 : 1 : g_assert_nonnull (struct_info);
119 : 1 : g_assert_true (gi_registered_type_info_is_boxed (GI_REGISTERED_TYPE_INFO (struct_info)));
120 : :
121 : 1 : g_clear_pointer (&struct_info, gi_base_info_unref);
122 : 1 : }
123 : :
124 : : int
125 : 1 : main (int argc,
126 : : char *argv[])
127 : : {
128 : 1 : repository_init (&argc, &argv);
129 : :
130 : 1 : ADD_REPOSITORY_TEST ("/struct-info/field-iterators", test_field_iterators, &typelib_load_spec_gobject);
131 : 1 : ADD_REPOSITORY_TEST ("/struct-info/sizeof-gvalue", test_size_of_gvalue, &typelib_load_spec_gobject);
132 : 1 : ADD_REPOSITORY_TEST ("/struct-info/is-pointer-for-struct-method-arg", test_is_pointer_for_struct_method_arg, &typelib_load_spec_glib);
133 : 1 : ADD_REPOSITORY_TEST ("/struct-info/boxed", test_boxed, &typelib_load_spec_gobject);
134 : :
135 : 1 : return g_test_run ();
136 : : }
|