size.cpp 839 B

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