forked from bblanchon/ArduinoJson
ResourceManager: replace allocFromPool()
with allocVariant()
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ TEST_CASE("ResourceManager::clear()") {
|
||||
ResourceManager resources(poolCapacity);
|
||||
|
||||
SECTION("Discards allocated variants") {
|
||||
new (&resources) VariantSlot();
|
||||
resources.allocVariant();
|
||||
|
||||
resources.clear();
|
||||
REQUIRE(resources.size() == 0);
|
||||
|
@ -25,10 +25,10 @@ TEST_CASE("ResourceManager::size()") {
|
||||
const size_t variantCount = resources.capacity() / sizeof(VariantSlot);
|
||||
|
||||
for (size_t i = 0; i < variantCount; i++)
|
||||
new (&resources) VariantSlot();
|
||||
resources.allocVariant();
|
||||
size_t size = resources.size();
|
||||
|
||||
new (&resources) VariantSlot();
|
||||
resources.allocVariant();
|
||||
|
||||
REQUIRE(size == resources.size());
|
||||
}
|
||||
|
Reference in New Issue
Block a user