module.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <config.h>
  2. #include <glib.h>
  3. #include <gmodule.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #ifdef HAVE_UNISTD_H
  7. #include <unistd.h>
  8. #endif
  9. #include "test.h"
  10. #if defined (G_OS_WIN32)
  11. #define EXTERNAL_SYMBOL "GetProcAddress"
  12. #else
  13. #define EXTERNAL_SYMBOL "system"
  14. #endif
  15. void G_MODULE_EXPORT
  16. dummy_test_export ()
  17. {
  18. }
  19. /* test for g_module_open (NULL, ...) */
  20. RESULT
  21. test_module_symbol_null ()
  22. {
  23. gpointer proc = GINT_TO_POINTER (42);
  24. GModule *m = g_module_open (NULL, G_MODULE_BIND_LAZY);
  25. if (m == NULL)
  26. return FAILED ("bind to main module failed. #0");
  27. if (g_module_symbol (m, "__unlikely_\nexistent__", &proc))
  28. return FAILED ("non-existent symbol lookup failed. #1");
  29. if (proc)
  30. return FAILED ("non-existent symbol lookup failed. #2");
  31. if (!g_module_symbol (m, EXTERNAL_SYMBOL, &proc))
  32. return FAILED ("external lookup failed. #3");
  33. if (!proc)
  34. return FAILED ("external lookup failed. #4");
  35. if (!g_module_symbol (m, "dummy_test_export", &proc))
  36. return FAILED ("in-proc lookup failed. #5");
  37. if (!proc)
  38. return FAILED ("in-proc lookup failed. #6");
  39. if (!g_module_close (m))
  40. return FAILED ("close failed. #7");
  41. return OK;
  42. }
  43. static Test module_tests [] = {
  44. {"g_module_symbol_null", test_module_symbol_null},
  45. {NULL, NULL}
  46. };
  47. DEFINE_TEST_GROUP_INIT(module_tests_init, module_tests)