forked from bblanchon/ArduinoJson
Marked strdup()
as deprecated (issue #658)
This commit is contained in:
@ -104,3 +104,37 @@ TEST_CASE("Deprecated functions") {
|
||||
REQUIRE(123.45 == obj["hello"].as<double>());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("DynamicJsonBuffer::strdup()") {
|
||||
DynamicJsonBuffer buffer;
|
||||
|
||||
SECTION("char*") {
|
||||
char original[] = "hello";
|
||||
const char* copy = buffer.strdup(original);
|
||||
strcpy(original, "world");
|
||||
REQUIRE(std::string("hello") == copy);
|
||||
}
|
||||
|
||||
SECTION("unsigned char*") {
|
||||
unsigned char value[] = "world";
|
||||
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
const char* dup = jsonBuffer.strdup(value);
|
||||
|
||||
REQUIRE(static_cast<const void*>(value) != static_cast<const void*>(dup));
|
||||
REQUIRE(std::string("world") == dup);
|
||||
}
|
||||
|
||||
SECTION("std::string") {
|
||||
std::string original("hello");
|
||||
const char* copy = buffer.strdup(original);
|
||||
original[0] = 'w';
|
||||
REQUIRE(std::string("hello") == copy);
|
||||
}
|
||||
|
||||
SECTION("NULL") {
|
||||
const char* original = NULL;
|
||||
const char* copy = buffer.strdup(original);
|
||||
REQUIRE(0 == copy);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user