Files
ArduinoJson/test/StaticJsonBuffer_Object_Tests.cpp

49 lines
1.2 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-16 16:23:24 +02:00
#include <gtest/gtest.h>
#include <ArduinoJson.h>
2014-10-18 23:05:54 +02:00
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;
JsonObject &object = json.createObject();
2014-11-05 13:54:53 +01:00
ASSERT_TRUE(object.success());
}
2014-11-05 13:54:53 +01:00
TEST(StaticJsonBuffer_Object_Tests, FailsWhenTooSmall) {
StaticJsonBuffer<JSON_OBJECT_SIZE(0) - 1> json;
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());
}