mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 00:38:27 +01:00
Test null
This commit is contained in:
@@ -50,4 +50,28 @@ TEST_CASE("JsonVariant::link()") {
|
||||
|
||||
CHECK(variant.as<std::string>() == "{\"hello\":\"WORLD!\"}");
|
||||
}
|
||||
|
||||
SECTION("target is unbound") {
|
||||
JsonVariant unbound;
|
||||
variant["hello"] = "world";
|
||||
|
||||
variant.link(unbound);
|
||||
|
||||
CHECK(variant.isUnbound() == false);
|
||||
CHECK(variant.isNull() == true);
|
||||
CHECK(variant.memoryUsage() == 0);
|
||||
CHECK(variant.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("variant is unbound") {
|
||||
JsonVariant unbound;
|
||||
doc2["hello"] = "world";
|
||||
|
||||
unbound.link(doc2);
|
||||
|
||||
CHECK(unbound.isUnbound() == true);
|
||||
CHECK(unbound.isNull() == true);
|
||||
CHECK(unbound.memoryUsage() == 0);
|
||||
CHECK(unbound.size() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,9 +244,10 @@ class VariantData {
|
||||
setType(VALUE_IS_NULL);
|
||||
}
|
||||
|
||||
void setPointer(const VariantData *value) {
|
||||
void setPointer(const VariantData *p) {
|
||||
ARDUINOJSON_ASSERT(p);
|
||||
setType(VALUE_IS_POINTER);
|
||||
_content.asPointer = value;
|
||||
_content.asPointer = p;
|
||||
}
|
||||
|
||||
void setString(String s) {
|
||||
|
||||
@@ -189,9 +189,13 @@ bool CopyStringStoragePolicy::store(TAdaptedString str, MemoryPool *pool,
|
||||
return copy != 0;
|
||||
}
|
||||
|
||||
inline void VariantRef::link(VariantConstRef var) {
|
||||
if (_data)
|
||||
_data->setPointer(var._data);
|
||||
inline void VariantRef::link(VariantConstRef target) {
|
||||
if (!_data)
|
||||
return;
|
||||
if (target._data)
|
||||
_data->setPointer(target._data);
|
||||
else
|
||||
_data->setNull();
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user