Apache HTTPD
ns_tests.c
Go to the documentation of this file.
1/* Tests in the "namespace" test case for the Expat test suite
2 __ __ _
3 ___\ \/ /_ __ __ _| |_
4 / _ \\ /| '_ \ / _` | __|
5 | __// \| |_) | (_| | |_
6 \___/_/\_\ .__/ \__,_|\__|
7 |_| XML parser
8
9 Copyright (c) 2001-2006 Fred L. Drake, Jr. <[email protected]>
10 Copyright (c) 2003 Greg Stein <[email protected]>
11 Copyright (c) 2005-2007 Steven Solie <[email protected]>
12 Copyright (c) 2005-2012 Karl Waclawek <[email protected]>
13 Copyright (c) 2016-2023 Sebastian Pipping <[email protected]>
14 Copyright (c) 2017-2022 Rhodri James <[email protected]>
15 Copyright (c) 2017 Joe Orton <[email protected]>
16 Copyright (c) 2017 José Gutiérrez de la Concha <[email protected]>
17 Copyright (c) 2018 Marco Maggi <[email protected]>
18 Copyright (c) 2019 David Loffredo <[email protected]>
19 Copyright (c) 2020 Tim Gates <[email protected]>
20 Copyright (c) 2021 Donghee Na <[email protected]>
21 Copyright (c) 2023 Sony Corporation / Snild Dolkow <[email protected]>
22 Licensed under the MIT license:
23
24 Permission is hereby granted, free of charge, to any person obtaining
25 a copy of this software and associated documentation files (the
26 "Software"), to deal in the Software without restriction, including
27 without limitation the rights to use, copy, modify, merge, publish,
28 distribute, sublicense, and/or sell copies of the Software, and to permit
29 persons to whom the Software is furnished to do so, subject to the
30 following conditions:
31
32 The above copyright notice and this permission notice shall be included
33 in all copies or substantial portions of the Software.
34
35 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
38 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
39 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
40 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
41 USE OR OTHER DEALINGS IN THE SOFTWARE.
42*/
43
44#include "expat_config.h"
45
46#include <string.h>
47
48#include "expat.h"
49#include "internal.h"
50#include "minicheck.h"
51#include "common.h"
52#include "dummy.h"
53#include "handlers.h"
54#include "ns_tests.h"
55
56static void
59 if (g_parser == NULL)
60 fail("Parser not created.");
61}
62
63static void
67
69 const char *text = "<foo:e xmlns:foo='http://example.org/' bar:a='12'\n"
70 " xmlns:bar='http://example.org/'>";
71 const char *epilog = "</foo:e>";
72 const XML_Char *elemstr[]
73 = {XCS("http://example.org/ e foo"), XCS("http://example.org/ a bar")};
85 /* Check that unsetting "return triplets" fails while still parsing */
91 fail("triplet_start_checker not invoked");
93 fail("triplet_end_checker not invoked");
96 fail("Namespace handlers not called");
97}
99
100/* Test that the parsing status is correctly reset by XML_ParserReset().
101 * We use test_return_ns_triplet() for our example parse to improve
102 * coverage of tidying up code executed.
103 */
106
108 if (status.parsing != XML_INITIALIZED)
109 fail("parsing status doesn't start INITIALIZED");
112 if (status.parsing != XML_FINISHED)
113 fail("parsing status doesn't end FINISHED");
116 if (status.parsing != XML_INITIALIZED)
117 fail("parsing status doesn't reset to INITIALIZED");
118}
120
121static void
133
134/* Regression test for SF bug #566334. */
136 const char *text = "<n:e xmlns:n='http://example.org/'>\n"
137 " <n:f n:attr='foo'/>\n"
138 " <n:g n:attr2='bar'/>\n"
139 "</n:e>";
140 const XML_Char *result = XCS("start http://example.org/ e\n")
141 XCS("start http://example.org/ f\n")
142 XCS("attribute http://example.org/ attr\n")
143 XCS("end http://example.org/ f\n")
144 XCS("start http://example.org/ g\n")
145 XCS("attribute http://example.org/ attr2\n")
146 XCS("end http://example.org/ g\n")
147 XCS("end http://example.org/ e\n");
149}
151
152/* Regression test for SF bug #566334. */
154 const char *text = "<n:e xmlns:n='http://example.org/'>\n"
155 " <n:f n:attr='foo'/>\n"
156 " <n:g n:attr2='bar'/>\n"
157 "</n:e>";
158 const XML_Char *result = XCS("start http://example.org/ e n\n")
159 XCS("start http://example.org/ f n\n")
160 XCS("attribute http://example.org/ attr n\n")
161 XCS("end http://example.org/ f n\n")
162 XCS("start http://example.org/ g n\n")
163 XCS("attribute http://example.org/ attr2 n\n")
164 XCS("end http://example.org/ g n\n")
165 XCS("end http://example.org/ e n\n");
168}
170
171/* Regression test for SF bug #620343. */
173 /* This needs to use separate start/end tags; using the empty tag
174 syntax doesn't cause the problematic path through Expat to be
175 taken.
176 */
177 const char *text = "<e xmlns='http://example.org/'></e>";
178
186}
188
189/* Regression test for SF bug #616863. */
191 const char *text = "<?xml version='1.0'?>\n"
192 "<!DOCTYPE doc SYSTEM 'http://example.org/doc.dtd' [\n"
193 " <!ENTITY en SYSTEM 'http://example.org/entity.ent'>\n"
194 "]>\n"
195 "<doc xmlns='http://example.org/ns1'>\n"
196 "&en;\n"
197 "</doc>";
198
201 /* We actually need to set this handler to tickle this bug. */
207}
209
210/* Regression test #1 for SF bug #673791. */
212 const char *text = "<doc xmlns:prefix='http://example.org/'>\n"
213 " <e xmlns:prefix=''/>\n"
214 "</doc>";
215
217 "Did not report re-setting namespace"
218 " URI with prefix to ''.");
219}
221
222/* Regression test #2 for SF bug #673791. */
224 const char *text = "<?xml version='1.0'?>\n"
225 "<docelem xmlns:pre=''/>";
226
228 "Did not report setting namespace URI with prefix to ''.");
229}
231
232/* Regression test #3 for SF bug #673791. */
234 const char *text = "<!DOCTYPE doc [\n"
235 " <!ELEMENT doc EMPTY>\n"
236 " <!ATTLIST doc\n"
237 " xmlns:prefix CDATA ''>\n"
238 "]>\n"
239 "<doc/>";
240
242 "Didn't report attr default setting NS w/ prefix to ''.");
243}
245
246/* Regression test #4 for SF bug #673791. */
248 const char *text = "<!DOCTYPE doc [\n"
249 " <!ELEMENT prefix:doc EMPTY>\n"
250 " <!ATTLIST prefix:doc\n"
251 " xmlns:prefix CDATA 'http://example.org/'>\n"
252 "]>\n"
253 "<prefix:doc/>";
254 /* Packaged info expected by the end element handler;
255 the weird structuring lets us reuse the triplet_end_checker()
256 function also used for another test. */
257 const XML_Char *elemstr[] = {XCS("http://example.org/ doc prefix")};
264}
266
267/* Test with non-xmlns prefix */
269 const char *text = "<!DOCTYPE doc [\n"
270 " <!ELEMENT prefix:doc EMPTY>\n"
271 " <!ATTLIST prefix:doc\n"
272 " notxmlns:prefix CDATA 'http://example.org/'>\n"
273 "]>\n"
274 "<prefix:doc/>";
275
278 fail("Unbound prefix incorrectly passed");
281}
283
285 const char *text = "<doc xmlns='http://example.org/'>\n"
286 " <e xmlns=''/>\n"
287 "</doc>";
288 /* Add some handlers to exercise extra code paths */
295}
297
298/* Regression test for SF bug #692964: two prefixes for one namespace. */
300 const char *text = "<doc xmlns:a='http://example.org/a'\n"
301 " xmlns:b='http://example.org/a'\n"
302 " a:a='v' b:a='v' />";
304 "did not report multiple attributes with same URI+name");
305}
307
309 /* The hash of an attribute is calculated as the hash of its URI
310 * concatenated with a space followed by its name (after the
311 * colon). We wish to generate attributes with the same hash
312 * value modulo the attribute table size so that we can check that
313 * the attribute hash table works correctly. The attribute hash
314 * table size will be the smallest power of two greater than the
315 * number of attributes, but at least eight. There is
316 * unfortunately no programmatic way of getting the hash or the
317 * table size at user level, but the test code coverage percentage
318 * will drop if the hashes cease to point to the same row.
319 *
320 * The cunning plan is to have few enough attributes to have a
321 * reliable table size of 8, and have the single letter attribute
322 * names be 8 characters apart, producing a hash which will be the
323 * same modulo 8.
324 */
325 const char *text = "<doc xmlns:a='http://example.org/a'\n"
326 " a:a='v' a:i='w' />";
330}
332
333/* Regression test for SF bug #695401: unbound prefix. */
335 const char *text = "<doc a:attr=''/>";
337 "did not report unbound prefix on attribute");
338}
340
341/* Regression test for SF bug #695401: unbound prefix. */
343 const char *text = "<a:doc/>";
345 "did not report unbound prefix on element");
346}
348
349/* Test that long element names with namespaces are handled correctly */
351 const char *text
352 = "<foo:thisisalongenoughelementnametotriggerareallocation\n"
353 " xmlns:foo='http://example.org/' bar:a='12'\n"
354 " xmlns:bar='http://example.org/'>"
355 "</foo:thisisalongenoughelementnametotriggerareallocation>";
356 const XML_Char *elemstr[]
357 = {XCS("http://example.org/")
358 XCS(" thisisalongenoughelementnametotriggerareallocation foo"),
359 XCS("http://example.org/ a bar")};
360
367}
369
370/* Test mixed population of prefixed and unprefixed attributes */
372 const char *text = "<e a='12' bar:b='13'\n"
373 " xmlns:bar='http://example.org/'>"
374 "</e>";
375
379}
381
382/* Test having a long namespaced element name inside a short one.
383 * This exercises some internal buffer reallocation that is shared
384 * across elements with the same namespace URI.
385 */
387 const char *text = "<foo:e xmlns:foo='http://example.org/'>"
388 " <foo:thisisalongenoughnametotriggerallocationaction"
389 " foo:a='12' />"
390 "</foo:e>";
394}
396
397/* Test that xmlns is correctly rejected as an attribute in the xmlns
398 * namespace, but not in other namespaces
399 */
401 const char *text1
402 = "<foo:e xmlns:foo='http://example.org/' xmlns:xmlns='12' />";
403 const char *text2
404 = "<foo:e xmlns:foo='http://example.org/' foo:xmlns='12' />";
406 "xmlns not rejected as an attribute");
411}
413
414/* Test more reserved attributes */
416 const char *text1 = "<foo:e xmlns:foo='http://example.org/'"
417 " xmlns:xml='http://example.org/' />";
418 const char *text2
419 = "<foo:e xmlns:foo='http://www.w3.org/XML/1998/namespace' />";
420 const char *text3 = "<foo:e xmlns:foo='http://www.w3.org/2000/xmlns/' />";
421
423 "xml not rejected as an attribute");
426 "Use of w3.org URL not faulted");
429 "Use of w3.org xmlns URL not faulted");
430}
432
433/* Test string pool handling of namespace names of 2048 characters */
434/* Exercises a particular string pool growth path */
436 /* C99 compilers are only required to support 4095-character
437 * strings, so the following needs to be split in two to be safe
438 * for all compilers.
439 */
440 const char *text1
441 = "<doc "
442 /* 64 character on each line */
443 /* ...gives a total length of 2048 */
444 "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
445 "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCD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JKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
511 "='foo'\n>"
512 "</doc>";
513
520}
522
523/* Test unknown encoding handlers in namespace setup */
525 const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n"
526 "<foo:e xmlns:foo='http://example.org/'>Hi</foo:e>";
527
530}
532
533/* Test that too many colons are rejected */
535 const char *text = "<foo:e xmlns:foo='http://example.org/' foo:a:b='bar' />";
536 const enum XML_Status status
538#ifdef XML_NS
539 if ((status == XML_STATUS_OK)
541 fail("Double colon in attribute name not faulted"
542 " (despite active namespace support)");
543 }
544#else
545 if (status != XML_STATUS_OK) {
546 fail("Double colon in attribute name faulted"
547 " (despite inactive namespace support");
548 }
549#endif
550}
552
554 const char *text = "<foo:bar:e xmlns:foo='http://example.org/' />";
555 const enum XML_Status status
557#ifdef XML_NS
558 if ((status == XML_STATUS_OK)
560 fail("Double colon in element name not faulted"
561 " (despite active namespace support)");
562 }
563#else
564 if (status != XML_STATUS_OK) {
565 fail("Double colon in element name faulted"
566 " (despite inactive namespace support");
567 }
568#endif
569}
571
572/* Test that non-name characters after a colon are rejected */
574 const char *text = "<foo:e xmlns:foo='http://example.org/' foo:?ar='baz' />";
575
577 "Invalid character in leafname not faulted");
578}
580
582 const char *text = "<foo:?oc xmlns:foo='http://example.org/' />";
583
585 "Invalid character in element leafname not faulted");
586}
588
589/* Test high-byte-set UTF-16 characters are valid in a leafname */
591 const char text[] =
592 /* <n:e xmlns:n='URI' n:{KHO KHWAI}='a' />
593 * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8
594 */
595 "<\0n\0:\0e\0 \0x\0m\0l\0n\0s\0:\0n\0=\0'\0U\0R\0I\0'\0 \0"
596 "n\0:\0\x04\x0e=\0'\0a\0'\0 \0/\0>\0";
597 const XML_Char *expected = XCS("a");
599
603 if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE)
607}
609
611 const char text[] =
612 /* <n:{KHO KHWAI} xmlns:n='URI'/>
613 * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8
614 */
615 "\0<\0n\0:\x0e\x04\0 \0x\0m\0l\0n\0s\0:\0n\0=\0'\0U\0R\0I\0'\0/\0>";
616#ifdef XML_UNICODE
617 const XML_Char *expected = XCS("URI \x0e04");
618#else
619 const XML_Char *expected = XCS("URI \xe0\xb8\x84");
620#endif
622
626 if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE)
630}
632
634 const char text[] =
635 /* <!DOCTYPE foo:{KHO KHWAI} [ <!ENTITY bar 'baz'> ]>\n
636 * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8
637 */
638 "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0f\0o\0o\0:\x0e\x04\0 "
639 "\0[\0 \0<\0!\0E\0N\0T\0I\0T\0Y\0 \0b\0a\0r\0 \0'\0b\0a\0z\0'\0>\0 "
640 "\0]\0>\0\n"
641 /* <foo:{KHO KHWAI} xmlns:foo='URI'>&bar;</foo:{KHO KHWAI}> */
642 "\0<\0f\0o\0o\0:\x0e\x04\0 "
643 "\0x\0m\0l\0n\0s\0:\0f\0o\0o\0=\0'\0U\0R\0I\0'\0>"
644 "\0&\0b\0a\0r\0;"
645 "\0<\0/\0f\0o\0o\0:\x0e\x04\0>";
646#ifdef XML_UNICODE
647 const XML_Char *expected = XCS("URI \x0e04");
648#else
649 const XML_Char *expected = XCS("URI \xe0\xb8\x84");
650#endif
652
657 if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE)
661}
663
665 const char *text = "<!DOCTYPE foo:!bad [ <!ENTITY bar 'baz' ]>\n"
666 "<foo:!bad>&bar;</foo:!bad>";
667
669 "Invalid character in document local name not faulted");
670}
672
674 const char *text = "<!DOCTYPE foo:a:doc [ <!ENTITY bar 'baz' ]>\n"
675 "<foo:a:doc>&bar;</foo:a:doc>";
676
678 "Double colon in document name not faulted");
679}
681
683 struct test_case {
685 const char *doc;
687 };
688 struct test_case cases[] = {
689 {XML_STATUS_OK, "<doc xmlns='one_two' />", XCS('\n')},
690 {XML_STATUS_ERROR, "<doc xmlns='one&#x0A;two' />", XCS('\n')},
691 {XML_STATUS_OK, "<doc xmlns='one:two' />", XCS(':')},
692 };
693
694 size_t i = 0;
695 size_t failCount = 0;
696 for (; i < sizeof(cases) / sizeof(cases[0]); i++) {
697 set_subtest("%s", cases[i].doc);
700 if (_XML_Parse_SINGLE_BYTES(parser, cases[i].doc, (int)strlen(cases[i].doc),
701 /*isFinal*/ XML_TRUE)
702 != cases[i].expectedStatus) {
703 failCount++;
704 }
706 }
707
708 if (failCount) {
709 fail("Namespace separator handling is broken");
710 }
711}
713
714void
716 TCase *tc_namespace = tcase_create("XML namespaces");
717
754}
void tcase_add_test__if_xml_ge(TCase *tc, tcase_test_function test)
Definition common.c:159
void tcase_add_test__ifdef_xml_dtd(TCase *tc, tcase_test_function test)
Definition common.c:149
void basic_teardown(void)
Definition common.c:169
enum XML_Status _XML_Parse_SINGLE_BYTES(XML_Parser parser, const char *s, int len, int isFinal)
Definition common.c:193
void CharData_Init(CharData *storage)
Definition chardata.c:61
int CharData_CheckXMLChars(CharData *storage, const XML_Char *expected)
Definition chardata.c:87
#define XCS(s)
Definition common.h:77
XML_Parser g_parser
Definition runtests.c:62
#define expect_failure(text, errorCode, errorMessage)
Definition common.h:108
#define run_character_check(text, expected)
Definition common.h:117
#define xml_failure(parser)
Definition common.h:99
void XMLCALL dummy_start_element(void *userData, const XML_Char *name, const XML_Char **atts)
Definition dummy.c:162
void XMLCALL dummy_end_element(void *userData, const XML_Char *name)
Definition dummy.c:171
void XMLCALL dummy_end_namespace_decl_handler(void *userData, const XML_Char *prefix)
Definition dummy.c:205
void XMLCALL dummy_start_namespace_decl_handler(void *userData, const XML_Char *prefix, const XML_Char *uri)
Definition dummy.c:196
void init_dummy_handlers(void)
Definition dummy.c:54
unsigned long get_dummy_handler_flags(void)
Definition dummy.c:59
#define DUMMY_END_NS_DECL_HANDLER_FLAG
Definition dummy.h:63
#define DUMMY_START_NS_DECL_HANDLER_FLAG
Definition dummy.h:62
#define XML_FALSE
Definition expat.h:59
void XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status)
Definition xmlparse.c:2310
@ XML_FINISHED
Definition expat.h:845
@ XML_INITIALIZED
Definition expat.h:845
#define XML_STATUS_ERROR
Definition expat.h:76
void XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, XML_EndElementHandler end)
Definition xmlparse.c:1691
void XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler handler)
Definition xmlparse.c:1700
void XML_SetStartNamespaceDeclHandler(XML_Parser parser, XML_StartNamespaceDeclHandler start)
Definition xmlparse.c:1817
void XML_UseParserAsHandlerArg(XML_Parser parser)
Definition xmlparse.c:1603
XML_Bool XML_ParserReset(XML_Parser parser, const XML_Char *encoding)
Definition xmlparse.c:1286
@ XML_ERROR_DUPLICATE_ATTRIBUTE
Definition expat.h:92
@ XML_ERROR_RESERVED_PREFIX_XML
Definition expat.h:125
@ XML_ERROR_RESERVED_NAMESPACE_URI
Definition expat.h:127
@ XML_ERROR_UNBOUND_PREFIX
Definition expat.h:112
@ XML_ERROR_UNDECLARING_PREFIX
Definition expat.h:114
@ XML_ERROR_INVALID_TOKEN
Definition expat.h:88
@ XML_ERROR_SYNTAX
Definition expat.h:86
@ XML_ERROR_RESERVED_PREFIX_XMLNS
Definition expat.h:126
void XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler)
Definition xmlparse.c:1706
void XML_SetUnknownEncodingHandler(XML_Parser parser, XML_UnknownEncodingHandler handler, void *encodingHandlerData)
Definition xmlparse.c:1862
enum XML_Error XML_GetErrorCode(XML_Parser parser)
Definition xmlparse.c:2318
@ XML_PARAM_ENTITY_PARSING_ALWAYS
Definition expat.h:883
void XML_SetNamespaceDeclHandler(XML_Parser parser, XML_StartNamespaceDeclHandler start, XML_EndNamespaceDeclHandler end)
Definition xmlparse.c:1807
void XML_ParserFree(XML_Parser parser)
Definition xmlparse.c:1537
void XML_SetReturnNSTriplet(XML_Parser parser, int do_nst)
Definition xmlparse.c:1626
void XML_SetUserData(XML_Parser parser, void *userData)
Definition xmlparse.c:1637
#define XML_STATUS_OK
Definition expat.h:78
void XML_SetEndNamespaceDeclHandler(XML_Parser parser, XML_EndNamespaceDeclHandler end)
Definition xmlparse.c:1824
XML_Parser XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator)
Definition xmlparse.c:771
void XML_SetExternalEntityRefHandler(XML_Parser parser, XML_ExternalEntityRefHandler handler)
Definition xmlparse.c:1838
#define XML_TRUE
Definition expat.h:58
int XML_SetParamEntityParsing(XML_Parser parser, enum XML_ParamEntityParsing parsing)
Definition xmlparse.c:1895
XML_Status
Definition expat.h:74
char XML_Char
apr_text_header const char * text
Definition apr_xml.h:78
apr_xml_parser ** parser
Definition apr_xml.h:228
apr_size_t size
apr_array_header_t ** result
const char * s
Definition apr_strings.h:95
int int status
void XMLCALL start_element_fail(void *userData, const XML_Char *name, const XML_Char **atts)
Definition handlers.c:241
int g_triplet_start_flag
Definition handlers.c:181
int XMLCALL MiscEncodingHandler(void *data, const XML_Char *encoding, XML_Encoding *info)
Definition handlers.c:349
int g_triplet_end_flag
Definition handlers.c:182
void XMLCALL accumulate_attribute(void *userData, const XML_Char *name, const XML_Char **atts)
Definition handlers.c:1916
void XMLCALL triplet_end_checker(void *userData, const XML_Char *name)
Definition handlers.c:207
void XMLCALL overwrite_end_checker(void *userData, const XML_Char *name)
Definition handlers.c:233
int XMLCALL external_entity_handler(XML_Parser parser, const XML_Char *context, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId)
Definition handlers.c:1236
void XMLCALL overwrite_start_checker(void *userData, const XML_Char *name, const XML_Char **atts)
Definition handlers.c:219
void XMLCALL triplet_start_checker(void *userData, const XML_Char *name, const XML_Char **atts)
Definition handlers.c:185
void XMLCALL start_ns_clearing_start_element(void *userData, const XML_Char *prefix, const XML_Char *uri)
Definition handlers.c:252
void XMLCALL start_element_event_handler(void *userData, const XML_Char *name, const XML_Char **atts)
Definition handlers.c:74
void tcase_add_test(TCase *tc, tcase_test_function test)
Definition minicheck.c:92
void suite_add_tcase(Suite *suite, TCase *tc)
Definition minicheck.c:74
void set_subtest(char const *fmt,...)
Definition minicheck.c:157
void tcase_add_checked_fixture(TCase *tc, tcase_setup_function setup, tcase_teardown_function teardown)
Definition minicheck.c:84
TCase * tcase_create(const char *name)
Definition minicheck.c:65
#define fail(msg)
Definition minicheck.h:87
#define END_TEST
Definition minicheck.h:81
#define START_TEST(testname)
Definition minicheck.h:77
static const ap_slotmem_provider_t * storage
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
static void test_ns_reserved_attributes(void)
Definition ns_tests.c:400
static void namespace_teardown(void)
Definition ns_tests.c:64
static void test_ns_double_colon(void)
Definition ns_tests.c:534
static void run_ns_tagname_overwrite_test(const char *text, const XML_Char *result)
Definition ns_tests.c:122
static void test_ns_double_colon_element(void)
Definition ns_tests.c:553
static void test_ns_unbound_prefix_on_element(void)
Definition ns_tests.c:342
void make_namespace_test_case(Suite *s)
Definition ns_tests.c:715
static void test_ns_reserved_attributes_2(void)
Definition ns_tests.c:415
static void test_ns_utf16_doctype(void)
Definition ns_tests.c:633
static void test_ns_parser_reset(void)
Definition ns_tests.c:104
static void test_ns_separator_in_uri(void)
Definition ns_tests.c:682
static void test_ns_duplicate_attrs_diff_prefixes(void)
Definition ns_tests.c:299
static void test_ns_unbound_prefix(void)
Definition ns_tests.c:268
static void test_ns_prefix_with_empty_uri_4(void)
Definition ns_tests.c:247
static void test_ns_prefix_with_empty_uri_3(void)
Definition ns_tests.c:233
static void test_ns_mixed_prefix_atts(void)
Definition ns_tests.c:371
static void test_ns_unbound_prefix_on_attribute(void)
Definition ns_tests.c:334
static void test_ns_duplicate_hashes(void)
Definition ns_tests.c:308
static void test_ns_long_element(void)
Definition ns_tests.c:350
static void test_ns_prefix_with_empty_uri_1(void)
Definition ns_tests.c:211
static void test_return_ns_triplet(void)
Definition ns_tests.c:68
static void test_ns_tagname_overwrite(void)
Definition ns_tests.c:135
static void namespace_setup(void)
Definition ns_tests.c:57
static void test_ns_tagname_overwrite_triplet(void)
Definition ns_tests.c:153
static void test_ns_utf16_leafname(void)
Definition ns_tests.c:590
static void test_ns_double_colon_doctype(void)
Definition ns_tests.c:673
static void test_start_ns_clears_start_element(void)
Definition ns_tests.c:172
static void test_ns_extremely_long_prefix(void)
Definition ns_tests.c:435
static void test_ns_bad_attr_leafname(void)
Definition ns_tests.c:573
static void test_ns_invalid_doctype(void)
Definition ns_tests.c:664
static void test_ns_unknown_encoding_success(void)
Definition ns_tests.c:524
static void test_ns_prefix_with_empty_uri_2(void)
Definition ns_tests.c:223
static void test_ns_bad_element_leafname(void)
Definition ns_tests.c:581
static void test_ns_default_with_empty_uri(void)
Definition ns_tests.c:284
static void test_ns_extend_uri_buffer(void)
Definition ns_tests.c:386
static void test_ns_utf16_element_leafname(void)
Definition ns_tests.c:610
static void test_default_ns_from_ext_subset_and_ext_ge(void)
Definition ns_tests.c:190