From 0214c9bcadf9261757eca379169a8f8b83b5d4a2 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sun, 23 Feb 2020 13:03:14 +0100 Subject: [PATCH] Improved coverage of JsonObject --- extras/tests/JsonObject/copy.cpp | 18 ++++++++++++++++++ extras/tests/JsonObject/equals.cpp | 14 ++++++++++++++ extras/tests/JsonObject/iterator.cpp | 10 ++++++++++ extras/tests/JsonObject/remove.cpp | 5 +++++ 4 files changed, 47 insertions(+) diff --git a/extras/tests/JsonObject/copy.cpp b/extras/tests/JsonObject/copy.cpp index 74e4b91e..a78c7e74 100644 --- a/extras/tests/JsonObject/copy.cpp +++ b/extras/tests/JsonObject/copy.cpp @@ -94,4 +94,22 @@ TEST_CASE("JsonObject::set()") { REQUIRE(success == false); REQUIRE(doc3.as() == "{\"hello\":null}"); } + + SECTION("destination is null") { + JsonObject null; + obj1["hello"] = "world"; + + bool success = null.set(obj1); + + REQUIRE(success == false); + } + + SECTION("source is null") { + JsonObject null; + obj1["hello"] = "world"; + + bool success = obj1.set(null); + + REQUIRE(success == false); + } } diff --git a/extras/tests/JsonObject/equals.cpp b/extras/tests/JsonObject/equals.cpp index eae3ba76..a04c37b9 100644 --- a/extras/tests/JsonObject/equals.cpp +++ b/extras/tests/JsonObject/equals.cpp @@ -50,4 +50,18 @@ TEST_CASE("JsonObject::operator==()") { 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); + } } diff --git a/extras/tests/JsonObject/iterator.cpp b/extras/tests/JsonObject/iterator.cpp index 49741e5d..24cd9b2c 100644 --- a/extras/tests/JsonObject/iterator.cpp +++ b/extras/tests/JsonObject/iterator.cpp @@ -30,6 +30,11 @@ TEST_CASE("JsonObject::begin()/end()") { REQUIRE(obj.end()->key().isNull()); REQUIRE(obj.end()->value().isNull()); } + + SECTION("null JsonObject") { + JsonObject null; + REQUIRE(null.begin() == null.end()); + } } TEST_CASE("JsonObjectConst::begin()/end()") { @@ -60,4 +65,9 @@ TEST_CASE("JsonObjectConst::begin()/end()") { REQUIRE(cobj.end()->key().isNull()); REQUIRE(cobj.end()->value().isNull()); } + + SECTION("null JsonObjectConst") { + JsonObjectConst null; + REQUIRE(null.begin() == null.end()); + } } diff --git a/extras/tests/JsonObject/remove.cpp b/extras/tests/JsonObject/remove.cpp index f8ff97d9..dde57144 100644 --- a/extras/tests/JsonObject/remove.cpp +++ b/extras/tests/JsonObject/remove.cpp @@ -69,4 +69,9 @@ TEST_CASE("JsonObject::remove()") { REQUIRE("{\"a\":0,\"c\":2}" == result); } #endif + + SECTION("should work on null object") { + JsonObject null; + null.remove("key"); + } }