clear.cpp 733 B

123456789101112131415161718192021222324252627282930
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2024, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson/Memory/ResourceManager.hpp>
  5. #include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
  6. #include <ArduinoJson/Strings/StringAdapters.hpp>
  7. #include <catch.hpp>
  8. using namespace ArduinoJson::detail;
  9. TEST_CASE("ResourceManager::clear()") {
  10. ResourceManager resources;
  11. SECTION("Discards allocated variants") {
  12. resources.allocVariant();
  13. resources.clear();
  14. REQUIRE(resources.size() == 0);
  15. }
  16. SECTION("Discards allocated strings") {
  17. resources.saveString(adaptString("123456789"));
  18. REQUIRE(resources.size() == sizeofString(9));
  19. resources.clear();
  20. REQUIRE(resources.size() == 0);
  21. }
  22. }