clear.cpp 726 B

1234567891011121314151617181920212223242526272829303132
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, 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_NAMESPACE;
  8. static const size_t poolCapacity = 512;
  9. TEST_CASE("MemoryPool::clear()") {
  10. char buffer[poolCapacity];
  11. MemoryPool pool(buffer, sizeof(buffer));
  12. SECTION("Discards allocated variants") {
  13. pool.allocVariant();
  14. pool.clear();
  15. REQUIRE(pool.size() == 0);
  16. }
  17. SECTION("Discards allocated strings") {
  18. pool.saveString(adaptString(const_cast<char*>("123456789")));
  19. REQUIRE(pool.size() == 10);
  20. pool.clear();
  21. REQUIRE(pool.size() == 0);
  22. }
  23. }