From c93b632b85cd9a7634c0c10d724b1448b3aa5f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfram=20R=C3=B6sler?= Date: Fri, 12 Jan 2018 10:49:07 +0100 Subject: [PATCH] Add test for binary data transparency - FAILS! Add the new test case ValueTest/binary which does the following: * Create a string with 1 million random bytes * Create a Json::Value that holds this string * Convert this value to the "styled string" representation * Scan this representation into another Json::Value using ">>" * Extract the string contents of that value * Compare the result to the random string we started with In version 1.8.4 the test fails. It seems like conversion of Json::Values to/from the "styled string" representation is no longer transparent with respect to strings that hold random data. (Note that the test string is most certainly not properly UTF-8 encoded.) WARNING: This commit contains a failing test case. Merging it will break the build. --- src/test_lib_json/main.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index d00e107a3..a9161687b 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -345,6 +345,21 @@ JSONTEST_FIXTURE(ValueTest, strings) { JSONTEST_ASSERT_STRING_EQUAL("a", string1_.asCString()); } +JSONTEST_FIXTURE(ValueTest, binary) { + std::string s; + for(auto _=0;_<1000*1000;++_) { + s += char(rand() % 0xFF); + } + + Json::Value a = s; + JSONTEST_ASSERT(a.asString()==s); + + std::istringstream iss(a.toStyledString()); + Json::Value b; + iss >> b; + JSONTEST_ASSERT(b.asString()==s); +} + JSONTEST_FIXTURE(ValueTest, bools) { JSONTEST_ASSERT_EQUAL(Json::booleanValue, false_.type()); @@ -2532,6 +2547,7 @@ int main(int argc, const char* argv[]) { JSONTEST_REGISTER_FIXTURE(runner, ValueTest, arrayIssue252); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, null); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, strings); + JSONTEST_REGISTER_FIXTURE(runner, ValueTest, binary); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, bools); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, integers); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, nonIntegers);