clear.cpp 715 B

123456789101112131415161718192021222324252627282930313233
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2021
  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. }