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 */ |
Igor Zlatkovic | f52de60 | 2005-04-06 20:42:35 +0000 | [diff] [blame] | 25 | #ifndef __MINGW32__ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 26 | #define PATH_MAX _MAX_PATH |
Igor Zlatkovic | f52de60 | 2005-04-06 20:42:35 +0000 | [diff] [blame] | 27 | #endif |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 28 | #else |
| 29 | #define MODULE_PATH ".libs" |
| 30 | #endif |
| 31 | |
Daniel Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 32 | typedef int (*hello_world_t)(void); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 33 | |
| 34 | int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
| 35 | xmlChar filename[PATH_MAX]; |
| 36 | xmlModulePtr module = NULL; |
| 37 | hello_world_t hello_world = NULL; |
| 38 | |
| 39 | /* build the module filename, and confirm the module exists */ |
Daniel Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 40 | xmlStrPrintf(filename, sizeof(filename), |
| 41 | (const xmlChar*) "%s/testdso%s", |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 42 | (const xmlChar*)MODULE_PATH, |
| 43 | (const xmlChar*)LIBXML_MODULE_EXTENSION); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 44 | |
Daniel Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 45 | module = xmlModuleOpen((const char*)filename, 0); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 46 | if (module) |
| 47 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 48 | if (xmlModuleSymbol(module, "hello_world", (void **) &hello_world)) { |
| 49 | fprintf(stderr, "Failure to lookup\n"); |
| 50 | return(1); |
| 51 | } |
| 52 | if (hello_world == NULL) { |
| 53 | fprintf(stderr, "Lookup returned NULL\n"); |
| 54 | return(1); |
| 55 | } |
| 56 | |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 57 | (*hello_world)(); |
| 58 | |
| 59 | xmlModuleClose(module); |
| 60 | } |
| 61 | |
| 62 | xmlMemoryDump(); |
| 63 | |
| 64 | return(0); |
| 65 | } |
| 66 | |
| 67 | #else |
| 68 | #include <stdio.h> |
| 69 | int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
| 70 | printf("%s : Module support not compiled in\n", argv[0]); |
| 71 | return(0); |
| 72 | } |
| 73 | #endif /* LIBXML_SCHEMAS_ENABLED */ |