startString.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. using namespace ArduinoJson::Internals;
  7. TEST_CASE("StaticMemoryPool::startString()") {
  8. SECTION("WorksWhenBufferIsBigEnough") {
  9. StaticMemoryPool<6> memoryPool;
  10. StaticMemoryPoolBase::String str = memoryPool.startString();
  11. str.append('h');
  12. str.append('e');
  13. str.append('l');
  14. str.append('l');
  15. str.append('o');
  16. REQUIRE(std::string("hello") == str.c_str());
  17. }
  18. SECTION("ReturnsNullWhenTooSmall") {
  19. StaticMemoryPool<5> memoryPool;
  20. StaticMemoryPoolBase::String str = memoryPool.startString();
  21. str.append('h');
  22. str.append('e');
  23. str.append('l');
  24. str.append('l');
  25. str.append('o');
  26. REQUIRE(0 == str.c_str());
  27. }
  28. SECTION("SizeIncreases") {
  29. StaticMemoryPool<5> memoryPool;
  30. StaticMemoryPoolBase::String str = memoryPool.startString();
  31. REQUIRE(0 == memoryPool.size());
  32. str.append('h');
  33. REQUIRE(1 == memoryPool.size());
  34. str.c_str();
  35. REQUIRE(2 == memoryPool.size());
  36. }
  37. }