forked from bblanchon/ArduinoJson
Fixed return value of JsonObject::set()
(issue #350)
This commit is contained in:
@ -5,6 +5,7 @@ HEAD
|
|||||||
----
|
----
|
||||||
|
|
||||||
* Fixed `array[idx].as<JsonVariant>()` and `object[key].as<JsonVariant>()`
|
* Fixed `array[idx].as<JsonVariant>()` and `object[key].as<JsonVariant>()`
|
||||||
|
* Fixed return value of `JsonObject::set()` (issue #350)
|
||||||
|
|
||||||
v5.6.6
|
v5.6.6
|
||||||
------
|
------
|
||||||
|
@ -15,14 +15,16 @@ namespace ArduinoJson {
|
|||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline bool JsonObject::setNodeValue(node_type *node, String &value) {
|
inline bool JsonObject::setNodeValue(node_type *node, String &value) {
|
||||||
node->content.value = _buffer->strdup(value);
|
const char *dup = _buffer->strdup(value);
|
||||||
return node->content.value;
|
node->content.value = dup;
|
||||||
|
return dup;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline bool JsonObject::setNodeValue(node_type *node, const String &value) {
|
inline bool JsonObject::setNodeValue(node_type *node, const String &value) {
|
||||||
node->content.value = _buffer->strdup(value);
|
const char *dup = _buffer->strdup(value);
|
||||||
return node->content.value;
|
node->content.value = dup;
|
||||||
|
return dup;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@ -107,3 +107,21 @@ TEST_(StoreObjectSubscript) {
|
|||||||
|
|
||||||
EXPECT_EQ(42, _object["a"]);
|
EXPECT_EQ(42, _object["a"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_(ShouldReturnTrue_WhenAllocationSucceeds) {
|
||||||
|
StaticJsonBuffer<JSON_OBJECT_SIZE(1) + 15> jsonBuffer;
|
||||||
|
JsonObject& obj = jsonBuffer.createObject();
|
||||||
|
|
||||||
|
bool result = obj.set(String("hello"), String("world"));
|
||||||
|
|
||||||
|
ASSERT_TRUE(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_(ShouldReturnFalse_WhenAllocationFails) {
|
||||||
|
StaticJsonBuffer<JSON_OBJECT_SIZE(1) + 10> jsonBuffer;
|
||||||
|
JsonObject& obj = jsonBuffer.createObject();
|
||||||
|
|
||||||
|
bool result = obj.set(String("hello"), String("world"));
|
||||||
|
|
||||||
|
ASSERT_FALSE(result);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user