clear.cpp 784 B

1234567891011121314151617181920212223242526272829303132
  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 <ArduinoJson/Strings/StringAdapters.hpp>
  7. #include <catch.hpp>
  8. using namespace ArduinoJson::detail;
  9. static const size_t poolCapacity = 512;
  10. TEST_CASE("ResourceManager::clear()") {
  11. ResourceManager resources(poolCapacity);
  12. SECTION("Discards allocated variants") {
  13. resources.allocVariant();
  14. resources.clear();
  15. REQUIRE(resources.size() == 0);
  16. }
  17. SECTION("Discards allocated strings") {
  18. resources.saveString(adaptString("123456789"));
  19. REQUIRE(resources.size() == sizeofString(9));
  20. resources.clear();
  21. REQUIRE(resources.size() == 0);
  22. }
  23. }