Files
ArduinoJson/test/StaticJsonBuffer_CreateArray_Tests.cpp

47 lines
1.1 KiB
C++
Raw Normal View History

// Copyright Benoit Blanchon 2014-2017
2014-11-05 21:07:36 +01:00
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
// If you like this project, please add a star!
2014-11-05 21:07:36 +01:00
#include <ArduinoJson.h>
#include <gtest/gtest.h>
2014-11-05 21:07:36 +01:00
2015-04-27 15:57:40 +02:00
TEST(StaticJsonBuffer_CreateArray_Tests, GrowsWithArray) {
2014-11-05 21:07:36 +01:00
StaticJsonBuffer<JSON_ARRAY_SIZE(2)> json;
JsonArray &array = json.createArray();
ASSERT_EQ(JSON_ARRAY_SIZE(0), json.size());
array.add("hello");
ASSERT_EQ(JSON_ARRAY_SIZE(1), json.size());
array.add("world");
ASSERT_EQ(JSON_ARRAY_SIZE(2), json.size());
}
2015-04-27 15:57:40 +02:00
TEST(StaticJsonBuffer_CreateArray_Tests, SucceedWhenBigEnough) {
2014-11-05 21:07:36 +01:00
StaticJsonBuffer<JSON_ARRAY_SIZE(0)> json;
JsonArray &array = json.createArray();
ASSERT_TRUE(array.success());
}
2015-04-27 15:57:40 +02:00
TEST(StaticJsonBuffer_CreateArray_Tests, FailsWhenTooSmall) {
2014-11-05 21:07:36 +01:00
StaticJsonBuffer<JSON_ARRAY_SIZE(0) - 1> json;
JsonArray &array = json.createArray();
ASSERT_FALSE(array.success());
}
2015-04-27 15:57:40 +02:00
TEST(StaticJsonBuffer_CreateArray_Tests, ArrayDoesntGrowWhenFull) {
2014-11-05 21:07:36 +01:00
StaticJsonBuffer<JSON_ARRAY_SIZE(1)> json;
JsonArray &array = json.createArray();
array.add("hello");
array.add("world");
EXPECT_EQ(1, array.size());
}