Add memoryUsage() to ElementProxy and MemberProxy (fixes #1730)

This commit is contained in:
Benoit Blanchon
2022-03-19 12:11:40 +01:00
parent 47f90b02c3
commit 3dc67c5663
6 changed files with 65 additions and 0 deletions

View File

@ -229,6 +229,20 @@ TEST_CASE("MemberProxy::size()") {
}
}
TEST_CASE("MemberProxy::memoryUsage()") {
DynamicJsonDocument doc(4096);
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
SECTION("returns 0 when null") {
REQUIRE(mp.memoryUsage() == 0);
}
SECTION("return the size for a string") {
mp.set(std::string("hello"));
REQUIRE(mp.memoryUsage() == 6);
}
}
TEST_CASE("MemberProxy::operator[]") {
DynamicJsonDocument doc(4096);
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];