Added more tests of StaticJsonBuffer

This commit is contained in:
Benoit Blanchon
2014-11-05 21:07:36 +01:00
parent 08de76e2ba
commit 01949f7da0
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,48 @@
// Copyright Benoit Blanchon 2014
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
#include <gtest/gtest.h>
#include <ArduinoJson/JsonArray.hpp>
#include <ArduinoJson/StaticJsonBuffer.hpp>
using namespace ArduinoJson;
TEST(StaticJsonBuffer_Array_Tests, GrowsWithArray) {
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());
}
TEST(StaticJsonBuffer_Array_Tests, SucceedWhenBigEnough) {
StaticJsonBuffer<JSON_ARRAY_SIZE(0)> json;
JsonArray &array = json.createArray();
ASSERT_TRUE(array.success());
}
TEST(StaticJsonBuffer_Array_Tests, FailsWhenTooSmall) {
StaticJsonBuffer<JSON_ARRAY_SIZE(0) - 1> json;
JsonArray &array = json.createArray();
ASSERT_FALSE(array.success());
}
TEST(StaticJsonBuffer_Array_Tests, ArrayDoesntGrowWhenFull) {
StaticJsonBuffer<JSON_ARRAY_SIZE(1)> json;
JsonArray &array = json.createArray();
array.add("hello");
array.add("world");
EXPECT_EQ(1, array.size());
}