Update to ArduinoJson 7.0.4

This commit is contained in:
iranl
2024-04-19 14:44:01 +02:00
parent 1378732081
commit 81be0a689a
444 changed files with 10842 additions and 9422 deletions

View File

@@ -1,12 +1,12 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// Copyright © 2014-2024, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonVariant::operator[]") {
DynamicJsonDocument doc(4096);
JsonDocument doc;
JsonVariant var = doc.to<JsonVariant>();
SECTION("The JsonVariant is null") {
@@ -50,7 +50,7 @@ TEST_CASE("JsonVariant::operator[]") {
}
SECTION("set value in a nested object") {
array.createNestedObject();
array.add<JsonObject>();
var[0]["hello"] = "world";
@@ -130,75 +130,3 @@ TEST_CASE("JsonVariant::operator[]") {
}
#endif
}
TEST_CASE("JsonVariantConst::operator[]") {
DynamicJsonDocument doc(4096);
JsonVariant var = doc.to<JsonVariant>();
JsonVariantConst cvar = var;
SECTION("The JsonVariant is null") {
REQUIRE(0 == cvar.size());
REQUIRE(cvar["0"].isNull());
REQUIRE(cvar[0].isNull());
}
SECTION("The JsonVariant is a string") {
var.set("hello world");
REQUIRE(0 == cvar.size());
REQUIRE(cvar["0"].isNull());
REQUIRE(cvar[0].isNull());
}
SECTION("The JsonVariant is a JsonArray") {
JsonArray array = var.to<JsonArray>();
SECTION("get value") {
array.add("element at index 0");
array.add("element at index 1");
REQUIRE(2 == cvar.size());
REQUIRE(std::string("element at index 0") == cvar[0]);
REQUIRE(std::string("element at index 1") == cvar[1]);
REQUIRE(std::string("element at index 0") ==
var[static_cast<unsigned char>(0)]); // issue #381
REQUIRE(cvar[666].isNull());
REQUIRE(cvar[3].isNull());
REQUIRE(cvar["0"].isNull());
}
}
SECTION("The JsonVariant is a JsonObject") {
JsonObject object = var.to<JsonObject>();
SECTION("get value") {
object["a"] = "element at key \"a\"";
object["b"] = "element at key \"b\"";
REQUIRE(2 == cvar.size());
REQUIRE(std::string("element at key \"a\"") == cvar["a"]);
REQUIRE(std::string("element at key \"b\"") == cvar["b"]);
REQUIRE(cvar["c"].isNull());
REQUIRE(cvar[0].isNull());
}
}
SECTION("Auto promote null JsonVariant to JsonObject") {
var["hello"] = "world";
REQUIRE(var.is<JsonObject>() == true);
}
SECTION("Don't auto promote non-null JsonVariant to JsonObject") {
var.set(42);
var["hello"] = "world";
REQUIRE(var.is<JsonObject>() == false);
}
SECTION("Don't auto promote null JsonVariant to JsonObject when reading") {
const char* value = var["hello"];
REQUIRE(var.is<JsonObject>() == false);
REQUIRE(value == 0);
}
}