From 070cd5b6c0f29912deca7f462ec64905f6d062a7 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Fri, 1 Feb 2019 11:28:27 +0100 Subject: [PATCH] Added more tests of JsonVariant::is() --- examples/ProgmemExample/ProgmemExample.ino | 2 +- test/JsonVariant/is.cpp | 12 ++++ test/JsonVariant/undefined.cpp | 70 ++++++++++++++++------ 3 files changed, 64 insertions(+), 20 deletions(-) diff --git a/examples/ProgmemExample/ProgmemExample.ino b/examples/ProgmemExample/ProgmemExample.ino index 4de5347a..6c899faa 100644 --- a/examples/ProgmemExample/ProgmemExample.ino +++ b/examples/ProgmemExample/ProgmemExample.ino @@ -17,7 +17,7 @@ void setup() { DynamicJsonDocument doc(1024); // You can use a Flash String as your JSON input. - // WARNING: the string in the input will be duplicated in the JsonDocument. + // WARNING: the strings in the input will be duplicated in the JsonDocument. deserializeJson(doc, F("{\"sensor\":\"gps\",\"time\":1351824120," "\"data\":[48.756080,2.302038]}")); JsonObject obj = doc.as(); diff --git a/test/JsonVariant/is.cpp b/test/JsonVariant/is.cpp index b9e17b77..c0e91d13 100644 --- a/test/JsonVariant/is.cpp +++ b/test/JsonVariant/is.cpp @@ -147,4 +147,16 @@ TEST_CASE("JsonVariant::is()") { SECTION("string") { testString("42"); } + + SECTION("null") { + DynamicJsonDocument doc(4096); + deserializeJson(doc, "[null]"); + JsonVariant v = doc[0]; + + REQUIRE(v.is() == false); + REQUIRE(v.is() == false); + REQUIRE(v.is() == false); + REQUIRE(v.is() == false); + REQUIRE(v.is() == false); + } } diff --git a/test/JsonVariant/undefined.cpp b/test/JsonVariant/undefined.cpp index 1e8fbf87..b27f3278 100644 --- a/test/JsonVariant/undefined.cpp +++ b/test/JsonVariant/undefined.cpp @@ -8,31 +8,63 @@ TEST_CASE("JsonVariant undefined") { JsonVariant variant; - SECTION("as()") { - REQUIRE(0 == variant.as()); + SECTION("as()") { + SECTION("long") { + REQUIRE(variant.as() == 0); + } + + SECTION("unsigned") { + REQUIRE(variant.as() == 0); + } + + SECTION("char*") { + REQUIRE(variant.as() == 0); + } + + SECTION("double") { + REQUIRE(variant.as() == 0); + } + + SECTION("bool") { + REQUIRE(variant.as() == false); + } + + SECTION("JsonArray") { + REQUIRE(variant.as().isNull()); + } + + SECTION("JsonObject") { + REQUIRE(variant.as().isNull()); + } } - SECTION("as()") { - REQUIRE(0 == variant.as()); - } + SECTION("is()") { + SECTION("long") { + REQUIRE(variant.is() == false); + } - SECTION("as()") { - REQUIRE(0 == variant.as()); - } + SECTION("unsigned") { + REQUIRE(variant.is() == false); + } - SECTION("as()") { - REQUIRE(0 == variant.as()); - } + SECTION("char*") { + REQUIRE(variant.is() == false); + } - SECTION("as()") { - REQUIRE(false == variant.as()); - } + SECTION("double") { + REQUIRE(variant.is() == false); + } - SECTION("as()") { - REQUIRE(variant.as().isNull()); - } + SECTION("bool") { + REQUIRE(variant.is() == false); + } - SECTION("as()") { - REQUIRE(variant.as().isNull()); + SECTION("JsonArray") { + REQUIRE(variant.is() == false); + } + + SECTION("JsonObject") { + REQUIRE(variant.is() == false); + } } }