size.cpp 724 B

12345678910111213141516171819202122232425262728293031
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2025, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson/Memory/ResourceManager.hpp>
  5. #include <catch.hpp>
  6. #include "Allocators.hpp"
  7. using namespace ArduinoJson::detail;
  8. TEST_CASE("ResourceManager::size()") {
  9. TimebombAllocator timebomb(0);
  10. ResourceManager resources(&timebomb);
  11. SECTION("Initial size is 0") {
  12. REQUIRE(0 == resources.size());
  13. }
  14. SECTION("Doesn't grow when allocation of second pool fails") {
  15. timebomb.setCountdown(1);
  16. for (size_t i = 0; i < ARDUINOJSON_POOL_CAPACITY; i++)
  17. resources.allocVariant();
  18. size_t size = resources.size();
  19. resources.allocVariant();
  20. REQUIRE(size == resources.size());
  21. }
  22. }