Files
ArduinoJson/test/JsonObject_Iterator_Tests.cpp

61 lines
1.4 KiB
C++
Raw Normal View History

2014-10-23 23:39:22 +02:00
// Copyright Benoit Blanchon 2014
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
2014-10-22 21:56:38 +02:00
#include <gtest/gtest.h>
#include <ArduinoJson/JsonObject.hpp>
#include <ArduinoJson/StaticJsonBuffer.hpp>
#include "Printers.hpp"
2014-10-22 21:56:38 +02:00
using namespace ArduinoJson;
class JsonObject_Iterator_Test : public testing::Test {
public:
JsonObject_Iterator_Test() : object(_buffer.createObject()) {
object["ab"] = 12;
object["cd"] = 34;
}
2014-10-22 21:56:38 +02:00
protected:
StaticJsonBuffer<256> _buffer;
JsonObject& object;
};
2014-10-22 21:56:38 +02:00
TEST_F(JsonObject_Iterator_Test, NonConstIterator) {
JsonObject::iterator it = object.begin();
ASSERT_NE(object.end(), it);
EXPECT_STREQ("ab", it->key);
EXPECT_EQ(12, it->value);
it->key = "a.b";
it->value = 1.2;
++it;
ASSERT_NE(object.end(), it);
EXPECT_STREQ("cd", it->key);
EXPECT_EQ(34, it->value);
it->key = "c.d";
it->value = 3.4;
++it;
ASSERT_EQ(object.end(), it);
ASSERT_EQ(2, object.size());
EXPECT_EQ(1.2, object["a.b"]);
EXPECT_EQ(3.4, object["c.d"]);
}
TEST_F(JsonObject_Iterator_Test, ConstIterator) {
const JsonObject& const_object = object;
JsonObject::const_iterator it = const_object.begin();
2014-10-22 21:56:38 +02:00
ASSERT_NE(const_object.end(), it);
2014-10-30 10:49:02 +01:00
EXPECT_STREQ("ab", it->key);
EXPECT_EQ(12, it->value);
2014-10-23 19:54:00 +02:00
++it;
ASSERT_NE(const_object.end(), it);
2014-10-30 10:49:02 +01:00
EXPECT_STREQ("cd", it->key);
EXPECT_EQ(34, it->value);
2014-10-23 19:54:00 +02:00
++it;
ASSERT_EQ(const_object.end(), it);
2014-10-23 23:45:36 +02:00
}