Files
ArduinoJson/extras/tests/MemoryPool/size.cpp

36 lines
829 B
C++
Raw Normal View History

// ArduinoJson - https://arduinojson.org
2023-02-16 11:45:01 +01:00
// Copyright © 2014-2023, Benoit BLANCHON
2018-09-03 16:14:21 +02:00
// MIT License
#include <ArduinoJson/Memory/MemoryPool.hpp>
#include <ArduinoJson/Variant/VariantSlot.hpp>
2018-09-03 16:14:21 +02:00
#include <catch.hpp>
using namespace ArduinoJson::detail;
2018-09-03 16:14:21 +02:00
TEST_CASE("MemoryPool::capacity()") {
const size_t capacity = 64;
MemoryPool pool(capacity);
REQUIRE(capacity == pool.capacity());
}
TEST_CASE("MemoryPool::size()") {
MemoryPool pool(4096);
2018-09-03 16:14:21 +02:00
SECTION("Initial size is 0") {
REQUIRE(0 == pool.size());
2018-09-03 16:14:21 +02:00
}
SECTION("Doesn't grow when memory pool is full") {
const size_t variantCount = pool.capacity() / sizeof(VariantSlot);
for (size_t i = 0; i < variantCount; i++)
new (&pool) VariantSlot();
size_t size = pool.size();
new (&pool) VariantSlot();
REQUIRE(size == pool.size());
2018-09-03 16:14:21 +02:00
}
}