2021-03-29 17:14:01 +02:00
|
|
|
// ArduinoJson - https://arduinojson.org
|
2023-02-16 11:45:01 +01:00
|
|
|
// Copyright © 2014-2023, Benoit BLANCHON
|
2018-11-09 17:27:32 +01:00
|
|
|
// MIT License
|
|
|
|
|
2023-06-17 16:10:56 +02:00
|
|
|
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
2023-06-17 16:24:12 +02:00
|
|
|
#include <ArduinoJson/Memory/VariantPoolImpl.hpp>
|
2020-07-21 20:15:31 +02:00
|
|
|
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
2018-11-09 17:27:32 +01:00
|
|
|
#include <catch.hpp>
|
|
|
|
|
2023-02-14 10:04:48 +01:00
|
|
|
using namespace ArduinoJson::detail;
|
2018-11-09 17:27:32 +01:00
|
|
|
|
|
|
|
static const size_t poolCapacity = 512;
|
|
|
|
|
2023-06-17 16:10:56 +02:00
|
|
|
TEST_CASE("ResourceManager::clear()") {
|
|
|
|
ResourceManager resources(poolCapacity);
|
2018-11-09 17:27:32 +01:00
|
|
|
|
|
|
|
SECTION("Discards allocated variants") {
|
2023-06-14 11:57:31 +02:00
|
|
|
resources.allocSlot();
|
2018-11-09 17:27:32 +01:00
|
|
|
|
2023-06-17 16:10:56 +02:00
|
|
|
resources.clear();
|
|
|
|
REQUIRE(resources.size() == 0);
|
2018-11-09 17:27:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Discards allocated strings") {
|
2023-06-17 16:10:56 +02:00
|
|
|
resources.saveString(adaptString("123456789"));
|
|
|
|
REQUIRE(resources.size() == sizeofString(9));
|
2018-11-09 17:27:32 +01:00
|
|
|
|
2023-06-17 16:10:56 +02:00
|
|
|
resources.clear();
|
2018-11-09 17:27:32 +01:00
|
|
|
|
2023-06-17 16:10:56 +02:00
|
|
|
REQUIRE(resources.size() == 0);
|
2018-11-09 17:27:32 +01:00
|
|
|
}
|
|
|
|
}
|