iterator.cpp 783 B

123456789101112131415161718192021222324252627282930313233343536
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. template <typename TIterator>
  7. static void run_iterator_test() {
  8. StaticJsonArray<JSON_ARRAY_SIZE(2)> array;
  9. array.add(12);
  10. array.add(34);
  11. TIterator it = array.begin();
  12. TIterator end = array.end();
  13. REQUIRE(end != it);
  14. REQUIRE(12 == it->template as<int>());
  15. REQUIRE(12 == static_cast<int>(*it));
  16. ++it;
  17. REQUIRE(end != it);
  18. REQUIRE(34 == it->template as<int>());
  19. REQUIRE(34 == static_cast<int>(*it));
  20. ++it;
  21. REQUIRE(end == it);
  22. }
  23. TEST_CASE("JsonArray::begin()/end()") {
  24. SECTION("Mutable") {
  25. run_iterator_test<JsonArray::iterator>();
  26. }
  27. SECTION("Const") {
  28. run_iterator_test<JsonArray::const_iterator>();
  29. }
  30. }