Add support for MsgPack extension

This commit is contained in:
Benoit Blanchon
2024-06-06 18:33:48 +02:00
parent aec642be20
commit e4f3fd8c91
13 changed files with 514 additions and 194 deletions

View File

@@ -41,6 +41,24 @@ TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 1") {
}
}
SECTION("set(MsgPackExtension)") {
SECTION("returns true if size <= 252") {
auto str = std::string(252, '?');
auto result = doc.set(MsgPackExtension(1, str.data(), str.size()));
REQUIRE(result == true);
REQUIRE(doc.overflowed() == false);
}
SECTION("returns false if size >= 253") {
auto str = std::string(253, '?');
auto result = doc.set(MsgPackExtension(1, str.data(), str.size()));
REQUIRE(result == false);
REQUIRE(doc.overflowed() == true);
}
}
SECTION("deserializeJson()") {
SECTION("returns Ok if string length <= 255") {
auto input = "\"" + std::string(255, '?') + "\"";
@@ -91,5 +109,21 @@ TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 1") {
REQUIRE(err == DeserializationError::NoMemory);
}
SECTION("returns Ok if extension size <= 252") {
auto input = "\xc7\xfc\x01" + std::string(252, '?');
auto err = deserializeMsgPack(doc, input);
REQUIRE(err == DeserializationError::Ok);
}
SECTION("returns NoMemory if binary size >= 253") {
auto input = "\xc7\xfd\x01" + std::string(253, '?');
auto err = deserializeMsgPack(doc, input);
REQUIRE(err == DeserializationError::NoMemory);
}
}
}