size.cpp 890 B

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