startString.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2023
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. using namespace ArduinoJson::Internals;
  7. TEST_CASE("StaticJsonBuffer::startString()") {
  8. SECTION("WorksWhenBufferIsBigEnough") {
  9. StaticJsonBuffer<6> jsonBuffer;
  10. StaticJsonBufferBase::String str = jsonBuffer.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. StaticJsonBuffer<5> jsonBuffer;
  20. StaticJsonBufferBase::String str = jsonBuffer.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. StaticJsonBuffer<5> jsonBuffer;
  30. StaticJsonBufferBase::String str = jsonBuffer.startString();
  31. REQUIRE(0 == jsonBuffer.size());
  32. str.append('h');
  33. REQUIRE(1 == jsonBuffer.size());
  34. str.c_str();
  35. REQUIRE(2 == jsonBuffer.size());
  36. }
  37. }