startString.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. typedef StaticMemoryPoolBase::StringBuilder StringBuilder;
  9. SECTION("WorksWhenBufferIsBigEnough") {
  10. StaticMemoryPool<6> memoryPool;
  11. StringBuilder str = memoryPool.startString();
  12. str.append('h');
  13. str.append('e');
  14. str.append('l');
  15. str.append('l');
  16. str.append('o');
  17. REQUIRE(str.complete().equals("hello"));
  18. }
  19. SECTION("ReturnsNullWhenTooSmall") {
  20. StaticMemoryPool<5> memoryPool;
  21. StringBuilder str = memoryPool.startString();
  22. str.append('h');
  23. str.append('e');
  24. str.append('l');
  25. str.append('l');
  26. str.append('o');
  27. REQUIRE(str.complete().isNull());
  28. }
  29. SECTION("SizeIncreases") {
  30. StaticMemoryPool<5> memoryPool;
  31. StringBuilder str = memoryPool.startString();
  32. REQUIRE(0 == memoryPool.size());
  33. str.append('h');
  34. REQUIRE(1 == memoryPool.size());
  35. str.complete();
  36. REQUIRE(2 == memoryPool.size());
  37. }
  38. }