mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-03 21:57:02 +02:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
67b6797b6d | |||
8d9504239b | |||
bf5d0c790c | |||
f4379f97ae | |||
3dc67c5663 | |||
47f90b02c3 | |||
27c924746b |
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@ -132,7 +132,9 @@ jobs:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Install
|
||||
run: sudo apt-get install -y g++-multilib
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y g++-multilib
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: GCC 32-bit
|
||||
@ -425,7 +427,9 @@ jobs:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Install
|
||||
run: sudo apt-get install -y valgrind ninja-build
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y valgrind ninja-build
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Configure
|
||||
|
@ -1,6 +1,14 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
v6.19.4 (2022-04-05)
|
||||
-------
|
||||
|
||||
* Add `ElementProxy::memoryUsage()`
|
||||
* Add `MemberProxy::memoryUsage()` (issue #1730)
|
||||
* Add implicit conversion from `JsonDocument` to `JsonVariant`
|
||||
* Fix comparisons operators with `const JsonDocument&`
|
||||
|
||||
v6.19.3 (2022-03-08)
|
||||
-------
|
||||
|
||||
|
@ -10,7 +10,7 @@ if(ESP_PLATFORM)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(ArduinoJson VERSION 6.19.3)
|
||||
project(ArduinoJson VERSION 6.19.4)
|
||||
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
include(CTest)
|
||||
|
@ -7,8 +7,8 @@
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||
[](https://lgtm.com/projects/g/bblanchon/ArduinoJson/)
|
||||
[](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.19.3)
|
||||
[](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.19.3)
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.19.4)
|
||||
[](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.19.4)
|
||||
[](https://github.com/bblanchon/ArduinoJson/stargazers)
|
||||
[](https://github.com/sponsors/bblanchon)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 6.19.3.{build}
|
||||
version: 6.19.4.{build}
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
|
||||
|
@ -5,6 +5,7 @@
|
||||
add_executable(JsonDocumentTests
|
||||
add.cpp
|
||||
BasicJsonDocument.cpp
|
||||
cast.cpp
|
||||
compare.cpp
|
||||
containsKey.cpp
|
||||
createNested.cpp
|
||||
|
@ -205,4 +205,26 @@ TEST_CASE("DynamicJsonDocument assignment") {
|
||||
REQUIRE_JSON(doc2, "42");
|
||||
REQUIRE(doc2.capacity() == 4096);
|
||||
}
|
||||
|
||||
SECTION("Assign from MemberProxy") {
|
||||
StaticJsonDocument<200> doc1;
|
||||
doc1["value"] = 42;
|
||||
|
||||
DynamicJsonDocument doc2(4096);
|
||||
doc2 = doc1["value"];
|
||||
|
||||
REQUIRE_JSON(doc2, "42");
|
||||
REQUIRE(doc2.capacity() == 4096);
|
||||
}
|
||||
|
||||
SECTION("Assign from ElementProxy") {
|
||||
StaticJsonDocument<200> doc1;
|
||||
doc1[0] = 42;
|
||||
|
||||
DynamicJsonDocument doc2(4096);
|
||||
doc2 = doc1[0];
|
||||
|
||||
REQUIRE_JSON(doc2, "42");
|
||||
REQUIRE(doc2.capacity() == 4096);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ using namespace ARDUINOJSON_NAMESPACE;
|
||||
TEST_CASE("ElementProxy::add()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
doc.addElement();
|
||||
ElementProxy<JsonDocument&> ep = doc[0];
|
||||
ElementProxy<JsonDocument &> ep = doc[0];
|
||||
|
||||
SECTION("add(int)") {
|
||||
ep.add(42);
|
||||
@ -36,7 +36,7 @@ TEST_CASE("ElementProxy::add()") {
|
||||
TEST_CASE("ElementProxy::clear()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
doc.addElement();
|
||||
ElementProxy<JsonDocument&> ep = doc[0];
|
||||
ElementProxy<JsonDocument &> ep = doc[0];
|
||||
|
||||
SECTION("size goes back to zero") {
|
||||
ep.add(42);
|
||||
@ -96,7 +96,7 @@ TEST_CASE("ElementProxy::operator==()") {
|
||||
TEST_CASE("ElementProxy::remove()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
doc.addElement();
|
||||
ElementProxy<JsonDocument&> ep = doc[0];
|
||||
ElementProxy<JsonDocument &> ep = doc[0];
|
||||
|
||||
SECTION("remove(int)") {
|
||||
ep.add(1);
|
||||
@ -143,7 +143,7 @@ TEST_CASE("ElementProxy::remove()") {
|
||||
|
||||
TEST_CASE("ElementProxy::set()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
ElementProxy<JsonDocument&> ep = doc[0];
|
||||
ElementProxy<JsonDocument &> ep = doc[0];
|
||||
|
||||
SECTION("set(int)") {
|
||||
ep.set(42);
|
||||
@ -169,7 +169,7 @@ TEST_CASE("ElementProxy::set()") {
|
||||
TEST_CASE("ElementProxy::size()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
doc.addElement();
|
||||
ElementProxy<JsonDocument&> ep = doc[0];
|
||||
ElementProxy<JsonDocument &> ep = doc[0];
|
||||
|
||||
SECTION("returns 0") {
|
||||
REQUIRE(ep.size() == 0);
|
||||
@ -188,9 +188,24 @@ TEST_CASE("ElementProxy::size()") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ElementProxy::memoryUsage()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
doc.addElement();
|
||||
ElementProxy<JsonDocument &> ep = doc[0];
|
||||
|
||||
SECTION("returns 0 for null") {
|
||||
REQUIRE(ep.memoryUsage() == 0);
|
||||
}
|
||||
|
||||
SECTION("returns size for string") {
|
||||
ep.set(std::string("hello"));
|
||||
REQUIRE(ep.memoryUsage() == 6);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ElementProxy::operator[]") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
ElementProxy<JsonDocument&> ep = doc[1];
|
||||
ElementProxy<JsonDocument &> ep = doc[1];
|
||||
|
||||
SECTION("set member") {
|
||||
ep["world"] = 42;
|
||||
@ -204,3 +219,29 @@ TEST_CASE("ElementProxy::operator[]") {
|
||||
REQUIRE(doc.as<std::string>() == "[null,[null,null,42]]");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ElementProxy cast to JsonVariantConst") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
doc[0] = "world";
|
||||
|
||||
const ElementProxy<JsonDocument &> ep = doc[0];
|
||||
|
||||
JsonVariantConst var = ep;
|
||||
|
||||
CHECK(var.as<std::string>() == "world");
|
||||
}
|
||||
|
||||
TEST_CASE("ElementProxy cast to JsonVariant") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
doc[0] = "world";
|
||||
|
||||
ElementProxy<JsonDocument &> ep = doc[0];
|
||||
|
||||
JsonVariant var = ep;
|
||||
|
||||
CHECK(var.as<std::string>() == "world");
|
||||
|
||||
var.set("toto");
|
||||
|
||||
CHECK(doc.as<std::string>() == "[\"toto\"]");
|
||||
}
|
||||
|
@ -229,6 +229,20 @@ TEST_CASE("MemberProxy::size()") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("MemberProxy::memoryUsage()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
|
||||
|
||||
SECTION("returns 0 when null") {
|
||||
REQUIRE(mp.memoryUsage() == 0);
|
||||
}
|
||||
|
||||
SECTION("return the size for a string") {
|
||||
mp.set(std::string("hello"));
|
||||
REQUIRE(mp.memoryUsage() == 6);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("MemberProxy::operator[]") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
|
||||
@ -245,3 +259,29 @@ TEST_CASE("MemberProxy::operator[]") {
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":[null,null,42]}");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("MemberProxy cast to JsonVariantConst") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
doc["hello"] = "world";
|
||||
|
||||
const MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
|
||||
|
||||
JsonVariantConst var = mp;
|
||||
|
||||
CHECK(var.as<std::string>() == "world");
|
||||
}
|
||||
|
||||
TEST_CASE("MemberProxy cast to JsonVariant") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
doc["hello"] = "world";
|
||||
|
||||
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
|
||||
|
||||
JsonVariant var = mp;
|
||||
|
||||
CHECK(var.as<std::string>() == "world");
|
||||
|
||||
var.set("toto");
|
||||
|
||||
CHECK(doc.as<std::string>() == "{\"hello\":\"toto\"}");
|
||||
}
|
||||
|
18
extras/tests/JsonDocument/cast.cpp
Normal file
18
extras/tests/JsonDocument/cast.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2022, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Implicit cast to JsonVariant") {
|
||||
StaticJsonDocument<128> doc;
|
||||
|
||||
doc["hello"] = "world";
|
||||
|
||||
JsonVariant var = doc;
|
||||
|
||||
CHECK(var.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
}
|
@ -75,3 +75,29 @@ TEST_CASE("StaticJsonDocument::operator==(const DynamicJsonDocument&)") {
|
||||
REQUIRE(doc1 != doc2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonDocument::operator==(const JsonDocument&)") {
|
||||
StaticJsonDocument<256> doc1;
|
||||
StaticJsonDocument<256> doc2;
|
||||
const JsonDocument& ref1 = doc1;
|
||||
const JsonDocument& ref2 = doc2;
|
||||
|
||||
SECTION("Empty") {
|
||||
REQUIRE(ref1 == ref2);
|
||||
REQUIRE_FALSE(ref1 != ref2);
|
||||
}
|
||||
|
||||
SECTION("With same object") {
|
||||
doc1["hello"] = "world";
|
||||
doc2["hello"] = "world";
|
||||
REQUIRE(ref1 == ref2);
|
||||
REQUIRE_FALSE(ref1 != ref2);
|
||||
}
|
||||
|
||||
SECTION("With different object") {
|
||||
doc1["hello"] = "world";
|
||||
doc2["world"] = "hello";
|
||||
REQUIRE_FALSE(ref1 == ref2);
|
||||
REQUIRE(ref1 != ref2);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/bblanchon/ArduinoJson.git"
|
||||
},
|
||||
"version": "6.19.3",
|
||||
"version": "6.19.4",
|
||||
"authors": {
|
||||
"name": "Benoit Blanchon",
|
||||
"url": "https://blog.benoitblanchon.fr"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ArduinoJson
|
||||
version=6.19.3
|
||||
version=6.19.4
|
||||
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
sentence=A simple and efficient JSON library for embedded C++.
|
||||
|
@ -118,6 +118,10 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
||||
return getUpstreamElement().size();
|
||||
}
|
||||
|
||||
FORCE_INLINE size_t memoryUsage() const {
|
||||
return getUpstreamElement().memoryUsage();
|
||||
}
|
||||
|
||||
template <typename TNestedKey>
|
||||
VariantRef getMember(TNestedKey* key) const {
|
||||
return getUpstreamElement().getMember(key);
|
||||
|
@ -14,7 +14,8 @@
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class JsonDocument : public Visitable {
|
||||
class JsonDocument : public Visitable,
|
||||
public VariantOperators<const JsonDocument&> {
|
||||
public:
|
||||
template <typename TVisitor>
|
||||
typename TVisitor::result_type accept(TVisitor& visitor) const {
|
||||
@ -295,16 +296,12 @@ class JsonDocument : public Visitable {
|
||||
_data.remove(adaptString(key));
|
||||
}
|
||||
|
||||
FORCE_INLINE operator VariantRef() {
|
||||
return getVariant();
|
||||
}
|
||||
|
||||
FORCE_INLINE operator VariantConstRef() const {
|
||||
return VariantConstRef(&_data);
|
||||
}
|
||||
|
||||
bool operator==(VariantConstRef rhs) const {
|
||||
return getVariant() == rhs;
|
||||
}
|
||||
|
||||
bool operator!=(VariantConstRef rhs) const {
|
||||
return getVariant() != rhs;
|
||||
return getVariant();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -94,6 +94,10 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
return getUpstreamMember().size();
|
||||
}
|
||||
|
||||
FORCE_INLINE size_t memoryUsage() const {
|
||||
return getUpstreamMember().memoryUsage();
|
||||
}
|
||||
|
||||
FORCE_INLINE void remove(size_t index) const {
|
||||
getUpstreamMember().remove(index);
|
||||
}
|
||||
|
@ -131,9 +131,9 @@ struct RawComparer : ComparerBase {
|
||||
template <typename T>
|
||||
struct Comparer<T, typename enable_if<IsVisitable<T>::value>::type>
|
||||
: ComparerBase {
|
||||
T rhs;
|
||||
const T *rhs; // TODO: should be a VariantConstRef
|
||||
|
||||
explicit Comparer(T value) : rhs(value) {}
|
||||
explicit Comparer(const T &value) : rhs(&value) {}
|
||||
|
||||
CompareResult visitArray(const CollectionData &lhs) {
|
||||
ArrayComparer comparer(lhs);
|
||||
@ -183,7 +183,7 @@ struct Comparer<T, typename enable_if<IsVisitable<T>::value>::type>
|
||||
private:
|
||||
template <typename TComparer>
|
||||
CompareResult accept(TComparer &comparer) {
|
||||
CompareResult reversedResult = rhs.accept(comparer);
|
||||
CompareResult reversedResult = rhs->accept(comparer);
|
||||
switch (reversedResult) {
|
||||
case COMPARE_RESULT_GREATER:
|
||||
return COMPARE_RESULT_LESS;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ARDUINOJSON_VERSION "6.19.3"
|
||||
#define ARDUINOJSON_VERSION "6.19.4"
|
||||
#define ARDUINOJSON_VERSION_MAJOR 6
|
||||
#define ARDUINOJSON_VERSION_MINOR 19
|
||||
#define ARDUINOJSON_VERSION_REVISION 3
|
||||
#define ARDUINOJSON_VERSION_REVISION 4
|
||||
|
Reference in New Issue
Block a user