GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-dynload.c
1 /*********************************************************************
2  * test-dynload.c
3  * test the ability to dlopen the gnc_module library and initialize
4  * it via dlsym
5  *********************************************************************/
6 
7 #include "config.h"
8 #include <stdio.h>
9 #include <gmodule.h>
10 #include <libguile.h>
11 #include <unittest-support.h>
12 
13 #include "gnc-module.h"
14 
15 static void
16 guile_main(void *closure, int argc, char ** argv)
17 {
18  GModule *gmodule;
19  gchar *msg = "Module '../../../src/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n";
20  gchar *logdomain = "gnc.module";
21  gchar *modpath;
22  guint loglevel = G_LOG_LEVEL_WARNING;
23  TestErrorStruct check = { loglevel, logdomain, msg };
24  g_log_set_handler (logdomain, loglevel,
25  (GLogFunc)test_checked_handler, &check);
26 
27  g_test_message(" test-dynload.c: testing dynamic linking of libgnc-module ...");
28 #ifdef G_OS_WIN32
29 /* MinGW builds libgnc-module-0.dll */
30  modpath = g_module_build_path ("../.libs", "gnc-module-0");
31 #elif defined(PLATFORM_OSX)
32 /* We build libgnc-module as a shared library for testing, and on OSX
33  * that means that g_module_build_path (), which uses ".so", doesn't
34  * build the right path name.
35  */
36  modpath = g_build_filename ("..", ".libs", "libgnc-module.dylib", NULL);
37 #else /* Regular Unix */
38  modpath = g_module_build_path ("../.libs", "gnc-module");
39 #endif
40  gmodule = g_module_open(modpath, 0);
41 
42  if (gmodule)
43  {
44  gpointer ptr;
45  if (g_module_symbol(gmodule, "gnc_module_system_init", &ptr))
46  {
47  void (* fn)(void) = ptr;
48  fn();
49  printf(" OK\n");
50  exit(0);
51  }
52  else
53  {
54  printf(" failed to find gnc_module_system_init\n");
55  exit(-1);
56  }
57  }
58  else
59  {
60  printf(" failed to open library.\n");
61  printf("%s\n", g_module_error());
62  exit(-1);
63  }
64 }
65 
66 int
67 main(int argc, char ** argv)
68 {
69  scm_boot_guile(argc, argv, guile_main, NULL);
70  return 0;
71 }
72