Files
ArduinoJson/extras/tests/MemoryPool/allocVariant.cpp
T

52 lines
1.2 KiB
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/MemoryPool.hpp>
2023-05-22 17:43:50 +02:00
#include <ArduinoJson/Variant/VariantSlot.hpp>
#include <catch.hpp>
2023-03-20 12:28:34 +01:00
#include "Allocators.hpp"
using namespace ArduinoJson::detail;
2023-05-22 17:43:50 +02:00
TEST_CASE("new (pool) VariantSlot()") {
SECTION("Returns different pointer") {
2023-03-20 12:28:34 +01:00
MemoryPool pool(4096);
2023-05-22 17:43:50 +02:00
VariantSlot* s1 = new (&pool) VariantSlot();
REQUIRE(s1 != 0);
2023-05-22 17:43:50 +02:00
VariantSlot* s2 = new (&pool) VariantSlot();
REQUIRE(s2 != 0);
REQUIRE(s1 != s2);
}
SECTION("Returns aligned pointers") {
2023-03-20 12:28:34 +01:00
MemoryPool pool(4096);
2023-05-22 17:43:50 +02:00
REQUIRE(isAligned(new (&pool) VariantSlot()));
REQUIRE(isAligned(new (&pool) VariantSlot()));
}
SECTION("Returns zero if capacity is 0") {
2023-03-20 12:28:34 +01:00
MemoryPool pool(0);
2023-05-22 17:43:50 +02:00
REQUIRE(new (&pool) VariantSlot() == 0);
}
SECTION("Returns zero if buffer is null") {
2023-03-20 12:28:34 +01:00
MemoryPool pool(4096, FailingAllocator::instance());
2023-05-22 17:43:50 +02:00
REQUIRE(new (&pool) VariantSlot() == 0);
}
SECTION("Returns zero if capacity is insufficient") {
2023-03-20 12:28:34 +01:00
MemoryPool pool(sizeof(VariantSlot));
2023-05-22 17:43:50 +02:00
new (&pool) VariantSlot();
2023-05-22 17:43:50 +02:00
REQUIRE(new (&pool) VariantSlot() == 0);
}
}