createObject.cpp 624 B

12345678910111213141516171819202122232425
  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. TEST_CASE("DynamicJsonBuffer::createObject()") {
  10. DynamicJsonBuffer json;
  11. JsonObject &obj = json.createObject();
  12. REQUIRE(JSON_OBJECT_SIZE(0) == json.size());
  13. obj["hello"] = 1;
  14. REQUIRE(JSON_OBJECT_SIZE(1) == json.size());
  15. obj["world"] = 2;
  16. REQUIRE(JSON_OBJECT_SIZE(2) == json.size());
  17. obj["world"] = 3; // <- same key, should not grow
  18. REQUIRE(JSON_OBJECT_SIZE(2) == json.size());
  19. }