forked from bblanchon/ArduinoJson
Increase coverage
This commit is contained in:
@ -44,6 +44,7 @@ TEST_CASE("Unbound JsonVariant") {
|
|||||||
CHECK_FALSE(variant.set(42L));
|
CHECK_FALSE(variant.set(42L));
|
||||||
CHECK_FALSE(variant.set(42U));
|
CHECK_FALSE(variant.set(42U));
|
||||||
CHECK_FALSE(variant.set(serialized("42")));
|
CHECK_FALSE(variant.set(serialized("42")));
|
||||||
|
CHECK_FALSE(variant.set(serialized(std::string("42"))));
|
||||||
CHECK_FALSE(variant.set(true));
|
CHECK_FALSE(variant.set(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,4 +64,13 @@ TEST_CASE("Unbound JsonVariant") {
|
|||||||
CHECK_FALSE(variant["key"].set(1));
|
CHECK_FALSE(variant["key"].set(1));
|
||||||
CHECK_FALSE(variant[std::string("key")].set(1));
|
CHECK_FALSE(variant[std::string("key")].set(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("containsKey()") {
|
||||||
|
CHECK_FALSE(variant.containsKey("hello"));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("remove()") {
|
||||||
|
variant.remove(0);
|
||||||
|
variant.remove("hello");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,6 @@ inline VariantData* collectionAddMember(CollectionData* obj, TAdaptedString key,
|
|||||||
MemoryPool* pool) {
|
MemoryPool* pool) {
|
||||||
ARDUINOJSON_ASSERT(!key.isNull());
|
ARDUINOJSON_ASSERT(!key.isNull());
|
||||||
ARDUINOJSON_ASSERT(obj != nullptr);
|
ARDUINOJSON_ASSERT(obj != nullptr);
|
||||||
if (!obj)
|
|
||||||
return nullptr;
|
|
||||||
auto slot = pool->allocVariant();
|
auto slot = pool->allocVariant();
|
||||||
if (!slot)
|
if (!slot)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -67,6 +65,14 @@ inline bool collectionCopy(CollectionData* dst, const CollectionData* src,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename TAdaptedString>
|
||||||
|
inline VariantData* collectionGetMember(const CollectionData* obj,
|
||||||
|
TAdaptedString key) {
|
||||||
|
if (!obj)
|
||||||
|
return nullptr;
|
||||||
|
return slotData(obj->get(key));
|
||||||
|
}
|
||||||
|
|
||||||
inline void collectionRemove(CollectionData* data, VariantSlot* slot,
|
inline void collectionRemove(CollectionData* data, VariantSlot* slot,
|
||||||
MemoryPool* pool) {
|
MemoryPool* pool) {
|
||||||
if (!data || !slot)
|
if (!data || !slot)
|
||||||
|
@ -59,8 +59,7 @@ inline VariantSlot* CollectionData::getPrevious(VariantSlot* target) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void CollectionData::remove(VariantSlot* slot) {
|
inline void CollectionData::remove(VariantSlot* slot) {
|
||||||
if (!slot)
|
ARDUINOJSON_ASSERT(slot != nullptr);
|
||||||
return;
|
|
||||||
VariantSlot* prev = getPrevious(slot);
|
VariantSlot* prev = getPrevious(slot);
|
||||||
VariantSlot* next = slot->next();
|
VariantSlot* next = slot->next();
|
||||||
if (prev)
|
if (prev)
|
||||||
|
@ -150,7 +150,7 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
|||||||
FORCE_INLINE
|
FORCE_INLINE
|
||||||
typename detail::enable_if<detail::IsString<TString>::value, bool>::type
|
typename detail::enable_if<detail::IsString<TString>::value, bool>::type
|
||||||
containsKey(const TString& key) const {
|
containsKey(const TString& key) const {
|
||||||
return getMember(detail::adaptString(key)) != 0;
|
return collectionGetMember(_data, detail::adaptString(key)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the object contains the specified key.
|
// Returns true if the object contains the specified key.
|
||||||
@ -159,7 +159,7 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
|||||||
FORCE_INLINE
|
FORCE_INLINE
|
||||||
typename detail::enable_if<detail::IsString<TChar*>::value, bool>::type
|
typename detail::enable_if<detail::IsString<TChar*>::value, bool>::type
|
||||||
containsKey(TChar* key) const {
|
containsKey(TChar* key) const {
|
||||||
return getMember(detail::adaptString(key)) != 0;
|
return collectionGetMember(_data, detail::adaptString(key)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates an array and adds it to the object.
|
// Creates an array and adds it to the object.
|
||||||
@ -199,13 +199,6 @@ class JsonObject : public detail::VariantOperators<JsonObject> {
|
|||||||
return detail::collectionToVariant(_data);
|
return detail::collectionToVariant(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TAdaptedString>
|
|
||||||
inline detail::VariantData* getMember(TAdaptedString key) const {
|
|
||||||
if (!_data)
|
|
||||||
return 0;
|
|
||||||
return slotData(_data->get(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename TAdaptedString>
|
template <typename TAdaptedString>
|
||||||
void removeMember(TAdaptedString key) const {
|
void removeMember(TAdaptedString key) const {
|
||||||
collectionRemove(_data, _data->get(key), _pool);
|
collectionRemove(_data, _data->get(key), _pool);
|
||||||
|
@ -76,14 +76,14 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
// https://arduinojson.org/v6/api/jsonobjectconst/containskey/
|
// https://arduinojson.org/v6/api/jsonobjectconst/containskey/
|
||||||
template <typename TString>
|
template <typename TString>
|
||||||
FORCE_INLINE bool containsKey(const TString& key) const {
|
FORCE_INLINE bool containsKey(const TString& key) const {
|
||||||
return getMember(detail::adaptString(key)) != 0;
|
return collectionGetMember(_data, detail::adaptString(key)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the object contains the specified key.
|
// Returns true if the object contains the specified key.
|
||||||
// https://arduinojson.org/v6/api/jsonobjectconst/containskey/
|
// https://arduinojson.org/v6/api/jsonobjectconst/containskey/
|
||||||
template <typename TChar>
|
template <typename TChar>
|
||||||
FORCE_INLINE bool containsKey(TChar* key) const {
|
FORCE_INLINE bool containsKey(TChar* key) const {
|
||||||
return getMember(detail::adaptString(key)) != 0;
|
return collectionGetMember(_data, detail::adaptString(key)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the member with specified key.
|
// Gets the member with specified key.
|
||||||
@ -92,7 +92,8 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
FORCE_INLINE typename detail::enable_if<detail::IsString<TString>::value,
|
FORCE_INLINE typename detail::enable_if<detail::IsString<TString>::value,
|
||||||
JsonVariantConst>::type
|
JsonVariantConst>::type
|
||||||
operator[](const TString& key) const {
|
operator[](const TString& key) const {
|
||||||
return JsonVariantConst(getMember(detail::adaptString(key)));
|
return JsonVariantConst(
|
||||||
|
collectionGetMember(_data, detail::adaptString(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the member with specified key.
|
// Gets the member with specified key.
|
||||||
@ -101,7 +102,8 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
FORCE_INLINE typename detail::enable_if<detail::IsString<TChar*>::value,
|
FORCE_INLINE typename detail::enable_if<detail::IsString<TChar*>::value,
|
||||||
JsonVariantConst>::type
|
JsonVariantConst>::type
|
||||||
operator[](TChar* key) const {
|
operator[](TChar* key) const {
|
||||||
return JsonVariantConst(getMember(detail::adaptString(key)));
|
return JsonVariantConst(
|
||||||
|
collectionGetMember(_data, detail::adaptString(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compares objects.
|
// Compares objects.
|
||||||
@ -126,13 +128,6 @@ class JsonObjectConst : public detail::VariantOperators<JsonObjectConst> {
|
|||||||
return collectionToVariant(_data);
|
return collectionToVariant(_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TAdaptedString>
|
|
||||||
const detail::VariantData* getMember(TAdaptedString key) const {
|
|
||||||
if (!_data)
|
|
||||||
return 0;
|
|
||||||
return slotData(_data->get(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
const detail::CollectionData* _data;
|
const detail::CollectionData* _data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user