// ArduinoJson - https://arduinojson.org // Copyright Benoit Blanchon 2014-2021 // MIT License #include #include TEST_CASE("deserialize JSON object with StaticJsonDocument") { SECTION("BufferOfTheRightSizeForEmptyObject") { StaticJsonDocument doc; char input[] = "{}"; DeserializationError err = deserializeJson(doc, input); REQUIRE(err == DeserializationError::Ok); } SECTION("TooSmallBufferForObjectWithOneValue") { StaticJsonDocument doc; char input[] = "{\"a\":1}"; DeserializationError err = deserializeJson(doc, input); REQUIRE(err == DeserializationError::NoMemory); } SECTION("BufferOfTheRightSizeForObjectWithOneValue") { StaticJsonDocument doc; char input[] = "{\"a\":1}"; DeserializationError err = deserializeJson(doc, input); REQUIRE(err == DeserializationError::Ok); } SECTION("TooSmallBufferForObjectWithNestedObject") { StaticJsonDocument doc; char input[] = "{\"a\":[]}"; DeserializationError err = deserializeJson(doc, input); REQUIRE(err == DeserializationError::NoMemory); } SECTION("BufferOfTheRightSizeForObjectWithNestedObject") { StaticJsonDocument doc; char input[] = "{\"a\":[]}"; DeserializationError err = deserializeJson(doc, input); REQUIRE(err == DeserializationError::Ok); } SECTION("Should clear the JsonObject") { StaticJsonDocument doc; char input[] = "{\"hello\":\"world\"}"; deserializeJson(doc, input); deserializeJson(doc, "{}"); REQUIRE(doc.as().size() == 0); REQUIRE(doc.memoryUsage() == JSON_OBJECT_SIZE(0)); } }