JsonArray_Iterator_Tests.cpp 888 B

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