startString.cpp 983 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_NAMESPACE;
  7. TEST_CASE("StaticMemoryPool::startString()") {
  8. SECTION("WorksWhenBufferIsBigEnough") {
  9. StaticMemoryPool<6> memoryPool;
  10. StringBuilder 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(str.complete().equals("hello"));
  17. }
  18. SECTION("ReturnsNullWhenTooSmall") {
  19. StaticMemoryPool<5> memoryPool;
  20. StringBuilder 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(str.complete().isNull());
  27. }
  28. SECTION("SizeIncreases") {
  29. StaticMemoryPool<5> memoryPool;
  30. StringBuilder str = memoryPool.startString();
  31. str.append('h');
  32. str.complete();
  33. REQUIRE(2 == memoryPool.size());
  34. }
  35. }