hook gvariant vectors up to kdbus
[platform/upstream/glib.git] / gio / tests / giomodule.c
1 /* Unit tests for GIOModule
2  * Copyright (C) 2013 Red Hat, Inc
3  * Author: Matthias Clasen
4  *
5  * This work is provided "as is"; redistribution and modification
6  * in whole or in part, in any medium, physical or electronic is
7  * permitted without restriction.
8  *
9  * This work is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * In no event shall the authors or contributors be liable for any
14  * direct, indirect, incidental, special, exemplary, or consequential
15  * damages (including, but not limited to, procurement of substitute
16  * goods or services; loss of use, data, or profits; or business
17  * interruption) however caused and on any theory of liability, whether
18  * in contract, strict liability, or tort (including negligence or
19  * otherwise) arising in any way out of the use of this software, even
20  * if advised of the possibility of such damage.
21  */
22
23 #include <gio/gio.h>
24
25 static void
26 test_extension_point (void)
27 {
28   GIOExtensionPoint *ep, *ep2;
29   GIOExtension *ext;
30   GList *list;
31   GType req;
32   GTypeClass *class;
33
34   ep = g_io_extension_point_lookup ("test-extension-point");
35   g_assert_null (ep);
36   ep = g_io_extension_point_register ("test-extension-point");
37   ep2 = g_io_extension_point_lookup ("test-extension-point");
38   g_assert (ep2 == ep);
39
40   req = g_io_extension_point_get_required_type (ep);
41   g_assert (req == G_TYPE_INVALID);
42   g_io_extension_point_set_required_type (ep, G_TYPE_OBJECT);
43   req = g_io_extension_point_get_required_type (ep);
44   g_assert (req == G_TYPE_OBJECT);
45
46   list = g_io_extension_point_get_extensions (ep);
47   g_assert_null (list);
48
49   g_io_extension_point_implement ("test-extension-point",
50                                   G_TYPE_VFS,
51                                   "extension1",
52                                   10);
53
54   g_io_extension_point_implement ("test-extension-point",
55                                   G_TYPE_OBJECT,
56                                   "extension2",
57                                   20);
58
59   list = g_io_extension_point_get_extensions (ep);
60   g_assert_cmpint (g_list_length (list), ==, 2);
61   
62   ext = list->data;
63   g_assert_cmpstr (g_io_extension_get_name (ext), ==, "extension2");
64   g_assert (g_io_extension_get_type (ext) == G_TYPE_OBJECT);
65   g_assert (g_io_extension_get_priority (ext) == 20);
66   class = g_io_extension_ref_class (ext);
67   g_assert (class == g_type_class_peek (G_TYPE_OBJECT));
68   g_type_class_unref (class);
69
70   ext = list->next->data;
71   g_assert_cmpstr (g_io_extension_get_name (ext), ==, "extension1");
72   g_assert (g_io_extension_get_type (ext) == G_TYPE_VFS);
73   g_assert (g_io_extension_get_priority (ext) == 10);
74 }
75
76 static void
77 test_module_scan_all (void)
78 {
79   if (g_test_subprocess ())
80     {
81       GIOExtensionPoint *ep;
82       GIOExtension *ext;
83       GList *list;
84       ep = g_io_extension_point_register ("test-extension-point");
85       g_io_modules_scan_all_in_directory (g_test_get_filename (G_TEST_BUILT, "modules", NULL));
86       g_io_modules_scan_all_in_directory (g_test_get_filename (G_TEST_BUILT, "modules/.libs", NULL));
87       list = g_io_extension_point_get_extensions (ep);
88       g_assert_cmpint (g_list_length (list), ==, 2);
89       ext = list->data;
90       g_assert_cmpstr (g_io_extension_get_name (ext), ==, "test-b");
91       ext = list->next->data;
92       g_assert_cmpstr (g_io_extension_get_name (ext), ==, "test-a");
93       return;
94     }
95   g_test_trap_subprocess (NULL, 0, 7);
96   g_test_trap_assert_passed ();
97 }
98
99 static void
100 test_module_scan_all_with_scope (void)
101 {
102   if (g_test_subprocess ())
103     {
104       GIOExtensionPoint *ep;
105       GIOModuleScope *scope;
106       GIOExtension *ext;
107       GList *list;
108
109       ep = g_io_extension_point_register ("test-extension-point");
110       scope = g_io_module_scope_new (G_IO_MODULE_SCOPE_BLOCK_DUPLICATES);
111       g_io_module_scope_block (scope, "libtestmoduleb." G_MODULE_SUFFIX);
112       g_io_modules_scan_all_in_directory_with_scope (g_test_get_filename (G_TEST_BUILT, "modules", NULL), scope);
113       list = g_io_extension_point_get_extensions (ep);
114       g_io_modules_scan_all_in_directory_with_scope (g_test_get_filename (G_TEST_BUILT, "modules/.libs", NULL), scope);
115       list = g_io_extension_point_get_extensions (ep);
116       g_assert_cmpint (g_list_length (list), ==, 1);
117       ext = list->data;
118       g_assert_cmpstr (g_io_extension_get_name (ext), ==, "test-a");
119       g_io_module_scope_free (scope);
120       return;
121     }
122   g_test_trap_subprocess (NULL, 0, 7);
123   g_test_trap_assert_passed ();
124 }
125
126 int
127 main (int argc, char *argv[])
128 {
129   g_test_init (&argc, &argv, NULL);
130
131   g_test_add_func ("/giomodule/extension-point", test_extension_point);
132   g_test_add_func ("/giomodule/module-scan-all", test_module_scan_all);
133   g_test_add_func ("/giomodule/module-scan-all-with-scope", test_module_scan_all_with_scope);
134
135   return g_test_run ();
136 }