1 /* -*- Mode: C; c-basic-offset: 2 -*-
2 * vim: shiftwidth=2 expandtab
5 #include "girepository.h"
12 test_enum_and_flags_cidentifier (GIRepository * repo)
18 ret = g_irepository_require (repo, "GIMarshallingTests", NULL, 0, &error);
20 g_error ("%s", error->message);
22 n_infos = g_irepository_get_n_infos (repo, "GIMarshallingTests");
24 for (i = 0; i < n_infos; i++)
28 info = g_irepository_get_info (repo, "GIMarshallingTests", i);
30 /* both GI_INFO_TYPE_ENUM and GI_INFO_TYPE_FLAGS use GIEnumInfo */
31 if (GI_IS_ENUM_INFO (info))
35 n_values = g_enum_info_get_n_values ((GIEnumInfo *) info);
36 for (j = 0; j < n_values; j++)
38 GIValueInfo *value_info;
39 const gchar *c_identifier = NULL;
41 value_info = g_enum_info_get_value ((GIEnumInfo *) info, j);
42 c_identifier = g_base_info_get_attribute ((GIBaseInfo *) value_info, "c:identifier");
44 if (c_identifier == NULL)
47 ("Error: no 'c:identifier' attribute on GIMarshallingTests.%s.%s\n",
48 g_base_info_get_name (info), g_base_info_get_name ((GIBaseInfo *) value_info));
51 g_base_info_unref ((GIBaseInfo *) value_info);
55 g_base_info_unref (info);
60 _check_enum_methods (GIBaseInfo * info, const gchar * name, const gchar * prefix)
64 n_methods = g_enum_info_get_n_methods ((GIEnumInfo *) info);
66 g_error ("%s should have methods", name);
68 for (i = 0; i < n_methods; i += n_methods - 1)
70 GIBaseInfo *function_info;
71 GIFunctionInfoFlags flags;
73 function_info = g_enum_info_get_method ((GIEnumInfo *) info, i);
75 g_error ("Could not find %s method nr. %d", name, i + 1);
76 flags = g_function_info_get_flags ((GIFunctionInfo *) function_info);
78 g_error ("%s methods should be static", name);
79 symbol = g_function_info_get_symbol ((GIFunctionInfo *) function_info);
80 if (!symbol || !g_str_has_prefix (symbol, prefix))
81 g_error ("Could not find valid function symbol");
82 g_base_info_unref (function_info);
87 test_enum_and_flags_static_methods (GIRepository * repo)
91 GIBaseInfo *enum_info;
93 ret = g_irepository_require (repo, "GIMarshallingTests", NULL, 0, &error);
95 g_error ("%s", error->message);
97 enum_info = g_irepository_find_by_name (repo, "GIMarshallingTests", "GEnum");
99 g_error ("Could not find GIMarshallingTests.GEnum");
100 _check_enum_methods (enum_info, "GIMarshallingTests.GEnum", "gi_marshalling_tests_genum_");
101 g_base_info_unref (enum_info);
103 enum_info = g_irepository_find_by_name (repo, "GIMarshallingTests", "Flags");
105 g_error ("Could not find GIMarshallingTests.Flags");
106 _check_enum_methods (enum_info, "GIMarshallingTests.Flags", "gi_marshalling_tests_flags_");
107 g_base_info_unref (enum_info);
111 test_size_of_gvalue (GIRepository * repo)
113 GIBaseInfo *struct_info;
115 struct_info = g_irepository_find_by_name (repo, "GObject", "Value");
117 g_error ("Could not find GObject.Value");
118 g_assert_cmpuint (g_struct_info_get_size (struct_info), ==, sizeof (GValue));
119 g_base_info_unref (struct_info);
123 test_is_pointer_for_struct_arg (GIRepository * repo)
126 GError *error = NULL;
127 GIStructInfo *variant_info;
128 GIFunctionInfo *equal_info;
130 GITypeInfo *type_info;
132 ret = g_irepository_require (repo, "GLib", NULL, 0, &error);
134 g_error ("%s", error->message);
136 variant_info = g_irepository_find_by_name (repo, "GLib", "Variant");
138 g_error ("Could not find GLib.Variant");
140 equal_info = g_struct_info_find_method (variant_info, "equal");
142 g_error ("Could not find GLib.Variant.equal()");
144 arg_info = g_callable_info_get_arg (equal_info, 0);
146 g_error ("Could not find 1st arg of GLib.Variant.equal()");
148 type_info = g_arg_info_get_type (arg_info);
150 g_error ("Could not find typeinfo of 1st arg of GLib.Variant.equal()");
152 g_assert (g_type_info_is_pointer (type_info));
154 g_base_info_unref (type_info);
155 g_base_info_unref (arg_info);
156 g_base_info_unref (equal_info);
157 g_base_info_unref (variant_info);
161 test_fundamental_get_ref_function_pointer (GIRepository * repo)
165 g_assert (g_irepository_require (repo, "Regress", NULL, 0, NULL));
166 info = g_irepository_find_by_name (repo, "Regress", "TestFundamentalObject");
167 g_object_info_get_ref_function_pointer (info);
168 g_base_info_unref (info);
172 test_hash_with_cairo_typelib (GIRepository * repo)
176 g_assert (g_irepository_require (repo, "cairo", NULL, 0, NULL));
177 info = g_irepository_find_by_name (repo, "cairo", "region");
178 g_assert (info == NULL);
181 static GIPropertyInfo *
182 lookup_property (GIObjectInfo * info, const gchar * name)
186 GIPropertyInfo *property_info;
188 n_props = g_object_info_get_n_properties (info);
189 for (i = 0; i < n_props; i++)
191 property_info = g_object_info_get_property (info, i);
192 if (strcmp (name, g_base_info_get_name (property_info)) == 0)
193 return property_info;
194 g_base_info_unref (property_info);
201 test_char_types (GIRepository * repo)
204 GError *error = NULL;
205 GIBaseInfo *prop_obj;
206 GIPropertyInfo *prop_info;
207 GITypeInfo *type_info;
209 ret = g_irepository_require (repo, "GIMarshallingTests", NULL, 0, &error);
211 g_error ("%s", error->message);
213 prop_obj = g_irepository_find_by_name (repo, "GIMarshallingTests", "PropertiesObject");
214 g_assert (prop_obj != NULL);
215 g_assert (GI_IS_OBJECT_INFO (prop_obj));
218 prop_info = lookup_property ((GIObjectInfo *) prop_obj, "some-uchar");
219 g_assert (prop_info != NULL);
220 type_info = g_property_info_get_type (prop_info);
221 g_assert_cmpuint (g_type_info_get_tag (type_info), ==, GI_TYPE_TAG_UINT8);
222 g_base_info_unref (type_info);
223 g_base_info_unref (prop_info);
226 prop_info = lookup_property ((GIObjectInfo *) prop_obj, "some-char");
227 g_assert (prop_info != NULL);
228 type_info = g_property_info_get_type (prop_info);
229 g_assert_cmpuint (g_type_info_get_tag (type_info), ==, GI_TYPE_TAG_INT8);
230 g_base_info_unref (type_info);
231 g_base_info_unref (prop_info);
233 g_base_info_unref (prop_obj);
237 test_signal_array_len (GIRepository * repo)
239 GIObjectInfo *testobj_info;
240 GISignalInfo *sig_info;
242 GITypeInfo type_info;
245 g_assert (g_irepository_require (repo, "Regress", NULL, 0, NULL));
246 testobj_info = g_irepository_find_by_name (repo, "Regress", "TestObj");
247 g_assert (testobj_info != NULL);
249 /* find sig-with-array-len-prop signal */
250 for (i = g_object_info_get_n_signals (testobj_info) - 1; i >= 0; --i)
252 sig_info = g_object_info_get_signal (testobj_info, i);
253 g_assert (sig_info != NULL);
254 if (strcmp (g_base_info_get_name (sig_info), "sig-with-array-len-prop") == 0)
256 g_base_info_unref (sig_info);
260 g_assert_cmpint (g_callable_info_get_n_args (sig_info), ==, 2);
262 /* verify array argument */
263 g_callable_info_load_arg (sig_info, 0, &arg_info);
264 g_assert_cmpstr (g_base_info_get_name (&arg_info), ==, "arr");
265 g_arg_info_load_type (&arg_info, &type_info);
266 g_assert_cmpint (g_type_info_get_tag (&type_info), ==, GI_TYPE_TAG_ARRAY);
267 g_assert_cmpint (g_type_info_get_array_type (&type_info), ==, GI_ARRAY_TYPE_C);
268 g_assert (!g_type_info_is_zero_terminated (&type_info));
269 g_assert_cmpint (g_type_info_get_array_length (&type_info), ==, 1);
271 /* verify array length argument */
272 g_callable_info_load_arg (sig_info, 1, &arg_info);
273 g_assert_cmpstr (g_base_info_get_name (&arg_info), ==, "len");
275 g_base_info_unref (sig_info);
276 g_base_info_unref (testobj_info);
280 main (int argc, char **argv)
284 repo = g_irepository_get_default ();
287 test_enum_and_flags_cidentifier (repo);
288 test_enum_and_flags_static_methods (repo);
289 test_size_of_gvalue (repo);
290 test_is_pointer_for_struct_arg (repo);
291 test_fundamental_get_ref_function_pointer (repo);
292 test_hash_with_cairo_typelib (repo);
293 test_char_types (repo);
294 test_signal_array_len (repo);