mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 00:38:27 +01:00
Replace with JsonVariant::link()
This commit is contained in:
@@ -8,11 +8,12 @@ add_executable(JsonVariantTests
|
||||
clear.cpp
|
||||
compare.cpp
|
||||
containsKey.cpp
|
||||
copy.cpp
|
||||
converters.cpp
|
||||
copy.cpp
|
||||
createNested.cpp
|
||||
is.cpp
|
||||
isnull.cpp
|
||||
link.cpp
|
||||
memoryUsage.cpp
|
||||
misc.cpp
|
||||
nesting.cpp
|
||||
|
||||
25
extras/tests/JsonVariant/link.cpp
Normal file
25
extras/tests/JsonVariant/link.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2022, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonVariant::link()") {
|
||||
StaticJsonDocument<1024> doc1, doc2;
|
||||
JsonVariant variant = doc1.to<JsonVariant>();
|
||||
|
||||
SECTION("JsonVariant::link(JsonDocument&)") {
|
||||
doc2["hello"] = "world";
|
||||
|
||||
variant.link(doc2.as<JsonVariant>());
|
||||
|
||||
CHECK(variant.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
CHECK(variant.memoryUsage() == 0);
|
||||
|
||||
// altering the linked document should change the result
|
||||
doc2["hello"] = "WORLD!";
|
||||
|
||||
CHECK(variant.as<std::string>() == "{\"hello\":\"WORLD!\"}");
|
||||
}
|
||||
}
|
||||
@@ -42,8 +42,8 @@ TEST_CASE("JsonVariant::memoryUsage()") {
|
||||
SECTION("ignore size of link document") {
|
||||
StaticJsonDocument<128> doc2;
|
||||
doc2["hello"] = "world";
|
||||
var.add(&doc2);
|
||||
CHECK(var.memoryUsage() == JSON_ARRAY_SIZE(1));
|
||||
var.link(doc2.as<JsonVariant>());
|
||||
CHECK(var.memoryUsage() == 0);
|
||||
CHECK(var.memoryUsage() == doc.memoryUsage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,18 +172,4 @@ TEST_CASE("Copy/link from other document") {
|
||||
|
||||
CHECK(variant.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
}
|
||||
|
||||
SECTION("JsonVariant::set(JsonDocument*)") {
|
||||
doc2["hello"] = "world";
|
||||
|
||||
variant.set(&doc2);
|
||||
|
||||
CHECK(variant.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
CHECK(variant.memoryUsage() == 0);
|
||||
|
||||
// altering the links document should change the result
|
||||
doc2["hello"] = "WORLD!";
|
||||
|
||||
CHECK(variant.as<std::string>() == "{\"hello\":\"WORLD!\"}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user