startString.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson/Memory/DynamicMemoryPool.hpp>
  5. #include <catch.hpp>
  6. using namespace ARDUINOJSON_NAMESPACE;
  7. TEST_CASE("DynamicMemoryPool::startString()") {
  8. SECTION("WorksWhenBufferIsBigEnough") {
  9. DynamicMemoryPool memoryPool(6);
  10. DynamicMemoryPool::String str = memoryPool.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("GrowsWhenBufferIsTooSmall") {
  19. DynamicMemoryPool memoryPool(5);
  20. DynamicMemoryPool::String str = memoryPool.startString();
  21. str.append('h');
  22. str.append('e');
  23. str.append('l');
  24. str.append('l');
  25. str.append('o');
  26. REQUIRE(std::string("hello") == str.c_str());
  27. }
  28. SECTION("SizeIncreases") {
  29. DynamicMemoryPool memoryPool(5);
  30. DynamicMemoryPool::String str = memoryPool.startString();
  31. REQUIRE(0 == memoryPool.size());
  32. str.append('h');
  33. REQUIRE(1 == memoryPool.size());
  34. str.c_str();
  35. REQUIRE(2 == memoryPool.size());
  36. }
  37. }