sl@0
|
1 |
/* module-test.c - test program for GMODULE
|
sl@0
|
2 |
* Copyright (C) 1998 Tim Janik
|
sl@0
|
3 |
* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
sl@0
|
4 |
* This library is free software; you can redistribute it and/or
|
sl@0
|
5 |
* modify it under the terms of the GNU Lesser General Public
|
sl@0
|
6 |
* License as published by the Free Software Foundation; either
|
sl@0
|
7 |
* version 2 of the License, or (at your option) any later version.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* This library is distributed in the hope that it will be useful,
|
sl@0
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
sl@0
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
sl@0
|
12 |
* Lesser General Public License for more details.
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* You should have received a copy of the GNU Lesser General Public
|
sl@0
|
15 |
* License along with this library; if not, write to the
|
sl@0
|
16 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
sl@0
|
17 |
* Boston, MA 02111-1307, USA.
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
/*
|
sl@0
|
21 |
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
sl@0
|
22 |
* file for a list of people on the GLib Team. See the ChangeLog
|
sl@0
|
23 |
* files for a list of changes. These files are distributed with
|
sl@0
|
24 |
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
sl@0
|
25 |
*/
|
sl@0
|
26 |
|
sl@0
|
27 |
#undef G_DISABLE_ASSERT
|
sl@0
|
28 |
#undef G_LOG_DOMAIN
|
sl@0
|
29 |
|
sl@0
|
30 |
#include <gmodule.h>
|
sl@0
|
31 |
#include <string.h>
|
sl@0
|
32 |
#include <stdio.h>
|
sl@0
|
33 |
|
sl@0
|
34 |
#ifdef SYMBIAN
|
sl@0
|
35 |
#include "mrt2_glib2_test.h"
|
sl@0
|
36 |
#endif /*SYMBIAN*/
|
sl@0
|
37 |
|
sl@0
|
38 |
|
sl@0
|
39 |
typedef int (*SimpleFunc) (void);
|
sl@0
|
40 |
|
sl@0
|
41 |
int
|
sl@0
|
42 |
main (int arg,
|
sl@0
|
43 |
char *argv[])
|
sl@0
|
44 |
{
|
sl@0
|
45 |
GModule *module_a, *module_b;
|
sl@0
|
46 |
gchar *plugin_a, *plugin_b;
|
sl@0
|
47 |
SimpleFunc f_a, f_b;
|
sl@0
|
48 |
int retVal;
|
sl@0
|
49 |
void *fun1,*fun2;
|
sl@0
|
50 |
gchar *build_path = NULL;
|
sl@0
|
51 |
gchar temp_build_path[100];
|
sl@0
|
52 |
gchar *lib_name = "xyz";
|
sl@0
|
53 |
|
sl@0
|
54 |
#ifdef SYMBIAN
|
sl@0
|
55 |
g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
|
sl@0
|
56 |
g_set_print_handler(mrtPrintHandler);
|
sl@0
|
57 |
#endif /*SYMBIAN*/
|
sl@0
|
58 |
|
sl@0
|
59 |
|
sl@0
|
60 |
if (!g_module_supported ())
|
sl@0
|
61 |
g_print ("dynamic modules not supported");
|
sl@0
|
62 |
|
sl@0
|
63 |
plugin_a = "libmoduletestplugin_a.dll";
|
sl@0
|
64 |
plugin_b = "libmoduletestplugin_b.dll";
|
sl@0
|
65 |
|
sl@0
|
66 |
build_path = g_module_build_path("c:\\sys\\bin",lib_name);
|
sl@0
|
67 |
g_assert(!strcmp(build_path,"c:\\sys\\bin\\xyz.dll"));
|
sl@0
|
68 |
g_free(build_path);
|
sl@0
|
69 |
|
sl@0
|
70 |
build_path = g_module_build_path(NULL,lib_name);
|
sl@0
|
71 |
g_assert(!strcmp(build_path,"xyz.dll"));
|
sl@0
|
72 |
g_free(build_path);
|
sl@0
|
73 |
|
sl@0
|
74 |
/* module handles */
|
sl@0
|
75 |
|
sl@0
|
76 |
module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
|
sl@0
|
77 |
if (!module_a)
|
sl@0
|
78 |
g_print ("error: %s", g_module_error ());
|
sl@0
|
79 |
|
sl@0
|
80 |
module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
|
sl@0
|
81 |
if (!module_b)
|
sl@0
|
82 |
g_print ("error: %s", g_module_error ());
|
sl@0
|
83 |
|
sl@0
|
84 |
/* get plugin specific symbols and call them
|
sl@0
|
85 |
*/
|
sl@0
|
86 |
if (!g_module_symbol (module_a, /*"gplugin_a_func1"*/"1", /*(gpointer *) &f_a*/&fun1))
|
sl@0
|
87 |
g_print ("error: %s", g_module_error ());
|
sl@0
|
88 |
|
sl@0
|
89 |
if (!g_module_symbol (module_b, /*"gplugin_b_func1"*/"1", /*(gpointer *) &f_b)*/&fun2))
|
sl@0
|
90 |
g_print ("error: %s", g_module_error ());
|
sl@0
|
91 |
|
sl@0
|
92 |
f_a = (SimpleFunc)fun1;
|
sl@0
|
93 |
f_b = (SimpleFunc)fun2;
|
sl@0
|
94 |
|
sl@0
|
95 |
retVal = f_a ();
|
sl@0
|
96 |
g_assert(retVal == 1);
|
sl@0
|
97 |
|
sl@0
|
98 |
retVal = f_b ();
|
sl@0
|
99 |
g_assert(retVal == 1);
|
sl@0
|
100 |
|
sl@0
|
101 |
if (!g_module_symbol (module_a, /*"gplugin_a_func2"*/"2", (gpointer *) &f_a))
|
sl@0
|
102 |
g_print ("error: %s", g_module_error ());
|
sl@0
|
103 |
|
sl@0
|
104 |
if (!g_module_symbol (module_b, /*"gplugin_b_func2"*/"2", (gpointer *) &f_b))
|
sl@0
|
105 |
g_print ("error: %s", g_module_error ());
|
sl@0
|
106 |
|
sl@0
|
107 |
retVal = f_a ();
|
sl@0
|
108 |
g_assert(retVal == 2);
|
sl@0
|
109 |
|
sl@0
|
110 |
retVal = f_b ();
|
sl@0
|
111 |
g_assert(retVal == 2);
|
sl@0
|
112 |
|
sl@0
|
113 |
//checks g_module_name
|
sl@0
|
114 |
g_assert(!strcmp(g_module_name(module_a),"libmoduletestplugin_a.dll"));
|
sl@0
|
115 |
|
sl@0
|
116 |
g_module_make_resident(module_a);
|
sl@0
|
117 |
|
sl@0
|
118 |
/* unload plugins */
|
sl@0
|
119 |
|
sl@0
|
120 |
//g_module_close is ignored because g_module_make_resident(module_a) is called
|
sl@0
|
121 |
if (!g_module_close (module_a))
|
sl@0
|
122 |
g_print ("error: %s", g_module_error ());
|
sl@0
|
123 |
|
sl@0
|
124 |
if (!g_module_close (module_b))
|
sl@0
|
125 |
g_print ("error: %s", g_module_error ());
|
sl@0
|
126 |
|
sl@0
|
127 |
|
sl@0
|
128 |
// As g_module_make_resident(module_a) is called g_module_close is ignored and therefore
|
sl@0
|
129 |
// we are able to get the symbol from the library and execute the funtion also
|
sl@0
|
130 |
if (!g_module_symbol (module_a, /*"gplugin_a_func1"*/"1", /*(gpointer *) &f_a*/&fun1))
|
sl@0
|
131 |
g_print ("error: %s", g_module_error ());
|
sl@0
|
132 |
|
sl@0
|
133 |
f_a = (SimpleFunc)fun1;
|
sl@0
|
134 |
|
sl@0
|
135 |
retVal = f_a ();
|
sl@0
|
136 |
g_assert(retVal == 1);
|
sl@0
|
137 |
|
sl@0
|
138 |
#ifdef SYMBIAN
|
sl@0
|
139 |
testResultXml("module-test");
|
sl@0
|
140 |
#endif /* EMULATOR */
|
sl@0
|
141 |
|
sl@0
|
142 |
return 0;
|
sl@0
|
143 |
}
|