Files
ArduinoJson/extras/tests/JsonVariant/size.cpp
Benoit Blanchon cd8373ad32 Change link() to shallowCopy() (issue #1343)
Instead of storing a pointer, the function copies the `VariantData`.

Benefits:
* smaller code
* no impact on programs that don't use this feature

Drawbacks:
* changes to the original variant are not always reflected on the copy
* modifying the original from the shallow copy leads to UB
2022-07-05 17:07:43 +02:00

37 lines
628 B
C++

// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonVariant::size()") {
DynamicJsonDocument doc(4096);
JsonVariant variant = doc.to<JsonVariant>();
SECTION("unbound reference") {
JsonVariant unbound;
CHECK(unbound.size() == 0);
}
SECTION("int") {
variant.set(42);
CHECK(variant.size() == 0);
}
SECTION("string") {
variant.set("hello");
CHECK(variant.size() == 0);
}
SECTION("object") {
variant["a"] = 1;
variant["b"] = 2;
CHECK(variant.size() == 2);
}
}