Skip to content

Commit a9ada18

Browse files
committed
tests: Start with testparser.c for extra tests
Several issues require customized tests. Start with a test that push parses large documents. See #539.
1 parent 572ecc1 commit a9ada18

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/testchar
2020
/testdict
2121
/testlimits
22+
/testparser
2223
/testrecurse
2324

2425
# Tests

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ if(LIBXML2_WITH_TESTS)
520520
testdict
521521
testModule
522522
testlimits
523+
testparser
523524
testrecurse
524525
testThreads
525526
)
@@ -543,6 +544,7 @@ if(LIBXML2_WITH_TESTS)
543544
endif()
544545
add_test(NAME testchar COMMAND testchar)
545546
add_test(NAME testdict COMMAND testdict)
547+
add_test(NAME testparser COMMAND testparser)
546548
add_test(NAME testrecurse COMMAND testrecurse WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
547549
add_test(NAME testThreads COMMAND testThreads WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
548550
endif()

Makefile.am

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ check_PROGRAMS = \
2424
testchar \
2525
testdict \
2626
testlimits \
27+
testparser \
2728
testrecurse
2829

2930
bin_PROGRAMS = xmllint xmlcatalog
@@ -140,6 +141,10 @@ testdict_SOURCES=testdict.c
140141
testdict_DEPENDENCIES = $(DEPS)
141142
testdict_LDADD= $(LDADDS)
142143

144+
testparser_SOURCES=testparser.c
145+
testparser_DEPENDENCIES = $(DEPS)
146+
testparser_LDADD= $(LDADDS)
147+
143148
runsuite_SOURCES=runsuite.c
144149
runsuite_DEPENDENCIES = $(DEPS)
145150
runsuite_LDADD= $(LDADDS)
@@ -193,6 +198,7 @@ check-local:
193198
$(CHECKER) ./testapi$(EXEEXT)
194199
$(CHECKER) ./testchar$(EXEEXT)
195200
$(CHECKER) ./testdict$(EXEEXT)
201+
$(CHECKER) ./testparser$(EXEEXT)
196202
$(CHECKER) ./testModule$(EXEEXT)
197203
$(CHECKER) ./testThreads$(EXEEXT)
198204
$(CHECKER) ./runxmlconf$(EXEEXT)

testparser.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* testparser.c: Additional parser tests
3+
*
4+
* See Copyright for the status of this software.
5+
*/
6+
7+
#include <libxml/parser.h>
8+
9+
#ifdef LIBXML_PUSH_ENABLED
10+
static int
11+
testHugePush(void) {
12+
xmlParserCtxtPtr ctxt;
13+
int err, i;
14+
15+
ctxt = xmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL);
16+
17+
/*
18+
* Push parse a document larger than XML_MAX_LOOKUP_LIMIT
19+
* (10,000,000 bytes). This mainly tests whether shrinking the
20+
* buffer works when push parsing.
21+
*/
22+
xmlParseChunk(ctxt, "<doc>", 5, 0);
23+
for (i = 0; i < 1000000; i++)
24+
xmlParseChunk(ctxt, "<elem>text</elem>", 17, 0);
25+
xmlParseChunk(ctxt, "</doc>", 6, 1);
26+
27+
err = ctxt->wellFormed ? 0 : 1;
28+
xmlFreeDoc(ctxt->myDoc);
29+
xmlFreeParserCtxt(ctxt);
30+
31+
return err;
32+
}
33+
#endif
34+
35+
int
36+
main(void) {
37+
int err = 0;
38+
39+
#ifdef LIBXML_PUSH_ENABLED
40+
err |= testHugePush();
41+
#endif
42+
43+
return err;
44+
}
45+

0 commit comments

Comments
 (0)