forked from bblanchon/ArduinoJson
Add more tests for JsonArrayConst
This commit is contained in:
@ -8,18 +8,15 @@
|
||||
TEST_CASE("JsonArray::operator==()") {
|
||||
JsonDocument doc1;
|
||||
JsonArray array1 = doc1.to<JsonArray>();
|
||||
JsonArrayConst array1c = array1;
|
||||
|
||||
JsonDocument doc2;
|
||||
JsonArray array2 = doc2.to<JsonArray>();
|
||||
JsonArrayConst array2c = array2;
|
||||
|
||||
SECTION("should return false when arrays differ") {
|
||||
array1.add("coucou");
|
||||
array2.add(1);
|
||||
|
||||
REQUIRE_FALSE(array1 == array2);
|
||||
REQUIRE_FALSE(array1c == array2c);
|
||||
}
|
||||
|
||||
SECTION("should return false when LHS has more elements") {
|
||||
@ -28,7 +25,6 @@ TEST_CASE("JsonArray::operator==()") {
|
||||
array2.add(1);
|
||||
|
||||
REQUIRE_FALSE(array1 == array2);
|
||||
REQUIRE_FALSE(array1c == array2c);
|
||||
}
|
||||
|
||||
SECTION("should return false when RHS has more elements") {
|
||||
@ -37,7 +33,6 @@ TEST_CASE("JsonArray::operator==()") {
|
||||
array2.add(2);
|
||||
|
||||
REQUIRE_FALSE(array1 == array2);
|
||||
REQUIRE_FALSE(array1c == array2c);
|
||||
}
|
||||
|
||||
SECTION("should return true when arrays equal") {
|
||||
@ -45,7 +40,6 @@ TEST_CASE("JsonArray::operator==()") {
|
||||
array2.add("coucou");
|
||||
|
||||
REQUIRE(array1 == array2);
|
||||
REQUIRE(array1c == array2c);
|
||||
}
|
||||
|
||||
SECTION("should return false when RHS is null") {
|
||||
|
@ -18,19 +18,6 @@ TEST_CASE("JsonArray::isNull()") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArrayConst::isNull()") {
|
||||
SECTION("returns true") {
|
||||
JsonArrayConst arr;
|
||||
REQUIRE(arr.isNull() == true);
|
||||
}
|
||||
|
||||
SECTION("returns false") {
|
||||
JsonDocument doc;
|
||||
JsonArrayConst arr = doc.to<JsonArray>();
|
||||
REQUIRE(arr.isNull() == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArray::operator bool()") {
|
||||
SECTION("returns false") {
|
||||
JsonArray arr;
|
||||
@ -43,16 +30,3 @@ TEST_CASE("JsonArray::operator bool()") {
|
||||
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") {
|
||||
JsonDocument doc;
|
||||
JsonArrayConst arr = doc.to<JsonArray>();
|
||||
REQUIRE(static_cast<bool>(arr) == true);
|
||||
}
|
||||
}
|
||||
|
@ -5,31 +5,25 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
template <typename TArray>
|
||||
static void run_iterator_test() {
|
||||
JsonDocument doc;
|
||||
JsonArray tmp = doc.to<JsonArray>();
|
||||
tmp.add(12);
|
||||
tmp.add(34);
|
||||
|
||||
TArray array = tmp;
|
||||
typename TArray::iterator it = array.begin();
|
||||
typename TArray::iterator end = array.end();
|
||||
|
||||
REQUIRE(end != it);
|
||||
REQUIRE(12 == it->template as<int>());
|
||||
REQUIRE(12 == static_cast<int>(*it));
|
||||
++it;
|
||||
REQUIRE(end != it);
|
||||
REQUIRE(34 == it->template as<int>());
|
||||
REQUIRE(34 == static_cast<int>(*it));
|
||||
++it;
|
||||
REQUIRE(end == it);
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArray::begin()/end()") {
|
||||
SECTION("Non null JsonArray") {
|
||||
run_iterator_test<JsonArray>();
|
||||
JsonDocument doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
array.add(12);
|
||||
array.add(34);
|
||||
|
||||
auto it = array.begin();
|
||||
auto end = array.end();
|
||||
|
||||
REQUIRE(end != it);
|
||||
REQUIRE(12 == it->as<int>());
|
||||
REQUIRE(12 == static_cast<int>(*it));
|
||||
++it;
|
||||
REQUIRE(end != it);
|
||||
REQUIRE(34 == it->as<int>());
|
||||
REQUIRE(34 == static_cast<int>(*it));
|
||||
++it;
|
||||
REQUIRE(end == it);
|
||||
}
|
||||
|
||||
SECTION("Null JsonArray") {
|
||||
@ -38,15 +32,3 @@ TEST_CASE("JsonArray::begin()/end()") {
|
||||
REQUIRE(array.begin() == array.end());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArrayConst::begin()/end()") {
|
||||
SECTION("Non null JsonArrayConst") {
|
||||
run_iterator_test<JsonArrayConst>();
|
||||
}
|
||||
|
||||
SECTION("Null JsonArrayConst") {
|
||||
JsonArrayConst array;
|
||||
|
||||
REQUIRE(array.begin() == array.end());
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,6 @@
|
||||
|
||||
#include "Allocators.hpp"
|
||||
|
||||
using ArduinoJson::detail::sizeofArray;
|
||||
|
||||
TEST_CASE("JsonArray::operator[]") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
@ -167,18 +165,3 @@ TEST_CASE("JsonArray::operator[]") {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArrayConst::operator[]") {
|
||||
JsonDocument doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
array.add(0);
|
||||
|
||||
SECTION("int") {
|
||||
array[0] = 123;
|
||||
JsonArrayConst carr = array;
|
||||
|
||||
REQUIRE(123 == carr[0].as<int>());
|
||||
REQUIRE(true == carr[0].is<int>());
|
||||
REQUIRE(false == carr[0].is<bool>());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user