createObject.cpp 538 B

12345678910111213141516171819202122
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2023
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("DynamicJsonBuffer::createObject()") {
  7. DynamicJsonBuffer json;
  8. JsonObject &obj = json.createObject();
  9. REQUIRE(JSON_OBJECT_SIZE(0) == json.size());
  10. obj["hello"] = 1;
  11. REQUIRE(JSON_OBJECT_SIZE(1) == json.size());
  12. obj["world"] = 2;
  13. REQUIRE(JSON_OBJECT_SIZE(2) == json.size());
  14. obj["world"] = 3; // <- same key, should not grow
  15. REQUIRE(JSON_OBJECT_SIZE(2) == json.size());
  16. }