JsonArray_Iterator_Tests.cpp 936 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright Benoit Blanchon 2014-2017
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. // If you like this project, please add a star!
  7. #include <ArduinoJson.h>
  8. #include <gtest/gtest.h>
  9. template <typename TIterator>
  10. static void run_iterator_test() {
  11. StaticJsonBuffer<JSON_ARRAY_SIZE(2)> jsonBuffer;
  12. JsonArray &array = jsonBuffer.createArray();
  13. array.add(12);
  14. array.add(34);
  15. TIterator it = array.begin();
  16. TIterator end = array.end();
  17. EXPECT_NE(end, it);
  18. EXPECT_EQ(12, it->template as<int>());
  19. EXPECT_EQ(12, static_cast<int>(*it));
  20. ++it;
  21. EXPECT_NE(end, it);
  22. EXPECT_EQ(34, it->template as<int>());
  23. EXPECT_EQ(34, static_cast<int>(*it));
  24. ++it;
  25. EXPECT_EQ(end, it);
  26. }
  27. TEST(JsonArray_Iterator_Test, RunItertorToEnd) {
  28. run_iterator_test<JsonArray::iterator>();
  29. }
  30. TEST(JsonArray_Iterator_Test, RunConstItertorToEnd) {
  31. run_iterator_test<JsonArray::const_iterator>();
  32. }