1 /* -*- Mode: C; c-basic-offset: 4 -*-
2 * vim: tabstop=4 shiftwidth=4 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++) {
27 info = g_irepository_get_info (repo, "GIMarshallingTests", i);
29 /* both GI_INFO_TYPE_ENUM and GI_INFO_TYPE_FLAGS use GIEnumInfo */
30 if (GI_IS_ENUM_INFO (info)) {
33 n_values = g_enum_info_get_n_values ((GIEnumInfo *) info);
34 for (j = 0; j < n_values; j++) {
35 GIValueInfo *value_info;
36 const gchar *c_identifier = NULL;
38 value_info = g_enum_info_get_value ((GIEnumInfo *) info, j);
39 c_identifier = g_base_info_get_attribute ((GIBaseInfo *) value_info, "c:identifier");
41 if (c_identifier == NULL) {
42 g_error ("Error: no 'c:identifier' attribute on GIMarshallingTests.%s.%s\n",
43 g_base_info_get_name (info),
44 g_base_info_get_name ((GIBaseInfo *) value_info));
47 g_base_info_unref ((GIBaseInfo *) value_info);
51 g_base_info_unref (info);
56 _check_enum_methods (GIBaseInfo *info, const gchar *name, const gchar *prefix)
60 n_methods = g_enum_info_get_n_methods ((GIEnumInfo *) info);
62 g_error ("%s should have methods", name);
64 for (i = 0; i < n_methods; i += n_methods-1) {
65 GIBaseInfo *function_info;
66 GIFunctionInfoFlags flags;
68 function_info = g_enum_info_get_method ((GIEnumInfo *) info, i);
70 g_error ("Could not find %s method nr. %d", name, i+1);
71 flags = g_function_info_get_flags ((GIFunctionInfo *) function_info);
73 g_error ("%s methods should be static", name);
74 symbol = g_function_info_get_symbol ((GIFunctionInfo *) function_info);
75 if (!symbol || !g_str_has_prefix (symbol, prefix))
76 g_error ("Could not find valid function symbol");
77 g_base_info_unref (function_info);
82 test_enum_and_flags_static_methods(GIRepository *repo)
86 GIBaseInfo *enum_info;
88 ret = g_irepository_require (repo, "GIMarshallingTests", NULL, 0, &error);
90 g_error ("%s", error->message);
92 enum_info = g_irepository_find_by_name (repo, "GIMarshallingTests", "GEnum");
94 g_error ("Could not find GIMarshallingTests.GEnum");
95 _check_enum_methods (enum_info,
96 "GIMarshallingTests.GEnum",
97 "gi_marshalling_tests_genum_");
98 g_base_info_unref (enum_info);
100 enum_info = g_irepository_find_by_name (repo, "GIMarshallingTests", "Flags");
102 g_error ("Could not find GIMarshallingTests.Flags");
103 _check_enum_methods (enum_info,
104 "GIMarshallingTests.Flags",
105 "gi_marshalling_tests_flags_");
106 g_base_info_unref (enum_info);
110 test_size_of_gvalue(GIRepository *repo)
112 GIBaseInfo *struct_info;
114 struct_info = g_irepository_find_by_name (repo, "GObject", "Value");
116 g_error ("Could not find GObject.Value");
117 g_assert_cmpuint (g_struct_info_get_size (struct_info), ==, sizeof (GValue));
118 g_base_info_unref (struct_info);
122 test_is_pointer_for_struct_arg (GIRepository *repo)
125 GError *error = NULL;
126 GIStructInfo *variant_info;
127 GIFunctionInfo *equal_info;
129 GITypeInfo *type_info;
131 ret = g_irepository_require (repo, "GLib", NULL, 0, &error);
133 g_error ("%s", error->message);
135 variant_info = g_irepository_find_by_name (repo, "GLib", "Variant");
137 g_error ("Could not find GLib.Variant");
139 equal_info = g_struct_info_find_method (variant_info, "equal");
141 g_error ("Could not find GLib.Variant.equal()");
143 arg_info = g_callable_info_get_arg (equal_info, 0);
145 g_error ("Could not find 1st arg of GLib.Variant.equal()");
147 type_info = g_arg_info_get_type (arg_info);
149 g_error ("Could not find typeinfo of 1st arg of GLib.Variant.equal()");
151 g_assert (g_type_info_is_pointer (type_info));
153 g_base_info_unref (type_info);
154 g_base_info_unref (arg_info);
155 g_base_info_unref (equal_info);
156 g_base_info_unref (variant_info);
160 test_fundamental_get_ref_function_pointer (GIRepository *repo)
164 g_assert (g_irepository_require (repo, "Regress", NULL, 0, NULL));
165 info = g_irepository_find_by_name (repo, "Regress",
166 "TestFundamentalObject");
167 g_object_info_get_ref_function_pointer (info);
168 g_base_info_unref (info);
172 main(int argc, char **argv)
178 repo = g_irepository_get_default ();
181 test_enum_and_flags_cidentifier (repo);
182 test_enum_and_flags_static_methods (repo);
183 test_size_of_gvalue (repo);
184 test_is_pointer_for_struct_arg (repo);
185 test_fundamental_get_ref_function_pointer (repo);