1 /* Unit tests for GIOModule
2 * Copyright (C) 2013 Red Hat, Inc
3 * Author: Matthias Clasen
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.
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.
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.
26 test_extension_point (void)
28 GIOExtensionPoint
*ep
, *ep2
;
34 ep
= g_io_extension_point_lookup ("test-extension-point");
36 ep
= g_io_extension_point_register ("test-extension-point");
37 ep2
= g_io_extension_point_lookup ("test-extension-point");
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
);
46 list
= g_io_extension_point_get_extensions (ep
);
49 g_io_extension_point_implement ("test-extension-point",
54 g_io_extension_point_implement ("test-extension-point",
59 list
= g_io_extension_point_get_extensions (ep
);
60 g_assert_cmpint (g_list_length (list
), ==, 2);
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);
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);
77 test_module_scan_all (void)
79 if (g_test_subprocess ())
81 GIOExtensionPoint
*ep
;
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);
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");
95 g_test_trap_subprocess (NULL
, 0, 7);
96 g_test_trap_assert_passed ();
100 test_module_scan_all_with_scope (void)
102 if (g_test_subprocess ())
104 GIOExtensionPoint
*ep
;
105 GIOModuleScope
*scope
;
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);
118 g_assert_cmpstr (g_io_extension_get_name (ext
), ==, "test-a");
119 g_io_module_scope_free (scope
);
122 g_test_trap_subprocess (NULL
, 0, 7);
123 g_test_trap_assert_passed ();
127 main (int argc
, char *argv
[])
129 g_test_init (&argc
, &argv
, NULL
);
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
);
135 return g_test_run ();