Added Visitable to reduce the number of definitions of operator<<

This commit is contained in:
Benoit Blanchon
2018-10-12 17:59:50 +02:00
parent b0560cbd99
commit 02d809f3f4
13 changed files with 118 additions and 102 deletions

View File

@ -6,39 +6,29 @@
#include <catch.hpp>
TEST_CASE("JsonArray::isNull()") {
SECTION("returns true for undefined JsonArray") {
JsonArray array;
REQUIRE(array.isNull() == true);
DynamicJsonDocument doc;
SECTION("returns true") {
JsonArray arr;
REQUIRE(arr.isNull() == true);
}
SECTION("returns false when allocation succeeds") {
StaticJsonDocument<JSON_ARRAY_SIZE(0)> doc;
JsonArray array = doc.to<JsonArray>();
REQUIRE(array.isNull() == false);
SECTION("returns false") {
JsonArray arr = doc.to<JsonArray>();
REQUIRE(arr.isNull() == false);
}
/* SECTION("returns true when allocation fails") {
StaticJsonDocument<1> doc;
JsonArray array = doc.to<JsonArray>();
REQUIRE(array.isNull() == true);
}*/
}
TEST_CASE("JsonArrayConst::isNull()") {
SECTION("returns true for undefined JsonArray") {
JsonArrayConst array;
REQUIRE(array.isNull() == true);
DynamicJsonDocument doc;
SECTION("returns true") {
JsonArrayConst arr;
REQUIRE(arr.isNull() == true);
}
SECTION("returns false when allocation succeeds") {
StaticJsonDocument<JSON_ARRAY_SIZE(0)> doc;
JsonArrayConst array = doc.to<JsonArray>();
REQUIRE(array.isNull() == false);
SECTION("returns false") {
JsonArrayConst arr = doc.to<JsonArray>();
REQUIRE(arr.isNull() == false);
}
/* SECTION("returns true when allocation fails") {
StaticJsonDocument<1> doc;
JsonArray array = doc.to<JsonArray>();
REQUIRE(array.isNull() == true);
}*/
}

View File

@ -6,20 +6,29 @@
#include <catch.hpp>
TEST_CASE("JsonObject::isNull()") {
SECTION("returns true for undefined JsonObject") {
JsonObject array;
REQUIRE(array.isNull() == true);
DynamicJsonDocument doc;
SECTION("returns true") {
JsonObject obj;
REQUIRE(obj.isNull() == true);
}
SECTION("returns false when allocation succeeds") {
StaticJsonDocument<JSON_OBJECT_SIZE(0)> doc;
JsonObject array = doc.to<JsonObject>();
REQUIRE(array.isNull() == false);
SECTION("returns false") {
JsonObject obj = doc.to<JsonObject>();
REQUIRE(obj.isNull() == false);
}
}
TEST_CASE("JsonObjectConst::isNull()") {
DynamicJsonDocument doc;
SECTION("returns true") {
JsonObjectConst obj;
REQUIRE(obj.isNull() == true);
}
SECTION("returns false") {
JsonObjectConst obj = doc.to<JsonObject>();
REQUIRE(obj.isNull() == false);
}
/* SECTION("returns true when allocation fails") {
StaticJsonDocument<1> doc;
JsonObject array = doc.to<JsonObject>();
REQUIRE(array.isNull() == true);
}*/
}

View File

@ -50,4 +50,19 @@ TEST_CASE("Polyfills/type_traits") {
CHECK(is_unsigned<float>::value == false);
CHECK(is_unsigned<double>::value == false);
}
SECTION("IsVisitable") {
CHECK(IsVisitable<DeserializationError>::value == false);
CHECK(IsVisitable<JsonPair>::value == false);
CHECK(IsVisitable<JsonVariant>::value == true);
CHECK(IsVisitable<JsonVariantConst>::value == true);
CHECK(IsVisitable<JsonArray>::value == true);
CHECK(IsVisitable<JsonArraySubscript>::value == true);
CHECK(IsVisitable<JsonArrayConst>::value == true);
CHECK(IsVisitable<JsonObject>::value == true);
CHECK(IsVisitable<JsonObjectSubscript<const char*> >::value == true);
CHECK(IsVisitable<JsonObjectConst>::value == true);
CHECK(IsVisitable<DynamicJsonDocument>::value == true);
CHECK(IsVisitable<StaticJsonDocument<10> >::value == true);
}
}