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