size.cpp 821 B

1234567891011121314151617181920212223242526272829303132333435
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2020
  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++) pool.allocVariant();
  22. size_t size = pool.size();
  23. pool.allocVariant();
  24. REQUIRE(size == pool.size());
  25. }
  26. }