mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
writer: Implement xmlTextWriterClose
This function can be used to make sure that closing the output stream succeeded. Fixes #513.
This commit is contained in:
47
testparser.c
47
testparser.c
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/xmlreader.h>
|
||||
#include <libxml/xmlwriter.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -203,6 +204,49 @@ testReaderXIncludeError(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LIBXML_WRITER_ENABLED
|
||||
static int
|
||||
testWriterIOWrite(void *ctxt, const char *data, int len) {
|
||||
(void) ctxt;
|
||||
(void) data;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int
|
||||
testWriterIOClose(void *ctxt) {
|
||||
(void) ctxt;
|
||||
|
||||
return XML_IO_ENAMETOOLONG;
|
||||
}
|
||||
|
||||
static int
|
||||
testWriterClose(void){
|
||||
xmlOutputBufferPtr out;
|
||||
xmlTextWriterPtr writer;
|
||||
int err = 0;
|
||||
int result;
|
||||
|
||||
out = xmlOutputBufferCreateIO(testWriterIOWrite, testWriterIOClose,
|
||||
NULL, NULL);
|
||||
writer = xmlNewTextWriter(out);
|
||||
xmlTextWriterStartDocument(writer, "1.0", "UTF-8", NULL);
|
||||
xmlTextWriterStartElement(writer, BAD_CAST "elem");
|
||||
xmlTextWriterEndElement(writer);
|
||||
xmlTextWriterEndDocument(writer);
|
||||
result = xmlTextWriterClose(writer);
|
||||
|
||||
if (result != XML_IO_ENAMETOOLONG) {
|
||||
fprintf(stderr, "xmlTextWriterClose reported wrong error %d\n",
|
||||
result);
|
||||
err = 1;
|
||||
}
|
||||
|
||||
xmlFreeTextWriter(writer);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main(void) {
|
||||
int err = 0;
|
||||
@@ -218,6 +262,9 @@ main(void) {
|
||||
#if defined(LIBXML_READER_ENABLED) && defined(LIBXML_XINCLUDE_ENABLED)
|
||||
err |= testReaderXIncludeError();
|
||||
#endif
|
||||
#ifdef LIBXML_WRITER_ENABLED
|
||||
err |= testWriterClose();
|
||||
#endif
|
||||
|
||||
return err;
|
||||
}
|
||||
|
Reference in New Issue
Block a user