StringBuilder.cpp 986 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. using namespace ArduinoJson::Internals;
  10. TEST_CASE("StringBuilder") {
  11. char output[20];
  12. StaticStringBuilder sb(output, sizeof(output));
  13. SECTION("InitialState") {
  14. REQUIRE(std::string("") == output);
  15. }
  16. SECTION("OverCapacity") {
  17. REQUIRE(19 == sb.print("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
  18. REQUIRE(0 == sb.print("ABC"));
  19. REQUIRE(std::string("ABCDEFGHIJKLMNOPQRS") == output);
  20. }
  21. SECTION("EmptyString") {
  22. REQUIRE(0 == sb.print(""));
  23. REQUIRE(std::string("") == output);
  24. }
  25. SECTION("OneString") {
  26. REQUIRE(4 == sb.print("ABCD"));
  27. REQUIRE(std::string("ABCD") == output);
  28. }
  29. SECTION("TwoStrings") {
  30. REQUIRE(4 == sb.print("ABCD"));
  31. REQUIRE(4 == sb.print("EFGH"));
  32. REQUIRE(std::string("ABCDEFGH") == output);
  33. }
  34. }