sl@0: /* module-test.c - test program for GMODULE sl@0: * Copyright (C) 1998 Tim Janik sl@0: * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: * This library is free software; you can redistribute it and/or sl@0: * modify it under the terms of the GNU Lesser General Public sl@0: * License as published by the Free Software Foundation; either sl@0: * version 2 of the License, or (at your option) any later version. sl@0: * sl@0: * This library is distributed in the hope that it will be useful, sl@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of sl@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU sl@0: * Lesser General Public License for more details. sl@0: * sl@0: * You should have received a copy of the GNU Lesser General Public sl@0: * License along with this library; if not, write to the sl@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, sl@0: * Boston, MA 02111-1307, USA. sl@0: */ sl@0: sl@0: /* sl@0: * Modified by the GLib Team and others 1997-2000. See the AUTHORS sl@0: * file for a list of people on the GLib Team. See the ChangeLog sl@0: * files for a list of changes. These files are distributed with sl@0: * GLib at ftp://ftp.gtk.org/pub/gtk/. sl@0: */ sl@0: sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifdef SYMBIAN sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: sl@0: typedef int (*SimpleFunc) (void); sl@0: sl@0: int sl@0: main (int arg, sl@0: char *argv[]) sl@0: { sl@0: GModule *module_a, *module_b; sl@0: gchar *plugin_a, *plugin_b; sl@0: SimpleFunc f_a, f_b; sl@0: int retVal; sl@0: void *fun1,*fun2; sl@0: gchar *build_path = NULL; sl@0: gchar temp_build_path[100]; sl@0: gchar *lib_name = "xyz"; sl@0: sl@0: #ifdef SYMBIAN sl@0: 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: g_set_print_handler(mrtPrintHandler); sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: sl@0: if (!g_module_supported ()) sl@0: g_print ("dynamic modules not supported"); sl@0: sl@0: plugin_a = "libmoduletestplugin_a.dll"; sl@0: plugin_b = "libmoduletestplugin_b.dll"; sl@0: sl@0: build_path = g_module_build_path("c:\\sys\\bin",lib_name); sl@0: g_assert(!strcmp(build_path,"c:\\sys\\bin\\xyz.dll")); sl@0: g_free(build_path); sl@0: sl@0: build_path = g_module_build_path(NULL,lib_name); sl@0: g_assert(!strcmp(build_path,"xyz.dll")); sl@0: g_free(build_path); sl@0: sl@0: /* module handles */ sl@0: sl@0: module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY); sl@0: if (!module_a) sl@0: g_print ("error: %s", g_module_error ()); sl@0: sl@0: module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY); sl@0: if (!module_b) sl@0: g_print ("error: %s", g_module_error ()); sl@0: sl@0: /* get plugin specific symbols and call them sl@0: */ sl@0: if (!g_module_symbol (module_a, /*"gplugin_a_func1"*/"1", /*(gpointer *) &f_a*/&fun1)) sl@0: g_print ("error: %s", g_module_error ()); sl@0: sl@0: if (!g_module_symbol (module_b, /*"gplugin_b_func1"*/"1", /*(gpointer *) &f_b)*/&fun2)) sl@0: g_print ("error: %s", g_module_error ()); sl@0: sl@0: f_a = (SimpleFunc)fun1; sl@0: f_b = (SimpleFunc)fun2; sl@0: sl@0: retVal = f_a (); sl@0: g_assert(retVal == 1); sl@0: sl@0: retVal = f_b (); sl@0: g_assert(retVal == 1); sl@0: sl@0: if (!g_module_symbol (module_a, /*"gplugin_a_func2"*/"2", (gpointer *) &f_a)) sl@0: g_print ("error: %s", g_module_error ()); sl@0: sl@0: if (!g_module_symbol (module_b, /*"gplugin_b_func2"*/"2", (gpointer *) &f_b)) sl@0: g_print ("error: %s", g_module_error ()); sl@0: sl@0: retVal = f_a (); sl@0: g_assert(retVal == 2); sl@0: sl@0: retVal = f_b (); sl@0: g_assert(retVal == 2); sl@0: sl@0: //checks g_module_name sl@0: g_assert(!strcmp(g_module_name(module_a),"libmoduletestplugin_a.dll")); sl@0: sl@0: g_module_make_resident(module_a); sl@0: sl@0: /* unload plugins */ sl@0: sl@0: //g_module_close is ignored because g_module_make_resident(module_a) is called sl@0: if (!g_module_close (module_a)) sl@0: g_print ("error: %s", g_module_error ()); sl@0: sl@0: if (!g_module_close (module_b)) sl@0: g_print ("error: %s", g_module_error ()); sl@0: sl@0: sl@0: // As g_module_make_resident(module_a) is called g_module_close is ignored and therefore sl@0: // we are able to get the symbol from the library and execute the funtion also sl@0: if (!g_module_symbol (module_a, /*"gplugin_a_func1"*/"1", /*(gpointer *) &f_a*/&fun1)) sl@0: g_print ("error: %s", g_module_error ()); sl@0: sl@0: f_a = (SimpleFunc)fun1; sl@0: sl@0: retVal = f_a (); sl@0: g_assert(retVal == 1); sl@0: sl@0: #ifdef SYMBIAN sl@0: testResultXml("module-test"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: return 0; sl@0: }