2023-06-17 16:10:56 +02:00
|
|
|
// ArduinoJson - https://arduinojson.org
|
|
|
|
// Copyright © 2014-2023, Benoit BLANCHON
|
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#include <ArduinoJson/Memory/ResourceManager.hpp>
|
2023-06-17 16:24:12 +02:00
|
|
|
#include <ArduinoJson/Memory/VariantPoolImpl.hpp>
|
2023-06-17 16:10:56 +02:00
|
|
|
#include <catch.hpp>
|
|
|
|
|
2023-07-17 14:39:57 +02:00
|
|
|
#include "Allocators.hpp"
|
2023-06-17 16:10:56 +02:00
|
|
|
|
2023-07-17 14:39:57 +02:00
|
|
|
using namespace ArduinoJson::detail;
|
2023-06-17 16:10:56 +02:00
|
|
|
|
|
|
|
TEST_CASE("ResourceManager::size()") {
|
2023-07-17 14:39:57 +02:00
|
|
|
TimebombAllocator allocator(0);
|
2023-07-17 18:15:13 +02:00
|
|
|
ResourceManager resources(&allocator);
|
2023-06-17 16:10:56 +02:00
|
|
|
|
|
|
|
SECTION("Initial size is 0") {
|
|
|
|
REQUIRE(0 == resources.size());
|
|
|
|
}
|
|
|
|
|
2023-07-17 14:39:57 +02:00
|
|
|
SECTION("Doesn't grow when allocation of second pool fails") {
|
2023-07-21 10:38:35 +02:00
|
|
|
allocator.setCountdown(1);
|
2023-07-17 14:39:57 +02:00
|
|
|
for (size_t i = 0; i < ARDUINOJSON_POOL_CAPACITY; i++)
|
2023-06-14 11:57:31 +02:00
|
|
|
resources.allocSlot();
|
2023-06-17 16:10:56 +02:00
|
|
|
size_t size = resources.size();
|
|
|
|
|
2023-06-14 11:57:31 +02:00
|
|
|
resources.allocSlot();
|
2023-06-17 16:10:56 +02:00
|
|
|
|
|
|
|
REQUIRE(size == resources.size());
|
|
|
|
}
|
|
|
|
}
|