Test that size can't go above capacity

This commit is contained in:
Benoit Blanchon
2014-09-27 11:33:18 +02:00
parent bb887f94e7
commit 890e811e80
2 changed files with 17 additions and 1 deletions

View File

@ -14,7 +14,12 @@ public:
virtual ~StaticJsonBuffer() {} virtual ~StaticJsonBuffer() {}
/*JsonObject*/void createObject() { _size++; } /*JsonObject*/
void createObject()
{
if (_size < CAPACITY)
_size++;
}
int capacity() int capacity()
{ {

View File

@ -23,3 +23,14 @@ TEST(StaticJsonBuffer, WhenCreateObjectIsCalled_ThenSizeIsIncreasedByOne)
json.createObject(); json.createObject();
EXPECT_EQ(2, json.size()); EXPECT_EQ(2, json.size());
} }
TEST(StaticJsonBuffer, GivenBufferIsFull_WhenCreateObjectIsCalled_ThenSizeDoesNotChange)
{
StaticJsonBuffer<1> json;
json.createObject();
EXPECT_EQ(1, json.size());
json.createObject();
EXPECT_EQ(1, json.size());
}