From 5eee947ffea909c60094492a041e65d62500b4bd Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 12 Nov 2018 21:36:39 +0100 Subject: [PATCH] Increased test coverage of MessagePack serialization --- .../MsgPackDeserializer/deserializeObject.cpp | 41 +++++++++++++++++++ test/MsgPackSerializer/serializeArray.cpp | 22 +++++----- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/test/MsgPackDeserializer/deserializeObject.cpp b/test/MsgPackDeserializer/deserializeObject.cpp index a52d4d87..9909b570 100644 --- a/test/MsgPackDeserializer/deserializeObject.cpp +++ b/test/MsgPackDeserializer/deserializeObject.cpp @@ -32,6 +32,47 @@ TEST_CASE("deserialize MsgPack object") { REQUIRE(obj["one"] == 1); REQUIRE(obj["two"] == 2); } + + SECTION("key is str 8") { + const char* input = "\x82\xd9\x03one\x01\xd9\x03two\x02"; + + DeserializationError error = deserializeMsgPack(doc, input); + JsonObject obj = doc.as(); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + REQUIRE(obj.size() == 2); + REQUIRE(obj["one"] == 1); + REQUIRE(obj["two"] == 2); + } + + SECTION("key is str 16") { + const char* input = + "\x82\xdb\x00\x00\x00\x03one\x01\xdb\x00\x00\x00\x03two\x02"; + + DeserializationError error = deserializeMsgPack(doc, input); + JsonObject obj = doc.as(); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + REQUIRE(obj.size() == 2); + REQUIRE(obj["one"] == 1); + REQUIRE(obj["two"] == 2); + } + + SECTION("key is str 32") { + const char* input = + "\x82\xdb\x00\x00\x00\x03one\x01\xdb\x00\x00\x00\x03two\x02"; + + DeserializationError error = deserializeMsgPack(doc, input); + JsonObject obj = doc.as(); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + REQUIRE(obj.size() == 2); + REQUIRE(obj["one"] == 1); + REQUIRE(obj["two"] == 2); + } } SECTION("map 16") { diff --git a/test/MsgPackSerializer/serializeArray.cpp b/test/MsgPackSerializer/serializeArray.cpp index 5a009ace..ca5e5060 100644 --- a/test/MsgPackSerializer/serializeArray.cpp +++ b/test/MsgPackSerializer/serializeArray.cpp @@ -21,10 +21,9 @@ static void check(const JsonArray array, const char (&expected_data)[N]) { check(array, expected_data, expected_len); } -// TODO: this function is used by the commented test -// static void check(const JsonArray array, const std::string& expected) { -// check(array, expected.data(), expected.length()); -// } +static void check(const JsonArray array, const std::string& expected) { + check(array, expected.data(), expected.length()); +} TEST_CASE("serialize MsgPack array") { DynamicJsonDocument doc; @@ -49,12 +48,11 @@ TEST_CASE("serialize MsgPack array") { "\x0E\x0F"); } - // TODO: this test is too slow - // SECTION("array 32") { - // const char* nil = 0; - // for (int i = 0; i < 65536; i++) array.add(nil); - // - // check(array, - // std::string("\xDD\x00\x01\x00\x00", 5) + std::string(65536, 0xC0)); - // } + SECTION("array 32") { + const char* nil = 0; + for (int i = 0; i < 65536; i++) array.add(nil); + + check(array, + std::string("\xDD\x00\x01\x00\x00", 5) + std::string(65536, '\xc0')); + } }