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