size.cpp 971 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson/Memory/StaticJsonBuffer.hpp>
  5. #include <catch.hpp>
  6. using namespace ArduinoJson::Internals;
  7. TEST_CASE("StaticJsonBuffer::size()") {
  8. StaticJsonBuffer<64> buffer;
  9. SECTION("Capacity equals template parameter") {
  10. REQUIRE(64 == buffer.capacity());
  11. }
  12. SECTION("Initial size is 0") {
  13. REQUIRE(0 == buffer.size());
  14. }
  15. SECTION("Increases after alloc()") {
  16. buffer.alloc(1);
  17. REQUIRE(1U <= buffer.size());
  18. buffer.alloc(1);
  19. REQUIRE(2U <= buffer.size());
  20. }
  21. SECTION("Doesn't grow when buffer is full") {
  22. buffer.alloc(64);
  23. buffer.alloc(1);
  24. REQUIRE(64 == buffer.size());
  25. }
  26. SECTION("Does't grow when buffer is too small for alloc") {
  27. buffer.alloc(65);
  28. REQUIRE(0 == buffer.size());
  29. }
  30. SECTION("Goes back to zero after clear()") {
  31. buffer.alloc(1);
  32. buffer.clear();
  33. REQUIRE(0 == buffer.size());
  34. }
  35. }