2018-11-03 20:21:33 +00:00
|
|
|
// ArduinoJson - arduinojson.org
|
|
|
|
// Copyright Benoit Blanchon 2014-2018
|
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <catch.hpp>
|
|
|
|
|
2018-11-13 14:50:48 +00:00
|
|
|
template <typename TArray>
|
2018-11-03 20:21:33 +00:00
|
|
|
static void run_iterator_test() {
|
|
|
|
StaticJsonDocument<JSON_ARRAY_SIZE(2)> doc;
|
2018-11-13 14:50:48 +00:00
|
|
|
JsonArray tmp = doc.to<JsonArray>();
|
|
|
|
tmp.add(12);
|
|
|
|
tmp.add(34);
|
2018-11-03 20:21:33 +00:00
|
|
|
|
2018-11-13 14:50:48 +00:00
|
|
|
TArray array = tmp;
|
|
|
|
typename TArray::iterator it = array.begin();
|
|
|
|
typename TArray::iterator end = array.end();
|
2018-11-03 20:21:33 +00:00
|
|
|
|
|
|
|
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()") {
|
2018-11-13 14:50:48 +00:00
|
|
|
run_iterator_test<JsonArray>();
|
|
|
|
}
|
2018-11-03 20:21:33 +00:00
|
|
|
|
2018-11-13 14:50:48 +00:00
|
|
|
TEST_CASE("JsonArrayConst::begin()/end()") {
|
|
|
|
run_iterator_test<JsonArrayConst>();
|
2018-11-03 20:21:33 +00:00
|
|
|
}
|