mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-16 12:02:14 +02:00
Recycle removed slots
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
|
||||
TEST_CASE("JsonArray::clear()") {
|
||||
SECTION("No-op on null JsonArray") {
|
||||
JsonArray array;
|
||||
@ -22,4 +24,25 @@ TEST_CASE("JsonArray::clear()") {
|
||||
REQUIRE(array.size() == 0);
|
||||
REQUIRE(array.isNull() == false);
|
||||
}
|
||||
|
||||
SECTION("Removed elements are recycled") {
|
||||
SpyingAllocator allocator;
|
||||
JsonDocument doc(&allocator);
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
|
||||
// fill the pool entirely
|
||||
for (int i = 0; i < ARDUINOJSON_POOL_CAPACITY; i++)
|
||||
array.add(i);
|
||||
|
||||
// clear and fill again
|
||||
array.clear();
|
||||
for (int i = 0; i < ARDUINOJSON_POOL_CAPACITY; i++)
|
||||
array.add(i);
|
||||
|
||||
REQUIRE(
|
||||
allocator.log() ==
|
||||
AllocatorLog() << AllocatorLog::Allocate(sizeofPoolList())
|
||||
<< AllocatorLog::Allocate(sizeofPool()) // only one pool
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user