iterator.cpp 837 B

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