Change string copy policy: only string literal are stored by pointer

This commit is contained in:
Benoit Blanchon
2024-11-25 11:32:03 +01:00
parent 5f8e3c0f0f
commit 594dc707cb
27 changed files with 456 additions and 197 deletions

View File

@ -26,7 +26,7 @@ TEST_CASE("JsonDocument::add(T)") {
});
}
SECTION("const char*") {
SECTION("string literal") {
doc.add("hello");
REQUIRE(doc.as<std::string>() == "[\"hello\"]");
@ -35,6 +35,17 @@ TEST_CASE("JsonDocument::add(T)") {
});
}
SECTION("const char*") {
const char* value = "hello";
doc.add(value);
REQUIRE(doc.as<std::string>() == "[\"hello\"]");
REQUIRE(spy.log() == AllocatorLog{
Allocate(sizeofPool()),
Allocate(sizeofString("hello")),
});
}
SECTION("std::string") {
doc.add("example"_s);
doc.add("example"_s);