StaticJsonBuffer_Object_Tests.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright Benoit Blanchon 2014
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. #include <gtest/gtest.h>
  7. #include <ArduinoJson/JsonObject.hpp>
  8. #include <ArduinoJson/StaticJsonBuffer.hpp>
  9. using namespace ArduinoJson;
  10. TEST(StaticJsonBuffer_Object_Tests, GrowsWithObject) {
  11. StaticJsonBuffer<JSON_OBJECT_SIZE(3)> json;
  12. JsonObject &obj = json.createObject();
  13. ASSERT_EQ(JSON_OBJECT_SIZE(0), json.size());
  14. obj["hello"];
  15. ASSERT_EQ(JSON_OBJECT_SIZE(1), json.size());
  16. obj["world"];
  17. ASSERT_EQ(JSON_OBJECT_SIZE(2), json.size());
  18. obj["world"]; // <- same value, should not grow
  19. ASSERT_EQ(JSON_OBJECT_SIZE(2), json.size());
  20. }
  21. TEST(StaticJsonBuffer_Object_Tests, SucceedWhenBigEnough) {
  22. StaticJsonBuffer<JSON_OBJECT_SIZE(0)> json;
  23. JsonObject &object = json.createObject();
  24. ASSERT_TRUE(object.success());
  25. }
  26. TEST(StaticJsonBuffer_Object_Tests, FailsWhenTooSmall) {
  27. StaticJsonBuffer<JSON_OBJECT_SIZE(0) - 1> json;
  28. JsonObject &object = json.createObject();
  29. ASSERT_FALSE(object.success());
  30. }