Files
ArduinoJson/test/DynamicMemoryPool/startString.cpp

52 lines
1.1 KiB
C++
Raw Normal View History

// ArduinoJson - arduinojson.org
2018-01-05 09:20:01 +01:00
// Copyright Benoit Blanchon 2014-2018
// MIT License
2018-09-03 16:14:21 +02:00
#include <ArduinoJson/Memory/DynamicMemoryPool.hpp>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
2018-10-04 11:16:23 +02:00
typedef DynamicMemoryPool::StringBuilder StringBuilder;
2018-09-03 16:14:21 +02:00
TEST_CASE("DynamicMemoryPool::startString()") {
SECTION("WorksWhenBufferIsBigEnough") {
2018-09-03 16:14:21 +02:00
DynamicMemoryPool memoryPool(6);
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("GrowsWhenBufferIsTooSmall") {
2018-09-03 16:14:21 +02:00
DynamicMemoryPool memoryPool(5);
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("SizeIncreases") {
2018-09-03 16:14:21 +02:00
DynamicMemoryPool memoryPool(5);
2018-10-04 11:16:23 +02:00
StringBuilder str = memoryPool.startString();
2018-09-03 16:14:21 +02:00
REQUIRE(0 == memoryPool.size());
str.append('h');
2018-09-03 16:14:21 +02:00
REQUIRE(1 == memoryPool.size());
2018-10-04 11:16:23 +02:00
str.complete();
2018-09-03 16:14:21 +02:00
REQUIRE(2 == memoryPool.size());
}
}