1 1.1 wiz /* Commonly used functions for the Expat test suite 2 1.1 wiz __ __ _ 3 1.1 wiz ___\ \/ /_ __ __ _| |_ 4 1.1 wiz / _ \\ /| '_ \ / _` | __| 5 1.1 wiz | __// \| |_) | (_| | |_ 6 1.1 wiz \___/_/\_\ .__/ \__,_|\__| 7 1.1 wiz |_| XML parser 8 1.1 wiz 9 1.1 wiz Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake (at) users.sourceforge.net> 10 1.1 wiz Copyright (c) 2003 Greg Stein <gstein (at) users.sourceforge.net> 11 1.1 wiz Copyright (c) 2005-2007 Steven Solie <steven (at) solie.ca> 12 1.1 wiz Copyright (c) 2005-2012 Karl Waclawek <karl (at) waclawek.net> 13 1.1.1.2 wiz Copyright (c) 2016-2025 Sebastian Pipping <sebastian (at) pipping.org> 14 1.1 wiz Copyright (c) 2017-2022 Rhodri James <rhodri (at) wildebeest.org.uk> 15 1.1 wiz Copyright (c) 2017 Joe Orton <jorton (at) redhat.com> 16 1.1 wiz Copyright (c) 2017 Jos Gutirrez de la Concha <jose (at) zeroc.com> 17 1.1 wiz Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu (at) poste.it> 18 1.1 wiz Copyright (c) 2019 David Loffredo <loffredo (at) steptools.com> 19 1.1 wiz Copyright (c) 2020 Tim Gates <tim.gates (at) iress.com> 20 1.1 wiz Copyright (c) 2021 Donghee Na <donghee.na (at) python.org> 21 1.1 wiz Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild (at) sony.com> 22 1.1 wiz Licensed under the MIT license: 23 1.1 wiz 24 1.1 wiz Permission is hereby granted, free of charge, to any person obtaining 25 1.1 wiz a copy of this software and associated documentation files (the 26 1.1 wiz "Software"), to deal in the Software without restriction, including 27 1.1 wiz without limitation the rights to use, copy, modify, merge, publish, 28 1.1 wiz distribute, sublicense, and/or sell copies of the Software, and to permit 29 1.1 wiz persons to whom the Software is furnished to do so, subject to the 30 1.1 wiz following conditions: 31 1.1 wiz 32 1.1 wiz The above copyright notice and this permission notice shall be included 33 1.1 wiz in all copies or substantial portions of the Software. 34 1.1 wiz 35 1.1 wiz THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 36 1.1 wiz EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 37 1.1 wiz MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 38 1.1 wiz NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 39 1.1 wiz DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 40 1.1 wiz OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 41 1.1 wiz USE OR OTHER DEALINGS IN THE SOFTWARE. 42 1.1 wiz */ 43 1.1 wiz 44 1.1 wiz #ifdef __cplusplus 45 1.1 wiz extern "C" { 46 1.1 wiz #endif 47 1.1 wiz 48 1.1 wiz #ifndef XML_COMMON_H 49 1.1 wiz # define XML_COMMON_H 50 1.1 wiz 51 1.1 wiz # include "expat_config.h" 52 1.1 wiz # include "minicheck.h" 53 1.1 wiz # include "chardata.h" 54 1.1 wiz 55 1.1 wiz # ifdef XML_LARGE_SIZE 56 1.1 wiz # define XML_FMT_INT_MOD "ll" 57 1.1 wiz # else 58 1.1 wiz # define XML_FMT_INT_MOD "l" 59 1.1 wiz # endif 60 1.1 wiz 61 1.1 wiz # ifdef XML_UNICODE_WCHAR_T 62 1.1 wiz # define XML_FMT_STR "ls" 63 1.1 wiz # include <wchar.h> 64 1.1 wiz # define xcstrlen(s) wcslen(s) 65 1.1 wiz # define xcstrcmp(s, t) wcscmp((s), (t)) 66 1.1 wiz # define xcstrncmp(s, t, n) wcsncmp((s), (t), (n)) 67 1.1 wiz # define XCS(s) _XCS(s) 68 1.1 wiz # define _XCS(s) L##s 69 1.1 wiz # else 70 1.1 wiz # ifdef XML_UNICODE 71 1.1 wiz # error "No support for UTF-16 character without wchar_t in tests" 72 1.1 wiz # else 73 1.1 wiz # define XML_FMT_STR "s" 74 1.1 wiz # define xcstrlen(s) strlen(s) 75 1.1 wiz # define xcstrcmp(s, t) strcmp((s), (t)) 76 1.1 wiz # define xcstrncmp(s, t, n) strncmp((s), (t), (n)) 77 1.1 wiz # define XCS(s) s 78 1.1 wiz # endif /* XML_UNICODE */ 79 1.1 wiz # endif /* XML_UNICODE_WCHAR_T */ 80 1.1 wiz 81 1.1 wiz extern XML_Parser g_parser; 82 1.1 wiz 83 1.1 wiz extern XML_Bool g_resumable; 84 1.1 wiz extern XML_Bool g_abortable; 85 1.1 wiz 86 1.1 wiz extern int g_chunkSize; 87 1.1 wiz 88 1.1 wiz extern const char *long_character_data_text; 89 1.1 wiz extern const char *long_cdata_text; 90 1.1 wiz extern const char *get_buffer_test_text; 91 1.1 wiz 92 1.1 wiz extern void tcase_add_test__ifdef_xml_dtd(TCase *tc, tcase_test_function test); 93 1.1 wiz extern void tcase_add_test__if_xml_ge(TCase *tc, tcase_test_function test); 94 1.1 wiz 95 1.1 wiz extern void basic_teardown(void); 96 1.1 wiz 97 1.1 wiz extern void _xml_failure(XML_Parser parser, const char *file, int line); 98 1.1 wiz 99 1.1 wiz # define xml_failure(parser) _xml_failure((parser), __FILE__, __LINE__) 100 1.1 wiz 101 1.1 wiz extern enum XML_Status _XML_Parse_SINGLE_BYTES(XML_Parser parser, const char *s, 102 1.1 wiz int len, int isFinal); 103 1.1 wiz 104 1.1 wiz extern void _expect_failure(const char *text, enum XML_Error errorCode, 105 1.1 wiz const char *errorMessage, const char *file, 106 1.1 wiz int lineno); 107 1.1 wiz 108 1.1 wiz # define expect_failure(text, errorCode, errorMessage) \ 109 1.1 wiz _expect_failure((text), (errorCode), (errorMessage), __FILE__, __LINE__) 110 1.1 wiz 111 1.1 wiz /* Support functions for handlers to collect up character and attribute data. 112 1.1 wiz */ 113 1.1 wiz 114 1.1 wiz extern void _run_character_check(const char *text, const XML_Char *expected, 115 1.1 wiz const char *file, int line); 116 1.1 wiz 117 1.1 wiz # define run_character_check(text, expected) \ 118 1.1 wiz _run_character_check(text, expected, __FILE__, __LINE__) 119 1.1 wiz 120 1.1 wiz extern void _run_attribute_check(const char *text, const XML_Char *expected, 121 1.1 wiz const char *file, int line); 122 1.1 wiz 123 1.1 wiz # define run_attribute_check(text, expected) \ 124 1.1 wiz _run_attribute_check(text, expected, __FILE__, __LINE__) 125 1.1 wiz 126 1.1 wiz typedef struct ExtTest { 127 1.1 wiz const char *parse_text; 128 1.1 wiz const XML_Char *encoding; 129 1.1 wiz CharData *storage; 130 1.1 wiz } ExtTest; 131 1.1 wiz 132 1.1 wiz extern void _run_ext_character_check(const char *text, ExtTest *test_data, 133 1.1 wiz const XML_Char *expected, const char *file, 134 1.1 wiz int line); 135 1.1 wiz 136 1.1 wiz # define run_ext_character_check(text, test_data, expected) \ 137 1.1 wiz _run_ext_character_check(text, test_data, expected, __FILE__, __LINE__) 138 1.1 wiz 139 1.1 wiz # define ALLOC_ALWAYS_SUCCEED (-1) 140 1.1 wiz # define REALLOC_ALWAYS_SUCCEED (-1) 141 1.1 wiz 142 1.1 wiz extern int g_allocation_count; 143 1.1 wiz extern int g_reallocation_count; 144 1.1 wiz 145 1.1 wiz extern void *duff_allocator(size_t size); 146 1.1 wiz 147 1.1 wiz extern void *duff_reallocator(void *ptr, size_t size); 148 1.1 wiz 149 1.1.1.2 wiz extern char *portable_strndup(const char *s, size_t n); 150 1.1.1.2 wiz 151 1.1 wiz #endif /* XML_COMMON_H */ 152 1.1 wiz 153 1.1 wiz #ifdef __cplusplus 154 1.1 wiz } 155 1.1 wiz #endif 156