diff --git a/tests/src/unit-bson.cpp b/tests/src/unit-bson.cpp index a231c8cca3..e7e30e94bc 100644 --- a/tests/src/unit-bson.cpp +++ b/tests/src/unit-bson.cpp @@ -12,6 +12,7 @@ using nlohmann::json; #include +#include #include #include "make_test_data_available.hpp" #include "test_utils.hpp" @@ -921,9 +922,9 @@ TEST_CASE("BSON numerical data") SECTION("signed std::int32_t: INT32_MIN .. INT32_MAX") { - std::vector numbers + std::vector numbers { - INT32_MIN, + std::numeric_limits::min(), -2147483647L, -1000000000L, -100000000L, @@ -947,12 +948,11 @@ TEST_CASE("BSON numerical data") 100000000L, 1000000000L, 2147483646L, - INT32_MAX + std::numeric_limits::max() }; for (auto i : numbers) { - CAPTURE(i) json j = @@ -988,9 +988,9 @@ TEST_CASE("BSON numerical data") SECTION("signed std::int64_t: INT32_MAX+1 .. INT64_MAX") { - std::vector numbers + std::vector numbers { - INT64_MAX, + std::numeric_limits::max(), 1000000000000000000LL, 100000000000000000LL, 10000000000000000LL, @@ -1000,12 +1000,11 @@ TEST_CASE("BSON numerical data") 1000000000000LL, 100000000000LL, 10000000000LL, - static_cast(INT32_MAX) + 1, + static_cast(std::numeric_limits::max()) + 1, }; for (auto i : numbers) { - CAPTURE(i) json j = @@ -1062,12 +1061,11 @@ TEST_CASE("BSON numerical data") 100000000ULL, 1000000000ULL, 2147483646ULL, - static_cast(INT32_MAX) + static_cast(std::numeric_limits::max()) }; for (auto i : numbers) { - CAPTURE(i) json j = @@ -1105,9 +1103,9 @@ TEST_CASE("BSON numerical data") { std::vector numbers { - static_cast(INT32_MAX) + 1, + static_cast(std::numeric_limits::max()) + 1, 4000000000ULL, - static_cast(UINT32_MAX), + static_cast(std::numeric_limits::max()), 10000000000ULL, 100000000000ULL, 1000000000000ULL, @@ -1117,12 +1115,11 @@ TEST_CASE("BSON numerical data") 10000000000000000ULL, 100000000000000000ULL, 1000000000000000000ULL, - static_cast(INT64_MAX), + static_cast(std::numeric_limits::max()), }; for (auto i : numbers) { - CAPTURE(i) json j = @@ -1163,16 +1160,15 @@ TEST_CASE("BSON numerical data") { std::vector numbers { - static_cast(INT64_MAX) + 1ULL, + static_cast(std::numeric_limits::max()) + 1ULL, 10000000000000000000ULL, 18000000000000000000ULL, - UINT64_MAX - 1ULL, - UINT64_MAX, + std::numeric_limits::max() - 1ULL, + std::numeric_limits::max() }; for (auto i : numbers) { - CAPTURE(i) json j = diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index ffa3e92d89..03c505dfde 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -12,10 +12,11 @@ using nlohmann::json; #include -#include #include #include +#include #include +#include #include "make_test_data_available.hpp" #include "test_utils.hpp" @@ -113,7 +114,7 @@ TEST_CASE("CBOR") { // NaN value json j = std::numeric_limits::quiet_NaN(); - std::vector expected = {0xf9, 0x7e, 0x00}; + std::vector expected = {0xf9, 0x7e, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); } @@ -122,7 +123,7 @@ TEST_CASE("CBOR") { // Infinity value json j = std::numeric_limits::infinity(); - std::vector expected = {0xf9, 0x7c, 0x00}; + std::vector expected = {0xf9, 0x7c, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); } @@ -130,7 +131,7 @@ TEST_CASE("CBOR") SECTION("null") { json j = nullptr; - std::vector expected = {0xf6}; + std::vector expected = {0xf6}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -144,7 +145,7 @@ TEST_CASE("CBOR") SECTION("true") { json j = true; - std::vector expected = {0xf5}; + std::vector expected = {0xf5}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -156,7 +157,7 @@ TEST_CASE("CBOR") SECTION("false") { json j = false; - std::vector expected = {0xf4}; + std::vector expected = {0xf4}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -172,8 +173,8 @@ TEST_CASE("CBOR") { SECTION("-9223372036854775808..-4294967297") { - std::vector numbers; - numbers.push_back(INT64_MIN); + std::vector numbers; + numbers.push_back(std::numeric_limits::min()); numbers.push_back(-1000000000000000000); numbers.push_back(-100000000000000000); numbers.push_back(-10000000000000000); @@ -195,17 +196,17 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x3b)); - auto positive = static_cast(-1 - i); - expected.push_back(static_cast((positive >> 56) & 0xff)); - expected.push_back(static_cast((positive >> 48) & 0xff)); - expected.push_back(static_cast((positive >> 40) & 0xff)); - expected.push_back(static_cast((positive >> 32) & 0xff)); - expected.push_back(static_cast((positive >> 24) & 0xff)); - expected.push_back(static_cast((positive >> 16) & 0xff)); - expected.push_back(static_cast((positive >> 8) & 0xff)); - expected.push_back(static_cast(positive & 0xff)); + std::vector expected; + expected.push_back(static_cast(0x3b)); + auto positive = static_cast(-1 - i); + expected.push_back(static_cast((positive >> 56) & 0xff)); + expected.push_back(static_cast((positive >> 48) & 0xff)); + expected.push_back(static_cast((positive >> 40) & 0xff)); + expected.push_back(static_cast((positive >> 32) & 0xff)); + expected.push_back(static_cast((positive >> 24) & 0xff)); + expected.push_back(static_cast((positive >> 16) & 0xff)); + expected.push_back(static_cast((positive >> 8) & 0xff)); + expected.push_back(static_cast(positive & 0xff)); // compare result + size const auto result = json::to_cbor(j); @@ -214,16 +215,16 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x3b); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + uint64_t restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == positive); - CHECK(-1 - static_cast(restored) == i); + CHECK(-1 - static_cast(restored) == i); // roundtrip CHECK(json::from_cbor(result) == j); @@ -233,7 +234,7 @@ TEST_CASE("CBOR") SECTION("-4294967296..-65537") { - std::vector numbers; + std::vector numbers; numbers.push_back(-65537); numbers.push_back(-100000); numbers.push_back(-1000000); @@ -252,13 +253,13 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x3a)); - auto positive = static_cast(static_cast(-1 - i) & 0x00000000ffffffff); - expected.push_back(static_cast((positive >> 24) & 0xff)); - expected.push_back(static_cast((positive >> 16) & 0xff)); - expected.push_back(static_cast((positive >> 8) & 0xff)); - expected.push_back(static_cast(positive & 0xff)); + std::vector expected; + expected.push_back(static_cast(0x3a)); + auto positive = static_cast(static_cast(-1 - i) & 0x00000000ffffffff); + expected.push_back(static_cast((positive >> 24) & 0xff)); + expected.push_back(static_cast((positive >> 16) & 0xff)); + expected.push_back(static_cast((positive >> 8) & 0xff)); + expected.push_back(static_cast(positive & 0xff)); // compare result + size const auto result = json::to_cbor(j); @@ -267,10 +268,10 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x3a); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + uint32_t restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == positive); CHECK(-1LL - restored == i); @@ -282,7 +283,7 @@ TEST_CASE("CBOR") SECTION("-65536..-257") { - for (int32_t i = -65536; i <= -257; ++i) + for (std::int32_t i = -65536; i <= -257; ++i) { CAPTURE(i) @@ -293,11 +294,11 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x39)); - auto positive = static_cast(-1 - i); - expected.push_back(static_cast((positive >> 8) & 0xff)); - expected.push_back(static_cast(positive & 0xff)); + std::vector expected; + expected.push_back(static_cast(0x39)); + auto positive = static_cast(-1 - i); + expected.push_back(static_cast((positive >> 8) & 0xff)); + expected.push_back(static_cast(positive & 0xff)); // compare result + size const auto result = json::to_cbor(j); @@ -306,7 +307,7 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x39); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == positive); CHECK(-1 - restored == i); @@ -319,12 +320,12 @@ TEST_CASE("CBOR") SECTION("-9263 (int 16)") { json j = -9263; - std::vector expected = {0x39, 0x24, 0x2e}; + std::vector expected = {0x39, 0x24, 0x2e}; const auto result = json::to_cbor(j); CHECK(result == expected); - auto restored = static_cast(-1 - ((result[1] << 8) + result[2])); + auto restored = static_cast(-1 - ((result[1] << 8) + result[2])); CHECK(restored == -9263); // roundtrip @@ -345,9 +346,9 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0x38); - expected.push_back(static_cast(-1 - i)); + expected.push_back(static_cast(-1 - i)); // compare result + size const auto result = json::to_cbor(j); @@ -356,7 +357,7 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x38); - CHECK(static_cast(-1 - result[1]) == i); + CHECK(static_cast(-1 - result[1]) == i); // roundtrip CHECK(json::from_cbor(result) == j); @@ -377,8 +378,8 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x20 - 1 - static_cast(i))); + std::vector expected; + expected.push_back(static_cast(0x20 - 1 - static_cast(i))); // compare result + size const auto result = json::to_cbor(j); @@ -386,7 +387,7 @@ TEST_CASE("CBOR") CHECK(result.size() == 1); // check individual bytes - CHECK(static_cast(0x20 - 1 - result[0]) == i); + CHECK(static_cast(0x20 - 1 - result[0]) == i); // roundtrip CHECK(json::from_cbor(result) == j); @@ -396,7 +397,7 @@ TEST_CASE("CBOR") SECTION("0..23") { - for (size_t i = 0; i <= 23; ++i) + for (std::size_t i = 0; i <= 23; ++i) { CAPTURE(i) @@ -408,8 +409,8 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(i)); + std::vector expected; + expected.push_back(static_cast(i)); // compare result + size const auto result = json::to_cbor(j); @@ -427,7 +428,7 @@ TEST_CASE("CBOR") SECTION("24..255") { - for (size_t i = 24; i <= 255; ++i) + for (std::size_t i = 24; i <= 255; ++i) { CAPTURE(i) @@ -439,9 +440,9 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x18)); - expected.push_back(static_cast(i)); + std::vector expected; + expected.push_back(static_cast(0x18)); + expected.push_back(static_cast(i)); // compare result + size const auto result = json::to_cbor(j); @@ -460,7 +461,7 @@ TEST_CASE("CBOR") SECTION("256..65535") { - for (size_t i = 256; i <= 65535; ++i) + for (std::size_t i = 256; i <= 65535; ++i) { CAPTURE(i) @@ -472,10 +473,10 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x19)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector expected; + expected.push_back(static_cast(0x19)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_cbor(j); @@ -484,7 +485,7 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x19); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == i); // roundtrip @@ -495,7 +496,7 @@ TEST_CASE("CBOR") SECTION("65536..4294967295") { - for (uint32_t i : + for (std::uint32_t i : { 65536u, 77777u, 1048576u }) @@ -510,12 +511,12 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0x1a); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 24) & 0xff)); + expected.push_back(static_cast((i >> 16) & 0xff)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_cbor(j); @@ -524,10 +525,10 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x1a); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + uint32_t restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == i); // roundtrip @@ -538,7 +539,7 @@ TEST_CASE("CBOR") SECTION("4294967296..4611686018427387903") { - for (uint64_t i : + for (std::uint64_t i : { 4294967296ul, 4611686018427387903ul }) @@ -553,16 +554,16 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0x1b); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 070) & 0xff)); + expected.push_back(static_cast((i >> 060) & 0xff)); + expected.push_back(static_cast((i >> 050) & 0xff)); + expected.push_back(static_cast((i >> 040) & 0xff)); + expected.push_back(static_cast((i >> 030) & 0xff)); + expected.push_back(static_cast((i >> 020) & 0xff)); + expected.push_back(static_cast((i >> 010) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_cbor(j); @@ -571,14 +572,14 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x1b); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + uint64_t restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -589,7 +590,7 @@ TEST_CASE("CBOR") SECTION("-32768..-129 (int 16)") { - for (int16_t i = -32768; i <= static_cast(-129); ++i) + for (std::int16_t i = -32768; i <= static_cast(-129); ++i) { CAPTURE(i) @@ -600,10 +601,10 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xd1); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_msgpack(j); @@ -612,7 +613,7 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0xd1); - auto restored = static_cast((result[1] << 8) + result[2]); + auto restored = static_cast((result[1] << 8) + result[2]); CHECK(restored == i); // roundtrip @@ -625,7 +626,7 @@ TEST_CASE("CBOR") { SECTION("0..23 (Integer)") { - for (size_t i = 0; i <= 23; ++i) + for (std::size_t i = 0; i <= 23; ++i) { CAPTURE(i) @@ -636,8 +637,8 @@ TEST_CASE("CBOR") CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(i)); + std::vector expected; + expected.push_back(static_cast(i)); // compare result + size const auto result = json::to_cbor(j); @@ -655,7 +656,7 @@ TEST_CASE("CBOR") SECTION("24..255 (one-byte uint8_t)") { - for (size_t i = 24; i <= 255; ++i) + for (std::size_t i = 24; i <= 255; ++i) { CAPTURE(i) @@ -666,9 +667,9 @@ TEST_CASE("CBOR") CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0x18); - expected.push_back(static_cast(i)); + expected.push_back(static_cast(i)); // compare result + size const auto result = json::to_cbor(j); @@ -677,7 +678,7 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x18); - auto restored = static_cast(result[1]); + auto restored = static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -688,7 +689,7 @@ TEST_CASE("CBOR") SECTION("256..65535 (two-byte uint16_t)") { - for (size_t i = 256; i <= 65535; ++i) + for (std::size_t i = 256; i <= 65535; ++i) { CAPTURE(i) @@ -699,10 +700,10 @@ TEST_CASE("CBOR") CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0x19); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_cbor(j); @@ -711,7 +712,7 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x19); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == i); // roundtrip @@ -722,7 +723,7 @@ TEST_CASE("CBOR") SECTION("65536..4294967295 (four-byte uint32_t)") { - for (uint32_t i : + for (std::uint32_t i : { 65536u, 77777u, 1048576u }) @@ -736,12 +737,12 @@ TEST_CASE("CBOR") CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0x1a); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 24) & 0xff)); + expected.push_back(static_cast((i >> 16) & 0xff)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_cbor(j); @@ -750,10 +751,10 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x1a); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + uint32_t restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == i); // roundtrip @@ -764,7 +765,7 @@ TEST_CASE("CBOR") SECTION("4294967296..4611686018427387903 (eight-byte uint64_t)") { - for (uint64_t i : + for (std::uint64_t i : { 4294967296ul, 4611686018427387903ul }) @@ -778,16 +779,16 @@ TEST_CASE("CBOR") CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0x1b); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 070) & 0xff)); + expected.push_back(static_cast((i >> 060) & 0xff)); + expected.push_back(static_cast((i >> 050) & 0xff)); + expected.push_back(static_cast((i >> 040) & 0xff)); + expected.push_back(static_cast((i >> 030) & 0xff)); + expected.push_back(static_cast((i >> 020) & 0xff)); + expected.push_back(static_cast((i >> 010) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_cbor(j); @@ -796,14 +797,14 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x1b); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + uint64_t restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -819,7 +820,7 @@ TEST_CASE("CBOR") { double v = 3.1415925; json j = v; - std::vector expected = + std::vector expected = { 0xfb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc }; @@ -843,7 +844,7 @@ TEST_CASE("CBOR") // its double-precision float binary value is // {0xfb, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // but to save memory, we can store it as single-precision float. - std::vector expected = {0xfa, 0x3f, 0x00, 0x00, 0x00}; + std::vector expected = {0xfa, 0x3f, 0x00, 0x00, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -856,7 +857,7 @@ TEST_CASE("CBOR") json j = v; // its double-precision binary value is: // {0xfb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - std::vector expected = {0xfa, 0x00, 0x00, 0x00, 0x00}; + std::vector expected = {0xfa, 0x00, 0x00, 0x00, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -869,7 +870,7 @@ TEST_CASE("CBOR") json j = v; // its double-precision binary value is: // {0xfb, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - std::vector expected = {0xfa, 0x80, 0x00, 0x00, 0x00}; + std::vector expected = {0xfa, 0x80, 0x00, 0x00, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -882,7 +883,7 @@ TEST_CASE("CBOR") json j = v; // its double-precision binary value is: // {0xfb, 0x40, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - std::vector expected = {0xfa, 0x42, 0xc8, 0x00, 0x00}; + std::vector expected = {0xfa, 0x42, 0xc8, 0x00, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -895,7 +896,7 @@ TEST_CASE("CBOR") json j = v; // its double-precision binary value is: // {0xfb, 0x40, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - std::vector expected = {0xfa, 0x43, 0x48, 0x00, 0x00}; + std::vector expected = {0xfa, 0x43, 0x48, 0x00, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -906,7 +907,7 @@ TEST_CASE("CBOR") { float v = (std::numeric_limits::max)(); json j = v; - std::vector expected = + std::vector expected = { 0xfa, 0x7f, 0x7f, 0xff, 0xff }; @@ -920,7 +921,7 @@ TEST_CASE("CBOR") { auto v = static_cast(std::numeric_limits::lowest()); json j = v; - std::vector expected = + std::vector expected = { 0xfa, 0xff, 0x7f, 0xff, 0xff }; @@ -934,7 +935,7 @@ TEST_CASE("CBOR") { double v = static_cast((std::numeric_limits::max)()) + 0.1e+34; json j = v; - std::vector expected = + std::vector expected = { 0xfb, 0x47, 0xf0, 0x00, 0x03, 0x04, 0xdc, 0x64, 0x49 }; @@ -949,7 +950,7 @@ TEST_CASE("CBOR") { double v = static_cast(std::numeric_limits::lowest()) - 1.0; json j = v; - std::vector expected = + std::vector expected = { 0xfa, 0xff, 0x7f, 0xff, 0xff }; @@ -970,14 +971,14 @@ TEST_CASE("CBOR") SECTION("no byte follows") { json _; - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xf9})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK(json::from_cbor(std::vector({0xf9}), true, false).is_discarded()); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xf9})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK(json::from_cbor(std::vector({0xf9}), true, false).is_discarded()); } SECTION("only one byte follows") { json _; - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xf9, 0x7c})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK(json::from_cbor(std::vector({0xf9, 0x7c}), true, false).is_discarded()); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xf9, 0x7c})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK(json::from_cbor(std::vector({0xf9, 0x7c}), true, false).is_discarded()); } } @@ -985,21 +986,21 @@ TEST_CASE("CBOR") { SECTION("0 (0 00000 0000000000)") { - json j = json::from_cbor(std::vector({0xf9, 0x00, 0x00})); + json j = json::from_cbor(std::vector({0xf9, 0x00, 0x00})); json::number_float_t d{j}; CHECK(d == 0.0); } SECTION("-0 (1 00000 0000000000)") { - json j = json::from_cbor(std::vector({0xf9, 0x80, 0x00})); + json j = json::from_cbor(std::vector({0xf9, 0x80, 0x00})); json::number_float_t d{j}; CHECK(d == -0.0); } SECTION("2**-24 (0 00000 0000000001)") { - json j = json::from_cbor(std::vector({0xf9, 0x00, 0x01})); + json j = json::from_cbor(std::vector({0xf9, 0x00, 0x01})); json::number_float_t d{j}; CHECK(d == std::pow(2.0, -24.0)); } @@ -1009,7 +1010,7 @@ TEST_CASE("CBOR") { SECTION("infinity (0 11111 0000000000)") { - json j = json::from_cbor(std::vector({0xf9, 0x7c, 0x00})); + json j = json::from_cbor(std::vector({0xf9, 0x7c, 0x00})); json::number_float_t d{j}; CHECK(d == std::numeric_limits::infinity()); CHECK(j.dump() == "null"); @@ -1017,7 +1018,7 @@ TEST_CASE("CBOR") SECTION("-infinity (1 11111 0000000000)") { - json j = json::from_cbor(std::vector({0xf9, 0xfc, 0x00})); + json j = json::from_cbor(std::vector({0xf9, 0xfc, 0x00})); json::number_float_t d{j}; CHECK(d == -std::numeric_limits::infinity()); CHECK(j.dump() == "null"); @@ -1028,21 +1029,21 @@ TEST_CASE("CBOR") { SECTION("1 (0 01111 0000000000)") { - json j = json::from_cbor(std::vector({0xf9, 0x3c, 0x00})); + json j = json::from_cbor(std::vector({0xf9, 0x3c, 0x00})); json::number_float_t d{j}; CHECK(d == 1); } SECTION("-2 (1 10000 0000000000)") { - json j = json::from_cbor(std::vector({0xf9, 0xc0, 0x00})); + json j = json::from_cbor(std::vector({0xf9, 0xc0, 0x00})); json::number_float_t d{j}; CHECK(d == -2); } SECTION("65504 (0 11110 1111111111)") { - json j = json::from_cbor(std::vector({0xf9, 0x7b, 0xff})); + json j = json::from_cbor(std::vector({0xf9, 0x7b, 0xff})); json::number_float_t d{j}; CHECK(d == 65504); } @@ -1050,7 +1051,7 @@ TEST_CASE("CBOR") SECTION("infinity") { - json j = json::from_cbor(std::vector({0xf9, 0x7c, 0x00})); + json j = json::from_cbor(std::vector({0xf9, 0x7c, 0x00})); json::number_float_t d{j}; CHECK(!std::isfinite(d)); CHECK(j.dump() == "null"); @@ -1058,7 +1059,7 @@ TEST_CASE("CBOR") SECTION("NaN") { - json j = json::from_cbor(std::vector({0xf9, 0x7e, 0x00})); + json j = json::from_cbor(std::vector({0xf9, 0x7e, 0x00})); json::number_float_t d{j}; CHECK(std::isnan(d)); CHECK(j.dump() == "null"); @@ -1070,7 +1071,7 @@ TEST_CASE("CBOR") { SECTION("N = 0..23") { - for (size_t N = 0; N <= 0x17; ++N) + for (std::size_t N = 0; N <= 0x17; ++N) { CAPTURE(N) @@ -1079,9 +1080,9 @@ TEST_CASE("CBOR") json j = s; // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x60 + N)); - for (size_t i = 0; i < N; ++i) + std::vector expected; + expected.push_back(static_cast(0x60 + N)); + for (std::size_t i = 0; i < N; ++i) { expected.push_back('x'); } @@ -1104,7 +1105,7 @@ TEST_CASE("CBOR") SECTION("N = 24..255") { - for (size_t N = 24; N <= 255; ++N) + for (std::size_t N = 24; N <= 255; ++N) { CAPTURE(N) @@ -1113,10 +1114,10 @@ TEST_CASE("CBOR") json j = s; // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0x78); - expected.push_back(static_cast(N)); - for (size_t i = 0; i < N; ++i) + expected.push_back(static_cast(N)); + for (std::size_t i = 0; i < N; ++i) { expected.push_back('x'); } @@ -1136,7 +1137,7 @@ TEST_CASE("CBOR") SECTION("N = 256..65535") { - for (size_t N : + for (std::size_t N : { 256u, 999u, 1025u, 3333u, 2048u, 65535u }) @@ -1148,10 +1149,10 @@ TEST_CASE("CBOR") json j = s; // create expected byte vector (hack: create string first) - std::vector expected(N, 'x'); + std::vector expected(N, 'x'); // reverse order of commands, because we insert at begin() - expected.insert(expected.begin(), static_cast(N & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); + expected.insert(expected.begin(), static_cast(N & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); expected.insert(expected.begin(), 0x79); // compare result + size @@ -1169,7 +1170,7 @@ TEST_CASE("CBOR") SECTION("N = 65536..4294967295") { - for (size_t N : + for (std::size_t N : { 65536u, 77777u, 1048576u }) @@ -1181,12 +1182,12 @@ TEST_CASE("CBOR") json j = s; // create expected byte vector (hack: create string first) - std::vector expected(N, 'x'); + std::vector expected(N, 'x'); // reverse order of commands, because we insert at begin() - expected.insert(expected.begin(), static_cast(N & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 16) & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 24) & 0xff)); + expected.insert(expected.begin(), static_cast(N & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 16) & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 24) & 0xff)); expected.insert(expected.begin(), 0x7a); // compare result + size @@ -1208,7 +1209,7 @@ TEST_CASE("CBOR") SECTION("empty") { json j = json::array(); - std::vector expected = {0x80}; + std::vector expected = {0x80}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1220,7 +1221,7 @@ TEST_CASE("CBOR") SECTION("[null]") { json j = {nullptr}; - std::vector expected = {0x81, 0xf6}; + std::vector expected = {0x81, 0xf6}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1232,7 +1233,7 @@ TEST_CASE("CBOR") SECTION("[1,2,3,4,5]") { json j = json::parse("[1,2,3,4,5]"); - std::vector expected = {0x85, 0x01, 0x02, 0x03, 0x04, 0x05}; + std::vector expected = {0x85, 0x01, 0x02, 0x03, 0x04, 0x05}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1244,7 +1245,7 @@ TEST_CASE("CBOR") SECTION("[[[[]]]]") { json j = json::parse("[[[[]]]]"); - std::vector expected = {0x81, 0x81, 0x81, 0x80}; + std::vector expected = {0x81, 0x81, 0x81, 0x80}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1256,7 +1257,7 @@ TEST_CASE("CBOR") SECTION("array with uint16_t elements") { json j(257, nullptr); - std::vector expected(j.size() + 3, 0xf6); // all null + std::vector expected(j.size() + 3, 0xf6); // all null expected[0] = 0x99; // array 16 bit expected[1] = 0x01; // size (0x0101), byte 0 expected[2] = 0x01; // size (0x0101), byte 1 @@ -1271,7 +1272,7 @@ TEST_CASE("CBOR") SECTION("array with uint32_t elements") { json j(65793, nullptr); - std::vector expected(j.size() + 5, 0xf6); // all null + std::vector expected(j.size() + 5, 0xf6); // all null expected[0] = 0x9a; // array 32 bit expected[1] = 0x00; // size (0x00010101), byte 0 expected[2] = 0x01; // size (0x00010101), byte 1 @@ -1291,7 +1292,7 @@ TEST_CASE("CBOR") SECTION("empty") { json j = json::object(); - std::vector expected = {0xa0}; + std::vector expected = {0xa0}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1303,7 +1304,7 @@ TEST_CASE("CBOR") SECTION("{\"\":null}") { json j = {{"", nullptr}}; - std::vector expected = {0xa1, 0x60, 0xf6}; + std::vector expected = {0xa1, 0x60, 0xf6}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1315,7 +1316,7 @@ TEST_CASE("CBOR") SECTION("{\"a\": {\"b\": {\"c\": {}}}}") { json j = json::parse(R"({"a": {"b": {"c": {}}}})"); - std::vector expected = + std::vector expected = { 0xa1, 0x61, 0x61, 0xa1, 0x61, 0x62, 0xa1, 0x61, 0x63, 0xa0 }; @@ -1419,18 +1420,18 @@ TEST_CASE("CBOR") { SECTION("N = 0..23") { - for (size_t N = 0; N <= 0x17; ++N) + for (std::size_t N = 0; N <= 0x17; ++N) { CAPTURE(N) // create JSON value with byte array containing of N * 'x' - const auto s = std::vector(N, 'x'); + const auto s = std::vector(N, 'x'); json j = json::binary(s); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x40 + N)); - for (size_t i = 0; i < N; ++i) + std::vector expected; + expected.push_back(static_cast(0x40 + N)); + for (std::size_t i = 0; i < N; ++i) { expected.push_back(0x78); } @@ -1453,19 +1454,19 @@ TEST_CASE("CBOR") SECTION("N = 24..255") { - for (size_t N = 24; N <= 255; ++N) + for (std::size_t N = 24; N <= 255; ++N) { CAPTURE(N) // create JSON value with string containing of N * 'x' - const auto s = std::vector(N, 'x'); + const auto s = std::vector(N, 'x'); json j = json::binary(s); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0x58); - expected.push_back(static_cast(N)); - for (size_t i = 0; i < N; ++i) + expected.push_back(static_cast(N)); + for (std::size_t i = 0; i < N; ++i) { expected.push_back('x'); } @@ -1485,7 +1486,7 @@ TEST_CASE("CBOR") SECTION("N = 256..65535") { - for (size_t N : + for (std::size_t N : { 256u, 999u, 1025u, 3333u, 2048u, 65535u }) @@ -1493,14 +1494,14 @@ TEST_CASE("CBOR") CAPTURE(N) // create JSON value with string containing of N * 'x' - const auto s = std::vector(N, 'x'); + const auto s = std::vector(N, 'x'); json j = json::binary(s); // create expected byte vector (hack: create string first) - std::vector expected(N, 'x'); + std::vector expected(N, 'x'); // reverse order of commands, because we insert at begin() - expected.insert(expected.begin(), static_cast(N & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); + expected.insert(expected.begin(), static_cast(N & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); expected.insert(expected.begin(), 0x59); // compare result + size @@ -1518,7 +1519,7 @@ TEST_CASE("CBOR") SECTION("N = 65536..4294967295") { - for (size_t N : + for (std::size_t N : { 65536u, 77777u, 1048576u }) @@ -1526,16 +1527,16 @@ TEST_CASE("CBOR") CAPTURE(N) // create JSON value with string containing of N * 'x' - const auto s = std::vector(N, 'x'); + const auto s = std::vector(N, 'x'); json j = json::binary(s); // create expected byte vector (hack: create string first) - std::vector expected(N, 'x'); + std::vector expected(N, 'x'); // reverse order of commands, because we insert at begin() - expected.insert(expected.begin(), static_cast(N & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 16) & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 24) & 0xff)); + expected.insert(expected.begin(), static_cast(N & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 16) & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 24) & 0xff)); expected.insert(expected.begin(), 0x5a); // compare result + size @@ -1606,36 +1607,36 @@ TEST_CASE("CBOR") { SECTION("0x5b (byte array)") { - std::vector given = {0x5b, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x61 - }; + std::vector given = {0x5b, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x61 + }; json j = json::from_cbor(given); - CHECK(j == json::binary(std::vector {'a'})); + CHECK(j == json::binary(std::vector {'a'})); } SECTION("0x7b (string)") { - std::vector given = {0x7b, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x61 - }; + std::vector given = {0x7b, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x61 + }; json j = json::from_cbor(given); CHECK(j == "a"); } SECTION("0x9b (array)") { - std::vector given = {0x9b, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0xf4 - }; + std::vector given = {0x9b, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0xf4 + }; json j = json::from_cbor(given); CHECK(j == json::parse("[false]")); } SECTION("0xbb (map)") { - std::vector given = {0xbb, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x60, 0xf4 - }; + std::vector given = {0xbb, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x60, 0xf4 + }; json j = json::from_cbor(given); CHECK(j == json::parse("{\"\": false}")); } @@ -1646,68 +1647,68 @@ TEST_CASE("CBOR") SECTION("empty byte vector") { json _; - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector()), "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); - CHECK(json::from_cbor(std::vector(), true, false).is_discarded()); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector()), "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); + CHECK(json::from_cbor(std::vector(), true, false).is_discarded()); } SECTION("too short byte vector") { json _; - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x18})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x19})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x19, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1a})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1a, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1a, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1a, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x62})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x62, 0x60})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x7F})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x7F, 0x60})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x82, 0x01})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x9F, 0x01})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xBF, 0x61, 0x61, 0xF5})), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xA1, 0x61, 0X61})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xBF, 0x61, 0X61})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x5F})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR binary: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x5F, 0x00})), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR binary: expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x00", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x41})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR binary: unexpected end of input", json::parse_error&); - - CHECK(json::from_cbor(std::vector({0x18}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x19}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x19, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1a}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1a, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1a, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1a, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1b}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1b, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x62}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x62, 0x60}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x7F}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x7F, 0x60}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x82, 0x01}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x9F, 0x01}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0xBF, 0x61, 0x61, 0xF5}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0xA1, 0x61, 0x61}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0xBF, 0x61, 0x61}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x5F}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x5F, 0x00}), true, false).is_discarded()); - CHECK(json::from_cbor(std::vector({0x41}), true, false).is_discarded()); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x18})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x19})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x19, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1a})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1a, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1a, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1a, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x62})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x62, 0x60})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x7F})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x7F, 0x60})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x82, 0x01})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x9F, 0x01})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xBF, 0x61, 0x61, 0xF5})), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xA1, 0x61, 0X61})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xBF, 0x61, 0X61})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x5F})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR binary: unexpected end of input", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x5F, 0x00})), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR binary: expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x00", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x41})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR binary: unexpected end of input", json::parse_error&); + + CHECK(json::from_cbor(std::vector({0x18}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x19}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x19, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1a}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1a, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1a, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1a, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1b}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1b, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x62}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x62, 0x60}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x7F}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x7F, 0x60}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x82, 0x01}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x9F, 0x01}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0xBF, 0x61, 0x61, 0xF5}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0xA1, 0x61, 0x61}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0xBF, 0x61, 0x61}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x5F}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x5F, 0x00}), true, false).is_discarded()); + CHECK(json::from_cbor(std::vector({0x41}), true, false).is_discarded()); } SECTION("unsupported bytes") @@ -1715,11 +1716,11 @@ TEST_CASE("CBOR") SECTION("concrete examples") { json _; - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1c})), "[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing CBOR value: invalid byte: 0x1C", json::parse_error&); - CHECK(json::from_cbor(std::vector({0x1c}), true, false).is_discarded()); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0x1c})), "[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing CBOR value: invalid byte: 0x1C", json::parse_error&); + CHECK(json::from_cbor(std::vector({0x1c}), true, false).is_discarded()); - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xf8})), "[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing CBOR value: invalid byte: 0xF8", json::parse_error&); - CHECK(json::from_cbor(std::vector({0xf8}), true, false).is_discarded()); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xf8})), "[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing CBOR value: invalid byte: 0xF8", json::parse_error&); + CHECK(json::from_cbor(std::vector({0xf8}), true, false).is_discarded()); } SECTION("all unsupported bytes") @@ -1763,8 +1764,8 @@ TEST_CASE("CBOR") }) { json _; - CHECK_THROWS_AS(_ = json::from_cbor(std::vector({static_cast(byte)})), json::parse_error&); - CHECK(json::from_cbor(std::vector({static_cast(byte)}), true, false).is_discarded()); + CHECK_THROWS_AS(_ = json::from_cbor(std::vector({static_cast(byte)})), json::parse_error&); + CHECK(json::from_cbor(std::vector({static_cast(byte)}), true, false).is_discarded()); } } } @@ -1772,13 +1773,13 @@ TEST_CASE("CBOR") SECTION("invalid string in map") { json _; - CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xa1, 0xff, 0x01})), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xFF", json::parse_error&); - CHECK(json::from_cbor(std::vector({0xa1, 0xff, 0x01}), true, false).is_discarded()); + CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector({0xa1, 0xff, 0x01})), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xFF", json::parse_error&); + CHECK(json::from_cbor(std::vector({0xa1, 0xff, 0x01}), true, false).is_discarded()); } SECTION("strict mode") { - std::vector vec = {0xf6, 0xf6}; + std::vector vec = {0xf6, 0xf6}; SECTION("non-strict mode") { const auto result = json::from_cbor(vec, false); @@ -1799,21 +1800,21 @@ TEST_CASE("CBOR") { SECTION("start_array(len)") { - std::vector v = {0x83, 0x01, 0x02, 0x03}; + std::vector v = {0x83, 0x01, 0x02, 0x03}; SaxCountdown scp(0); CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor)); } SECTION("start_object(len)") { - std::vector v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4}; + std::vector v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4}; SaxCountdown scp(0); CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor)); } SECTION("key()") { - std::vector v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4}; + std::vector v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4}; SaxCountdown scp(1); CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor)); } @@ -1910,7 +1911,7 @@ TEST_CASE("CBOR regressions") try { // step 2: round trip - std::vector vec2 = json::to_cbor(j1); + std::vector vec2 = json::to_cbor(j1); // parse serialization json j2 = json::from_cbor(vec2); @@ -2103,7 +2104,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) CAPTURE(filename) { - INFO_WITH_TEMP(filename + ": std::vector"); + INFO_WITH_TEMP(filename + ": std::vector"); // parse JSON file std::ifstream f_json(filename); json j1 = json::parse(f_json); @@ -2159,8 +2160,8 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) if (exclude_packed.count(filename) == 0u) { { - INFO_WITH_TEMP(filename + ": output adapters: std::vector"); - std::vector vec; + INFO_WITH_TEMP(filename + ": output adapters: std::vector"); + std::vector vec; json::to_cbor(j1, vec); CHECK(vec == packed); } @@ -2174,7 +2175,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) TEST_CASE("all CBOR first bytes") { // these bytes will fail immediately with exception parse_error.112 - std::set unsupported = + std::set unsupported = { //// types not supported by this library @@ -2219,11 +2220,11 @@ TEST_CASE("all CBOR first bytes") for (auto i = 0; i < 256; ++i) { - const auto byte = static_cast(i); + const auto byte = static_cast(i); try { - auto res = json::from_cbor(std::vector(1, byte)); + auto res = json::from_cbor(std::vector(1, byte)); } catch (const json::parse_error& e) { @@ -2247,144 +2248,144 @@ TEST_CASE("examples from RFC 7049 Appendix A") { SECTION("numbers") { - CHECK(json::to_cbor(json::parse("0")) == std::vector({0x00})); - CHECK(json::parse("0") == json::from_cbor(std::vector({0x00}))); + CHECK(json::to_cbor(json::parse("0")) == std::vector({0x00})); + CHECK(json::parse("0") == json::from_cbor(std::vector({0x00}))); - CHECK(json::to_cbor(json::parse("1")) == std::vector({0x01})); - CHECK(json::parse("1") == json::from_cbor(std::vector({0x01}))); + CHECK(json::to_cbor(json::parse("1")) == std::vector({0x01})); + CHECK(json::parse("1") == json::from_cbor(std::vector({0x01}))); - CHECK(json::to_cbor(json::parse("10")) == std::vector({0x0a})); - CHECK(json::parse("10") == json::from_cbor(std::vector({0x0a}))); + CHECK(json::to_cbor(json::parse("10")) == std::vector({0x0a})); + CHECK(json::parse("10") == json::from_cbor(std::vector({0x0a}))); - CHECK(json::to_cbor(json::parse("23")) == std::vector({0x17})); - CHECK(json::parse("23") == json::from_cbor(std::vector({0x17}))); + CHECK(json::to_cbor(json::parse("23")) == std::vector({0x17})); + CHECK(json::parse("23") == json::from_cbor(std::vector({0x17}))); - CHECK(json::to_cbor(json::parse("24")) == std::vector({0x18, 0x18})); - CHECK(json::parse("24") == json::from_cbor(std::vector({0x18, 0x18}))); + CHECK(json::to_cbor(json::parse("24")) == std::vector({0x18, 0x18})); + CHECK(json::parse("24") == json::from_cbor(std::vector({0x18, 0x18}))); - CHECK(json::to_cbor(json::parse("25")) == std::vector({0x18, 0x19})); - CHECK(json::parse("25") == json::from_cbor(std::vector({0x18, 0x19}))); + CHECK(json::to_cbor(json::parse("25")) == std::vector({0x18, 0x19})); + CHECK(json::parse("25") == json::from_cbor(std::vector({0x18, 0x19}))); - CHECK(json::to_cbor(json::parse("100")) == std::vector({0x18, 0x64})); - CHECK(json::parse("100") == json::from_cbor(std::vector({0x18, 0x64}))); + CHECK(json::to_cbor(json::parse("100")) == std::vector({0x18, 0x64})); + CHECK(json::parse("100") == json::from_cbor(std::vector({0x18, 0x64}))); - CHECK(json::to_cbor(json::parse("1000")) == std::vector({0x19, 0x03, 0xe8})); - CHECK(json::parse("1000") == json::from_cbor(std::vector({0x19, 0x03, 0xe8}))); + CHECK(json::to_cbor(json::parse("1000")) == std::vector({0x19, 0x03, 0xe8})); + CHECK(json::parse("1000") == json::from_cbor(std::vector({0x19, 0x03, 0xe8}))); - CHECK(json::to_cbor(json::parse("1000000")) == std::vector({0x1a, 0x00, 0x0f, 0x42, 0x40})); - CHECK(json::parse("1000000") == json::from_cbor(std::vector({0x1a, 0x00, 0x0f, 0x42, 0x40}))); + CHECK(json::to_cbor(json::parse("1000000")) == std::vector({0x1a, 0x00, 0x0f, 0x42, 0x40})); + CHECK(json::parse("1000000") == json::from_cbor(std::vector({0x1a, 0x00, 0x0f, 0x42, 0x40}))); - CHECK(json::to_cbor(json::parse("1000000000000")) == std::vector({0x1b, 0x00, 0x00, 0x00, 0xe8, 0xd4, 0xa5, 0x10, 0x00})); - CHECK(json::parse("1000000000000") == json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0xe8, 0xd4, 0xa5, 0x10, 0x00}))); + CHECK(json::to_cbor(json::parse("1000000000000")) == std::vector({0x1b, 0x00, 0x00, 0x00, 0xe8, 0xd4, 0xa5, 0x10, 0x00})); + CHECK(json::parse("1000000000000") == json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0xe8, 0xd4, 0xa5, 0x10, 0x00}))); - CHECK(json::to_cbor(json::parse("18446744073709551615")) == std::vector({0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})); - CHECK(json::parse("18446744073709551615") == json::from_cbor(std::vector({0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}))); + CHECK(json::to_cbor(json::parse("18446744073709551615")) == std::vector({0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})); + CHECK(json::parse("18446744073709551615") == json::from_cbor(std::vector({0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}))); // positive bignum is not supported - //CHECK(json::to_cbor(json::parse("18446744073709551616")) == std::vector({0xc2, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})); - //CHECK(json::parse("18446744073709551616") == json::from_cbor(std::vector({0xc2, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}))); + //CHECK(json::to_cbor(json::parse("18446744073709551616")) == std::vector({0xc2, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})); + //CHECK(json::parse("18446744073709551616") == json::from_cbor(std::vector({0xc2, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}))); - //CHECK(json::to_cbor(json::parse("-18446744073709551616")) == std::vector({0x3b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})); - //CHECK(json::parse("-18446744073709551616") == json::from_cbor(std::vector({0x3b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}))); + //CHECK(json::to_cbor(json::parse("-18446744073709551616")) == std::vector({0x3b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})); + //CHECK(json::parse("-18446744073709551616") == json::from_cbor(std::vector({0x3b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}))); // negative bignum is not supported - //CHECK(json::to_cbor(json::parse("-18446744073709551617")) == std::vector({0xc3, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})); - //CHECK(json::parse("-18446744073709551617") == json::from_cbor(std::vector({0xc3, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}))); + //CHECK(json::to_cbor(json::parse("-18446744073709551617")) == std::vector({0xc3, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})); + //CHECK(json::parse("-18446744073709551617") == json::from_cbor(std::vector({0xc3, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}))); - CHECK(json::to_cbor(json::parse("-1")) == std::vector({0x20})); - CHECK(json::parse("-1") == json::from_cbor(std::vector({0x20}))); + CHECK(json::to_cbor(json::parse("-1")) == std::vector({0x20})); + CHECK(json::parse("-1") == json::from_cbor(std::vector({0x20}))); - CHECK(json::to_cbor(json::parse("-10")) == std::vector({0x29})); - CHECK(json::parse("-10") == json::from_cbor(std::vector({0x29}))); + CHECK(json::to_cbor(json::parse("-10")) == std::vector({0x29})); + CHECK(json::parse("-10") == json::from_cbor(std::vector({0x29}))); - CHECK(json::to_cbor(json::parse("-100")) == std::vector({0x38, 0x63})); - CHECK(json::parse("-100") == json::from_cbor(std::vector({0x38, 0x63}))); + CHECK(json::to_cbor(json::parse("-100")) == std::vector({0x38, 0x63})); + CHECK(json::parse("-100") == json::from_cbor(std::vector({0x38, 0x63}))); - CHECK(json::to_cbor(json::parse("-1000")) == std::vector({0x39, 0x03, 0xe7})); - CHECK(json::parse("-1000") == json::from_cbor(std::vector({0x39, 0x03, 0xe7}))); + CHECK(json::to_cbor(json::parse("-1000")) == std::vector({0x39, 0x03, 0xe7})); + CHECK(json::parse("-1000") == json::from_cbor(std::vector({0x39, 0x03, 0xe7}))); // half-precision float - //CHECK(json::to_cbor(json::parse("0.0")) == std::vector({0xf9, 0x00, 0x00})); - CHECK(json::parse("0.0") == json::from_cbor(std::vector({0xf9, 0x00, 0x00}))); + //CHECK(json::to_cbor(json::parse("0.0")) == std::vector({0xf9, 0x00, 0x00})); + CHECK(json::parse("0.0") == json::from_cbor(std::vector({0xf9, 0x00, 0x00}))); // half-precision float - //CHECK(json::to_cbor(json::parse("-0.0")) == std::vector({0xf9, 0x80, 0x00})); - CHECK(json::parse("-0.0") == json::from_cbor(std::vector({0xf9, 0x80, 0x00}))); + //CHECK(json::to_cbor(json::parse("-0.0")) == std::vector({0xf9, 0x80, 0x00})); + CHECK(json::parse("-0.0") == json::from_cbor(std::vector({0xf9, 0x80, 0x00}))); // half-precision float - //CHECK(json::to_cbor(json::parse("1.0")) == std::vector({0xf9, 0x3c, 0x00})); - CHECK(json::parse("1.0") == json::from_cbor(std::vector({0xf9, 0x3c, 0x00}))); + //CHECK(json::to_cbor(json::parse("1.0")) == std::vector({0xf9, 0x3c, 0x00})); + CHECK(json::parse("1.0") == json::from_cbor(std::vector({0xf9, 0x3c, 0x00}))); - CHECK(json::to_cbor(json::parse("1.1")) == std::vector({0xfb, 0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a})); - CHECK(json::parse("1.1") == json::from_cbor(std::vector({0xfb, 0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a}))); + CHECK(json::to_cbor(json::parse("1.1")) == std::vector({0xfb, 0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a})); + CHECK(json::parse("1.1") == json::from_cbor(std::vector({0xfb, 0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a}))); // half-precision float - //CHECK(json::to_cbor(json::parse("1.5")) == std::vector({0xf9, 0x3e, 0x00})); - CHECK(json::parse("1.5") == json::from_cbor(std::vector({0xf9, 0x3e, 0x00}))); + //CHECK(json::to_cbor(json::parse("1.5")) == std::vector({0xf9, 0x3e, 0x00})); + CHECK(json::parse("1.5") == json::from_cbor(std::vector({0xf9, 0x3e, 0x00}))); // half-precision float - //CHECK(json::to_cbor(json::parse("65504.0")) == std::vector({0xf9, 0x7b, 0xff})); - CHECK(json::parse("65504.0") == json::from_cbor(std::vector({0xf9, 0x7b, 0xff}))); + //CHECK(json::to_cbor(json::parse("65504.0")) == std::vector({0xf9, 0x7b, 0xff})); + CHECK(json::parse("65504.0") == json::from_cbor(std::vector({0xf9, 0x7b, 0xff}))); - //CHECK(json::to_cbor(json::parse("100000.0")) == std::vector({0xfa, 0x47, 0xc3, 0x50, 0x00})); - CHECK(json::parse("100000.0") == json::from_cbor(std::vector({0xfa, 0x47, 0xc3, 0x50, 0x00}))); + //CHECK(json::to_cbor(json::parse("100000.0")) == std::vector({0xfa, 0x47, 0xc3, 0x50, 0x00})); + CHECK(json::parse("100000.0") == json::from_cbor(std::vector({0xfa, 0x47, 0xc3, 0x50, 0x00}))); - //CHECK(json::to_cbor(json::parse("3.4028234663852886e+38")) == std::vector({0xfa, 0x7f, 0x7f, 0xff, 0xff})); - CHECK(json::parse("3.4028234663852886e+38") == json::from_cbor(std::vector({0xfa, 0x7f, 0x7f, 0xff, 0xff}))); + //CHECK(json::to_cbor(json::parse("3.4028234663852886e+38")) == std::vector({0xfa, 0x7f, 0x7f, 0xff, 0xff})); + CHECK(json::parse("3.4028234663852886e+38") == json::from_cbor(std::vector({0xfa, 0x7f, 0x7f, 0xff, 0xff}))); - CHECK(json::to_cbor(json::parse("1.0e+300")) == std::vector({0xfb, 0x7e, 0x37, 0xe4, 0x3c, 0x88, 0x00, 0x75, 0x9c})); - CHECK(json::parse("1.0e+300") == json::from_cbor(std::vector({0xfb, 0x7e, 0x37, 0xe4, 0x3c, 0x88, 0x00, 0x75, 0x9c}))); + CHECK(json::to_cbor(json::parse("1.0e+300")) == std::vector({0xfb, 0x7e, 0x37, 0xe4, 0x3c, 0x88, 0x00, 0x75, 0x9c})); + CHECK(json::parse("1.0e+300") == json::from_cbor(std::vector({0xfb, 0x7e, 0x37, 0xe4, 0x3c, 0x88, 0x00, 0x75, 0x9c}))); // half-precision float - //CHECK(json::to_cbor(json::parse("5.960464477539063e-8")) == std::vector({0xf9, 0x00, 0x01})); - CHECK(json::parse("-4.0") == json::from_cbor(std::vector({0xf9, 0xc4, 0x00}))); + //CHECK(json::to_cbor(json::parse("5.960464477539063e-8")) == std::vector({0xf9, 0x00, 0x01})); + CHECK(json::parse("-4.0") == json::from_cbor(std::vector({0xf9, 0xc4, 0x00}))); // half-precision float - //CHECK(json::to_cbor(json::parse("0.00006103515625")) == std::vector({0xf9, 0x04, 0x00})); - CHECK(json::parse("-4.0") == json::from_cbor(std::vector({0xf9, 0xc4, 0x00}))); + //CHECK(json::to_cbor(json::parse("0.00006103515625")) == std::vector({0xf9, 0x04, 0x00})); + CHECK(json::parse("-4.0") == json::from_cbor(std::vector({0xf9, 0xc4, 0x00}))); // half-precision float - //CHECK(json::to_cbor(json::parse("-4.0")) == std::vector({0xf9, 0xc4, 0x00})); - CHECK(json::parse("-4.0") == json::from_cbor(std::vector({0xf9, 0xc4, 0x00}))); + //CHECK(json::to_cbor(json::parse("-4.0")) == std::vector({0xf9, 0xc4, 0x00})); + CHECK(json::parse("-4.0") == json::from_cbor(std::vector({0xf9, 0xc4, 0x00}))); - CHECK(json::to_cbor(json::parse("-4.1")) == std::vector({0xfb, 0xc0, 0x10, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66})); - CHECK(json::parse("-4.1") == json::from_cbor(std::vector({0xfb, 0xc0, 0x10, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66}))); + CHECK(json::to_cbor(json::parse("-4.1")) == std::vector({0xfb, 0xc0, 0x10, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66})); + CHECK(json::parse("-4.1") == json::from_cbor(std::vector({0xfb, 0xc0, 0x10, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66}))); } SECTION("simple values") { - CHECK(json::to_cbor(json::parse("false")) == std::vector({0xf4})); - CHECK(json::parse("false") == json::from_cbor(std::vector({0xf4}))); + CHECK(json::to_cbor(json::parse("false")) == std::vector({0xf4})); + CHECK(json::parse("false") == json::from_cbor(std::vector({0xf4}))); - CHECK(json::to_cbor(json::parse("true")) == std::vector({0xf5})); - CHECK(json::parse("true") == json::from_cbor(std::vector({0xf5}))); + CHECK(json::to_cbor(json::parse("true")) == std::vector({0xf5})); + CHECK(json::parse("true") == json::from_cbor(std::vector({0xf5}))); - CHECK(json::to_cbor(json::parse("true")) == std::vector({0xf5})); - CHECK(json::parse("true") == json::from_cbor(std::vector({0xf5}))); + CHECK(json::to_cbor(json::parse("true")) == std::vector({0xf5})); + CHECK(json::parse("true") == json::from_cbor(std::vector({0xf5}))); } SECTION("strings") { - CHECK(json::to_cbor(json::parse("\"\"")) == std::vector({0x60})); - CHECK(json::parse("\"\"") == json::from_cbor(std::vector({0x60}))); + CHECK(json::to_cbor(json::parse("\"\"")) == std::vector({0x60})); + CHECK(json::parse("\"\"") == json::from_cbor(std::vector({0x60}))); - CHECK(json::to_cbor(json::parse("\"a\"")) == std::vector({0x61, 0x61})); - CHECK(json::parse("\"a\"") == json::from_cbor(std::vector({0x61, 0x61}))); + CHECK(json::to_cbor(json::parse("\"a\"")) == std::vector({0x61, 0x61})); + CHECK(json::parse("\"a\"") == json::from_cbor(std::vector({0x61, 0x61}))); - CHECK(json::to_cbor(json::parse("\"IETF\"")) == std::vector({0x64, 0x49, 0x45, 0x54, 0x46})); - CHECK(json::parse("\"IETF\"") == json::from_cbor(std::vector({0x64, 0x49, 0x45, 0x54, 0x46}))); + CHECK(json::to_cbor(json::parse("\"IETF\"")) == std::vector({0x64, 0x49, 0x45, 0x54, 0x46})); + CHECK(json::parse("\"IETF\"") == json::from_cbor(std::vector({0x64, 0x49, 0x45, 0x54, 0x46}))); - CHECK(json::to_cbor(json::parse("\"\\u00fc\"")) == std::vector({0x62, 0xc3, 0xbc})); - CHECK(json::parse("\"\\u00fc\"") == json::from_cbor(std::vector({0x62, 0xc3, 0xbc}))); + CHECK(json::to_cbor(json::parse("\"\\u00fc\"")) == std::vector({0x62, 0xc3, 0xbc})); + CHECK(json::parse("\"\\u00fc\"") == json::from_cbor(std::vector({0x62, 0xc3, 0xbc}))); - CHECK(json::to_cbor(json::parse("\"\\u6c34\"")) == std::vector({0x63, 0xe6, 0xb0, 0xb4})); - CHECK(json::parse("\"\\u6c34\"") == json::from_cbor(std::vector({0x63, 0xe6, 0xb0, 0xb4}))); + CHECK(json::to_cbor(json::parse("\"\\u6c34\"")) == std::vector({0x63, 0xe6, 0xb0, 0xb4})); + CHECK(json::parse("\"\\u6c34\"") == json::from_cbor(std::vector({0x63, 0xe6, 0xb0, 0xb4}))); - CHECK(json::to_cbor(json::parse("\"\\ud800\\udd51\"")) == std::vector({0x64, 0xf0, 0x90, 0x85, 0x91})); - CHECK(json::parse("\"\\ud800\\udd51\"") == json::from_cbor(std::vector({0x64, 0xf0, 0x90, 0x85, 0x91}))); + CHECK(json::to_cbor(json::parse("\"\\ud800\\udd51\"")) == std::vector({0x64, 0xf0, 0x90, 0x85, 0x91})); + CHECK(json::parse("\"\\ud800\\udd51\"") == json::from_cbor(std::vector({0x64, 0xf0, 0x90, 0x85, 0x91}))); // indefinite length strings - CHECK(json::parse("\"streaming\"") == json::from_cbor(std::vector({0x7f, 0x65, 0x73, 0x74, 0x72, 0x65, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x67, 0xff}))); + CHECK(json::parse("\"streaming\"") == json::from_cbor(std::vector({0x7f, 0x65, 0x73, 0x74, 0x72, 0x65, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x67, 0xff}))); } SECTION("byte arrays") @@ -2397,64 +2398,64 @@ TEST_CASE("examples from RFC 7049 Appendix A") CHECK(j == json::binary(expected)); // 0xd8 - CHECK(json::to_cbor(json::binary(std::vector {}, 0x42)) == std::vector {0xd8, 0x42, 0x40}); - CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector {}, 0x42)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); - CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector {}, 0x42)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 0x42); + CHECK(json::to_cbor(json::binary(std::vector {}, 0x42)) == std::vector {0xd8, 0x42, 0x40}); + CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector {}, 0x42)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); + CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector {}, 0x42)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 0x42); // 0xd9 - CHECK(json::to_cbor(json::binary(std::vector {}, 1000)) == std::vector {0xd9, 0x03, 0xe8, 0x40}); - CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector {}, 1000)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); - CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector {}, 1000)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 1000); + CHECK(json::to_cbor(json::binary(std::vector {}, 1000)) == std::vector {0xd9, 0x03, 0xe8, 0x40}); + CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector {}, 1000)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); + CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector {}, 1000)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 1000); // 0xda - CHECK(json::to_cbor(json::binary(std::vector {}, 394216)) == std::vector {0xda, 0x00, 0x06, 0x03, 0xe8, 0x40}); - CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector {}, 394216)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); - CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector {}, 394216)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 394216); + CHECK(json::to_cbor(json::binary(std::vector {}, 394216)) == std::vector {0xda, 0x00, 0x06, 0x03, 0xe8, 0x40}); + CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector {}, 394216)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); + CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector {}, 394216)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 394216); // 0xdb - CHECK(json::to_cbor(json::binary(std::vector {}, 8589934590)) == std::vector {0xdb, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x40}); - CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector {}, 8589934590)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); - CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector {}, 8589934590)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 8589934590); + CHECK(json::to_cbor(json::binary(std::vector {}, 8589934590)) == std::vector {0xdb, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x40}); + CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector {}, 8589934590)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype()); + CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector {}, 8589934590)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 8589934590); } SECTION("arrays") { - CHECK(json::to_cbor(json::parse("[]")) == std::vector({0x80})); - CHECK(json::parse("[]") == json::from_cbor(std::vector({0x80}))); + CHECK(json::to_cbor(json::parse("[]")) == std::vector({0x80})); + CHECK(json::parse("[]") == json::from_cbor(std::vector({0x80}))); - CHECK(json::to_cbor(json::parse("[1, 2, 3]")) == std::vector({0x83, 0x01, 0x02, 0x03})); - CHECK(json::parse("[1, 2, 3]") == json::from_cbor(std::vector({0x83, 0x01, 0x02, 0x03}))); + CHECK(json::to_cbor(json::parse("[1, 2, 3]")) == std::vector({0x83, 0x01, 0x02, 0x03})); + CHECK(json::parse("[1, 2, 3]") == json::from_cbor(std::vector({0x83, 0x01, 0x02, 0x03}))); - CHECK(json::to_cbor(json::parse("[1, [2, 3], [4, 5]]")) == std::vector({0x83, 0x01, 0x82, 0x02, 0x03, 0x82, 0x04, 0x05})); - CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector({0x83, 0x01, 0x82, 0x02, 0x03, 0x82, 0x04, 0x05}))); + CHECK(json::to_cbor(json::parse("[1, [2, 3], [4, 5]]")) == std::vector({0x83, 0x01, 0x82, 0x02, 0x03, 0x82, 0x04, 0x05})); + CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector({0x83, 0x01, 0x82, 0x02, 0x03, 0x82, 0x04, 0x05}))); - CHECK(json::to_cbor(json::parse("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]")) == std::vector({0x98, 0x19, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x18, 0x18, 0x19})); - CHECK(json::parse("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]") == json::from_cbor(std::vector({0x98, 0x19, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x18, 0x18, 0x19}))); + CHECK(json::to_cbor(json::parse("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]")) == std::vector({0x98, 0x19, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x18, 0x18, 0x19})); + CHECK(json::parse("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]") == json::from_cbor(std::vector({0x98, 0x19, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x18, 0x18, 0x19}))); // indefinite length arrays - CHECK(json::parse("[]") == json::from_cbor(std::vector({0x9f, 0xff}))); - CHECK(json::parse("[1, [2, 3], [4, 5]] ") == json::from_cbor(std::vector({0x9f, 0x01, 0x82, 0x02, 0x03, 0x9f, 0x04, 0x05, 0xff, 0xff}))); - CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector({0x9f, 0x01, 0x82, 0x02, 0x03, 0x82, 0x04, 0x05, 0xff}))); - CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector({0x83, 0x01, 0x82, 0x02, 0x03, 0x9f, 0x04, 0x05, 0xff}))); - CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector({0x83, 0x01, 0x9f, 0x02, 0x03, 0xff, 0x82, 0x04, 0x05}))); - CHECK(json::parse("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]") == json::from_cbor(std::vector({0x9f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x18, 0x18, 0x19, 0xff}))); + CHECK(json::parse("[]") == json::from_cbor(std::vector({0x9f, 0xff}))); + CHECK(json::parse("[1, [2, 3], [4, 5]] ") == json::from_cbor(std::vector({0x9f, 0x01, 0x82, 0x02, 0x03, 0x9f, 0x04, 0x05, 0xff, 0xff}))); + CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector({0x9f, 0x01, 0x82, 0x02, 0x03, 0x82, 0x04, 0x05, 0xff}))); + CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector({0x83, 0x01, 0x82, 0x02, 0x03, 0x9f, 0x04, 0x05, 0xff}))); + CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector({0x83, 0x01, 0x9f, 0x02, 0x03, 0xff, 0x82, 0x04, 0x05}))); + CHECK(json::parse("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]") == json::from_cbor(std::vector({0x9f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x18, 0x18, 0x19, 0xff}))); } SECTION("objects") { - CHECK(json::to_cbor(json::parse("{}")) == std::vector({0xa0})); - CHECK(json::parse("{}") == json::from_cbor(std::vector({0xa0}))); + CHECK(json::to_cbor(json::parse("{}")) == std::vector({0xa0})); + CHECK(json::parse("{}") == json::from_cbor(std::vector({0xa0}))); - CHECK(json::to_cbor(json::parse("{\"a\": 1, \"b\": [2, 3]}")) == std::vector({0xa2, 0x61, 0x61, 0x01, 0x61, 0x62, 0x82, 0x02, 0x03})); - CHECK(json::parse("{\"a\": 1, \"b\": [2, 3]}") == json::from_cbor(std::vector({0xa2, 0x61, 0x61, 0x01, 0x61, 0x62, 0x82, 0x02, 0x03}))); + CHECK(json::to_cbor(json::parse("{\"a\": 1, \"b\": [2, 3]}")) == std::vector({0xa2, 0x61, 0x61, 0x01, 0x61, 0x62, 0x82, 0x02, 0x03})); + CHECK(json::parse("{\"a\": 1, \"b\": [2, 3]}") == json::from_cbor(std::vector({0xa2, 0x61, 0x61, 0x01, 0x61, 0x62, 0x82, 0x02, 0x03}))); - CHECK(json::to_cbor(json::parse("[\"a\", {\"b\": \"c\"}]")) == std::vector({0x82, 0x61, 0x61, 0xa1, 0x61, 0x62, 0x61, 0x63})); - CHECK(json::parse("[\"a\", {\"b\": \"c\"}]") == json::from_cbor(std::vector({0x82, 0x61, 0x61, 0xa1, 0x61, 0x62, 0x61, 0x63}))); + CHECK(json::to_cbor(json::parse("[\"a\", {\"b\": \"c\"}]")) == std::vector({0x82, 0x61, 0x61, 0xa1, 0x61, 0x62, 0x61, 0x63})); + CHECK(json::parse("[\"a\", {\"b\": \"c\"}]") == json::from_cbor(std::vector({0x82, 0x61, 0x61, 0xa1, 0x61, 0x62, 0x61, 0x63}))); - CHECK(json::to_cbor(json::parse("{\"a\": \"A\", \"b\": \"B\", \"c\": \"C\", \"d\": \"D\", \"e\": \"E\"}")) == std::vector({0xa5, 0x61, 0x61, 0x61, 0x41, 0x61, 0x62, 0x61, 0x42, 0x61, 0x63, 0x61, 0x43, 0x61, 0x64, 0x61, 0x44, 0x61, 0x65, 0x61, 0x45})); - CHECK(json::parse("{\"a\": \"A\", \"b\": \"B\", \"c\": \"C\", \"d\": \"D\", \"e\": \"E\"}") == json::from_cbor(std::vector({0xa5, 0x61, 0x61, 0x61, 0x41, 0x61, 0x62, 0x61, 0x42, 0x61, 0x63, 0x61, 0x43, 0x61, 0x64, 0x61, 0x44, 0x61, 0x65, 0x61, 0x45}))); + CHECK(json::to_cbor(json::parse("{\"a\": \"A\", \"b\": \"B\", \"c\": \"C\", \"d\": \"D\", \"e\": \"E\"}")) == std::vector({0xa5, 0x61, 0x61, 0x61, 0x41, 0x61, 0x62, 0x61, 0x42, 0x61, 0x63, 0x61, 0x43, 0x61, 0x64, 0x61, 0x44, 0x61, 0x65, 0x61, 0x45})); + CHECK(json::parse("{\"a\": \"A\", \"b\": \"B\", \"c\": \"C\", \"d\": \"D\", \"e\": \"E\"}") == json::from_cbor(std::vector({0xa5, 0x61, 0x61, 0x61, 0x41, 0x61, 0x62, 0x61, 0x42, 0x61, 0x63, 0x61, 0x43, 0x61, 0x64, 0x61, 0x44, 0x61, 0x65, 0x61, 0x45}))); // indefinite length objects - CHECK(json::parse("{\"a\": 1, \"b\": [2, 3]}") == json::from_cbor(std::vector({0xbf, 0x61, 0x61, 0x01, 0x61, 0x62, 0x9f, 0x02, 0x03, 0xff, 0xff}))); - CHECK(json::parse("[\"a\", {\"b\": \"c\"}]") == json::from_cbor(std::vector({0x82, 0x61, 0x61, 0xbf, 0x61, 0x62, 0x61, 0x63, 0xff}))); - CHECK(json::parse("{\"Fun\": true, \"Amt\": -2}") == json::from_cbor(std::vector({0xbf, 0x63, 0x46, 0x75, 0x6e, 0xf5, 0x63, 0x41, 0x6d, 0x74, 0x21, 0xff}))); + CHECK(json::parse("{\"a\": 1, \"b\": [2, 3]}") == json::from_cbor(std::vector({0xbf, 0x61, 0x61, 0x01, 0x61, 0x62, 0x9f, 0x02, 0x03, 0xff, 0xff}))); + CHECK(json::parse("[\"a\", {\"b\": \"c\"}]") == json::from_cbor(std::vector({0x82, 0x61, 0x61, 0xbf, 0x61, 0x62, 0x61, 0x63, 0xff}))); + CHECK(json::parse("{\"Fun\": true, \"Amt\": -2}") == json::from_cbor(std::vector({0xbf, 0x63, 0x46, 0x75, 0x6e, 0xf5, 0x63, 0x41, 0x6d, 0x74, 0x21, 0xff}))); } } diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index 0f7aab8da1..5f8ee948c9 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -15,9 +15,10 @@ using nlohmann::json; #endif #include -#include #include +#include #include +#include #include "make_test_data_available.hpp" #include "test_utils.hpp" @@ -114,7 +115,7 @@ TEST_CASE("MessagePack") SECTION("null") { json j = nullptr; - std::vector expected = {0xc0}; + std::vector expected = {0xc0}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -128,7 +129,7 @@ TEST_CASE("MessagePack") SECTION("true") { json j = true; - std::vector expected = {0xc3}; + std::vector expected = {0xc3}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -140,7 +141,7 @@ TEST_CASE("MessagePack") SECTION("false") { json j = false; - std::vector expected = {0xc2}; + std::vector expected = {0xc2}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -167,8 +168,8 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(i)); + std::vector expected; + expected.push_back(static_cast(i)); // compare result + size const auto result = json::to_msgpack(j); @@ -176,7 +177,7 @@ TEST_CASE("MessagePack") CHECK(result.size() == 1); // check individual bytes - CHECK(static_cast(result[0]) == i); + CHECK(static_cast(result[0]) == i); // roundtrip CHECK(json::from_msgpack(result) == j); @@ -198,8 +199,8 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(i)); + std::vector expected; + expected.push_back(static_cast(i)); // compare result + size const auto result = json::to_msgpack(j); @@ -229,9 +230,9 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xcc); - expected.push_back(static_cast(i)); + expected.push_back(static_cast(i)); // compare result + size const auto result = json::to_msgpack(j); @@ -240,7 +241,7 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcc); - auto restored = static_cast(result[1]); + auto restored = static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -263,10 +264,10 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xcd); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_msgpack(j); @@ -275,7 +276,7 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcd); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == i); // roundtrip @@ -286,7 +287,7 @@ TEST_CASE("MessagePack") SECTION("65536..4294967295 (int 32)") { - for (uint32_t i : + for (std::uint32_t i : { 65536u, 77777u, 1048576u, 4294967295u }) @@ -301,12 +302,12 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xce); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 24) & 0xff)); + expected.push_back(static_cast((i >> 16) & 0xff)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_msgpack(j); @@ -315,10 +316,10 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xce); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + std::uint32_t restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == i); // roundtrip @@ -329,7 +330,7 @@ TEST_CASE("MessagePack") SECTION("4294967296..9223372036854775807 (int 64)") { - for (uint64_t i : + for (std::uint64_t i : { 4294967296LU, 9223372036854775807LU }) @@ -344,16 +345,16 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xcf); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 070) & 0xff)); + expected.push_back(static_cast((i >> 060) & 0xff)); + expected.push_back(static_cast((i >> 050) & 0xff)); + expected.push_back(static_cast((i >> 040) & 0xff)); + expected.push_back(static_cast((i >> 030) & 0xff)); + expected.push_back(static_cast((i >> 020) & 0xff)); + expected.push_back(static_cast((i >> 010) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_msgpack(j); @@ -362,14 +363,14 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcf); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + std::uint64_t restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -391,9 +392,9 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xd0); - expected.push_back(static_cast(i)); + expected.push_back(static_cast(i)); // compare result + size const auto result = json::to_msgpack(j); @@ -402,7 +403,7 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xd0); - CHECK(static_cast(result[1]) == i); + CHECK(static_cast(result[1]) == i); // roundtrip CHECK(json::from_msgpack(result) == j); @@ -413,12 +414,12 @@ TEST_CASE("MessagePack") SECTION("-9263 (int 16)") { json j = -9263; - std::vector expected = {0xd1, 0xdb, 0xd1}; + std::vector expected = {0xd1, 0xdb, 0xd1}; const auto result = json::to_msgpack(j); CHECK(result == expected); - auto restored = static_cast((result[1] << 8) + result[2]); + auto restored = static_cast((result[1] << 8) + result[2]); CHECK(restored == -9263); // roundtrip @@ -428,7 +429,7 @@ TEST_CASE("MessagePack") SECTION("-32768..-129 (int 16)") { - for (int16_t i = -32768; i <= static_cast(-129); ++i) + for (std::int16_t i = -32768; i <= static_cast(-129); ++i) { CAPTURE(i) @@ -439,10 +440,10 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xd1); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_msgpack(j); @@ -451,7 +452,7 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xd1); - auto restored = static_cast((result[1] << 8) + result[2]); + auto restored = static_cast((result[1] << 8) + result[2]); CHECK(restored == i); // roundtrip @@ -462,7 +463,7 @@ TEST_CASE("MessagePack") SECTION("-32769..-2147483648") { - std::vector numbers; + std::vector numbers; numbers.push_back(-32769); numbers.push_back(-65536); numbers.push_back(-77777); @@ -479,12 +480,12 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xd2); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 24) & 0xff)); + expected.push_back(static_cast((i >> 16) & 0xff)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_msgpack(j); @@ -493,10 +494,10 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xd2); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + std::uint32_t restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(static_cast(restored) == i); // roundtrip @@ -507,8 +508,8 @@ TEST_CASE("MessagePack") SECTION("-9223372036854775808..-2147483649 (int 64)") { - std::vector numbers; - numbers.push_back(INT64_MIN); + std::vector numbers; + numbers.push_back(std::numeric_limits::min()); numbers.push_back(-2147483649LL); for (auto i : numbers) { @@ -521,16 +522,16 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xd3); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 070) & 0xff)); + expected.push_back(static_cast((i >> 060) & 0xff)); + expected.push_back(static_cast((i >> 050) & 0xff)); + expected.push_back(static_cast((i >> 040) & 0xff)); + expected.push_back(static_cast((i >> 030) & 0xff)); + expected.push_back(static_cast((i >> 020) & 0xff)); + expected.push_back(static_cast((i >> 010) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_msgpack(j); @@ -539,14 +540,14 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xd3); - int64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + std::int64_t restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -571,8 +572,8 @@ TEST_CASE("MessagePack") CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(i)); + std::vector expected; + expected.push_back(static_cast(i)); // compare result + size const auto result = json::to_msgpack(j); @@ -601,9 +602,9 @@ TEST_CASE("MessagePack") CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xcc); - expected.push_back(static_cast(i)); + expected.push_back(static_cast(i)); // compare result + size const auto result = json::to_msgpack(j); @@ -612,7 +613,7 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcc); - auto restored = static_cast(result[1]); + auto restored = static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -623,7 +624,7 @@ TEST_CASE("MessagePack") SECTION("256..65535 (uint 16)") { - for (size_t i = 256; i <= 65535; ++i) + for (std::size_t i = 256; i <= 65535; ++i) { CAPTURE(i) @@ -634,10 +635,10 @@ TEST_CASE("MessagePack") CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xcd); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_msgpack(j); @@ -646,7 +647,7 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcd); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == i); // roundtrip @@ -657,7 +658,7 @@ TEST_CASE("MessagePack") SECTION("65536..4294967295 (uint 32)") { - for (uint32_t i : + for (std::uint32_t i : { 65536u, 77777u, 1048576u, 4294967295u }) @@ -671,12 +672,12 @@ TEST_CASE("MessagePack") CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xce); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 24) & 0xff)); + expected.push_back(static_cast((i >> 16) & 0xff)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_msgpack(j); @@ -685,10 +686,10 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xce); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + std::uint32_t restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == i); // roundtrip @@ -699,7 +700,7 @@ TEST_CASE("MessagePack") SECTION("4294967296..18446744073709551615 (uint 64)") { - for (uint64_t i : + for (std::uint64_t i : { 4294967296LU, 18446744073709551615LU }) @@ -713,16 +714,16 @@ TEST_CASE("MessagePack") CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xcf); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + expected.push_back(static_cast((i >> 070) & 0xff)); + expected.push_back(static_cast((i >> 060) & 0xff)); + expected.push_back(static_cast((i >> 050) & 0xff)); + expected.push_back(static_cast((i >> 040) & 0xff)); + expected.push_back(static_cast((i >> 030) & 0xff)); + expected.push_back(static_cast((i >> 020) & 0xff)); + expected.push_back(static_cast((i >> 010) & 0xff)); + expected.push_back(static_cast(i & 0xff)); // compare result + size const auto result = json::to_msgpack(j); @@ -731,14 +732,14 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcf); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + std::uint64_t restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -754,7 +755,7 @@ TEST_CASE("MessagePack") { double v = 3.1415925; json j = v; - std::vector expected = + std::vector expected = { 0xcb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc }; @@ -771,7 +772,7 @@ TEST_CASE("MessagePack") { double v = 1.0; json j = v; - std::vector expected = + std::vector expected = { 0xca, 0x3f, 0x80, 0x00, 0x00 }; @@ -788,7 +789,7 @@ TEST_CASE("MessagePack") { double v = 128.1280059814453125; json j = v; - std::vector expected = + std::vector expected = { 0xca, 0x43, 0x00, 0x20, 0xc5 }; @@ -808,7 +809,7 @@ TEST_CASE("MessagePack") SECTION("N = 0..31") { // explicitly enumerate the first byte for all 32 strings - const std::vector first_bytes = + const std::vector first_bytes = { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, @@ -825,7 +826,7 @@ TEST_CASE("MessagePack") json j = s; // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(first_bytes[N]); for (size_t i = 0; i < N; ++i) { @@ -862,9 +863,9 @@ TEST_CASE("MessagePack") json j = s; // create expected byte vector - std::vector expected; + std::vector expected; expected.push_back(0xd9); - expected.push_back(static_cast(N)); + expected.push_back(static_cast(N)); for (size_t i = 0; i < N; ++i) { expected.push_back('x'); @@ -897,10 +898,10 @@ TEST_CASE("MessagePack") json j = s; // create expected byte vector (hack: create string first) - std::vector expected(N, 'x'); + std::vector expected(N, 'x'); // reverse order of commands, because we insert at begin() - expected.insert(expected.begin(), static_cast(N & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); + expected.insert(expected.begin(), static_cast(N & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); expected.insert(expected.begin(), 0xda); // compare result + size @@ -930,12 +931,12 @@ TEST_CASE("MessagePack") json j = s; // create expected byte vector (hack: create string first) - std::vector expected(N, 'x'); + std::vector expected(N, 'x'); // reverse order of commands, because we insert at begin() - expected.insert(expected.begin(), static_cast(N & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 16) & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 24) & 0xff)); + expected.insert(expected.begin(), static_cast(N & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 16) & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 24) & 0xff)); expected.insert(expected.begin(), 0xdb); // compare result + size @@ -957,7 +958,7 @@ TEST_CASE("MessagePack") SECTION("empty") { json j = json::array(); - std::vector expected = {0x90}; + std::vector expected = {0x90}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -969,7 +970,7 @@ TEST_CASE("MessagePack") SECTION("[null]") { json j = {nullptr}; - std::vector expected = {0x91, 0xc0}; + std::vector expected = {0x91, 0xc0}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -981,7 +982,7 @@ TEST_CASE("MessagePack") SECTION("[1,2,3,4,5]") { json j = json::parse("[1,2,3,4,5]"); - std::vector expected = {0x95, 0x01, 0x02, 0x03, 0x04, 0x05}; + std::vector expected = {0x95, 0x01, 0x02, 0x03, 0x04, 0x05}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -993,7 +994,7 @@ TEST_CASE("MessagePack") SECTION("[[[[]]]]") { json j = json::parse("[[[[]]]]"); - std::vector expected = {0x91, 0x91, 0x91, 0x90}; + std::vector expected = {0x91, 0x91, 0x91, 0x90}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -1005,7 +1006,7 @@ TEST_CASE("MessagePack") SECTION("array 16") { json j(16, nullptr); - std::vector expected(j.size() + 3, 0xc0); // all null + std::vector expected(j.size() + 3, 0xc0); // all null expected[0] = 0xdc; // array 16 expected[1] = 0x00; // size (0x0010), byte 0 expected[2] = 0x10; // size (0x0010), byte 1 @@ -1020,7 +1021,7 @@ TEST_CASE("MessagePack") SECTION("array 32") { json j(65536, nullptr); - std::vector expected(j.size() + 5, 0xc0); // all null + std::vector expected(j.size() + 5, 0xc0); // all null expected[0] = 0xdd; // array 32 expected[1] = 0x00; // size (0x00100000), byte 0 expected[2] = 0x01; // size (0x00100000), byte 1 @@ -1047,7 +1048,7 @@ TEST_CASE("MessagePack") SECTION("empty") { json j = json::object(); - std::vector expected = {0x80}; + std::vector expected = {0x80}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -1059,7 +1060,7 @@ TEST_CASE("MessagePack") SECTION("{\"\":null}") { json j = {{"", nullptr}}; - std::vector expected = {0x81, 0xa0, 0xc0}; + std::vector expected = {0x81, 0xa0, 0xc0}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -1071,7 +1072,7 @@ TEST_CASE("MessagePack") SECTION("{\"a\": {\"b\": {\"c\": {}}}}") { json j = json::parse(R"({"a": {"b": {"c": {}}}})"); - std::vector expected = + std::vector expected = { 0x81, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0x81, 0xa1, 0x63, 0x80 }; @@ -1148,13 +1149,13 @@ TEST_CASE("MessagePack") CAPTURE(N) // create JSON value with byte array containing of N * 'x' - const auto s = std::vector(N, 'x'); + const auto s = std::vector(N, 'x'); json j = json::binary(s); std::uint8_t subtype = 42; j.get_binary().set_subtype(subtype); // create expected byte vector - std::vector expected; + std::vector expected; switch (N) { case 1: @@ -1223,17 +1224,17 @@ TEST_CASE("MessagePack") CAPTURE(N) // create JSON value with string containing of N * 'x' - const auto s = std::vector(N, 'x'); + const auto s = std::vector(N, 'x'); json j = json::binary(s); std::uint8_t subtype = 42; j.get_binary().set_subtype(subtype); // create expected byte vector (hack: create string first) - std::vector expected(N, 'x'); + std::vector expected(N, 'x'); // reverse order of commands, because we insert at begin() expected.insert(expected.begin(), subtype); - expected.insert(expected.begin(), static_cast(N & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); + expected.insert(expected.begin(), static_cast(N & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); expected.insert(expected.begin(), 0xC8); // compare result + size @@ -1259,19 +1260,19 @@ TEST_CASE("MessagePack") CAPTURE(N) // create JSON value with string containing of N * 'x' - const auto s = std::vector(N, 'x'); + const auto s = std::vector(N, 'x'); json j = json::binary(s); std::uint8_t subtype = 42; j.get_binary().set_subtype(subtype); // create expected byte vector (hack: create string first) - std::vector expected(N, 'x'); + std::vector expected(N, 'x'); // reverse order of commands, because we insert at begin() expected.insert(expected.begin(), subtype); - expected.insert(expected.begin(), static_cast(N & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 16) & 0xff)); - expected.insert(expected.begin(), static_cast((N >> 24) & 0xff)); + expected.insert(expected.begin(), static_cast(N & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 16) & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 24) & 0xff)); expected.insert(expected.begin(), 0xC9); // compare result + size @@ -1297,7 +1298,7 @@ TEST_CASE("MessagePack") CAPTURE(N) // create JSON value with byte array containing of N * 'x' - const auto s = std::vector(N, 'x'); + const auto s = std::vector(N, 'x'); json j = json::binary(s); // create expected byte vector @@ -1372,7 +1373,7 @@ TEST_CASE("MessagePack") json j = json::binary(s); // create expected byte vector (hack: create string first) - std::vector expected(N, 'x'); + std::vector expected(N, 'x'); // reverse order of commands, because we insert at begin() expected.insert(expected.begin(), static_cast(N & 0xff)); expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); @@ -1397,7 +1398,7 @@ TEST_CASE("MessagePack") SECTION("from float32") { - auto given = std::vector({0xca, 0x41, 0xc8, 0x00, 0x01}); + auto given = std::vector({0xca, 0x41, 0xc8, 0x00, 0x01}); json j = json::from_msgpack(given); CHECK(j.get() == Approx(25.0000019073486)); } @@ -1407,76 +1408,76 @@ TEST_CASE("MessagePack") SECTION("empty byte vector") { json _; - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector()), "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&); - CHECK(json::from_msgpack(std::vector(), true, false).is_discarded()); + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector()), "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&); + CHECK(json::from_msgpack(std::vector(), true, false).is_discarded()); } SECTION("too short byte vector") { json _; - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0x87})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0x87})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcc})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcc})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcd})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcd})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcd, 0x00})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcd, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xce})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xce})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xce, 0x00})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xce, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xce, 0x00, 0x00})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xce, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xce, 0x00, 0x00, 0x00})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xce, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xa5, 0x68, 0x65})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xa5, 0x68, 0x65})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack string: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0x92, 0x01})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0x92, 0x01})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0x81, 0xa1, 0x61})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0x81, 0xa1, 0x61})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&); - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xc4, 0x02})), + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xc4, 0x02})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack binary: unexpected end of input", json::parse_error&); - CHECK(json::from_msgpack(std::vector({0x87}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xcc}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xcd}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xcd, 0x00}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xce}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xce, 0x00}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xce, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xce, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xcf}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xcf, 0x00}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xa5, 0x68, 0x65}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0x92, 0x01}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0x81, 0xA1, 0x61}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xc4, 0x02}), true, false).is_discarded()); - CHECK(json::from_msgpack(std::vector({0xc4}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0x87}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xcc}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xcd}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xcd, 0x00}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xce}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xce, 0x00}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xce, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xce, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xcf}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xcf, 0x00}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xa5, 0x68, 0x65}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0x92, 0x01}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0x81, 0xA1, 0x61}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xc4, 0x02}), true, false).is_discarded()); + CHECK(json::from_msgpack(std::vector({0xc4}), true, false).is_discarded()); } SECTION("unsupported bytes") @@ -1484,7 +1485,7 @@ TEST_CASE("MessagePack") SECTION("concrete examples") { json _; - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xc1})), "[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing MessagePack value: invalid byte: 0xC1", json::parse_error&); + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0xc1})), "[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing MessagePack value: invalid byte: 0xC1", json::parse_error&); } SECTION("all unsupported bytes") @@ -1496,8 +1497,8 @@ TEST_CASE("MessagePack") }) { json _; - CHECK_THROWS_AS(_ = json::from_msgpack(std::vector({static_cast(byte)})), json::parse_error&); - CHECK(json::from_msgpack(std::vector({static_cast(byte)}), true, false).is_discarded()); + CHECK_THROWS_AS(_ = json::from_msgpack(std::vector({static_cast(byte)})), json::parse_error&); + CHECK(json::from_msgpack(std::vector({static_cast(byte)}), true, false).is_discarded()); } } } @@ -1505,13 +1506,13 @@ TEST_CASE("MessagePack") SECTION("invalid string in map") { json _; - CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0x81, 0xff, 0x01})), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing MessagePack string: expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0xFF", json::parse_error&); - CHECK(json::from_msgpack(std::vector({0x81, 0xff, 0x01}), true, false).is_discarded()); + CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector({0x81, 0xff, 0x01})), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing MessagePack string: expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0xFF", json::parse_error&); + CHECK(json::from_msgpack(std::vector({0x81, 0xff, 0x01}), true, false).is_discarded()); } SECTION("strict mode") { - std::vector vec = {0xc0, 0xc0}; + std::vector vec = {0xc0, 0xc0}; SECTION("non-strict mode") { const auto result = json::from_msgpack(vec, false); @@ -1531,21 +1532,21 @@ TEST_CASE("MessagePack") { SECTION("start_array(len)") { - std::vector v = {0x93, 0x01, 0x02, 0x03}; + std::vector v = {0x93, 0x01, 0x02, 0x03}; SaxCountdown scp(0); CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack)); } SECTION("start_object(len)") { - std::vector v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2}; + std::vector v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2}; SaxCountdown scp(0); CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack)); } SECTION("key()") { - std::vector v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2}; + std::vector v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2}; SaxCountdown scp(1); CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack)); } @@ -1769,7 +1770,7 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip()) CAPTURE(filename) { - INFO_WITH_TEMP(filename + ": std::vector"); + INFO_WITH_TEMP(filename + ": std::vector"); // parse JSON file std::ifstream f_json(filename); json j1 = json::parse(f_json); @@ -1825,8 +1826,8 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip()) if (exclude_packed.count(filename) == 0u) { { - INFO_WITH_TEMP(filename + ": output adapters: std::vector"); - std::vector vec; + INFO_WITH_TEMP(filename + ": output adapters: std::vector"); + std::vector vec; json::to_msgpack(j1, vec); CHECK(vec == packed); } diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index ee7f8bc12c..ee471259f7 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -18,10 +18,11 @@ using nlohmann::json; using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif +#include #include -#include +#include #include -#include +#include #include "make_test_data_available.hpp" #ifdef JSON_HAS_CPP_17 @@ -877,12 +878,12 @@ TEST_CASE("regression tests 1") // original test case json j1 = json::parse("-9223372036854775808"); CHECK(j1.is_number_integer()); - CHECK(j1.get() == INT64_MIN); + CHECK(j1.get() == std::numeric_limits::min()); // edge case (+1; still an integer) json j2 = json::parse("-9223372036854775807"); CHECK(j2.is_number_integer()); - CHECK(j2.get() == INT64_MIN + 1); + CHECK(j2.get() == std::numeric_limits::min() + 1); // edge case (-1; overflow -> floats) json j3 = json::parse("-9223372036854775809"); diff --git a/tests/src/unit-to_chars.cpp b/tests/src/unit-to_chars.cpp index 0d5fcd4226..3048bdb488 100644 --- a/tests/src/unit-to_chars.cpp +++ b/tests/src/unit-to_chars.cpp @@ -463,8 +463,8 @@ TEST_CASE("formatting") }; // edge cases - check_integer(INT64_MIN, "-9223372036854775808"); - check_integer(INT64_MAX, "9223372036854775807"); + check_integer(std::numeric_limits::min(), "-9223372036854775808"); + check_integer(std::numeric_limits::max(), "9223372036854775807"); // few random big integers check_integer(-3456789012345678901LL, "-3456789012345678901");