diff --git a/CHANGELOG.md b/CHANGELOG.md index 61a9430e..b8a63c99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ArduinoJson: change log HEAD ---- -* Added operators `==` and `!=` for `JsonDocument` and `MemberProxy` +* Added operators `==` and `!=` for `JsonDocument`, `ElementProxy`, and `MemberProxy` v6.11.2 (2019-07-08) ------- diff --git a/src/ArduinoJson/Array/ElementProxy.hpp b/src/ArduinoJson/Array/ElementProxy.hpp index e1c784ad..c7ef9c61 100644 --- a/src/ArduinoJson/Array/ElementProxy.hpp +++ b/src/ArduinoJson/Array/ElementProxy.hpp @@ -47,6 +47,14 @@ class ElementProxy : public VariantOperators >, return *this; } + FORCE_INLINE bool operator==(VariantConstRef rhs) const { + return static_cast(getUpstreamElement()) == rhs; + } + + FORCE_INLINE bool operator!=(VariantConstRef rhs) const { + return static_cast(getUpstreamElement()) != rhs; + } + FORCE_INLINE void clear() const { getUpstreamElement().clear(); } diff --git a/test/ElementProxy/CMakeLists.txt b/test/ElementProxy/CMakeLists.txt index ab419f48..246e13c9 100644 --- a/test/ElementProxy/CMakeLists.txt +++ b/test/ElementProxy/CMakeLists.txt @@ -5,6 +5,7 @@ add_executable(ElementProxyTests add.cpp clear.cpp + compare.cpp remove.cpp set.cpp size.cpp diff --git a/test/ElementProxy/compare.cpp b/test/ElementProxy/compare.cpp new file mode 100644 index 00000000..c8cb3c6f --- /dev/null +++ b/test/ElementProxy/compare.cpp @@ -0,0 +1,28 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2019 +// MIT License + +#include +#include + +using namespace ARDUINOJSON_NAMESPACE; + +TEST_CASE("ElementProxy::operator==()") { + DynamicJsonDocument doc(4096); + + SECTION("same value") { + doc.add(1); + doc.add(1); + + REQUIRE(doc[0] == doc[1]); + REQUIRE_FALSE(doc[0] != doc[1]); + } + + SECTION("different values") { + doc.add(1); + doc.add(2); + + REQUIRE_FALSE(doc[0] == doc[1]); + REQUIRE(doc[0] != doc[1]); + } +}