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:
iranl
2024-08-11 11:20:31 +02:00
committed by GitHub
parent 4af90cbc79
commit 9d55c2173d
216 changed files with 6437 additions and 5705 deletions

View File

@@ -5,6 +5,8 @@
#include <ArduinoJson.h>
#include <catch.hpp>
#include "Literals.hpp"
typedef ArduinoJson::detail::ElementProxy<JsonDocument&> ElementProxy;
TEST_CASE("ElementProxy::add()") {
@@ -121,7 +123,7 @@ TEST_CASE("ElementProxy::remove()") {
ep["a"] = 1;
ep["b"] = 2;
ep.remove(std::string("b"));
ep.remove("b"_s);
REQUIRE(ep.as<std::string>() == "{\"a\":1}");
}

View File

@@ -9,6 +9,7 @@
#include <catch.hpp>
#include "Allocators.hpp"
#include "Literals.hpp"
using ArduinoJson::detail::sizeofArray;
using ArduinoJson::detail::sizeofObject;
@@ -106,8 +107,8 @@ TEST_CASE("MemberProxy::containsKey()") {
SECTION("containsKey(std::string)") {
mp["key"] = "value";
REQUIRE(mp.containsKey(std::string("key")) == true);
REQUIRE(mp.containsKey(std::string("key")) == true);
REQUIRE(mp.containsKey("key"_s) == true);
REQUIRE(mp.containsKey("key"_s) == true);
}
}
@@ -117,8 +118,8 @@ TEST_CASE("MemberProxy::operator|()") {
SECTION("const char*") {
doc["a"] = "hello";
REQUIRE((doc["a"] | "world") == std::string("hello"));
REQUIRE((doc["b"] | "world") == std::string("world"));
REQUIRE((doc["a"] | "world") == "hello"_s);
REQUIRE((doc["b"] | "world") == "world"_s);
}
SECTION("Issue #1411") {
@@ -128,7 +129,7 @@ TEST_CASE("MemberProxy::operator|()") {
// to trigger the bug
const char* sensor = doc["sensor"] | test; // "gps"
REQUIRE(sensor == std::string("gps"));
REQUIRE(sensor == "gps"_s);
}
SECTION("Issue #1415") {
@@ -170,7 +171,7 @@ TEST_CASE("MemberProxy::remove()") {
mp["a"] = 1;
mp["b"] = 2;
mp.remove(std::string("b"));
mp.remove("b"_s);
REQUIRE(mp.as<std::string>() == "{\"a\":1}");
}
@@ -286,8 +287,8 @@ TEST_CASE("Deduplicate keys") {
JsonDocument doc(&spy);
SECTION("std::string") {
doc[0][std::string("example")] = 1;
doc[1][std::string("example")] = 2;
doc[0]["example"_s] = 1;
doc[1]["example"_s] = 2;
const char* key1 = doc[0].as<JsonObject>().begin()->key().c_str();
const char* key2 = doc[1].as<JsonObject>().begin()->key().c_str();
@@ -351,7 +352,7 @@ TEST_CASE("MemberProxy under memory constraints") {
SECTION("key allocation fails") {
killswitch.on();
doc[std::string("hello")] = "world";
doc["hello"_s] = "world";
REQUIRE(doc.is<JsonObject>());
REQUIRE(doc.size() == 0);

View File

@@ -9,6 +9,7 @@
#include <catch.hpp>
#include "Allocators.hpp"
#include "Literals.hpp"
using ArduinoJson::detail::sizeofArray;
@@ -35,8 +36,8 @@ TEST_CASE("JsonDocument::add(T)") {
}
SECTION("std::string") {
doc.add(std::string("example"));
doc.add(std::string("example"));
doc.add("example"_s);
doc.add("example"_s);
CHECK(doc[0].as<const char*>() == doc[1].as<const char*>());
REQUIRE(spy.log() == AllocatorLog{
@@ -90,15 +91,57 @@ TEST_CASE("JsonDocument::add<T>()") {
REQUIRE(doc.as<std::string>() == "[[1,2]]");
}
SECTION("JsonObject") {
JsonObject object = doc.add<JsonObject>();
object["hello"] = "world";
REQUIRE(doc.as<std::string>() == "[{\"hello\":\"world\"}]");
}
SECTION("JsonVariant") {
JsonVariant variant = doc.add<JsonVariant>();
variant.set(42);
REQUIRE(doc.as<std::string>() == "[42]");
}
}
TEST_CASE("JsonObject::add(JsonObject) ") {
JsonDocument doc1;
doc1["hello"_s] = "world"_s;
TimebombAllocator allocator(10);
SpyingAllocator spy(&allocator);
JsonDocument doc2(&spy);
SECTION("success") {
bool result = doc2.add(doc1.as<JsonObject>());
REQUIRE(result == true);
REQUIRE(doc2.as<std::string>() == "[{\"hello\":\"world\"}]");
REQUIRE(spy.log() == AllocatorLog{
Allocate(sizeofPool()),
Allocate(sizeofString("hello")),
Allocate(sizeofString("world")),
});
}
SECTION("partial failure") { // issue #2081
allocator.setCountdown(2);
bool result = doc2.add(doc1.as<JsonObject>());
REQUIRE(result == false);
REQUIRE(doc2.as<std::string>() == "[]");
REQUIRE(spy.log() == AllocatorLog{
Allocate(sizeofPool()),
Allocate(sizeofString("hello")),
AllocateFail(sizeofString("world")),
Deallocate(sizeofString("hello")),
});
}
SECTION("complete failure") {
allocator.setCountdown(0);
bool result = doc2.add(doc1.as<JsonObject>());
REQUIRE(result == false);
REQUIRE(doc2.as<std::string>() == "[]");
REQUIRE(spy.log() == AllocatorLog{
AllocateFail(sizeofPool()),
});
}
}

View File

@@ -6,6 +6,7 @@
#include <catch.hpp>
#include "Allocators.hpp"
#include "Literals.hpp"
TEST_CASE("JsonDocument assignment") {
SpyingAllocator spyingAllocator;
@@ -62,7 +63,7 @@ TEST_CASE("JsonDocument assignment") {
SECTION("Move assign") {
{
JsonDocument doc1(&spyingAllocator);
doc1[std::string("hello")] = std::string("world");
doc1["hello"_s] = "world"_s;
JsonDocument doc2(&spyingAllocator);
doc2 = std::move(doc1);

View File

@@ -9,6 +9,7 @@
#include <string>
#include "Allocators.hpp"
#include "Literals.hpp"
TEST_CASE("JsonDocument::clear()") {
SpyingAllocator spy;
@@ -22,7 +23,7 @@ TEST_CASE("JsonDocument::clear()") {
}
SECTION("releases resources") {
doc[std::string("hello")] = std::string("world");
doc["hello"_s] = "world"_s;
spy.clearLog();
doc.clear();

View File

@@ -6,6 +6,7 @@
#include <catch.hpp>
#include "Allocators.hpp"
#include "Literals.hpp"
using ArduinoJson::detail::addPadding;
@@ -20,7 +21,7 @@ TEST_CASE("JsonDocument constructor") {
SECTION("JsonDocument(const JsonDocument&)") {
{
JsonDocument doc1(&spyingAllocator);
doc1.set(std::string("The size of this string is 32!!"));
doc1.set("The size of this string is 32!!"_s);
JsonDocument doc2(doc1);
@@ -38,7 +39,7 @@ TEST_CASE("JsonDocument constructor") {
SECTION("JsonDocument(JsonDocument&&)") {
{
JsonDocument doc1(&spyingAllocator);
doc1.set(std::string("The size of this string is 32!!"));
doc1.set("The size of this string is 32!!"_s);
JsonDocument doc2(std::move(doc1));
@@ -117,4 +118,31 @@ TEST_CASE("JsonDocument constructor") {
REQUIRE(doc2.as<std::string>() == "hello");
}
SECTION("JsonDocument(JsonVariantConst)") {
JsonDocument doc1;
deserializeJson(doc1, "\"hello\"");
JsonDocument doc2(doc1.as<JsonVariantConst>());
REQUIRE(doc2.as<std::string>() == "hello");
}
SECTION("JsonDocument(ElementProxy)") {
JsonDocument doc1;
deserializeJson(doc1, "[\"hello\",\"world\"]");
JsonDocument doc2(doc1[1]);
REQUIRE(doc2.as<std::string>() == "world");
}
SECTION("JsonDocument(MemberProxy)") {
JsonDocument doc1;
deserializeJson(doc1, "{\"hello\":\"world\"}");
JsonDocument doc2(doc1["hello"]);
REQUIRE(doc2.as<std::string>() == "world");
}
}

View File

@@ -5,6 +5,8 @@
#include <ArduinoJson.h>
#include <catch.hpp>
#include "Literals.hpp"
TEST_CASE("JsonDocument::containsKey()") {
JsonDocument doc;
@@ -23,7 +25,7 @@ TEST_CASE("JsonDocument::containsKey()") {
SECTION("returns true when key is a std::string") {
doc["hello"] = "world";
REQUIRE(doc.containsKey(std::string("hello")) == true);
REQUIRE(doc.containsKey("hello"_s) == true);
}
SECTION("returns false on object") {
@@ -41,4 +43,12 @@ TEST_CASE("JsonDocument::containsKey()") {
SECTION("returns false on null") {
REQUIRE(doc.containsKey("hello") == false);
}
SECTION("support JsonVariant") {
doc["hello"] = "world";
doc["key"] = "hello";
REQUIRE(doc.containsKey(doc["key"]) == true);
REQUIRE(doc.containsKey(doc["foo"]) == false);
}
}

View File

@@ -2,6 +2,8 @@
#include <catch.hpp>
#include "Literals.hpp"
TEST_CASE("Issue #1120") {
JsonDocument doc;
constexpr char str[] =
@@ -10,12 +12,12 @@ TEST_CASE("Issue #1120") {
SECTION("MemberProxy<std::string>::isNull()") {
SECTION("returns false") {
auto value = doc[std::string("contents")];
auto value = doc["contents"_s];
CHECK(value.isNull() == false);
}
SECTION("returns true") {
auto value = doc[std::string("zontents")];
auto value = doc["zontents"_s];
CHECK(value.isNull() == true);
}
}
@@ -46,12 +48,12 @@ TEST_CASE("Issue #1120") {
SECTION("MemberProxy<ElementProxy<MemberProxy>, std::string>::isNull()") {
SECTION("returns false") {
auto value = doc["contents"][1][std::string("module")];
auto value = doc["contents"][1]["module"_s];
CHECK(value.isNull() == false);
}
SECTION("returns true") {
auto value = doc["contents"][1][std::string("zodule")];
auto value = doc["contents"][1]["zodule"_s];
CHECK(value.isNull() == true);
}
}

View File

@@ -6,6 +6,7 @@
#include <catch.hpp>
#include "Allocators.hpp"
#include "Literals.hpp"
TEST_CASE("JsonDocument::overflowed()") {
TimebombAllocator timebomb(10);
@@ -30,13 +31,13 @@ TEST_CASE("JsonDocument::overflowed()") {
SECTION("returns true after a failed string copy") {
timebomb.setCountdown(0);
doc.add(std::string("example"));
doc.add("example"_s);
CHECK(doc.overflowed() == true);
}
SECTION("returns false after a successful string copy") {
timebomb.setCountdown(3);
doc.add(std::string("example"));
doc.add("example"_s);
CHECK(doc.overflowed() == false);
}

View File

@@ -5,6 +5,8 @@
#include <ArduinoJson.h>
#include <catch.hpp>
#include "Literals.hpp"
TEST_CASE("JsonDocument::remove()") {
JsonDocument doc;
@@ -31,7 +33,7 @@ TEST_CASE("JsonDocument::remove()") {
doc["a"] = 1;
doc["b"] = 2;
doc.remove(std::string("b"));
doc.remove("b"_s);
REQUIRE(doc.as<std::string>() == "{\"a\":1}");
}
@@ -49,4 +51,25 @@ TEST_CASE("JsonDocument::remove()") {
REQUIRE(doc.as<std::string>() == "{\"a\":1}");
}
#endif
SECTION("remove(JsonVariant) from object") {
doc["a"] = 1;
doc["b"] = 2;
doc["c"] = "b";
doc.remove(doc["c"]);
REQUIRE(doc.as<std::string>() == "{\"a\":1,\"c\":\"b\"}");
}
SECTION("remove(JsonVariant) from array") {
doc[0] = 3;
doc[1] = 2;
doc[2] = 1;
doc.remove(doc[2]);
doc.remove(doc[3]); // noop
REQUIRE(doc.as<std::string>() == "[3,1]");
}
}

View File

@@ -9,6 +9,7 @@
#include <string>
#include "Allocators.hpp"
#include "Literals.hpp"
using ArduinoJson::detail::sizeofArray;
using ArduinoJson::detail::sizeofObject;
@@ -78,7 +79,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") {
}
SECTION("owned string") {
doc.set(std::string("abcdefg"));
doc.set("abcdefg"_s);
REQUIRE(doc.as<std::string>() == "abcdefg");
doc.shrinkToFit();
@@ -114,7 +115,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") {
}
SECTION("owned key") {
doc[std::string("abcdefg")] = 42;
doc["abcdefg"_s] = 42;
doc.shrinkToFit();
@@ -141,7 +142,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") {
}
SECTION("owned string in array") {
doc.add(std::string("abcdefg"));
doc.add("abcdefg"_s);
doc.shrinkToFit();
@@ -168,7 +169,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") {
}
SECTION("owned string in object") {
doc["key"] = std::string("abcdefg");
doc["key"] = "abcdefg"_s;
doc.shrinkToFit();

View File

@@ -5,6 +5,8 @@
#include <ArduinoJson.h>
#include <catch.hpp>
#include "Literals.hpp"
TEST_CASE("JsonDocument::operator[]") {
JsonDocument doc;
const JsonDocument& cdoc = doc;
@@ -18,21 +20,35 @@ TEST_CASE("JsonDocument::operator[]") {
}
SECTION("std::string") {
REQUIRE(doc[std::string("hello")] == "world");
REQUIRE(cdoc[std::string("hello")] == "world");
REQUIRE(doc["hello"_s] == "world");
REQUIRE(cdoc["hello"_s] == "world");
}
SECTION("JsonVariant") {
doc["key"] = "hello";
REQUIRE(doc[doc["key"]] == "world");
REQUIRE(cdoc[cdoc["key"]] == "world");
}
SECTION("supports operator|") {
REQUIRE((doc["hello"] | "nope") == std::string("world"));
REQUIRE((doc["world"] | "nope") == std::string("nope"));
REQUIRE((doc["hello"] | "nope") == "world"_s);
REQUIRE((doc["world"] | "nope") == "nope"_s);
}
}
SECTION("array") {
deserializeJson(doc, "[\"hello\",\"world\"]");
REQUIRE(doc[1] == "world");
REQUIRE(cdoc[1] == "world");
SECTION("int") {
REQUIRE(doc[1] == "world");
REQUIRE(cdoc[1] == "world");
}
SECTION("JsonVariant") {
doc[2] = 1;
REQUIRE(doc[doc[2]] == "world");
REQUIRE(cdoc[doc[2]] == "world");
}
}
}