2017-11-07 20:42:50 +01:00
|
|
|
// ArduinoJson - arduinojson.org
|
2018-01-05 09:20:01 +01:00
|
|
|
// Copyright Benoit Blanchon 2014-2018
|
2017-04-18 18:22:24 +02:00
|
|
|
// MIT License
|
|
|
|
|
2018-09-03 16:14:21 +02:00
|
|
|
#include <ArduinoJson/Memory/DynamicMemoryPool.hpp>
|
2017-04-18 18:22:24 +02:00
|
|
|
#include <catch.hpp>
|
|
|
|
|
2018-04-17 21:27:45 +02:00
|
|
|
using namespace ArduinoJson::Internals;
|
|
|
|
|
2018-09-03 16:14:21 +02:00
|
|
|
TEST_CASE("DynamicMemoryPool::startString()") {
|
2017-04-18 18:22:24 +02:00
|
|
|
SECTION("WorksWhenBufferIsBigEnough") {
|
2018-09-03 16:14:21 +02:00
|
|
|
DynamicMemoryPool memoryPool(6);
|
2017-04-18 18:22:24 +02:00
|
|
|
|
2018-09-03 16:14:21 +02:00
|
|
|
DynamicMemoryPool::String str = memoryPool.startString();
|
2017-04-18 18:22:24 +02:00
|
|
|
str.append('h');
|
|
|
|
str.append('e');
|
|
|
|
str.append('l');
|
|
|
|
str.append('l');
|
|
|
|
str.append('o');
|
|
|
|
|
|
|
|
REQUIRE(std::string("hello") == str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("GrowsWhenBufferIsTooSmall") {
|
2018-09-03 16:14:21 +02:00
|
|
|
DynamicMemoryPool memoryPool(5);
|
2017-04-18 18:22:24 +02:00
|
|
|
|
2018-09-03 16:14:21 +02:00
|
|
|
DynamicMemoryPool::String str = memoryPool.startString();
|
2017-04-18 18:22:24 +02:00
|
|
|
str.append('h');
|
|
|
|
str.append('e');
|
|
|
|
str.append('l');
|
|
|
|
str.append('l');
|
|
|
|
str.append('o');
|
|
|
|
|
|
|
|
REQUIRE(std::string("hello") == str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("SizeIncreases") {
|
2018-09-03 16:14:21 +02:00
|
|
|
DynamicMemoryPool memoryPool(5);
|
2017-04-18 18:22:24 +02:00
|
|
|
|
2018-09-03 16:14:21 +02:00
|
|
|
DynamicMemoryPool::String str = memoryPool.startString();
|
|
|
|
REQUIRE(0 == memoryPool.size());
|
2017-04-18 18:22:24 +02:00
|
|
|
|
|
|
|
str.append('h');
|
2018-09-03 16:14:21 +02:00
|
|
|
REQUIRE(1 == memoryPool.size());
|
2017-04-18 18:22:24 +02:00
|
|
|
|
|
|
|
str.c_str();
|
2018-09-03 16:14:21 +02:00
|
|
|
REQUIRE(2 == memoryPool.size());
|
2017-04-18 18:22:24 +02:00
|
|
|
}
|
|
|
|
}
|