2014-10-23 23:39:22 +02:00
|
|
|
// Copyright Benoit Blanchon 2014
|
|
|
|
// MIT License
|
|
|
|
//
|
|
|
|
// Arduino JSON library
|
|
|
|
// https://github.com/bblanchon/ArduinoJson
|
|
|
|
|
2014-10-16 16:23:24 +02:00
|
|
|
#include <gtest/gtest.h>
|
2014-10-27 22:50:50 +01:00
|
|
|
#include <ArduinoJson/JsonObject.hpp>
|
|
|
|
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
2014-10-16 16:23:24 +02:00
|
|
|
|
2014-10-18 23:05:54 +02:00
|
|
|
using namespace ArduinoJson;
|
|
|
|
|
2014-11-05 13:54:53 +01:00
|
|
|
TEST(StaticJsonBuffer_Object_Tests, GrowsWithObject) {
|
|
|
|
StaticJsonBuffer<JSON_OBJECT_SIZE(3)> json;
|
2014-10-31 11:38:58 +01:00
|
|
|
|
2014-11-05 13:54:53 +01:00
|
|
|
JsonObject &obj = json.createObject();
|
|
|
|
ASSERT_EQ(JSON_OBJECT_SIZE(0), json.size());
|
2014-10-16 16:23:24 +02:00
|
|
|
|
2014-11-05 13:54:53 +01:00
|
|
|
obj["hello"];
|
|
|
|
ASSERT_EQ(JSON_OBJECT_SIZE(1), json.size());
|
2014-10-16 16:23:24 +02:00
|
|
|
|
2014-11-05 13:54:53 +01:00
|
|
|
obj["world"];
|
|
|
|
ASSERT_EQ(JSON_OBJECT_SIZE(2), json.size());
|
2014-10-16 16:23:24 +02:00
|
|
|
|
2014-11-05 13:54:53 +01:00
|
|
|
obj["world"]; // <- same value, should not grow
|
|
|
|
ASSERT_EQ(JSON_OBJECT_SIZE(2), json.size());
|
2014-10-16 16:23:24 +02:00
|
|
|
}
|
|
|
|
|
2014-11-05 13:54:53 +01:00
|
|
|
TEST(StaticJsonBuffer_Object_Tests, SucceedWhenBigEnough) {
|
|
|
|
StaticJsonBuffer<JSON_OBJECT_SIZE(0)> json;
|
2014-11-05 13:31:00 +01:00
|
|
|
|
|
|
|
JsonObject &object = json.createObject();
|
2014-11-05 13:54:53 +01:00
|
|
|
ASSERT_TRUE(object.success());
|
2014-11-05 13:31:00 +01:00
|
|
|
}
|
|
|
|
|
2014-11-05 13:54:53 +01:00
|
|
|
TEST(StaticJsonBuffer_Object_Tests, FailsWhenTooSmall) {
|
|
|
|
StaticJsonBuffer<JSON_OBJECT_SIZE(0) - 1> json;
|
2014-11-05 13:31:00 +01:00
|
|
|
|
|
|
|
JsonObject &object = json.createObject();
|
2014-11-05 13:54:53 +01:00
|
|
|
ASSERT_FALSE(object.success());
|
2014-10-23 23:45:36 +02:00
|
|
|
}
|
2014-11-05 21:07:36 +01:00
|
|
|
|
|
|
|
TEST(StaticJsonBuffer_Object_Tests, ObjectDoesntGrowWhenFull) {
|
|
|
|
StaticJsonBuffer<JSON_OBJECT_SIZE(1)> json;
|
|
|
|
|
|
|
|
JsonObject &obj = json.createObject();
|
|
|
|
obj["hello"];
|
|
|
|
obj["world"];
|
|
|
|
|
|
|
|
ASSERT_EQ(JSON_OBJECT_SIZE(1), json.size());
|
|
|
|
}
|