mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-15 03:26:39 +02:00
Return JsonArray
and JsonObject
by value (closes #309)
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
|
||||
TEST_CASE("JsonObject::set()") {
|
||||
DynamicJsonDocument doc;
|
||||
JsonObject& obj = doc.to<JsonObject>();
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
|
||||
SECTION("int") {
|
||||
obj.set("hello", 123);
|
||||
@ -44,29 +44,29 @@ TEST_CASE("JsonObject::set()") {
|
||||
|
||||
SECTION("nested array") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonArray& arr = doc2.to<JsonArray>();
|
||||
JsonArray arr = doc2.to<JsonArray>();
|
||||
|
||||
obj.set("hello", arr);
|
||||
|
||||
REQUIRE(&arr == &obj["hello"].as<JsonArray>());
|
||||
REQUIRE(obj["hello"].is<JsonArray&>());
|
||||
REQUIRE_FALSE(obj["hello"].is<JsonObject&>());
|
||||
REQUIRE(arr == obj["hello"].as<JsonArray>());
|
||||
REQUIRE(obj["hello"].is<JsonArray>());
|
||||
REQUIRE_FALSE(obj["hello"].is<JsonObject>());
|
||||
}
|
||||
|
||||
SECTION("nested object") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonObject& obj2 = doc2.to<JsonObject>();
|
||||
JsonObject obj2 = doc2.to<JsonObject>();
|
||||
|
||||
obj.set("hello", obj2);
|
||||
|
||||
REQUIRE(&obj2 == &obj["hello"].as<JsonObject>());
|
||||
REQUIRE(obj["hello"].is<JsonObject&>());
|
||||
REQUIRE_FALSE(obj["hello"].is<JsonArray&>());
|
||||
REQUIRE(obj2 == obj["hello"].as<JsonObject>());
|
||||
REQUIRE(obj["hello"].is<JsonObject>());
|
||||
REQUIRE_FALSE(obj["hello"].is<JsonArray>());
|
||||
}
|
||||
|
||||
SECTION("array subscript") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonArray& arr = doc2.to<JsonArray>();
|
||||
JsonArray arr = doc2.to<JsonArray>();
|
||||
arr.add(42);
|
||||
|
||||
obj.set("a", arr[0]);
|
||||
@ -76,7 +76,7 @@ TEST_CASE("JsonObject::set()") {
|
||||
|
||||
SECTION("object subscript") {
|
||||
DynamicJsonDocument doc2;
|
||||
JsonObject& obj2 = doc2.to<JsonObject>();
|
||||
JsonObject obj2 = doc2.to<JsonObject>();
|
||||
obj2.set("x", 42);
|
||||
|
||||
obj.set("a", obj2["x"]);
|
||||
@ -86,14 +86,14 @@ TEST_CASE("JsonObject::set()") {
|
||||
|
||||
SECTION("returns true when allocation succeeds") {
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(1) + 15> doc2;
|
||||
JsonObject& obj2 = doc2.to<JsonObject>();
|
||||
JsonObject obj2 = doc2.to<JsonObject>();
|
||||
|
||||
REQUIRE(true == obj2.set(std::string("hello"), std::string("world")));
|
||||
}
|
||||
|
||||
SECTION("returns false when allocation fails") {
|
||||
StaticJsonDocument<JSON_OBJECT_SIZE(1) + 10> doc2;
|
||||
JsonObject& obj2 = doc2.to<JsonObject>();
|
||||
JsonObject obj2 = doc2.to<JsonObject>();
|
||||
|
||||
REQUIRE(false == obj2.set(std::string("hello"), std::string("world")));
|
||||
}
|
||||
|
Reference in New Issue
Block a user