allocString.cpp 729 B

12345678910111213141516171819202122232425262728
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson/Memory/DynamicMemoryPool.hpp>
  5. #include <catch.hpp>
  6. #include <sstream>
  7. using namespace ARDUINOJSON_NAMESPACE;
  8. TEST_CASE("DynamicMemoryPool::allocFrozenString()") {
  9. DynamicMemoryPool pool;
  10. SECTION("Returns different pointers") {
  11. StringSlot* a = pool.allocFrozenString(1);
  12. StringSlot* b = pool.allocFrozenString(2);
  13. REQUIRE(a != b);
  14. REQUIRE(a->value != b->value);
  15. }
  16. SECTION("Returns same slot after freeString") {
  17. StringSlot* a = pool.allocFrozenString(1);
  18. pool.freeString(a);
  19. StringSlot* b = pool.allocFrozenString(2);
  20. REQUIRE(a == b);
  21. REQUIRE(a->value == b->value);
  22. }
  23. }