forked from bblanchon/ArduinoJson
Added JsonVariant::clear()
This commit is contained in:
@ -17,6 +17,7 @@ HEAD
|
|||||||
* Fixed segfault after `variant.set(serialized((char*)0))`
|
* Fixed segfault after `variant.set(serialized((char*)0))`
|
||||||
* Detect `IncompleteInput` in `false`, `true`, and `null`
|
* Detect `IncompleteInput` in `false`, `true`, and `null`
|
||||||
* Added `JsonDocument::size()`
|
* Added `JsonDocument::size()`
|
||||||
|
* Added `JsonVariant::clear()`
|
||||||
|
|
||||||
v6.8.0-beta (2019-01-30)
|
v6.8.0-beta (2019-01-30)
|
||||||
-----------
|
-----------
|
||||||
|
@ -47,6 +47,10 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FORCE_INLINE void clear() const {
|
||||||
|
getUpstreamElement().clear();
|
||||||
|
}
|
||||||
|
|
||||||
FORCE_INLINE bool isNull() const {
|
FORCE_INLINE bool isNull() const {
|
||||||
return getUpstreamElement().isNull();
|
return getUpstreamElement().isNull();
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,10 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FORCE_INLINE void clear() const {
|
||||||
|
getUpstreamMember().clear();
|
||||||
|
}
|
||||||
|
|
||||||
FORCE_INLINE bool isNull() const {
|
FORCE_INLINE bool isNull() const {
|
||||||
return getUpstreamMember().isNull();
|
return getUpstreamMember().isNull();
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,10 @@ class VariantRef : public VariantRefBase<VariantData>,
|
|||||||
// Creates an uninitialized VariantRef
|
// Creates an uninitialized VariantRef
|
||||||
FORCE_INLINE VariantRef() : base_type(0), _pool(0) {}
|
FORCE_INLINE VariantRef() : base_type(0), _pool(0) {}
|
||||||
|
|
||||||
|
FORCE_INLINE void clear() const {
|
||||||
|
return variantSetNull(_data);
|
||||||
|
}
|
||||||
|
|
||||||
// set(bool value)
|
// set(bool value)
|
||||||
FORCE_INLINE bool set(bool value) const {
|
FORCE_INLINE bool set(bool value) const {
|
||||||
return variantSetBoolean(_data, value);
|
return variantSetBoolean(_data, value);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
add_executable(ElementProxyTests
|
add_executable(ElementProxyTests
|
||||||
add.cpp
|
add.cpp
|
||||||
|
clear.cpp
|
||||||
set.cpp
|
set.cpp
|
||||||
size.cpp
|
size.cpp
|
||||||
)
|
)
|
||||||
|
28
test/ElementProxy/clear.cpp
Normal file
28
test/ElementProxy/clear.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// ArduinoJson - arduinojson.org
|
||||||
|
// Copyright Benoit Blanchon 2014-2019
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <catch.hpp>
|
||||||
|
|
||||||
|
using namespace ARDUINOJSON_NAMESPACE;
|
||||||
|
|
||||||
|
TEST_CASE("ElementProxy::clear()") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
doc.addElement();
|
||||||
|
ElementProxy<JsonDocument&> ep = doc[0];
|
||||||
|
|
||||||
|
SECTION("size goes back to zero") {
|
||||||
|
ep.add(42);
|
||||||
|
ep.clear();
|
||||||
|
|
||||||
|
REQUIRE(ep.size() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("isNull() return true") {
|
||||||
|
ep.add("hello");
|
||||||
|
ep.clear();
|
||||||
|
|
||||||
|
REQUIRE(ep.isNull() == true);
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@
|
|||||||
add_executable(JsonVariantTests
|
add_executable(JsonVariantTests
|
||||||
add.cpp
|
add.cpp
|
||||||
as.cpp
|
as.cpp
|
||||||
|
clear.cpp
|
||||||
compare.cpp
|
compare.cpp
|
||||||
copy.cpp
|
copy.cpp
|
||||||
createNested.cpp
|
createNested.cpp
|
||||||
|
28
test/JsonVariant/clear.cpp
Normal file
28
test/JsonVariant/clear.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// ArduinoJson - arduinojson.org
|
||||||
|
// Copyright Benoit Blanchon 2014-2019
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <catch.hpp>
|
||||||
|
|
||||||
|
static const char* null = 0;
|
||||||
|
|
||||||
|
TEST_CASE("JsonVariant::clear()") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
JsonVariant var = doc.to<JsonVariant>();
|
||||||
|
|
||||||
|
SECTION("size goes back to zero") {
|
||||||
|
var.add(42);
|
||||||
|
var.clear();
|
||||||
|
|
||||||
|
REQUIRE(var.size() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("isNull() return true") {
|
||||||
|
var.add("hello");
|
||||||
|
var.clear();
|
||||||
|
|
||||||
|
REQUIRE(var.isNull() == true);
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
add_executable(MemberProxyTests
|
add_executable(MemberProxyTests
|
||||||
add.cpp
|
add.cpp
|
||||||
|
clear.cpp
|
||||||
subscript.cpp
|
subscript.cpp
|
||||||
set.cpp
|
set.cpp
|
||||||
size.cpp
|
size.cpp
|
||||||
|
27
test/MemberProxy/clear.cpp
Normal file
27
test/MemberProxy/clear.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// ArduinoJson - arduinojson.org
|
||||||
|
// Copyright Benoit Blanchon 2014-2019
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <catch.hpp>
|
||||||
|
|
||||||
|
using namespace ARDUINOJSON_NAMESPACE;
|
||||||
|
|
||||||
|
TEST_CASE("MemberProxy::clear()") {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
MemberProxy<JsonDocument&, const char*> mp = doc["hello"];
|
||||||
|
|
||||||
|
SECTION("size goes back to zero") {
|
||||||
|
mp.add(42);
|
||||||
|
mp.clear();
|
||||||
|
|
||||||
|
REQUIRE(mp.size() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("isNull() return true") {
|
||||||
|
mp.add("hello");
|
||||||
|
mp.clear();
|
||||||
|
|
||||||
|
REQUIRE(mp.isNull() == true);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user