forked from bblanchon/ArduinoJson
Added conversion from JsonArray/JsonObject to bool
This commit is contained in:
@ -5,6 +5,7 @@ HEAD
|
|||||||
----
|
----
|
||||||
|
|
||||||
* Added support for custom writer classes (issue #1088)
|
* Added support for custom writer classes (issue #1088)
|
||||||
|
* Added conversion from `JsonArray` and `JsonObject` to `bool`, to be consistent with `JsonVariant`
|
||||||
|
|
||||||
v6.12.0 (2019-09-05)
|
v6.12.0 (2019-09-05)
|
||||||
-------
|
-------
|
||||||
|
@ -6,29 +6,53 @@
|
|||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
|
|
||||||
TEST_CASE("JsonArray::isNull()") {
|
TEST_CASE("JsonArray::isNull()") {
|
||||||
DynamicJsonDocument doc(4096);
|
|
||||||
|
|
||||||
SECTION("returns true") {
|
SECTION("returns true") {
|
||||||
JsonArray arr;
|
JsonArray arr;
|
||||||
REQUIRE(arr.isNull() == true);
|
REQUIRE(arr.isNull() == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("returns false") {
|
SECTION("returns false") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
JsonArray arr = doc.to<JsonArray>();
|
JsonArray arr = doc.to<JsonArray>();
|
||||||
REQUIRE(arr.isNull() == false);
|
REQUIRE(arr.isNull() == false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("JsonArrayConst::isNull()") {
|
TEST_CASE("JsonArrayConst::isNull()") {
|
||||||
DynamicJsonDocument doc(4096);
|
|
||||||
|
|
||||||
SECTION("returns true") {
|
SECTION("returns true") {
|
||||||
JsonArrayConst arr;
|
JsonArrayConst arr;
|
||||||
REQUIRE(arr.isNull() == true);
|
REQUIRE(arr.isNull() == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("returns false") {
|
SECTION("returns false") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
JsonArrayConst arr = doc.to<JsonArray>();
|
JsonArrayConst arr = doc.to<JsonArray>();
|
||||||
REQUIRE(arr.isNull() == false);
|
REQUIRE(arr.isNull() == false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("JsonArray::operator bool()") {
|
||||||
|
SECTION("returns false") {
|
||||||
|
JsonArray arr;
|
||||||
|
REQUIRE(static_cast<bool>(arr) == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("returns true") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
JsonArray arr = doc.to<JsonArray>();
|
||||||
|
REQUIRE(static_cast<bool>(arr) == true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("JsonArrayConst::operator bool()") {
|
||||||
|
SECTION("returns false") {
|
||||||
|
JsonArrayConst arr;
|
||||||
|
REQUIRE(static_cast<bool>(arr) == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("returns true") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
JsonArrayConst arr = doc.to<JsonArray>();
|
||||||
|
REQUIRE(static_cast<bool>(arr) == true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,29 +6,53 @@
|
|||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
|
|
||||||
TEST_CASE("JsonObject::isNull()") {
|
TEST_CASE("JsonObject::isNull()") {
|
||||||
DynamicJsonDocument doc(4096);
|
|
||||||
|
|
||||||
SECTION("returns true") {
|
SECTION("returns true") {
|
||||||
JsonObject obj;
|
JsonObject obj;
|
||||||
REQUIRE(obj.isNull() == true);
|
REQUIRE(obj.isNull() == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("returns false") {
|
SECTION("returns false") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
JsonObject obj = doc.to<JsonObject>();
|
JsonObject obj = doc.to<JsonObject>();
|
||||||
REQUIRE(obj.isNull() == false);
|
REQUIRE(obj.isNull() == false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("JsonObjectConst::isNull()") {
|
TEST_CASE("JsonObjectConst::isNull()") {
|
||||||
DynamicJsonDocument doc(4096);
|
|
||||||
|
|
||||||
SECTION("returns true") {
|
SECTION("returns true") {
|
||||||
JsonObjectConst obj;
|
JsonObjectConst obj;
|
||||||
REQUIRE(obj.isNull() == true);
|
REQUIRE(obj.isNull() == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("returns false") {
|
SECTION("returns false") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
JsonObjectConst obj = doc.to<JsonObject>();
|
JsonObjectConst obj = doc.to<JsonObject>();
|
||||||
REQUIRE(obj.isNull() == false);
|
REQUIRE(obj.isNull() == false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("JsonObject::operator bool()") {
|
||||||
|
SECTION("returns false") {
|
||||||
|
JsonObject obj;
|
||||||
|
REQUIRE(static_cast<bool>(obj) == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("returns true") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
JsonObject obj = doc.to<JsonObject>();
|
||||||
|
REQUIRE(static_cast<bool>(obj) == true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("JsonObjectConst::operator bool()") {
|
||||||
|
SECTION("returns false") {
|
||||||
|
JsonObjectConst obj;
|
||||||
|
REQUIRE(static_cast<bool>(obj) == false);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("returns true") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
JsonObjectConst obj = doc.to<JsonObject>();
|
||||||
|
REQUIRE(static_cast<bool>(obj) == true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -36,6 +36,10 @@ class ArrayRefBase {
|
|||||||
return _data == 0;
|
return _data == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FORCE_INLINE operator bool() const {
|
||||||
|
return _data != 0;
|
||||||
|
}
|
||||||
|
|
||||||
FORCE_INLINE size_t memoryUsage() const {
|
FORCE_INLINE size_t memoryUsage() const {
|
||||||
return _data ? _data->memoryUsage() : 0;
|
return _data ? _data->memoryUsage() : 0;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,10 @@ class ObjectRefBase {
|
|||||||
return _data == 0;
|
return _data == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FORCE_INLINE operator bool() const {
|
||||||
|
return _data != 0;
|
||||||
|
}
|
||||||
|
|
||||||
FORCE_INLINE size_t memoryUsage() const {
|
FORCE_INLINE size_t memoryUsage() const {
|
||||||
return _data ? _data->memoryUsage() : 0;
|
return _data ? _data->memoryUsage() : 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user