testModule.c 1.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * testModule.c : a small tester program for xmlModule
 *
 * See Copyright for the status of this software.
 *
 * joelwreed@comcast.net
 */

#include "libxml.h"
#ifdef LIBXML_MODULES_ENABLED
#include <libxml/xmlversion.h>

#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>

#include <libxml/xmlmemory.h>
#include <libxml/debugXML.h>
#include <libxml/xmlmodule.h>

#ifdef _WIN32
#define MODULE_PATH "."
#include <stdlib.h> /* for _MAX_PATH */
Igor Zlatkovic's avatar
Igor Zlatkovic committed
25
#ifndef __MINGW32__
26
#define PATH_MAX _MAX_PATH
Igor Zlatkovic's avatar
Igor Zlatkovic committed
27
#endif
28 29 30 31
#else
#define MODULE_PATH ".libs"
#endif

32 33 34 35 36 37 38 39 40
/* Used for SCO Openserver*/
#ifndef PATH_MAX
#ifdef _POSIX_PATH_MAX
#define PATH_MAX _POSIX_PATH_MAX
#else
#define PATH_MAX 4096
#endif
#endif

41
typedef int (*hello_world_t)(void);
42

43 44 45 46 47 48
int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
    xmlChar filename[PATH_MAX];
    xmlModulePtr module = NULL;
    hello_world_t hello_world = NULL;

    /* build the module filename, and confirm the module exists */
49
    xmlStrPrintf(filename, sizeof(filename),
50
                 "%s/testdso%s",
51 52
                 (const xmlChar*)MODULE_PATH,
		 (const xmlChar*)LIBXML_MODULE_EXTENSION);
53

54
    module = xmlModuleOpen((const char*)filename, 0);
55 56
    if (module)
      {
57 58 59 60 61 62 63 64
        if (xmlModuleSymbol(module, "hello_world", (void **) &hello_world)) {
	    fprintf(stderr, "Failure to lookup\n");
	    return(1);
	}
	if (hello_world == NULL) {
	    fprintf(stderr, "Lookup returned NULL\n");
	    return(1);
	}
65

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
        (*hello_world)();

        xmlModuleClose(module);
      }

    xmlMemoryDump();

    return(0);
}

#else
#include <stdio.h>
int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) {
    printf("%s : Module support not compiled in\n", argv[0]);
    return(0);
}
#endif /* LIBXML_SCHEMAS_ENABLED */