size.cpp 904 B

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