diff --git a/test/src/unit-cbor.cpp b/test/src/unit-cbor.cpp index 9c5f76e7..aaad8c14 100644 --- a/test/src/unit-cbor.cpp +++ b/test/src/unit-cbor.cpp @@ -1109,6 +1109,58 @@ TEST_CASE("CBOR") } } } + + SECTION("additonal deserialization") + { + SECTION("0x7b (string)") + { + 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 + }; + 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 + }; + json j = json::from_cbor(given); + CHECK(j == json::parse("{\"\": false}")); + } + } + + SECTION("errors") + { + SECTION("too short byte vector") + { + CHECK_THROWS_AS(json::from_cbor(std::vector({0x18})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x19})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x19, 0x00})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1a})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1a, 0x00})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1a, 0x00, 0x00})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1a, 0x00, 0x00, 0x00})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1b})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1b, 0x00})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1b, 0x00, 0x00})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), std::out_of_range); + CHECK_THROWS_AS(json::from_cbor(std::vector({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), std::out_of_range); + } + } } // use this testcase outside [hide] to run it with Valgrind diff --git a/test/src/unit-msgpack.cpp b/test/src/unit-msgpack.cpp index 448cd019..26ce76d2 100644 --- a/test/src/unit-msgpack.cpp +++ b/test/src/unit-msgpack.cpp @@ -850,6 +850,13 @@ TEST_CASE("MessagePack") } } } + + SECTION("from double") + { + auto given = std::vector({0x19, 0x41, 0xc8, 0x00, 0x00}); + json j = json::from_msgpack(given); + CHECK(j == json(25.0)); + } }