summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pipping <sebastian@pipping.org>2021-04-26 15:12:53 +0200
committerSebastian Pipping <sebastian@pipping.org>2021-05-07 18:25:08 +0200
commit5dbc857f47ecd6c37748ce279c6535fbbf526590 (patch)
treef2d66b9d96da95ec2f0acde646a4c69c26edefb3
parente9d8f115580c3a25a9579c213f096af623dd92ce (diff)
downloadlibexpat-git-5dbc857f47ecd6c37748ce279c6535fbbf526590.tar.gz
tests: Cover helper unsignedCharToPrintable
-rw-r--r--expat/lib/internal.h1
-rw-r--r--expat/lib/xmlparse.c3
-rw-r--r--expat/tests/runtests.c20
3 files changed, 22 insertions, 2 deletions
diff --git a/expat/lib/internal.h b/expat/lib/internal.h
index 377c12b6..444eba0f 100644
--- a/expat/lib/internal.h
+++ b/expat/lib/internal.h
@@ -155,6 +155,7 @@ void _INTERNAL_trim_to_complete_utf8_characters(const char *from,
#if defined(XML_DTD)
unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser);
unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser);
+const char *unsignedCharToPrintable(unsigned char c);
#endif
#ifdef __cplusplus
diff --git a/expat/lib/xmlparse.c b/expat/lib/xmlparse.c
index adaab233..a1aadd86 100644
--- a/expat/lib/xmlparse.c
+++ b/expat/lib/xmlparse.c
@@ -580,7 +580,6 @@ static void entityTrackingOnClose(XML_Parser parser, ENTITY *entity,
static XML_Parser getRootParserOf(XML_Parser parser,
unsigned int *outLevelDiff);
-static const char *unsignedCharToPrintable(unsigned char c);
#endif /* XML_DTD */
static unsigned long getDebugLevel(const char *variableName,
@@ -7433,7 +7432,7 @@ getRootParserOf(XML_Parser parser, unsigned int *outLevelDiff) {
return rootParser;
}
-static const char *
+const char *
unsignedCharToPrintable(unsigned char c) {
switch (c) {
case 0:
diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c
index 8c5ad72b..0e2b49fa 100644
--- a/expat/tests/runtests.c
+++ b/expat/tests/runtests.c
@@ -11578,6 +11578,25 @@ START_TEST(test_billion_laughs_attack_protection_api) {
XML_ParserFree(parserWithoutParent);
}
END_TEST
+
+START_TEST(test_helper_unsigned_char_to_printable) {
+ // Smoke test
+ unsigned char uc = 0;
+ for (; uc < (unsigned char)-1; uc++) {
+ const char *const printable = unsignedCharToPrintable(uc);
+ if (printable == NULL)
+ fail("unsignedCharToPrintable returned NULL");
+ if (strlen(printable) < (size_t)1)
+ fail("unsignedCharToPrintable returned empty string");
+ }
+
+ // Two concrete samples
+ if (strcmp(unsignedCharToPrintable('A'), "A") != 0)
+ fail("unsignedCharToPrintable result mistaken");
+ if (strcmp(unsignedCharToPrintable('\\'), "\\\\") != 0)
+ fail("unsignedCharToPrintable result mistaken");
+}
+END_TEST
#endif // defined(XML_DTD)
static Suite *
@@ -11955,6 +11974,7 @@ make_suite(void) {
suite_add_tcase(s, tc_accounting);
tcase_add_test(tc_accounting, test_accounting_precision);
tcase_add_test(tc_accounting, test_billion_laughs_attack_protection_api);
+ tcase_add_test(tc_accounting, test_helper_unsigned_char_to_printable);
#endif
return s;