startString.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright Benoit Blanchon 2014-2017
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://bblanchon.github.io/ArduinoJson/
  6. // If you like this project, please add a star!
  7. #include <ArduinoJson.h>
  8. #include <catch.hpp>
  9. TEST_CASE("StaticJsonBuffer::startString()") {
  10. SECTION("WorksWhenBufferIsBigEnough") {
  11. StaticJsonBuffer<6> jsonBuffer;
  12. StaticJsonBufferBase::String str = jsonBuffer.startString();
  13. str.append('h');
  14. str.append('e');
  15. str.append('l');
  16. str.append('l');
  17. str.append('o');
  18. REQUIRE(std::string("hello") == str.c_str());
  19. }
  20. SECTION("ReturnsNullWhenTooSmall") {
  21. StaticJsonBuffer<5> jsonBuffer;
  22. StaticJsonBufferBase::String str = jsonBuffer.startString();
  23. str.append('h');
  24. str.append('e');
  25. str.append('l');
  26. str.append('l');
  27. str.append('o');
  28. REQUIRE(0 == str.c_str());
  29. }
  30. SECTION("SizeIncreases") {
  31. StaticJsonBuffer<5> jsonBuffer;
  32. StaticJsonBufferBase::String str = jsonBuffer.startString();
  33. REQUIRE(0 == jsonBuffer.size());
  34. str.append('h');
  35. REQUIRE(1 == jsonBuffer.size());
  36. str.c_str();
  37. REQUIRE(2 == jsonBuffer.size());
  38. }
  39. }