iterator.cpp 885 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2024, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonObjectConst::begin()/end()") {
  7. JsonDocument doc;
  8. JsonObjectConst obj = doc.to<JsonObject>();
  9. doc["ab"] = 12;
  10. doc["cd"] = 34;
  11. SECTION("Iteration") {
  12. JsonObjectConst::iterator it = obj.begin();
  13. REQUIRE(obj.end() != it);
  14. REQUIRE(it->key() == "ab");
  15. REQUIRE(12 == it->value());
  16. ++it;
  17. REQUIRE(obj.end() != it);
  18. JsonPairConst pair = *it;
  19. REQUIRE(pair.key() == "cd");
  20. REQUIRE(34 == pair.value());
  21. ++it;
  22. REQUIRE(obj.end() == it);
  23. }
  24. SECTION("Dereferencing end() is safe") {
  25. REQUIRE(obj.end()->key().isNull());
  26. REQUIRE(obj.end()->value().isNull());
  27. }
  28. SECTION("null JsonObjectConst") {
  29. JsonObjectConst null;
  30. REQUIRE(null.begin() == null.end());
  31. }
  32. }