Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 1 | /* |
| 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 Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 30 | typedef int (*hello_world_t)(void); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 31 | |
| 32 | int 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 Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 38 | xmlStrPrintf(filename, sizeof(filename), |
| 39 | (const xmlChar*) "%s/testdso%s", |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 40 | (const xmlChar*)MODULE_PATH, |
| 41 | (const xmlChar*)LIBXML_MODULE_EXTENSION); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 42 | |
Daniel Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 43 | module = xmlModuleOpen((const char*)filename, 0); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 44 | if (module) |
| 45 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 46 | 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 Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 55 | (*hello_world)(); |
| 56 | |
| 57 | xmlModuleClose(module); |
| 58 | } |
| 59 | |
| 60 | xmlMemoryDump(); |
| 61 | |
| 62 | return(0); |
| 63 | } |
| 64 | |
| 65 | #else |
| 66 | #include <stdio.h> |
| 67 | int 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 */ |