1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tsrc/BC/tests/module-test.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,143 @@
1.4 +/* module-test.c - test program for GMODULE
1.5 + * Copyright (C) 1998 Tim Janik
1.6 + * Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.7 + * This library is free software; you can redistribute it and/or
1.8 + * modify it under the terms of the GNU Lesser General Public
1.9 + * License as published by the Free Software Foundation; either
1.10 + * version 2 of the License, or (at your option) any later version.
1.11 + *
1.12 + * This library is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.15 + * Lesser General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU Lesser General Public
1.18 + * License along with this library; if not, write to the
1.19 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.20 + * Boston, MA 02111-1307, USA.
1.21 + */
1.22 +
1.23 +/*
1.24 + * Modified by the GLib Team and others 1997-2000. See the AUTHORS
1.25 + * file for a list of people on the GLib Team. See the ChangeLog
1.26 + * files for a list of changes. These files are distributed with
1.27 + * GLib at ftp://ftp.gtk.org/pub/gtk/.
1.28 + */
1.29 +
1.30 +#undef G_DISABLE_ASSERT
1.31 +#undef G_LOG_DOMAIN
1.32 +
1.33 +#include <gmodule.h>
1.34 +#include <string.h>
1.35 +#include <stdio.h>
1.36 +
1.37 +#ifdef SYMBIAN
1.38 +#include "mrt2_glib2_test.h"
1.39 +#endif /*SYMBIAN*/
1.40 +
1.41 +
1.42 +typedef int (*SimpleFunc) (void);
1.43 +
1.44 +int
1.45 +main (int arg,
1.46 + char *argv[])
1.47 +{
1.48 + GModule *module_a, *module_b;
1.49 + gchar *plugin_a, *plugin_b;
1.50 + SimpleFunc f_a, f_b;
1.51 + int retVal;
1.52 + void *fun1,*fun2;
1.53 + gchar *build_path = NULL;
1.54 + gchar temp_build_path[100];
1.55 + gchar *lib_name = "xyz";
1.56 +
1.57 + #ifdef SYMBIAN
1.58 + 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);
1.59 + g_set_print_handler(mrtPrintHandler);
1.60 + #endif /*SYMBIAN*/
1.61 +
1.62 +
1.63 + if (!g_module_supported ())
1.64 + g_print ("dynamic modules not supported");
1.65 +
1.66 + plugin_a = "libmoduletestplugin_a.dll";
1.67 + plugin_b = "libmoduletestplugin_b.dll";
1.68 +
1.69 + build_path = g_module_build_path("c:\\sys\\bin",lib_name);
1.70 + g_assert(!strcmp(build_path,"c:\\sys\\bin\\xyz.dll"));
1.71 + g_free(build_path);
1.72 +
1.73 + build_path = g_module_build_path(NULL,lib_name);
1.74 + g_assert(!strcmp(build_path,"xyz.dll"));
1.75 + g_free(build_path);
1.76 +
1.77 + /* module handles */
1.78 +
1.79 + module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
1.80 + if (!module_a)
1.81 + g_print ("error: %s", g_module_error ());
1.82 +
1.83 + module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
1.84 + if (!module_b)
1.85 + g_print ("error: %s", g_module_error ());
1.86 +
1.87 + /* get plugin specific symbols and call them
1.88 + */
1.89 + if (!g_module_symbol (module_a, /*"gplugin_a_func1"*/"1", /*(gpointer *) &f_a*/&fun1))
1.90 + g_print ("error: %s", g_module_error ());
1.91 +
1.92 + if (!g_module_symbol (module_b, /*"gplugin_b_func1"*/"1", /*(gpointer *) &f_b)*/&fun2))
1.93 + g_print ("error: %s", g_module_error ());
1.94 +
1.95 + f_a = (SimpleFunc)fun1;
1.96 + f_b = (SimpleFunc)fun2;
1.97 +
1.98 + retVal = f_a ();
1.99 + g_assert(retVal == 1);
1.100 +
1.101 + retVal = f_b ();
1.102 + g_assert(retVal == 1);
1.103 +
1.104 + if (!g_module_symbol (module_a, /*"gplugin_a_func2"*/"2", (gpointer *) &f_a))
1.105 + g_print ("error: %s", g_module_error ());
1.106 +
1.107 + if (!g_module_symbol (module_b, /*"gplugin_b_func2"*/"2", (gpointer *) &f_b))
1.108 + g_print ("error: %s", g_module_error ());
1.109 +
1.110 + retVal = f_a ();
1.111 + g_assert(retVal == 2);
1.112 +
1.113 + retVal = f_b ();
1.114 + g_assert(retVal == 2);
1.115 +
1.116 + //checks g_module_name
1.117 + g_assert(!strcmp(g_module_name(module_a),"libmoduletestplugin_a.dll"));
1.118 +
1.119 + g_module_make_resident(module_a);
1.120 +
1.121 + /* unload plugins */
1.122 +
1.123 + //g_module_close is ignored because g_module_make_resident(module_a) is called
1.124 + if (!g_module_close (module_a))
1.125 + g_print ("error: %s", g_module_error ());
1.126 +
1.127 + if (!g_module_close (module_b))
1.128 + g_print ("error: %s", g_module_error ());
1.129 +
1.130 +
1.131 + // As g_module_make_resident(module_a) is called g_module_close is ignored and therefore
1.132 + // we are able to get the symbol from the library and execute the funtion also
1.133 + if (!g_module_symbol (module_a, /*"gplugin_a_func1"*/"1", /*(gpointer *) &f_a*/&fun1))
1.134 + g_print ("error: %s", g_module_error ());
1.135 +
1.136 + f_a = (SimpleFunc)fun1;
1.137 +
1.138 + retVal = f_a ();
1.139 + g_assert(retVal == 1);
1.140 +
1.141 + #ifdef SYMBIAN
1.142 + testResultXml("module-test");
1.143 + #endif /* EMULATOR */
1.144 +
1.145 + return 0;
1.146 +}