mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 12:02:14 +02:00
JsonArray::remove() and JsonObject::remove() now release the memory of strings
This commit is contained in:
39
test/StaticMemoryPool/StringBuilder.cpp
Normal file
39
test/StaticMemoryPool/StringBuilder.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2018
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson/Memory/StaticMemoryPool.hpp>
|
||||
#include <ArduinoJson/Memory/StringBuilder.hpp>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("StringBuilder") {
|
||||
SECTION("WorksWhenBufferIsBigEnough") {
|
||||
StaticMemoryPool<JSON_STRING_SIZE(6)> memoryPool;
|
||||
|
||||
StringBuilder str(&memoryPool);
|
||||
str.append("hello");
|
||||
|
||||
REQUIRE(str.complete().equals("hello"));
|
||||
}
|
||||
|
||||
SECTION("ReturnsNullWhenTooSmall") {
|
||||
StaticMemoryPool<1> memoryPool;
|
||||
|
||||
StringBuilder str(&memoryPool);
|
||||
str.append("hello!!!");
|
||||
|
||||
REQUIRE(str.complete().isNull());
|
||||
}
|
||||
|
||||
SECTION("Increases size of memory pool") {
|
||||
StaticMemoryPool<JSON_STRING_SIZE(6)> memoryPool;
|
||||
|
||||
StringBuilder str(&memoryPool);
|
||||
str.append('h');
|
||||
str.complete();
|
||||
|
||||
REQUIRE(JSON_STRING_SIZE(2) == memoryPool.size());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user