StringBuilder.cpp 910 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson/Memory/StaticMemoryPool.hpp>
  5. #include <ArduinoJson/Memory/StringBuilder.hpp>
  6. #include <catch.hpp>
  7. using namespace ARDUINOJSON_NAMESPACE;
  8. TEST_CASE("StringBuilder") {
  9. SECTION("WorksWhenBufferIsBigEnough") {
  10. StaticMemoryPool<JSON_STRING_SIZE(6)> memoryPool;
  11. StringBuilder str(&memoryPool);
  12. str.append("hello");
  13. REQUIRE(str.complete().equals("hello"));
  14. }
  15. SECTION("ReturnsNullWhenTooSmall") {
  16. StaticMemoryPool<1> memoryPool;
  17. StringBuilder str(&memoryPool);
  18. str.append("hello!!!");
  19. REQUIRE(str.complete().isNull());
  20. }
  21. SECTION("Increases size of memory pool") {
  22. StaticMemoryPool<JSON_STRING_SIZE(6)> memoryPool;
  23. StringBuilder str(&memoryPool);
  24. str.append('h');
  25. str.complete();
  26. REQUIRE(JSON_STRING_SIZE(2) == memoryPool.size());
  27. }
  28. }