007ce02ea1a971861dd42076c517c9371a7a7cdd
[gnome.gobject-introspection] / tests / repository / gitestrepo.c
1
2 #include "girepository.h"
3
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
7
8 void test_constructor_return_type(GIBaseInfo* object_info);
9
10 void
11 test_constructor_return_type(GIBaseInfo* object_info)
12 {
13   GIFunctionInfo* constructor;
14   GITypeInfo* return_type;
15   GIBaseInfo *return_info;
16   const gchar* class_name;
17   const gchar* return_name;
18
19   class_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*) object_info);
20   g_assert (class_name);
21
22   constructor = g_object_info_find_method((GIObjectInfo*)object_info, "new");
23   g_assert (constructor);
24
25   return_type = g_callable_info_get_return_type ((GICallableInfo*)constructor);
26   g_assert (return_type);
27   g_assert (g_type_info_get_tag (return_type) == GI_TYPE_TAG_INTERFACE);
28
29   return_info = g_type_info_get_interface (return_type);
30   g_assert (return_info);
31
32   return_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*) return_info);
33   g_assert (strcmp (class_name, return_name) == 0);
34 }
35
36
37 int
38 main(int argc, char **argv)
39 {
40   GIRepository *repo;
41   GTypelib *ret;
42   GError *error = NULL;
43   GIBaseInfo *info;
44   GType gtype;
45   char *girdir;
46
47   g_type_init ();
48
49   repo = g_irepository_get_default ();
50
51   girdir = g_build_filename (g_getenv ("top_builddir"), "gir", NULL);
52   g_irepository_prepend_search_path (girdir);
53   g_free (girdir);
54
55   ret = g_irepository_require (repo, "Gio", NULL, 0, &error);
56   g_assert (ret);
57   g_assert (error == NULL);
58
59   info = g_irepository_find_by_name (repo, "Gio", "Cancellable");
60   g_assert (info != NULL);
61   g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_OBJECT);
62
63   gtype = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *)info);
64   g_assert (g_type_is_a (gtype, G_TYPE_OBJECT));
65
66   info = g_irepository_find_by_gtype (repo, g_type_from_name ("GCancellable"));
67   g_assert (info != NULL);
68
69   g_print ("Successfully found GCancellable\n");
70
71   test_constructor_return_type (info);
72
73   exit(0);
74 }