blob: f245829b0e784a8b59a5bce1803b93eb1229ba1a [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 */
25#define PATH_MAX _MAX_PATH
26#else
27#define MODULE_PATH ".libs"
28#endif
29
Daniel Veillard48df9612005-01-04 21:50:05 +000030typedef int (*hello_world_t)(void);
Daniel Veillardce1648b2005-01-04 15:10:22 +000031
32int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
33 xmlChar filename[PATH_MAX];
34 xmlModulePtr module = NULL;
35 hello_world_t hello_world = NULL;
36
37 /* build the module filename, and confirm the module exists */
Daniel Veillard48df9612005-01-04 21:50:05 +000038 xmlStrPrintf(filename, sizeof(filename),
39 (const xmlChar*) "%s/testdso%s",
Daniel Veillardbe076e92005-01-04 20:18:14 +000040 (const xmlChar*)MODULE_PATH,
41 (const xmlChar*)LIBXML_MODULE_EXTENSION);
Daniel Veillardce1648b2005-01-04 15:10:22 +000042
Daniel Veillard48df9612005-01-04 21:50:05 +000043 module = xmlModuleOpen((const char*)filename, 0);
Daniel Veillardce1648b2005-01-04 15:10:22 +000044 if (module)
45 {
Daniel Veillardbe076e92005-01-04 20:18:14 +000046 if (xmlModuleSymbol(module, "hello_world", (void **) &hello_world)) {
47 fprintf(stderr, "Failure to lookup\n");
48 return(1);
49 }
50 if (hello_world == NULL) {
51 fprintf(stderr, "Lookup returned NULL\n");
52 return(1);
53 }
54
Daniel Veillardce1648b2005-01-04 15:10:22 +000055 (*hello_world)();
56
57 xmlModuleClose(module);
58 }
59
60 xmlMemoryDump();
61
62 return(0);
63}
64
65#else
66#include <stdio.h>
67int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
68 printf("%s : Module support not compiled in\n", argv[0]);
69 return(0);
70}
71#endif /* LIBXML_SCHEMAS_ENABLED */