Files
ArduinoJson/test/DynamicMemoryPool/startString.cpp

50 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-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-09-03 16:14:21 +02:00
DynamicMemoryPool::String str = memoryPool.startString();
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);
2018-09-03 16:14:21 +02:00
DynamicMemoryPool::String str = memoryPool.startString();
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);
2018-09-03 16:14:21 +02:00
DynamicMemoryPool::String str = memoryPool.startString();
REQUIRE(0 == memoryPool.size());
str.append('h');
2018-09-03 16:14:21 +02:00
REQUIRE(1 == memoryPool.size());
str.c_str();
2018-09-03 16:14:21 +02:00
REQUIRE(2 == memoryPool.size());
}
}