ResourceManager: replace allocFromPool() with allocVariant()

This commit is contained in:
Benoit Blanchon
2023-06-16 16:09:40 +02:00
parent 2cf7fc5427
commit 8147625921
9 changed files with 34 additions and 35 deletions

View File

@ -10,13 +10,13 @@
using namespace ArduinoJson::detail;
TEST_CASE("new (resources) VariantSlot()") {
TEST_CASE("ResourceManager::allocVariant()") {
SECTION("Returns different pointer") {
ResourceManager resources(4096);
VariantSlot* s1 = new (&resources) VariantSlot();
VariantSlot* s1 = resources.allocVariant();
REQUIRE(s1 != 0);
VariantSlot* s2 = new (&resources) VariantSlot();
VariantSlot* s2 = resources.allocVariant();
REQUIRE(s2 != 0);
REQUIRE(s1 != s2);
@ -25,27 +25,27 @@ TEST_CASE("new (resources) VariantSlot()") {
SECTION("Returns aligned pointers") {
ResourceManager resources(4096);
REQUIRE(isAligned(new (&resources) VariantSlot()));
REQUIRE(isAligned(new (&resources) VariantSlot()));
REQUIRE(isAligned(resources.allocVariant()));
REQUIRE(isAligned(resources.allocVariant()));
}
SECTION("Returns zero if capacity is 0") {
ResourceManager resources(0);
REQUIRE(new (&resources) VariantSlot() == 0);
REQUIRE(resources.allocVariant() == 0);
}
SECTION("Returns zero if buffer is null") {
ResourceManager resources(4096, FailingAllocator::instance());
REQUIRE(new (&resources) VariantSlot() == 0);
REQUIRE(resources.allocVariant() == 0);
}
SECTION("Returns zero if capacity is insufficient") {
ResourceManager resources(sizeof(VariantSlot));
new (&resources) VariantSlot();
resources.allocVariant();
REQUIRE(new (&resources) VariantSlot() == 0);
REQUIRE(resources.allocVariant() == 0);
}
}