diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d8f4151..ada234ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -504,7 +504,7 @@ if(LIBXML2_WITH_TESTS) endif() add_test(NAME testchar COMMAND testchar) add_test(NAME testdict COMMAND testdict) - add_test(NAME testparser COMMAND testparser) + add_test(NAME testparser COMMAND testparser WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) add_test(NAME testrecurse COMMAND testrecurse WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) endif() diff --git a/testparser.c b/testparser.c index 46b65eb1..ffc85a88 100644 --- a/testparser.c +++ b/testparser.c @@ -4,6 +4,8 @@ * See Copyright for the status of this software. */ +#define XML_DEPRECATED + #include "libxml.h" #include #include @@ -96,6 +98,34 @@ testNodeGetContent(void) { return err; } +static int +testCFileIO(void) { + xmlDocPtr doc; + int err = 0; + + /* Deprecated FILE-based API */ + xmlRegisterInputCallbacks(xmlFileMatch, xmlFileOpen, xmlFileRead, + xmlFileClose); + doc = xmlReadFile("test/ent1", NULL, 0); + + if (doc == NULL) { + err = 1; + } else { + xmlNodePtr root = xmlDocGetRootElement(doc); + + if (root == NULL || !xmlStrEqual(root->name, BAD_CAST "EXAMPLE")) + err = 1; + } + + xmlFreeDoc(doc); + xmlPopInputCallbacks(); + + if (err) + fprintf(stderr, "xmlReadFile failed with FILE input callbacks\n"); + + return err; +} + #ifdef LIBXML_SAX1_ENABLED static int testBalancedChunk(void) { @@ -650,6 +680,7 @@ main(void) { err |= testStandaloneWithEncoding(); err |= testUnsupportedEncoding(); err |= testNodeGetContent(); + err |= testCFileIO(); #ifdef LIBXML_SAX1_ENABLED err |= testBalancedChunk(); #endif diff --git a/xmlIO.c b/xmlIO.c index 96815cbc..a0884723 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -706,7 +706,7 @@ xmlFileRead(void * context, char * buffer, int len) { if ((bytes < (size_t) len) && (ferror(file))) return(-xmlIOErr(errno)); - return(len); + return(bytes); } #ifdef LIBXML_OUTPUT_ENABLED