lib: Hide some test-only code behind new macro XML_TESTING

This commit is contained in:
Sebastian Pipping 2024-02-21 12:53:48 +01:00
parent a4a420eedc
commit 7e2a0da9ba
6 changed files with 24 additions and 5 deletions

View file

@ -676,6 +676,8 @@ if(EXPAT_BUILD_TESTS)
)
foreach(_target ${_EXPAT_TEST_TARGETS})
target_compile_definitions(${_target} PRIVATE -DXML_TESTING)
set_property(TARGET ${_target} PROPERTY RUNTIME_OUTPUT_DIRECTORY tests)
expat_add_test(${_target} $<TARGET_FILE:${_target}>)

View file

@ -68,6 +68,7 @@ flags=(
-DXML_DTD
-DXML_GE
-DXML_NS
-DXML_TESTING
)
if [[ $# -gt 0 ]]; then

View file

@ -52,6 +52,8 @@ libexpat_la_SOURCES = \
xmlrole.c
if WITH_TESTS
libtestpat_la_CPPFLAGS = -DXML_TESTING
libtestpat_la_SOURCES = $(libexpat_la_SOURCES)
endif

View file

@ -161,8 +161,14 @@ unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser);
const char *unsignedCharToPrintable(unsigned char c);
#endif
extern XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c
extern unsigned int g_bytesScanned; // used for testing only
extern
#if ! defined(XML_TESTING)
const
#endif
XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c
#if defined(XML_TESTING)
extern unsigned int g_bytesScanned; // used for testing only
#endif
#ifdef __cplusplus
}

View file

@ -629,8 +629,14 @@ static unsigned long getDebugLevel(const char *variableName,
? 0 \
: ((*((pool)->ptr)++ = c), 1))
XML_Bool g_reparseDeferralEnabledDefault = XML_TRUE; // write ONLY in runtests.c
unsigned int g_bytesScanned = 0; // used for testing only
#if ! defined(XML_TESTING)
const
#endif
XML_Bool g_reparseDeferralEnabledDefault
= XML_TRUE; // write ONLY in runtests.c
#if defined(XML_TESTING)
unsigned int g_bytesScanned = 0; // used for testing only
#endif
struct XML_ParserStruct {
/* The first member must be m_userData so that the XML_GetUserData
@ -1017,7 +1023,9 @@ callProcessor(XML_Parser parser, const char *start, const char *end,
return XML_ERROR_NONE;
}
}
#if defined(XML_TESTING)
g_bytesScanned += (unsigned)have_now;
#endif
const enum XML_Error ret = parser->m_processor(parser, start, end, endPtr);
if (ret == XML_ERROR_NONE) {
// if we consumed nothing, remember what we had on this parse attempt.

View file

@ -32,7 +32,7 @@
SUBDIRS = . benchmark
AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib
AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib -DXML_TESTING
check_PROGRAMS = runtests runtests_cxx
TESTS = runtests runtests_cxx