blob: 77b7ba106abd337bc77edee85ec50e506f356857 [file] [log] [blame]
Daniel Veillardce1648b2005-01-04 15:10:22 +00001/*
2 * testModule.c : a small tester program for xmlModule
3 *
4 * See Copyright for the status of this software.
5 *
6 * joelwreed@comcast.net
7 */
8
9#include "libxml.h"
10#ifdef LIBXML_MODULES_ENABLED
11#include <libxml/xmlversion.h>
12
13#include <limits.h>
14#include <stdio.h>
15#include <string.h>
16#include <stdarg.h>
17
18#include <libxml/xmlmemory.h>
19#include <libxml/debugXML.h>
20#include <libxml/xmlmodule.h>
21
22#ifdef _WIN32
23#define MODULE_PATH "."
24#include <stdlib.h> /* for _MAX_PATH */
Igor Zlatkovicf52de602005-04-06 20:42:35 +000025#ifndef __MINGW32__
Daniel Veillardce1648b2005-01-04 15:10:22 +000026#define PATH_MAX _MAX_PATH
Igor Zlatkovicf52de602005-04-06 20:42:35 +000027#endif
Daniel Veillardce1648b2005-01-04 15:10:22 +000028#else
29#define MODULE_PATH ".libs"
30#endif
31
Daniel Veillard70e20ad2008-02-25 15:44:43 +000032/* Used for SCO Openserver*/
33#ifndef PATH_MAX
34#ifdef _POSIX_PATH_MAX
35#define PATH_MAX _POSIX_PATH_MAX
36#else
37#define PATH_MAX 4096
38#endif
39#endif
40
Daniel Veillard48df9612005-01-04 21:50:05 +000041typedef int (*hello_world_t)(void);
Daniel Veillardf8e3db02012-09-11 13:26:36 +080042
Daniel Veillardce1648b2005-01-04 15:10:22 +000043int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
44 xmlChar filename[PATH_MAX];
45 xmlModulePtr module = NULL;
46 hello_world_t hello_world = NULL;
47
48 /* build the module filename, and confirm the module exists */
Daniel Veillard48df9612005-01-04 21:50:05 +000049 xmlStrPrintf(filename, sizeof(filename),
David Kilzer4472c3a2016-05-13 15:13:17 +080050 "%s/testdso%s",
Daniel Veillardbe076e92005-01-04 20:18:14 +000051 (const xmlChar*)MODULE_PATH,
52 (const xmlChar*)LIBXML_MODULE_EXTENSION);
Daniel Veillardce1648b2005-01-04 15:10:22 +000053
Daniel Veillard48df9612005-01-04 21:50:05 +000054 module = xmlModuleOpen((const char*)filename, 0);
Daniel Veillardce1648b2005-01-04 15:10:22 +000055 if (module)
56 {
Daniel Veillardbe076e92005-01-04 20:18:14 +000057 if (xmlModuleSymbol(module, "hello_world", (void **) &hello_world)) {
58 fprintf(stderr, "Failure to lookup\n");
59 return(1);
60 }
61 if (hello_world == NULL) {
62 fprintf(stderr, "Lookup returned NULL\n");
63 return(1);
64 }
Daniel Veillardf8e3db02012-09-11 13:26:36 +080065
Daniel Veillardce1648b2005-01-04 15:10:22 +000066 (*hello_world)();
67
68 xmlModuleClose(module);
69 }
70
71 xmlMemoryDump();
72
73 return(0);
74}
75
76#else
77#include <stdio.h>
78int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
79 printf("%s : Module support not compiled in\n", argv[0]);
80 return(0);
81}
82#endif /* LIBXML_SCHEMAS_ENABLED */