mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-03 13:46:46 +02:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
a6f029ded0 | |||
b54de58e6b | |||
795e37278f | |||
7ce1039d7c | |||
aba42faf69 |
@ -1,6 +1,12 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
v6.11.3 (2019-07-22)
|
||||
-------
|
||||
|
||||
* Added operators `==` and `!=` for `JsonDocument`, `ElementProxy`, and `MemberProxy`
|
||||
* Fixed comparison of `JsonVariant` when one contains a linked string and the other contains an owned string (issue #1051)
|
||||
|
||||
v6.11.2 (2019-07-08)
|
||||
-------
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
---
|
||||
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.11.2)
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.11.3)
|
||||
[](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||
[](https://travis-ci.org/bblanchon/ArduinoJson)
|
||||
[](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 6.11.2.{build}
|
||||
version: 6.11.3.{build}
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
|
@ -7,7 +7,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/bblanchon/ArduinoJson.git"
|
||||
},
|
||||
"version": "6.11.2",
|
||||
"version": "6.11.3",
|
||||
"authors": {
|
||||
"name": "Benoit Blanchon",
|
||||
"url": "https://blog.benoitblanchon.fr"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ArduinoJson
|
||||
version=6.11.2
|
||||
version=6.11.3
|
||||
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
sentence=An efficient and elegant JSON library for Arduino.
|
||||
|
@ -47,6 +47,14 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
||||
return *this;
|
||||
}
|
||||
|
||||
FORCE_INLINE bool operator==(VariantConstRef rhs) const {
|
||||
return static_cast<VariantConstRef>(getUpstreamElement()) == rhs;
|
||||
}
|
||||
|
||||
FORCE_INLINE bool operator!=(VariantConstRef rhs) const {
|
||||
return static_cast<VariantConstRef>(getUpstreamElement()) != rhs;
|
||||
}
|
||||
|
||||
FORCE_INLINE void clear() const {
|
||||
getUpstreamElement().clear();
|
||||
}
|
||||
|
@ -282,6 +282,14 @@ class JsonDocument : public Visitable {
|
||||
return VariantConstRef(&_data);
|
||||
}
|
||||
|
||||
bool operator==(VariantConstRef rhs) const {
|
||||
return getVariant() == rhs;
|
||||
}
|
||||
|
||||
bool operator!=(VariantConstRef rhs) const {
|
||||
return getVariant() != rhs;
|
||||
}
|
||||
|
||||
protected:
|
||||
JsonDocument(MemoryPool pool) : _pool(pool) {
|
||||
_data.setNull();
|
||||
|
@ -49,6 +49,14 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
return *this;
|
||||
}
|
||||
|
||||
FORCE_INLINE bool operator==(VariantConstRef rhs) const {
|
||||
return static_cast<VariantConstRef>(getUpstreamMember()) == rhs;
|
||||
}
|
||||
|
||||
FORCE_INLINE bool operator!=(VariantConstRef rhs) const {
|
||||
return static_cast<VariantConstRef>(getUpstreamMember()) != rhs;
|
||||
}
|
||||
|
||||
FORCE_INLINE void clear() const {
|
||||
getUpstreamMember().clear();
|
||||
}
|
||||
|
@ -126,7 +126,8 @@ class VariantComparisons {
|
||||
return compare(rhs, lhs) == 0;
|
||||
}
|
||||
template <typename T>
|
||||
friend bool operator==(const T &lhs, TVariant rhs) {
|
||||
friend typename enable_if<!IsVisitable<T>::value, bool>::type operator==(
|
||||
const T &lhs, TVariant rhs) {
|
||||
return compare(rhs, lhs) == 0;
|
||||
}
|
||||
|
||||
@ -136,7 +137,8 @@ class VariantComparisons {
|
||||
return compare(lhs, rhs) == 0;
|
||||
}
|
||||
template <typename T>
|
||||
friend bool operator==(TVariant lhs, const T &rhs) {
|
||||
friend typename enable_if<!IsVisitable<T>::value, bool>::type operator==(
|
||||
TVariant lhs, const T &rhs) {
|
||||
return compare(lhs, rhs) == 0;
|
||||
}
|
||||
|
||||
@ -146,7 +148,8 @@ class VariantComparisons {
|
||||
return compare(rhs, lhs) != 0;
|
||||
}
|
||||
template <typename T>
|
||||
friend bool operator!=(const T &lhs, TVariant rhs) {
|
||||
friend typename enable_if<!IsVisitable<T>::value, bool>::type operator!=(
|
||||
const T &lhs, TVariant rhs) {
|
||||
return compare(rhs, lhs) != 0;
|
||||
}
|
||||
|
||||
@ -156,7 +159,8 @@ class VariantComparisons {
|
||||
return compare(lhs, rhs) != 0;
|
||||
}
|
||||
template <typename T>
|
||||
friend bool operator!=(TVariant lhs, const T &rhs) {
|
||||
friend typename enable_if<!IsVisitable<T>::value, bool>::type operator!=(
|
||||
TVariant lhs, const T &rhs) {
|
||||
return compare(lhs, rhs) != 0;
|
||||
}
|
||||
|
||||
|
@ -16,15 +16,18 @@ namespace ARDUINOJSON_NAMESPACE {
|
||||
enum {
|
||||
VALUE_MASK = 0x7F,
|
||||
|
||||
OWNERSHIP_BIT = 0x01,
|
||||
VALUE_IS_NULL = 0,
|
||||
VALUE_IS_LINKED_RAW = 0x01,
|
||||
VALUE_IS_OWNED_RAW = 0x02,
|
||||
VALUE_IS_LINKED_STRING = 0x03,
|
||||
VALUE_IS_OWNED_STRING = 0x04,
|
||||
VALUE_IS_BOOLEAN = 0x05,
|
||||
VALUE_IS_POSITIVE_INTEGER = 0x06,
|
||||
VALUE_IS_NEGATIVE_INTEGER = 0x07,
|
||||
VALUE_IS_FLOAT = 0x08,
|
||||
VALUE_IS_LINKED_RAW = 0x02,
|
||||
VALUE_IS_OWNED_RAW = 0x03,
|
||||
VALUE_IS_LINKED_STRING = 0x04,
|
||||
VALUE_IS_OWNED_STRING = 0x05,
|
||||
|
||||
// CAUTION: no OWNERSHIP_BIT below
|
||||
VALUE_IS_BOOLEAN = 0x06,
|
||||
VALUE_IS_POSITIVE_INTEGER = 0x08,
|
||||
VALUE_IS_NEGATIVE_INTEGER = 0x0A,
|
||||
VALUE_IS_FLOAT = 0x0C,
|
||||
|
||||
COLLECTION_MASK = 0x60,
|
||||
VALUE_IS_OBJECT = 0x20,
|
||||
|
@ -101,7 +101,9 @@ class VariantData {
|
||||
}
|
||||
|
||||
bool equals(const VariantData &other) const {
|
||||
if (type() != other.type()) return false;
|
||||
// Check that variant have the same type, but ignore string ownership
|
||||
if ((type() | OWNERSHIP_BIT) != (other.type() | OWNERSHIP_BIT))
|
||||
return false;
|
||||
|
||||
switch (type()) {
|
||||
case VALUE_IS_LINKED_STRING:
|
||||
|
@ -380,5 +380,13 @@ class VariantConstRef : public VariantRefBase<const VariantData>,
|
||||
const CollectionData *obj = variantAsObject(_data);
|
||||
return VariantConstRef(obj ? obj->get(adaptString(key)) : 0);
|
||||
}
|
||||
|
||||
FORCE_INLINE bool operator==(VariantConstRef lhs) const {
|
||||
return variantEquals(_data, lhs._data);
|
||||
}
|
||||
|
||||
FORCE_INLINE bool operator!=(VariantConstRef lhs) const {
|
||||
return !variantEquals(_data, lhs._data);
|
||||
}
|
||||
};
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ARDUINOJSON_VERSION "6.11.2"
|
||||
#define ARDUINOJSON_VERSION "6.11.3"
|
||||
#define ARDUINOJSON_VERSION_MAJOR 6
|
||||
#define ARDUINOJSON_VERSION_MINOR 11
|
||||
#define ARDUINOJSON_VERSION_REVISION 2
|
||||
#define ARDUINOJSON_VERSION_REVISION 3
|
||||
|
@ -5,6 +5,7 @@
|
||||
add_executable(ElementProxyTests
|
||||
add.cpp
|
||||
clear.cpp
|
||||
compare.cpp
|
||||
remove.cpp
|
||||
set.cpp
|
||||
size.cpp
|
||||
|
28
test/ElementProxy/compare.cpp
Normal file
28
test/ElementProxy/compare.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::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]);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
add_executable(JsonDocumentTests
|
||||
add.cpp
|
||||
BasicJsonDocument.cpp
|
||||
compare.cpp
|
||||
containsKey.cpp
|
||||
createNested.cpp
|
||||
DynamicJsonDocument.cpp
|
||||
|
77
test/JsonDocument/compare.cpp
Normal file
77
test/JsonDocument/compare.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("DynamicJsonDocument::operator==(const DynamicJsonDocument&)") {
|
||||
DynamicJsonDocument doc1(4096);
|
||||
DynamicJsonDocument doc2(4096);
|
||||
|
||||
SECTION("Empty") {
|
||||
REQUIRE(doc1 == doc2);
|
||||
REQUIRE_FALSE(doc1 != doc2);
|
||||
}
|
||||
|
||||
SECTION("With same object") {
|
||||
doc1["hello"] = "world";
|
||||
doc2["hello"] = "world";
|
||||
REQUIRE(doc1 == doc2);
|
||||
REQUIRE_FALSE(doc1 != doc2);
|
||||
}
|
||||
SECTION("With different object") {
|
||||
doc1["hello"] = "world";
|
||||
doc2["world"] = "hello";
|
||||
REQUIRE_FALSE(doc1 == doc2);
|
||||
REQUIRE(doc1 != doc2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("DynamicJsonDocument::operator==(const StaticJsonDocument&)") {
|
||||
DynamicJsonDocument doc1(4096);
|
||||
StaticJsonDocument<256> doc2;
|
||||
|
||||
SECTION("Empty") {
|
||||
REQUIRE(doc1 == doc2);
|
||||
REQUIRE_FALSE(doc1 != doc2);
|
||||
}
|
||||
|
||||
SECTION("With same object") {
|
||||
doc1["hello"] = "world";
|
||||
doc2["hello"] = "world";
|
||||
REQUIRE(doc1 == doc2);
|
||||
REQUIRE_FALSE(doc1 != doc2);
|
||||
}
|
||||
|
||||
SECTION("With different object") {
|
||||
doc1["hello"] = "world";
|
||||
doc2["world"] = "hello";
|
||||
REQUIRE_FALSE(doc1 == doc2);
|
||||
REQUIRE(doc1 != doc2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("StaticJsonDocument::operator==(const DynamicJsonDocument&)") {
|
||||
StaticJsonDocument<256> doc1;
|
||||
DynamicJsonDocument doc2(4096);
|
||||
|
||||
SECTION("Empty") {
|
||||
REQUIRE(doc1 == doc2);
|
||||
REQUIRE_FALSE(doc1 != doc2);
|
||||
}
|
||||
|
||||
SECTION("With same object") {
|
||||
doc1["hello"] = "world";
|
||||
doc2["hello"] = "world";
|
||||
REQUIRE(doc1 == doc2);
|
||||
REQUIRE_FALSE(doc1 != doc2);
|
||||
}
|
||||
|
||||
SECTION("With different object") {
|
||||
doc1["hello"] = "world";
|
||||
doc2["world"] = "hello";
|
||||
REQUIRE_FALSE(doc1 == doc2);
|
||||
REQUIRE(doc1 != doc2);
|
||||
}
|
||||
}
|
@ -286,6 +286,17 @@ TEST_CASE("JsonVariant comparisons") {
|
||||
REQUIRE_FALSE(variant1 == variant3);
|
||||
}
|
||||
|
||||
SECTION("Variants containing mixed strings (issue #1051)") {
|
||||
variant1.set("hello");
|
||||
variant2.set(std::string("hello"));
|
||||
|
||||
REQUIRE(variant1 == variant2);
|
||||
REQUIRE_FALSE(variant1 != variant2);
|
||||
|
||||
REQUIRE(variant2 == variant1);
|
||||
REQUIRE_FALSE(variant2 != variant1);
|
||||
}
|
||||
|
||||
SECTION("Variants containing double") {
|
||||
variant1.set(42.0);
|
||||
variant2.set(42.0);
|
||||
|
@ -5,6 +5,7 @@
|
||||
add_executable(MemberProxyTests
|
||||
add.cpp
|
||||
clear.cpp
|
||||
compare.cpp
|
||||
containsKey.cpp
|
||||
remove.cpp
|
||||
set.cpp
|
||||
|
26
test/MemberProxy/compare.cpp
Normal file
26
test/MemberProxy/compare.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
using namespace ARDUINOJSON_NAMESPACE;
|
||||
|
||||
TEST_CASE("MemberProxy::operator==()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
|
||||
SECTION("same values") {
|
||||
doc["key1"] = "value";
|
||||
doc["key2"] = "value";
|
||||
REQUIRE(doc["key1"] == doc["key2"]);
|
||||
REQUIRE_FALSE(doc["key1"] != doc["key2"]);
|
||||
}
|
||||
|
||||
SECTION("different values") {
|
||||
doc["key1"] = "value1";
|
||||
doc["key2"] = "value2";
|
||||
REQUIRE_FALSE(doc["key1"] == doc["key2"]);
|
||||
REQUIRE(doc["key1"] != doc["key2"]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user