📄 testapi.c
字号:
/* * testapi.c: libxml2 API tester program. * * Automatically generated by gentest.py from libxml2-api.xml * * See Copyright for the status of this software. * * daniel@veillard.com */#include <stdio.h>#include <string.h>#include <libxml/xmlerror.h>#include <libxml/relaxng.h>static int testlibxml2(void);static int test_module(const char *module);static int generic_errors = 0;static int call_tests = 0;static int function_tests = 0;static xmlChar chartab[1024];static int inttab[1024];static unsigned long longtab[1024];static xmlDocPtr api_doc = NULL;static xmlDtdPtr api_dtd = NULL;static xmlNodePtr api_root = NULL;static xmlAttrPtr api_attr = NULL;static xmlNsPtr api_ns = NULL;static voidstructured_errors(void *userData ATTRIBUTE_UNUSED, xmlErrorPtr error ATTRIBUTE_UNUSED) { generic_errors++;}static voidfree_api_doc(void) { xmlFreeDoc(api_doc); api_doc = NULL; api_dtd = NULL; api_root = NULL; api_attr = NULL; api_ns = NULL;}static xmlDocPtrget_api_doc(void) { if (api_doc == NULL) { api_doc = xmlReadMemory("<!DOCTYPE root [<!ELEMENT root EMPTY>]><root xmlns:h='http://example.com/' h:foo='bar'/>", 88, "root_test", NULL, 0); api_root = NULL; api_attr = NULL; } return(api_doc);}static xmlDtdPtrget_api_dtd(void) { if ((api_dtd == NULL) || (api_dtd->type != XML_DTD_NODE)) { get_api_doc(); if ((api_doc != NULL) && (api_doc->children != NULL) && (api_doc->children->type == XML_DTD_NODE)) api_dtd = (xmlDtdPtr) api_doc->children; } return(api_dtd);}static xmlNodePtrget_api_root(void) { if ((api_root == NULL) || (api_root->type != XML_ELEMENT_NODE)) { get_api_doc(); if ((api_doc != NULL) && (api_doc->children != NULL) && (api_doc->children->next != NULL) && (api_doc->children->next->type == XML_ELEMENT_NODE)) api_root = api_doc->children->next; } return(api_root);}static xmlNsPtrget_api_ns(void) { get_api_root(); if (api_root != NULL) api_ns = api_root->nsDef; return(api_ns);}static xmlAttrPtrget_api_attr(void) {#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_HTML_ENABLED) static int nr = 0; xmlChar name[20];#endif if ((api_root == NULL) || (api_root->type != XML_ELEMENT_NODE)) { get_api_root(); } if (api_root == NULL) return(NULL); if (api_root->properties != NULL) { api_attr = api_root->properties; return(api_root->properties); } api_attr = NULL;#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_HTML_ENABLED) snprintf((char *) name, 20, "foo%d", nr++); api_attr = xmlSetProp(api_root, name, (const xmlChar *) "bar");#endif return(api_attr);}static int quiet = 0;int main(int argc, char **argv) { int ret; int blocks, mem; memset(chartab, 0, sizeof(chartab)); strncpy((char *) chartab, " chartab\n", 20); memset(inttab, 0, sizeof(inttab)); memset(longtab, 0, sizeof(longtab)); xmlInitParser();#ifdef LIBXML_SCHEMAS_ENABLED xmlRelaxNGInitTypes();#endif LIBXML_TEST_VERSION xmlSetStructuredErrorFunc(NULL, structured_errors); if (argc >= 2) { if (!strcmp(argv[1], "-q")) { quiet = 1; if (argc >= 3) ret = test_module(argv[2]); else ret = testlibxml2(); } else { ret = test_module(argv[1]); } } else ret = testlibxml2(); xmlCleanupParser(); blocks = xmlMemBlocks(); mem = xmlMemUsed(); if ((blocks != 0) || (mem != 0)) { printf("testapi leaked %d bytes in %d blocks\n", mem, blocks); } xmlMemoryDump(); return (ret != 0);}#include <libxml/HTMLparser.h>#include <libxml/HTMLtree.h>#include <libxml/catalog.h>#include <libxml/chvalid.h>#include <libxml/dict.h>#include <libxml/encoding.h>#include <libxml/entities.h>#include <libxml/hash.h>#include <libxml/list.h>#include <libxml/nanoftp.h>#include <libxml/nanohttp.h>#include <libxml/parser.h>#include <libxml/parserInternals.h>#include <libxml/pattern.h>#include <libxml/relaxng.h>#include <libxml/schemasInternals.h>#include <libxml/tree.h>#include <libxml/uri.h>#include <libxml/valid.h>#include <libxml/xinclude.h>#include <libxml/xmlIO.h>#include <libxml/xmlerror.h>#include <libxml/xmlreader.h>#include <libxml/xmlsave.h>#include <libxml/xmlschemas.h>#include <libxml/xmlschemastypes.h>#include <libxml/xmlstring.h>#include <libxml/xmlwriter.h>#include <libxml/xpath.h>#include <libxml/xpointer.h>#include <libxml/debugXML.h>/* We manually define xmlErrMemory because it's normal declaration is "hidden" by #ifdef IN_LIBXML*/void xmlErrMemory(xmlParserCtxtPtr ctxt, const char *extra);/* We need some "remote" addresses, but want to avoid getting into name resolution delays, so we use these*/#define REMOTE1GOOD "http://localhost/"#define REMOTE1BAD "http://missing. example.org/"#define REMOTE2GOOD "ftp://localhost/foo"#define gen_nb_void_ptr 2static void *gen_void_ptr(int no ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) { return(NULL);}static void des_void_ptr(int no ATTRIBUTE_UNUSED, void *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {}#if 0#define gen_nb_const_void_ptr 2static const void *gen_const_void_ptr(int no, int nr ATTRIBUTE_UNUSED) { if (no == 0) return((const void *) "immutable string"); return(NULL);}static void des_const_void_ptr(int no ATTRIBUTE_UNUSED, const void *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {}#endif#define gen_nb_userdata 3static void *gen_userdata(int no, int nr ATTRIBUTE_UNUSED) { if (no == 0) return((void *) &call_tests); if (no == 1) return((void *) -1); return(NULL);}static void des_userdata(int no ATTRIBUTE_UNUSED, void *val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {}#define gen_nb_int 4static int gen_int(int no, int nr ATTRIBUTE_UNUSED) { if (no == 0) return(0); if (no == 1) return(1); if (no == 2) return(-1); if (no == 3) return(122); return(-1);}static void des_int(int no ATTRIBUTE_UNUSED, int val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {}#define gen_nb_parseroptions 5static int gen_parseroptions(int no, int nr ATTRIBUTE_UNUSED) { if (no == 0) return(XML_PARSE_NOBLANKS | XML_PARSE_RECOVER); if (no == 1) return(XML_PARSE_NOENT | XML_PARSE_DTDLOAD | XML_PARSE_DTDATTR | XML_PARSE_DTDVALID | XML_PARSE_NOCDATA); if (no == 2) return(XML_PARSE_XINCLUDE | XML_PARSE_NOXINCNODE | XML_PARSE_NSCLEAN); if (no == 3) return(XML_PARSE_XINCLUDE | XML_PARSE_NODICT); return(XML_PARSE_SAX1);}static void des_parseroptions(int no ATTRIBUTE_UNUSED, int val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {}#if 0#define gen_nb_long 5static long gen_long(int no, int nr ATTRIBUTE_UNUSED) { if (no == 0) return(0); if (no == 1) return(1); if (no == 2) return(-1); if (no == 3) return(122); return(-1);}static void des_long(int no ATTRIBUTE_UNUSED, long val ATTRIBUTE_UNUSED, int nr ATTRIBUTE_UNUSED) {}#endif#define gen_nb_xmlChar 4static xmlChar gen_xmlChar(int no, int nr ATTRIBUTE_UNUSED) { if (no == 0) return('a'); if (no == 1) return(' '); if (no == 2) return('
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -