Add more tests for JsonObjectConst

This commit is contained in:
Benoit Blanchon
2024-01-08 18:48:11 +01:00
parent 44d2d47863
commit 08cac13c43
15 changed files with 281 additions and 89 deletions

View File

@ -15,12 +15,6 @@ TEST_CASE("JsonObject::containsKey()") {
REQUIRE(true == obj.containsKey("hello"));
}
SECTION("works with JsonObjectConst") {
JsonObjectConst cobj = obj;
REQUIRE(false == cobj.containsKey("world"));
REQUIRE(true == cobj.containsKey("hello"));
}
SECTION("returns false after remove()") {
obj.remove("hello");

View File

@ -8,18 +8,15 @@
TEST_CASE("JsonObject::operator==()") {
JsonDocument doc1;
JsonObject obj1 = doc1.to<JsonObject>();
JsonObjectConst obj1c = obj1;
JsonDocument doc2;
JsonObject obj2 = doc2.to<JsonObject>();
JsonObjectConst obj2c = obj2;
SECTION("should return false when objs differ") {
obj1["hello"] = "coucou";
obj2["world"] = 1;
REQUIRE_FALSE(obj1 == obj2);
REQUIRE_FALSE(obj1c == obj2c);
}
SECTION("should return false when LHS has more elements") {
@ -28,7 +25,6 @@ TEST_CASE("JsonObject::operator==()") {
obj2["hello"] = "coucou";
REQUIRE_FALSE(obj1 == obj2);
REQUIRE_FALSE(obj1c == obj2c);
}
SECTION("should return false when RKS has more elements") {
@ -37,7 +33,6 @@ TEST_CASE("JsonObject::operator==()") {
obj2["world"] = 666;
REQUIRE_FALSE(obj1 == obj2);
REQUIRE_FALSE(obj1c == obj2c);
}
SECTION("should return true when objs equal") {
@ -48,20 +43,17 @@ TEST_CASE("JsonObject::operator==()") {
obj2["hello"] = "world";
REQUIRE(obj1 == obj2);
REQUIRE(obj1c == obj2c);
}
SECTION("should return false when RHS is null") {
JsonObject null;
REQUIRE_FALSE(obj1 == null);
REQUIRE_FALSE(obj1c == null);
}
SECTION("should return false when LHS is null") {
JsonObject null;
REQUIRE_FALSE(null == obj2);
REQUIRE_FALSE(null == obj2c);
}
}

View File

@ -18,19 +18,6 @@ TEST_CASE("JsonObject::isNull()") {
}
}
TEST_CASE("JsonObjectConst::isNull()") {
SECTION("returns true") {
JsonObjectConst obj;
REQUIRE(obj.isNull() == true);
}
SECTION("returns false") {
JsonDocument doc;
JsonObjectConst obj = doc.to<JsonObject>();
REQUIRE(obj.isNull() == false);
}
}
TEST_CASE("JsonObject::operator bool()") {
SECTION("returns false") {
JsonObject obj;
@ -43,16 +30,3 @@ TEST_CASE("JsonObject::operator bool()") {
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") {
JsonDocument doc;
JsonObjectConst obj = doc.to<JsonObject>();
REQUIRE(static_cast<bool>(obj) == true);
}
}

View File

@ -5,8 +5,6 @@
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace Catch::Matchers;
TEST_CASE("JsonObject::begin()/end()") {
JsonDocument doc;
JsonObject obj = doc.to<JsonObject>();
@ -36,38 +34,3 @@ TEST_CASE("JsonObject::begin()/end()") {
REQUIRE(null.begin() == null.end());
}
}
TEST_CASE("JsonObjectConst::begin()/end()") {
JsonDocument doc;
JsonObject obj = doc.to<JsonObject>();
obj["ab"] = 12;
obj["cd"] = 34;
JsonObjectConst cobj = obj;
SECTION("Iteration") {
JsonObjectConst::iterator it = cobj.begin();
REQUIRE(cobj.end() != it);
REQUIRE(it->key() == "ab");
REQUIRE(12 == it->value());
++it;
REQUIRE(cobj.end() != it);
JsonPairConst pair = *it;
REQUIRE(pair.key() == "cd");
REQUIRE(34 == pair.value());
++it;
REQUIRE(cobj.end() == it);
}
SECTION("Dereferencing end() is safe") {
REQUIRE(cobj.end()->key().isNull());
REQUIRE(cobj.end()->value().isNull());
}
SECTION("null JsonObjectConst") {
JsonObjectConst null;
REQUIRE(null.begin() == null.end());
}
}

View File

@ -7,8 +7,6 @@
#include "Allocators.hpp"
using ArduinoJson::detail::sizeofObject;
TEST_CASE("JsonObject::operator[]") {
SpyingAllocator spy;
JsonDocument doc(&spy);
@ -252,11 +250,3 @@ TEST_CASE("JsonObject::operator[]") {
REQUIRE(false == obj["hello"]["world"].is<bool>());
}
}
TEST_CASE("JsonObjectConst::operator[]") {
JsonDocument doc;
doc["hello"] = "world";
JsonObjectConst obj = doc.as<JsonObjectConst>();
REQUIRE(obj["hello"] == "world"); // issue #2019
}