diff --git a/test/src/unit-bson.cpp b/test/src/unit-bson.cpp index ee5bf06d..be53fa8e 100644 --- a/test/src/unit-bson.cpp +++ b/test/src/unit-bson.cpp @@ -584,10 +584,9 @@ TEST_CASE("BSON input/output_adapters") { SECTION("std::ostringstream") { - std::ostringstream ss; + std::basic_ostringstream ss; json::to_bson(json_representation, ss); - std::istringstream iss(ss.str()); - json j3 = json::from_bson(iss); + json j3 = json::from_bson(ss.str()); CHECK(json_representation == j3); } diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index 73f23386..b7c2e2c9 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -1580,7 +1580,7 @@ TEST_CASE("single CBOR roundtrip") { SECTION("std::ostringstream") { - std::ostringstream ss; + std::basic_ostringstream ss; json::to_cbor(j1, ss); json j3 = json::from_cbor(ss.str()); CHECK(j1 == j3); diff --git a/test/src/unit-msgpack.cpp b/test/src/unit-msgpack.cpp index d37c3678..391cd883 100644 --- a/test/src/unit-msgpack.cpp +++ b/test/src/unit-msgpack.cpp @@ -1334,7 +1334,7 @@ TEST_CASE("single MessagePack roundtrip") { SECTION("std::ostringstream") { - std::ostringstream ss; + std::basic_ostringstream ss; json::to_msgpack(j1, ss); json j3 = json::from_msgpack(ss.str()); CHECK(j1 == j3); diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index 17672248..d60f7a55 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -1749,31 +1749,37 @@ TEST_CASE("regression tests") { SECTION("a bunch of -1, ensure_ascii=true") { + const auto length = 300; + json dump_test; - std::vector data(300, -1); - std::vector vec_string(300, "\\ufffd"); - std::string s{data.data(), data.size()}; - dump_test["1"] = s; - std::ostringstream os; - os << "{\"1\":\""; - std::copy( vec_string.begin(), vec_string.end(), std::ostream_iterator(os)); - os << "\"}"; - s = dump_test.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace); - CHECK(s == os.str()); + dump_test["1"] = std::string(length, -1); + + std::string expected = "{\"1\":\""; + for (int i = 0; i < length; ++i) + { + expected += "\\ufffd"; + } + expected += "\"}"; + + auto s = dump_test.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace); + CHECK(s == expected); } SECTION("a bunch of -2, ensure_ascii=false") { + const auto length = 500; + json dump_test; - std::vector data(500, -2); - std::vector vec_string(500, "\xEF\xBF\xBD"); - std::string s{data.data(), data.size()}; - dump_test["1"] = s; - std::ostringstream os; - os << "{\"1\":\""; - std::copy( vec_string.begin(), vec_string.end(), std::ostream_iterator(os)); - os << "\"}"; - s = dump_test.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace); - CHECK(s == os.str()); + dump_test["1"] = std::string(length, -2); + + std::string expected = "{\"1\":\""; + for (int i = 0; i < length; ++i) + { + expected += "\xEF\xBF\xBD"; + } + expected += "\"}"; + + auto s = dump_test.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace); + CHECK(s == expected); } SECTION("test case in issue #1445") {