size.cpp 829 B

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