clear.cpp 679 B

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