clear.cpp 628 B

12345678910111213141516171819202122232425262728293031
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2019
  3. // MIT License
  4. #include <ArduinoJson/Memory/MemoryPool.hpp>
  5. #include <catch.hpp>
  6. using namespace ARDUINOJSON_NAMESPACE;
  7. static const size_t poolCapacity = 512;
  8. TEST_CASE("MemoryPool::clear()") {
  9. char buffer[poolCapacity];
  10. MemoryPool pool(buffer, sizeof(buffer));
  11. SECTION("Discards allocated variants") {
  12. pool.allocVariant();
  13. pool.clear();
  14. REQUIRE(pool.size() == 0);
  15. }
  16. SECTION("Discards allocated strings") {
  17. pool.allocFrozenString(10);
  18. REQUIRE(pool.size() > 0);
  19. pool.clear();
  20. REQUIRE(pool.size() == 0);
  21. }
  22. }