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>
|
2014-11-05 13:10:22 +01:00
|
|
|
#include "Printers.hpp"
|
2014-10-22 21:56:38 +02:00
|
|
|
|
|
|
|
using namespace ArduinoJson;
|
|
|
|
|
2014-11-05 13:10:22 +01:00
|
|
|
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
|
|
|
|
2014-11-05 13:10:22 +01:00
|
|
|
protected:
|
|
|
|
StaticJsonBuffer<256> _buffer;
|
|
|
|
JsonObject& object;
|
|
|
|
};
|
2014-10-22 21:56:38 +02:00
|
|
|
|
2014-11-05 13:10:22 +01:00
|
|
|
TEST_F(JsonObject_Iterator_Test, NonConstIterator) {
|
2014-10-24 18:53:03 +02:00
|
|
|
JsonObject::iterator it = object.begin();
|
2014-11-05 13:10:22 +01:00
|
|
|
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
|
|
|
|
2014-11-05 13:10:22 +01:00
|
|
|
ASSERT_NE(const_object.end(), it);
|
2014-10-30 10:49:02 +01:00
|
|
|
EXPECT_STREQ("ab", it->key);
|
2014-11-05 13:10:22 +01:00
|
|
|
EXPECT_EQ(12, it->value);
|
2014-10-23 19:54:00 +02:00
|
|
|
++it;
|
2014-11-05 13:10:22 +01:00
|
|
|
ASSERT_NE(const_object.end(), it);
|
2014-10-30 10:49:02 +01:00
|
|
|
EXPECT_STREQ("cd", it->key);
|
2014-11-05 13:10:22 +01:00
|
|
|
EXPECT_EQ(34, it->value);
|
2014-10-23 19:54:00 +02:00
|
|
|
++it;
|
2014-11-05 13:10:22 +01:00
|
|
|
ASSERT_EQ(const_object.end(), it);
|
2014-10-23 23:45:36 +02:00
|
|
|
}
|