Move framework for allocation tests to new alloc_tests.c

Note that the alloc_setup and alloc_teardown functions are
not static for the moment, since they will be required in both
alloc_tests.c and runtests.c until the test case move is complete.
This commit is contained in:
Rhodri James 2022-10-31 16:24:38 +00:00
parent 38d65ef5f3
commit badcbe21f7
5 changed files with 140 additions and 20 deletions

View file

@ -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

View file

@ -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 \

73
expat/tests/alloc_tests.c Normal file
View file

@ -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. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Dong-hee Na <donghee.na@python.org>
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 */
}

62
expat/tests/alloc_tests.h Normal file
View file

@ -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. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Dong-hee Na <donghee.na@python.org>
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

View file

@ -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 = "<?xml version='1.0' encoding='utf-8'?>\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);