2007-04-17 Jeffrey Stedfast <fejj@gnome.org>
[mono.git] / eglib / test / module.c
1 #include <glib.h>
2 #include <gmodule.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include "test.h"
7
8 #if defined (G_OS_WIN32)
9 #define EXTERNAL_SYMBOL "GetProcAddress"
10 #else
11 #define EXTERNAL_SYMBOL "system"
12 #endif
13
14 void G_MODULE_EXPORT
15 dummy_test_export ()
16 {
17 }
18
19 /* test for g_module_open (NULL, ...) */
20 RESULT
21 test_module_symbol_null ()
22 {
23         gpointer proc = GINT_TO_POINTER (42);
24
25         GModule *m = g_module_open (NULL, G_MODULE_BIND_LAZY);
26
27         if (m == NULL)
28                 return FAILED ("bind to main module failed. #0");
29
30         if (g_module_symbol (m, "__unlikely_\nexistent__", &proc))
31                 return FAILED ("non-existent symbol lookup failed. #1");
32
33         if (proc)
34                 return FAILED ("non-existent symbol lookup failed. #2");
35
36         if (!g_module_symbol (m, EXTERNAL_SYMBOL, &proc))
37                 return FAILED ("external lookup failed. #3");
38
39         if (!proc)
40                 return FAILED ("external lookup failed. #4");
41
42         if (!g_module_symbol (m, "dummy_test_export", &proc))
43                 return FAILED ("in-proc lookup failed. #5");
44
45         if (!proc)
46                 return FAILED ("in-proc lookup failed. #6");
47
48         if (!g_module_close (m))
49                 return FAILED ("close failed. #7");
50
51         return OK;
52 }
53
54 static Test module_tests [] = {
55         {"g_module_symbol_null", test_module_symbol_null},
56         {NULL, NULL}
57 };
58
59 DEFINE_TEST_GROUP_INIT(module_tests_init, module_tests)
60