Files
ArduinoJson/test/StaticMemoryPool/startString.cpp

47 lines
983 B
C++
Raw Normal View History

// ArduinoJson - arduinojson.org
2018-01-05 09:20:01 +01:00
// Copyright Benoit Blanchon 2014-2018
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
2018-09-03 16:14:21 +02:00
TEST_CASE("StaticMemoryPool::startString()") {
SECTION("WorksWhenBufferIsBigEnough") {
2018-09-03 16:14:21 +02:00
StaticMemoryPool<6> memoryPool;
2018-10-04 11:16:23 +02:00
StringBuilder str = memoryPool.startString();
str.append('h');
str.append('e');
str.append('l');
str.append('l');
str.append('o');
2018-10-04 11:16:23 +02:00
REQUIRE(str.complete().equals("hello"));
}
SECTION("ReturnsNullWhenTooSmall") {
2018-09-03 16:14:21 +02:00
StaticMemoryPool<5> memoryPool;
2018-10-04 11:16:23 +02:00
StringBuilder str = memoryPool.startString();
str.append('h');
str.append('e');
str.append('l');
str.append('l');
str.append('o');
2018-10-04 11:16:23 +02:00
REQUIRE(str.complete().isNull());
}
SECTION("SizeIncreases") {
2018-09-03 16:14:21 +02:00
StaticMemoryPool<5> memoryPool;
2018-10-04 11:16:23 +02:00
StringBuilder str = memoryPool.startString();
str.append('h');
2018-10-04 11:16:23 +02:00
str.complete();
2018-09-03 16:14:21 +02:00
REQUIRE(2 == memoryPool.size());
}
}