FoodDelivery/ArduinoJson/extras/tests/MsgPackDeserializer/notSupported.cpp
tk b708b47c4b 【类 型】:fix
【主	题】:添加库文件
【描	述】:
	[原因]:
	[过程]:
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
2024-06-14 17:16:36 +08:00

83 lines
2.2 KiB
C++

// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
static void checkMsgPackDocument(const char* input, size_t inputSize,
const char* expectedJson) {
DynamicJsonDocument doc(4096);
DeserializationError error = deserializeMsgPack(doc, input, inputSize);
REQUIRE(error == DeserializationError::Ok);
std::string actualJson;
serializeJson(doc, actualJson);
REQUIRE(actualJson == expectedJson);
}
static void checkMsgPackError(const char* input, size_t inputSize,
DeserializationError expectedError) {
DynamicJsonDocument doc(4096);
DeserializationError error = deserializeMsgPack(doc, input, inputSize);
REQUIRE(error == expectedError);
}
TEST_CASE("deserializeMsgPack() return NotSupported") {
SECTION("bin 8") {
checkMsgPackDocument("\x92\xc4\x01X\x2A", 5, "[null,42]");
}
SECTION("bin 16") {
checkMsgPackDocument("\x92\xc5\x00\x01X\x2A", 6, "[null,42]");
}
SECTION("bin 32") {
checkMsgPackDocument("\x92\xc6\x00\x00\x00\x01X\x2A", 8, "[null,42]");
}
SECTION("ext 8") {
checkMsgPackDocument("\x92\xc7\x01\x01\x01\x2A", 6, "[null,42]");
}
SECTION("ext 16") {
checkMsgPackDocument("\x92\xc8\x00\x01\x01\x01\x2A", 7, "[null,42]");
}
SECTION("ext 32") {
checkMsgPackDocument("\x92\xc9\x00\x00\x00\x01\x01\x01\x2A", 9,
"[null,42]");
}
SECTION("fixext 1") {
checkMsgPackDocument("\x92\xd4\x01\x01\x2A", 5, "[null,42]");
}
SECTION("fixext 2") {
checkMsgPackDocument("\x92\xd5\x01\x01\x02\x2A", 6, "[null,42]");
}
SECTION("fixext 4") {
checkMsgPackDocument("\x92\xd6\x01\x01\x02\x03\x04\x2A", 8, "[null,42]");
}
SECTION("fixext 8") {
checkMsgPackDocument("\x92\xd7\x01\x01\x02\x03\x04\x05\x06\x07\x08\x2A", 12,
"[null,42]");
}
SECTION("fixext 16") {
checkMsgPackDocument(
"\x92\xd8\x01\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E"
"\x0F\x10\x2A",
20, "[null,42]");
}
SECTION("integer as key") {
checkMsgPackError("\x81\x01\xA1H", 3, DeserializationError::InvalidInput);
}
}