allocVariant.cpp 959 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson/Memory/StaticMemoryPool.hpp>
  5. #include <catch.hpp>
  6. using namespace ARDUINOJSON_NAMESPACE;
  7. TEST_CASE("StaticMemoryPool::allocVariant()") {
  8. StaticMemoryPool<128> memoryPool;
  9. SECTION("Returns different pointer") {
  10. VariantSlot* s1 = memoryPool.allocVariant();
  11. REQUIRE(s1 != 0);
  12. VariantSlot* s2 = memoryPool.allocVariant();
  13. REQUIRE(s2 != 0);
  14. REQUIRE(s1 != s2);
  15. }
  16. SECTION("Returns same pointer after freeSlot()") {
  17. VariantSlot* s1 = memoryPool.allocVariant();
  18. memoryPool.freeVariant(s1);
  19. VariantSlot* s2 = memoryPool.allocVariant();
  20. REQUIRE(s1 == s2);
  21. }
  22. SECTION("Returns aligned pointers") {
  23. // make room for two
  24. // pass an uneven capacity
  25. StaticMemoryPool<2 * sizeof(VariantSlot) + 1> pool;
  26. REQUIRE(isAligned(pool.allocVariant()));
  27. REQUIRE(isAligned(pool.allocVariant()));
  28. }
  29. }