common.h 5.7 KB

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