Files
ArduinoJson/extras/tests/ResourceManager/clear.cpp

33 lines
781 B
C++
Raw Normal View History

// ArduinoJson - https://arduinojson.org
2023-02-16 11:45:01 +01:00
// Copyright © 2014-2023, Benoit BLANCHON
// MIT License
#include <ArduinoJson/Memory/ResourceManager.hpp>
#include <ArduinoJson/Memory/VariantPoolImpl.hpp>
#include <ArduinoJson/Strings/StringAdapters.hpp>
#include <catch.hpp>
using namespace ArduinoJson::detail;
static const size_t poolCapacity = 512;
TEST_CASE("ResourceManager::clear()") {
ResourceManager resources(poolCapacity);
SECTION("Discards allocated variants") {
resources.allocSlot();
resources.clear();
REQUIRE(resources.size() == 0);
}
SECTION("Discards allocated strings") {
resources.saveString(adaptString("123456789"));
REQUIRE(resources.size() == sizeofString(9));
resources.clear();
REQUIRE(resources.size() == 0);
}
}