diff --git a/expat/CMakeLists.txt b/expat/CMakeLists.txt index 94837279..3121a003 100644 --- a/expat/CMakeLists.txt +++ b/expat/CMakeLists.txt @@ -596,6 +596,7 @@ if(EXPAT_BUILD_TESTS) enable_testing() set(test_SRCS + tests/alloc_tests.c tests/basic_tests.c tests/chardata.c tests/common.c diff --git a/expat/tests/Makefile.am b/expat/tests/Makefile.am index a7e6cf3e..5c1fc655 100644 --- a/expat/tests/Makefile.am +++ b/expat/tests/Makefile.am @@ -43,6 +43,7 @@ TESTS = runtests runtestspp LOG_DRIVER = $(srcdir)/../test-driver-wrapper.sh libruntests_a_SOURCES = \ + alloc_tests.c \ basic_tests.c \ chardata.c \ common.c \ @@ -67,6 +68,7 @@ runtests_LDFLAGS = @AM_LDFLAGS@ @LIBM@ runtestspp_LDFLAGS = @AM_LDFLAGS@ @LIBM@ EXTRA_DIST = \ + alloc_tests.h \ basic_tests.h \ chardata.h \ common.h \ diff --git a/expat/tests/alloc_tests.c b/expat/tests/alloc_tests.c new file mode 100644 index 00000000..0498d7a3 --- /dev/null +++ b/expat/tests/alloc_tests.c @@ -0,0 +1,73 @@ +/* Tests in the "allocation" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. + Copyright (c) 2003 Greg Stein + Copyright (c) 2005-2007 Steven Solie + Copyright (c) 2005-2012 Karl Waclawek + Copyright (c) 2016-2022 Sebastian Pipping + Copyright (c) 2017-2022 Rhodri James + Copyright (c) 2017 Joe Orton + Copyright (c) 2017 José Gutiérrez de la Concha + Copyright (c) 2018 Marco Maggi + Copyright (c) 2019 David Loffredo + Copyright (c) 2020 Tim Gates + Copyright (c) 2021 Dong-hee Na + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "expat.h" +#include "common.h" +#include "minicheck.h" +#include "alloc_tests.h" + +void +alloc_setup(void) { + XML_Memory_Handling_Suite memsuite = {duff_allocator, duff_reallocator, free}; + + /* Ensure the parser creation will go through */ + g_allocation_count = ALLOC_ALWAYS_SUCCEED; + g_reallocation_count = REALLOC_ALWAYS_SUCCEED; + g_parser = XML_ParserCreate_MM(NULL, &memsuite, NULL); + if (g_parser == NULL) + fail("Parser not created"); +} + +void +alloc_teardown(void) { + basic_teardown(); +} + +TCase * +make_alloc_test_case(Suite *s) { + TCase *tc_alloc = tcase_create("allocation tests"); + + suite_add_tcase(s, tc_alloc); + tcase_add_checked_fixture(tc_alloc, alloc_setup, alloc_teardown); + + return tc_alloc; /* TEMPORARY: this will become a void function */ +} diff --git a/expat/tests/alloc_tests.h b/expat/tests/alloc_tests.h new file mode 100644 index 00000000..3517aeb7 --- /dev/null +++ b/expat/tests/alloc_tests.h @@ -0,0 +1,62 @@ +/* Tests in the "allocation" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. + Copyright (c) 2003 Greg Stein + Copyright (c) 2005-2007 Steven Solie + Copyright (c) 2005-2012 Karl Waclawek + Copyright (c) 2016-2022 Sebastian Pipping + Copyright (c) 2017-2022 Rhodri James + Copyright (c) 2017 Joe Orton + Copyright (c) 2017 José Gutiérrez de la Concha + Copyright (c) 2018 Marco Maggi + Copyright (c) 2019 David Loffredo + Copyright (c) 2020 Tim Gates + Copyright (c) 2021 Dong-hee Na + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef XML_ALLOC_TESTS_H +# define XML_ALLOC_TESTS_H + +/* TEMPORARY: these will return to being static functions once all + * the test cases are transferred to alloc_tests.c + */ +extern void alloc_setup(void); +extern void alloc_teardown(void); + +extern TCase *make_alloc_test_case(Suite *s); + +#endif /* XML_ALLOC_TESTS_H */ + +#ifdef __cplusplus +} +#endif diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index 33aa8424..9d451a99 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -72,26 +72,10 @@ #include "basic_tests.h" #include "ns_tests.h" #include "misc_tests.h" +#include "alloc_tests.h" XML_Parser g_parser = NULL; -static void -alloc_setup(void) { - XML_Memory_Handling_Suite memsuite = {duff_allocator, duff_reallocator, free}; - - /* Ensure the parser creation will go through */ - g_allocation_count = ALLOC_ALWAYS_SUCCEED; - g_reallocation_count = REALLOC_ALWAYS_SUCCEED; - g_parser = XML_ParserCreate_MM(NULL, &memsuite, NULL); - if (g_parser == NULL) - fail("Parser not created"); -} - -static void -alloc_teardown(void) { - basic_teardown(); -} - /* Test the effects of allocation failures on xml declaration processing */ START_TEST(test_alloc_parse_xdecl) { const char *text = "\n" @@ -4168,14 +4152,12 @@ make_suite(void) { make_basic_test_case(s); make_namespace_test_case(s); make_miscellaneous_test_case(s); - TCase *tc_alloc = tcase_create("allocation tests"); + TCase *tc_alloc = make_alloc_test_case(s); TCase *tc_nsalloc = tcase_create("namespace allocation tests"); #if defined(XML_DTD) TCase *tc_accounting = tcase_create("accounting tests"); #endif - suite_add_tcase(s, tc_alloc); - tcase_add_checked_fixture(tc_alloc, alloc_setup, alloc_teardown); tcase_add_test(tc_alloc, test_alloc_parse_xdecl); tcase_add_test(tc_alloc, test_alloc_parse_xdecl_2); tcase_add_test(tc_alloc, test_alloc_parse_pi);