size.cpp 770 B

12345678910111213141516171819202122232425262728293031323334
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2023, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson/Memory/MemoryPool.hpp>
  5. #include <catch.hpp>
  6. using namespace ArduinoJson::detail;
  7. TEST_CASE("MemoryPool::capacity()") {
  8. const size_t capacity = 64;
  9. MemoryPool pool(capacity);
  10. REQUIRE(capacity == pool.capacity());
  11. }
  12. TEST_CASE("MemoryPool::size()") {
  13. MemoryPool pool(4096);
  14. SECTION("Initial size is 0") {
  15. REQUIRE(0 == pool.size());
  16. }
  17. SECTION("Doesn't grow when memory pool is full") {
  18. const size_t variantCount = pool.capacity() / sizeof(VariantSlot);
  19. for (size_t i = 0; i < variantCount; i++)
  20. pool.allocVariant();
  21. size_t size = pool.size();
  22. pool.allocVariant();
  23. REQUIRE(size == pool.size());
  24. }
  25. }