mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-11-02 15:41:37 +01:00
Change string copy policy: only string literal are stored by pointer
This commit is contained in:
@@ -11,6 +11,21 @@ TEST_CASE("JsonDocument::set()") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
|
||||
SECTION("nullptr") {
|
||||
doc.set(nullptr);
|
||||
|
||||
REQUIRE(doc.isNull());
|
||||
REQUIRE(spy.log() == AllocatorLog{});
|
||||
}
|
||||
|
||||
SECTION("integer&") {
|
||||
int toto = 42;
|
||||
doc.set(toto);
|
||||
|
||||
REQUIRE(doc.as<std::string>() == "42");
|
||||
REQUIRE(spy.log() == AllocatorLog{});
|
||||
}
|
||||
|
||||
SECTION("integer") {
|
||||
doc.set(42);
|
||||
|
||||
@@ -18,13 +33,23 @@ TEST_CASE("JsonDocument::set()") {
|
||||
REQUIRE(spy.log() == AllocatorLog{});
|
||||
}
|
||||
|
||||
SECTION("const char*") {
|
||||
SECTION("string literal") {
|
||||
doc.set("example");
|
||||
|
||||
REQUIRE(doc.as<const char*>() == "example"_s);
|
||||
REQUIRE(spy.log() == AllocatorLog{});
|
||||
}
|
||||
|
||||
SECTION("const char*") {
|
||||
const char* value = "example";
|
||||
doc.set(value);
|
||||
|
||||
REQUIRE(doc.as<const char*>() == "example"_s);
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofString("example")),
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("std::string") {
|
||||
doc.set("example"_s);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user