diff --git a/extras/tests/JsonVariant/CMakeLists.txt b/extras/tests/JsonVariant/CMakeLists.txt index 134c6751..78f810e1 100644 --- a/extras/tests/JsonVariant/CMakeLists.txt +++ b/extras/tests/JsonVariant/CMakeLists.txt @@ -8,8 +8,8 @@ add_executable(JsonVariantTests clear.cpp compare.cpp containsKey.cpp - copy.cpp converters.cpp + copy.cpp createNested.cpp is.cpp isnull.cpp @@ -20,6 +20,7 @@ add_executable(JsonVariantTests overflow.cpp remove.cpp set.cpp + size.cpp subscript.cpp types.cpp unbound.cpp diff --git a/extras/tests/JsonVariant/size.cpp b/extras/tests/JsonVariant/size.cpp new file mode 100644 index 00000000..a08aaead --- /dev/null +++ b/extras/tests/JsonVariant/size.cpp @@ -0,0 +1,44 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2022, Benoit BLANCHON +// MIT License + +#include +#include + +TEST_CASE("JsonVariant::size()") { + DynamicJsonDocument doc(4096); + JsonVariant variant = doc.to(); + + 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); + } + + SECTION("linked object") { + StaticJsonDocument<1024> doc2; + doc2["hello"] = "world"; + variant.link(doc2); + + CHECK(variant.size() == 1); + } +}