forked from bblanchon/ArduinoJson
Always store serialized("string")
by copy (#1915)
This commit is contained in:
@ -115,9 +115,9 @@ TEST_CASE("JsonArray::add()") {
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should not duplicate serialized(const char*)") {
|
||||
SECTION("should duplicate serialized(const char*)") {
|
||||
array.add(serialized("{}"));
|
||||
const size_t expectedSize = sizeofArray(1);
|
||||
const size_t expectedSize = sizeofArray(1) + sizeofString(2);
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
|
@ -97,17 +97,6 @@ TEST_CASE("JsonDocument::shrinkToFit()") {
|
||||
<< AllocatorLog::Reallocate(4096, 0));
|
||||
}
|
||||
|
||||
SECTION("linked raw") {
|
||||
doc.set(serialized("[{},123]"));
|
||||
|
||||
doc.shrinkToFit();
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "[{},123]");
|
||||
REQUIRE(spyingAllocator.log() == AllocatorLog()
|
||||
<< AllocatorLog::Allocate(4096)
|
||||
<< AllocatorLog::Reallocate(4096, 0));
|
||||
}
|
||||
|
||||
SECTION("owned raw") {
|
||||
doc.set(serialized(std::string("[{},12]")));
|
||||
|
||||
|
@ -89,15 +89,16 @@ TEST_CASE("JsonVariant::set(JsonVariant)") {
|
||||
AllocatorLog() << AllocatorLog::Allocate(sizeofString((7))));
|
||||
}
|
||||
|
||||
SECTION("stores Serialized<const char*> by reference") {
|
||||
var1.set(serialized("hello!!", 8));
|
||||
SECTION("stores Serialized<const char*> by copy") {
|
||||
var1.set(serialized("hello!!", 7));
|
||||
spyingAllocator.clearLog();
|
||||
|
||||
var2.set(var1);
|
||||
|
||||
REQUIRE(doc1.memoryUsage() == 0);
|
||||
REQUIRE(doc2.memoryUsage() == 0);
|
||||
REQUIRE(spyingAllocator.log() == AllocatorLog());
|
||||
REQUIRE(doc1.memoryUsage() == sizeofString(7));
|
||||
REQUIRE(doc2.memoryUsage() == sizeofString(7));
|
||||
REQUIRE(spyingAllocator.log() ==
|
||||
AllocatorLog() << AllocatorLog::Allocate(sizeofString((7))));
|
||||
}
|
||||
|
||||
SECTION("stores Serialized<char*> by copy") {
|
||||
|
@ -205,6 +205,6 @@ TEST_CASE("JsonVariant::set() releases the previous value") {
|
||||
|
||||
SECTION("Serialized<const char*>") {
|
||||
v.set(serialized("[]"));
|
||||
REQUIRE(doc.memoryUsage() == sizeofObject(1));
|
||||
REQUIRE(doc.memoryUsage() == sizeofObject(1) + sizeofString(2));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user