From 367530b6495a455ad53827bce7f331419ed2ab83 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 8 May 2021 13:30:19 +0100 Subject: Update tests to coverage encoding strings Fixes char (byte) type lookup. --- lib/jsonParse-persistence.cpp | 2 +- test/test-persistence.cpp | 44 ++++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/lib/jsonParse-persistence.cpp b/lib/jsonParse-persistence.cpp index 6ecfff8..5062796 100644 --- a/lib/jsonParse-persistence.cpp +++ b/lib/jsonParse-persistence.cpp @@ -170,7 +170,7 @@ namespace Persistence { { strm << '"'; std::for_each(value.begin(), value.end(), [this](char ch) { - outFuncs[ch](strm, ch); + outFuncs[(unsigned char)ch](strm, ch); }); strm << '"'; } diff --git a/test/test-persistence.cpp b/test/test-persistence.cpp index 547396b..ab16166 100644 --- a/test/test-persistence.cpp +++ b/test/test-persistence.cpp @@ -257,23 +257,25 @@ BOOST_FIXTURE_TEST_CASE(load_shared_object_null, JPP) } using svs = std::tuple; -BOOST_DATA_TEST_CASE_F(JPP, load_strings, - boost::unit_test::data::make({ - {R"J("")J", ""}, - {R"J("non empty")J", "non empty"}, - {R"J("new\nline")J", "new\nline"}, - {R"J("quote\"mark")J", "quote\"mark"}, - {R"J("tab\t")J", "tab\t"}, - {R"J("back\bspace?")J", "back\bspace?"}, - {R"J("form\ffeed?")J", "form\ffeed?"}, - {R"J("forward\/slash")J", "forward/slash"}, - {R"J("\u00a5 yen")J", "¥ yen"}, - {R"J("gbp \u00a3")J", "gbp £"}, - {R"J("\u007E tilde")J", "~ tilde"}, - {R"J("\u056b ARMENIAN SMALL LETTER INI")J", "ի ARMENIAN SMALL LETTER INI"}, - {R"J("\u0833 SAMARITAN PUNCTUATION BAU")J", "࠳ SAMARITAN PUNCTUATION BAU"}, - }), - in, exp) +auto const TEST_STRINGS = boost::unit_test::data::make({ + {R"J("")J", ""}, + {R"J("non empty")J", "non empty"}, + {R"J("new\nline")J", "new\nline"}, + {R"J("quote\"mark")J", "quote\"mark"}, + {R"J("tab\t")J", "tab\t"}, + {R"J("back\bspace?")J", "back\bspace?"}, + {R"J("form\ffeed?")J", "form\ffeed?"}, + {R"J("a \u0007 bell")J", "a \a bell"}, +}); +auto const TEST_STRINGS_DECODE_ONLY = boost::unit_test::data::make({ + {R"J("forward\/slash")J", "forward/slash"}, + {R"J("\u00a5 yen")J", "¥ yen"}, + {R"J("gbp \u00a3")J", "gbp £"}, + {R"J("\u007E tilde")J", "~ tilde"}, + {R"J("\u056b ARMENIAN SMALL LETTER INI")J", "ի ARMENIAN SMALL LETTER INI"}, + {R"J("\u0833 SAMARITAN PUNCTUATION BAU")J", "࠳ SAMARITAN PUNCTUATION BAU"}, +}); +BOOST_DATA_TEST_CASE_F(JPP, load_strings, TEST_STRINGS + TEST_STRINGS_DECODE_ONLY, in, exp) { std::stringstream str {in}; BOOST_CHECK_EQUAL(loadState(str), exp); @@ -346,3 +348,11 @@ BOOST_FIXTURE_TEST_CASE(write_test_loaded_shared, JPP) // BOOST_CHECK_EQUAL(ss.str(), // R"({"@typeid":"SharedTestObject","sptr":{"@typeid":"SubObject","@id":"someid"},"ssptr":"someid"})"); } + +BOOST_DATA_TEST_CASE(write_special_strings, TEST_STRINGS, exp, in) +{ + std::stringstream ss; + std::string copy(in); + Persistence::JsonWritePersistence {ss}.saveState(copy); + BOOST_CHECK_EQUAL(ss.str(), exp); +} -- cgit v1.2.3