Remove JsonDocument::garbageCollect()

This commit is contained in:
Benoit Blanchon
2023-07-25 14:37:25 +02:00
parent 00c9d8680a
commit a8329564e2
5 changed files with 1 additions and 69 deletions

View File

@ -11,7 +11,6 @@ add_executable(JsonDocumentTests
containsKey.cpp
createNested.cpp
ElementProxy.cpp
garbageCollect.cpp
isNull.cpp
issue1120.cpp
MemberProxy.cpp

View File

@ -1,50 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <stdlib.h> // malloc, free
#include <catch.hpp>
#include <utility>
#include "Allocators.hpp"
using ArduinoJson::detail::sizeofObject;
using ArduinoJson::detail::sizeofString;
TEST_CASE("JsonDocument::garbageCollect()") {
ControllableAllocator controllableAllocator;
SpyingAllocator spyingAllocator(&controllableAllocator);
JsonDocument doc(&spyingAllocator);
SECTION("when allocation succeeds") {
deserializeJson(doc, "{\"blanket\":1,\"dancing\":2}");
doc.remove("blanket");
spyingAllocator.clearLog();
bool result = doc.garbageCollect();
REQUIRE(result == true);
REQUIRE(doc.as<std::string>() == "{\"dancing\":2}");
REQUIRE(spyingAllocator.log() ==
AllocatorLog() << AllocatorLog::Allocate(sizeofString(7))
<< AllocatorLog::Allocate(sizeofPool())
<< AllocatorLog::Deallocate(sizeofString(7))
<< AllocatorLog::Deallocate(sizeofPool()));
}
SECTION("when allocation fails") {
deserializeJson(doc, "{\"blanket\":1,\"dancing\":2}");
doc.remove("blanket");
controllableAllocator.disable();
spyingAllocator.clearLog();
bool result = doc.garbageCollect();
REQUIRE(result == false);
REQUIRE(doc.as<std::string>() == "{\"dancing\":2}");
REQUIRE(spyingAllocator.log() ==
AllocatorLog() << AllocatorLog::AllocateFail(sizeofString(7)));
}
}

View File

@ -80,11 +80,4 @@ TEST_CASE("JsonDocument::overflowed()") {
doc.shrinkToFit();
CHECK(doc.overflowed() == true);
}
SECTION("return false after garbageCollect()") {
allocator.setCountdown(0);
doc.add(0);
doc.garbageCollect();
CHECK(doc.overflowed() == false);
}
}