Files
ArduinoJson/test/StaticMemoryPool/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
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ArduinoJson::Internals;
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-09-03 16:14:21 +02:00
StaticMemoryPoolBase::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("ReturnsNullWhenTooSmall") {
2018-09-03 16:14:21 +02:00
StaticMemoryPool<5> memoryPool;
2018-09-03 16:14:21 +02:00
StaticMemoryPoolBase::String str = memoryPool.startString();
str.append('h');
str.append('e');
str.append('l');
str.append('l');
str.append('o');
REQUIRE(0 == str.c_str());
}
SECTION("SizeIncreases") {
2018-09-03 16:14:21 +02:00
StaticMemoryPool<5> memoryPool;
2018-09-03 16:14:21 +02:00
StaticMemoryPoolBase::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());
}
}