First public contribution.
1 /* module-test.c - test program for GMODULE
2 * Copyright (C) 1998 Tim Janik
3 * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
27 #undef G_DISABLE_ASSERT
35 #include "mrt2_glib2_test.h"
39 typedef int (*SimpleFunc) (void);
45 GModule *module_a, *module_b;
46 gchar *plugin_a, *plugin_b;
50 gchar *build_path = NULL;
51 gchar temp_build_path[100];
52 gchar *lib_name = "xyz";
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);
56 g_set_print_handler(mrtPrintHandler);
60 if (!g_module_supported ())
61 g_print ("dynamic modules not supported");
63 plugin_a = "libmoduletestplugin_a.dll";
64 plugin_b = "libmoduletestplugin_b.dll";
66 build_path = g_module_build_path("c:\\sys\\bin",lib_name);
67 g_assert(!strcmp(build_path,"c:\\sys\\bin\\xyz.dll"));
70 build_path = g_module_build_path(NULL,lib_name);
71 g_assert(!strcmp(build_path,"xyz.dll"));
76 module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
78 g_print ("error: %s", g_module_error ());
80 module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
82 g_print ("error: %s", g_module_error ());
84 /* get plugin specific symbols and call them
86 if (!g_module_symbol (module_a, /*"gplugin_a_func1"*/"1", /*(gpointer *) &f_a*/&fun1))
87 g_print ("error: %s", g_module_error ());
89 if (!g_module_symbol (module_b, /*"gplugin_b_func1"*/"1", /*(gpointer *) &f_b)*/&fun2))
90 g_print ("error: %s", g_module_error ());
92 f_a = (SimpleFunc)fun1;
93 f_b = (SimpleFunc)fun2;
96 g_assert(retVal == 1);
99 g_assert(retVal == 1);
101 if (!g_module_symbol (module_a, /*"gplugin_a_func2"*/"2", (gpointer *) &f_a))
102 g_print ("error: %s", g_module_error ());
104 if (!g_module_symbol (module_b, /*"gplugin_b_func2"*/"2", (gpointer *) &f_b))
105 g_print ("error: %s", g_module_error ());
108 g_assert(retVal == 2);
111 g_assert(retVal == 2);
113 //checks g_module_name
114 g_assert(!strcmp(g_module_name(module_a),"libmoduletestplugin_a.dll"));
116 g_module_make_resident(module_a);
120 //g_module_close is ignored because g_module_make_resident(module_a) is called
121 if (!g_module_close (module_a))
122 g_print ("error: %s", g_module_error ());
124 if (!g_module_close (module_b))
125 g_print ("error: %s", g_module_error ());
128 // As g_module_make_resident(module_a) is called g_module_close is ignored and therefore
129 // we are able to get the symbol from the library and execute the funtion also
130 if (!g_module_symbol (module_a, /*"gplugin_a_func1"*/"1", /*(gpointer *) &f_a*/&fun1))
131 g_print ("error: %s", g_module_error ());
133 f_a = (SimpleFunc)fun1;
136 g_assert(retVal == 1);
139 testResultXml("module-test");
140 #endif /* EMULATOR */