Support JsonDocument*

This commit is contained in:
Benoit Blanchon
2022-03-10 13:50:33 +01:00
parent c584966520
commit 0bcf14bb89
2 changed files with 25 additions and 0 deletions

View File

@@ -43,4 +43,24 @@ TEST_CASE("JsonVariant::add()") {
REQUIRE(var.as<std::string>() == "{\"val\":123}");
}
SECTION("add JsonDocument to new variant") {
StaticJsonDocument<128> doc2;
doc2["hello"] = "world";
var.add(doc2);
CHECK(var.as<std::string>() == "[{\"hello\":\"world\"}]");
CHECK(var.memoryUsage() == JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(1));
}
SECTION("add JsonDocument* to new variant") {
StaticJsonDocument<128> doc2;
doc2["hello"] = "world";
var.add(&doc2);
CHECK(var.as<std::string>() == "[{\"hello\":\"world\"}]");
CHECK(var.memoryUsage() == JSON_ARRAY_SIZE(1));
}
}