size.cpp 777 B

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