Update ArduinoJSON, esp-nimble-cpp, Arduino Core, ESP-IDF (#448)
* ArduinoJSON 7.1.0 * Update nimble and arduino core * Update nuki_ble
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
template <typename T>
|
||||
static void checkValue(const char* input, T expected) {
|
||||
@@ -123,21 +124,171 @@ TEST_CASE("deserialize MsgPack value") {
|
||||
|
||||
SECTION("fixstr") {
|
||||
checkValue<std::string>("\xA0", std::string(""));
|
||||
checkValue<std::string>("\xABhello world", std::string("hello world"));
|
||||
checkValue<std::string>("\xABhello world", "hello world"_s);
|
||||
checkValue<std::string>("\xBFhello world hello world hello !",
|
||||
std::string("hello world hello world hello !"));
|
||||
"hello world hello world hello !"_s);
|
||||
}
|
||||
|
||||
SECTION("str 8") {
|
||||
checkValue<std::string>("\xd9\x05hello", std::string("hello"));
|
||||
checkValue<std::string>("\xd9\x05hello", "hello"_s);
|
||||
}
|
||||
|
||||
SECTION("str 16") {
|
||||
checkValue<std::string>("\xda\x00\x05hello", std::string("hello"));
|
||||
checkValue<std::string>("\xda\x00\x05hello", "hello"_s);
|
||||
}
|
||||
|
||||
SECTION("str 32") {
|
||||
checkValue<std::string>("\xdb\x00\x00\x00\x05hello", std::string("hello"));
|
||||
checkValue<std::string>("\xdb\x00\x00\x00\x05hello", "hello"_s);
|
||||
}
|
||||
|
||||
SECTION("bin 8") {
|
||||
JsonDocument doc;
|
||||
|
||||
DeserializationError error = deserializeMsgPack(doc, "\xc4\x01?");
|
||||
|
||||
REQUIRE(error == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<MsgPackBinary>());
|
||||
auto binary = doc.as<MsgPackBinary>();
|
||||
REQUIRE(binary.size() == 1);
|
||||
REQUIRE(binary.data() != nullptr);
|
||||
REQUIRE(reinterpret_cast<const char*>(binary.data())[0] == '?');
|
||||
}
|
||||
|
||||
SECTION("bin 16") {
|
||||
JsonDocument doc;
|
||||
auto str = std::string(256, '?');
|
||||
auto input = "\xc5\x01\x00"_s + str;
|
||||
|
||||
DeserializationError error = deserializeMsgPack(doc, input);
|
||||
|
||||
REQUIRE(error == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<MsgPackBinary>());
|
||||
auto binary = doc.as<MsgPackBinary>();
|
||||
REQUIRE(binary.size() == 0x100);
|
||||
REQUIRE(binary.data() != nullptr);
|
||||
REQUIRE(std::string(reinterpret_cast<const char*>(binary.data()),
|
||||
binary.size()) == str);
|
||||
}
|
||||
|
||||
SECTION("fixext 1") {
|
||||
JsonDocument doc;
|
||||
|
||||
auto error = deserializeMsgPack(doc, "\xd4\x01\x02");
|
||||
|
||||
REQUIRE(error == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<MsgPackExtension>());
|
||||
auto ext = doc.as<MsgPackExtension>();
|
||||
REQUIRE(ext.type() == 1);
|
||||
REQUIRE(ext.size() == 1);
|
||||
auto data = reinterpret_cast<const uint8_t*>(ext.data());
|
||||
REQUIRE(data[0] == 2);
|
||||
}
|
||||
|
||||
SECTION("fixext 2") {
|
||||
JsonDocument doc;
|
||||
|
||||
auto error = deserializeMsgPack(doc, "\xd5\x01\x02\x03");
|
||||
|
||||
REQUIRE(error == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<MsgPackExtension>());
|
||||
auto ext = doc.as<MsgPackExtension>();
|
||||
REQUIRE(ext.type() == 1);
|
||||
REQUIRE(ext.size() == 2);
|
||||
auto data = reinterpret_cast<const uint8_t*>(ext.data());
|
||||
REQUIRE(data[0] == 2);
|
||||
REQUIRE(data[1] == 3);
|
||||
}
|
||||
|
||||
SECTION("fixext 4") {
|
||||
JsonDocument doc;
|
||||
|
||||
auto error = deserializeMsgPack(doc, "\xd6\x01\x02\x03\x04\x05");
|
||||
|
||||
REQUIRE(error == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<MsgPackExtension>());
|
||||
auto ext = doc.as<MsgPackExtension>();
|
||||
REQUIRE(ext.type() == 1);
|
||||
REQUIRE(ext.size() == 4);
|
||||
auto data = reinterpret_cast<const uint8_t*>(ext.data());
|
||||
REQUIRE(data[0] == 2);
|
||||
REQUIRE(data[1] == 3);
|
||||
REQUIRE(data[2] == 4);
|
||||
REQUIRE(data[3] == 5);
|
||||
}
|
||||
|
||||
SECTION("fixext 8") {
|
||||
JsonDocument doc;
|
||||
|
||||
auto error = deserializeMsgPack(doc, "\xd7\x01????????");
|
||||
|
||||
REQUIRE(error == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<MsgPackExtension>());
|
||||
auto ext = doc.as<MsgPackExtension>();
|
||||
REQUIRE(ext.type() == 1);
|
||||
REQUIRE(ext.size() == 8);
|
||||
auto data = reinterpret_cast<const uint8_t*>(ext.data());
|
||||
REQUIRE(data[0] == '?');
|
||||
REQUIRE(data[7] == '?');
|
||||
}
|
||||
|
||||
SECTION("fixext 16") {
|
||||
JsonDocument doc;
|
||||
|
||||
auto error = deserializeMsgPack(doc, "\xd8\x01?????????????????");
|
||||
|
||||
REQUIRE(error == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<MsgPackExtension>());
|
||||
auto ext = doc.as<MsgPackExtension>();
|
||||
REQUIRE(ext.type() == 1);
|
||||
REQUIRE(ext.size() == 16);
|
||||
auto data = reinterpret_cast<const uint8_t*>(ext.data());
|
||||
REQUIRE(data[0] == '?');
|
||||
REQUIRE(data[15] == '?');
|
||||
}
|
||||
|
||||
SECTION("ext 8") {
|
||||
JsonDocument doc;
|
||||
|
||||
auto error = deserializeMsgPack(doc, "\xc7\x02\x01\x03\x04");
|
||||
|
||||
REQUIRE(error == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<MsgPackExtension>());
|
||||
auto ext = doc.as<MsgPackExtension>();
|
||||
REQUIRE(ext.type() == 1);
|
||||
REQUIRE(ext.size() == 2);
|
||||
auto data = reinterpret_cast<const uint8_t*>(ext.data());
|
||||
REQUIRE(data[0] == 3);
|
||||
REQUIRE(data[1] == 4);
|
||||
}
|
||||
|
||||
SECTION("ext 16") {
|
||||
JsonDocument doc;
|
||||
|
||||
auto error = deserializeMsgPack(doc, "\xc8\x00\x02\x01\x03\x04");
|
||||
|
||||
REQUIRE(error == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<MsgPackExtension>());
|
||||
auto ext = doc.as<MsgPackExtension>();
|
||||
REQUIRE(ext.type() == 1);
|
||||
REQUIRE(ext.size() == 2);
|
||||
auto data = reinterpret_cast<const uint8_t*>(ext.data());
|
||||
REQUIRE(data[0] == 3);
|
||||
REQUIRE(data[1] == 4);
|
||||
}
|
||||
|
||||
SECTION("ext 32") {
|
||||
JsonDocument doc;
|
||||
|
||||
auto error = deserializeMsgPack(doc, "\xc9\x00\x00\x00\x02\x01\x03\x04");
|
||||
|
||||
REQUIRE(error == DeserializationError::Ok);
|
||||
REQUIRE(doc.is<MsgPackExtension>());
|
||||
auto ext = doc.as<MsgPackExtension>();
|
||||
REQUIRE(ext.type() == 1);
|
||||
REQUIRE(ext.size() == 2);
|
||||
auto data = reinterpret_cast<const uint8_t*>(ext.data());
|
||||
REQUIRE(data[0] == 3);
|
||||
REQUIRE(data[1] == 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,12 +349,12 @@ TEST_CASE("deserializeMsgPack() under memory constaints") {
|
||||
checkError(0, "\x80", DeserializationError::Ok);
|
||||
}
|
||||
SECTION("{H:1}") {
|
||||
checkError(0, "\x81\xA1H\x01", DeserializationError::NoMemory);
|
||||
checkError(3, "\x81\xA1H\x01", DeserializationError::Ok);
|
||||
checkError(1, "\x81\xA1H\x01", DeserializationError::NoMemory);
|
||||
checkError(2, "\x81\xA1H\x01", DeserializationError::Ok);
|
||||
}
|
||||
SECTION("{H:1,W:2}") {
|
||||
checkError(3, "\x82\xA1H\x01\xA1W\x02", DeserializationError::NoMemory);
|
||||
checkError(5, "\x82\xA1H\x01\xA1W\x02", DeserializationError::Ok);
|
||||
checkError(2, "\x82\xA1H\x01\xA1W\x02", DeserializationError::NoMemory);
|
||||
checkError(3, "\x82\xA1H\x01\xA1W\x02", DeserializationError::Ok);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,13 +363,13 @@ TEST_CASE("deserializeMsgPack() under memory constaints") {
|
||||
checkError(0, "\xDE\x00\x00", DeserializationError::Ok);
|
||||
}
|
||||
SECTION("{H:1}") {
|
||||
checkError(2, "\xDE\x00\x01\xA1H\x01", DeserializationError::NoMemory);
|
||||
checkError(3, "\xDE\x00\x01\xA1H\x01", DeserializationError::Ok);
|
||||
checkError(1, "\xDE\x00\x01\xA1H\x01", DeserializationError::NoMemory);
|
||||
checkError(2, "\xDE\x00\x01\xA1H\x01", DeserializationError::Ok);
|
||||
}
|
||||
SECTION("{H:1,W:2}") {
|
||||
checkError(3, "\xDE\x00\x02\xA1H\x01\xA1W\x02",
|
||||
checkError(2, "\xDE\x00\x02\xA1H\x01\xA1W\x02",
|
||||
DeserializationError::NoMemory);
|
||||
checkError(5, "\xDE\x00\x02\xA1H\x01\xA1W\x02", DeserializationError::Ok);
|
||||
checkError(3, "\xDE\x00\x02\xA1H\x01\xA1W\x02", DeserializationError::Ok);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,14 +378,14 @@ TEST_CASE("deserializeMsgPack() under memory constaints") {
|
||||
checkError(0, "\xDF\x00\x00\x00\x00", DeserializationError::Ok);
|
||||
}
|
||||
SECTION("{H:1}") {
|
||||
checkError(2, "\xDF\x00\x00\x00\x01\xA1H\x01",
|
||||
checkError(1, "\xDF\x00\x00\x00\x01\xA1H\x01",
|
||||
DeserializationError::NoMemory);
|
||||
checkError(3, "\xDF\x00\x00\x00\x01\xA1H\x01", DeserializationError::Ok);
|
||||
checkError(2, "\xDF\x00\x00\x00\x01\xA1H\x01", DeserializationError::Ok);
|
||||
}
|
||||
SECTION("{H:1,W:2}") {
|
||||
checkError(3, "\xDF\x00\x00\x00\x02\xA1H\x01\xA1W\x02",
|
||||
checkError(2, "\xDF\x00\x00\x00\x02\xA1H\x01\xA1W\x02",
|
||||
DeserializationError::NoMemory);
|
||||
checkError(5, "\xDF\x00\x00\x00\x02\xA1H\x01\xA1W\x02",
|
||||
checkError(3, "\xDF\x00\x00\x00\x02\xA1H\x01\xA1W\x02",
|
||||
DeserializationError::Ok);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
using ArduinoJson::detail::sizeofArray;
|
||||
using ArduinoJson::detail::sizeofObject;
|
||||
@@ -15,7 +16,7 @@ using ArduinoJson::detail::sizeofObject;
|
||||
TEST_CASE("deserializeMsgPack(JsonDocument&)") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
doc.add(std::string("hello"));
|
||||
doc.add("hello"_s);
|
||||
spy.clearLog();
|
||||
|
||||
auto err = deserializeMsgPack(doc, "\x91\x2A");
|
||||
@@ -34,7 +35,7 @@ TEST_CASE("deserializeMsgPack(JsonVariant)") {
|
||||
SECTION("variant is bound") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
doc.add(std::string("hello"));
|
||||
doc.add("hello"_s);
|
||||
spy.clearLog();
|
||||
|
||||
JsonVariant variant = doc[0];
|
||||
@@ -60,7 +61,7 @@ TEST_CASE("deserializeMsgPack(JsonVariant)") {
|
||||
TEST_CASE("deserializeMsgPack(ElementProxy)") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
doc.add(std::string("hello"));
|
||||
doc.add("hello"_s);
|
||||
spy.clearLog();
|
||||
|
||||
SECTION("element already exists") {
|
||||
@@ -85,7 +86,7 @@ TEST_CASE("deserializeMsgPack(ElementProxy)") {
|
||||
TEST_CASE("deserializeMsgPack(MemberProxy)") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
doc[std::string("hello")] = std::string("world");
|
||||
doc["hello"_s] = "world"_s;
|
||||
spy.clearLog();
|
||||
|
||||
SECTION("member already exists") {
|
||||
|
||||
@@ -13,7 +13,7 @@ static void check(const char* input, T expected) {
|
||||
uint8_t* f = reinterpret_cast<uint8_t*>(&actual);
|
||||
const uint8_t* d = reinterpret_cast<const uint8_t*>(input);
|
||||
doubleToFloat(d, f);
|
||||
fixEndianess(actual);
|
||||
fixEndianness(actual);
|
||||
CHECK(actual == expected);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
|
||||
TEST_CASE("deserializeMsgPack() returns InvalidInput") {
|
||||
JsonDocument doc;
|
||||
|
||||
@@ -182,84 +184,18 @@ TEST_CASE("deserializeMsgPack() returns IncompleteInput") {
|
||||
}
|
||||
}
|
||||
|
||||
static std::string msgPackToJson(const char* input, size_t inputSize) {
|
||||
JsonDocument doc;
|
||||
auto err = deserializeMsgPack(doc, input, inputSize);
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
return doc.as<std::string>();
|
||||
}
|
||||
TEST_CASE(
|
||||
"deserializeMsgPack() returns NoMemory when string allocation fails") {
|
||||
TimebombAllocator allocator(0);
|
||||
JsonDocument doc(&allocator);
|
||||
|
||||
SECTION("fixstr") {
|
||||
DeserializationError err = deserializeMsgPack(doc, "\xA5hello", 9);
|
||||
REQUIRE(err == DeserializationError::NoMemory);
|
||||
}
|
||||
|
||||
TEST_CASE("deserializeMsgPack() replaces unsupported types by null") {
|
||||
SECTION("bin 8") {
|
||||
REQUIRE(msgPackToJson("\x92\xc4\x01X\x2A", 5) == "[null,42]");
|
||||
}
|
||||
|
||||
SECTION("bin 16") {
|
||||
REQUIRE(msgPackToJson("\x92\xc5\x00\x01X\x2A", 6) == "[null,42]");
|
||||
}
|
||||
|
||||
SECTION("bin 32") {
|
||||
REQUIRE(msgPackToJson("\x92\xc6\x00\x00\x00\x01X\x2A", 8) == "[null,42]");
|
||||
}
|
||||
|
||||
SECTION("ext 8") {
|
||||
REQUIRE(msgPackToJson("\x92\xc7\x01\x01\x01\x2A", 6) == "[null,42]");
|
||||
}
|
||||
|
||||
SECTION("ext 16") {
|
||||
REQUIRE(msgPackToJson("\x92\xc8\x00\x01\x01\x01\x2A", 7) == "[null,42]");
|
||||
}
|
||||
|
||||
SECTION("ext 32") {
|
||||
REQUIRE(msgPackToJson("\x92\xc9\x00\x00\x00\x01\x01\x01\x2A", 9) ==
|
||||
"[null,42]");
|
||||
}
|
||||
|
||||
SECTION("fixext 1") {
|
||||
REQUIRE(msgPackToJson("\x92\xd4\x01\x01\x2A", 5) == "[null,42]");
|
||||
}
|
||||
|
||||
SECTION("fixext 2") {
|
||||
REQUIRE(msgPackToJson("\x92\xd5\x01\x01\x02\x2A", 6) == "[null,42]");
|
||||
}
|
||||
|
||||
SECTION("fixext 4") {
|
||||
REQUIRE(msgPackToJson("\x92\xd6\x01\x01\x02\x03\x04\x2A", 8) ==
|
||||
"[null,42]");
|
||||
}
|
||||
|
||||
SECTION("fixext 8") {
|
||||
REQUIRE(msgPackToJson("\x92\xd7\x01\x01\x02\x03\x04\x05\x06\x07\x08\x2A",
|
||||
12) == "[null,42]");
|
||||
}
|
||||
|
||||
SECTION("fixext 16") {
|
||||
REQUIRE(msgPackToJson("\x92\xd8\x01\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A"
|
||||
"\x0B\x0C\x0D\x0E"
|
||||
"\x0F\x10\x2A",
|
||||
20) == "[null,42]");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("deserializeMsgPack() returns NoMemory is string length overflows") {
|
||||
JsonDocument doc;
|
||||
auto maxLength = ArduinoJson::detail::StringNode::maxLength;
|
||||
|
||||
SECTION("max length should succeed") {
|
||||
auto len = maxLength;
|
||||
std::string prefix = {'\xdb', char(len >> 24), char(len >> 16),
|
||||
char(len >> 8), char(len)};
|
||||
|
||||
auto err = deserializeMsgPack(doc, prefix + std::string(len, 'a'));
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
}
|
||||
|
||||
SECTION("one above max length should fail") {
|
||||
auto len = maxLength + 1;
|
||||
std::string prefix = {'\xdb', char(len >> 24), char(len >> 16),
|
||||
char(len >> 8), char(len)};
|
||||
|
||||
auto err = deserializeMsgPack(doc, prefix + std::string(len, 'a'));
|
||||
DeserializationError err = deserializeMsgPack(doc, "\xC4\x01X", 3);
|
||||
REQUIRE(err == DeserializationError::NoMemory);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "CustomReader.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
using ArduinoJson::detail::sizeofObject;
|
||||
|
||||
@@ -21,8 +22,7 @@ TEST_CASE("deserializeMsgPack(const std::string&)") {
|
||||
}
|
||||
|
||||
SECTION("should accept temporary string") {
|
||||
DeserializationError err =
|
||||
deserializeMsgPack(doc, std::string("\x92\x01\x02"));
|
||||
DeserializationError err = deserializeMsgPack(doc, "\x92\x01\x02"_s);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
}
|
||||
@@ -35,12 +35,11 @@ TEST_CASE("deserializeMsgPack(const std::string&)") {
|
||||
|
||||
JsonArray array = doc.as<JsonArray>();
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(std::string("hello") == array[0]);
|
||||
REQUIRE("hello"_s == array[0]);
|
||||
}
|
||||
|
||||
SECTION("should accept a zero in input") {
|
||||
DeserializationError err =
|
||||
deserializeMsgPack(doc, std::string("\x92\x00\x02", 3));
|
||||
DeserializationError err = deserializeMsgPack(doc, "\x92\x00\x02"_s);
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
JsonArray arr = doc.as<JsonArray>();
|
||||
@@ -53,7 +52,7 @@ TEST_CASE("deserializeMsgPack(std::istream&)") {
|
||||
JsonDocument doc;
|
||||
|
||||
SECTION("should accept a zero in input") {
|
||||
std::istringstream input(std::string("\x92\x00\x02", 3));
|
||||
std::istringstream input("\x92\x00\x02"_s);
|
||||
|
||||
DeserializationError err = deserializeMsgPack(doc, input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user