diff --git a/lib/ArduinoJson/CHANGELOG.md b/lib/ArduinoJson/CHANGELOG.md index 0d0b7b1..b348d56 100644 --- a/lib/ArduinoJson/CHANGELOG.md +++ b/lib/ArduinoJson/CHANGELOG.md @@ -1,6 +1,21 @@ ArduinoJson: change log ======================= +v7.1.0 (2024-06-27) +------ + +* Add `ARDUINOJSON_STRING_LENGTH_SIZE` to the namespace name +* Add support for MsgPack binary (PR #2078 by @Sanae6) +* Add support for MsgPack extension +* Make string support even more generic (PR #2084 by @d-a-v) +* Optimize `deserializeMsgPack()` +* Allow using a `JsonVariant` as a key or index (issue #2080) + Note: works only for reading, not for writing +* Support `ElementProxy` and `MemberProxy` in `JsonDocument`'s constructor +* Don't add partial objects when allocation fails (issue #2081) +* Read MsgPack's 64-bit integers even if `ARDUINOJSON_USE_LONG_LONG` is `0` + (they are set to `null` if they don't fit in a `long`) + v7.0.4 (2024-03-12) ------ diff --git a/lib/ArduinoJson/CMakeLists.txt b/lib/ArduinoJson/CMakeLists.txt index e770095..d76b837 100644 --- a/lib/ArduinoJson/CMakeLists.txt +++ b/lib/ArduinoJson/CMakeLists.txt @@ -10,7 +10,7 @@ if(ESP_PLATFORM) return() endif() -project(ArduinoJson VERSION 7.0.4) +project(ArduinoJson VERSION 7.1.0) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) include(CTest) diff --git a/lib/ArduinoJson/README b/lib/ArduinoJson/README new file mode 100644 index 0000000..2593a33 --- /dev/null +++ b/lib/ArduinoJson/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/lib/ArduinoJson/appveyor.yml b/lib/ArduinoJson/appveyor.yml index 05340f7..edcdb4b 100644 --- a/lib/ArduinoJson/appveyor.yml +++ b/lib/ArduinoJson/appveyor.yml @@ -1,4 +1,4 @@ -version: 7.0.4.{build} +version: 7.1.0.{build} environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 diff --git a/lib/ArduinoJson/extras/CompileOptions.cmake b/lib/ArduinoJson/extras/CompileOptions.cmake index ae1139f..5d9f804 100644 --- a/lib/ArduinoJson/extras/CompileOptions.cmake +++ b/lib/ArduinoJson/extras/CompileOptions.cmake @@ -1,3 +1,7 @@ +if(NOT DEFINED COVERAGE) + set(COVERAGE OFF) +endif() + if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") add_compile_options( -pedantic @@ -30,7 +34,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) AND(NOT ${COVERAGE})) + if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9) AND(NOT ${COVERAGE})) add_compile_options(-g -Og) else() # GCC 4.8 add_compile_options( diff --git a/lib/ArduinoJson/extras/fuzzing/CMakeLists.txt b/lib/ArduinoJson/extras/fuzzing/CMakeLists.txt index 911375e..cc6e05d 100644 --- a/lib/ArduinoJson/extras/fuzzing/CMakeLists.txt +++ b/lib/ArduinoJson/extras/fuzzing/CMakeLists.txt @@ -52,7 +52,16 @@ macro(add_fuzzer name) ) endmacro() -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6) +# Needs Clang 6+ to compile +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6) + if(DEFINED ENV{GITHUB_ACTIONS} AND CMAKE_CXX_COMPILER_VERSION MATCHES "^11\\.") + # Clang 11 fails on GitHub Actions with the following error: + # > ERROR: UndefinedBehaviorSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22) + # > Sanitizer CHECK failed: /build/llvm-toolchain-11-mnvtwk/llvm-toolchain-11-11.1.0/compiler-rt/lib/sanitizer_common/sanitizer_common.cpp:54 ((0 && "unable to mmap")) != (0) (0, 0) + message(WARNING "Fuzzing is disabled on GitHub Actions to workaround a bug in Clang 11") + return() + endif() + add_fuzzer(json) add_fuzzer(msgpack) endif() diff --git a/lib/ArduinoJson/extras/tests/Cpp17/string_view.cpp b/lib/ArduinoJson/extras/tests/Cpp17/string_view.cpp index 32163b2..92e0a62 100644 --- a/lib/ArduinoJson/extras/tests/Cpp17/string_view.cpp +++ b/lib/ArduinoJson/extras/tests/Cpp17/string_view.cpp @@ -12,6 +12,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" #if !ARDUINOJSON_ENABLE_STRING_VIEW # error ARDUINOJSON_ENABLE_STRING_VIEW must be set to 1 @@ -92,7 +93,7 @@ TEST_CASE("string_view") { } SECTION("String containing NUL") { - doc.set(std::string("hello\0world", 11)); + doc.set("hello\0world"_s); REQUIRE(doc.as().size() == 11); REQUIRE(doc.as() == std::string_view("hello\0world", 11)); } diff --git a/lib/ArduinoJson/extras/tests/Deprecated/createNestedArray.cpp b/lib/ArduinoJson/extras/tests/Deprecated/createNestedArray.cpp index 716517f..6efbd88 100644 --- a/lib/ArduinoJson/extras/tests/Deprecated/createNestedArray.cpp +++ b/lib/ArduinoJson/extras/tests/Deprecated/createNestedArray.cpp @@ -7,6 +7,8 @@ #include +#include "Literals.hpp" + TEST_CASE("JsonDocument::createNestedArray()") { JsonDocument doc; @@ -23,7 +25,7 @@ TEST_CASE("JsonDocument::createNestedArray()") { } SECTION("createNestedArray(std::string)") { - JsonArray array = doc.createNestedArray(std::string("key")); + JsonArray array = doc.createNestedArray("key"_s); array.add(42); REQUIRE(doc.as() == "{\"key\":[42]}"); } @@ -59,7 +61,7 @@ TEST_CASE("JsonObject::createNestedArray()") { } SECTION("createNestedArray(std::string)") { - JsonArray array = object.createNestedArray(std::string("key")); + JsonArray array = object.createNestedArray("key"_s); array.add(42); REQUIRE(doc.as() == "{\"key\":[42]}"); } @@ -93,7 +95,7 @@ TEST_CASE("JsonVariant::createNestedArray()") { } SECTION("createNestedArray(std::string)") { - JsonArray array = variant.createNestedArray(std::string("key")); + JsonArray array = variant.createNestedArray("key"_s); array.add(42); REQUIRE(doc.as() == "{\"key\":[42]}"); } diff --git a/lib/ArduinoJson/extras/tests/Deprecated/createNestedObject.cpp b/lib/ArduinoJson/extras/tests/Deprecated/createNestedObject.cpp index 684f31d..8b73c8b 100644 --- a/lib/ArduinoJson/extras/tests/Deprecated/createNestedObject.cpp +++ b/lib/ArduinoJson/extras/tests/Deprecated/createNestedObject.cpp @@ -7,6 +7,8 @@ #include +#include "Literals.hpp" + TEST_CASE("JsonDocument::createNestedObject()") { JsonDocument doc; @@ -23,7 +25,7 @@ TEST_CASE("JsonDocument::createNestedObject()") { } SECTION("createNestedObject(std::string)") { - JsonObject object = doc.createNestedObject(std::string("key")); + JsonObject object = doc.createNestedObject("key"_s); object["hello"] = "world"; REQUIRE(doc.as() == "{\"key\":{\"hello\":\"world\"}}"); } @@ -59,7 +61,7 @@ TEST_CASE("JsonObject::createNestedObject()") { } SECTION("createNestedObject(std::string)") { - JsonObject nestedObject = object.createNestedObject(std::string("key")); + JsonObject nestedObject = object.createNestedObject("key"_s); nestedObject["hello"] = "world"; REQUIRE(doc.as() == "{\"key\":{\"hello\":\"world\"}}"); } @@ -93,7 +95,7 @@ TEST_CASE("JsonVariant::createNestedObject()") { } SECTION("createNestedObject(std::string)") { - JsonObject object = variant.createNestedObject(std::string("key")); + JsonObject object = variant.createNestedObject("key"_s); object["hello"] = "world"; REQUIRE(doc.as() == "{\"key\":{\"hello\":\"world\"}}"); } diff --git a/lib/ArduinoJson/extras/tests/Helpers/Allocators.hpp b/lib/ArduinoJson/extras/tests/Helpers/Allocators.hpp index 5df98ed..095d726 100644 --- a/lib/ArduinoJson/extras/tests/Helpers/Allocators.hpp +++ b/lib/ArduinoJson/extras/tests/Helpers/Allocators.hpp @@ -10,6 +10,8 @@ #include +namespace { + struct FailingAllocator : ArduinoJson::Allocator { static FailingAllocator* instance() { static FailingAllocator allocator; @@ -54,31 +56,31 @@ class AllocatorLogEntry { inline AllocatorLogEntry Allocate(size_t s) { char buffer[32]; - sprintf(buffer, "allocate(%zu)", s); + snprintf(buffer, sizeof(buffer), "allocate(%zu)", s); return AllocatorLogEntry(buffer); } inline AllocatorLogEntry AllocateFail(size_t s) { char buffer[32]; - sprintf(buffer, "allocate(%zu) -> nullptr", s); + snprintf(buffer, sizeof(buffer), "allocate(%zu) -> nullptr", s); return AllocatorLogEntry(buffer); } inline AllocatorLogEntry Reallocate(size_t s1, size_t s2) { char buffer[32]; - sprintf(buffer, "reallocate(%zu, %zu)", s1, s2); + snprintf(buffer, sizeof(buffer), "reallocate(%zu, %zu)", s1, s2); return AllocatorLogEntry(buffer); } inline AllocatorLogEntry ReallocateFail(size_t s1, size_t s2) { char buffer[32]; - sprintf(buffer, "reallocate(%zu, %zu) -> nullptr", s1, s2); + snprintf(buffer, sizeof(buffer), "reallocate(%zu, %zu) -> nullptr", s1, s2); return AllocatorLogEntry(buffer); } inline AllocatorLogEntry Deallocate(size_t s) { char buffer[32]; - sprintf(buffer, "deallocate(%zu)", s); + snprintf(buffer, sizeof(buffer), "deallocate(%zu)", s); return AllocatorLogEntry(buffer); } @@ -260,6 +262,7 @@ class TimebombAllocator : public ArduinoJson::Allocator { size_t countdown_ = 0; Allocator* upstream_; }; +} // namespace inline size_t sizeofPoolList(size_t n = ARDUINOJSON_INITIAL_POOL_COUNT) { return sizeof(ArduinoJson::detail::VariantPool) * n; diff --git a/lib/ArduinoJson/extras/tests/Helpers/Literals.hpp b/lib/ArduinoJson/extras/tests/Helpers/Literals.hpp new file mode 100644 index 0000000..59164cf --- /dev/null +++ b/lib/ArduinoJson/extras/tests/Helpers/Literals.hpp @@ -0,0 +1,12 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2024, Benoit BLANCHON +// MIT License + +#pragma once + +#include + +// the space before _s is required by GCC 4.8 +inline std::string operator"" _s(const char* str, size_t len) { + return std::string(str, len); +} diff --git a/lib/ArduinoJson/extras/tests/JsonArray/add.cpp b/lib/ArduinoJson/extras/tests/JsonArray/add.cpp index 22f9920..1527670 100644 --- a/lib/ArduinoJson/extras/tests/JsonArray/add.cpp +++ b/lib/ArduinoJson/extras/tests/JsonArray/add.cpp @@ -6,6 +6,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" using ArduinoJson::detail::sizeofArray; @@ -51,7 +52,7 @@ TEST_CASE("JsonArray::add(T)") { array.add(vla); - REQUIRE(std::string("world") == array[0]); + REQUIRE("world"_s == array[0]); } #endif @@ -115,7 +116,7 @@ TEST_CASE("JsonArray::add(T)") { } SECTION("should duplicate std::string") { - array.add(std::string("world")); + array.add("world"_s); REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofPool()), Allocate(sizeofString("world")), @@ -139,7 +140,7 @@ TEST_CASE("JsonArray::add(T)") { } SECTION("should duplicate serialized(std::string)") { - array.add(serialized(std::string("{}"))); + array.add(serialized("{}"_s)); REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofPool()), Allocate(sizeofString("{}")), @@ -147,7 +148,7 @@ TEST_CASE("JsonArray::add(T)") { } SECTION("should duplicate serialized(std::string)") { - array.add(serialized(std::string("\0XX", 3))); + array.add(serialized("\0XX"_s)); REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofPool()), Allocate(sizeofString(" XX")), @@ -179,3 +180,52 @@ TEST_CASE("JsonArray::add()") { REQUIRE(doc.as() == "[42]"); } } + +TEST_CASE("JsonObject::add(JsonObject) ") { + JsonDocument doc1; + doc1["key1"_s] = "value1"_s; + + TimebombAllocator allocator(10); + SpyingAllocator spy(&allocator); + JsonDocument doc2(&spy); + JsonArray array = doc2.to(); + + SECTION("success") { + bool result = array.add(doc1.as()); + + REQUIRE(result == true); + REQUIRE(doc2.as() == "[{\"key1\":\"value1\"}]"); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("key1")), + Allocate(sizeofString("value1")), + }); + } + + SECTION("partial failure") { // issue #2081 + allocator.setCountdown(2); + + bool result = array.add(doc1.as()); + + REQUIRE(result == false); + REQUIRE(doc2.as() == "[]"); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("key1")), + AllocateFail(sizeofString("value1")), + Deallocate(sizeofString("key1")), + }); + } + + SECTION("complete failure") { + allocator.setCountdown(0); + + bool result = array.add(doc1.as()); + + REQUIRE(result == false); + REQUIRE(doc2.as() == "[]"); + REQUIRE(spy.log() == AllocatorLog{ + AllocateFail(sizeofPool()), + }); + } +} diff --git a/lib/ArduinoJson/extras/tests/JsonArray/copyArray.cpp b/lib/ArduinoJson/extras/tests/JsonArray/copyArray.cpp index f7a2ada..a82a6f8 100644 --- a/lib/ArduinoJson/extras/tests/JsonArray/copyArray.cpp +++ b/lib/ArduinoJson/extras/tests/JsonArray/copyArray.cpp @@ -6,6 +6,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" TEST_CASE("copyArray()") { SECTION("int[] -> JsonArray") { @@ -18,7 +19,7 @@ TEST_CASE("copyArray()") { CHECK(ok); serializeJson(array, json); - CHECK(std::string("[1,2,3]") == json); + CHECK("[1,2,3]"_s == json); } SECTION("std::string[] -> JsonArray") { @@ -31,7 +32,7 @@ TEST_CASE("copyArray()") { CHECK(ok); serializeJson(array, json); - CHECK(std::string("[\"a\",\"b\",\"c\"]") == json); + CHECK("[\"a\",\"b\",\"c\"]"_s == json); } SECTION("const char*[] -> JsonArray") { @@ -44,7 +45,7 @@ TEST_CASE("copyArray()") { CHECK(ok); serializeJson(array, json); - CHECK(std::string("[\"a\",\"b\",\"c\"]") == json); + CHECK("[\"a\",\"b\",\"c\"]"_s == json); } SECTION("const char[][] -> JsonArray") { @@ -57,7 +58,7 @@ TEST_CASE("copyArray()") { CHECK(ok); serializeJson(array, json); - CHECK(std::string("[\"a\",\"b\",\"c\"]") == json); + CHECK("[\"a\",\"b\",\"c\"]"_s == json); } SECTION("const char[][] -> JsonDocument") { @@ -69,7 +70,7 @@ TEST_CASE("copyArray()") { CHECK(ok); serializeJson(doc, json); - CHECK(std::string("[\"a\",\"b\",\"c\"]") == json); + CHECK("[\"a\",\"b\",\"c\"]"_s == json); } SECTION("const char[][] -> MemberProxy") { @@ -81,7 +82,7 @@ TEST_CASE("copyArray()") { CHECK(ok); serializeJson(doc, json); - CHECK(std::string("{\"data\":[\"a\",\"b\",\"c\"]}") == json); + CHECK("{\"data\":[\"a\",\"b\",\"c\"]}"_s == json); } SECTION("int[] -> JsonDocument") { @@ -93,7 +94,7 @@ TEST_CASE("copyArray()") { CHECK(ok); serializeJson(doc, json); - CHECK(std::string("[1,2,3]") == json); + CHECK("[1,2,3]"_s == json); } SECTION("int[] -> MemberProxy") { @@ -105,7 +106,7 @@ TEST_CASE("copyArray()") { CHECK(ok); serializeJson(doc, json); - CHECK(std::string("{\"data\":[1,2,3]}") == json); + CHECK("{\"data\":[1,2,3]}"_s == json); } SECTION("int[] -> JsonArray, but not enough memory") { @@ -127,7 +128,7 @@ TEST_CASE("copyArray()") { CHECK(ok); serializeJson(array, json); - CHECK(std::string("[[1,2,3],[4,5,6]]") == json); + CHECK("[[1,2,3],[4,5,6]]"_s == json); } SECTION("int[][] -> MemberProxy") { @@ -139,7 +140,7 @@ TEST_CASE("copyArray()") { CHECK(ok); serializeJson(doc, json); - CHECK(std::string("{\"data\":[[1,2,3],[4,5,6]]}") == json); + CHECK("{\"data\":[[1,2,3],[4,5,6]]}"_s == json); } SECTION("int[][] -> JsonDocument") { @@ -151,7 +152,7 @@ TEST_CASE("copyArray()") { CHECK(ok); serializeJson(doc, json); - CHECK(std::string("[[1,2,3],[4,5,6]]") == json); + CHECK("[[1,2,3],[4,5,6]]"_s == json); } SECTION("int[][] -> JsonArray, but not enough memory") { @@ -223,9 +224,9 @@ TEST_CASE("copyArray()") { size_t result = copyArray(array, destination); CHECK(3 == result); - CHECK(std::string("a12345") == destination[0]); - CHECK(std::string("b123456") == destination[1]); - CHECK(std::string("c123456") == destination[2]); // truncated + CHECK("a12345"_s == destination[0]); + CHECK("b123456"_s == destination[1]); + CHECK("c123456"_s == destination[2]); // truncated CHECK(std::string("") == destination[3]); } diff --git a/lib/ArduinoJson/extras/tests/JsonArray/remove.cpp b/lib/ArduinoJson/extras/tests/JsonArray/remove.cpp index 6e67130..9cbd90b 100644 --- a/lib/ArduinoJson/extras/tests/JsonArray/remove.cpp +++ b/lib/ArduinoJson/extras/tests/JsonArray/remove.cpp @@ -88,6 +88,15 @@ TEST_CASE("JsonArray::remove()") { JsonArray unboundArray; unboundArray.remove(unboundArray.begin()); } + + SECTION("use JsonVariant as index") { + array.remove(array[3]); // no effect with null variant + array.remove(array[0]); // remove element at index 1 + + REQUIRE(2 == array.size()); + REQUIRE(array[0] == 1); + REQUIRE(array[1] == 3); + } } TEST_CASE("Removed elements are recycled") { diff --git a/lib/ArduinoJson/extras/tests/JsonArray/std_string.cpp b/lib/ArduinoJson/extras/tests/JsonArray/std_string.cpp index fc28d52..d6cae2e 100644 --- a/lib/ArduinoJson/extras/tests/JsonArray/std_string.cpp +++ b/lib/ArduinoJson/extras/tests/JsonArray/std_string.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + static void eraseString(std::string& str) { char* p = const_cast(str.c_str()); while (*p) @@ -19,7 +21,7 @@ TEST_CASE("std::string") { std::string value("hello"); array.add(value); eraseString(value); - REQUIRE(std::string("hello") == array[0]); + REQUIRE("hello"_s == array[0]); } SECTION("operator[]") { @@ -27,6 +29,6 @@ TEST_CASE("std::string") { array.add("hello"); array[0] = value; eraseString(value); - REQUIRE(std::string("world") == array[0]); + REQUIRE("world"_s == array[0]); } } diff --git a/lib/ArduinoJson/extras/tests/JsonArray/subscript.cpp b/lib/ArduinoJson/extras/tests/JsonArray/subscript.cpp index fde7617..b0332f8 100644 --- a/lib/ArduinoJson/extras/tests/JsonArray/subscript.cpp +++ b/lib/ArduinoJson/extras/tests/JsonArray/subscript.cpp @@ -7,6 +7,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" TEST_CASE("JsonArray::operator[]") { SpyingAllocator spy; @@ -129,7 +130,7 @@ TEST_CASE("JsonArray::operator[]") { } SECTION("should duplicate std::string") { - array[0] = std::string("world"); + array[0] = "world"_s; REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofPool()), Allocate(sizeofString("world")), @@ -150,7 +151,7 @@ TEST_CASE("JsonArray::operator[]") { array.add("hello"); array[0].set(vla); - REQUIRE(std::string("world") == array[0]); + REQUIRE("world"_s == array[0]); } SECTION("operator=(VLA)") { @@ -161,7 +162,16 @@ TEST_CASE("JsonArray::operator[]") { array.add("hello"); array[0] = vla; - REQUIRE(std::string("world") == array[0]); + REQUIRE("world"_s == array[0]); } #endif + + SECTION("Use a JsonVariant as index") { + array[0] = 1; + array[1] = 2; + array[2] = 3; + + REQUIRE(array[array[1]] == 3); + REQUIRE(array[array[3]] == nullptr); + } } diff --git a/lib/ArduinoJson/extras/tests/JsonArrayConst/subscript.cpp b/lib/ArduinoJson/extras/tests/JsonArrayConst/subscript.cpp index 4525287..28512b2 100644 --- a/lib/ArduinoJson/extras/tests/JsonArrayConst/subscript.cpp +++ b/lib/ArduinoJson/extras/tests/JsonArrayConst/subscript.cpp @@ -13,8 +13,15 @@ TEST_CASE("JsonArrayConst::operator[]") { doc.add(2); doc.add(3); - REQUIRE(1 == arr[0].as()); - REQUIRE(2 == arr[1].as()); - REQUIRE(3 == arr[2].as()); - REQUIRE(0 == arr[3].as()); + SECTION("int") { + REQUIRE(1 == arr[0].as()); + REQUIRE(2 == arr[1].as()); + REQUIRE(3 == arr[2].as()); + REQUIRE(0 == arr[3].as()); + } + + SECTION("JsonVariant") { + REQUIRE(2 == arr[arr[0]].as()); + REQUIRE(0 == arr[arr[3]].as()); + } } diff --git a/lib/ArduinoJson/extras/tests/JsonDeserializer/destination_types.cpp b/lib/ArduinoJson/extras/tests/JsonDeserializer/destination_types.cpp index d74dfb7..dc5c012 100644 --- a/lib/ArduinoJson/extras/tests/JsonDeserializer/destination_types.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDeserializer/destination_types.cpp @@ -8,6 +8,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" using ArduinoJson::detail::sizeofArray; using ArduinoJson::detail::sizeofObject; @@ -15,7 +16,7 @@ using ArduinoJson::detail::sizeofObject; TEST_CASE("deserializeJson(JsonDocument&)") { SpyingAllocator spy; JsonDocument doc(&spy); - doc.add(std::string("hello")); + doc.add("hello"_s); spy.clearLog(); auto err = deserializeJson(doc, "[42]"); @@ -34,7 +35,7 @@ TEST_CASE("deserializeJson(JsonVariant)") { SECTION("variant is bound") { SpyingAllocator spy; JsonDocument doc(&spy); - doc.add(std::string("hello")); + doc.add("hello"_s); spy.clearLog(); JsonVariant variant = doc[0]; @@ -60,7 +61,7 @@ TEST_CASE("deserializeJson(JsonVariant)") { TEST_CASE("deserializeJson(ElementProxy)") { SpyingAllocator spy; JsonDocument doc(&spy); - doc.add(std::string("hello")); + doc.add("hello"_s); spy.clearLog(); SECTION("element already exists") { @@ -85,7 +86,7 @@ TEST_CASE("deserializeJson(ElementProxy)") { TEST_CASE("deserializeJson(MemberProxy)") { SpyingAllocator spy; JsonDocument doc(&spy); - doc[std::string("hello")] = std::string("world"); + doc["hello"_s] = "world"_s; spy.clearLog(); SECTION("member already exists") { diff --git a/lib/ArduinoJson/extras/tests/JsonDeserializer/filter.cpp b/lib/ArduinoJson/extras/tests/JsonDeserializer/filter.cpp index b183382..4dc2fc6 100644 --- a/lib/ArduinoJson/extras/tests/JsonDeserializer/filter.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDeserializer/filter.cpp @@ -10,6 +10,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" using ArduinoJson::detail::sizeofArray; using ArduinoJson::detail::sizeofObject; @@ -732,7 +733,7 @@ TEST_CASE("Overloads") { } SECTION("const std::string&, Filter") { - deserializeJson(doc, std::string("{}"), Filter(filter)); + deserializeJson(doc, "{}"_s, Filter(filter)); } SECTION("std::istream&, Filter") { @@ -760,7 +761,7 @@ TEST_CASE("Overloads") { } SECTION("const std::string&, Filter, NestingLimit") { - deserializeJson(doc, std::string("{}"), Filter(filter), NestingLimit(5)); + deserializeJson(doc, "{}"_s, Filter(filter), NestingLimit(5)); } SECTION("std::istream&, Filter, NestingLimit") { @@ -788,7 +789,7 @@ TEST_CASE("Overloads") { } SECTION("const std::string&, NestingLimit, Filter") { - deserializeJson(doc, std::string("{}"), NestingLimit(5), Filter(filter)); + deserializeJson(doc, "{}"_s, NestingLimit(5), Filter(filter)); } SECTION("std::istream&, NestingLimit, Filter") { diff --git a/lib/ArduinoJson/extras/tests/JsonDeserializer/input_types.cpp b/lib/ArduinoJson/extras/tests/JsonDeserializer/input_types.cpp index 94f3c0e..a8a9e56 100644 --- a/lib/ArduinoJson/extras/tests/JsonDeserializer/input_types.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDeserializer/input_types.cpp @@ -9,6 +9,7 @@ #include "Allocators.hpp" #include "CustomReader.hpp" +#include "Literals.hpp" using ArduinoJson::detail::sizeofObject; @@ -69,7 +70,7 @@ TEST_CASE("deserializeJson(const std::string&)") { } SECTION("should accept temporary string") { - DeserializationError err = deserializeJson(doc, std::string("[42]")); + DeserializationError err = deserializeJson(doc, "[42]"_s); REQUIRE(err == DeserializationError::Ok); } @@ -82,7 +83,7 @@ TEST_CASE("deserializeJson(const std::string&)") { JsonArray array = doc.as(); REQUIRE(err == DeserializationError::Ok); - REQUIRE(std::string("hello") == array[0]); + REQUIRE("hello"_s == array[0]); } } @@ -108,7 +109,7 @@ TEST_CASE("deserializeJson(std::istream&)") { REQUIRE(err == DeserializationError::Ok); REQUIRE(1 == obj.size()); - REQUIRE(std::string("world") == obj["hello"]); + REQUIRE("world"_s == obj["hello"]); } SECTION("Should not read after the closing brace of an empty object") { diff --git a/lib/ArduinoJson/extras/tests/JsonDeserializer/nestingLimit.cpp b/lib/ArduinoJson/extras/tests/JsonDeserializer/nestingLimit.cpp index c5c5403..cd11841 100644 --- a/lib/ArduinoJson/extras/tests/JsonDeserializer/nestingLimit.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDeserializer/nestingLimit.cpp @@ -7,6 +7,8 @@ #include +#include "Literals.hpp" + #define SHOULD_WORK(expression) REQUIRE(DeserializationError::Ok == expression); #define SHOULD_FAIL(expression) \ REQUIRE(DeserializationError::TooDeep == expression); @@ -63,23 +65,23 @@ TEST_CASE("JsonDeserializer nesting") { SECTION("Input = std::string") { SECTION("limit = 0") { DeserializationOption::NestingLimit nesting(0); - SHOULD_WORK(deserializeJson(doc, std::string("\"toto\""), nesting)); - SHOULD_WORK(deserializeJson(doc, std::string("123"), nesting)); - SHOULD_WORK(deserializeJson(doc, std::string("true"), nesting)); - SHOULD_FAIL(deserializeJson(doc, std::string("[]"), nesting)); - SHOULD_FAIL(deserializeJson(doc, std::string("{}"), nesting)); - SHOULD_FAIL(deserializeJson(doc, std::string("[\"toto\"]"), nesting)); - SHOULD_FAIL(deserializeJson(doc, std::string("{\"toto\":1}"), nesting)); + SHOULD_WORK(deserializeJson(doc, "\"toto\""_s, nesting)); + SHOULD_WORK(deserializeJson(doc, "123"_s, nesting)); + SHOULD_WORK(deserializeJson(doc, "true"_s, nesting)); + SHOULD_FAIL(deserializeJson(doc, "[]"_s, nesting)); + SHOULD_FAIL(deserializeJson(doc, "{}"_s, nesting)); + SHOULD_FAIL(deserializeJson(doc, "[\"toto\"]"_s, nesting)); + SHOULD_FAIL(deserializeJson(doc, "{\"toto\":1}"_s, nesting)); } SECTION("limit = 1") { DeserializationOption::NestingLimit nesting(1); - SHOULD_WORK(deserializeJson(doc, std::string("[\"toto\"]"), nesting)); - SHOULD_WORK(deserializeJson(doc, std::string("{\"toto\":1}"), nesting)); - SHOULD_FAIL(deserializeJson(doc, std::string("{\"toto\":{}}"), nesting)); - SHOULD_FAIL(deserializeJson(doc, std::string("{\"toto\":[]}"), nesting)); - SHOULD_FAIL(deserializeJson(doc, std::string("[[\"toto\"]]"), nesting)); - SHOULD_FAIL(deserializeJson(doc, std::string("[{\"toto\":1}]"), nesting)); + SHOULD_WORK(deserializeJson(doc, "[\"toto\"]"_s, nesting)); + SHOULD_WORK(deserializeJson(doc, "{\"toto\":1}"_s, nesting)); + SHOULD_FAIL(deserializeJson(doc, "{\"toto\":{}}"_s, nesting)); + SHOULD_FAIL(deserializeJson(doc, "{\"toto\":[]}"_s, nesting)); + SHOULD_FAIL(deserializeJson(doc, "[[\"toto\"]]"_s, nesting)); + SHOULD_FAIL(deserializeJson(doc, "[{\"toto\":1}]"_s, nesting)); } } diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/ElementProxy.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/ElementProxy.cpp index d13f210..0a9039d 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/ElementProxy.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/ElementProxy.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + typedef ArduinoJson::detail::ElementProxy ElementProxy; TEST_CASE("ElementProxy::add()") { @@ -121,7 +123,7 @@ TEST_CASE("ElementProxy::remove()") { ep["a"] = 1; ep["b"] = 2; - ep.remove(std::string("b")); + ep.remove("b"_s); REQUIRE(ep.as() == "{\"a\":1}"); } diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/MemberProxy.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/MemberProxy.cpp index 5bdafa0..bb6acdf 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/MemberProxy.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/MemberProxy.cpp @@ -9,6 +9,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" using ArduinoJson::detail::sizeofArray; using ArduinoJson::detail::sizeofObject; @@ -106,8 +107,8 @@ TEST_CASE("MemberProxy::containsKey()") { SECTION("containsKey(std::string)") { mp["key"] = "value"; - REQUIRE(mp.containsKey(std::string("key")) == true); - REQUIRE(mp.containsKey(std::string("key")) == true); + REQUIRE(mp.containsKey("key"_s) == true); + REQUIRE(mp.containsKey("key"_s) == true); } } @@ -117,8 +118,8 @@ TEST_CASE("MemberProxy::operator|()") { SECTION("const char*") { doc["a"] = "hello"; - REQUIRE((doc["a"] | "world") == std::string("hello")); - REQUIRE((doc["b"] | "world") == std::string("world")); + REQUIRE((doc["a"] | "world") == "hello"_s); + REQUIRE((doc["b"] | "world") == "world"_s); } SECTION("Issue #1411") { @@ -128,7 +129,7 @@ TEST_CASE("MemberProxy::operator|()") { // to trigger the bug const char* sensor = doc["sensor"] | test; // "gps" - REQUIRE(sensor == std::string("gps")); + REQUIRE(sensor == "gps"_s); } SECTION("Issue #1415") { @@ -170,7 +171,7 @@ TEST_CASE("MemberProxy::remove()") { mp["a"] = 1; mp["b"] = 2; - mp.remove(std::string("b")); + mp.remove("b"_s); REQUIRE(mp.as() == "{\"a\":1}"); } @@ -286,8 +287,8 @@ TEST_CASE("Deduplicate keys") { JsonDocument doc(&spy); SECTION("std::string") { - doc[0][std::string("example")] = 1; - doc[1][std::string("example")] = 2; + doc[0]["example"_s] = 1; + doc[1]["example"_s] = 2; const char* key1 = doc[0].as().begin()->key().c_str(); const char* key2 = doc[1].as().begin()->key().c_str(); @@ -351,7 +352,7 @@ TEST_CASE("MemberProxy under memory constraints") { SECTION("key allocation fails") { killswitch.on(); - doc[std::string("hello")] = "world"; + doc["hello"_s] = "world"; REQUIRE(doc.is()); REQUIRE(doc.size() == 0); diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/add.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/add.cpp index b7fe758..498663c 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/add.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/add.cpp @@ -9,6 +9,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" using ArduinoJson::detail::sizeofArray; @@ -35,8 +36,8 @@ TEST_CASE("JsonDocument::add(T)") { } SECTION("std::string") { - doc.add(std::string("example")); - doc.add(std::string("example")); + doc.add("example"_s); + doc.add("example"_s); CHECK(doc[0].as() == doc[1].as()); REQUIRE(spy.log() == AllocatorLog{ @@ -90,15 +91,57 @@ TEST_CASE("JsonDocument::add()") { REQUIRE(doc.as() == "[[1,2]]"); } - SECTION("JsonObject") { - JsonObject object = doc.add(); - object["hello"] = "world"; - REQUIRE(doc.as() == "[{\"hello\":\"world\"}]"); - } - SECTION("JsonVariant") { JsonVariant variant = doc.add(); variant.set(42); REQUIRE(doc.as() == "[42]"); } } + +TEST_CASE("JsonObject::add(JsonObject) ") { + JsonDocument doc1; + doc1["hello"_s] = "world"_s; + + TimebombAllocator allocator(10); + SpyingAllocator spy(&allocator); + JsonDocument doc2(&spy); + + SECTION("success") { + bool result = doc2.add(doc1.as()); + + REQUIRE(result == true); + REQUIRE(doc2.as() == "[{\"hello\":\"world\"}]"); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("hello")), + Allocate(sizeofString("world")), + }); + } + + SECTION("partial failure") { // issue #2081 + allocator.setCountdown(2); + + bool result = doc2.add(doc1.as()); + + REQUIRE(result == false); + REQUIRE(doc2.as() == "[]"); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("hello")), + AllocateFail(sizeofString("world")), + Deallocate(sizeofString("hello")), + }); + } + + SECTION("complete failure") { + allocator.setCountdown(0); + + bool result = doc2.add(doc1.as()); + + REQUIRE(result == false); + REQUIRE(doc2.as() == "[]"); + REQUIRE(spy.log() == AllocatorLog{ + AllocateFail(sizeofPool()), + }); + } +} diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/assignment.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/assignment.cpp index 832c12b..42cef3e 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/assignment.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/assignment.cpp @@ -6,6 +6,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" TEST_CASE("JsonDocument assignment") { SpyingAllocator spyingAllocator; @@ -62,7 +63,7 @@ TEST_CASE("JsonDocument assignment") { SECTION("Move assign") { { JsonDocument doc1(&spyingAllocator); - doc1[std::string("hello")] = std::string("world"); + doc1["hello"_s] = "world"_s; JsonDocument doc2(&spyingAllocator); doc2 = std::move(doc1); diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/clear.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/clear.cpp index 8d3f227..3b9f6ee 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/clear.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/clear.cpp @@ -9,6 +9,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" TEST_CASE("JsonDocument::clear()") { SpyingAllocator spy; @@ -22,7 +23,7 @@ TEST_CASE("JsonDocument::clear()") { } SECTION("releases resources") { - doc[std::string("hello")] = std::string("world"); + doc["hello"_s] = "world"_s; spy.clearLog(); doc.clear(); diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/constructor.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/constructor.cpp index 4d63695..239b3bf 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/constructor.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/constructor.cpp @@ -6,6 +6,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" using ArduinoJson::detail::addPadding; @@ -20,7 +21,7 @@ TEST_CASE("JsonDocument constructor") { SECTION("JsonDocument(const JsonDocument&)") { { JsonDocument doc1(&spyingAllocator); - doc1.set(std::string("The size of this string is 32!!")); + doc1.set("The size of this string is 32!!"_s); JsonDocument doc2(doc1); @@ -38,7 +39,7 @@ TEST_CASE("JsonDocument constructor") { SECTION("JsonDocument(JsonDocument&&)") { { JsonDocument doc1(&spyingAllocator); - doc1.set(std::string("The size of this string is 32!!")); + doc1.set("The size of this string is 32!!"_s); JsonDocument doc2(std::move(doc1)); @@ -117,4 +118,31 @@ TEST_CASE("JsonDocument constructor") { REQUIRE(doc2.as() == "hello"); } + + SECTION("JsonDocument(JsonVariantConst)") { + JsonDocument doc1; + deserializeJson(doc1, "\"hello\""); + + JsonDocument doc2(doc1.as()); + + REQUIRE(doc2.as() == "hello"); + } + + SECTION("JsonDocument(ElementProxy)") { + JsonDocument doc1; + deserializeJson(doc1, "[\"hello\",\"world\"]"); + + JsonDocument doc2(doc1[1]); + + REQUIRE(doc2.as() == "world"); + } + + SECTION("JsonDocument(MemberProxy)") { + JsonDocument doc1; + deserializeJson(doc1, "{\"hello\":\"world\"}"); + + JsonDocument doc2(doc1["hello"]); + + REQUIRE(doc2.as() == "world"); + } } diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/containsKey.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/containsKey.cpp index 9425e01..a68236e 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/containsKey.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/containsKey.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + TEST_CASE("JsonDocument::containsKey()") { JsonDocument doc; @@ -23,7 +25,7 @@ TEST_CASE("JsonDocument::containsKey()") { SECTION("returns true when key is a std::string") { doc["hello"] = "world"; - REQUIRE(doc.containsKey(std::string("hello")) == true); + REQUIRE(doc.containsKey("hello"_s) == true); } SECTION("returns false on object") { @@ -41,4 +43,12 @@ TEST_CASE("JsonDocument::containsKey()") { SECTION("returns false on null") { REQUIRE(doc.containsKey("hello") == false); } + + SECTION("support JsonVariant") { + doc["hello"] = "world"; + doc["key"] = "hello"; + + REQUIRE(doc.containsKey(doc["key"]) == true); + REQUIRE(doc.containsKey(doc["foo"]) == false); + } } diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/issue1120.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/issue1120.cpp index 766ecea..07ad932 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/issue1120.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/issue1120.cpp @@ -2,6 +2,8 @@ #include +#include "Literals.hpp" + TEST_CASE("Issue #1120") { JsonDocument doc; constexpr char str[] = @@ -10,12 +12,12 @@ TEST_CASE("Issue #1120") { SECTION("MemberProxy::isNull()") { SECTION("returns false") { - auto value = doc[std::string("contents")]; + auto value = doc["contents"_s]; CHECK(value.isNull() == false); } SECTION("returns true") { - auto value = doc[std::string("zontents")]; + auto value = doc["zontents"_s]; CHECK(value.isNull() == true); } } @@ -46,12 +48,12 @@ TEST_CASE("Issue #1120") { SECTION("MemberProxy, std::string>::isNull()") { SECTION("returns false") { - auto value = doc["contents"][1][std::string("module")]; + auto value = doc["contents"][1]["module"_s]; CHECK(value.isNull() == false); } SECTION("returns true") { - auto value = doc["contents"][1][std::string("zodule")]; + auto value = doc["contents"][1]["zodule"_s]; CHECK(value.isNull() == true); } } diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/overflowed.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/overflowed.cpp index 145cbc9..9dfa83f 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/overflowed.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/overflowed.cpp @@ -6,6 +6,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" TEST_CASE("JsonDocument::overflowed()") { TimebombAllocator timebomb(10); @@ -30,13 +31,13 @@ TEST_CASE("JsonDocument::overflowed()") { SECTION("returns true after a failed string copy") { timebomb.setCountdown(0); - doc.add(std::string("example")); + doc.add("example"_s); CHECK(doc.overflowed() == true); } SECTION("returns false after a successful string copy") { timebomb.setCountdown(3); - doc.add(std::string("example")); + doc.add("example"_s); CHECK(doc.overflowed() == false); } diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/remove.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/remove.cpp index 26048e3..afabf4e 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/remove.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/remove.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + TEST_CASE("JsonDocument::remove()") { JsonDocument doc; @@ -31,7 +33,7 @@ TEST_CASE("JsonDocument::remove()") { doc["a"] = 1; doc["b"] = 2; - doc.remove(std::string("b")); + doc.remove("b"_s); REQUIRE(doc.as() == "{\"a\":1}"); } @@ -49,4 +51,25 @@ TEST_CASE("JsonDocument::remove()") { REQUIRE(doc.as() == "{\"a\":1}"); } #endif + + SECTION("remove(JsonVariant) from object") { + doc["a"] = 1; + doc["b"] = 2; + doc["c"] = "b"; + + doc.remove(doc["c"]); + + REQUIRE(doc.as() == "{\"a\":1,\"c\":\"b\"}"); + } + + SECTION("remove(JsonVariant) from array") { + doc[0] = 3; + doc[1] = 2; + doc[2] = 1; + + doc.remove(doc[2]); + doc.remove(doc[3]); // noop + + REQUIRE(doc.as() == "[3,1]"); + } } diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/shrinkToFit.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/shrinkToFit.cpp index 82a65f4..1d43140 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/shrinkToFit.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/shrinkToFit.cpp @@ -9,6 +9,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" using ArduinoJson::detail::sizeofArray; using ArduinoJson::detail::sizeofObject; @@ -78,7 +79,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") { } SECTION("owned string") { - doc.set(std::string("abcdefg")); + doc.set("abcdefg"_s); REQUIRE(doc.as() == "abcdefg"); doc.shrinkToFit(); @@ -114,7 +115,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") { } SECTION("owned key") { - doc[std::string("abcdefg")] = 42; + doc["abcdefg"_s] = 42; doc.shrinkToFit(); @@ -141,7 +142,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") { } SECTION("owned string in array") { - doc.add(std::string("abcdefg")); + doc.add("abcdefg"_s); doc.shrinkToFit(); @@ -168,7 +169,7 @@ TEST_CASE("JsonDocument::shrinkToFit()") { } SECTION("owned string in object") { - doc["key"] = std::string("abcdefg"); + doc["key"] = "abcdefg"_s; doc.shrinkToFit(); diff --git a/lib/ArduinoJson/extras/tests/JsonDocument/subscript.cpp b/lib/ArduinoJson/extras/tests/JsonDocument/subscript.cpp index ed8a695..5c7a65d 100644 --- a/lib/ArduinoJson/extras/tests/JsonDocument/subscript.cpp +++ b/lib/ArduinoJson/extras/tests/JsonDocument/subscript.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + TEST_CASE("JsonDocument::operator[]") { JsonDocument doc; const JsonDocument& cdoc = doc; @@ -18,21 +20,35 @@ TEST_CASE("JsonDocument::operator[]") { } SECTION("std::string") { - REQUIRE(doc[std::string("hello")] == "world"); - REQUIRE(cdoc[std::string("hello")] == "world"); + REQUIRE(doc["hello"_s] == "world"); + REQUIRE(cdoc["hello"_s] == "world"); + } + + SECTION("JsonVariant") { + doc["key"] = "hello"; + REQUIRE(doc[doc["key"]] == "world"); + REQUIRE(cdoc[cdoc["key"]] == "world"); } SECTION("supports operator|") { - REQUIRE((doc["hello"] | "nope") == std::string("world")); - REQUIRE((doc["world"] | "nope") == std::string("nope")); + REQUIRE((doc["hello"] | "nope") == "world"_s); + REQUIRE((doc["world"] | "nope") == "nope"_s); } } SECTION("array") { deserializeJson(doc, "[\"hello\",\"world\"]"); - REQUIRE(doc[1] == "world"); - REQUIRE(cdoc[1] == "world"); + SECTION("int") { + REQUIRE(doc[1] == "world"); + REQUIRE(cdoc[1] == "world"); + } + + SECTION("JsonVariant") { + doc[2] = 1; + REQUIRE(doc[doc[2]] == "world"); + REQUIRE(cdoc[doc[2]] == "world"); + } } } diff --git a/lib/ArduinoJson/extras/tests/JsonObject/CMakeLists.txt b/lib/ArduinoJson/extras/tests/JsonObject/CMakeLists.txt index 15c4035..dd2dfaa 100644 --- a/lib/ArduinoJson/extras/tests/JsonObject/CMakeLists.txt +++ b/lib/ArduinoJson/extras/tests/JsonObject/CMakeLists.txt @@ -6,12 +6,12 @@ add_executable(JsonObjectTests clear.cpp compare.cpp containsKey.cpp - copy.cpp equals.cpp isNull.cpp iterator.cpp nesting.cpp remove.cpp + set.cpp size.cpp std_string.cpp subscript.cpp diff --git a/lib/ArduinoJson/extras/tests/JsonObject/containsKey.cpp b/lib/ArduinoJson/extras/tests/JsonObject/containsKey.cpp index a5e20e9..d7dd8d1 100644 --- a/lib/ArduinoJson/extras/tests/JsonObject/containsKey.cpp +++ b/lib/ArduinoJson/extras/tests/JsonObject/containsKey.cpp @@ -30,4 +30,10 @@ TEST_CASE("JsonObject::containsKey()") { REQUIRE(true == obj.containsKey(vla)); } #endif + + SECTION("key is a JsonVariant") { + doc["key"] = "hello"; + REQUIRE(true == obj.containsKey(obj["key"])); + REQUIRE(false == obj.containsKey(obj["hello"])); + } } diff --git a/lib/ArduinoJson/extras/tests/JsonObject/remove.cpp b/lib/ArduinoJson/extras/tests/JsonObject/remove.cpp index 0124c4a..4c3e35d 100644 --- a/lib/ArduinoJson/extras/tests/JsonObject/remove.cpp +++ b/lib/ArduinoJson/extras/tests/JsonObject/remove.cpp @@ -80,4 +80,10 @@ TEST_CASE("JsonObject::remove()") { JsonObject unboundObject; unboundObject.remove(unboundObject.begin()); } + + SECTION("remove(JsonVariant)") { + obj["key"] = "b"; + obj.remove(obj["key"]); + REQUIRE("{\"a\":0,\"c\":2,\"key\":\"b\"}" == doc.as()); + } } diff --git a/lib/ArduinoJson/extras/tests/JsonObject/copy.cpp b/lib/ArduinoJson/extras/tests/JsonObject/set.cpp similarity index 84% rename from lib/ArduinoJson/extras/tests/JsonObject/copy.cpp rename to lib/ArduinoJson/extras/tests/JsonObject/set.cpp index 6c67d08..f80f8a8 100644 --- a/lib/ArduinoJson/extras/tests/JsonObject/copy.cpp +++ b/lib/ArduinoJson/extras/tests/JsonObject/set.cpp @@ -6,6 +6,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" TEST_CASE("JsonObject::set()") { SpyingAllocator spy; @@ -22,20 +23,20 @@ TEST_CASE("JsonObject::set()") { bool success = obj2.set(obj1); REQUIRE(success == true); - REQUIRE(obj2["hello"] == std::string("world")); + REQUIRE(obj2["hello"] == "world"_s); REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofPool()), }); } SECTION("copy local string value") { - obj1["hello"] = std::string("world"); + obj1["hello"] = "world"_s; spy.clearLog(); bool success = obj2.set(obj1); REQUIRE(success == true); - REQUIRE(obj2["hello"] == std::string("world")); + REQUIRE(obj2["hello"] == "world"_s); REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofPool()), Allocate(sizeofString("world")), @@ -43,13 +44,13 @@ TEST_CASE("JsonObject::set()") { } SECTION("copy local key") { - obj1[std::string("hello")] = "world"; + obj1["hello"_s] = "world"; spy.clearLog(); bool success = obj2.set(obj1); REQUIRE(success == true); - REQUIRE(obj2["hello"] == std::string("world")); + REQUIRE(obj2["hello"] == "world"_s); REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofString("hello")), Allocate(sizeofPool()), @@ -63,7 +64,7 @@ TEST_CASE("JsonObject::set()") { bool success = obj2.set(obj1); REQUIRE(success == true); - REQUIRE(obj2["hello"] == std::string("world")); + REQUIRE(obj2["hello"] == "world"_s); REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofString("hello")), Allocate(sizeofPool()), @@ -78,7 +79,7 @@ TEST_CASE("JsonObject::set()") { bool success = obj2.set(obj1); REQUIRE(success == true); - REQUIRE(obj2["hello"] == std::string("world")); + REQUIRE(obj2["hello"] == "world"_s); REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofString("hello")), Allocate(sizeofPool()), @@ -91,7 +92,7 @@ TEST_CASE("JsonObject::set()") { obj2.set(static_cast(obj1)); - REQUIRE(obj2["hello"] == std::string("world")); + REQUIRE(obj2["hello"] == "world"_s); } SECTION("copy fails in the middle of an object") { @@ -99,8 +100,8 @@ TEST_CASE("JsonObject::set()") { JsonDocument doc3(&timebomb); JsonObject obj3 = doc3.to(); - obj1[std::string("a")] = 1; - obj1[std::string("b")] = 2; + obj1["a"_s] = 1; + obj1["b"_s] = 2; bool success = obj3.set(obj1); @@ -113,12 +114,12 @@ TEST_CASE("JsonObject::set()") { JsonDocument doc3(&timebomb); JsonObject obj3 = doc3.to(); - obj1["hello"][0] = std::string("world"); + obj1["hello"][0] = "world"_s; bool success = obj3.set(obj1); REQUIRE(success == false); - REQUIRE(doc3.as() == "{\"hello\":[null]}"); + REQUIRE(doc3.as() == "{\"hello\":[]}"); } SECTION("destination is null") { diff --git a/lib/ArduinoJson/extras/tests/JsonObject/std_string.cpp b/lib/ArduinoJson/extras/tests/JsonObject/std_string.cpp index 1bd533c..613e0bd 100644 --- a/lib/ArduinoJson/extras/tests/JsonObject/std_string.cpp +++ b/lib/ArduinoJson/extras/tests/JsonObject/std_string.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + static void eraseString(std::string& str) { char* p = const_cast(str.c_str()); while (*p) @@ -20,7 +22,7 @@ TEST_CASE("std::string") { deserializeJson(doc, json); JsonObject obj = doc.as(); - REQUIRE(std::string("value") == obj[std::string("key")]); + REQUIRE("value"_s == obj["key"_s]); } SECTION("operator[] const") { @@ -29,21 +31,21 @@ TEST_CASE("std::string") { deserializeJson(doc, json); JsonObject obj = doc.as(); - REQUIRE(std::string("value") == obj[std::string("key")]); + REQUIRE("value"_s == obj["key"_s]); } SECTION("containsKey()") { char json[] = "{\"key\":\"value\"}"; deserializeJson(doc, json); JsonObject obj = doc.as(); - REQUIRE(true == obj.containsKey(std::string("key"))); + REQUIRE(true == obj.containsKey("key"_s)); } SECTION("remove()") { JsonObject obj = doc.to(); obj["key"] = "value"; - obj.remove(std::string("key")); + obj.remove("key"_s); REQUIRE(0 == obj.size()); } @@ -53,7 +55,7 @@ TEST_CASE("std::string") { JsonObject obj = doc.to(); obj[key] = "world"; eraseString(key); - REQUIRE(std::string("world") == obj["hello"]); + REQUIRE("world"_s == obj["hello"]); } SECTION("operator[], set value") { @@ -61,6 +63,6 @@ TEST_CASE("std::string") { JsonObject obj = doc.to(); obj["hello"] = value; eraseString(value); - REQUIRE(std::string("world") == obj["hello"]); + REQUIRE("world"_s == obj["hello"]); } } diff --git a/lib/ArduinoJson/extras/tests/JsonObject/subscript.cpp b/lib/ArduinoJson/extras/tests/JsonObject/subscript.cpp index 2f8c95f..775d149 100644 --- a/lib/ArduinoJson/extras/tests/JsonObject/subscript.cpp +++ b/lib/ArduinoJson/extras/tests/JsonObject/subscript.cpp @@ -6,6 +6,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" TEST_CASE("JsonObject::operator[]") { SpyingAllocator spy; @@ -50,7 +51,7 @@ TEST_CASE("JsonObject::operator[]") { REQUIRE(true == obj["hello"].is()); REQUIRE(false == obj["hello"].is()); - REQUIRE(std::string("h3110") == obj["hello"].as()); + REQUIRE("h3110"_s == obj["hello"].as()); } SECTION("array") { @@ -132,7 +133,7 @@ TEST_CASE("JsonObject::operator[]") { } SECTION("should duplicate std::string value") { - obj["hello"] = std::string("world"); + obj["hello"] = "world"_s; REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofPool()), Allocate(sizeofString("world")), @@ -140,7 +141,7 @@ TEST_CASE("JsonObject::operator[]") { } SECTION("should duplicate std::string key") { - obj[std::string("hello")] = "world"; + obj["hello"_s] = "world"; REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofString("hello")), Allocate(sizeofPool()), @@ -148,7 +149,7 @@ TEST_CASE("JsonObject::operator[]") { } SECTION("should duplicate std::string key&value") { - obj[std::string("hello")] = std::string("world"); + obj["hello"_s] = "world"_s; REQUIRE(spy.log() == AllocatorLog{ Allocate(sizeofString("hello")), Allocate(sizeofPool()), @@ -197,7 +198,7 @@ TEST_CASE("JsonObject::operator[]") { obj[vla] = "world"; - REQUIRE(std::string("world") == obj["hello"]); + REQUIRE("world"_s == obj["hello"]); } SECTION("obj[str] = VLA") { // issue #416 @@ -207,7 +208,7 @@ TEST_CASE("JsonObject::operator[]") { obj["hello"] = vla; - REQUIRE(std::string("world") == obj["hello"].as()); + REQUIRE("world"_s == obj["hello"].as()); } SECTION("obj.set(VLA, str)") { @@ -217,7 +218,7 @@ TEST_CASE("JsonObject::operator[]") { obj[vla] = "world"; - REQUIRE(std::string("world") == obj["hello"]); + REQUIRE("world"_s == obj["hello"]); } SECTION("obj.set(str, VLA)") { @@ -227,7 +228,7 @@ TEST_CASE("JsonObject::operator[]") { obj["hello"].set(vla); - REQUIRE(std::string("world") == obj["hello"].as()); + REQUIRE("world"_s == obj["hello"].as()); } SECTION("obj[VLA]") { @@ -238,7 +239,7 @@ TEST_CASE("JsonObject::operator[]") { deserializeJson(doc, "{\"hello\":\"world\"}"); obj = doc.as(); - REQUIRE(std::string("world") == obj[vla]); + REQUIRE("world"_s == obj[vla]); } #endif @@ -249,4 +250,12 @@ TEST_CASE("JsonObject::operator[]") { REQUIRE(true == obj["hello"]["world"].is()); REQUIRE(false == obj["hello"]["world"].is()); } + + SECTION("JsonVariant") { + obj["hello"] = "world"; + doc["key"] = "hello"; + + REQUIRE(obj[obj["key"]] == "world"); + REQUIRE(obj[obj["foo"]] == nullptr); + } } diff --git a/lib/ArduinoJson/extras/tests/JsonObjectConst/containsKey.cpp b/lib/ArduinoJson/extras/tests/JsonObjectConst/containsKey.cpp index 3b63941..3283c08 100644 --- a/lib/ArduinoJson/extras/tests/JsonObjectConst/containsKey.cpp +++ b/lib/ArduinoJson/extras/tests/JsonObjectConst/containsKey.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + TEST_CASE("JsonObjectConst::containsKey()") { JsonDocument doc; doc["hello"] = 42; @@ -16,8 +18,8 @@ TEST_CASE("JsonObjectConst::containsKey()") { } SECTION("supports std::string") { - REQUIRE(false == obj.containsKey(std::string("world"))); - REQUIRE(true == obj.containsKey(std::string("hello"))); + REQUIRE(false == obj.containsKey("world"_s)); + REQUIRE(true == obj.containsKey("hello"_s)); } #ifdef HAS_VARIABLE_LENGTH_ARRAY @@ -29,4 +31,10 @@ TEST_CASE("JsonObjectConst::containsKey()") { REQUIRE(true == obj.containsKey(vla)); } #endif + + SECTION("supports JsonVariant") { + doc["key"] = "hello"; + REQUIRE(true == obj.containsKey(obj["key"])); + REQUIRE(false == obj.containsKey(obj["hello"])); + } } diff --git a/lib/ArduinoJson/extras/tests/JsonObjectConst/subscript.cpp b/lib/ArduinoJson/extras/tests/JsonObjectConst/subscript.cpp index 917b54a..12f080c 100644 --- a/lib/ArduinoJson/extras/tests/JsonObjectConst/subscript.cpp +++ b/lib/ArduinoJson/extras/tests/JsonObjectConst/subscript.cpp @@ -6,6 +6,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" TEST_CASE("JsonObjectConst::operator[]") { JsonDocument doc; @@ -17,7 +18,7 @@ TEST_CASE("JsonObjectConst::operator[]") { } SECTION("supports std::string") { - REQUIRE(obj[std::string("hello")] == "world"); // issue #2019 + REQUIRE(obj["hello"_s] == "world"); // issue #2019 } #if defined(HAS_VARIABLE_LENGTH_ARRAY) && \ @@ -27,7 +28,13 @@ TEST_CASE("JsonObjectConst::operator[]") { char vla[i]; strcpy(vla, "hello"); - REQUIRE(std::string("world") == obj[vla]); + REQUIRE("world"_s == obj[vla]); } #endif + + SECTION("supports JsonVariant") { + doc["key"] = "hello"; + REQUIRE(obj[obj["key"]] == "world"); + REQUIRE(obj[obj["foo"]] == nullptr); + } } diff --git a/lib/ArduinoJson/extras/tests/JsonSerializer/JsonVariant.cpp b/lib/ArduinoJson/extras/tests/JsonSerializer/JsonVariant.cpp index 694cbb0..800c3a9 100644 --- a/lib/ArduinoJson/extras/tests/JsonSerializer/JsonVariant.cpp +++ b/lib/ArduinoJson/extras/tests/JsonSerializer/JsonVariant.cpp @@ -6,6 +6,8 @@ #include #include +#include "Literals.hpp" + template void check(T value, const std::string& expected) { JsonDocument doc; @@ -30,42 +32,42 @@ TEST_CASE("serializeJson(JsonVariant)") { } SECTION("string") { - check(std::string("hello"), "\"hello\""); + check("hello"_s, "\"hello\""); SECTION("Escape quotation mark") { - check(std::string("hello \"world\""), "\"hello \\\"world\\\"\""); + check("hello \"world\""_s, "\"hello \\\"world\\\"\""); } SECTION("Escape reverse solidus") { - check(std::string("hello\\world"), "\"hello\\\\world\""); + check("hello\\world"_s, "\"hello\\\\world\""); } SECTION("Don't escape solidus") { - check(std::string("fifty/fifty"), "\"fifty/fifty\""); + check("fifty/fifty"_s, "\"fifty/fifty\""); } SECTION("Escape backspace") { - check(std::string("hello\bworld"), "\"hello\\bworld\""); + check("hello\bworld"_s, "\"hello\\bworld\""); } SECTION("Escape formfeed") { - check(std::string("hello\fworld"), "\"hello\\fworld\""); + check("hello\fworld"_s, "\"hello\\fworld\""); } SECTION("Escape linefeed") { - check(std::string("hello\nworld"), "\"hello\\nworld\""); + check("hello\nworld"_s, "\"hello\\nworld\""); } SECTION("Escape carriage return") { - check(std::string("hello\rworld"), "\"hello\\rworld\""); + check("hello\rworld"_s, "\"hello\\rworld\""); } SECTION("Escape tab") { - check(std::string("hello\tworld"), "\"hello\\tworld\""); + check("hello\tworld"_s, "\"hello\\tworld\""); } SECTION("NUL char") { - check(std::string("hello\0world", 11), "\"hello\\u0000world\""); + check("hello\0world"_s, "\"hello\\u0000world\""); } } @@ -74,7 +76,7 @@ TEST_CASE("serializeJson(JsonVariant)") { } SECTION("SerializedValue") { - check(serialized(std::string("[1,2]")), "[1,2]"); + check(serialized("[1,2]"_s), "[1,2]"); } SECTION("Double") { diff --git a/lib/ArduinoJson/extras/tests/JsonSerializer/std_string.cpp b/lib/ArduinoJson/extras/tests/JsonSerializer/std_string.cpp index e70ed28..33b8f50 100644 --- a/lib/ArduinoJson/extras/tests/JsonSerializer/std_string.cpp +++ b/lib/ArduinoJson/extras/tests/JsonSerializer/std_string.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + TEST_CASE("serialize JsonArray to std::string") { JsonDocument doc; JsonArray array = doc.to(); @@ -48,7 +50,7 @@ TEST_CASE("serialize JsonObject to std::string") { TEST_CASE("serialize an std::string containing a NUL") { JsonDocument doc; - doc.set(std::string("hello\0world", 11)); + doc.set("hello\0world"_s); std::string json = "erase me"; serializeJson(doc, json); diff --git a/lib/ArduinoJson/extras/tests/JsonVariant/add.cpp b/lib/ArduinoJson/extras/tests/JsonVariant/add.cpp index 71e53dc..8b3e602 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariant/add.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariant/add.cpp @@ -6,6 +6,9 @@ #include #include +#include "Allocators.hpp" +#include "Literals.hpp" + TEST_CASE("JsonVariant::add(T)") { JsonDocument doc; JsonVariant var = doc.to(); @@ -23,7 +26,7 @@ TEST_CASE("JsonVariant::add(T)") { } SECTION("add std::string to new variant") { - var.add(std::string("hello")); + var.add("hello"_s); REQUIRE(var.as() == "[\"hello\"]"); } @@ -56,15 +59,58 @@ TEST_CASE("JsonVariant::add()") { REQUIRE(doc.as() == "[[1,2]]"); } - SECTION("JsonObject") { - JsonObject object = var.add(); - object["hello"] = "world"; - REQUIRE(doc.as() == "[{\"hello\":\"world\"}]"); - } - SECTION("JsonVariant") { JsonVariant variant = var.add(); variant.set(42); REQUIRE(doc.as() == "[42]"); } } + +TEST_CASE("JsonObject::add(JsonObject) ") { + JsonDocument doc1; + doc1["hello"_s] = "world"_s; + + TimebombAllocator allocator(10); + SpyingAllocator spy(&allocator); + JsonDocument doc2(&spy); + JsonVariant variant = doc2.to(); + + SECTION("success") { + bool result = variant.add(doc1.as()); + + REQUIRE(result == true); + REQUIRE(doc2.as() == "[{\"hello\":\"world\"}]"); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("hello")), + Allocate(sizeofString("world")), + }); + } + + SECTION("partial failure") { // issue #2081 + allocator.setCountdown(2); + + bool result = variant.add(doc1.as()); + + REQUIRE(result == false); + REQUIRE(doc2.as() == "[]"); + REQUIRE(spy.log() == AllocatorLog{ + Allocate(sizeofPool()), + Allocate(sizeofString("hello")), + AllocateFail(sizeofString("world")), + Deallocate(sizeofString("hello")), + }); + } + + SECTION("complete failure") { + allocator.setCountdown(0); + + bool result = variant.add(doc1.as()); + + REQUIRE(result == false); + REQUIRE(doc2.as() == "[]"); + REQUIRE(spy.log() == AllocatorLog{ + AllocateFail(sizeofPool()), + }); + } +} diff --git a/lib/ArduinoJson/extras/tests/JsonVariant/as.cpp b/lib/ArduinoJson/extras/tests/JsonVariant/as.cpp index cacf895..fa76b0e 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariant/as.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariant/as.cpp @@ -6,6 +6,8 @@ #include #include +#include "Literals.hpp" + namespace my { using ArduinoJson::detail::isinf; } // namespace my @@ -25,6 +27,8 @@ TEST_CASE("JsonVariant::as()") { REQUIRE(0 == variant.as()); REQUIRE("null" == variant.as()); REQUIRE(variant.as().isNull()); + REQUIRE(variant.as().data() == nullptr); + REQUIRE(variant.as().data() == nullptr); } SECTION("set(4.2)") { @@ -36,6 +40,8 @@ TEST_CASE("JsonVariant::as()") { REQUIRE(variant.as() == 4L); REQUIRE(variant.as() == 4U); REQUIRE(variant.as().isNull()); + REQUIRE(variant.as().data() == nullptr); + REQUIRE(variant.as().data() == nullptr); } SECTION("set(0.0)") { @@ -44,6 +50,8 @@ TEST_CASE("JsonVariant::as()") { REQUIRE(variant.as() == false); REQUIRE(variant.as() == 0L); REQUIRE(variant.as().isNull()); + REQUIRE(variant.as().data() == nullptr); + REQUIRE(variant.as().data() == nullptr); } SECTION("set(false)") { @@ -54,6 +62,8 @@ TEST_CASE("JsonVariant::as()") { REQUIRE(variant.as() == 0L); REQUIRE(variant.as() == "false"); REQUIRE(variant.as().isNull()); + REQUIRE(variant.as().data() == nullptr); + REQUIRE(variant.as().data() == nullptr); } SECTION("set(true)") { @@ -64,6 +74,8 @@ TEST_CASE("JsonVariant::as()") { REQUIRE(variant.as() == 1L); REQUIRE(variant.as() == "true"); REQUIRE(variant.as().isNull()); + REQUIRE(variant.as().data() == nullptr); + REQUIRE(variant.as().data() == nullptr); } SECTION("set(42)") { @@ -75,6 +87,8 @@ TEST_CASE("JsonVariant::as()") { REQUIRE(variant.as() == 42U); // issue #1601 REQUIRE(variant.as() == "42"); REQUIRE(variant.as().isNull()); + REQUIRE(variant.as().data() == nullptr); + REQUIRE(variant.as().data() == nullptr); } SECTION("set(42L)") { @@ -144,20 +158,20 @@ TEST_CASE("JsonVariant::as()") { REQUIRE(variant.as() == true); REQUIRE(variant.as() == 0L); - REQUIRE(variant.as() == std::string("hello")); - REQUIRE(variant.as() == std::string("hello")); - REQUIRE(variant.as() == std::string("hello")); + REQUIRE(variant.as() == "hello"_s); + REQUIRE(variant.as() == "hello"_s); + REQUIRE(variant.as() == "hello"_s); REQUIRE(variant.as() == "hello"); } SECTION("set(std::string(\"4.2\"))") { - variant.set(std::string("4.2")); + variant.set("4.2"_s); REQUIRE(variant.as() == true); REQUIRE(variant.as() == 4L); REQUIRE(variant.as() == 4.2); - REQUIRE(variant.as() == std::string("4.2")); - REQUIRE(variant.as() == std::string("4.2")); + REQUIRE(variant.as() == "4.2"_s); + REQUIRE(variant.as() == "4.2"_s); REQUIRE(variant.as() == "4.2"); REQUIRE(variant.as().isLinked() == false); } @@ -199,6 +213,13 @@ TEST_CASE("JsonVariant::as()") { REQUIRE(variant.as().isNull()); } + SECTION("set(serialized(\"hello\"))") { + variant.set(serialized("hello")); + + REQUIRE(variant.as().data() == nullptr); + REQUIRE(variant.as().data() == nullptr); + } + SECTION("to()") { JsonObject obj = variant.to(); obj["key"] = "value"; @@ -208,13 +229,13 @@ TEST_CASE("JsonVariant::as()") { } SECTION("as()") { - REQUIRE(variant.as() == std::string("{\"key\":\"value\"}")); + REQUIRE(variant.as() == "{\"key\":\"value\"}"_s); } SECTION("ObjectAsJsonObject") { JsonObject o = variant.as(); REQUIRE(o.size() == 1); - REQUIRE(o["key"] == std::string("value")); + REQUIRE(o["key"] == "value"_s); } } @@ -228,7 +249,7 @@ TEST_CASE("JsonVariant::as()") { } SECTION("as()") { - REQUIRE(variant.as() == std::string("[4,2]")); + REQUIRE(variant.as() == "[4,2]"_s); } SECTION("as()") { @@ -245,7 +266,7 @@ TEST_CASE("JsonVariant::as()") { REQUIRE(variant.as() == -9223372036854775807 - 1); } - SECTION("Biggerst int64 positive") { + SECTION("Biggest int64 positive") { variant.set("9223372036854775807"); REQUIRE(variant.as() == 9223372036854775807); } diff --git a/lib/ArduinoJson/extras/tests/JsonVariant/clear.cpp b/lib/ArduinoJson/extras/tests/JsonVariant/clear.cpp index b36a52e..8e292d2 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariant/clear.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariant/clear.cpp @@ -7,6 +7,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" TEST_CASE("JsonVariant::clear()") { SpyingAllocator spy; @@ -28,7 +29,7 @@ TEST_CASE("JsonVariant::clear()") { } SECTION("releases owned string") { - var.set(std::string("hello")); + var.set("hello"_s); var.clear(); REQUIRE(spy.log() == AllocatorLog{ diff --git a/lib/ArduinoJson/extras/tests/JsonVariant/compare.cpp b/lib/ArduinoJson/extras/tests/JsonVariant/compare.cpp index 3061cdd..de7ced7 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariant/compare.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariant/compare.cpp @@ -113,6 +113,42 @@ TEST_CASE("Compare JsonVariant with JsonVariant") { CHECK_FALSE(a == b); } + SECTION("MsgPackBinary('abc') vs MsgPackBinary('abc')") { + a.set(MsgPackBinary("abc", 4)); + b.set(MsgPackBinary("abc", 4)); + + CHECK(a == b); + CHECK(a <= b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } + + SECTION("MsgPackBinary('abc') vs MsgPackBinary('bcd')") { + a.set(MsgPackBinary("abc", 4)); + b.set(MsgPackBinary("bcd", 4)); + + CHECK(a != b); + CHECK(a < b); + CHECK(a <= b); + CHECK_FALSE(a == b); + CHECK_FALSE(a > b); + CHECK_FALSE(a >= b); + } + + SECTION("MsgPackBinary('bcd') vs MsgPackBinary('abc')") { + a.set(MsgPackBinary("bcd", 4)); + b.set(MsgPackBinary("abc", 4)); + + CHECK(a != b); + CHECK(a > b); + CHECK(a >= b); + CHECK_FALSE(a < b); + CHECK_FALSE(a <= b); + CHECK_FALSE(a == b); + } + SECTION("false vs true") { a.set(false); b.set(true); diff --git a/lib/ArduinoJson/extras/tests/JsonVariant/containsKey.cpp b/lib/ArduinoJson/extras/tests/JsonVariant/containsKey.cpp index 45af06d..a406fe1 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariant/containsKey.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariant/containsKey.cpp @@ -6,6 +6,8 @@ #include #include +#include "Literals.hpp" + TEST_CASE("JsonVariant::containsKey()") { JsonDocument doc; JsonVariant var = doc.to(); @@ -20,7 +22,15 @@ TEST_CASE("JsonVariant::containsKey()") { SECTION("containsKey(std::string)") { var["hello"] = "world"; - REQUIRE(var.containsKey(std::string("hello")) == true); - REQUIRE(var.containsKey(std::string("world")) == false); + REQUIRE(var.containsKey("hello"_s) == true); + REQUIRE(var.containsKey("world"_s) == false); + } + + SECTION("containsKey(JsonVariant)") { + var["hello"] = "world"; + var["key"] = "hello"; + + REQUIRE(var.containsKey(doc["key"]) == true); + REQUIRE(var.containsKey(doc["foo"]) == false); } } diff --git a/lib/ArduinoJson/extras/tests/JsonVariant/converters.cpp b/lib/ArduinoJson/extras/tests/JsonVariant/converters.cpp index 259c8ac..545c4be 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariant/converters.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariant/converters.cpp @@ -140,15 +140,3 @@ TEST_CASE("Custom converter with specialization") { REQUIRE(doc["value"]["imag"] == 3); } } - -TEST_CASE("ConverterNeedsWriteableRef") { - using namespace ArduinoJson::detail; - CHECK(ConverterNeedsWriteableRef::value == false); - CHECK(ConverterNeedsWriteableRef::value == false); - CHECK(ConverterNeedsWriteableRef::value == true); - CHECK(ConverterNeedsWriteableRef::value == false); - CHECK(ConverterNeedsWriteableRef::value == true); - CHECK(ConverterNeedsWriteableRef::value == false); - CHECK(ConverterNeedsWriteableRef::value == true); - CHECK(ConverterNeedsWriteableRef::value == false); -} diff --git a/lib/ArduinoJson/extras/tests/JsonVariant/copy.cpp b/lib/ArduinoJson/extras/tests/JsonVariant/copy.cpp index 1904f57..7a52c2e 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariant/copy.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariant/copy.cpp @@ -6,6 +6,8 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" + TEST_CASE("JsonVariant::set(JsonVariant)") { KillswitchAllocator killswitch; SpyingAllocator spyingAllocator(&killswitch); @@ -72,7 +74,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { } SECTION("stores std::string by copy") { - var1.set(std::string("hello!!")); + var1.set("hello!!"_s); spyingAllocator.clearLog(); var2.set(var1); @@ -106,7 +108,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { } SECTION("stores Serialized by copy") { - var1.set(serialized(std::string("hello!!"))); + var1.set(serialized("hello!!"_s)); spyingAllocator.clearLog(); var2.set(var1); @@ -117,7 +119,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { } SECTION("fails gracefully if raw string allocation fails") { - var1.set(serialized(std::string("hello!!"))); + var1.set(serialized("hello!!"_s)); killswitch.on(); spyingAllocator.clearLog(); diff --git a/lib/ArduinoJson/extras/tests/JsonVariant/remove.cpp b/lib/ArduinoJson/extras/tests/JsonVariant/remove.cpp index 3412bc0..b8dfc0e 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariant/remove.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariant/remove.cpp @@ -7,6 +7,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" using ArduinoJson::detail::sizeofArray; @@ -15,9 +16,9 @@ TEST_CASE("JsonVariant::remove(int)") { JsonDocument doc(&spy); SECTION("release top level strings") { - doc.add(std::string("hello")); - doc.add(std::string("hello")); - doc.add(std::string("world")); + doc.add("hello"_s); + doc.add("hello"_s); + doc.add("world"_s); JsonVariant var = doc.as(); REQUIRE(var.as() == "[\"hello\",\"hello\",\"world\"]"); @@ -43,7 +44,7 @@ TEST_CASE("JsonVariant::remove(int)") { } SECTION("release strings in nested array") { - doc[0][0] = std::string("hello"); + doc[0][0] = "hello"_s; JsonVariant var = doc.as(); REQUIRE(var.as() == "[[\"hello\"]]"); @@ -77,7 +78,34 @@ TEST_CASE("JsonVariant::remove(std::string)") { var["a"] = 1; var["b"] = 2; - var.remove(std::string("b")); + var.remove("b"_s); REQUIRE(var.as() == "{\"a\":1}"); } + +TEST_CASE("JsonVariant::remove(JsonVariant) from object") { + JsonDocument doc; + JsonVariant var = doc.to(); + + var["a"] = "a"; + var["b"] = 2; + var["c"] = "b"; + + var.remove(var["c"]); + + REQUIRE(var.as() == "{\"a\":\"a\",\"c\":\"b\"}"); +} + +TEST_CASE("JsonVariant::remove(JsonVariant) from array") { + JsonDocument doc; + JsonVariant var = doc.to(); + + var[0] = 3; + var[1] = 2; + var[2] = 1; + + var.remove(var[2]); + var.remove(var[3]); // noop + + REQUIRE(var.as() == "[3,1]"); +} diff --git a/lib/ArduinoJson/extras/tests/JsonVariant/set.cpp b/lib/ArduinoJson/extras/tests/JsonVariant/set.cpp index ff02d4a..e47c2b4 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariant/set.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariant/set.cpp @@ -6,6 +6,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" using ArduinoJson::detail::sizeofObject; @@ -137,14 +138,14 @@ TEST_CASE("JsonVariant::set() with not enough memory") { JsonVariant v = doc.to(); SECTION("std::string") { - bool result = v.set(std::string("hello world!!")); + bool result = v.set("hello world!!"_s); REQUIRE(result == false); REQUIRE(v.isNull()); } SECTION("Serialized") { - bool result = v.set(serialized(std::string("hello world!!"))); + bool result = v.set(serialized("hello world!!"_s)); REQUIRE(result == false); REQUIRE(v.isNull()); @@ -178,7 +179,7 @@ TEST_CASE("JsonVariant::set(JsonDocument)") { TEST_CASE("JsonVariant::set() releases the previous value") { SpyingAllocator spy; JsonDocument doc(&spy); - doc["hello"] = std::string("world"); + doc["hello"] = "world"_s; spy.clearLog(); JsonVariant v = doc["hello"]; diff --git a/lib/ArduinoJson/extras/tests/JsonVariant/subscript.cpp b/lib/ArduinoJson/extras/tests/JsonVariant/subscript.cpp index 9f2e912..946d84c 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariant/subscript.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariant/subscript.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + TEST_CASE("JsonVariant::operator[]") { JsonDocument doc; JsonVariant var = doc.to(); @@ -31,9 +33,9 @@ TEST_CASE("JsonVariant::operator[]") { REQUIRE(2 == var.size()); var[0].as(); - // REQUIRE(std::string("element at index 0") == ); - REQUIRE(std::string("element at index 1") == var[1]); - REQUIRE(std::string("element at index 0") == + // REQUIRE("element at index 0"_s == ); + REQUIRE("element at index 1"_s == var[1]); + REQUIRE("element at index 0"_s == var[static_cast(0)]); // issue #381 REQUIRE(var[666].isNull()); REQUIRE(var[3].isNull()); @@ -46,7 +48,7 @@ TEST_CASE("JsonVariant::operator[]") { var[1] = "world"; REQUIRE(var.size() == 2); - REQUIRE(std::string("world") == var[1]); + REQUIRE("world"_s == var[1]); } SECTION("set value in a nested object") { @@ -56,7 +58,7 @@ TEST_CASE("JsonVariant::operator[]") { REQUIRE(1 == var.size()); REQUIRE(1 == var[0].size()); - REQUIRE(std::string("world") == var[0]["hello"]); + REQUIRE("world"_s == var[0]["hello"]); } SECTION("variant[0] when variant contains an integer") { @@ -67,6 +69,15 @@ TEST_CASE("JsonVariant::operator[]") { REQUIRE(var.is()); REQUIRE(var.as() == 123); } + + SECTION("use JsonVariant as index") { + array.add("A"); + array.add("B"); + array.add(1); + + REQUIRE(var[var[2]] == "B"); + REQUIRE(var[var[3]].isNull()); + } } SECTION("The JsonVariant is a JsonObject") { @@ -77,8 +88,8 @@ TEST_CASE("JsonVariant::operator[]") { object["b"] = "element at key \"b\""; REQUIRE(2 == var.size()); - REQUIRE(std::string("element at key \"a\"") == var["a"]); - REQUIRE(std::string("element at key \"b\"") == var["b"]); + REQUIRE("element at key \"a\""_s == var["a"]); + REQUIRE("element at key \"b\""_s == var["b"]); REQUIRE(var["c"].isNull()); REQUIRE(var[0].isNull()); } @@ -87,7 +98,7 @@ TEST_CASE("JsonVariant::operator[]") { var["hello"] = "world"; REQUIRE(1 == var.size()); - REQUIRE(std::string("world") == var["hello"]); + REQUIRE("world"_s == var["hello"]); } SECTION("set value, key is a char[]") { @@ -96,13 +107,22 @@ TEST_CASE("JsonVariant::operator[]") { key[0] = '!'; // make sure the key is duplicated REQUIRE(1 == var.size()); - REQUIRE(std::string("world") == var["hello"]); + REQUIRE("world"_s == var["hello"]); } SECTION("var[key].to()") { JsonArray arr = var["hello"].to(); REQUIRE(arr.isNull() == false); } + + SECTION("use JsonVariant as key") { + object["a"] = "a"; + object["b"] = "b"; + object["c"] = "b"; + + REQUIRE(var[var["c"]] == "b"); + REQUIRE(var[var["d"]].isNull()); + } } #if defined(HAS_VARIABLE_LENGTH_ARRAY) && \ @@ -115,7 +135,7 @@ TEST_CASE("JsonVariant::operator[]") { deserializeJson(doc, "{\"hello\":\"world\"}"); JsonVariant variant = doc.as(); - REQUIRE(std::string("world") == variant[vla]); + REQUIRE("world"_s == variant[vla]); } SECTION("key is a VLA, const JsonVariant") { @@ -126,7 +146,7 @@ TEST_CASE("JsonVariant::operator[]") { deserializeJson(doc, "{\"hello\":\"world\"}"); const JsonVariant variant = doc.as(); - REQUIRE(std::string("world") == variant[vla]); + REQUIRE("world"_s == variant[vla]); } #endif } diff --git a/lib/ArduinoJson/extras/tests/JsonVariant/unbound.cpp b/lib/ArduinoJson/extras/tests/JsonVariant/unbound.cpp index fa761a8..ff93625 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariant/unbound.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariant/unbound.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + TEST_CASE("Unbound JsonVariant") { JsonVariant variant; @@ -21,6 +23,10 @@ TEST_CASE("Unbound JsonVariant") { CHECK(variant.as().isNull()); CHECK(variant.as().isNull()); CHECK(variant.as().isNull()); + CHECK(variant.as().data() == nullptr); + CHECK(variant.as().size() == 0); + CHECK(variant.as().data() == nullptr); + CHECK(variant.as().size() == 0); } SECTION("is()") { @@ -44,8 +50,10 @@ TEST_CASE("Unbound JsonVariant") { CHECK_FALSE(variant.set(42L)); CHECK_FALSE(variant.set(42U)); CHECK_FALSE(variant.set(serialized("42"))); - CHECK_FALSE(variant.set(serialized(std::string("42")))); + CHECK_FALSE(variant.set(serialized("42"_s))); CHECK_FALSE(variant.set(true)); + CHECK_FALSE(variant.set(MsgPackBinary("hello", 5))); + CHECK_FALSE(variant.set(MsgPackExtension(1, "hello", 5))); } SECTION("add()") { @@ -62,7 +70,7 @@ TEST_CASE("Unbound JsonVariant") { CHECK(variant["key"].isNull()); CHECK_FALSE(variant[0].set(1)); CHECK_FALSE(variant["key"].set(1)); - CHECK_FALSE(variant[std::string("key")].set(1)); + CHECK_FALSE(variant["key"_s].set(1)); } SECTION("containsKey()") { diff --git a/lib/ArduinoJson/extras/tests/JsonVariantConst/as.cpp b/lib/ArduinoJson/extras/tests/JsonVariantConst/as.cpp index 6b86f15..5ef1563 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariantConst/as.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariantConst/as.cpp @@ -6,6 +6,8 @@ #include #include +#include "Literals.hpp" + TEST_CASE("JsonVariantConst::as()") { JsonDocument doc; JsonVariantConst var = doc.to(); @@ -14,6 +16,27 @@ TEST_CASE("JsonVariantConst::as()") { REQUIRE(var.as() == true); REQUIRE(var.as() == 0L); - REQUIRE(var.as() == std::string("hello")); - REQUIRE(var.as() == std::string("hello")); + REQUIRE(var.as() == "hello"_s); + REQUIRE(var.as() == "hello"_s); +} + +TEST_CASE("Invalid conversions") { + using namespace ArduinoJson::detail; + + JsonVariantConst variant; + + CHECK(is_same()), int>::value); + CHECK(is_same()), float>::value); + CHECK(is_same()), + JsonVariantConst>::value); + CHECK( + is_same()), JsonObjectConst>::value); + CHECK(is_same()), JsonArrayConst>::value); + + CHECK(is_same()), + InvalidConversion>::value); + CHECK(is_same()), + InvalidConversion>::value); + CHECK(is_same()), + InvalidConversion>::value); } diff --git a/lib/ArduinoJson/extras/tests/JsonVariantConst/containsKey.cpp b/lib/ArduinoJson/extras/tests/JsonVariantConst/containsKey.cpp index 7ab9630..dfa1fc8 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariantConst/containsKey.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariantConst/containsKey.cpp @@ -6,6 +6,8 @@ #include #include +#include "Literals.hpp" + TEST_CASE("JsonVariantConst::containsKey()") { JsonDocument doc; doc["hello"] = "world"; @@ -17,8 +19,8 @@ TEST_CASE("JsonVariantConst::containsKey()") { } SECTION("support std::string") { - REQUIRE(var.containsKey(std::string("hello")) == true); - REQUIRE(var.containsKey(std::string("world")) == false); + REQUIRE(var.containsKey("hello"_s) == true); + REQUIRE(var.containsKey("world"_s) == false); } #ifdef HAS_VARIABLE_LENGTH_ARRAY @@ -30,4 +32,10 @@ TEST_CASE("JsonVariantConst::containsKey()") { REQUIRE(true == var.containsKey(vla)); } #endif + + SECTION("support JsonVariant") { + doc["key"] = "hello"; + REQUIRE(var.containsKey(var["key"]) == true); + REQUIRE(var.containsKey(var["foo"]) == false); + } } diff --git a/lib/ArduinoJson/extras/tests/JsonVariantConst/subscript.cpp b/lib/ArduinoJson/extras/tests/JsonVariantConst/subscript.cpp index 70a733b..67ac98e 100644 --- a/lib/ArduinoJson/extras/tests/JsonVariantConst/subscript.cpp +++ b/lib/ArduinoJson/extras/tests/JsonVariantConst/subscript.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + TEST_CASE("JsonVariantConst::operator[]") { JsonDocument doc; JsonVariantConst var = doc.to(); @@ -27,13 +29,23 @@ TEST_CASE("JsonVariantConst::operator[]") { array.add("A"); array.add("B"); - REQUIRE(std::string("A") == var[0]); - REQUIRE(std::string("B") == var[1]); - REQUIRE(std::string("A") == - var[static_cast(0)]); // issue #381 - REQUIRE(var[666].isNull()); - REQUIRE(var[3].isNull()); - REQUIRE(var["0"].isNull()); + SECTION("int") { + REQUIRE("A"_s == var[0]); + REQUIRE("B"_s == var[1]); + REQUIRE("A"_s == var[static_cast(0)]); // issue #381 + REQUIRE(var[666].isNull()); + REQUIRE(var[3].isNull()); + } + + SECTION("const char*") { + REQUIRE(var["0"].isNull()); + } + + SECTION("JsonVariant") { + array.add(1); + REQUIRE(var[var[2]] == "B"_s); + REQUIRE(var[var[3]].isNull()); + } } SECTION("object") { @@ -42,16 +54,16 @@ TEST_CASE("JsonVariantConst::operator[]") { object["b"] = "B"; SECTION("supports const char*") { - REQUIRE(std::string("A") == var["a"]); - REQUIRE(std::string("B") == var["b"]); + REQUIRE("A"_s == var["a"]); + REQUIRE("B"_s == var["b"]); REQUIRE(var["c"].isNull()); REQUIRE(var[0].isNull()); } SECTION("supports std::string") { - REQUIRE(std::string("A") == var[std::string("a")]); - REQUIRE(std::string("B") == var[std::string("b")]); - REQUIRE(var[std::string("c")].isNull()); + REQUIRE("A"_s == var["a"_s]); + REQUIRE("B"_s == var["b"_s]); + REQUIRE(var["c"_s].isNull()); } #if defined(HAS_VARIABLE_LENGTH_ARRAY) && \ @@ -61,8 +73,14 @@ TEST_CASE("JsonVariantConst::operator[]") { char vla[i]; strcpy(vla, "a"); - REQUIRE(std::string("A") == var[vla]); + REQUIRE("A"_s == var[vla]); } #endif + + SECTION("supports JsonVariant") { + object["c"] = "b"; + REQUIRE(var[var["c"]] == "B"); + REQUIRE(var[var["d"]].isNull()); + } } } diff --git a/lib/ArduinoJson/extras/tests/Misc/StringWriter.cpp b/lib/ArduinoJson/extras/tests/Misc/StringWriter.cpp index f18e21e..3bf60ec 100644 --- a/lib/ArduinoJson/extras/tests/Misc/StringWriter.cpp +++ b/lib/ArduinoJson/extras/tests/Misc/StringWriter.cpp @@ -9,6 +9,7 @@ #include +#include "Literals.hpp" #include "custom_string.hpp" using namespace ArduinoJson::detail; @@ -36,13 +37,13 @@ void common_tests(StringWriter& writer, const String& output) { SECTION("OneString") { REQUIRE(4 == print(writer, "ABCD")); - REQUIRE(std::string("ABCD") == output); + REQUIRE("ABCD"_s == output); } SECTION("TwoStrings") { REQUIRE(4 == print(writer, "ABCD")); REQUIRE(4 == print(writer, "EFGH")); - REQUIRE(std::string("ABCDEFGH") == output); + REQUIRE("ABCDEFGH"_s == output); } } diff --git a/lib/ArduinoJson/extras/tests/Misc/conflicts.cpp b/lib/ArduinoJson/extras/tests/Misc/conflicts.cpp index d265f34..5ce6823 100644 --- a/lib/ArduinoJson/extras/tests/Misc/conflicts.cpp +++ b/lib/ArduinoJson/extras/tests/Misc/conflicts.cpp @@ -58,5 +58,10 @@ // issue #1914 #define V7 7 +// STM32, Mbed, Particle +#define A0 16 +#define A1 17 +#define A2 18 + // catch.hpp mutes several warnings, this file also allows to detect them #include "ArduinoJson.h" diff --git a/lib/ArduinoJson/extras/tests/Misc/custom_string.hpp b/lib/ArduinoJson/extras/tests/Misc/custom_string.hpp index cabd21b..acc6752 100644 --- a/lib/ArduinoJson/extras/tests/Misc/custom_string.hpp +++ b/lib/ArduinoJson/extras/tests/Misc/custom_string.hpp @@ -7,6 +7,5 @@ #include struct custom_char_traits : std::char_traits {}; -struct custom_allocator : std::allocator {}; -typedef std::basic_string - custom_string; + +typedef std::basic_string custom_string; diff --git a/lib/ArduinoJson/extras/tests/Misc/unsigned_char.cpp b/lib/ArduinoJson/extras/tests/Misc/unsigned_char.cpp index d7f1134..fd780d6 100644 --- a/lib/ArduinoJson/extras/tests/Misc/unsigned_char.cpp +++ b/lib/ArduinoJson/extras/tests/Misc/unsigned_char.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + #if defined(__clang__) # define CONFLICTS_WITH_BUILTIN_OPERATOR #endif @@ -111,7 +113,7 @@ TEST_CASE("unsigned char[]") { deserializeJson(doc, "{\"hello\":\"world\"}"); JsonVariant variant = doc.as(); - REQUIRE(std::string("world") == variant[key]); + REQUIRE("world"_s == variant[key]); } #endif @@ -122,7 +124,7 @@ TEST_CASE("unsigned char[]") { deserializeJson(doc, "{\"hello\":\"world\"}"); const JsonVariant variant = doc.as(); - REQUIRE(std::string("world") == variant[key]); + REQUIRE("world"_s == variant[key]); } #endif @@ -160,7 +162,7 @@ TEST_CASE("unsigned char[]") { JsonObject obj = doc.to(); obj[key] = "world"; - REQUIRE(std::string("world") == obj["hello"]); + REQUIRE("world"_s == obj["hello"]); } SECTION("JsonObject::operator[] const") { @@ -170,7 +172,7 @@ TEST_CASE("unsigned char[]") { deserializeJson(doc, "{\"hello\":\"world\"}"); JsonObject obj = doc.as(); - REQUIRE(std::string("world") == obj[key]); + REQUIRE("world"_s == obj[key]); } #endif @@ -203,7 +205,7 @@ TEST_CASE("unsigned char[]") { JsonObject obj = doc.to(); obj["hello"] = value; - REQUIRE(std::string("world") == obj["hello"]); + REQUIRE("world"_s == obj["hello"]); } SECTION("set()") { @@ -213,7 +215,7 @@ TEST_CASE("unsigned char[]") { JsonObject obj = doc.to(); obj["hello"].set(value); - REQUIRE(std::string("world") == obj["hello"]); + REQUIRE("world"_s == obj["hello"]); } } @@ -225,7 +227,7 @@ TEST_CASE("unsigned char[]") { JsonArray arr = doc.to(); arr.add(value); - REQUIRE(std::string("world") == arr[0]); + REQUIRE("world"_s == arr[0]); } } @@ -238,7 +240,7 @@ TEST_CASE("unsigned char[]") { arr.add("hello"); arr[0].set(value); - REQUIRE(std::string("world") == arr[0]); + REQUIRE("world"_s == arr[0]); } SECTION("operator=") { @@ -249,7 +251,7 @@ TEST_CASE("unsigned char[]") { arr.add("hello"); arr[0] = value; - REQUIRE(std::string("world") == arr[0]); + REQUIRE("world"_s == arr[0]); } } } diff --git a/lib/ArduinoJson/extras/tests/MixedConfiguration/CMakeLists.txt b/lib/ArduinoJson/extras/tests/MixedConfiguration/CMakeLists.txt index 17ea007..b8cad8e 100644 --- a/lib/ArduinoJson/extras/tests/MixedConfiguration/CMakeLists.txt +++ b/lib/ArduinoJson/extras/tests/MixedConfiguration/CMakeLists.txt @@ -15,6 +15,9 @@ add_executable(MixedConfigurationTests enable_nan_1.cpp enable_progmem_1.cpp issue1707.cpp + string_length_size_1.cpp + string_length_size_2.cpp + string_length_size_4.cpp use_double_0.cpp use_double_1.cpp use_long_long_0.cpp diff --git a/lib/ArduinoJson/extras/tests/MixedConfiguration/string_length_size_1.cpp b/lib/ArduinoJson/extras/tests/MixedConfiguration/string_length_size_1.cpp new file mode 100644 index 0000000..3263686 --- /dev/null +++ b/lib/ArduinoJson/extras/tests/MixedConfiguration/string_length_size_1.cpp @@ -0,0 +1,131 @@ +#define ARDUINOJSON_STRING_LENGTH_SIZE 1 +#include + +#include +#include + +#include "Literals.hpp" + +TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 1") { + JsonDocument doc; + + SECTION("set(std::string)") { + SECTION("returns true if len <= 255") { + auto result = doc.set(std::string(255, '?')); + + REQUIRE(result == true); + REQUIRE(doc.overflowed() == false); + } + + SECTION("returns false if len >= 256") { + auto result = doc.set(std::string(256, '?')); + + REQUIRE(result == false); + REQUIRE(doc.overflowed() == true); + } + } + + SECTION("set(MsgPackBinary)") { + SECTION("returns true if size <= 253") { + auto str = std::string(253, '?'); + auto result = doc.set(MsgPackBinary(str.data(), str.size())); + + REQUIRE(result == true); + REQUIRE(doc.overflowed() == false); + } + + SECTION("returns false if size >= 254") { + auto str = std::string(254, '?'); + auto result = doc.set(MsgPackBinary(str.data(), str.size())); + + REQUIRE(result == false); + REQUIRE(doc.overflowed() == true); + } + } + + SECTION("set(MsgPackExtension)") { + SECTION("returns true if size <= 252") { + auto str = std::string(252, '?'); + auto result = doc.set(MsgPackExtension(1, str.data(), str.size())); + + REQUIRE(result == true); + REQUIRE(doc.overflowed() == false); + } + + SECTION("returns false if size >= 253") { + auto str = std::string(253, '?'); + auto result = doc.set(MsgPackExtension(1, str.data(), str.size())); + + REQUIRE(result == false); + REQUIRE(doc.overflowed() == true); + } + } + + SECTION("deserializeJson()") { + SECTION("returns Ok if string length <= 255") { + auto input = "\"" + std::string(255, '?') + "\""; + + auto err = deserializeJson(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + + SECTION("returns NoMemory if string length >= 256") { + auto input = "\"" + std::string(256, '?') + "\""; + + auto err = deserializeJson(doc, input); + + REQUIRE(err == DeserializationError::NoMemory); + } + } + + SECTION("deserializeMsgPack()") { + SECTION("returns Ok if string length <= 255") { + auto input = "\xd9\xff" + std::string(255, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + + SECTION("returns NoMemory if string length >= 256") { + auto input = "\xda\x01\x00"_s + std::string(256, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::NoMemory); + } + + SECTION("returns Ok if binary size <= 253") { + auto input = "\xc4\xfd" + std::string(253, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + + SECTION("returns NoMemory if binary size >= 254") { + auto input = "\xc4\xfe" + std::string(254, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::NoMemory); + } + + SECTION("returns Ok if extension size <= 252") { + auto input = "\xc7\xfc\x01" + std::string(252, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + + SECTION("returns NoMemory if binary size >= 253") { + auto input = "\xc7\xfd\x01" + std::string(253, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::NoMemory); + } + } +} diff --git a/lib/ArduinoJson/extras/tests/MixedConfiguration/string_length_size_2.cpp b/lib/ArduinoJson/extras/tests/MixedConfiguration/string_length_size_2.cpp new file mode 100644 index 0000000..2c1315b --- /dev/null +++ b/lib/ArduinoJson/extras/tests/MixedConfiguration/string_length_size_2.cpp @@ -0,0 +1,140 @@ +#define ARDUINOJSON_STRING_LENGTH_SIZE 2 +#include + +#include +#include + +#include "Literals.hpp" + +TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 2") { + JsonDocument doc; + + SECTION("set(std::string)") { + SECTION("returns true if len <= 65535") { + auto result = doc.set(std::string(65535, '?')); + + REQUIRE(result == true); + REQUIRE(doc.overflowed() == false); + } + + SECTION("returns false if len >= 65536") { + auto result = doc.set(std::string(65536, '?')); + + REQUIRE(result == false); + REQUIRE(doc.overflowed() == true); + } + } + + SECTION("set(MsgPackBinary)") { + SECTION("returns true if size <= 65532") { + auto str = std::string(65532, '?'); + auto result = doc.set(MsgPackBinary(str.data(), str.size())); + + REQUIRE(result == true); + REQUIRE(doc.overflowed() == false); + } + + SECTION("returns false if size >= 65533") { + auto str = std::string(65533, '?'); + auto result = doc.set(MsgPackBinary(str.data(), str.size())); + + REQUIRE(result == false); + REQUIRE(doc.overflowed() == true); + } + } + + SECTION("set(MsgPackExtension)") { + SECTION("returns true if size <= 65531") { + auto str = std::string(65531, '?'); + auto result = doc.set(MsgPackExtension(1, str.data(), str.size())); + + REQUIRE(result == true); + REQUIRE(doc.overflowed() == false); + } + + SECTION("returns false if size >= 65532") { + auto str = std::string(65532, '?'); + auto result = doc.set(MsgPackExtension(1, str.data(), str.size())); + + REQUIRE(result == false); + REQUIRE(doc.overflowed() == true); + } + } + + SECTION("deserializeJson()") { + SECTION("returns Ok if string length <= 65535") { + auto input = "\"" + std::string(65535, '?') + "\""; + + auto err = deserializeJson(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + + SECTION("returns NoMemory if string length >= 65536") { + auto input = "\"" + std::string(65536, '?') + "\""; + + auto err = deserializeJson(doc, input); + + REQUIRE(err == DeserializationError::NoMemory); + } + } + + SECTION("deserializeMsgPack()") { + SECTION("returns Ok if string length <= 65535") { + auto input = "\xda\xff\xff" + std::string(65535, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + + SECTION("returns NoMemory if string length >= 65536") { + auto input = "\xdb\x00\x01\x00\x00"_s + std::string(65536, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::NoMemory); + } + + SECTION("returns Ok if binary size <= 65532") { + auto input = "\xc5\xff\xfc" + std::string(65532, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + + SECTION("returns NoMemory if binary size >= 65534") { + auto input = "\xc5\xff\xfd" + std::string(65534, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::NoMemory); + } + + // https://oss-fuzz.com/testcase?key=5354792971993088 + SECTION("doesn't overflow if binary size == 0xFFFF") { + auto input = "\xc5\xff\xff"_s; + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::NoMemory); + } + + SECTION("returns Ok if extension size <= 65531") { + auto input = "\xc8\xff\xfb\x01" + std::string(65531, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + + SECTION("returns NoMemory if extension size >= 65532") { + auto input = "\xc8\xff\xfc\x01" + std::string(65532, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::NoMemory); + } + } +} diff --git a/lib/ArduinoJson/extras/tests/MixedConfiguration/string_length_size_4.cpp b/lib/ArduinoJson/extras/tests/MixedConfiguration/string_length_size_4.cpp new file mode 100644 index 0000000..4059c3d --- /dev/null +++ b/lib/ArduinoJson/extras/tests/MixedConfiguration/string_length_size_4.cpp @@ -0,0 +1,146 @@ +#define ARDUINOJSON_STRING_LENGTH_SIZE 4 +#include + +#include +#include + +#include "Literals.hpp" + +TEST_CASE("ARDUINOJSON_STRING_LENGTH_SIZE == 4") { + JsonDocument doc; + + SECTION("set(std::string)") { + SECTION("returns true if string length >= 65536") { + auto result = doc.set(std::string(65536, '?')); + + REQUIRE(result == true); + REQUIRE(doc.overflowed() == false); + } + } + + SECTION("set(MsgPackBinary)") { + SECTION("returns true if size >= 65536") { + auto str = std::string(65536, '?'); + auto result = doc.set(MsgPackBinary(str.data(), str.size())); + + REQUIRE(result == true); + REQUIRE(doc.overflowed() == false); + } + } + + SECTION("set(MsgPackExtension)") { + SECTION("returns true if size >= 65532") { + auto str = std::string(65532, '?'); + auto result = doc.set(MsgPackExtension(1, str.data(), str.size())); + + REQUIRE(result == true); + REQUIRE(doc.overflowed() == false); + } + } + + SECTION("deserializeJson()") { + SECTION("returns Ok if string length >= 65536") { + auto input = "\"" + std::string(65536, '?') + "\""; + + auto err = deserializeJson(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + } + + SECTION("deserializeMsgPack()") { + SECTION("returns Ok if string size >= 65536") { + auto input = "\xda\xff\xff" + std::string(65536, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + + SECTION("returns Ok if binary size >= 65536") { + auto input = "\xc5\xff\xff" + std::string(65536, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + + SECTION("returns Ok if extension size >= 65532") { + auto input = "\xc8\xff\xfb\x01" + std::string(65532, '?'); + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::Ok); + } + + // https://oss-fuzz.com/testcase?key=5354792971993088 + SECTION("doesn't overflow if binary size == 0xFFFFFFFF") { + auto input = "\xc6\xff\xff\xff\xff"_s; + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::NoMemory); + } + + SECTION("doesn't overflow if string size == 0xFFFFFFFF") { + auto input = "\xdb\xff\xff\xff\xff???????????????????"_s; + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err != DeserializationError::Ok); + } + } + + SECTION("bin 32 deserialization") { + auto str = std::string(65536, '?'); + auto input = "\xc6\x00\x01\x00\x00"_s + str; + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(doc.is()); + auto binary = doc.as(); + REQUIRE(binary.size() == 65536); + REQUIRE(binary.data() != nullptr); + REQUIRE(std::string(reinterpret_cast(binary.data()), + binary.size()) == str); + } + + SECTION("bin 32 serialization") { + auto str = std::string(65536, '?'); + doc.set(MsgPackBinary(str.data(), str.size())); + + std::string output; + auto result = serializeMsgPack(doc, output); + + REQUIRE(result == 5 + str.size()); + REQUIRE(output == "\xc6\x00\x01\x00\x00"_s + str); + } + + SECTION("ext 32 deserialization") { + auto str = std::string(65536, '?'); + auto input = "\xc9\x00\x01\x00\x00\x2a"_s + str; + + auto err = deserializeMsgPack(doc, input); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(doc.is()); + auto value = doc.as(); + REQUIRE(value.type() == 42); + REQUIRE(value.size() == 65536); + REQUIRE(value.data() != nullptr); + REQUIRE(std::string(reinterpret_cast(value.data()), + value.size()) == str); + } + + SECTION("ext 32 serialization") { + auto str = std::string(65536, '?'); + doc.set(MsgPackExtension(42, str.data(), str.size())); + + std::string output; + auto result = serializeMsgPack(doc, output); + + REQUIRE(result == 6 + str.size()); + REQUIRE(output == "\xc9\x00\x01\x00\x00\x2a"_s + str); + } +} diff --git a/lib/ArduinoJson/extras/tests/MixedConfiguration/use_long_long_0.cpp b/lib/ArduinoJson/extras/tests/MixedConfiguration/use_long_long_0.cpp index 4c7f0ad..2781a76 100644 --- a/lib/ArduinoJson/extras/tests/MixedConfiguration/use_long_long_0.cpp +++ b/lib/ArduinoJson/extras/tests/MixedConfiguration/use_long_long_0.cpp @@ -3,14 +3,40 @@ #include +#include "Literals.hpp" + TEST_CASE("ARDUINOJSON_USE_LONG_LONG == 0") { JsonDocument doc; - doc["A"] = 42; - doc["B"] = 84; + SECTION("smoke test") { + doc["A"] = 42; + doc["B"] = 84; - std::string json; - serializeJson(doc, json); + std::string json; + serializeJson(doc, json); - REQUIRE(json == "{\"A\":42,\"B\":84}"); + REQUIRE(json == "{\"A\":42,\"B\":84}"); + } + + SECTION("deserializeMsgPack()") { + SECTION("cf 00 00 00 00 ff ff ff ff") { + auto err = + deserializeMsgPack(doc, "\xcf\x00\x00\x00\x00\xff\xff\xff\xff"_s); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(doc.as() == 0xFFFFFFFF); + } + + SECTION("cf 00 00 00 01 00 00 00 00") { + auto err = + deserializeMsgPack(doc, "\xcf\x00\x00\x00\x01\x00\x00\x00\x00"_s); + + REQUIRE(err == DeserializationError::Ok); +#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ >= 8 + REQUIRE(doc.as() == 0x100000000); +#else + REQUIRE(doc.isNull()); +#endif + } + } } diff --git a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/deserializeVariant.cpp b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/deserializeVariant.cpp index 0136177..412d541 100644 --- a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/deserializeVariant.cpp +++ b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/deserializeVariant.cpp @@ -6,6 +6,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" template static void checkValue(const char* input, T expected) { @@ -123,21 +124,171 @@ TEST_CASE("deserialize MsgPack value") { SECTION("fixstr") { checkValue("\xA0", std::string("")); - checkValue("\xABhello world", std::string("hello world")); + checkValue("\xABhello world", "hello world"_s); checkValue("\xBFhello world hello world hello !", - std::string("hello world hello world hello !")); + "hello world hello world hello !"_s); } SECTION("str 8") { - checkValue("\xd9\x05hello", std::string("hello")); + checkValue("\xd9\x05hello", "hello"_s); } SECTION("str 16") { - checkValue("\xda\x00\x05hello", std::string("hello")); + checkValue("\xda\x00\x05hello", "hello"_s); } SECTION("str 32") { - checkValue("\xdb\x00\x00\x00\x05hello", std::string("hello")); + checkValue("\xdb\x00\x00\x00\x05hello", "hello"_s); + } + + SECTION("bin 8") { + JsonDocument doc; + + DeserializationError error = deserializeMsgPack(doc, "\xc4\x01?"); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + auto binary = doc.as(); + REQUIRE(binary.size() == 1); + REQUIRE(binary.data() != nullptr); + REQUIRE(reinterpret_cast(binary.data())[0] == '?'); + } + + SECTION("bin 16") { + JsonDocument doc; + auto str = std::string(256, '?'); + auto input = "\xc5\x01\x00"_s + str; + + DeserializationError error = deserializeMsgPack(doc, input); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + auto binary = doc.as(); + REQUIRE(binary.size() == 0x100); + REQUIRE(binary.data() != nullptr); + REQUIRE(std::string(reinterpret_cast(binary.data()), + binary.size()) == str); + } + + SECTION("fixext 1") { + JsonDocument doc; + + auto error = deserializeMsgPack(doc, "\xd4\x01\x02"); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + auto ext = doc.as(); + REQUIRE(ext.type() == 1); + REQUIRE(ext.size() == 1); + auto data = reinterpret_cast(ext.data()); + REQUIRE(data[0] == 2); + } + + SECTION("fixext 2") { + JsonDocument doc; + + auto error = deserializeMsgPack(doc, "\xd5\x01\x02\x03"); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + auto ext = doc.as(); + REQUIRE(ext.type() == 1); + REQUIRE(ext.size() == 2); + auto data = reinterpret_cast(ext.data()); + REQUIRE(data[0] == 2); + REQUIRE(data[1] == 3); + } + + SECTION("fixext 4") { + JsonDocument doc; + + auto error = deserializeMsgPack(doc, "\xd6\x01\x02\x03\x04\x05"); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + auto ext = doc.as(); + REQUIRE(ext.type() == 1); + REQUIRE(ext.size() == 4); + auto data = reinterpret_cast(ext.data()); + REQUIRE(data[0] == 2); + REQUIRE(data[1] == 3); + REQUIRE(data[2] == 4); + REQUIRE(data[3] == 5); + } + + SECTION("fixext 8") { + JsonDocument doc; + + auto error = deserializeMsgPack(doc, "\xd7\x01????????"); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + auto ext = doc.as(); + REQUIRE(ext.type() == 1); + REQUIRE(ext.size() == 8); + auto data = reinterpret_cast(ext.data()); + REQUIRE(data[0] == '?'); + REQUIRE(data[7] == '?'); + } + + SECTION("fixext 16") { + JsonDocument doc; + + auto error = deserializeMsgPack(doc, "\xd8\x01?????????????????"); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + auto ext = doc.as(); + REQUIRE(ext.type() == 1); + REQUIRE(ext.size() == 16); + auto data = reinterpret_cast(ext.data()); + REQUIRE(data[0] == '?'); + REQUIRE(data[15] == '?'); + } + + SECTION("ext 8") { + JsonDocument doc; + + auto error = deserializeMsgPack(doc, "\xc7\x02\x01\x03\x04"); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + auto ext = doc.as(); + REQUIRE(ext.type() == 1); + REQUIRE(ext.size() == 2); + auto data = reinterpret_cast(ext.data()); + REQUIRE(data[0] == 3); + REQUIRE(data[1] == 4); + } + + SECTION("ext 16") { + JsonDocument doc; + + auto error = deserializeMsgPack(doc, "\xc8\x00\x02\x01\x03\x04"); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + auto ext = doc.as(); + REQUIRE(ext.type() == 1); + REQUIRE(ext.size() == 2); + auto data = reinterpret_cast(ext.data()); + REQUIRE(data[0] == 3); + REQUIRE(data[1] == 4); + } + + SECTION("ext 32") { + JsonDocument doc; + + auto error = deserializeMsgPack(doc, "\xc9\x00\x00\x00\x02\x01\x03\x04"); + + REQUIRE(error == DeserializationError::Ok); + REQUIRE(doc.is()); + auto ext = doc.as(); + REQUIRE(ext.type() == 1); + REQUIRE(ext.size() == 2); + auto data = reinterpret_cast(ext.data()); + REQUIRE(data[0] == 3); + REQUIRE(data[1] == 4); } } @@ -198,12 +349,12 @@ TEST_CASE("deserializeMsgPack() under memory constaints") { checkError(0, "\x80", DeserializationError::Ok); } SECTION("{H:1}") { - checkError(0, "\x81\xA1H\x01", DeserializationError::NoMemory); - checkError(3, "\x81\xA1H\x01", DeserializationError::Ok); + checkError(1, "\x81\xA1H\x01", DeserializationError::NoMemory); + checkError(2, "\x81\xA1H\x01", DeserializationError::Ok); } SECTION("{H:1,W:2}") { - checkError(3, "\x82\xA1H\x01\xA1W\x02", DeserializationError::NoMemory); - checkError(5, "\x82\xA1H\x01\xA1W\x02", DeserializationError::Ok); + checkError(2, "\x82\xA1H\x01\xA1W\x02", DeserializationError::NoMemory); + checkError(3, "\x82\xA1H\x01\xA1W\x02", DeserializationError::Ok); } } @@ -212,13 +363,13 @@ TEST_CASE("deserializeMsgPack() under memory constaints") { checkError(0, "\xDE\x00\x00", DeserializationError::Ok); } SECTION("{H:1}") { - checkError(2, "\xDE\x00\x01\xA1H\x01", DeserializationError::NoMemory); - checkError(3, "\xDE\x00\x01\xA1H\x01", DeserializationError::Ok); + checkError(1, "\xDE\x00\x01\xA1H\x01", DeserializationError::NoMemory); + checkError(2, "\xDE\x00\x01\xA1H\x01", DeserializationError::Ok); } SECTION("{H:1,W:2}") { - checkError(3, "\xDE\x00\x02\xA1H\x01\xA1W\x02", + checkError(2, "\xDE\x00\x02\xA1H\x01\xA1W\x02", DeserializationError::NoMemory); - checkError(5, "\xDE\x00\x02\xA1H\x01\xA1W\x02", DeserializationError::Ok); + checkError(3, "\xDE\x00\x02\xA1H\x01\xA1W\x02", DeserializationError::Ok); } } @@ -227,14 +378,14 @@ TEST_CASE("deserializeMsgPack() under memory constaints") { checkError(0, "\xDF\x00\x00\x00\x00", DeserializationError::Ok); } SECTION("{H:1}") { - checkError(2, "\xDF\x00\x00\x00\x01\xA1H\x01", + checkError(1, "\xDF\x00\x00\x00\x01\xA1H\x01", DeserializationError::NoMemory); - checkError(3, "\xDF\x00\x00\x00\x01\xA1H\x01", DeserializationError::Ok); + checkError(2, "\xDF\x00\x00\x00\x01\xA1H\x01", DeserializationError::Ok); } SECTION("{H:1,W:2}") { - checkError(3, "\xDF\x00\x00\x00\x02\xA1H\x01\xA1W\x02", + checkError(2, "\xDF\x00\x00\x00\x02\xA1H\x01\xA1W\x02", DeserializationError::NoMemory); - checkError(5, "\xDF\x00\x00\x00\x02\xA1H\x01\xA1W\x02", + checkError(3, "\xDF\x00\x00\x00\x02\xA1H\x01\xA1W\x02", DeserializationError::Ok); } } diff --git a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/destination_types.cpp b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/destination_types.cpp index d8b9db1..f0d04d6 100644 --- a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/destination_types.cpp +++ b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/destination_types.cpp @@ -8,6 +8,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" using ArduinoJson::detail::sizeofArray; using ArduinoJson::detail::sizeofObject; @@ -15,7 +16,7 @@ using ArduinoJson::detail::sizeofObject; TEST_CASE("deserializeMsgPack(JsonDocument&)") { SpyingAllocator spy; JsonDocument doc(&spy); - doc.add(std::string("hello")); + doc.add("hello"_s); spy.clearLog(); auto err = deserializeMsgPack(doc, "\x91\x2A"); @@ -34,7 +35,7 @@ TEST_CASE("deserializeMsgPack(JsonVariant)") { SECTION("variant is bound") { SpyingAllocator spy; JsonDocument doc(&spy); - doc.add(std::string("hello")); + doc.add("hello"_s); spy.clearLog(); JsonVariant variant = doc[0]; @@ -60,7 +61,7 @@ TEST_CASE("deserializeMsgPack(JsonVariant)") { TEST_CASE("deserializeMsgPack(ElementProxy)") { SpyingAllocator spy; JsonDocument doc(&spy); - doc.add(std::string("hello")); + doc.add("hello"_s); spy.clearLog(); SECTION("element already exists") { @@ -85,7 +86,7 @@ TEST_CASE("deserializeMsgPack(ElementProxy)") { TEST_CASE("deserializeMsgPack(MemberProxy)") { SpyingAllocator spy; JsonDocument doc(&spy); - doc[std::string("hello")] = std::string("world"); + doc["hello"_s] = "world"_s; spy.clearLog(); SECTION("member already exists") { diff --git a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/doubleToFloat.cpp b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/doubleToFloat.cpp index b0e2948..167261f 100644 --- a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/doubleToFloat.cpp +++ b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/doubleToFloat.cpp @@ -13,7 +13,7 @@ static void check(const char* input, T expected) { uint8_t* f = reinterpret_cast(&actual); const uint8_t* d = reinterpret_cast(input); doubleToFloat(d, f); - fixEndianess(actual); + fixEndianness(actual); CHECK(actual == expected); } diff --git a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/errors.cpp b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/errors.cpp index d81d489..01e761a 100644 --- a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/errors.cpp +++ b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/errors.cpp @@ -7,6 +7,8 @@ #include +#include "Allocators.hpp" + TEST_CASE("deserializeMsgPack() returns InvalidInput") { JsonDocument doc; @@ -182,84 +184,18 @@ TEST_CASE("deserializeMsgPack() returns IncompleteInput") { } } -static std::string msgPackToJson(const char* input, size_t inputSize) { - JsonDocument doc; - auto err = deserializeMsgPack(doc, input, inputSize); - REQUIRE(err == DeserializationError::Ok); - return doc.as(); -} +TEST_CASE( + "deserializeMsgPack() returns NoMemory when string allocation fails") { + TimebombAllocator allocator(0); + JsonDocument doc(&allocator); + + SECTION("fixstr") { + DeserializationError err = deserializeMsgPack(doc, "\xA5hello", 9); + REQUIRE(err == DeserializationError::NoMemory); + } -TEST_CASE("deserializeMsgPack() replaces unsupported types by null") { SECTION("bin 8") { - REQUIRE(msgPackToJson("\x92\xc4\x01X\x2A", 5) == "[null,42]"); - } - - SECTION("bin 16") { - REQUIRE(msgPackToJson("\x92\xc5\x00\x01X\x2A", 6) == "[null,42]"); - } - - SECTION("bin 32") { - REQUIRE(msgPackToJson("\x92\xc6\x00\x00\x00\x01X\x2A", 8) == "[null,42]"); - } - - SECTION("ext 8") { - REQUIRE(msgPackToJson("\x92\xc7\x01\x01\x01\x2A", 6) == "[null,42]"); - } - - SECTION("ext 16") { - REQUIRE(msgPackToJson("\x92\xc8\x00\x01\x01\x01\x2A", 7) == "[null,42]"); - } - - SECTION("ext 32") { - REQUIRE(msgPackToJson("\x92\xc9\x00\x00\x00\x01\x01\x01\x2A", 9) == - "[null,42]"); - } - - SECTION("fixext 1") { - REQUIRE(msgPackToJson("\x92\xd4\x01\x01\x2A", 5) == "[null,42]"); - } - - SECTION("fixext 2") { - REQUIRE(msgPackToJson("\x92\xd5\x01\x01\x02\x2A", 6) == "[null,42]"); - } - - SECTION("fixext 4") { - REQUIRE(msgPackToJson("\x92\xd6\x01\x01\x02\x03\x04\x2A", 8) == - "[null,42]"); - } - - SECTION("fixext 8") { - REQUIRE(msgPackToJson("\x92\xd7\x01\x01\x02\x03\x04\x05\x06\x07\x08\x2A", - 12) == "[null,42]"); - } - - SECTION("fixext 16") { - REQUIRE(msgPackToJson("\x92\xd8\x01\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A" - "\x0B\x0C\x0D\x0E" - "\x0F\x10\x2A", - 20) == "[null,42]"); - } -} - -TEST_CASE("deserializeMsgPack() returns NoMemory is string length overflows") { - JsonDocument doc; - auto maxLength = ArduinoJson::detail::StringNode::maxLength; - - SECTION("max length should succeed") { - auto len = maxLength; - std::string prefix = {'\xdb', char(len >> 24), char(len >> 16), - char(len >> 8), char(len)}; - - auto err = deserializeMsgPack(doc, prefix + std::string(len, 'a')); - REQUIRE(err == DeserializationError::Ok); - } - - SECTION("one above max length should fail") { - auto len = maxLength + 1; - std::string prefix = {'\xdb', char(len >> 24), char(len >> 16), - char(len >> 8), char(len)}; - - auto err = deserializeMsgPack(doc, prefix + std::string(len, 'a')); + DeserializationError err = deserializeMsgPack(doc, "\xC4\x01X", 3); REQUIRE(err == DeserializationError::NoMemory); } } diff --git a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/filter.cpp b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/filter.cpp index c119822..dcd2d54 100644 --- a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/filter.cpp +++ b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/filter.cpp @@ -8,6 +8,7 @@ #include #include "Allocators.hpp" +#include "Literals.hpp" using namespace ArduinoJson::detail; @@ -30,8 +31,8 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::IncompleteInput); CHECK(doc.as() == "{}"); CHECK(spy.log() == AllocatorLog{ - Allocate(sizeofStringBuffer()), - Deallocate(sizeofStringBuffer()), + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), }); } @@ -42,8 +43,8 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::IncompleteInput); CHECK(doc.as() == "{}"); CHECK(spy.log() == AllocatorLog{ - Allocate(sizeofStringBuffer()), - Deallocate(sizeofStringBuffer()), + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), }); } @@ -53,8 +54,8 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::IncompleteInput); CHECK(doc.as() == "{}"); CHECK(spy.log() == AllocatorLog{ - Allocate(sizeofStringBuffer()), - Deallocate(sizeofStringBuffer()), + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), }); } @@ -64,8 +65,8 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::IncompleteInput); CHECK(doc.as() == "{}"); CHECK(spy.log() == AllocatorLog{ - Allocate(sizeofStringBuffer()), - Deallocate(sizeofStringBuffer()), + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), }); } @@ -75,13 +76,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("reject 0xc1") { @@ -90,8 +91,8 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::InvalidInput); CHECK(spy.log() == AllocatorLog{ - Allocate(sizeofStringBuffer()), - Deallocate(sizeofStringBuffer()), + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), }); } @@ -101,13 +102,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip true") { @@ -116,13 +117,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip positive fixint") { @@ -131,13 +132,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip negative fixint") { @@ -146,13 +147,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip uint 8") { @@ -161,13 +162,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip int 8") { @@ -176,13 +177,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip uint 16") { @@ -191,13 +192,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip int 16") { @@ -206,13 +207,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip uint 32") { @@ -222,13 +223,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip int 32") { @@ -238,13 +239,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip uint 64") { @@ -255,13 +256,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip int 64") { @@ -272,13 +273,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip float 32") { @@ -288,13 +289,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip float 64") { @@ -305,13 +306,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip fixstr") { @@ -320,13 +321,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip str 8") { @@ -335,13 +336,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip str 16") { @@ -350,13 +351,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip str 32") { @@ -366,13 +367,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip bin 8") { @@ -381,13 +382,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip bin 16") { @@ -396,13 +397,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip bin 32") { @@ -412,13 +413,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip fixarray") { @@ -427,13 +428,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip array 16") { @@ -443,13 +444,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip array 32") { @@ -462,13 +463,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip fixmap") { @@ -478,13 +479,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip map 16") { @@ -496,13 +497,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip map 32") { @@ -516,13 +517,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip fixext 1") { @@ -534,13 +535,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip fixext 2") { @@ -552,13 +553,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip fixext 4") { @@ -570,13 +571,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip fixext 8") { @@ -588,13 +589,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip fixext 16") { @@ -608,13 +609,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip ext 8") { @@ -626,13 +627,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip ext 16") { @@ -644,13 +645,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } SECTION("skip ext 32") { @@ -662,13 +663,13 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Allocate(sizeofPool()), - Reallocate(sizeofPool(), sizeofObject(1)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("ignore")), + Deallocate(sizeofString("ignore")), + Allocate(sizeofString("include")), + Allocate(sizeofPool()), + Reallocate(sizeofPool(), sizeofObject(1)), + }); } } @@ -691,13 +692,12 @@ TEST_CASE("deserializeMsgPack() filter") { "{\"onlyarr\":[{\"measure\":2},{\"measure\":4}],\"include\":42}"); CHECK(spy.log() == AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofString("onlyarr")), Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("measure")), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofString("location")), + Reallocate(sizeofString("location"), sizeofString("measure")), + Allocate(sizeofString("location")), + Reallocate(sizeofString("location"), sizeofString("include")), Reallocate(sizeofPool(), sizeofObject(2) + sizeofArray(2) + 2 * sizeofObject(1)), }); @@ -717,13 +717,12 @@ TEST_CASE("deserializeMsgPack() filter") { "{\"onlyarr\":[{\"measure\":2},{\"measure\":4}],\"include\":42}"); CHECK(spy.log() == AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofString("onlyarr")), Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("measure")), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofString("location")), + Reallocate(sizeofString("location"), sizeofString("measure")), + Allocate(sizeofString("location")), + Reallocate(sizeofString("location"), sizeofString("include")), Reallocate(sizeofPool(), sizeofObject(2) + sizeofArray(2) + 2 * sizeofObject(1)), }); @@ -743,13 +742,12 @@ TEST_CASE("deserializeMsgPack() filter") { "{\"onlyarr\":[{\"measure\":2},{\"measure\":4}],\"include\":42}"); CHECK(spy.log() == AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), + Allocate(sizeofString("onlyarr")), Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("measure")), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofString("location")), + Reallocate(sizeofString("location"), sizeofString("measure")), + Allocate(sizeofString("location")), + Reallocate(sizeofString("location"), sizeofString("include")), Reallocate(sizeofPool(), sizeofObject(2) + sizeofArray(2) + 2 * sizeofObject(1)), }); @@ -761,15 +759,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip false") { @@ -778,15 +773,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip true") { @@ -795,15 +787,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip positive fixint") { @@ -812,15 +801,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip negative fixint") { @@ -829,15 +815,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip uint 8") { @@ -846,15 +829,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip uint 16") { @@ -863,15 +843,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip uint 32") { @@ -881,15 +858,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip uint 64") { @@ -900,15 +874,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip int 8") { @@ -917,15 +888,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip int 16") { @@ -934,15 +902,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip int 32") { @@ -952,15 +917,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip int 64") { @@ -971,15 +933,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip float 32") { @@ -989,15 +948,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip float 64") { @@ -1008,15 +964,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip fixstr") { @@ -1025,15 +978,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip str 8") { @@ -1055,15 +1005,12 @@ TEST_CASE("deserializeMsgPack() filter") { doc, "\x82\xA7onlyarr\xdb\x00\x00\x00\x05hello\xA7include\x2A", filterOpt); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip fixmap") { @@ -1073,15 +1020,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("one")), + Deallocate(sizeofString("one")), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip map 16") { @@ -1093,15 +1039,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("H")), + Deallocate(sizeofString("H")), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip map 32") { @@ -1115,15 +1060,14 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyarr\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("zero")), + Deallocate(sizeofString("zero")), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } } } @@ -1177,13 +1121,11 @@ TEST_CASE("deserializeMsgPack() filter") { "{\"onlyobj\":{\"measure\":2},\"include\":42}"); CHECK(spy.log() == AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyobj")), + Allocate(sizeofString("onlyobj")), Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("measure")), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofString("location")), + Reallocate(sizeofString("location"), sizeofString("measure")), + Allocate(sizeofString("include")), Reallocate(sizeofPool(), sizeofObject(2) + sizeofObject(1)), }); } @@ -1200,13 +1142,11 @@ TEST_CASE("deserializeMsgPack() filter") { "{\"onlyobj\":{\"measure\":2},\"include\":42}"); CHECK(spy.log() == AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyobj")), + Allocate(sizeofString("onlyobj")), Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("measure")), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofString("location")), + Reallocate(sizeofString("location"), sizeofString("measure")), + Allocate(sizeofString("include")), Reallocate(sizeofPool(), sizeofObject(2) + sizeofObject(1)), }); } @@ -1224,13 +1164,11 @@ TEST_CASE("deserializeMsgPack() filter") { "{\"onlyobj\":{\"measure\":2},\"include\":42}"); CHECK(spy.log() == AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyobj")), + Allocate(sizeofString("onlyobj")), Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("measure")), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), + Allocate(sizeofString("location")), + Reallocate(sizeofString("location"), sizeofString("measure")), + Allocate(sizeofString("include")), Reallocate(sizeofPool(), sizeofObject(2) + sizeofObject(1)), }); } @@ -1241,15 +1179,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip false") { @@ -1258,15 +1193,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip true") { @@ -1275,15 +1207,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip positive fixint") { @@ -1292,15 +1221,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip negative fixint") { @@ -1309,15 +1235,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip uint 8") { @@ -1326,15 +1249,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip uint 16") { @@ -1343,15 +1263,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip uint 32") { @@ -1360,15 +1277,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip uint 64") { @@ -1379,15 +1293,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip int 8") { @@ -1396,15 +1307,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip int 16") { @@ -1413,15 +1321,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip int 32") { @@ -1430,15 +1335,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip int 64") { @@ -1449,15 +1351,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip float 32") { @@ -1466,15 +1365,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip float 64") { @@ -1485,15 +1381,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip fixstr") { @@ -1502,15 +1395,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip str 8") { @@ -1532,15 +1422,12 @@ TEST_CASE("deserializeMsgPack() filter") { doc, "\x82\xA7onlyobj\xdb\x00\x00\x00\x05hello\xA7include\x2A", filterOpt); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip fixarray") { @@ -1549,15 +1436,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip array 16") { @@ -1568,15 +1452,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } SECTION("skip array 32") { @@ -1588,15 +1469,12 @@ TEST_CASE("deserializeMsgPack() filter") { CHECK(error == DeserializationError::Ok); CHECK(doc.as() == "{\"onlyobj\":null,\"include\":42}"); - CHECK(spy.log() == - AllocatorLog{ - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")), - Allocate(sizeofPool()), - Allocate(sizeofStringBuffer()), - Reallocate(sizeofStringBuffer(), sizeofString("include")), - Reallocate(sizeofPool(), sizeofObject(2)), - }); + CHECK(spy.log() == AllocatorLog{ + Allocate(sizeofString("onlyarr")), + Allocate(sizeofPool()), + Allocate(sizeofString("include")), + Reallocate(sizeofPool(), sizeofObject(2)), + }); } } @@ -1675,7 +1553,7 @@ TEST_CASE("Overloads") { } SECTION("const std::string&, Filter") { - deserializeMsgPack(doc, std::string("{}"), Filter(filter)); + deserializeMsgPack(doc, "{}"_s, Filter(filter)); } SECTION("std::istream&, Filter") { @@ -1703,7 +1581,7 @@ TEST_CASE("Overloads") { } SECTION("const std::string&, Filter, NestingLimit") { - deserializeMsgPack(doc, std::string("{}"), Filter(filter), NestingLimit(5)); + deserializeMsgPack(doc, "{}"_s, Filter(filter), NestingLimit(5)); } SECTION("std::istream&, Filter, NestingLimit") { @@ -1731,7 +1609,7 @@ TEST_CASE("Overloads") { } SECTION("const std::string&, NestingLimit, Filter") { - deserializeMsgPack(doc, std::string("{}"), NestingLimit(5), Filter(filter)); + deserializeMsgPack(doc, "{}"_s, NestingLimit(5), Filter(filter)); } SECTION("std::istream&, NestingLimit, Filter") { diff --git a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/input_types.cpp b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/input_types.cpp index 5417d9c..b581f20 100644 --- a/lib/ArduinoJson/extras/tests/MsgPackDeserializer/input_types.cpp +++ b/lib/ArduinoJson/extras/tests/MsgPackDeserializer/input_types.cpp @@ -6,6 +6,7 @@ #include #include "CustomReader.hpp" +#include "Literals.hpp" using ArduinoJson::detail::sizeofObject; @@ -21,8 +22,7 @@ TEST_CASE("deserializeMsgPack(const std::string&)") { } SECTION("should accept temporary string") { - DeserializationError err = - deserializeMsgPack(doc, std::string("\x92\x01\x02")); + DeserializationError err = deserializeMsgPack(doc, "\x92\x01\x02"_s); REQUIRE(err == DeserializationError::Ok); } @@ -35,12 +35,11 @@ TEST_CASE("deserializeMsgPack(const std::string&)") { JsonArray array = doc.as(); REQUIRE(err == DeserializationError::Ok); - REQUIRE(std::string("hello") == array[0]); + REQUIRE("hello"_s == array[0]); } SECTION("should accept a zero in input") { - DeserializationError err = - deserializeMsgPack(doc, std::string("\x92\x00\x02", 3)); + DeserializationError err = deserializeMsgPack(doc, "\x92\x00\x02"_s); REQUIRE(err == DeserializationError::Ok); JsonArray arr = doc.as(); @@ -53,7 +52,7 @@ TEST_CASE("deserializeMsgPack(std::istream&)") { JsonDocument doc; SECTION("should accept a zero in input") { - std::istringstream input(std::string("\x92\x00\x02", 3)); + std::istringstream input("\x92\x00\x02"_s); DeserializationError err = deserializeMsgPack(doc, input); diff --git a/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeArray.cpp b/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeArray.cpp index 2310085..3e36b9f 100644 --- a/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeArray.cpp +++ b/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeArray.cpp @@ -7,6 +7,8 @@ #include #include +#include "Literals.hpp" + static void check(const JsonArray array, const char* expected_data, size_t expected_len) { std::string expected(expected_data, expected_data + expected_len); @@ -57,7 +59,6 @@ TEST_CASE("serialize MsgPack array") { array.add(nil); REQUIRE(array.size() == 65536); - check(array, - std::string("\xDD\x00\x01\x00\x00", 5) + std::string(65536, '\xc0')); + check(array, "\xDD\x00\x01\x00\x00"_s + std::string(65536, '\xc0')); } } diff --git a/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeObject.cpp b/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeObject.cpp index 127a683..07774d0 100644 --- a/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeObject.cpp +++ b/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeObject.cpp @@ -6,6 +6,8 @@ #include #include +#include "Literals.hpp" + static void check(const JsonObject object, const char* expected_data, size_t expected_len) { std::string expected(expected_data, expected_data + expected_len); @@ -44,7 +46,7 @@ TEST_CASE("serialize MsgPack object") { SECTION("map 16") { for (int i = 0; i < 16; ++i) { char key[16]; - sprintf(key, "i%X", i); + snprintf(key, sizeof(key), "i%X", i); object[key] = i; } @@ -60,7 +62,7 @@ TEST_CASE("serialize MsgPack object") { // // for (int i = 0; i < 65536; ++i) { // char kv[16]; - // sprintf(kv, "%04x", i); + // snprintf(kv, sizeof(kv), "%04x", i); // object[kv] = kv; // expected += '\xA4'; // expected += kv; @@ -77,7 +79,7 @@ TEST_CASE("serialize MsgPack object") { } SECTION("serialized(std::string)") { - object["hello"] = serialized(std::string("\xDB\x00\x01\x00\x00", 5)); + object["hello"] = serialized("\xDB\x00\x01\x00\x00"_s); check(object, "\x81\xA5hello\xDB\x00\x01\x00\x00"); } } diff --git a/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeVariant.cpp b/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeVariant.cpp index 65ce0bc..43ca3ff 100644 --- a/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeVariant.cpp +++ b/lib/ArduinoJson/extras/tests/MsgPackSerializer/serializeVariant.cpp @@ -5,6 +5,8 @@ #include #include +#include "Literals.hpp" + template static void checkVariant(T value, const char* expected_data, size_t expected_len) { @@ -129,16 +131,15 @@ TEST_CASE("serialize MsgPack value") { SECTION("str 16") { std::string shortest(256, '?'); - checkVariant(shortest.c_str(), std::string("\xDA\x01\x00", 3) + shortest); + checkVariant(shortest.c_str(), "\xDA\x01\x00"_s + shortest); std::string longest(65535, '?'); - checkVariant(longest.c_str(), std::string("\xDA\xFF\xFF", 3) + longest); + checkVariant(longest.c_str(), "\xDA\xFF\xFF"_s + longest); } SECTION("str 32") { std::string shortest(65536, '?'); - checkVariant(shortest.c_str(), - std::string("\xDB\x00\x01\x00\x00", 5) + shortest); + checkVariant(shortest.c_str(), "\xDB\x00\x01\x00\x00"_s + shortest); } SECTION("serialized(const char*)") { @@ -146,6 +147,56 @@ TEST_CASE("serialize MsgPack value") { checkVariant(serialized("\xDB\x00\x01\x00\x00", 5), "\xDB\x00\x01\x00\x00"); } + SECTION("bin 8") { + checkVariant(MsgPackBinary("?", 1), "\xC4\x01?"); + } + + SECTION("bin 16") { + auto str = std::string(256, '?'); + checkVariant(MsgPackBinary(str.data(), str.size()), "\xC5\x01\x00"_s + str); + } + + // bin 32 is tested in string_length_size_4.cpp + + SECTION("fixext 1") { + checkVariant(MsgPackExtension(1, "\x02", 1), "\xD4\x01\x02"); + } + + SECTION("fixext 2") { + checkVariant(MsgPackExtension(1, "\x03\x04", 2), "\xD5\x01\x03\x04"); + } + + SECTION("fixext 4") { + checkVariant(MsgPackExtension(1, "\x05\x06\x07\x08", 4), + "\xD6\x01\x05\x06\x07\x08"); + } + + SECTION("fixext 8") { + checkVariant(MsgPackExtension(1, "????????", 8), "\xD7\x01????????"); + } + + SECTION("fixext 16") { + checkVariant(MsgPackExtension(1, "????????????????", 16), + "\xD8\x01????????????????"); + } + + SECTION("ext 8") { + checkVariant(MsgPackExtension(2, "???", 3), "\xC7\x03\x02???"); + checkVariant(MsgPackExtension(2, "?????", 5), "\xC7\x05\x02?????"); + checkVariant(MsgPackExtension(2, "???????", 7), "\xC7\x07\x02???????"); + checkVariant(MsgPackExtension(2, "?????????", 9), "\xC7\x09\x02?????????"); + checkVariant(MsgPackExtension(2, "???????????????", 15), + "\xC7\x0F\x02???????????????"); + checkVariant(MsgPackExtension(2, "?????????????????", 17), + "\xC7\x11\x02?????????????????"); + } + + SECTION("ext 16") { + auto str = std::string(256, '?'); + checkVariant(MsgPackExtension(2, str.data(), str.size()), + "\xC8\x01\x00\x02"_s + str); + } + SECTION("serialize round double as integer") { // Issue #1718 checkVariant(-32768.0, "\xD1\x80\x00"); checkVariant(-129.0, "\xD1\xFF\x7F"); diff --git a/lib/ArduinoJson/extras/tests/ResourceManager/StringBuilder.cpp b/lib/ArduinoJson/extras/tests/ResourceManager/StringBuilder.cpp index b649afe..f839858 100644 --- a/lib/ArduinoJson/extras/tests/ResourceManager/StringBuilder.cpp +++ b/lib/ArduinoJson/extras/tests/ResourceManager/StringBuilder.cpp @@ -3,6 +3,7 @@ // MIT License #include +#include #include #include "Allocators.hpp" diff --git a/lib/ArduinoJson/extras/tests/ResourceManager/allocVariant.cpp b/lib/ArduinoJson/extras/tests/ResourceManager/allocVariant.cpp index d884a28..4a3685d 100644 --- a/lib/ArduinoJson/extras/tests/ResourceManager/allocVariant.cpp +++ b/lib/ArduinoJson/extras/tests/ResourceManager/allocVariant.cpp @@ -2,9 +2,7 @@ // Copyright © 2014-2024, Benoit BLANCHON // MIT License -#include -#include -#include +#include #include #include "Allocators.hpp" diff --git a/lib/ArduinoJson/extras/tests/ResourceManager/saveString.cpp b/lib/ArduinoJson/extras/tests/ResourceManager/saveString.cpp index 88c242f..f19ac19 100644 --- a/lib/ArduinoJson/extras/tests/ResourceManager/saveString.cpp +++ b/lib/ArduinoJson/extras/tests/ResourceManager/saveString.cpp @@ -3,6 +3,7 @@ // MIT License #include +#include #include #include diff --git a/lib/ArduinoJson/idf_component.yml b/lib/ArduinoJson/idf_component.yml index fe30cfe..2f504e4 100644 --- a/lib/ArduinoJson/idf_component.yml +++ b/lib/ArduinoJson/idf_component.yml @@ -1,7 +1,7 @@ -version: "7.0.4" +version: "7.1.0" description: >- A simple and efficient JSON library for embedded C++. - ⭐ 6503 stars on GitHub! + ⭐ 6624 stars on GitHub! Supports serialization, deserialization, MessagePack, streams, filtering, and more. Fully tested and documented. url: https://arduinojson.org/ diff --git a/lib/ArduinoJson/library.json b/lib/ArduinoJson/library.json index 7e48770..e1c712a 100644 --- a/lib/ArduinoJson/library.json +++ b/lib/ArduinoJson/library.json @@ -1,13 +1,13 @@ { "name": "ArduinoJson", "keywords": "json, rest, http, web", - "description": "A simple and efficient JSON library for embedded C++. ⭐ 6503 stars on GitHub! Supports serialization, deserialization, MessagePack, streams, filtering, and more. Fully tested and documented.", + "description": "A simple and efficient JSON library for embedded C++. ⭐ 6624 stars on GitHub! Supports serialization, deserialization, MessagePack, streams, filtering, and more. Fully tested and documented.", "homepage": "https://arduinojson.org/?utm_source=meta&utm_medium=library.json", "repository": { "type": "git", "url": "https://github.com/bblanchon/ArduinoJson.git" }, - "version": "7.0.4", + "version": "7.1.0", "authors": { "name": "Benoit Blanchon", "url": "https://blog.benoitblanchon.fr" diff --git a/lib/ArduinoJson/library.properties b/lib/ArduinoJson/library.properties index e2a8ee3..9a59308 100644 --- a/lib/ArduinoJson/library.properties +++ b/lib/ArduinoJson/library.properties @@ -1,9 +1,9 @@ name=ArduinoJson -version=7.0.4 +version=7.1.0 author=Benoit Blanchon maintainer=Benoit Blanchon sentence=A simple and efficient JSON library for embedded C++. -paragraph=⭐ 6503 stars on GitHub! Supports serialization, deserialization, MessagePack, streams, filtering, and more. Fully tested and documented. +paragraph=⭐ 6624 stars on GitHub! Supports serialization, deserialization, MessagePack, streams, filtering, and more. Fully tested and documented. category=Data Processing url=https://arduinojson.org/?utm_source=meta&utm_medium=library.properties architectures=* diff --git a/lib/ArduinoJson/src/ArduinoJson.hpp b/lib/ArduinoJson/src/ArduinoJson.hpp index c210ed2..085507a 100644 --- a/lib/ArduinoJson/src/ArduinoJson.hpp +++ b/lib/ArduinoJson/src/ArduinoJson.hpp @@ -36,6 +36,7 @@ #include "ArduinoJson/Array/ElementProxy.hpp" #include "ArduinoJson/Array/Utilities.hpp" #include "ArduinoJson/Collection/CollectionImpl.hpp" +#include "ArduinoJson/Memory/ResourceManagerImpl.hpp" #include "ArduinoJson/Memory/VariantPoolImpl.hpp" #include "ArduinoJson/Object/MemberProxy.hpp" #include "ArduinoJson/Object/ObjectImpl.hpp" @@ -47,7 +48,9 @@ #include "ArduinoJson/Json/JsonDeserializer.hpp" #include "ArduinoJson/Json/JsonSerializer.hpp" #include "ArduinoJson/Json/PrettyJsonSerializer.hpp" +#include "ArduinoJson/MsgPack/MsgPackBinary.hpp" #include "ArduinoJson/MsgPack/MsgPackDeserializer.hpp" +#include "ArduinoJson/MsgPack/MsgPackExtension.hpp" #include "ArduinoJson/MsgPack/MsgPackSerializer.hpp" #include "ArduinoJson/compatibility.hpp" diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/ArrayData.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayData.hpp index 93a65d5..7e15ab1 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/ArrayData.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayData.hpp @@ -20,6 +20,17 @@ class ArrayData : public CollectionData { return array->addElement(resources); } + template + bool addValue(T&& value, ResourceManager* resources); + + template + static bool addValue(ArrayData* array, T&& value, + ResourceManager* resources) { + if (!array) + return false; + return array->addValue(value, resources); + } + VariantData* getOrAddElement(size_t index, ResourceManager* resources); VariantData* getElement(size_t index, const ResourceManager* resources) const; diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp index 595e847..9b96138 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp @@ -47,4 +47,19 @@ inline void ArrayData::removeElement(size_t index, ResourceManager* resources) { remove(at(index, resources), resources); } +template +inline bool ArrayData::addValue(T&& value, ResourceManager* resources) { + ARDUINOJSON_ASSERT(resources != nullptr); + auto slot = resources->allocSlot(); + if (!slot) + return false; + JsonVariant variant(slot->data(), resources); + if (!variant.set(detail::forward(value))) { + resources->freeSlot(slot); + return false; + } + addSlot(slot, resources); + return true; +} + ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp index 2923363..9a4e5f9 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp @@ -44,8 +44,7 @@ class JsonArray : public detail::VariantOperators { // Returns a reference to the new element. // https://arduinojson.org/v7/api/jsonarray/add/ template - typename detail::enable_if::value, T>::type - add() const { + detail::enable_if_t::value, T> add() const { return add().to(); } @@ -53,8 +52,7 @@ class JsonArray : public detail::VariantOperators { // Returns a reference to the new element. // https://arduinojson.org/v7/api/jsonarray/add/ template - typename detail::enable_if::value, T>::type - add() const { + detail::enable_if_t::value, T> add() const { return JsonVariant(detail::ArrayData::addElement(data_, resources_), resources_); } @@ -63,14 +61,14 @@ class JsonArray : public detail::VariantOperators { // https://arduinojson.org/v7/api/jsonarray/add/ template bool add(const T& value) const { - return add().set(value); + return detail::ArrayData::addValue(data_, value, resources_); } // Appends a value to the array. // https://arduinojson.org/v7/api/jsonarray/add/ template bool add(T* value) const { - return add().set(value); + return detail::ArrayData::addValue(data_, value, resources_); } // Returns an iterator to the first element of the array. @@ -114,6 +112,15 @@ class JsonArray : public detail::VariantOperators { detail::ArrayData::removeElement(data_, index, resources_); } + // Removes the element at the specified index. + // https://arduinojson.org/v7/api/jsonarray/remove/ + template + detail::enable_if_t::value> remove( + TVariant variant) const { + if (variant.template is()) + remove(variant.template as()); + } + // Removes all the elements of the array. // https://arduinojson.org/v7/api/jsonarray/clear/ void clear() const { @@ -122,8 +129,23 @@ class JsonArray : public detail::VariantOperators { // Gets or sets the element at the specified index. // https://arduinojson.org/v7/api/jsonarray/subscript/ - detail::ElementProxy operator[](size_t index) const { - return {*this, index}; + template + detail::enable_if_t::value, + detail::ElementProxy> + operator[](T index) const { + return {*this, size_t(index)}; + } + + // Gets or sets the element at the specified index. + // https://arduinojson.org/v7/api/jsonarray/subscript/ + template + detail::enable_if_t::value, + detail::ElementProxy> + operator[](const TVariant& variant) const { + if (variant.template is()) + return operator[](variant.template as()); + else + return {*this, size_t(-1)}; } operator JsonVariantConst() const { diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp index 6c0d7db..c6e027f 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp @@ -36,7 +36,7 @@ class JsonArrayConst : public detail::VariantOperators { } // Creates an unbound reference. - JsonArrayConst() : data_(0) {} + JsonArrayConst() : data_(0), resources_(0) {} // INTERNAL USE ONLY JsonArrayConst(const detail::ArrayData* data, @@ -45,9 +45,23 @@ class JsonArrayConst : public detail::VariantOperators { // Returns the element at the specified index. // https://arduinojson.org/v7/api/jsonarrayconst/subscript/ - JsonVariantConst operator[](size_t index) const { + template + detail::enable_if_t::value, JsonVariantConst> + operator[](T index) const { return JsonVariantConst( - detail::ArrayData::getElement(data_, index, resources_), resources_); + detail::ArrayData::getElement(data_, size_t(index), resources_), + resources_); + } + + // Returns the element at the specified index. + // https://arduinojson.org/v7/api/jsonarrayconst/subscript/ + template + detail::enable_if_t::value, JsonVariantConst> + operator[](const TVariant& variant) const { + if (variant.template is()) + return operator[](variant.template as()); + else + return JsonVariantConst(); } operator JsonVariantConst() const { diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp index ff589ce..9073468 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp @@ -12,16 +12,16 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE // Copies a value to a JsonVariant. // This is a degenerated form of copyArray() to stop the recursion. template -inline typename detail::enable_if::value, bool>::type -copyArray(const T& src, JsonVariant dst) { +inline detail::enable_if_t::value, bool> copyArray( + const T& src, JsonVariant dst) { return dst.set(src); } // Copies values from an array to a JsonArray or a JsonVariant. // https://arduinojson.org/v7/api/misc/copyarray/ template -inline typename detail::enable_if< - !detail::is_base_of::value, bool>::type +inline detail::enable_if_t< + !detail::is_base_of::value, bool> copyArray(T (&src)[N], const TDestination& dst) { return copyArray(src, N, dst); } @@ -29,8 +29,8 @@ copyArray(T (&src)[N], const TDestination& dst) { // Copies values from an array to a JsonArray or a JsonVariant. // https://arduinojson.org/v7/api/misc/copyarray/ template -inline typename detail::enable_if< - !detail::is_base_of::value, bool>::type +inline detail::enable_if_t< + !detail::is_base_of::value, bool> copyArray(const T* src, size_t len, const TDestination& dst) { bool ok = true; for (size_t i = 0; i < len; i++) { @@ -63,8 +63,8 @@ inline bool copyArray(const T* src, size_t len, JsonDocument& dst) { // Copies a value from a JsonVariant. // This is a degenerated form of copyArray() to stop the recursion. template -inline typename detail::enable_if::value, size_t>::type -copyArray(JsonVariantConst src, T& dst) { +inline detail::enable_if_t::value, size_t> copyArray( + JsonVariantConst src, T& dst) { dst = src.as(); return 1; } @@ -103,10 +103,9 @@ inline size_t copyArray(JsonVariantConst src, char (&dst)[N]) { // Copies values from a JsonDocument to an array. // https://arduinojson.org/v7/api/misc/copyarray/ template -inline typename detail::enable_if< - detail::is_array::value && - detail::is_base_of::value, - size_t>::type +inline detail::enable_if_t::value && + detail::is_base_of::value, + size_t> copyArray(const TSource& src, T& dst) { return copyArray(src.template as(), dst); } diff --git a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp index 07fe7e0..07e6982 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp @@ -111,12 +111,13 @@ class CollectionData { return head_; } + void addSlot(SlotWithId slot, ResourceManager* resources); + protected: iterator addSlot(ResourceManager*); private: SlotWithId getPreviousSlot(VariantSlot*, const ResourceManager*) const; - void releaseSlot(SlotWithId, ResourceManager*); }; inline const VariantData* collectionToVariant( diff --git a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp index 79d9ac7..c7e23a3 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp @@ -63,13 +63,25 @@ inline CollectionData::iterator CollectionData::addSlot( return iterator(slot, slot.id()); } +inline void CollectionData::addSlot(SlotWithId slot, + ResourceManager* resources) { + if (tail_ != NULL_SLOT) { + auto tail = resources->getSlot(tail_); + tail->setNext(slot.id()); + tail_ = slot.id(); + } else { + head_ = slot.id(); + tail_ = slot.id(); + } +} + inline void CollectionData::clear(ResourceManager* resources) { auto next = head_; while (next != NULL_SLOT) { auto currId = next; auto slot = resources->getSlot(next); next = slot->next(); - releaseSlot(SlotWithId(slot, currId), resources); + resources->freeSlot(SlotWithId(slot, currId)); } head_ = NULL_SLOT; @@ -102,7 +114,7 @@ inline void CollectionData::remove(iterator it, ResourceManager* resources) { head_ = next; if (next == NULL_SLOT) tail_ = prev.id(); - releaseSlot({it.slot_, it.currentId_}, resources); + resources->freeSlot({it.slot_, it.currentId_}); } inline size_t CollectionData::nesting(const ResourceManager* resources) const { @@ -122,12 +134,4 @@ inline size_t CollectionData::size(const ResourceManager* resources) const { return count; } -inline void CollectionData::releaseSlot(SlotWithId slot, - ResourceManager* resources) { - if (slot->ownsKey()) - resources->dereferenceString(slot->key()); - slot->data()->setNull(resources); - resources->freeSlot(slot); -} - ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp b/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp index cc6292a..ae60890 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp @@ -93,11 +93,14 @@ // https://arduinojson.org/v7/config/slot_id_size/ #ifndef ARDUINOJSON_SLOT_ID_SIZE # if ARDUINOJSON_SIZEOF_POINTER <= 2 -# define ARDUINOJSON_SLOT_ID_SIZE 1 // up to 255 slots +// 8-bit and 16-bit archs => up to 255 slots +# define ARDUINOJSON_SLOT_ID_SIZE 1 # elif ARDUINOJSON_SIZEOF_POINTER == 4 -# define ARDUINOJSON_SLOT_ID_SIZE 2 // up to 65535 slots +// 32-bit arch => up to 65535 slots +# define ARDUINOJSON_SLOT_ID_SIZE 2 # else -# define ARDUINOJSON_SLOT_ID_SIZE 4 // up to 4294967295 slots +// 64-bit arch => up to 4294967295 slots +# define ARDUINOJSON_SLOT_ID_SIZE 4 # endif #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp index c4b5edb..fed87b3 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp @@ -62,9 +62,8 @@ ARDUINOJSON_END_PRIVATE_NAMESPACE ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE template -Reader::type> makeReader(TInput&& input) { - return Reader::type>{ - detail::forward(input)}; +Reader> makeReader(TInput&& input) { + return Reader>{detail::forward(input)}; } template diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp index 43c5a43..a4b1143 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp @@ -9,8 +9,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE template -struct Reader::value>::type> { +struct Reader::value>> { public: explicit Reader(Stream& stream) : stream_(&stream) {} diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp index 4730be0..d55859f 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp @@ -9,8 +9,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE template -struct Reader::value>::type> +struct Reader::value>> : BoundedReader { explicit Reader(const ::String& s) : BoundedReader(s.c_str(), s.length()) {} diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp index 1ca46c8..5584ec5 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp @@ -4,6 +4,8 @@ #pragma once +#include + ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE template @@ -29,13 +31,8 @@ class IteratorReader { } }; -template -struct void_ { - typedef void type; -}; - template -struct Reader::type> +struct Reader> : IteratorReader { explicit Reader(const TSource& source) : IteratorReader(source.begin(), diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp index 8603bb1..4739d72 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp @@ -19,8 +19,7 @@ template struct IsCharOrVoid : IsCharOrVoid {}; template -struct Reader::value>::type> { +struct Reader::value>> { const char* ptr_; public: @@ -39,8 +38,7 @@ struct Reader -struct BoundedReader::value>::type> +struct BoundedReader::value>> : public IteratorReader { public: explicit BoundedReader(const void* ptr, size_t len) diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp index 25ba636..947dd7f 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp @@ -9,8 +9,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE template -struct Reader::value>::type> { +struct Reader::value>> { public: explicit Reader(std::istream& stream) : stream_(&stream) {} diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp index ddb07b8..92f9541 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp @@ -10,7 +10,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE template -struct Reader::value>::type> +struct Reader::value>> : Reader { explicit Reader(const TVariant& x) : Reader(x.template as()) {} diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp index 21d1876..b33313e 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp @@ -29,10 +29,9 @@ struct is_deserialize_destination : false_type {}; template struct is_deserialize_destination< - T, typename enable_if())), - ResourceManager*>::value>::type> : true_type { -}; + T, enable_if_t())), + ResourceManager*>::value>> : true_type {}; template inline void shrinkJsonDocument(TDestination&) { @@ -62,8 +61,8 @@ DeserializationError doDeserialize(TDestination&& dst, TReader reader, template