From 6ee79cfe143d857cb267caf0ba061db057c138ae Mon Sep 17 00:00:00 2001 From: jimmys01 Date: Sat, 11 Jul 2020 13:11:44 +0300 Subject: [PATCH] arduJSON library update --- lib/ArduinoJson-6.x/.clang-format | 3 + lib/ArduinoJson-6.x/.github/lock.yml | 7 + lib/ArduinoJson-6.x/.gitignore | 6 +- lib/ArduinoJson-6.x/.travis.yml | 17 +- lib/ArduinoJson-6.x/ArduinoJson.h | 2 +- lib/ArduinoJson-6.x/CHANGELOG.md | 165 ++++ lib/ArduinoJson-6.x/CMakeLists.txt | 23 +- lib/ArduinoJson-6.x/LICENSE.md | 2 +- lib/ArduinoJson-6.x/README.md | 143 ++-- lib/ArduinoJson-6.x/appveyor.yml | 4 +- lib/ArduinoJson-6.x/component.mk | 1 + .../JsonConfigFile/JsonConfigFile.ino | 11 +- .../JsonFilterExample/JsonFilterExample.ino | 63 ++ .../JsonGeneratorExample.ino | 2 +- .../JsonHttpClient/JsonHttpClient.ino | 2 +- .../JsonParserExample/JsonParserExample.ino | 2 +- .../examples/JsonServer/JsonServer.ino | 2 +- .../examples/JsonUdpBeacon/JsonUdpBeacon.ino | 2 +- .../examples/MsgPackParser/MsgPackParser.ino | 2 +- .../ProgmemExample/ProgmemExample.ino | 2 +- .../examples/StringExample/StringExample.ino | 2 +- .../extras/ArduinoJsonConfig.cmake.in | 4 + .../CompileOptions.cmake} | 56 +- .../{scripts/travis => extras/ci}/arduino.sh | 0 lib/ArduinoJson-6.x/extras/ci/build.sh | 7 + .../{scripts/travis => extras/ci}/coverage.sh | 3 +- .../{scripts/travis => extras/ci}/fuzz.sh | 2 +- .../travis => extras/ci}/platformio.sh | 2 - lib/ArduinoJson-6.x/extras/ci/test.sh | 10 + .../{ => extras}/fuzzing/CMakeLists.txt | 8 +- .../{ => extras}/fuzzing/Makefile | 4 +- .../{ => extras}/fuzzing/fuzzer_main.cpp | 4 +- .../fuzzing/json_corpus/.gitignore | 0 .../{ => extras}/fuzzing/json_fuzzer.cpp | 0 .../fuzzing/json_seed_corpus/Comments.json | 0 .../fuzzing/json_seed_corpus/EmptyArray.json | 0 .../fuzzing/json_seed_corpus/EmptyObject.json | 0 .../json_seed_corpus/ExcessiveNesting.json | 0 .../json_seed_corpus/IntegerOverflow.json | 0 .../fuzzing/json_seed_corpus/Numbers.json | 0 .../json_seed_corpus/OpenWeatherMap.json | 0 .../fuzzing/json_seed_corpus/Strings.json | 0 .../json_seed_corpus/WeatherUnderground.json | 0 .../fuzzing/msgpack_corpus/.gitignore | 0 .../{ => extras}/fuzzing/msgpack_fuzzer.cpp | 0 .../fuzzing/msgpack_seed_corpus/array16 | Bin .../fuzzing/msgpack_seed_corpus/array32 | Bin .../fuzzing/msgpack_seed_corpus/false | 0 .../fuzzing/msgpack_seed_corpus/fixarray | 0 .../msgpack_seed_corpus/fixint_negative | 0 .../msgpack_seed_corpus/fixint_positive | 0 .../fuzzing/msgpack_seed_corpus/fixmap | 0 .../fuzzing/msgpack_seed_corpus/fixstr | 0 .../fuzzing/msgpack_seed_corpus/float32 | 0 .../fuzzing/msgpack_seed_corpus/float64 | 0 .../fuzzing/msgpack_seed_corpus/int16 | 0 .../fuzzing/msgpack_seed_corpus/int32 | 0 .../fuzzing/msgpack_seed_corpus/int64 | 0 .../fuzzing/msgpack_seed_corpus/int8 | 0 .../fuzzing/msgpack_seed_corpus/map16 | Bin .../fuzzing/msgpack_seed_corpus/map32 | Bin .../fuzzing/msgpack_seed_corpus/nil | 0 .../fuzzing/msgpack_seed_corpus/str16 | Bin .../fuzzing/msgpack_seed_corpus/str32 | Bin .../fuzzing/msgpack_seed_corpus/str8 | 0 .../fuzzing/msgpack_seed_corpus/true | 0 .../fuzzing/msgpack_seed_corpus/uint16 | 0 .../fuzzing/msgpack_seed_corpus/uint32 | 0 .../fuzzing/msgpack_seed_corpus/uint64 | 0 .../fuzzing/msgpack_seed_corpus/uint8 | 0 .../scripts/build-arduino-package.sh | 2 +- .../extras/scripts/build-single-header.sh | 82 ++ .../scripts/publish-particle-library.sh | 2 +- .../{ => extras}/scripts/publish.sh | 21 +- .../scripts/wandbox/JsonGeneratorExample.cpp | 2 +- .../scripts/wandbox/JsonParserExample.cpp | 2 +- .../scripts/wandbox/MsgPackParserExample.cpp | 2 +- .../{ => extras}/scripts/wandbox/publish.sh | 0 .../extras/tests/CMakeLists.txt | 26 + .../tests}/ElementProxy/CMakeLists.txt | 4 +- .../tests}/ElementProxy/add.cpp | 10 +- .../tests}/ElementProxy/clear.cpp | 2 +- .../extras/tests/ElementProxy/compare.cpp | 48 ++ .../tests}/ElementProxy/remove.cpp | 2 +- .../tests}/ElementProxy/set.cpp | 11 +- .../tests}/ElementProxy/size.cpp | 2 +- .../extras/tests/ElementProxy/subscript.cpp | 25 + .../extras/tests/FailingBuilds/CMakeLists.txt | 38 + .../extras/tests/FailingBuilds/Issue1189.cpp | 13 + .../tests/FailingBuilds}/Issue978.cpp | 2 +- .../tests/FailingBuilds/read_long_long.cpp | 20 + .../tests/FailingBuilds/write_long_long.cpp | 19 + .../extras/tests/Helpers/CustomReader.hpp | 26 + .../extras/tests/Helpers/Stream.h | 14 + .../extras/tests/Helpers/WString.h | 42 + .../tests/Helpers/progmem_emulation.hpp | 23 + .../tests}/IntegrationTests/CMakeLists.txt | 4 +- .../tests}/IntegrationTests/gbathree.cpp | 2 +- .../tests}/IntegrationTests/issue772.cpp | 2 +- .../tests/IntegrationTests/openweathermap.cpp | 68 ++ .../tests}/IntegrationTests/round_trip.cpp | 2 +- .../tests}/JsonArray/CMakeLists.txt | 3 +- .../{test => extras/tests}/JsonArray/add.cpp | 6 +- .../tests}/JsonArray/copyArray.cpp | 60 +- .../tests}/JsonArray/createNested.cpp | 2 +- .../tests}/JsonArray/equals.cpp | 23 +- .../{test => extras/tests}/JsonArray/get.cpp | 2 +- .../extras/tests/JsonArray/isNull.cpp | 58 ++ .../tests}/JsonArray/iterator.cpp | 22 +- .../tests}/JsonArray/memoryUsage.cpp | 2 +- .../tests}/JsonArray/nesting.cpp | 2 +- .../tests}/JsonArray/remove.cpp | 2 +- .../{test => extras/tests}/JsonArray/size.cpp | 2 +- .../tests}/JsonArray/std_string.cpp | 2 +- .../tests}/JsonArray/subscript.cpp | 21 +- .../tests}/JsonArray/undefined.cpp | 2 +- .../tests}/JsonDeserializer/CMakeLists.txt | 8 +- .../JsonDeserializer/DeserializationError.cpp | 2 +- .../tests}/JsonDeserializer/array.cpp | 151 +--- .../tests}/JsonDeserializer/array_static.cpp | 4 +- .../extras/tests/JsonDeserializer/filter.cpp | 749 ++++++++++++++++++ .../JsonDeserializer/incomplete_input.cpp | 6 +- .../tests}/JsonDeserializer/input_types.cpp | 73 +- .../tests}/JsonDeserializer/invalid_input.cpp | 11 +- .../tests}/JsonDeserializer/misc.cpp | 34 +- .../tests}/JsonDeserializer/nestingLimit.cpp | 2 +- .../tests}/JsonDeserializer/number.cpp | 2 +- .../tests}/JsonDeserializer/object.cpp | 209 +---- .../tests}/JsonDeserializer/object_static.cpp | 2 +- .../tests}/JsonDeserializer/string.cpp | 41 +- .../tests/JsonDocument/BasicJsonDocument.cpp | 157 ++++ .../tests}/JsonDocument/CMakeLists.txt | 5 +- .../JsonDocument/DynamicJsonDocument.cpp | 6 +- .../JsonDocument/StaticJsonDocument.cpp | 14 +- .../tests}/JsonDocument/add.cpp | 2 +- .../extras/tests/JsonDocument/compare.cpp | 77 ++ .../tests}/JsonDocument/containsKey.cpp | 2 +- .../tests}/JsonDocument/createNested.cpp | 2 +- .../tests}/JsonDocument/isNull.cpp | 2 +- .../tests}/JsonDocument/nesting.cpp | 2 +- .../tests}/JsonDocument/remove.cpp | 2 +- .../extras/tests/JsonDocument/shrinkToFit.cpp | 154 ++++ .../tests}/JsonDocument/size.cpp | 2 +- .../tests}/JsonDocument/subscript.cpp | 10 +- .../tests}/JsonObject/CMakeLists.txt | 3 +- .../tests}/JsonObject/containsKey.cpp | 2 +- .../tests}/JsonObject/copy.cpp | 59 +- .../tests}/JsonObject/createNestedArray.cpp | 2 +- .../tests}/JsonObject/createNestedObject.cpp | 2 +- .../tests}/JsonObject/equals.cpp | 16 +- .../tests}/JsonObject/invalid.cpp | 2 +- .../extras/tests/JsonObject/isNull.cpp | 58 ++ .../tests}/JsonObject/iterator.cpp | 21 +- .../tests}/JsonObject/memoryUsage.cpp | 2 +- .../tests}/JsonObject/nesting.cpp | 2 +- .../tests}/JsonObject/remove.cpp | 7 +- .../tests}/JsonObject/size.cpp | 2 +- .../tests}/JsonObject/std_string.cpp | 2 +- .../tests}/JsonObject/subscript.cpp | 16 +- .../tests}/JsonSerializer/CMakeLists.txt | 4 +- .../tests/JsonSerializer/CustomWriter.cpp | 52 ++ .../tests}/JsonSerializer/JsonArray.cpp | 2 +- .../tests}/JsonSerializer/JsonArrayPretty.cpp | 54 +- .../tests}/JsonSerializer/JsonObject.cpp | 30 +- .../tests/JsonSerializer/JsonObjectPretty.cpp | 77 ++ .../tests}/JsonSerializer/JsonVariant.cpp | 34 +- .../tests}/JsonSerializer/misc.cpp | 10 - .../tests}/JsonSerializer/std_stream.cpp | 2 +- .../tests}/JsonSerializer/std_string.cpp | 2 +- .../tests}/JsonVariant/CMakeLists.txt | 3 +- .../tests}/JsonVariant/add.cpp | 4 +- .../{test => extras/tests}/JsonVariant/as.cpp | 39 +- .../tests}/JsonVariant/clear.cpp | 4 +- .../extras/tests/JsonVariant/compare.cpp | 280 +++++++ .../tests}/JsonVariant/containsKey.cpp | 18 +- .../tests}/JsonVariant/copy.cpp | 24 +- .../tests}/JsonVariant/createNested.cpp | 4 +- .../{test => extras/tests}/JsonVariant/is.cpp | 6 +- .../tests}/JsonVariant/isnull.cpp | 2 +- .../tests}/JsonVariant/memoryUsage.cpp | 2 +- .../tests}/JsonVariant/misc.cpp | 2 +- .../tests}/JsonVariant/nesting.cpp | 2 +- .../{test => extras/tests}/JsonVariant/or.cpp | 2 +- .../tests}/JsonVariant/overflow.cpp | 2 +- .../tests}/JsonVariant/remove.cpp | 2 +- .../tests}/JsonVariant/set.cpp | 31 +- .../tests}/JsonVariant/subscript.cpp | 8 +- .../tests}/JsonVariant/types.cpp | 2 +- .../tests}/JsonVariant/undefined.cpp | 2 +- .../tests}/MemberProxy/CMakeLists.txt | 4 +- .../tests}/MemberProxy/add.cpp | 2 +- .../tests}/MemberProxy/clear.cpp | 2 +- .../extras/tests/MemberProxy/compare.cpp | 48 ++ .../tests}/MemberProxy/containsKey.cpp | 2 +- .../tests}/MemberProxy/remove.cpp | 2 +- .../tests}/MemberProxy/set.cpp | 10 +- .../tests}/MemberProxy/size.cpp | 2 +- .../tests}/MemberProxy/subscript.cpp | 10 +- .../tests}/MemoryPool/CMakeLists.txt | 3 +- .../tests}/MemoryPool/StringBuilder.cpp | 8 +- .../tests}/MemoryPool/allocString.cpp | 2 +- .../tests}/MemoryPool/allocVariant.cpp | 6 +- .../tests}/MemoryPool/clear.cpp | 2 +- .../tests}/MemoryPool/size.cpp | 18 +- .../extras/tests/Misc/CMakeLists.txt | 21 + .../tests}/Misc/FloatParts.cpp | 2 +- .../extras/tests/Misc/Readers.cpp | 225 ++++++ .../extras/tests/Misc/StringAdapters.cpp | 156 ++++ .../extras/tests/Misc/StringWriter.cpp | 118 +++ .../tests}/Misc/TypeTraits.cpp | 47 +- .../extras/tests/Misc/Utf16.cpp | 68 ++ .../extras/tests/Misc/Utf8.cpp | 59 ++ .../extras/tests/Misc/arithmeticCompare.cpp | 103 +++ .../{test => extras/tests}/Misc/conflicts.cpp | 4 +- .../extras/tests/Misc/custom_string.hpp | 12 + .../tests}/Misc/unsigned_char.cpp | 66 +- .../{test => extras/tests}/Misc/version.cpp | 2 +- .../extras/tests/Misc/weird_strcmp.hpp | 23 + .../tests}/MixedConfiguration/CMakeLists.txt | 10 +- .../extras/tests/MixedConfiguration/cpp11.cpp | 94 +++ .../MixedConfiguration/decode_unicode_0.cpp | 0 .../MixedConfiguration/decode_unicode_1.cpp | 0 .../MixedConfiguration/enable_alignment_0.cpp | 41 + .../MixedConfiguration/enable_alignment_1.cpp | 40 + .../MixedConfiguration/enable_comments_0.cpp | 54 ++ .../MixedConfiguration/enable_comments_1.cpp | 405 ++++++++++ .../MixedConfiguration/enable_infinity_0.cpp | 0 .../MixedConfiguration/enable_infinity_1.cpp | 0 .../MixedConfiguration/enable_nan_0.cpp | 0 .../MixedConfiguration/enable_nan_1.cpp | 0 .../MixedConfiguration/enable_progmem_1.cpp | 167 ++++ .../MixedConfiguration/use_double_0.cpp | 0 .../MixedConfiguration/use_double_1.cpp | 0 .../MixedConfiguration/use_long_long_0.cpp | 16 + .../MixedConfiguration/use_long_long_1.cpp | 0 .../tests}/MsgPackDeserializer/CMakeLists.txt | 3 +- .../MsgPackDeserializer/deserializeArray.cpp | 2 +- .../MsgPackDeserializer/deserializeObject.cpp | 2 +- .../deserializeStaticVariant.cpp | 8 +- .../deserializeVariant.cpp | 2 +- .../MsgPackDeserializer/doubleToFloat.cpp | 2 +- .../MsgPackDeserializer/incompleteInput.cpp | 3 +- .../MsgPackDeserializer/input_types.cpp | 15 +- .../MsgPackDeserializer/nestingLimit.cpp | 2 +- .../MsgPackDeserializer/notSupported.cpp | 2 +- .../tests}/MsgPackSerializer/CMakeLists.txt | 3 +- .../MsgPackSerializer/destination_types.cpp | 2 +- .../tests}/MsgPackSerializer/measure.cpp | 2 +- .../tests}/MsgPackSerializer/misc.cpp | 0 .../MsgPackSerializer/serializeArray.cpp | 2 +- .../MsgPackSerializer/serializeObject.cpp | 2 +- .../MsgPackSerializer/serializeVariant.cpp | 141 ++++ .../tests}/Numbers/CMakeLists.txt | 4 +- .../extras/tests/Numbers/parseFloat.cpp | 172 ++++ .../extras/tests/Numbers/parseInteger.cpp | 67 ++ .../tests}/Numbers/parseNumber.cpp | 2 +- .../extras/tests/TextFormatter/CMakeLists.txt | 12 + .../tests}/TextFormatter/writeFloat.cpp | 8 +- .../tests}/TextFormatter/writeString.cpp | 8 +- .../tests}/catch/CMakeLists.txt | 2 +- .../tests}/catch/catch.cpp | 2 +- .../tests}/catch/catch.hpp | 0 lib/ArduinoJson-6.x/keywords.txt | 3 + lib/ArduinoJson-6.x/library.json | 10 +- lib/ArduinoJson-6.x/library.properties | 6 +- .../scripts/build-single-header.sh | 53 -- .../scripts/create-build-envs.sh | 29 - .../scripts/oss-fuzz/.gitignore | 2 - .../scripts/oss-fuzz/Vagrantfile | 34 - lib/ArduinoJson-6.x/scripts/travis/build.sh | 14 - lib/ArduinoJson-6.x/scripts/travis/test.sh | 4 - lib/ArduinoJson-6.x/src/ArduinoJson.h | 2 +- lib/ArduinoJson-6.x/src/ArduinoJson.hpp | 14 +- .../src/ArduinoJson/Array/ArrayFunctions.hpp | 13 +- .../src/ArduinoJson/Array/ArrayImpl.hpp | 12 +- .../src/ArduinoJson/Array/ArrayIterator.hpp | 6 +- .../src/ArduinoJson/Array/ArrayRef.hpp | 40 +- .../src/ArduinoJson/Array/ArrayShortcuts.hpp | 8 +- .../src/ArduinoJson/Array/ElementProxy.hpp | 47 +- .../src/ArduinoJson/Array/Utilities.hpp | 35 +- .../ArduinoJson/Collection/CollectionData.hpp | 64 +- .../ArduinoJson/Collection/CollectionImpl.hpp | 125 ++- .../src/ArduinoJson/Configuration.hpp | 85 +- .../Deserialization/ArduinoStreamReader.hpp | 31 - .../Deserialization/CharPointerReader.hpp | 67 -- .../Deserialization/DeserializationError.hpp | 4 +- .../ArduinoJson/Deserialization/Filter.hpp | 66 ++ .../Deserialization/FlashStringReader.hpp | 48 -- .../Deserialization/IteratorReader.hpp | 31 - .../Deserialization/NestingLimit.hpp | 24 +- .../ArduinoJson/Deserialization/Reader.hpp | 56 ++ .../Readers/ArduinoStreamReader.hpp | 31 + .../Readers/ArduinoStringReader.hpp | 17 + .../Deserialization/Readers/FlashReader.hpp | 53 ++ .../Readers/IteratorReader.hpp | 43 + .../Deserialization/Readers/RamReader.hpp | 50 ++ .../Readers/StdStreamReader.hpp | 29 + .../Deserialization/Readers/VariantReader.hpp | 34 + .../Deserialization/StdStreamReader.hpp | 34 - .../Deserialization/deserialize.hpp | 91 +-- .../Document/BasicJsonDocument.hpp | 111 ++- .../Document/DynamicJsonDocument.hpp | 16 +- .../src/ArduinoJson/Document/JsonDocument.hpp | 49 +- .../Document/StaticJsonDocument.hpp | 9 +- .../src/ArduinoJson/Json/EscapeSequence.hpp | 18 +- .../src/ArduinoJson/Json/JsonDeserializer.hpp | 508 +++++++++--- .../src/ArduinoJson/Json/JsonSerializer.hpp | 20 +- .../src/ArduinoJson/Json/Latch.hpp | 55 ++ .../ArduinoJson/Json/PrettyJsonSerializer.hpp | 18 +- .../src/ArduinoJson/Json/TextFormatter.hpp | 39 +- .../src/ArduinoJson/Json/Utf16.hpp | 65 ++ .../src/ArduinoJson/Json/Utf8.hpp | 42 +- .../src/ArduinoJson/Memory/Alignment.hpp | 38 +- .../src/ArduinoJson/Memory/MemoryPool.hpp | 82 +- .../src/ArduinoJson/Memory/StringBuilder.hpp | 7 +- .../src/ArduinoJson/Memory/StringSlot.hpp | 7 +- .../src/ArduinoJson/Misc/SerializedValue.hpp | 4 +- .../src/ArduinoJson/Misc/Visitable.hpp | 4 +- .../MsgPack/MsgPackDeserializer.hpp | 162 ++-- .../ArduinoJson/MsgPack/MsgPackSerializer.hpp | 35 +- .../src/ArduinoJson/MsgPack/endianess.hpp | 6 +- .../src/ArduinoJson/MsgPack/ieee754.hpp | 4 +- .../src/ArduinoJson/Namespace.hpp | 21 +- .../src/ArduinoJson/Numbers/Float.hpp | 5 +- .../src/ArduinoJson/Numbers/FloatParts.hpp | 8 +- .../src/ArduinoJson/Numbers/FloatTraits.hpp | 21 +- .../src/ArduinoJson/Numbers/Integer.hpp | 16 +- .../ArduinoJson/Numbers/arithmeticCompare.hpp | 121 +++ .../src/ArduinoJson/Numbers/convertNumber.hpp | 10 +- .../src/ArduinoJson/Numbers/parseFloat.hpp | 6 +- .../src/ArduinoJson/Numbers/parseInteger.hpp | 8 +- .../src/ArduinoJson/Numbers/parseNumber.hpp | 37 +- .../src/ArduinoJson/Object/MemberProxy.hpp | 46 +- .../ArduinoJson/Object/ObjectFunctions.hpp | 39 +- .../src/ArduinoJson/Object/ObjectImpl.hpp | 23 +- .../src/ArduinoJson/Object/ObjectIterator.hpp | 6 +- .../src/ArduinoJson/Object/ObjectRef.hpp | 49 +- .../ArduinoJson/Object/ObjectShortcuts.hpp | 17 +- .../src/ArduinoJson/Object/Pair.hpp | 6 +- .../ArduinoJson/Operators/VariantCasts.hpp | 24 - .../Operators/VariantComparisons.hpp | 244 ------ .../Operators/VariantOperators.hpp | 19 - .../src/ArduinoJson/Operators/VariantOr.hpp | 37 - .../src/ArduinoJson/Polyfills/alias_cast.hpp | 7 +- .../src/ArduinoJson/Polyfills/assert.hpp | 6 +- .../src/ArduinoJson/Polyfills/attributes.hpp | 2 +- .../src/ArduinoJson/Polyfills/ctype.hpp | 4 +- .../ArduinoJson/Polyfills/gsl/not_null.hpp | 5 +- .../src/ArduinoJson/Polyfills/limits.hpp | 4 +- .../src/ArduinoJson/Polyfills/math.hpp | 4 +- .../src/ArduinoJson/Polyfills/mpl/max.hpp | 4 +- .../src/ArduinoJson/Polyfills/pgmspace.hpp | 78 ++ .../src/ArduinoJson/Polyfills/safe_strcmp.hpp | 32 +- .../src/ArduinoJson/Polyfills/type_traits.hpp | 5 +- .../Polyfills/type_traits/conditional.hpp | 4 +- .../Polyfills/type_traits/declval.hpp | 14 + .../Polyfills/type_traits/enable_if.hpp | 4 +- .../type_traits/integral_constant.hpp | 4 +- .../Polyfills/type_traits/is_array.hpp | 4 +- .../Polyfills/type_traits/is_base_of.hpp | 4 +- .../Polyfills/type_traits/is_class.hpp | 26 + .../Polyfills/type_traits/is_const.hpp | 2 +- .../Polyfills/type_traits/is_convertible.hpp | 34 + .../Polyfills/type_traits/is_enum.hpp | 22 + .../type_traits/is_floating_point.hpp | 2 +- .../Polyfills/type_traits/is_integral.hpp | 8 +- .../Polyfills/type_traits/is_same.hpp | 2 +- .../Polyfills/type_traits/is_signed.hpp | 2 +- .../Polyfills/type_traits/is_unsigned.hpp | 2 +- .../Polyfills/type_traits/make_unsigned.hpp | 2 +- .../Polyfills/type_traits/remove_const.hpp | 4 +- .../type_traits/remove_reference.hpp | 4 +- .../Polyfills/type_traits/type_identity.hpp | 2 +- .../src/ArduinoJson/Polyfills/utility.hpp | 16 +- .../Serialization/DynamicStringWriter.hpp | 79 -- .../Serialization/StreamWriter.hpp | 38 - .../src/ArduinoJson/Serialization/Writer.hpp | 47 ++ .../Writers/ArduinoStringWriter.hpp | 52 ++ .../{ => Writers}/DummyWriter.hpp | 4 +- .../Serialization/Writers/PrintWriter.hpp | 28 + .../{ => Writers}/StaticStringWriter.hpp | 7 +- .../Serialization/Writers/StdStreamWriter.hpp | 32 + .../Serialization/Writers/StdStringWriter.hpp | 40 + .../src/ArduinoJson/Serialization/measure.hpp | 4 +- .../ArduinoJson/Serialization/serialize.hpp | 55 +- .../StringStorage/StringCopier.hpp | 10 +- .../ArduinoJson/StringStorage/StringMover.hpp | 9 +- .../StringStorage/StringStorage.hpp | 6 +- .../Strings/ArduinoStringAdapter.hpp | 25 +- .../Strings/ConstRamStringAdapter.hpp | 27 +- .../Strings/FlashStringAdapter.hpp | 36 +- .../src/ArduinoJson/Strings/IsString.hpp | 18 + .../ArduinoJson/Strings/IsWriteableString.hpp | 37 + .../ArduinoJson/Strings/RamStringAdapter.hpp | 18 +- .../Strings/SizedFlashStringAdapter.hpp | 28 +- .../Strings/SizedRamStringAdapter.hpp | 21 +- .../ArduinoJson/Strings/StlStringAdapter.hpp | 48 +- .../src/ArduinoJson/Strings/StoragePolicy.hpp | 15 + .../src/ArduinoJson/Strings/String.hpp | 20 +- .../ArduinoJson/Strings/StringAdapters.hpp | 30 +- .../src/ArduinoJson/Variant/SlotFunctions.hpp | 41 +- .../src/ArduinoJson/Variant/VariantAs.hpp | 47 +- .../src/ArduinoJson/Variant/VariantAsImpl.hpp | 26 +- .../ArduinoJson/Variant/VariantCompare.hpp | 241 ++++++ .../ArduinoJson/Variant/VariantContent.hpp | 27 +- .../src/ArduinoJson/Variant/VariantData.hpp | 125 +-- .../ArduinoJson/Variant/VariantFunctions.hpp | 109 ++- .../src/ArduinoJson/Variant/VariantImpl.hpp | 43 +- .../ArduinoJson/Variant/VariantOperators.hpp | 163 ++++ .../src/ArduinoJson/Variant/VariantRef.hpp | 168 ++-- .../VariantShortcuts.hpp | 6 +- .../src/ArduinoJson/Variant/VariantSlot.hpp | 20 +- .../src/ArduinoJson/Variant/VariantTo.hpp | 4 +- .../src/ArduinoJson/compatibility.hpp | 2 +- .../src/ArduinoJson/version.hpp | 8 +- lib/ArduinoJson-6.x/src/CMakeLists.txt | 90 +++ lib/ArduinoJson-6.x/test/JsonArray/isNull.cpp | 34 - .../test/JsonDocument/BasicJsonDocument.cpp | 49 -- .../test/JsonObject/isNull.cpp | 34 - .../test/JsonSerializer/JsonObjectPretty.cpp | 76 -- .../test/JsonVariant/compare.cpp | 453 ----------- lib/ArduinoJson-6.x/test/Misc/CMakeLists.txt | 38 - .../test/Misc/StreamReader.cpp | 33 - .../test/Misc/StringAdapters.cpp | 45 -- .../test/Misc/StringWriter.cpp | 55 -- .../test/MixedConfiguration/cpp11.cpp | 31 - .../MixedConfiguration/use_long_long_0.cpp | 30 - .../MsgPackSerializer/serializeVariant.cpp | 138 ---- .../test/Numbers/parseFloat.cpp | 166 ---- .../test/Numbers/parseInteger.cpp | 67 -- .../test/TextFormatter/CMakeLists.txt | 11 - 431 files changed, 9057 insertions(+), 3994 deletions(-) create mode 100644 lib/ArduinoJson-6.x/.github/lock.yml create mode 100644 lib/ArduinoJson-6.x/component.mk create mode 100644 lib/ArduinoJson-6.x/examples/JsonFilterExample/JsonFilterExample.ino create mode 100644 lib/ArduinoJson-6.x/extras/ArduinoJsonConfig.cmake.in rename lib/ArduinoJson-6.x/{test/CMakeLists.txt => extras/CompileOptions.cmake} (62%) rename lib/ArduinoJson-6.x/{scripts/travis => extras/ci}/arduino.sh (100%) create mode 100644 lib/ArduinoJson-6.x/extras/ci/build.sh rename lib/ArduinoJson-6.x/{scripts/travis => extras/ci}/coverage.sh (65%) rename lib/ArduinoJson-6.x/{scripts/travis => extras/ci}/fuzz.sh (95%) rename lib/ArduinoJson-6.x/{scripts/travis => extras/ci}/platformio.sh (96%) create mode 100644 lib/ArduinoJson-6.x/extras/ci/test.sh rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/CMakeLists.txt (63%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/Makefile (81%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/fuzzer_main.cpp (92%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/json_corpus/.gitignore (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/json_fuzzer.cpp (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/json_seed_corpus/Comments.json (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/json_seed_corpus/EmptyArray.json (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/json_seed_corpus/EmptyObject.json (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/json_seed_corpus/ExcessiveNesting.json (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/json_seed_corpus/IntegerOverflow.json (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/json_seed_corpus/Numbers.json (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/json_seed_corpus/OpenWeatherMap.json (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/json_seed_corpus/Strings.json (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/json_seed_corpus/WeatherUnderground.json (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_corpus/.gitignore (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_fuzzer.cpp (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/array16 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/array32 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/false (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/fixarray (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/fixint_negative (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/fixint_positive (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/fixmap (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/fixstr (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/float32 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/float64 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/int16 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/int32 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/int64 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/int8 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/map16 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/map32 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/nil (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/str16 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/str32 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/str8 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/true (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/uint16 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/uint32 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/uint64 (100%) rename lib/ArduinoJson-6.x/{ => extras}/fuzzing/msgpack_seed_corpus/uint8 (100%) rename lib/ArduinoJson-6.x/{ => extras}/scripts/build-arduino-package.sh (92%) create mode 100644 lib/ArduinoJson-6.x/extras/scripts/build-single-header.sh rename lib/ArduinoJson-6.x/{ => extras}/scripts/publish-particle-library.sh (92%) rename lib/ArduinoJson-6.x/{ => extras}/scripts/publish.sh (79%) rename lib/ArduinoJson-6.x/{ => extras}/scripts/wandbox/JsonGeneratorExample.cpp (97%) rename lib/ArduinoJson-6.x/{ => extras}/scripts/wandbox/JsonParserExample.cpp (97%) rename lib/ArduinoJson-6.x/{ => extras}/scripts/wandbox/MsgPackParserExample.cpp (98%) rename lib/ArduinoJson-6.x/{ => extras}/scripts/wandbox/publish.sh (100%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/CMakeLists.txt rename lib/ArduinoJson-6.x/{test => extras/tests}/ElementProxy/CMakeLists.txt (67%) rename lib/ArduinoJson-6.x/{test => extras/tests}/ElementProxy/add.cpp (71%) rename lib/ArduinoJson-6.x/{test => extras/tests}/ElementProxy/clear.cpp (92%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/ElementProxy/compare.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/ElementProxy/remove.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/ElementProxy/set.cpp (70%) rename lib/ArduinoJson-6.x/{test => extras/tests}/ElementProxy/size.cpp (93%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/ElementProxy/subscript.cpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/FailingBuilds/CMakeLists.txt create mode 100644 lib/ArduinoJson-6.x/extras/tests/FailingBuilds/Issue1189.cpp rename lib/ArduinoJson-6.x/{test/Misc => extras/tests/FailingBuilds}/Issue978.cpp (83%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/FailingBuilds/read_long_long.cpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/FailingBuilds/write_long_long.cpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/Helpers/CustomReader.hpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/Helpers/Stream.h create mode 100644 lib/ArduinoJson-6.x/extras/tests/Helpers/WString.h create mode 100644 lib/ArduinoJson-6.x/extras/tests/Helpers/progmem_emulation.hpp rename lib/ArduinoJson-6.x/{test => extras/tests}/IntegrationTests/CMakeLists.txt (78%) rename lib/ArduinoJson-6.x/{test => extras/tests}/IntegrationTests/gbathree.cpp (99%) rename lib/ArduinoJson-6.x/{test => extras/tests}/IntegrationTests/issue772.cpp (95%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/IntegrationTests/openweathermap.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/IntegrationTests/round_trip.cpp (99%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/CMakeLists.txt (78%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/add.cpp (98%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/copyArray.cpp (67%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/createNested.cpp (92%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/equals.cpp (69%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/get.cpp (88%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/JsonArray/isNull.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/iterator.cpp (64%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/memoryUsage.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/nesting.cpp (94%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/remove.cpp (97%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/size.cpp (94%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/std_string.cpp (94%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/subscript.cpp (89%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonArray/undefined.cpp (94%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/CMakeLists.txt (72%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/DeserializationError.cpp (98%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/array.cpp (60%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/array_static.cpp (95%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/filter.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/incomplete_input.cpp (79%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/input_types.cpp (58%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/invalid_input.cpp (75%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/misc.cpp (75%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/nestingLimit.cpp (99%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/number.cpp (98%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/object.cpp (57%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/object_static.cpp (97%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDeserializer/string.cpp (59%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/JsonDocument/BasicJsonDocument.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDocument/CMakeLists.txt (78%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDocument/DynamicJsonDocument.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDocument/StaticJsonDocument.cpp (93%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDocument/add.cpp (90%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/JsonDocument/compare.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDocument/containsKey.cpp (95%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDocument/createNested.cpp (97%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDocument/isNull.cpp (95%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDocument/nesting.cpp (93%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDocument/remove.cpp (95%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/JsonDocument/shrinkToFit.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDocument/size.cpp (91%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonDocument/subscript.cpp (83%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/CMakeLists.txt (79%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/containsKey.cpp (95%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/copy.cpp (54%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/createNestedArray.cpp (93%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/createNestedObject.cpp (92%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/equals.cpp (78%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/invalid.cpp (94%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/JsonObject/isNull.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/iterator.cpp (78%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/memoryUsage.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/nesting.cpp (95%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/remove.cpp (91%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/size.cpp (95%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/std_string.cpp (98%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonObject/subscript.cpp (97%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonSerializer/CMakeLists.txt (75%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/JsonSerializer/CustomWriter.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonSerializer/JsonArray.cpp (98%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonSerializer/JsonArrayPretty.cpp (55%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonSerializer/JsonObject.cpp (70%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonObjectPretty.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonSerializer/JsonVariant.cpp (64%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonSerializer/misc.cpp (71%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonSerializer/std_stream.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonSerializer/std_string.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/CMakeLists.txt (80%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/add.cpp (88%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/as.cpp (88%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/clear.cpp (86%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/JsonVariant/compare.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/containsKey.cpp (55%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/copy.cpp (71%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/createNested.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/is.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/isnull.cpp (97%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/memoryUsage.cpp (95%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/misc.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/nesting.cpp (94%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/or.cpp (98%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/overflow.cpp (97%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/remove.cpp (94%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/set.cpp (76%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/subscript.cpp (97%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/types.cpp (98%) rename lib/ArduinoJson-6.x/{test => extras/tests}/JsonVariant/undefined.cpp (97%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemberProxy/CMakeLists.txt (70%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemberProxy/add.cpp (92%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemberProxy/clear.cpp (92%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/MemberProxy/compare.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/MemberProxy/containsKey.cpp (94%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemberProxy/remove.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemberProxy/set.cpp (69%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemberProxy/size.cpp (93%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemberProxy/subscript.cpp (66%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemoryPool/CMakeLists.txt (70%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemoryPool/StringBuilder.cpp (87%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemoryPool/allocString.cpp (97%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemoryPool/allocVariant.cpp (94%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemoryPool/clear.cpp (93%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MemoryPool/size.cpp (78%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/Misc/CMakeLists.txt rename lib/ArduinoJson-6.x/{test => extras/tests}/Misc/FloatParts.cpp (96%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/Misc/Readers.cpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/Misc/StringAdapters.cpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/Misc/StringWriter.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/Misc/TypeTraits.cpp (58%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/Misc/Utf16.cpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/Misc/Utf8.cpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/Misc/arithmeticCompare.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/Misc/conflicts.cpp (95%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/Misc/custom_string.hpp rename lib/ArduinoJson-6.x/{test => extras/tests}/Misc/unsigned_char.cpp (74%) rename lib/ArduinoJson-6.x/{test => extras/tests}/Misc/version.cpp (91%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/Misc/weird_strcmp.hpp rename lib/ArduinoJson-6.x/{test => extras/tests}/MixedConfiguration/CMakeLists.txt (64%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/cpp11.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/MixedConfiguration/decode_unicode_0.cpp (100%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MixedConfiguration/decode_unicode_1.cpp (100%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_alignment_0.cpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_alignment_1.cpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_comments_0.cpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_comments_1.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/MixedConfiguration/enable_infinity_0.cpp (100%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MixedConfiguration/enable_infinity_1.cpp (100%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MixedConfiguration/enable_nan_0.cpp (100%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MixedConfiguration/enable_nan_1.cpp (100%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_progmem_1.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/MixedConfiguration/use_double_0.cpp (100%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MixedConfiguration/use_double_1.cpp (100%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/use_long_long_0.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/MixedConfiguration/use_long_long_1.cpp (100%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackDeserializer/CMakeLists.txt (78%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackDeserializer/deserializeArray.cpp (98%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackDeserializer/deserializeObject.cpp (98%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackDeserializer/deserializeStaticVariant.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackDeserializer/deserializeVariant.cpp (99%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackDeserializer/doubleToFloat.cpp (94%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackDeserializer/incompleteInput.cpp (95%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackDeserializer/input_types.cpp (84%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackDeserializer/nestingLimit.cpp (98%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackDeserializer/notSupported.cpp (97%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackSerializer/CMakeLists.txt (73%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackSerializer/destination_types.cpp (96%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackSerializer/measure.cpp (87%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackSerializer/misc.cpp (100%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackSerializer/serializeArray.cpp (97%) rename lib/ArduinoJson-6.x/{test => extras/tests}/MsgPackSerializer/serializeObject.cpp (98%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/serializeVariant.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/Numbers/CMakeLists.txt (66%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/Numbers/parseFloat.cpp create mode 100644 lib/ArduinoJson-6.x/extras/tests/Numbers/parseInteger.cpp rename lib/ArduinoJson-6.x/{test => extras/tests}/Numbers/parseNumber.cpp (94%) create mode 100644 lib/ArduinoJson-6.x/extras/tests/TextFormatter/CMakeLists.txt rename lib/ArduinoJson-6.x/{test => extras/tests}/TextFormatter/writeFloat.cpp (93%) rename lib/ArduinoJson-6.x/{test => extras/tests}/TextFormatter/writeString.cpp (87%) rename lib/ArduinoJson-6.x/{third-party => extras/tests}/catch/CMakeLists.txt (89%) rename lib/ArduinoJson-6.x/{third-party => extras/tests}/catch/catch.cpp (71%) rename lib/ArduinoJson-6.x/{third-party => extras/tests}/catch/catch.hpp (100%) delete mode 100644 lib/ArduinoJson-6.x/scripts/build-single-header.sh delete mode 100644 lib/ArduinoJson-6.x/scripts/create-build-envs.sh delete mode 100644 lib/ArduinoJson-6.x/scripts/oss-fuzz/.gitignore delete mode 100644 lib/ArduinoJson-6.x/scripts/oss-fuzz/Vagrantfile delete mode 100644 lib/ArduinoJson-6.x/scripts/travis/build.sh delete mode 100644 lib/ArduinoJson-6.x/scripts/travis/test.sh delete mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp delete mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/CharPointerReader.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Filter.hpp delete mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/FlashStringReader.hpp delete mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/IteratorReader.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Reader.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/RamReader.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp delete mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/StdStreamReader.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Json/Latch.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Json/Utf16.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Numbers/arithmeticCompare.hpp delete mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Operators/VariantCasts.hpp delete mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Operators/VariantComparisons.hpp delete mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Operators/VariantOperators.hpp delete mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Operators/VariantOr.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Polyfills/pgmspace.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Polyfills/type_traits/declval.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Polyfills/type_traits/is_class.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Polyfills/type_traits/is_convertible.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Polyfills/type_traits/is_enum.hpp delete mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Serialization/DynamicStringWriter.hpp delete mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Serialization/StreamWriter.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Serialization/Writer.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp rename lib/ArduinoJson-6.x/src/ArduinoJson/Serialization/{ => Writers}/DummyWriter.hpp (78%) create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Serialization/Writers/PrintWriter.hpp rename lib/ArduinoJson-6.x/src/ArduinoJson/Serialization/{ => Writers}/StaticStringWriter.hpp (85%) create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Serialization/Writers/StdStreamWriter.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Serialization/Writers/StdStringWriter.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Strings/IsString.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Strings/IsWriteableString.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Strings/StoragePolicy.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Variant/VariantCompare.hpp create mode 100644 lib/ArduinoJson-6.x/src/ArduinoJson/Variant/VariantOperators.hpp rename lib/ArduinoJson-6.x/src/ArduinoJson/{Operators => Variant}/VariantShortcuts.hpp (81%) create mode 100644 lib/ArduinoJson-6.x/src/CMakeLists.txt delete mode 100644 lib/ArduinoJson-6.x/test/JsonArray/isNull.cpp delete mode 100644 lib/ArduinoJson-6.x/test/JsonDocument/BasicJsonDocument.cpp delete mode 100644 lib/ArduinoJson-6.x/test/JsonObject/isNull.cpp delete mode 100644 lib/ArduinoJson-6.x/test/JsonSerializer/JsonObjectPretty.cpp delete mode 100644 lib/ArduinoJson-6.x/test/JsonVariant/compare.cpp delete mode 100644 lib/ArduinoJson-6.x/test/Misc/CMakeLists.txt delete mode 100644 lib/ArduinoJson-6.x/test/Misc/StreamReader.cpp delete mode 100644 lib/ArduinoJson-6.x/test/Misc/StringAdapters.cpp delete mode 100644 lib/ArduinoJson-6.x/test/Misc/StringWriter.cpp delete mode 100644 lib/ArduinoJson-6.x/test/MixedConfiguration/cpp11.cpp delete mode 100644 lib/ArduinoJson-6.x/test/MixedConfiguration/use_long_long_0.cpp delete mode 100644 lib/ArduinoJson-6.x/test/MsgPackSerializer/serializeVariant.cpp delete mode 100644 lib/ArduinoJson-6.x/test/Numbers/parseFloat.cpp delete mode 100644 lib/ArduinoJson-6.x/test/Numbers/parseInteger.cpp delete mode 100644 lib/ArduinoJson-6.x/test/TextFormatter/CMakeLists.txt diff --git a/lib/ArduinoJson-6.x/.clang-format b/lib/ArduinoJson-6.x/.clang-format index 368093632..b375ca280 100644 --- a/lib/ArduinoJson-6.x/.clang-format +++ b/lib/ArduinoJson-6.x/.clang-format @@ -3,3 +3,6 @@ BasedOnStyle: Google Standard: Cpp03 AllowShortFunctionsOnASingleLine: Empty + +# Always break after if to get accurate coverage +AllowShortIfStatementsOnASingleLine: false diff --git a/lib/ArduinoJson-6.x/.github/lock.yml b/lib/ArduinoJson-6.x/.github/lock.yml new file mode 100644 index 000000000..427d4dc3e --- /dev/null +++ b/lib/ArduinoJson-6.x/.github/lock.yml @@ -0,0 +1,7 @@ +# Configuration for Lock Threads - https://github.com/dessant/lock-threads + +# Number of days of inactivity before a closed issue or pull request is locked +daysUntilLock: 30 + +# Comment to post before locking. Set to `false` to disable +lockComment: false diff --git a/lib/ArduinoJson-6.x/.gitignore b/lib/ArduinoJson-6.x/.gitignore index 1071ea6b1..caac53639 100644 --- a/lib/ArduinoJson-6.x/.gitignore +++ b/lib/ArduinoJson-6.x/.gitignore @@ -6,7 +6,7 @@ /sftp-config.json .tags .tags_sorted_by_file -/fuzzing/*_fuzzer -/fuzzing/*_fuzzer.options -/fuzzing/*_fuzzer_seed_corpus.zip +/extras/fuzzing/*_fuzzer +/extras/fuzzing/*_fuzzer.options +/extras/fuzzing/*_fuzzer_seed_corpus.zip .vs/ diff --git a/lib/ArduinoJson-6.x/.travis.yml b/lib/ArduinoJson-6.x/.travis.yml index db996d701..f58bdd3b6 100644 --- a/lib/ArduinoJson-6.x/.travis.yml +++ b/lib/ArduinoJson-6.x/.travis.yml @@ -47,6 +47,11 @@ matrix: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-8'] env: SCRIPT=test _CC=gcc-8 _CXX=g++-8 + - addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: ['g++-9'] + env: SCRIPT=test _CC=gcc-9 _CXX=g++-9 - addons: apt: packages: ['g++-arm-linux-gnueabihf'] @@ -84,12 +89,12 @@ matrix: env: SCRIPT=test _CC=clang-4.0 _CXX=clang++-4.0 - addons: apt: - sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-5.0'] + sources: ['ubuntu-toolchain-r-test'] packages: ['clang-5.0'] env: SCRIPT=test _CC=clang-5.0 _CXX=clang++-5.0 - addons: apt: - sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-6.0'] + sources: ['ubuntu-toolchain-r-test'] packages: ['clang-6.0'] env: SCRIPT=test _CC=clang-6.0 _CXX=clang++-6.0 - addons: @@ -121,12 +126,12 @@ matrix: - env: SCRIPT=platformio BOARD=esp01 - addons: apt: - sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-6.0'] + sources: ['ubuntu-toolchain-r-test'] packages: ['clang-6.0','llvm-6.0'] env: SCRIPT=fuzz CLANG=6.0 cache: directories: - "~/.platformio" - - "fuzzing/json_corpus" - - "fuzzing/msgpack_corpus" -script: scripts/travis/$SCRIPT.sh + - "extras/fuzzing/json_corpus" + - "extras/fuzzing/msgpack_corpus" +script: extras/ci/$SCRIPT.sh diff --git a/lib/ArduinoJson-6.x/ArduinoJson.h b/lib/ArduinoJson-6.x/ArduinoJson.h index d69f47910..1606a3d6a 100644 --- a/lib/ArduinoJson-6.x/ArduinoJson.h +++ b/lib/ArduinoJson-6.x/ArduinoJson.h @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include "src/ArduinoJson.h" diff --git a/lib/ArduinoJson-6.x/CHANGELOG.md b/lib/ArduinoJson-6.x/CHANGELOG.md index df45b6fdb..f3c049f16 100644 --- a/lib/ArduinoJson-6.x/CHANGELOG.md +++ b/lib/ArduinoJson-6.x/CHANGELOG.md @@ -1,6 +1,171 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Added comparisons (`>`, `>=`, `==`, `!=`, `<`, and `<=`) between `JsonVariant`s + +v6.15.2 (2020-05-15) +------- + +* CMake: don't build tests when imported in another project +* CMake: made project arch-independent +* Visual Studio: fixed error C2766 with flag `/Zc:__cplusplus` (issue #1250) +* Added support for `JsonDocument` to `copyArray()` (issue #1255) +* Added support for `enum`s in `as()` and `is()` (issue #1256) +* Added `JsonVariant` as an input type for `deserializeXxx()` + For example, you can do: `deserializeJson(doc2, doc1["payload"])` +* Break the build if using 64-bit integers with ARDUINOJSON_USE_LONG_LONG==0 + +v6.15.1 (2020-04-08) +------- + +* Fixed "maybe-uninitialized" warning (issue #1217) +* Fixed "statement is unreachable" warning on IAR (issue #1233) +* Fixed "pointless integer comparison" warning on IAR (issue #1233) +* Added CMake "install" target (issue #1209) +* Disabled alignment on AVR (issue #1231) + +v6.15.0 (2020-03-22) +------- + +* Added `DeserializationOption::Filter` (issue #959) +* Added example `JsonFilterExample.ino` +* Changed the array subscript operator to automatically add missing elements +* Fixed "deprecated-copy" warning on GCC 9 (fixes #1184) +* Fixed `MemberProxy::set(char[])` not duplicating the string (issue #1191) +* Fixed enums serialized as booleans (issue #1197) +* Fixed incorrect string comparison on some platforms (issue #1198) +* Added move-constructor and move-assignment to `BasicJsonDocument` +* Added `BasicJsonDocument::garbageCollect()` (issue #1195) +* Added `StaticJsonDocument::garbageCollect()` +* Changed copy-constructor of `BasicJsonDocument` to preserve the capacity of the source. +* Removed copy-constructor of `JsonDocument` (issue #1189) + +> ### BREAKING CHANGES +> +> #### Copy-constructor of `BasicJsonDocument` +> +> In previous versions, the copy constructor of `BasicJsonDocument` looked at the source's `memoryUsage()` to choose its capacity. +> Now, the copy constructor of `BasicJsonDocument` uses the same capacity as the source. +> +> Example: +> +> ```c++ +> DynamicJsonDocument doc1(64); +> doc1.set(String("example")); +> +> DynamicJsonDocument doc2 = doc1; +> Serial.print(doc2.capacity()); // 8 with ArduinoJson 6.14 +> // 64 with ArduinoJson 6.15 +> ``` +> +> I made this change to get consistent results between copy-constructor and move-constructor, and whether RVO applies or not. +> +> If you use the copy-constructor to optimize your documents, you can use `garbageCollect()` or `shrinkToFit()` instead. +> +> #### Copy-constructor of `JsonDocument` +> +> In previous versions, it was possible to create a function that take a `JsonDocument` by value. +> +> ```c++ +> void myFunction(JsonDocument doc) {} +> ``` +> +> This function gives the wrong clues because it doesn't receive a copy of the `JsonDocument`, only a sliced version. +> It worked because the copy constructor copied the internal pointers, but it was an accident. +> +> From now, if you need to pass a `JsonDocument` to a function, you must use a reference: +> +> ```c++ +> void myFunction(JsonDocument& doc) {} +> ``` + +v6.14.1 (2020-01-27) +------- + +* Fixed regression in UTF16 decoding (issue #1173) +* Fixed `containsKey()` on `JsonVariantConst` +* Added `getElement()` and `getMember()` to `JsonVariantConst` + +v6.14.0 (2020-01-16) +------- + +* Added `BasicJsonDocument::shrinkToFit()` +* Added support of `uint8_t` for `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` (issue #1142) +* Added `ARDUINOJSON_ENABLE_COMMENTS` to enable support for comments (defaults to 0) +* Auto enable support for `std::string` and `std::stream` on modern compilers (issue #1156) + (No need to define `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_STD_STREAM` anymore) +* Improved decoding of UTF-16 surrogate pairs (PR #1157 by @kaysievers) + (ArduinoJson now produces standard UTF-8 instead of CESU-8) +* Added `measureJson`, `measureJsonPretty`, and `measureMsgPack` to `keywords.txt` + (This file is used for syntax highlighting in the Arduino IDE) +* Fixed `variant.is()` +* Fixed value returned by `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String` +* Improved speed of `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String` + +> ### BREAKING CHANGES +> +> #### Comments +> +> Support for comments in input is now optional and disabled by default. +> +> If you need support for comments, you must defined `ARDUINOJSON_ENABLE_COMMENTS` to `1`; otherwise, you'll receive `InvalidInput` errors. +> +> ```c++ +> #define ARDUINOJSON_ENABLE_COMMENTS 1 +> #include +> ``` + +v6.13.0 (2019-11-01) +------- + +* Added support for custom writer/reader classes (issue #1088) +* Added conversion from `JsonArray` and `JsonObject` to `bool`, to be consistent with `JsonVariant` +* Fixed `deserializeJson()` when input contains duplicate keys (issue #1095) +* Improved `deserializeMsgPack()` speed by reading several bytes at once +* Added detection of Atmel AVR8/GNU C Compiler (issue #1112) +* Fixed deserializer that stopped reading at the first `0xFF` (PR #1118 by @mikee47) +* Fixed dangling reference in copies of `MemberProxy` and `ElementProxy` (issue #1120) + +v6.12.0 (2019-09-05) +------- + +* Use absolute instead of relative includes (issue #1072) +* Changed `JsonVariant::as()` to return `true` for any non-null value (issue #1005) +* Moved ancillary files to `extras/` (issue #1011) + +v6.11.5 (2019-08-23) +------- + +* Added fallback implementations of `strlen_P()`, `strncmp_P()`, `strcmp_P()`, and `memcpy_P()` (issue #1073) + +v6.11.4 (2019-08-12) +------- + +* Added `measureJson()` to the `ArduinoJson` namespace (PR #1069 by @nomis) +* Added support for `basic_string` (issue #1045) +* Fixed example `JsonConfigFile.ino` for ESP8266 +* Include `Arduino.h` if `ARDUINO` is defined (PR #1071 by @nomis) + +v6.11.3 (2019-07-22) +------- + +* Added operators `==` and `!=` for `JsonDocument`, `ElementProxy`, and `MemberProxy` +* Fixed comparison of `JsonVariant` when one contains a linked string and the other contains an owned string (issue #1051) + +v6.11.2 (2019-07-08) +------- + +* Fixed assignment of `JsonDocument` to `JsonVariant` (issue #1023) +* Fix invalid conversion error on Particle Argon (issue #1035) + +v6.11.1 (2019-06-21) +------- + +* Fixed `serialized()` not working with Flash strings (issue #1030) + v6.11.0 (2019-05-26) ------- diff --git a/lib/ArduinoJson-6.x/CMakeLists.txt b/lib/ArduinoJson-6.x/CMakeLists.txt index 1ef4459f9..d854fdb99 100644 --- a/lib/ArduinoJson-6.x/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/CMakeLists.txt @@ -1,22 +1,19 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License cmake_minimum_required(VERSION 3.0) -project(ArduinoJson) -enable_testing() +project(ArduinoJson VERSION 6.15.1) -add_definitions(-DARDUINOJSON_DEBUG) -if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") - add_compile_options(-g -O0) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + include(CTest) endif() -if(${COVERAGE}) - set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage") -endif() +add_subdirectory(src) -include_directories(${CMAKE_CURRENT_LIST_DIR}/src) -add_subdirectory(third-party/catch) -add_subdirectory(test) -add_subdirectory(fuzzing) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) + include(extras/CompileOptions.cmake) + add_subdirectory(extras/tests) + add_subdirectory(extras/fuzzing) +endif() diff --git a/lib/ArduinoJson-6.x/LICENSE.md b/lib/ArduinoJson-6.x/LICENSE.md index 3805c383e..30cef0992 100644 --- a/lib/ArduinoJson-6.x/LICENSE.md +++ b/lib/ArduinoJson-6.x/LICENSE.md @@ -1,7 +1,7 @@ The MIT License (MIT) --------------------- -Copyright © 2014-2019 Benoit BLANCHON +Copyright © 2014-2020 Benoit BLANCHON Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/lib/ArduinoJson-6.x/README.md b/lib/ArduinoJson-6.x/README.md index 162e85a13..ae2e2960f 100644 --- a/lib/ArduinoJson-6.x/README.md +++ b/lib/ArduinoJson-6.x/README.md @@ -2,58 +2,92 @@ --- -[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.11.0)](https://www.ardu-badge.com/ArduinoJson/6.11.0) +[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.15.2)](https://www.ardu-badge.com/ArduinoJson/6.15.2) [![Build Status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) [![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=6.x)](https://travis-ci.org/bblanchon/ArduinoJson) +[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) [![Coverage Status](https://coveralls.io/repos/github/bblanchon/ArduinoJson/badge.svg?branch=6.x)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) -[![Star this project](http://githubbadges.com/star.svg?user=bblanchon&repo=ArduinoJson&style=flat&color=fff&background=007ec6)](https://github.com/bblanchon/ArduinoJson) +[![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat)](https://github.com/bblanchon/ArduinoJson/stargazers) ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). ## Features -* JSON decoding (comments are supported) -* JSON encoding (with optional indentation) -* MessagePack -* Elegant API, easy to use -* Fixed memory allocation (zero malloc) -* No data duplication (zero copy) -* Portable (written in C++98, can be used in any C++ project) -* Self-contained (no external dependency) -* Small footprint -* Input and output streams -* [100% code coverage](https://coveralls.io/github/bblanchon/ArduinoJson) -* [Header-only library](https://en.wikipedia.org/wiki/Header-only) -* [MIT License](https://en.wikipedia.org/wiki/MIT_License) -* [Comprehensive documentation](https://arduinojson.org?utm_source=github&utm_medium=readme) - -## Compatibility - -ArduinoJson works on the following hardware: - -* Arduino boards: [Uno](https://www.arduino.cc/en/Main/ArduinoBoardUno), [Due](https://www.arduino.cc/en/Main/ArduinoBoardDue), [Mini](https://www.arduino.cc/en/Main/ArduinoBoardMini), [Micro](https://www.arduino.cc/en/Main/ArduinoBoardMicro), [Yun](https://www.arduino.cc/en/Main/ArduinoBoardYun)... -* Espressif chips: [ESP8266](https://en.wikipedia.org/wiki/ESP8266), [ESP32](https://en.wikipedia.org/wiki/ESP32) -* WeMos boards: [D1](https://wiki.wemos.cc/products:d1:d1), [D1 mini](https://wiki.wemos.cc/products:d1:d1_mini), ... -* RedBearLab boards: [BLE Nano](http://redbearlab.com/blenano/), [BLE Mini](http://redbearlab.com/blemini/), [WiFi Micro](https://redbear.cc/product/wifi/wifi-micro.html), [LOLIN32](https://wiki.wemos.cc/products:lolin32:lolin32)... -* [Teensy](https://www.pjrc.com/teensy/) boards -* Intel boards: Edison, Galileo... -* Particle boards: [Photon](https://www.particle.io/products/hardware/photon-wifi-dev-kit), [Electron](https://www.particle.io/products/hardware/electron-cellular-dev-kit)... -* Texas Instruments boards: [MSP430](http://www.ti.com/microcontrollers/msp430-ultra-low-power-mcus/overview/overview.html)... - -ArduinoJson compiles with zero warning on the following compilers, IDEs, and platforms: - -* [Arduino IDE](https://www.arduino.cc/en/Main/Software) -* [PlatformIO](http://platformio.org/) -* [Energia](http://energia.nu/) -* [Visual Micro](http://www.visualmicro.com/) -* [Atmel Studio](http://www.atmel.com/microsite/atmel-studio/) -* [IAR Embedded Workbench](https://www.iar.com/iar-embedded-workbench/) -* [Atollic TrueSTUDIO](https://atollic.com/truestudio/) -* [Keil uVision](http://www.keil.com/) -* [MPLAB X IDE](http://www.microchip.com/mplab/mplab-x-ide) -* [GCC](https://gcc.gnu.org/) -* [Clang](https://clang.llvm.org/) -* [Visual Studio](https://www.visualstudio.com/) +* [JSON deserialization](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme) + * [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/?utm_source=github&utm_medium=readme) + * [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme) + * [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/?utm_source=github&utm_medium=readme) + * [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#filtering) + * Supports single quotes as a string delimiter + * Compatible with NDJSON and JSON Lines +* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme) + * [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme) + * [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/?utm_source=github&utm_medium=readme) +* [MessagePack serialization](https://arduinojson.org/v6/api/msgpack/serializemsgpack/?utm_source=github&utm_medium=readme) +* [MessagePack deserialization](https://arduinojson.org/v6/api/msgpack/deserializemsgpack/?utm_source=github&utm_medium=readme) +* Efficient + * [Twice smaller than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme) + * [Almost 10% faster than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme) + * [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme) + * [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/?utm_source=github&utm_medium=readme) + * [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/?utm_source=github&utm_medium=readme) +* Versatile + * [Supports custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/?utm_source=github&utm_medium=readme) + * Supports [Arduino's `String`](https://arduinojson.org/v6/api/config/enable_arduino_string/) and [STL's `std::string`](https://arduinojson.org/v6/api/config/enable_std_string/?utm_source=github&utm_medium=readme) + * Supports Arduino's `Stream` and [STL's `std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/?utm_source=github&utm_medium=readme) + * [Supports Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/?utm_source=github&utm_medium=readme) + * Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme#custom-writer) +* Portable + * Usable on any C++ project (not limited to Arduino) + * Compatible with C++98 + * Zero warnings with `-Wall -Wextra -pedantic` and `/W4` + * [Header-only library](https://en.wikipedia.org/wiki/Header-only) + * Works with virtually any board + * Arduino boards: [Uno](https://amzn.to/38aL2ik), [Due](https://amzn.to/36YkWi2), [Micro](https://amzn.to/35WkdwG), [Nano](https://amzn.to/2QTvwRX), [Mega](https://amzn.to/36XWhuf), [Yun](https://amzn.to/30odURc), [Leonardo](https://amzn.to/36XWjlR)... + * Espressif chips: [ESP8266](https://amzn.to/36YluV8), [ESP32](https://amzn.to/2G4pRCB) + * Lolin (WeMos) boards: [D1 mini](https://amzn.to/2QUpz7q), [D1 Mini Pro](https://amzn.to/36UsGSs)... + * Teensy boards: [4.0](https://amzn.to/30ljXGq), [3.2](https://amzn.to/2FT0EuC), [2.0](https://amzn.to/2QXUMXj) + * Particle boards: [Argon](https://amzn.to/2FQHa9X), [Boron](https://amzn.to/36WgLUd), [Electron](https://amzn.to/30vEc4k), [Photon](https://amzn.to/387F9Cd)... + * Texas Instruments boards: [MSP430](https://amzn.to/30nJWgg)... + * Tested on all major development environments + * [Arduino IDE](https://www.arduino.cc/en/Main/Software) + * [Atmel Studio](http://www.atmel.com/microsite/atmel-studio/) + * [Atollic TrueSTUDIO](https://atollic.com/truestudio/) + * [Energia](http://energia.nu/) + * [IAR Embedded Workbench](https://www.iar.com/iar-embedded-workbench/) + * [Keil uVision](http://www.keil.com/) + * [MPLAB X IDE](http://www.microchip.com/mplab/mplab-x-ide) + * [PlatformIO](http://platformio.org/) + * [Sloeber plugin for Eclipse](https://eclipse.baeyens.it/) + * [Visual Micro](http://www.visualmicro.com/) + * [Visual Studio](https://www.visualstudio.com/) + * [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/t7KP7I6dVuLhqzDl) + * [CMake friendly](https://arduinojson.org/v6/how-to/use-arduinojson-with-cmake/?utm_source=github&utm_medium=readme) +* Well designed + * [Elegant API](http://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme) + * [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety) + * Self-contained (no external dependency) + * `const` friendly + * [`for` friendly](https://arduinojson.org/v6/api/jsonobject/begin_end/?utm_source=github&utm_medium=readme) + * [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming) + * Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/?utm_source=github&utm_medium=readme#integer-overflows) +* Well tested + * [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) + * Continuously tested on + * [Visual Studio 2010, 2012, 2013, 2015, 2017, 2019](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) + * [GCC 4.4, 4.6, 4.7, 4.8, 4.9, 5, 6, 7, 8](https://travis-ci.org/bblanchon/ArduinoJson) + * [Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8](https://travis-ci.org/bblanchon/ArduinoJson) + * [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) +* Well documented + * [Tutorials](https://arduinojson.org/v6/doc/deserialization/?utm_source=github&utm_medium=readme) + * [Examples](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme) + * [How-tos](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme) + * [FAQ](https://arduinojson.org/v6/faq/?utm_source=github&utm_medium=readme) + * [Book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme) +* Vibrant user community + * Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories) and [PlatformIO](https://platformio.org/lib/search) + * [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson) + * [Responsive support](https://github.com/bblanchon/ArduinoJson/issues?q=is%3Aissue+is%3Aclosed) ## Quickstart @@ -84,10 +118,8 @@ DynamicJsonDocument doc(1024); doc["sensor"] = "gps"; doc["time"] = 1351824120; - -JsonArray data = doc.createNestedArray("data"); -data.add(48.756080); -data.add(2.302038); +doc["data"][0] = 48.756080; +doc["data"][1] = 2.302038; serializeJson(doc, Serial); // This prints: @@ -96,18 +128,9 @@ serializeJson(doc, Serial); See the [tutorial on arduinojson.org](https://arduinojson.org/doc/encoding/?utm_source=github&utm_medium=readme) -## Documentation - -The documentation is available on [arduinojson.org](https://arduinojson.org/?utm_source=github&utm_medium=readme), here are some shortcuts: - -* The [Examples](https://arduinojson.org/example/?utm_source=github&utm_medium=readme) show how to use the library in various situations. -* The [API Reference](https://arduinojson.org/api/?utm_source=github&utm_medium=readme) contains the description of each class and function. -* The [FAQ](https://arduinojson.org/faq/?utm_source=github&utm_medium=readme) has the answer to virtually every question. -* The [ArduinoJson Assistant](https://arduinojson.org/assistant/?utm_source=github&utm_medium=readme) writes programs for you! - ---- +## Support the project Do you like this library? Please [star this project on GitHub](https://github.com/bblanchon/ArduinoJson/stargazers)! -What? You don't like it but you *love* it? -We don't take donations anymore, but [we sell a book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme), so you can help and learn at the same time! +What? You don't like it but you *love* it? +We don't take donations anymore, but [we sell a book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme), so you can help and learn at the same time. diff --git a/lib/ArduinoJson-6.x/appveyor.yml b/lib/ArduinoJson-6.x/appveyor.yml index 2a6fecba7..ca4bc858c 100644 --- a/lib/ArduinoJson-6.x/appveyor.yml +++ b/lib/ArduinoJson-6.x/appveyor.yml @@ -1,6 +1,8 @@ -version: 6.11.0.{build} +version: 6.15.2.{build} environment: matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 + CMAKE_GENERATOR: Visual Studio 16 2019 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 CMAKE_GENERATOR: Visual Studio 15 2017 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 diff --git a/lib/ArduinoJson-6.x/component.mk b/lib/ArduinoJson-6.x/component.mk new file mode 100644 index 000000000..dc25d1c0e --- /dev/null +++ b/lib/ArduinoJson-6.x/component.mk @@ -0,0 +1 @@ +COMPONENT_ADD_INCLUDEDIRS := src diff --git a/lib/ArduinoJson-6.x/examples/JsonConfigFile/JsonConfigFile.ino b/lib/ArduinoJson-6.x/examples/JsonConfigFile/JsonConfigFile.ino index 675da498b..9c6bf41ea 100644 --- a/lib/ArduinoJson-6.x/examples/JsonConfigFile/JsonConfigFile.ino +++ b/lib/ArduinoJson-6.x/examples/JsonConfigFile/JsonConfigFile.ino @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows how to store your project configuration in a file. @@ -11,6 +11,12 @@ // "port": 2731 // } // +// To run this program, you need an SD card connected to the SPI bus as follows: +// * MOSI <-> pin 11 +// * MISO <-> pin 12 +// * CLK <-> pin 13 +// * CS <-> pin 4 +// // https://arduinojson.org/v6/example/config/ #include @@ -111,7 +117,8 @@ void setup() { while (!Serial) continue; // Initialize SD library - while (!SD.begin()) { + const int chipSelect = 4; + while (!SD.begin(chipSelect)) { Serial.println(F("Failed to initialize SD library")); delay(1000); } diff --git a/lib/ArduinoJson-6.x/examples/JsonFilterExample/JsonFilterExample.ino b/lib/ArduinoJson-6.x/examples/JsonFilterExample/JsonFilterExample.ino new file mode 100644 index 000000000..9de2a4903 --- /dev/null +++ b/lib/ArduinoJson-6.x/examples/JsonFilterExample/JsonFilterExample.ino @@ -0,0 +1,63 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License +// +// This example shows how to use DeserializationOpion::Filter +// +// https://arduinojson.org/v6/example/filter/ + +#include + +void setup() { + // Initialize serial port + Serial.begin(9600); + while (!Serial) continue; + + // The huge input: an extract from OpenWeatherMap response + const __FlashStringHelper* input_json = F( + "{\"cod\":\"200\",\"message\":0,\"list\":[{\"dt\":1581498000,\"main\":{" + "\"temp\":3.23,\"feels_like\":-3.63,\"temp_min\":3.23,\"temp_max\":4.62," + "\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1010,\"humidity\":" + "58,\"temp_kf\":-1.39},\"weather\":[{\"id\":800,\"main\":\"Clear\"," + "\"description\":\"clear " + "sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":0},\"wind\":{\"speed\":6." + "19,\"deg\":266},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-12 " + "09:00:00\"},{\"dt\":1581508800,\"main\":{\"temp\":6.09,\"feels_like\":-" + "1.07,\"temp_min\":6.09,\"temp_max\":7.13,\"pressure\":1015,\"sea_" + "level\":1015,\"grnd_level\":1011,\"humidity\":48,\"temp_kf\":-1.04}," + "\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear " + "sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":9},\"wind\":{\"speed\":6." + "64,\"deg\":268},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-12 " + "12:00:00\"}],\"city\":{\"id\":2643743,\"name\":\"London\",\"coord\":{" + "\"lat\":51.5085,\"lon\":-0.1257},\"country\":\"GB\",\"population\":" + "1000000,\"timezone\":0,\"sunrise\":1581492085,\"sunset\":1581527294}}"); + + // The filter: it contains "true" for each value we want to keep + StaticJsonDocument<200> filter; + filter["list"][0]["dt"] = true; + filter["list"][0]["main"]["temp"] = true; + + // Deserialize the document + StaticJsonDocument<400> doc; + deserializeJson(doc, input_json, DeserializationOption::Filter(filter)); + + // Print the result + serializeJsonPretty(doc, Serial); +} + +void loop() { + // not used in this example +} + +// See also +// -------- +// +// https://arduinojson.org/ contains the documentation for all the functions +// used above. It also includes an FAQ that will help you solve any +// deserialization problem. +// +// The book "Mastering ArduinoJson" contains a tutorial on deserialization. +// It begins with a simple example, like the one above, and then adds more +// features like deserializing directly from a file or an HTTP request. +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/lib/ArduinoJson-6.x/examples/JsonGeneratorExample/JsonGeneratorExample.ino b/lib/ArduinoJson-6.x/examples/JsonGeneratorExample/JsonGeneratorExample.ino index d43de25cb..ca4a4f112 100644 --- a/lib/ArduinoJson-6.x/examples/JsonGeneratorExample/JsonGeneratorExample.ino +++ b/lib/ArduinoJson-6.x/examples/JsonGeneratorExample/JsonGeneratorExample.ino @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows how to generate a JSON document with ArduinoJson. diff --git a/lib/ArduinoJson-6.x/examples/JsonHttpClient/JsonHttpClient.ino b/lib/ArduinoJson-6.x/examples/JsonHttpClient/JsonHttpClient.ino index 57301ca41..5c894c44a 100644 --- a/lib/ArduinoJson-6.x/examples/JsonHttpClient/JsonHttpClient.ino +++ b/lib/ArduinoJson-6.x/examples/JsonHttpClient/JsonHttpClient.ino @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows how to parse a JSON document in an HTTP response. diff --git a/lib/ArduinoJson-6.x/examples/JsonParserExample/JsonParserExample.ino b/lib/ArduinoJson-6.x/examples/JsonParserExample/JsonParserExample.ino index 11ab1fdf9..d6c82b432 100644 --- a/lib/ArduinoJson-6.x/examples/JsonParserExample/JsonParserExample.ino +++ b/lib/ArduinoJson-6.x/examples/JsonParserExample/JsonParserExample.ino @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows how to deserialize a JSON document with ArduinoJson. diff --git a/lib/ArduinoJson-6.x/examples/JsonServer/JsonServer.ino b/lib/ArduinoJson-6.x/examples/JsonServer/JsonServer.ino index 9d2cc58a4..7c9d4eae6 100644 --- a/lib/ArduinoJson-6.x/examples/JsonServer/JsonServer.ino +++ b/lib/ArduinoJson-6.x/examples/JsonServer/JsonServer.ino @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows how to implement an HTTP server that sends a JSON document diff --git a/lib/ArduinoJson-6.x/examples/JsonUdpBeacon/JsonUdpBeacon.ino b/lib/ArduinoJson-6.x/examples/JsonUdpBeacon/JsonUdpBeacon.ino index 0514fe4b7..df56d9250 100644 --- a/lib/ArduinoJson-6.x/examples/JsonUdpBeacon/JsonUdpBeacon.ino +++ b/lib/ArduinoJson-6.x/examples/JsonUdpBeacon/JsonUdpBeacon.ino @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows how to send a JSON document to a UDP socket. diff --git a/lib/ArduinoJson-6.x/examples/MsgPackParser/MsgPackParser.ino b/lib/ArduinoJson-6.x/examples/MsgPackParser/MsgPackParser.ino index d149e3977..2596cc5eb 100644 --- a/lib/ArduinoJson-6.x/examples/MsgPackParser/MsgPackParser.ino +++ b/lib/ArduinoJson-6.x/examples/MsgPackParser/MsgPackParser.ino @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows how to deserialize a MessagePack document with diff --git a/lib/ArduinoJson-6.x/examples/ProgmemExample/ProgmemExample.ino b/lib/ArduinoJson-6.x/examples/ProgmemExample/ProgmemExample.ino index 310a820cc..40ee44c9f 100644 --- a/lib/ArduinoJson-6.x/examples/ProgmemExample/ProgmemExample.ino +++ b/lib/ArduinoJson-6.x/examples/ProgmemExample/ProgmemExample.ino @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows the different ways you can use Flash strings with diff --git a/lib/ArduinoJson-6.x/examples/StringExample/StringExample.ino b/lib/ArduinoJson-6.x/examples/StringExample/StringExample.ino index 040f8e463..46fc82d43 100644 --- a/lib/ArduinoJson-6.x/examples/StringExample/StringExample.ino +++ b/lib/ArduinoJson-6.x/examples/StringExample/StringExample.ino @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows the different ways you can use String with ArduinoJson. diff --git a/lib/ArduinoJson-6.x/extras/ArduinoJsonConfig.cmake.in b/lib/ArduinoJson-6.x/extras/ArduinoJsonConfig.cmake.in new file mode 100644 index 000000000..9c15f36a2 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/ArduinoJsonConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/lib/ArduinoJson-6.x/test/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/CompileOptions.cmake similarity index 62% rename from lib/ArduinoJson-6.x/test/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/CompileOptions.cmake index ff374b6ea..a3c87b8af 100644 --- a/lib/ArduinoJson-6.x/test/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/CompileOptions.cmake @@ -1,7 +1,3 @@ -# ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 -# MIT License - if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") add_compile_options( -pedantic @@ -32,9 +28,20 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") -std=c++98 ) endif() + + if(${COVERAGE}) + set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage") + endif() + endif() -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) + add_compile_options(-g -Og) + else() + add_compile_options(-g -O0) + endif() + add_compile_options( -Wstrict-null-sentinel -Wno-vla # Allow VLA in tests @@ -62,27 +69,32 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") ) endif() +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) + add_compile_options(-g -Og) + else() + add_compile_options(-g -O0) + endif() +endif() + +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) + add_compile_options(-g -Og) + else() + add_compile_options(-g -O0) + endif() +endif() + if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_compile_options( /W4 # Set warning level /WX # Treats all compiler warnings as errors. ) -endif() -add_subdirectory(ElementProxy) -add_subdirectory(IntegrationTests) -add_subdirectory(JsonArray) -add_subdirectory(JsonDeserializer) -add_subdirectory(JsonDocument) -add_subdirectory(JsonObject) -add_subdirectory(JsonSerializer) -add_subdirectory(JsonVariant) -add_subdirectory(MemberProxy) -add_subdirectory(MemoryPool) -add_subdirectory(Misc) -add_subdirectory(MixedConfiguration) -add_subdirectory(MsgPackDeserializer) -add_subdirectory(MsgPackSerializer) -add_subdirectory(Numbers) -add_subdirectory(TextFormatter) + if (NOT MSVC_VERSION LESS 1910) # >= Visual Studio 2017 + add_compile_options( + /Zc:__cplusplus # Enable updated __cplusplus macro + ) + endif() +endif() diff --git a/lib/ArduinoJson-6.x/scripts/travis/arduino.sh b/lib/ArduinoJson-6.x/extras/ci/arduino.sh similarity index 100% rename from lib/ArduinoJson-6.x/scripts/travis/arduino.sh rename to lib/ArduinoJson-6.x/extras/ci/arduino.sh diff --git a/lib/ArduinoJson-6.x/extras/ci/build.sh b/lib/ArduinoJson-6.x/extras/ci/build.sh new file mode 100644 index 000000000..4741963bd --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/ci/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh -ex + +export CC="$_CC" +export CXX="$_CXX" + +cmake -DCMAKE_BUILD_TYPE=Release . +cmake --build . diff --git a/lib/ArduinoJson-6.x/scripts/travis/coverage.sh b/lib/ArduinoJson-6.x/extras/ci/coverage.sh similarity index 65% rename from lib/ArduinoJson-6.x/scripts/travis/coverage.sh rename to lib/ArduinoJson-6.x/extras/ci/coverage.sh index f90c0fb73..3e155b92d 100644 --- a/lib/ArduinoJson-6.x/scripts/travis/coverage.sh +++ b/lib/ArduinoJson-6.x/extras/ci/coverage.sh @@ -5,4 +5,5 @@ make make test pip install --user cpp-coveralls 'requests[security]' -coveralls --exclude third-party --gcov-options '\-lp'; fi +pwd +coveralls --include 'src' --gcov-options '\-lp' diff --git a/lib/ArduinoJson-6.x/scripts/travis/fuzz.sh b/lib/ArduinoJson-6.x/extras/ci/fuzz.sh similarity index 95% rename from lib/ArduinoJson-6.x/scripts/travis/fuzz.sh rename to lib/ArduinoJson-6.x/extras/ci/fuzz.sh index 1d4e32d91..ba3385e94 100644 --- a/lib/ArduinoJson-6.x/scripts/travis/fuzz.sh +++ b/lib/ArduinoJson-6.x/extras/ci/fuzz.sh @@ -2,7 +2,7 @@ ROOT_DIR=$(dirname $0)/../../ INCLUDE_DIR=${ROOT_DIR}/src/ -FUZZING_DIR=${ROOT_DIR}/fuzzing/ +FUZZING_DIR=${ROOT_DIR}/extras/fuzzing/ CXXFLAGS="-g -fprofile-instr-generate -fcoverage-mapping -fsanitize=address,undefined,fuzzer -fno-sanitize-recover=all" fuzz() { diff --git a/lib/ArduinoJson-6.x/scripts/travis/platformio.sh b/lib/ArduinoJson-6.x/extras/ci/platformio.sh similarity index 96% rename from lib/ArduinoJson-6.x/scripts/travis/platformio.sh rename to lib/ArduinoJson-6.x/extras/ci/platformio.sh index 518262529..905e1bb12 100644 --- a/lib/ArduinoJson-6.x/scripts/travis/platformio.sh +++ b/lib/ArduinoJson-6.x/extras/ci/platformio.sh @@ -2,8 +2,6 @@ pip install --user platformio -rm -r test - case $BOARD in uno) platformio lib install 868 # SD library diff --git a/lib/ArduinoJson-6.x/extras/ci/test.sh b/lib/ArduinoJson-6.x/extras/ci/test.sh new file mode 100644 index 000000000..ce76eb698 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/ci/test.sh @@ -0,0 +1,10 @@ +#!/bin/sh -ex + +export CC="$_CC" +export CXX="$_CXX" + +[ -n "$SANITIZE" ] && export CXXFLAGS="-fsanitize=$SANITIZE" + +cmake -DCMAKE_BUILD_TYPE=Debug . +cmake --build . +ctest --output-on-failure . diff --git a/lib/ArduinoJson-6.x/fuzzing/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/fuzzing/CMakeLists.txt similarity index 63% rename from lib/ArduinoJson-6.x/fuzzing/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/fuzzing/CMakeLists.txt index 5d5a268a5..f890786a4 100644 --- a/lib/ArduinoJson-6.x/fuzzing/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/fuzzing/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License if(MSVC) @@ -10,8 +10,14 @@ add_executable(msgpack_fuzzer msgpack_fuzzer.cpp fuzzer_main.cpp ) +target_link_libraries(msgpack_fuzzer + ArduinoJson +) add_executable(json_fuzzer json_fuzzer.cpp fuzzer_main.cpp ) +target_link_libraries(json_fuzzer + ArduinoJson +) diff --git a/lib/ArduinoJson-6.x/fuzzing/Makefile b/lib/ArduinoJson-6.x/extras/fuzzing/Makefile similarity index 81% rename from lib/ArduinoJson-6.x/fuzzing/Makefile rename to lib/ArduinoJson-6.x/extras/fuzzing/Makefile index ce4ede322..d3c574e18 100644 --- a/lib/ArduinoJson-6.x/fuzzing/Makefile +++ b/lib/ArduinoJson-6.x/extras/fuzzing/Makefile @@ -1,6 +1,6 @@ # CAUTION: this file is invoked by https://github.com/google/oss-fuzz -CXXFLAGS += -I../src -DARDUINOJSON_DEBUG +CXXFLAGS += -I../../src -DARDUINOJSON_DEBUG=1 all: \ $(OUT)/json_fuzzer \ @@ -10,7 +10,7 @@ all: \ $(OUT)/msgpack_fuzzer_seed_corpus.zip \ $(OUT)/msgpack_fuzzer.options -$(OUT)/%_fuzzer: %_fuzzer.cpp $(shell find ../src -type f) +$(OUT)/%_fuzzer: %_fuzzer.cpp $(shell find ../../src -type f) $(CXX) $(CXXFLAGS) $< -o$@ $(LIB_FUZZING_ENGINE) $(OUT)/%_fuzzer_seed_corpus.zip: %_seed_corpus/* diff --git a/lib/ArduinoJson-6.x/fuzzing/fuzzer_main.cpp b/lib/ArduinoJson-6.x/extras/fuzzing/fuzzer_main.cpp similarity index 92% rename from lib/ArduinoJson-6.x/fuzzing/fuzzer_main.cpp rename to lib/ArduinoJson-6.x/extras/fuzzing/fuzzer_main.cpp index 5dc7916a3..22c90a467 100644 --- a/lib/ArduinoJson-6.x/fuzzing/fuzzer_main.cpp +++ b/lib/ArduinoJson-6.x/extras/fuzzing/fuzzer_main.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // This file is NOT use by Google's OSS fuzz @@ -21,7 +21,7 @@ std::vector read(const char* path) { } fseek(f, 0, SEEK_END); - size_t size = ftell(f); + size_t size = static_cast(ftell(f)); fseek(f, 0, SEEK_SET); std::vector buffer(size); diff --git a/lib/ArduinoJson-6.x/fuzzing/json_corpus/.gitignore b/lib/ArduinoJson-6.x/extras/fuzzing/json_corpus/.gitignore similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/json_corpus/.gitignore rename to lib/ArduinoJson-6.x/extras/fuzzing/json_corpus/.gitignore diff --git a/lib/ArduinoJson-6.x/fuzzing/json_fuzzer.cpp b/lib/ArduinoJson-6.x/extras/fuzzing/json_fuzzer.cpp similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/json_fuzzer.cpp rename to lib/ArduinoJson-6.x/extras/fuzzing/json_fuzzer.cpp diff --git a/lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/Comments.json b/lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/Comments.json similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/Comments.json rename to lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/Comments.json diff --git a/lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/EmptyArray.json b/lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/EmptyArray.json similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/EmptyArray.json rename to lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/EmptyArray.json diff --git a/lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/EmptyObject.json b/lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/EmptyObject.json similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/EmptyObject.json rename to lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/EmptyObject.json diff --git a/lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/ExcessiveNesting.json b/lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/ExcessiveNesting.json similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/ExcessiveNesting.json rename to lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/ExcessiveNesting.json diff --git a/lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/IntegerOverflow.json b/lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/IntegerOverflow.json similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/IntegerOverflow.json rename to lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/IntegerOverflow.json diff --git a/lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/Numbers.json b/lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/Numbers.json similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/Numbers.json rename to lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/Numbers.json diff --git a/lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/OpenWeatherMap.json b/lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/OpenWeatherMap.json similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/OpenWeatherMap.json rename to lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/OpenWeatherMap.json diff --git a/lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/Strings.json b/lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/Strings.json similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/Strings.json rename to lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/Strings.json diff --git a/lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/WeatherUnderground.json b/lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/WeatherUnderground.json similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/json_seed_corpus/WeatherUnderground.json rename to lib/ArduinoJson-6.x/extras/fuzzing/json_seed_corpus/WeatherUnderground.json diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_corpus/.gitignore b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_corpus/.gitignore similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_corpus/.gitignore rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_corpus/.gitignore diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_fuzzer.cpp b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_fuzzer.cpp similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_fuzzer.cpp rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_fuzzer.cpp diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/array16 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/array16 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/array16 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/array16 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/array32 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/array32 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/array32 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/array32 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/false b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/false similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/false rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/false diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/fixarray b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/fixarray similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/fixarray rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/fixarray diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/fixint_negative b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/fixint_negative similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/fixint_negative rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/fixint_negative diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/fixint_positive b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/fixint_positive similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/fixint_positive rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/fixint_positive diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/fixmap b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/fixmap similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/fixmap rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/fixmap diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/fixstr b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/fixstr similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/fixstr rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/fixstr diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/float32 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/float32 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/float32 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/float32 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/float64 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/float64 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/float64 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/float64 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/int16 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/int16 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/int16 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/int16 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/int32 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/int32 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/int32 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/int32 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/int64 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/int64 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/int64 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/int64 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/int8 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/int8 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/int8 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/int8 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/map16 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/map16 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/map16 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/map16 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/map32 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/map32 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/map32 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/map32 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/nil b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/nil similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/nil rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/nil diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/str16 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/str16 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/str16 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/str16 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/str32 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/str32 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/str32 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/str32 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/str8 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/str8 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/str8 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/str8 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/true b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/true similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/true rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/true diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/uint16 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/uint16 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/uint16 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/uint16 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/uint32 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/uint32 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/uint32 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/uint32 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/uint64 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/uint64 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/uint64 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/uint64 diff --git a/lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/uint8 b/lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/uint8 similarity index 100% rename from lib/ArduinoJson-6.x/fuzzing/msgpack_seed_corpus/uint8 rename to lib/ArduinoJson-6.x/extras/fuzzing/msgpack_seed_corpus/uint8 diff --git a/lib/ArduinoJson-6.x/scripts/build-arduino-package.sh b/lib/ArduinoJson-6.x/extras/scripts/build-arduino-package.sh similarity index 92% rename from lib/ArduinoJson-6.x/scripts/build-arduino-package.sh rename to lib/ArduinoJson-6.x/extras/scripts/build-arduino-package.sh index 6976bcd31..f79abe0f0 100644 --- a/lib/ArduinoJson-6.x/scripts/build-arduino-package.sh +++ b/lib/ArduinoJson-6.x/extras/scripts/build-arduino-package.sh @@ -3,7 +3,7 @@ TAG=$(git describe) OUTPUT="ArduinoJson-$TAG.zip" -cd $(dirname $0)/../.. +cd $(dirname $0)/../../.. # remove existing file rm -f $OUTPUT diff --git a/lib/ArduinoJson-6.x/extras/scripts/build-single-header.sh b/lib/ArduinoJson-6.x/extras/scripts/build-single-header.sh new file mode 100644 index 000000000..d2346b060 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/scripts/build-single-header.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +set -e + +TAG=$(git describe) +RE_RELATIVE_INCLUDE='^#include[[:space:]]*"(.*)"' +RE_ABSOLUTE_INCLUDE='^#include[[:space:]]*<(ArduinoJson/.*)>' +RE_SYSTEM_INCLUDE='^#include[[:space:]]*<(.*)>' +RE_EMPTY='^(#pragma[[:space:]]+once)?[[:space:]]*(//.*)?$' +SRC_DIRECTORY="$(realpath "$(dirname $0)/../../src")" + + +declare -A INCLUDED + +process() +{ + local PARENT=$1 + local FOLDER=$(dirname $1) + local SHOW_COMMENT=$2 + while IFS= read -r LINE; do + if [[ $LINE =~ $RE_ABSOLUTE_INCLUDE ]]; then + local CHILD=${BASH_REMATCH[1]} + local CHILD_PATH + CHILD_PATH=$(realpath "$SRC_DIRECTORY/$CHILD") + echo "$PARENT -> $CHILD" >&2 + if [[ ! ${INCLUDED[$CHILD_PATH]} ]]; then + INCLUDED[$CHILD_PATH]=true + process "$CHILD" false + fi + elif [[ $LINE =~ $RE_RELATIVE_INCLUDE ]]; then + local CHILD=${BASH_REMATCH[1]} + pushd "$FOLDER" > /dev/null + local CHILD_PATH + CHILD_PATH=$(realpath "$CHILD") + echo "$PARENT -> $CHILD" >&2 + if [[ ! ${INCLUDED[$CHILD_PATH]} ]]; then + INCLUDED[$CHILD_PATH]=true + process "$CHILD" false + fi + popd > /dev/null + elif [[ $LINE =~ $RE_SYSTEM_INCLUDE ]]; then + local CHILD=${BASH_REMATCH[1]} + echo "$PARENT -> <$CHILD>" >&2 + if [[ ! ${INCLUDED[$CHILD]} ]]; then + echo "#include <$CHILD>" + INCLUDED[$CHILD]=true + fi + elif [[ "${SHOW_COMMENT}" = "true" ]] ; then + echo "$LINE" + elif [[ ! $LINE =~ $RE_EMPTY ]]; then + echo "$LINE" + fi + done < $PARENT +} + +simplify_namespaces() { + perl -p0i -e 's|\} // namespace ARDUINOJSON_NAMESPACE\r?\nnamespace ARDUINOJSON_NAMESPACE \{\r?\n||igs' "$1" + rm -f "$1.bak" +} + +cd $(dirname $0)/../.. +INCLUDED=() +process src/ArduinoJson.h true > ../ArduinoJson-$TAG.h +simplify_namespaces ../ArduinoJson-$TAG.h +g++ -x c++ -c -o ../smoketest.o - < doc; + deserializeJson(doc, "{}"); +} +END + +INCLUDED=() +process src/ArduinoJson.hpp true > ../ArduinoJson-$TAG.hpp +simplify_namespaces ../ArduinoJson-$TAG.hpp +g++ -x c++ -c -o ../smoketest.o - < doc; + ArduinoJson::deserializeJson(doc, "{}"); +} +END diff --git a/lib/ArduinoJson-6.x/scripts/publish-particle-library.sh b/lib/ArduinoJson-6.x/extras/scripts/publish-particle-library.sh similarity index 92% rename from lib/ArduinoJson-6.x/scripts/publish-particle-library.sh rename to lib/ArduinoJson-6.x/extras/scripts/publish-particle-library.sh index e37e7965e..62c3140f5 100644 --- a/lib/ArduinoJson-6.x/scripts/publish-particle-library.sh +++ b/lib/ArduinoJson-6.x/extras/scripts/publish-particle-library.sh @@ -2,7 +2,7 @@ set -eu -SOURCE_DIR="$(dirname "$0")/.." +SOURCE_DIR="$(dirname "$0")/../.." WORK_DIR=$(mktemp -d) trap 'rm -rf "$WORK_DIR"' EXIT diff --git a/lib/ArduinoJson-6.x/scripts/publish.sh b/lib/ArduinoJson-6.x/extras/scripts/publish.sh similarity index 79% rename from lib/ArduinoJson-6.x/scripts/publish.sh rename to lib/ArduinoJson-6.x/extras/scripts/publish.sh index 2d2f06930..caad1394b 100644 --- a/lib/ArduinoJson-6.x/scripts/publish.sh +++ b/lib/ArduinoJson-6.x/extras/scripts/publish.sh @@ -2,7 +2,7 @@ set -eu -cd "$(dirname "$0")/.." +cd "$(dirname "$0")/../.." VERSION="$1" DATE=$(date +%F) @@ -14,19 +14,22 @@ update_version_in_source () { UNDERLINE=$(printf -- '-%.0s' $(seq 1 ${#TAG})) sed -i~ -bE "s/version=$VERSION_REGEX/version=$VERSION/; s|ardu-badge.com/ArduinoJson/$VERSION_REGEX|ardu-badge.com/ArduinoJson/$VERSION|; " README.md - rm README.md*~ + rm README.md~ sed -i~ -bE "4s/HEAD/$TAG ($DATE)/; 5s/-+/$UNDERLINE/" CHANGELOG.md - rm CHANGELOG.md*~ + rm CHANGELOG.md~ + + sed -i~ -bE "s/(project\\s*\\(ArduinoJson\\s+VERSION\\s+).*?\\)/\\1$MAJOR.$MINOR.$REVISION)/" CMakeLists.txt + rm CMakeLists.txt~ sed -i~ -bE "s/\"version\":.*$/\"version\": \"$VERSION\",/" library.json - rm library.json*~ + rm library.json~ sed -i~ -bE "s/version=.*$/version=$VERSION/" library.properties - rm library.properties*~ + rm library.properties~ sed -i~ -bE "s/version: .*$/version: $VERSION.{build}/" appveyor.yml - rm appveyor.yml*~ + rm appveyor.yml~ sed -i~ -bE \ -e "s/ARDUINOJSON_VERSION .*$/ARDUINOJSON_VERSION \"$VERSION\"/" \ @@ -56,6 +59,6 @@ commit_new_version add_tag push -scripts/build-arduino-package.sh -scripts/build-single-header.sh -scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h" +extras/scripts/build-arduino-package.sh +extras/scripts/build-single-header.sh +extras/scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h" diff --git a/lib/ArduinoJson-6.x/scripts/wandbox/JsonGeneratorExample.cpp b/lib/ArduinoJson-6.x/extras/scripts/wandbox/JsonGeneratorExample.cpp similarity index 97% rename from lib/ArduinoJson-6.x/scripts/wandbox/JsonGeneratorExample.cpp rename to lib/ArduinoJson-6.x/extras/scripts/wandbox/JsonGeneratorExample.cpp index 9220eb83f..21a66db1f 100644 --- a/lib/ArduinoJson-6.x/scripts/wandbox/JsonGeneratorExample.cpp +++ b/lib/ArduinoJson-6.x/extras/scripts/wandbox/JsonGeneratorExample.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows how to generate a JSON document with ArduinoJson. diff --git a/lib/ArduinoJson-6.x/scripts/wandbox/JsonParserExample.cpp b/lib/ArduinoJson-6.x/extras/scripts/wandbox/JsonParserExample.cpp similarity index 97% rename from lib/ArduinoJson-6.x/scripts/wandbox/JsonParserExample.cpp rename to lib/ArduinoJson-6.x/extras/scripts/wandbox/JsonParserExample.cpp index f51771760..8cf6b9e9d 100644 --- a/lib/ArduinoJson-6.x/scripts/wandbox/JsonParserExample.cpp +++ b/lib/ArduinoJson-6.x/extras/scripts/wandbox/JsonParserExample.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows how to deserialize a JSON document with ArduinoJson. diff --git a/lib/ArduinoJson-6.x/scripts/wandbox/MsgPackParserExample.cpp b/lib/ArduinoJson-6.x/extras/scripts/wandbox/MsgPackParserExample.cpp similarity index 98% rename from lib/ArduinoJson-6.x/scripts/wandbox/MsgPackParserExample.cpp rename to lib/ArduinoJson-6.x/extras/scripts/wandbox/MsgPackParserExample.cpp index 778011db2..241d76913 100644 --- a/lib/ArduinoJson-6.x/scripts/wandbox/MsgPackParserExample.cpp +++ b/lib/ArduinoJson-6.x/extras/scripts/wandbox/MsgPackParserExample.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // // This example shows how to generate a JSON document with ArduinoJson. diff --git a/lib/ArduinoJson-6.x/scripts/wandbox/publish.sh b/lib/ArduinoJson-6.x/extras/scripts/wandbox/publish.sh similarity index 100% rename from lib/ArduinoJson-6.x/scripts/wandbox/publish.sh rename to lib/ArduinoJson-6.x/extras/scripts/wandbox/publish.sh diff --git a/lib/ArduinoJson-6.x/extras/tests/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/CMakeLists.txt new file mode 100644 index 000000000..0fce75ef7 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/CMakeLists.txt @@ -0,0 +1,26 @@ +# ArduinoJson - arduinojson.org +# Copyright Benoit Blanchon 2014-2020 +# MIT License + +add_subdirectory(catch) + +link_libraries(ArduinoJson catch) + +include_directories(Helpers) +add_subdirectory(ElementProxy) +add_subdirectory(FailingBuilds) +add_subdirectory(IntegrationTests) +add_subdirectory(JsonArray) +add_subdirectory(JsonDeserializer) +add_subdirectory(JsonDocument) +add_subdirectory(JsonObject) +add_subdirectory(JsonSerializer) +add_subdirectory(JsonVariant) +add_subdirectory(MemberProxy) +add_subdirectory(MemoryPool) +add_subdirectory(Misc) +add_subdirectory(MixedConfiguration) +add_subdirectory(MsgPackDeserializer) +add_subdirectory(MsgPackSerializer) +add_subdirectory(Numbers) +add_subdirectory(TextFormatter) diff --git a/lib/ArduinoJson-6.x/test/ElementProxy/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/CMakeLists.txt similarity index 67% rename from lib/ArduinoJson-6.x/test/ElementProxy/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/ElementProxy/CMakeLists.txt index ab419f48e..f86d6bb0c 100644 --- a/lib/ArduinoJson-6.x/test/ElementProxy/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/CMakeLists.txt @@ -1,14 +1,14 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(ElementProxyTests add.cpp clear.cpp + compare.cpp remove.cpp set.cpp size.cpp ) -target_link_libraries(ElementProxyTests catch) add_test(ElementProxy ElementProxyTests) diff --git a/lib/ArduinoJson-6.x/test/ElementProxy/add.cpp b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/add.cpp similarity index 71% rename from lib/ArduinoJson-6.x/test/ElementProxy/add.cpp rename to lib/ArduinoJson-6.x/extras/tests/ElementProxy/add.cpp index 0f18e674c..705b3e186 100644 --- a/lib/ArduinoJson-6.x/test/ElementProxy/add.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/add.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -23,4 +23,12 @@ TEST_CASE("ElementProxy::add()") { REQUIRE(doc.as() == "[[\"world\"]]"); } + + SECTION("set(char[])") { + char s[] = "world"; + ep.add(s); + strcpy(s, "!!!!!"); + + REQUIRE(doc.as() == "[[\"world\"]]"); + } } diff --git a/lib/ArduinoJson-6.x/test/ElementProxy/clear.cpp b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/clear.cpp similarity index 92% rename from lib/ArduinoJson-6.x/test/ElementProxy/clear.cpp rename to lib/ArduinoJson-6.x/extras/tests/ElementProxy/clear.cpp index 2634d187c..0c795a827 100644 --- a/lib/ArduinoJson-6.x/test/ElementProxy/clear.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/clear.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/ElementProxy/compare.cpp b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/compare.cpp new file mode 100644 index 000000000..0023bf2c7 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/compare.cpp @@ -0,0 +1,48 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +using namespace ARDUINOJSON_NAMESPACE; + +TEST_CASE("ElementProxy::operator==()") { + DynamicJsonDocument doc(4096); + + SECTION("1 vs 1") { + doc.add(1); + doc.add(1); + + REQUIRE(doc[0] <= doc[1]); + REQUIRE(doc[0] == doc[1]); + REQUIRE(doc[0] >= doc[1]); + REQUIRE_FALSE(doc[0] != doc[1]); + REQUIRE_FALSE(doc[0] < doc[1]); + REQUIRE_FALSE(doc[0] > doc[1]); + } + + SECTION("1 vs 2") { + doc.add(1); + doc.add(2); + + REQUIRE(doc[0] != doc[1]); + REQUIRE(doc[0] < doc[1]); + REQUIRE(doc[0] <= doc[1]); + REQUIRE_FALSE(doc[0] == doc[1]); + REQUIRE_FALSE(doc[0] > doc[1]); + REQUIRE_FALSE(doc[0] >= doc[1]); + } + + SECTION("'abc' vs 'bcd'") { + doc.add("abc"); + doc.add("bcd"); + + REQUIRE(doc[0] != doc[1]); + REQUIRE(doc[0] < doc[1]); + REQUIRE(doc[0] <= doc[1]); + REQUIRE_FALSE(doc[0] == doc[1]); + REQUIRE_FALSE(doc[0] > doc[1]); + REQUIRE_FALSE(doc[0] >= doc[1]); + } +} diff --git a/lib/ArduinoJson-6.x/test/ElementProxy/remove.cpp b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/remove.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/ElementProxy/remove.cpp rename to lib/ArduinoJson-6.x/extras/tests/ElementProxy/remove.cpp index 8a2138498..c6917cb48 100644 --- a/lib/ArduinoJson-6.x/test/ElementProxy/remove.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/remove.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/ElementProxy/set.cpp b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/set.cpp similarity index 70% rename from lib/ArduinoJson-6.x/test/ElementProxy/set.cpp rename to lib/ArduinoJson-6.x/extras/tests/ElementProxy/set.cpp index d172121b4..bb99e15d9 100644 --- a/lib/ArduinoJson-6.x/test/ElementProxy/set.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/set.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -9,7 +9,6 @@ using namespace ARDUINOJSON_NAMESPACE; TEST_CASE("ElementProxy::set()") { DynamicJsonDocument doc(4096); - doc.addElement(); ElementProxy ep = doc[0]; SECTION("set(int)") { @@ -23,4 +22,12 @@ TEST_CASE("ElementProxy::set()") { REQUIRE(doc.as() == "[\"world\"]"); } + + SECTION("set(char[])") { + char s[] = "world"; + ep.set(s); + strcpy(s, "!!!!!"); + + REQUIRE(doc.as() == "[\"world\"]"); + } } diff --git a/lib/ArduinoJson-6.x/test/ElementProxy/size.cpp b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/size.cpp similarity index 93% rename from lib/ArduinoJson-6.x/test/ElementProxy/size.cpp rename to lib/ArduinoJson-6.x/extras/tests/ElementProxy/size.cpp index 6ae235c85..d5176c018 100644 --- a/lib/ArduinoJson-6.x/test/ElementProxy/size.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/size.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/ElementProxy/subscript.cpp b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/subscript.cpp new file mode 100644 index 000000000..70bf273a8 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/ElementProxy/subscript.cpp @@ -0,0 +1,25 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +using namespace ARDUINOJSON_NAMESPACE; + +TEST_CASE("MemberProxy::operator[]") { + DynamicJsonDocument doc(4096); + ElementProxy ep = doc[1]; + + SECTION("set member") { + ep["world"] = 42; + + REQUIRE(doc.as() == "[null,{\"world\":42}]"); + } + + SECTION("set element") { + ep[2] = 42; + + REQUIRE(doc.as() == "[null,[null,null,42]]"); + } +} diff --git a/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/CMakeLists.txt new file mode 100644 index 000000000..986c86443 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/CMakeLists.txt @@ -0,0 +1,38 @@ +# ArduinoJson - arduinojson.org +# Copyright Benoit Blanchon 2014-2020 +# MIT License + +macro(build_should_fail target) + set_target_properties(${target} + PROPERTIES + EXCLUDE_FROM_ALL TRUE + EXCLUDE_FROM_DEFAULT_BUILD TRUE + ) + add_test( + NAME + ${target} + COMMAND + ${CMAKE_COMMAND} --build . --target ${target} --config $ + WORKING_DIRECTORY + ${CMAKE_BINARY_DIR} + ) + set_tests_properties(${target} + PROPERTIES + WILL_FAIL TRUE + ) +endmacro() + + +add_executable(Issue978 Issue978.cpp) +build_should_fail(Issue978) + +add_executable(Issue1189 Issue1189.cpp) +build_should_fail(Issue1189) + +add_executable(read_long_long read_long_long.cpp) +set_property(TARGET read_long_long PROPERTY CXX_STANDARD 11) +build_should_fail(read_long_long) + +add_executable(write_long_long write_long_long.cpp) +set_property(TARGET write_long_long PROPERTY CXX_STANDARD 11) +build_should_fail(write_long_long) diff --git a/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/Issue1189.cpp b/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/Issue1189.cpp new file mode 100644 index 000000000..b3832a325 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/Issue1189.cpp @@ -0,0 +1,13 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include + +// a function should not be able to get a JsonDocument by value +void f(JsonDocument) {} + +int main() { + DynamicJsonDocument doc(1024); + f(doc); +} diff --git a/lib/ArduinoJson-6.x/test/Misc/Issue978.cpp b/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/Issue978.cpp similarity index 83% rename from lib/ArduinoJson-6.x/test/Misc/Issue978.cpp rename to lib/ArduinoJson-6.x/extras/tests/FailingBuilds/Issue978.cpp index 927f99c07..e3d9c2009 100644 --- a/lib/ArduinoJson-6.x/test/Misc/Issue978.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/Issue978.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/read_long_long.cpp b/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/read_long_long.cpp new file mode 100644 index 000000000..94a9499a5 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/read_long_long.cpp @@ -0,0 +1,20 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#define ARDUINOJSON_USE_LONG_LONG 0 +#include + +#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ >= 8 +#error This test requires sizeof(long) < 8 +#endif + +#if !ARDUINOJSON_HAS_LONG_LONG +#error This test requires C++11 +#endif + +ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(long long) +int main() { + DynamicJsonDocument doc(1024); + doc["dummy"].as(); +} diff --git a/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/write_long_long.cpp b/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/write_long_long.cpp new file mode 100644 index 000000000..094bd4c1c --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/FailingBuilds/write_long_long.cpp @@ -0,0 +1,19 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#define ARDUINOJSON_USE_LONG_LONG 0 +#include + +#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ >= 8 +#error This test requires sizeof(long) < 8 +#endif + +#if !ARDUINOJSON_HAS_LONG_LONG +#error This test requires C++11 +#endif + +int main() { + DynamicJsonDocument doc(1024); + doc["dummy"] = static_cast(42); +} diff --git a/lib/ArduinoJson-6.x/extras/tests/Helpers/CustomReader.hpp b/lib/ArduinoJson-6.x/extras/tests/Helpers/CustomReader.hpp new file mode 100644 index 000000000..616786f09 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Helpers/CustomReader.hpp @@ -0,0 +1,26 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +class CustomReader { + std::stringstream _stream; + + public: + CustomReader(const char* input) : _stream(input) {} + + int read() { + return _stream.get(); + } + + size_t readBytes(char* buffer, size_t length) { + _stream.read(buffer, static_cast(length)); + return static_cast(_stream.gcount()); + } + + private: + CustomReader(const CustomReader&); +}; diff --git a/lib/ArduinoJson-6.x/extras/tests/Helpers/Stream.h b/lib/ArduinoJson-6.x/extras/tests/Helpers/Stream.h new file mode 100644 index 000000000..034449396 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Helpers/Stream.h @@ -0,0 +1,14 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +// Reproduces Arduino's Stream class +class Stream // : public Print +{ + public: + virtual ~Stream() {} + virtual int read() = 0; + virtual size_t readBytes(char *buffer, size_t length) = 0; +}; diff --git a/lib/ArduinoJson-6.x/extras/tests/Helpers/WString.h b/lib/ArduinoJson-6.x/extras/tests/Helpers/WString.h new file mode 100644 index 000000000..18122f7ee --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Helpers/WString.h @@ -0,0 +1,42 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +// Reproduces Arduino's String class +class String { + public: + String& operator+=(const char* rhs) { + _str += rhs; + return *this; + } + + size_t length() const { + return _str.size(); + } + + const char* c_str() const { + return _str.c_str(); + } + + bool operator==(const char* s) const { + return _str == s; + } + + friend std::ostream& operator<<(std::ostream& lhs, const ::String& rhs) { + lhs << rhs._str; + return lhs; + } + + private: + std::string _str; +}; + +class StringSumHelper; + +inline bool operator==(const std::string& lhs, const ::String& rhs) { + return lhs == rhs.c_str(); +} diff --git a/lib/ArduinoJson-6.x/extras/tests/Helpers/progmem_emulation.hpp b/lib/ArduinoJson-6.x/extras/tests/Helpers/progmem_emulation.hpp new file mode 100644 index 000000000..4a7f17990 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Helpers/progmem_emulation.hpp @@ -0,0 +1,23 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include // uint8_t +#include // strcmp, strlen... + +class __FlashStringHelper; + +inline const void* convertPtrToFlash(const void* s) { + return reinterpret_cast(s) + 42; +} + +inline const void* convertFlashToPtr(const void* s) { + return reinterpret_cast(s) - 42; +} + +#define F(X) reinterpret_cast(convertPtrToFlash(X)) +#define FC(X) reinterpret_cast(convertPtrToFlash(X)) + +inline uint8_t pgm_read_byte(const void* p) { + return *reinterpret_cast(convertFlashToPtr(p)); +} diff --git a/lib/ArduinoJson-6.x/test/IntegrationTests/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/IntegrationTests/CMakeLists.txt similarity index 78% rename from lib/ArduinoJson-6.x/test/IntegrationTests/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/IntegrationTests/CMakeLists.txt index ce12734f1..556a70daa 100644 --- a/lib/ArduinoJson-6.x/test/IntegrationTests/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/IntegrationTests/CMakeLists.txt @@ -1,11 +1,12 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(IntegrationTests gbathree.cpp issue772.cpp round_trip.cpp + openweathermap.cpp ) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") @@ -15,5 +16,4 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") ) endif() -target_link_libraries(IntegrationTests catch) add_test(IntegrationTests IntegrationTests) diff --git a/lib/ArduinoJson-6.x/test/IntegrationTests/gbathree.cpp b/lib/ArduinoJson-6.x/extras/tests/IntegrationTests/gbathree.cpp similarity index 99% rename from lib/ArduinoJson-6.x/test/IntegrationTests/gbathree.cpp rename to lib/ArduinoJson-6.x/extras/tests/IntegrationTests/gbathree.cpp index c30257734..0e586fdc5 100644 --- a/lib/ArduinoJson-6.x/test/IntegrationTests/gbathree.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/IntegrationTests/gbathree.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/IntegrationTests/issue772.cpp b/lib/ArduinoJson-6.x/extras/tests/IntegrationTests/issue772.cpp similarity index 95% rename from lib/ArduinoJson-6.x/test/IntegrationTests/issue772.cpp rename to lib/ArduinoJson-6.x/extras/tests/IntegrationTests/issue772.cpp index 97fd7f5d7..2df512495 100644 --- a/lib/ArduinoJson-6.x/test/IntegrationTests/issue772.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/IntegrationTests/issue772.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/IntegrationTests/openweathermap.cpp b/lib/ArduinoJson-6.x/extras/tests/IntegrationTests/openweathermap.cpp new file mode 100644 index 000000000..335af3591 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/IntegrationTests/openweathermap.cpp @@ -0,0 +1,68 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +TEST_CASE("OpenWeatherMap") { + // clang-format off + const char* input_json = "{\"cod\":\"200\",\"message\":0,\"cnt\":40,\"list\":[{\"dt\":1581498000,\"main\":{\"temp\":3.23,\"feels_like\":-3.63,\"temp_min\":3.23,\"temp_max\":4.62,\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1010,\"humidity\":58,\"temp_kf\":-1.39},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":0},\"wind\":{\"speed\":6.19,\"deg\":266},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-12 09:00:00\"},{\"dt\":1581508800,\"main\":{\"temp\":6.09,\"feels_like\":-1.07,\"temp_min\":6.09,\"temp_max\":7.13,\"pressure\":1015,\"sea_level\":1015,\"grnd_level\":1011,\"humidity\":48,\"temp_kf\":-1.04},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":9},\"wind\":{\"speed\":6.64,\"deg\":268},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-12 12:00:00\"},{\"dt\":1581519600,\"main\":{\"temp\":6.82,\"feels_like\":0.47,\"temp_min\":6.82,\"temp_max\":7.52,\"pressure\":1015,\"sea_level\":1015,\"grnd_level\":1011,\"humidity\":47,\"temp_kf\":-0.7},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":97},\"wind\":{\"speed\":5.55,\"deg\":267},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-12 15:00:00\"},{\"dt\":1581530400,\"main\":{\"temp\":5.76,\"feels_like\":1.84,\"temp_min\":5.76,\"temp_max\":6.11,\"pressure\":1015,\"sea_level\":1015,\"grnd_level\":1010,\"humidity\":57,\"temp_kf\":-0.35},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":99},\"wind\":{\"speed\":2.35,\"deg\":232},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-12 18:00:00\"},{\"dt\":1581541200,\"main\":{\"temp\":5.7,\"feels_like\":1.34,\"temp_min\":5.7,\"temp_max\":5.7,\"pressure\":1012,\"sea_level\":1012,\"grnd_level\":1008,\"humidity\":71,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":3.57,\"deg\":198},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-12 21:00:00\"},{\"dt\":1581552000,\"main\":{\"temp\":5.82,\"feels_like\":1.39,\"temp_min\":5.82,\"temp_max\":5.82,\"pressure\":1009,\"sea_level\":1009,\"grnd_level\":1004,\"humidity\":86,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":4.35,\"deg\":169},\"rain\":{\"3h\":0.5},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-13 00:00:00\"},{\"dt\":1581562800,\"main\":{\"temp\":5.9,\"feels_like\":-0.85,\"temp_min\":5.9,\"temp_max\":5.9,\"pressure\":1000,\"sea_level\":1000,\"grnd_level\":997,\"humidity\":86,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":7.69,\"deg\":178},\"rain\":{\"3h\":1.75},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-13 03:00:00\"},{\"dt\":1581573600,\"main\":{\"temp\":7.52,\"feels_like\":1.74,\"temp_min\":7.52,\"temp_max\":7.52,\"pressure\":993,\"sea_level\":993,\"grnd_level\":988,\"humidity\":88,\"temp_kf\":0},\"weather\":[{\"id\":501,\"main\":\"Rain\",\"description\":\"moderate rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":6.84,\"deg\":184},\"rain\":{\"3h\":7.06},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-13 06:00:00\"},{\"dt\":1581584400,\"main\":{\"temp\":7.23,\"feels_like\":0.81,\"temp_min\":7.23,\"temp_max\":7.23,\"pressure\":992,\"sea_level\":992,\"grnd_level\":988,\"humidity\":69,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":49},\"wind\":{\"speed\":6.77,\"deg\":239},\"rain\":{\"3h\":0.25},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-13 09:00:00\"},{\"dt\":1581595200,\"main\":{\"temp\":7.67,\"feels_like\":2.81,\"temp_min\":7.67,\"temp_max\":7.67,\"pressure\":991,\"sea_level\":991,\"grnd_level\":987,\"humidity\":75,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":73},\"wind\":{\"speed\":4.93,\"deg\":235},\"rain\":{\"3h\":0.75},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-13 12:00:00\"},{\"dt\":1581606000,\"main\":{\"temp\":8.83,\"feels_like\":3.23,\"temp_min\":8.83,\"temp_max\":8.83,\"pressure\":993,\"sea_level\":993,\"grnd_level\":990,\"humidity\":64,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":83},\"wind\":{\"speed\":5.7,\"deg\":293},\"rain\":{\"3h\":0.38},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-13 15:00:00\"},{\"dt\":1581616800,\"main\":{\"temp\":7.42,\"feels_like\":1.77,\"temp_min\":7.42,\"temp_max\":7.42,\"pressure\":1000,\"sea_level\":1000,\"grnd_level\":996,\"humidity\":71,\"temp_kf\":0},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":54},\"wind\":{\"speed\":5.81,\"deg\":307},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-13 18:00:00\"},{\"dt\":1581627600,\"main\":{\"temp\":5.82,\"feels_like\":0.89,\"temp_min\":5.82,\"temp_max\":5.82,\"pressure\":1007,\"sea_level\":1007,\"grnd_level\":1003,\"humidity\":79,\"temp_kf\":0},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01n\"}],\"clouds\":{\"all\":6},\"wind\":{\"speed\":4.76,\"deg\":300},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-13 21:00:00\"},{\"dt\":1581638400,\"main\":{\"temp\":5.58,\"feels_like\":2.09,\"temp_min\":5.58,\"temp_max\":5.58,\"pressure\":1011,\"sea_level\":1011,\"grnd_level\":1007,\"humidity\":81,\"temp_kf\":0},\"weather\":[{\"id\":802,\"main\":\"Clouds\",\"description\":\"scattered clouds\",\"icon\":\"03n\"}],\"clouds\":{\"all\":47},\"wind\":{\"speed\":2.73,\"deg\":326},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-14 00:00:00\"},{\"dt\":1581649200,\"main\":{\"temp\":4.27,\"feels_like\":1.72,\"temp_min\":4.27,\"temp_max\":4.27,\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1010,\"humidity\":85,\"temp_kf\":0},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":69},\"wind\":{\"speed\":1.24,\"deg\":295},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-14 03:00:00\"},{\"dt\":1581660000,\"main\":{\"temp\":3.91,\"feels_like\":1.54,\"temp_min\":3.91,\"temp_max\":3.91,\"pressure\":1016,\"sea_level\":1016,\"grnd_level\":1012,\"humidity\":87,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":85},\"wind\":{\"speed\":0.98,\"deg\":211},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-14 06:00:00\"},{\"dt\":1581670800,\"main\":{\"temp\":4.77,\"feels_like\":0.74,\"temp_min\":4.77,\"temp_max\":4.77,\"pressure\":1017,\"sea_level\":1017,\"grnd_level\":1013,\"humidity\":78,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":3.19,\"deg\":184},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-14 09:00:00\"},{\"dt\":1581681600,\"main\":{\"temp\":9.03,\"feels_like\":4,\"temp_min\":9.03,\"temp_max\":9.03,\"pressure\":1016,\"sea_level\":1016,\"grnd_level\":1012,\"humidity\":73,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":5.43,\"deg\":206},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-14 12:00:00\"},{\"dt\":1581692400,\"main\":{\"temp\":9.86,\"feels_like\":4.22,\"temp_min\":9.86,\"temp_max\":9.86,\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1010,\"humidity\":74,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":6.58,\"deg\":209},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-14 15:00:00\"},{\"dt\":1581703200,\"main\":{\"temp\":9.48,\"feels_like\":4.8,\"temp_min\":9.48,\"temp_max\":9.48,\"pressure\":1013,\"sea_level\":1013,\"grnd_level\":1009,\"humidity\":83,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":5.6,\"deg\":206},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-14 18:00:00\"},{\"dt\":1581714000,\"main\":{\"temp\":10.03,\"feels_like\":6.48,\"temp_min\":10.03,\"temp_max\":10.03,\"pressure\":1013,\"sea_level\":1013,\"grnd_level\":1009,\"humidity\":93,\"temp_kf\":0},\"weather\":[{\"id\":501,\"main\":\"Rain\",\"description\":\"moderate rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":4.75,\"deg\":226},\"rain\":{\"3h\":3.13},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-14 21:00:00\"},{\"dt\":1581724800,\"main\":{\"temp\":9.48,\"feels_like\":6.25,\"temp_min\":9.48,\"temp_max\":9.48,\"pressure\":1013,\"sea_level\":1013,\"grnd_level\":1009,\"humidity\":89,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":3.87,\"deg\":214},\"rain\":{\"3h\":2.38},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-15 00:00:00\"},{\"dt\":1581735600,\"main\":{\"temp\":9.12,\"feels_like\":7.08,\"temp_min\":9.12,\"temp_max\":9.12,\"pressure\":1011,\"sea_level\":1011,\"grnd_level\":1007,\"humidity\":96,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":2.43,\"deg\":194},\"rain\":{\"3h\":1},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-15 03:00:00\"},{\"dt\":1581746400,\"main\":{\"temp\":10.32,\"feels_like\":6.71,\"temp_min\":10.32,\"temp_max\":10.32,\"pressure\":1009,\"sea_level\":1009,\"grnd_level\":1004,\"humidity\":95,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":5.05,\"deg\":196},\"rain\":{\"3h\":1.75},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-15 06:00:00\"},{\"dt\":1581757200,\"main\":{\"temp\":11.57,\"feels_like\":5.85,\"temp_min\":11.57,\"temp_max\":11.57,\"pressure\":1006,\"sea_level\":1006,\"grnd_level\":1002,\"humidity\":85,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":7.91,\"deg\":205},\"rain\":{\"3h\":1.44},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-15 09:00:00\"},{\"dt\":1581768000,\"main\":{\"temp\":12.25,\"feels_like\":4.46,\"temp_min\":12.25,\"temp_max\":12.25,\"pressure\":1003,\"sea_level\":1003,\"grnd_level\":998,\"humidity\":78,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":10.65,\"deg\":201},\"rain\":{\"3h\":1.81},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-15 12:00:00\"},{\"dt\":1581778800,\"main\":{\"temp\":12.19,\"feels_like\":3.17,\"temp_min\":12.19,\"temp_max\":12.19,\"pressure\":998,\"sea_level\":998,\"grnd_level\":994,\"humidity\":80,\"temp_kf\":0},\"weather\":[{\"id\":501,\"main\":\"Rain\",\"description\":\"moderate rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":12.52,\"deg\":204},\"rain\":{\"3h\":3.5},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-15 15:00:00\"},{\"dt\":1581789600,\"main\":{\"temp\":12.25,\"feels_like\":4.15,\"temp_min\":12.25,\"temp_max\":12.25,\"pressure\":996,\"sea_level\":996,\"grnd_level\":992,\"humidity\":83,\"temp_kf\":0},\"weather\":[{\"id\":501,\"main\":\"Rain\",\"description\":\"moderate rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":11.42,\"deg\":215},\"rain\":{\"3h\":4.88},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-15 18:00:00\"},{\"dt\":1581800400,\"main\":{\"temp\":12.64,\"feels_like\":5.85,\"temp_min\":12.64,\"temp_max\":12.64,\"pressure\":994,\"sea_level\":994,\"grnd_level\":990,\"humidity\":76,\"temp_kf\":0},\"weather\":[{\"id\":501,\"main\":\"Rain\",\"description\":\"moderate rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":9.22,\"deg\":217},\"rain\":{\"3h\":6.88},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-15 21:00:00\"},{\"dt\":1581811200,\"main\":{\"temp\":12.96,\"feels_like\":4.03,\"temp_min\":12.96,\"temp_max\":12.96,\"pressure\":988,\"sea_level\":988,\"grnd_level\":984,\"humidity\":83,\"temp_kf\":0},\"weather\":[{\"id\":501,\"main\":\"Rain\",\"description\":\"moderate rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":12.88,\"deg\":211},\"rain\":{\"3h\":5.63},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-16 00:00:00\"},{\"dt\":1581822000,\"main\":{\"temp\":13.13,\"feels_like\":5.17,\"temp_min\":13.13,\"temp_max\":13.13,\"pressure\":987,\"sea_level\":987,\"grnd_level\":982,\"humidity\":82,\"temp_kf\":0},\"weather\":[{\"id\":501,\"main\":\"Rain\",\"description\":\"moderate rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":11.49,\"deg\":246},\"rain\":{\"3h\":7.25},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-16 03:00:00\"},{\"dt\":1581832800,\"main\":{\"temp\":9.07,\"feels_like\":0.79,\"temp_min\":9.07,\"temp_max\":9.07,\"pressure\":990,\"sea_level\":990,\"grnd_level\":986,\"humidity\":75,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10n\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":10.18,\"deg\":255},\"rain\":{\"3h\":2},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-16 06:00:00\"},{\"dt\":1581843600,\"main\":{\"temp\":8.05,\"feels_like\":-0.9,\"temp_min\":8.05,\"temp_max\":8.05,\"pressure\":994,\"sea_level\":994,\"grnd_level\":990,\"humidity\":51,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":100},\"wind\":{\"speed\":9.65,\"deg\":245},\"rain\":{\"3h\":1.19},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-16 09:00:00\"},{\"dt\":1581854400,\"main\":{\"temp\":9.54,\"feels_like\":0.13,\"temp_min\":9.54,\"temp_max\":9.54,\"pressure\":996,\"sea_level\":996,\"grnd_level\":991,\"humidity\":41,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04d\"}],\"clouds\":{\"all\":94},\"wind\":{\"speed\":10.03,\"deg\":243},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-16 12:00:00\"},{\"dt\":1581865200,\"main\":{\"temp\":9.08,\"feels_like\":-0.35,\"temp_min\":9.08,\"temp_max\":9.08,\"pressure\":996,\"sea_level\":996,\"grnd_level\":991,\"humidity\":44,\"temp_kf\":0},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"clouds\":{\"all\":89},\"wind\":{\"speed\":10.15,\"deg\":246},\"rain\":{\"3h\":0.25},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-16 15:00:00\"},{\"dt\":1581876000,\"main\":{\"temp\":7.41,\"feels_like\":-1.34,\"temp_min\":7.41,\"temp_max\":7.41,\"pressure\":996,\"sea_level\":996,\"grnd_level\":992,\"humidity\":50,\"temp_kf\":0},\"weather\":[{\"id\":804,\"main\":\"Clouds\",\"description\":\"overcast clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":94},\"wind\":{\"speed\":9.21,\"deg\":240},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-16 18:00:00\"},{\"dt\":1581886800,\"main\":{\"temp\":6.42,\"feels_like\":-1.7,\"temp_min\":6.42,\"temp_max\":6.42,\"pressure\":997,\"sea_level\":997,\"grnd_level\":993,\"humidity\":58,\"temp_kf\":0},\"weather\":[{\"id\":803,\"main\":\"Clouds\",\"description\":\"broken clouds\",\"icon\":\"04n\"}],\"clouds\":{\"all\":67},\"wind\":{\"speed\":8.52,\"deg\":236},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-16 21:00:00\"},{\"dt\":1581897600,\"main\":{\"temp\":6.03,\"feels_like\":-2.65,\"temp_min\":6.03,\"temp_max\":6.03,\"pressure\":996,\"sea_level\":996,\"grnd_level\":993,\"humidity\":51,\"temp_kf\":0},\"weather\":[{\"id\":802,\"main\":\"Clouds\",\"description\":\"scattered clouds\",\"icon\":\"03n\"}],\"clouds\":{\"all\":38},\"wind\":{\"speed\":8.94,\"deg\":240},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-17 00:00:00\"},{\"dt\":1581908400,\"main\":{\"temp\":5.62,\"feels_like\":-2.86,\"temp_min\":5.62,\"temp_max\":5.62,\"pressure\":995,\"sea_level\":995,\"grnd_level\":991,\"humidity\":53,\"temp_kf\":0},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01n\"}],\"clouds\":{\"all\":0},\"wind\":{\"speed\":8.67,\"deg\":241},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-17 03:00:00\"},{\"dt\":1581919200,\"main\":{\"temp\":5.51,\"feels_like\":-2.41,\"temp_min\":5.51,\"temp_max\":5.51,\"pressure\":995,\"sea_level\":995,\"grnd_level\":991,\"humidity\":61,\"temp_kf\":0},\"weather\":[{\"id\":802,\"main\":\"Clouds\",\"description\":\"scattered clouds\",\"icon\":\"03n\"}],\"clouds\":{\"all\":35},\"wind\":{\"speed\":8.2,\"deg\":244},\"sys\":{\"pod\":\"n\"},\"dt_txt\":\"2020-02-17 06:00:00\"}],\"city\":{\"id\":2643743,\"name\":\"London\",\"coord\":{\"lat\":51.5085,\"lon\":-0.1257},\"country\":\"GB\",\"population\":1000000,\"timezone\":0,\"sunrise\":1581492085,\"sunset\":1581527294}}"; + + const char* expected_json = "{\"list\":[" + "{\"dt\":1581498000,\"main\":{\"temp\":3.23},\"weather\":[{\"description\":\"clear sky\"}]}," + "{\"dt\":1581508800,\"main\":{\"temp\":6.09},\"weather\":[{\"description\":\"clear sky\"}]}," + "{\"dt\":1581519600,\"main\":{\"temp\":6.82},\"weather\":[{\"description\":\"overcast clouds\"}]}," + "{\"dt\":1581530400,\"main\":{\"temp\":5.76},\"weather\":[{\"description\":\"overcast clouds\"}]}," + "{\"dt\":1581541200,\"main\":{\"temp\":5.7},\"weather\":[{\"description\":\"overcast clouds\"}]}," + "{\"dt\":1581552000,\"main\":{\"temp\":5.82},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581562800,\"main\":{\"temp\":5.9},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581573600,\"main\":{\"temp\":7.52},\"weather\":[{\"description\":\"moderate rain\"}]}," + "{\"dt\":1581584400,\"main\":{\"temp\":7.23},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581595200,\"main\":{\"temp\":7.67},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581606000,\"main\":{\"temp\":8.83},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581616800,\"main\":{\"temp\":7.42},\"weather\":[{\"description\":\"broken clouds\"}]}," + "{\"dt\":1581627600,\"main\":{\"temp\":5.82},\"weather\":[{\"description\":\"clear sky\"}]}," + "{\"dt\":1581638400,\"main\":{\"temp\":5.58},\"weather\":[{\"description\":\"scattered clouds\"}]}," + "{\"dt\":1581649200,\"main\":{\"temp\":4.27},\"weather\":[{\"description\":\"broken clouds\"}]}," + "{\"dt\":1581660000,\"main\":{\"temp\":3.91},\"weather\":[{\"description\":\"overcast clouds\"}]}," + "{\"dt\":1581670800,\"main\":{\"temp\":4.77},\"weather\":[{\"description\":\"overcast clouds\"}]}," + "{\"dt\":1581681600,\"main\":{\"temp\":9.03},\"weather\":[{\"description\":\"overcast clouds\"}]}," + "{\"dt\":1581692400,\"main\":{\"temp\":9.86},\"weather\":[{\"description\":\"overcast clouds\"}]}," + "{\"dt\":1581703200,\"main\":{\"temp\":9.48},\"weather\":[{\"description\":\"overcast clouds\"}]}," + "{\"dt\":1581714000,\"main\":{\"temp\":10.03},\"weather\":[{\"description\":\"moderate rain\"}]}," + "{\"dt\":1581724800,\"main\":{\"temp\":9.48},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581735600,\"main\":{\"temp\":9.12},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581746400,\"main\":{\"temp\":10.32},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581757200,\"main\":{\"temp\":11.57},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581768000,\"main\":{\"temp\":12.25},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581778800,\"main\":{\"temp\":12.19},\"weather\":[{\"description\":\"moderate rain\"}]}," + "{\"dt\":1581789600,\"main\":{\"temp\":12.25},\"weather\":[{\"description\":\"moderate rain\"}]}," + "{\"dt\":1581800400,\"main\":{\"temp\":12.64},\"weather\":[{\"description\":\"moderate rain\"}]}," + "{\"dt\":1581811200,\"main\":{\"temp\":12.96},\"weather\":[{\"description\":\"moderate rain\"}]}," + "{\"dt\":1581822000,\"main\":{\"temp\":13.13},\"weather\":[{\"description\":\"moderate rain\"}]}," + "{\"dt\":1581832800,\"main\":{\"temp\":9.07},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581843600,\"main\":{\"temp\":8.05},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581854400,\"main\":{\"temp\":9.54},\"weather\":[{\"description\":\"overcast clouds\"}]}," + "{\"dt\":1581865200,\"main\":{\"temp\":9.08},\"weather\":[{\"description\":\"light rain\"}]}," + "{\"dt\":1581876000,\"main\":{\"temp\":7.41},\"weather\":[{\"description\":\"overcast clouds\"}]}," + "{\"dt\":1581886800,\"main\":{\"temp\":6.42},\"weather\":[{\"description\":\"broken clouds\"}]}," + "{\"dt\":1581897600,\"main\":{\"temp\":6.03},\"weather\":[{\"description\":\"scattered clouds\"}]}," + "{\"dt\":1581908400,\"main\":{\"temp\":5.62},\"weather\":[{\"description\":\"clear sky\"}]}," + "{\"dt\":1581919200,\"main\":{\"temp\":5.51},\"weather\":[{\"description\":\"scattered clouds\"}]}" + "]}"; + // clang-format on + + StaticJsonDocument<512> filter; + filter["list"][0]["dt"] = true; + filter["list"][0]["main"]["temp"] = true; + filter["list"][0]["weather"][0]["description"] = true; + + DynamicJsonDocument doc(16384); + + REQUIRE( + deserializeJson(doc, input_json, DeserializationOption::Filter(filter)) == + DeserializationError::Ok); + + REQUIRE(doc.as() == expected_json); +} diff --git a/lib/ArduinoJson-6.x/test/IntegrationTests/round_trip.cpp b/lib/ArduinoJson-6.x/extras/tests/IntegrationTests/round_trip.cpp similarity index 99% rename from lib/ArduinoJson-6.x/test/IntegrationTests/round_trip.cpp rename to lib/ArduinoJson-6.x/extras/tests/IntegrationTests/round_trip.cpp index fcd110642..9967f4228 100644 --- a/lib/ArduinoJson-6.x/test/IntegrationTests/round_trip.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/IntegrationTests/round_trip.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonArray/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/JsonArray/CMakeLists.txt similarity index 78% rename from lib/ArduinoJson-6.x/test/JsonArray/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/CMakeLists.txt index fdc2cd07b..dd2ac36fd 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(JsonArrayTests @@ -19,5 +19,4 @@ add_executable(JsonArrayTests undefined.cpp ) -target_link_libraries(JsonArrayTests catch) add_test(JsonArray JsonArrayTests) diff --git a/lib/ArduinoJson-6.x/test/JsonArray/add.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/add.cpp similarity index 98% rename from lib/ArduinoJson-6.x/test/JsonArray/add.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/add.cpp index bab86ed6f..4202fa9e1 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/add.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/add.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -102,13 +102,13 @@ TEST_CASE("JsonArray::add()") { SECTION("should duplicate char*") { array.add(const_cast("world")); - const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(6); + const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5); REQUIRE(expectedSize == doc.memoryUsage()); } SECTION("should duplicate std::string") { array.add(std::string("world")); - const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(6); + const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5); REQUIRE(expectedSize == doc.memoryUsage()); } diff --git a/lib/ArduinoJson-6.x/test/JsonArray/copyArray.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/copyArray.cpp similarity index 67% rename from lib/ArduinoJson-6.x/test/JsonArray/copyArray.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/copyArray.cpp index 1ead2b1ff..7455f8fe5 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/copyArray.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/copyArray.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -19,6 +19,18 @@ TEST_CASE("copyArray()") { REQUIRE(std::string("[1,2,3]") == json); } + SECTION("1D -> JsonDocument") { + DynamicJsonDocument doc(4096); + char json[32]; + int source[] = {1, 2, 3}; + + bool ok = copyArray(source, doc); + REQUIRE(ok); + + serializeJson(doc, json, sizeof(json)); + REQUIRE(std::string("[1,2,3]") == json); + } + SECTION("1D -> JsonArray, but not enough memory") { const size_t SIZE = JSON_ARRAY_SIZE(2); StaticJsonDocument doc; @@ -46,6 +58,18 @@ TEST_CASE("copyArray()") { REQUIRE(std::string("[[1,2,3],[4,5,6]]") == json); } + SECTION("2D -> JsonDocument") { + DynamicJsonDocument doc(4096); + char json[32]; + int source[][3] = {{1, 2, 3}, {4, 5, 6}}; + + bool ok = copyArray(source, doc); + REQUIRE(ok); + + serializeJson(doc, json, sizeof(json)); + REQUIRE(std::string("[[1,2,3],[4,5,6]]") == json); + } + SECTION("2D -> JsonArray, but not enough memory") { const size_t SIZE = JSON_ARRAY_SIZE(2) + JSON_ARRAY_SIZE(3) + JSON_ARRAY_SIZE(2); @@ -96,6 +120,22 @@ TEST_CASE("copyArray()") { REQUIRE(2 == destination[1]); } + SECTION("JsonDocument -> 1D") { + DynamicJsonDocument doc(4096); + char json[] = "[1,2,3]"; + DeserializationError err = deserializeJson(doc, json); + REQUIRE(err == DeserializationError::Ok); + + int destination[4] = {0}; + size_t result = copyArray(doc, destination); + + REQUIRE(3 == result); + REQUIRE(1 == destination[0]); + REQUIRE(2 == destination[1]); + REQUIRE(3 == destination[2]); + REQUIRE(0 == destination[3]); + } + SECTION("JsonArray -> 2D") { DynamicJsonDocument doc(4096); char json[] = "[[1,2],[3],[4]]"; @@ -114,4 +154,22 @@ TEST_CASE("copyArray()") { REQUIRE(4 == destination[2][0]); REQUIRE(0 == destination[2][1]); } + + SECTION("JsonDocument -> 2D") { + DynamicJsonDocument doc(4096); + char json[] = "[[1,2],[3],[4]]"; + + DeserializationError err = deserializeJson(doc, json); + REQUIRE(err == DeserializationError::Ok); + + int destination[3][2] = {{0}}; + copyArray(doc, destination); + + REQUIRE(1 == destination[0][0]); + REQUIRE(2 == destination[0][1]); + REQUIRE(3 == destination[1][0]); + REQUIRE(0 == destination[1][1]); + REQUIRE(4 == destination[2][0]); + REQUIRE(0 == destination[2][1]); + } } diff --git a/lib/ArduinoJson-6.x/test/JsonArray/createNested.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/createNested.cpp similarity index 92% rename from lib/ArduinoJson-6.x/test/JsonArray/createNested.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/createNested.cpp index efe069628..8f8d36991 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/createNested.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/createNested.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonArray/equals.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/equals.cpp similarity index 69% rename from lib/ArduinoJson-6.x/test/JsonArray/equals.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/equals.cpp index 8aa6c48d7..595bd6eaa 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/equals.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/equals.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -31,7 +31,7 @@ TEST_CASE("JsonArray::operator==()") { REQUIRE_FALSE(array1c == array2c); } - SECTION("should return false when RKS has more elements") { + SECTION("should return false when RHS has more elements") { array1.add(1); array2.add(1); array2.add(2); @@ -47,4 +47,23 @@ TEST_CASE("JsonArray::operator==()") { REQUIRE(array1 == array2); REQUIRE(array1c == array2c); } + + SECTION("should return false when RHS is null") { + JsonArray null; + + REQUIRE_FALSE(array1 == null); + } + + SECTION("should return false when LHS is null") { + JsonArray null; + + REQUIRE_FALSE(null == array1); + } + + SECTION("should return true when both are null") { + JsonArray null1; + JsonArray null2; + + REQUIRE(null1 == null2); + } } diff --git a/lib/ArduinoJson-6.x/test/JsonArray/get.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/get.cpp similarity index 88% rename from lib/ArduinoJson-6.x/test/JsonArray/get.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/get.cpp index 0b5956da9..39bb944e0 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/get.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/get.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/JsonArray/isNull.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/isNull.cpp new file mode 100644 index 000000000..ccf260ca8 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/isNull.cpp @@ -0,0 +1,58 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +TEST_CASE("JsonArray::isNull()") { + SECTION("returns true") { + JsonArray arr; + REQUIRE(arr.isNull() == true); + } + + SECTION("returns false") { + DynamicJsonDocument doc(4096); + JsonArray arr = doc.to(); + REQUIRE(arr.isNull() == false); + } +} + +TEST_CASE("JsonArrayConst::isNull()") { + SECTION("returns true") { + JsonArrayConst arr; + REQUIRE(arr.isNull() == true); + } + + SECTION("returns false") { + DynamicJsonDocument doc(4096); + JsonArrayConst arr = doc.to(); + REQUIRE(arr.isNull() == false); + } +} + +TEST_CASE("JsonArray::operator bool()") { + SECTION("returns false") { + JsonArray arr; + REQUIRE(static_cast(arr) == false); + } + + SECTION("returns true") { + DynamicJsonDocument doc(4096); + JsonArray arr = doc.to(); + REQUIRE(static_cast(arr) == true); + } +} + +TEST_CASE("JsonArrayConst::operator bool()") { + SECTION("returns false") { + JsonArrayConst arr; + REQUIRE(static_cast(arr) == false); + } + + SECTION("returns true") { + DynamicJsonDocument doc(4096); + JsonArrayConst arr = doc.to(); + REQUIRE(static_cast(arr) == true); + } +} diff --git a/lib/ArduinoJson-6.x/test/JsonArray/iterator.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/iterator.cpp similarity index 64% rename from lib/ArduinoJson-6.x/test/JsonArray/iterator.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/iterator.cpp index 9128e6a03..4fe31bff1 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/iterator.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/iterator.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -28,9 +28,25 @@ static void run_iterator_test() { } TEST_CASE("JsonArray::begin()/end()") { - run_iterator_test(); + SECTION("Non null JsonArray") { + run_iterator_test(); + } + + SECTION("Null JsonArray") { + JsonArray array; + + REQUIRE(array.begin() == array.end()); + } } TEST_CASE("JsonArrayConst::begin()/end()") { - run_iterator_test(); + SECTION("Non null JsonArrayConst") { + run_iterator_test(); + } + + SECTION("Null JsonArrayConst") { + JsonArrayConst array; + + REQUIRE(array.begin() == array.end()); + } } diff --git a/lib/ArduinoJson-6.x/test/JsonArray/memoryUsage.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/memoryUsage.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/JsonArray/memoryUsage.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/memoryUsage.cpp index fc0e4b10a..8b2ed3a23 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/memoryUsage.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/memoryUsage.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonArray/nesting.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/nesting.cpp similarity index 94% rename from lib/ArduinoJson-6.x/test/JsonArray/nesting.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/nesting.cpp index 0669036d8..9ad1ea259 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/nesting.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/nesting.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonArray/remove.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/remove.cpp similarity index 97% rename from lib/ArduinoJson-6.x/test/JsonArray/remove.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/remove.cpp index e9af64036..20203148d 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/remove.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/remove.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonArray/size.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/size.cpp similarity index 94% rename from lib/ArduinoJson-6.x/test/JsonArray/size.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/size.cpp index 6e320df9e..d94def6fa 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/size.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/size.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonArray/std_string.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/std_string.cpp similarity index 94% rename from lib/ArduinoJson-6.x/test/JsonArray/std_string.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/std_string.cpp index 0440a6fc8..e5303ff35 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/std_string.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/std_string.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonArray/subscript.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/subscript.cpp similarity index 89% rename from lib/ArduinoJson-6.x/test/JsonArray/subscript.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/subscript.cpp index 92051cf13..51e89627b 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/subscript.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/subscript.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -9,7 +9,20 @@ TEST_CASE("JsonArray::operator[]") { DynamicJsonDocument doc(4096); JsonArray array = doc.to(); - array.add(0); + + SECTION("Pad with null") { + array[2] = 2; + array[5] = 5; + REQUIRE(array.size() == 6); + REQUIRE(array[0].isNull() == true); + REQUIRE(array[1].isNull() == true); + REQUIRE(array[2].isNull() == false); + REQUIRE(array[3].isNull() == true); + REQUIRE(array[4].isNull() == true); + REQUIRE(array[5].isNull() == false); + REQUIRE(array[2] == 2); + REQUIRE(array[5] == 5); + } SECTION("int") { array[0] = 123; @@ -106,13 +119,13 @@ TEST_CASE("JsonArray::operator[]") { SECTION("should duplicate char*") { array[0] = const_cast("world"); - const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(6); + const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5); REQUIRE(expectedSize == doc.memoryUsage()); } SECTION("should duplicate std::string") { array[0] = std::string("world"); - const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(6); + const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5); REQUIRE(expectedSize == doc.memoryUsage()); } diff --git a/lib/ArduinoJson-6.x/test/JsonArray/undefined.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonArray/undefined.cpp similarity index 94% rename from lib/ArduinoJson-6.x/test/JsonArray/undefined.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonArray/undefined.cpp index 8f97356cd..b9eb37949 100644 --- a/lib/ArduinoJson-6.x/test/JsonArray/undefined.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonArray/undefined.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/CMakeLists.txt similarity index 72% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/CMakeLists.txt index 70e71db01..805ee0e86 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/CMakeLists.txt @@ -1,21 +1,23 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(JsonDeserializerTests array.cpp array_static.cpp DeserializationError.cpp + filter.cpp incomplete_input.cpp input_types.cpp - number.cpp invalid_input.cpp misc.cpp nestingLimit.cpp + number.cpp object.cpp object_static.cpp string.cpp ) -target_link_libraries(JsonDeserializerTests catch) +set_target_properties(JsonDeserializerTests PROPERTIES UNITY_BUILD OFF) + add_test(JsonDeserializer JsonDeserializerTests) diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/DeserializationError.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/DeserializationError.cpp similarity index 98% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/DeserializationError.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/DeserializationError.cpp index a89f0fb6a..a04f25a19 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/DeserializationError.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/DeserializationError.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/array.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/array.cpp similarity index 60% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/array.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/array.cpp index 4cfa00b84..a3b0a1466 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/array.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/array.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -170,155 +170,6 @@ TEST_CASE("deserialize JSON array") { } } - SECTION("Block comments") { - SECTION("Before opening bracket") { - DeserializationError err = - deserializeJson(doc, "/*COMMENT*/ [\"hello\"]"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(1 == arr.size()); - REQUIRE(arr[0] == "hello"); - } - - SECTION("After opening bracket") { - DeserializationError err = - deserializeJson(doc, "[/*COMMENT*/ \"hello\"]"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(1 == arr.size()); - REQUIRE(arr[0] == "hello"); - } - - SECTION("Before closing bracket") { - DeserializationError err = deserializeJson(doc, "[\"hello\"/*COMMENT*/]"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(1 == arr.size()); - REQUIRE(arr[0] == "hello"); - } - - SECTION("After closing bracket") { - DeserializationError err = deserializeJson(doc, "[\"hello\"]/*COMMENT*/"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(1 == arr.size()); - REQUIRE(arr[0] == "hello"); - } - - SECTION("Before comma") { - DeserializationError err = - deserializeJson(doc, "[\"hello\"/*COMMENT*/,\"world\"]"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(2 == arr.size()); - REQUIRE(arr[0] == "hello"); - REQUIRE(arr[1] == "world"); - } - - SECTION("After comma") { - DeserializationError err = - deserializeJson(doc, "[\"hello\",/*COMMENT*/ \"world\"]"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(2 == arr.size()); - REQUIRE(arr[0] == "hello"); - REQUIRE(arr[1] == "world"); - } - - SECTION("/*/") { - DeserializationError err = deserializeJson(doc, "[/*/\n]"); - REQUIRE(err == DeserializationError::IncompleteInput); - } - - SECTION("Unfinished comment") { - DeserializationError err = deserializeJson(doc, "[/*COMMENT]"); - REQUIRE(err == DeserializationError::IncompleteInput); - } - - SECTION("Final slash missing") { - DeserializationError err = deserializeJson(doc, "[/*COMMENT*]"); - REQUIRE(err == DeserializationError::IncompleteInput); - } - } - - SECTION("Trailing comments") { - SECTION("Before opening bracket") { - DeserializationError err = - deserializeJson(doc, "//COMMENT\n\t[\"hello\"]"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(1 == arr.size()); - REQUIRE(arr[0] == "hello"); - } - - SECTION("After opening bracket") { - DeserializationError err = deserializeJson(doc, "[//COMMENT\n\"hello\"]"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(1 == arr.size()); - REQUIRE(arr[0] == "hello"); - } - - SECTION("Before closing bracket") { - DeserializationError err = - deserializeJson(doc, "[\"hello\"//COMMENT\r\n]"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(1 == arr.size()); - REQUIRE(arr[0] == "hello"); - } - - SECTION("After closing bracket") { - DeserializationError err = deserializeJson(doc, "[\"hello\"]//COMMENT\n"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(1 == arr.size()); - REQUIRE(arr[0] == "hello"); - } - - SECTION("Before comma") { - DeserializationError err = - deserializeJson(doc, "[\"hello\"//COMMENT\n,\"world\"]"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(2 == arr.size()); - REQUIRE(arr[0] == "hello"); - REQUIRE(arr[1] == "world"); - } - - SECTION("After comma") { - DeserializationError err = - deserializeJson(doc, "[\"hello\",//COMMENT\n\"world\"]"); - JsonArray arr = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(2 == arr.size()); - REQUIRE(arr[0] == "hello"); - REQUIRE(arr[1] == "world"); - } - - SECTION("Invalid comment") { - DeserializationError err = deserializeJson(doc, "[/COMMENT\n]"); - REQUIRE(err == DeserializationError::InvalidInput); - } - - SECTION("End document with comment") { - DeserializationError err = deserializeJson(doc, "[//COMMENT"); - REQUIRE(err == DeserializationError::IncompleteInput); - } - } - SECTION("Premature null-terminator") { SECTION("After opening bracket") { DeserializationError err = deserializeJson(doc, "["); diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/array_static.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/array_static.cpp similarity index 95% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/array_static.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/array_static.cpp index cffce0869..574448c04 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/array_static.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/array_static.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -56,7 +56,7 @@ TEST_CASE("deserialize JSON array with a StaticJsonDocument") { deserializeJson(doc, " [ \"1234567\" ] "); - REQUIRE(JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(8) == doc.memoryUsage()); + REQUIRE(JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(7) == doc.memoryUsage()); // note: we use a string of 8 bytes to be sure that the StaticMemoryPool // will not insert bytes to enforce alignement } diff --git a/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/filter.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/filter.cpp new file mode 100644 index 000000000..7296e8860 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/filter.cpp @@ -0,0 +1,749 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#define ARDUINOJSON_ENABLE_COMMENTS 1 +#include +#include + +#include +#include + +TEST_CASE("Filtering") { + struct TestCase { + const char* input; + const char* filter; + uint8_t nestingLimit; + DeserializationError error; + const char* output; + size_t memoryUsage; + }; + + // clang-format off + TestCase testCases[] = { + { + "{\"hello\":\"world\"}", // 1. input + "null", // 2. filter + 10, // 3. nestingLimit + DeserializationError::Ok, // 4. error + "null", // 5. output + 0 // 6. memoryUsage + }, + { + "{\"hello\":\"world\"}", + "false", + 10, + DeserializationError::Ok, + "null", + 0 + }, + { + "{\"abcdefg\":\"hijklmn\"}", + "true", + 10, + DeserializationError::Ok, + "{\"abcdefg\":\"hijklmn\"}", + JSON_OBJECT_SIZE(1) + 16 + }, + { + "{\"hello\":\"world\"}", + "{}", + 10, + DeserializationError::Ok, + "{}", + JSON_OBJECT_SIZE(0) + }, + { + // Input in an object, but filter wants an array + "{\"hello\":\"world\"}", + "[]", + 10, + DeserializationError::Ok, + "null", + 0 + }, + { + // Input is an array, but filter wants an object + "[\"hello\",\"world\"]", + "{}", + 10, + DeserializationError::Ok, + "null", + 0 + }, + { + // Input is a bool, but filter wants an object + "true", + "{}", + 10, + DeserializationError::Ok, + "null", + 0 + }, + { + // Input is a string, but filter wants an object + "\"hello\"", + "{}", + 10, + DeserializationError::Ok, + "null", + 0 + }, + { + // skip an integer + "{\"an_integer\":666,example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // skip a float + "{\"a_float\":12.34e-6,example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // can skip a boolean + "{\"a_bool\":false,example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // can skip a double-quoted string + "{\"a_double_quoted_string\":\"hello\",example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // can skip a single-quoted string + "{\"a_single_quoted_string\":'hello',example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // can skip an empty array + "{\"an_empty_array\":[],example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // can skip an empty array with spaces in it + "{\"an_empty_array\":[\t],example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // can skip an array + "{\"an_array\":[1,2,3],example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // can skip an array with spaces in it + "{\"an_array\": [ 1 , 2 , 3 ] ,example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // can skip an empty object + "{\"an_empty_object\":{},example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // can skip an empty object with spaces in it + "{\"an_empty_object\":{ },example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // can skip an object + "{\"an_object\":{a:1,'b':2,\"c\":3},example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // skip an object with spaces in it + "{\"an_object\" : { a : 1 , 'b' : 2 , \"c\" : 3 } ,example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + "{\"an_integer\": 0,\"example\":{\"type\":\"int\",\"outcome\":42}}", + "{\"example\":{\"outcome\":true}}", + 10, + DeserializationError::Ok, + "{\"example\":{\"outcome\":42}}", + 2 * JSON_OBJECT_SIZE(1) + 16 + }, + { + // only the first element of array counts + "[1,2,3]", + "[true, false]", + 10, + DeserializationError::Ok, + "[1,2,3]", + JSON_ARRAY_SIZE(3) + }, + { + // only the first element of array counts + "[1,2,3]", + "[false, true]", + 10, + DeserializationError::Ok, + "[]", + JSON_ARRAY_SIZE(0) + }, + { + // filter members of object in array + "[{\"example\":1,\"ignore\":2},{\"example\":3,\"ignore\":4}]", + "[{\"example\":true}]", + 10, + DeserializationError::Ok, + "[{\"example\":1},{\"example\":3}]", + JSON_ARRAY_SIZE(2) + 2 * JSON_OBJECT_SIZE(1) + 16 + }, + { + "[',2,3]", + "[false,true]", + 10, + DeserializationError::IncompleteInput, + "[]", + JSON_ARRAY_SIZE(0) + }, + { + "[\",2,3]", + "[false,true]", + 10, + DeserializationError::IncompleteInput, + "[]", + JSON_ARRAY_SIZE(0) + }, + { + // detect errors in skipped value + "[!,2,\\]", + "[false]", + 10, + DeserializationError::InvalidInput, + "[]", + JSON_ARRAY_SIZE(0) + }, + { + // detect incomplete string event if it's skipped + "\"ABC", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, + { + // detect incomplete string event if it's skipped + "'ABC", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, + { + // handle escaped quotes + "'A\\'BC'", + "false", + 10, + DeserializationError::Ok, + "null", + 0 + }, + { + // handle escaped quotes + "\"A\\\"BC\"", + "false", + 10, + DeserializationError::Ok, + "null", + 0 + }, + { + // detect incomplete string in presence of escaped quotes + "'A\\'BC", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, + { + // detect incomplete string in presence of escaped quotes + "\"A\\\"BC", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, + { + // skip empty array + "[]", + "false", + 10, + DeserializationError::Ok, + "null", + 0 + }, + { + // skip empty array with spaces + " [ ] ", + "false", + 10, + DeserializationError::Ok, + "null", + 0 + }, + { + // bubble up element error even if array is skipped + "[1,'2,3]", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, + { + // bubble up member error even if object is skipped + "{'hello':'worl}", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, + { + // bubble up colon error even if object is skipped + "{'hello','world'}", + "false", + 10, + DeserializationError::InvalidInput, + "null", + 0 + }, + { + // bubble up key error even if object is skipped + "{'hello:1}", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, + { + // detect invalid value in skipped object + "{'hello':!}", + "false", + 10, + DeserializationError::InvalidInput, + "null", + 0 + }, + { + // ignore invalid value in skipped object + "{'hello':\\}", + "false", + 10, + DeserializationError::InvalidInput, + "null", + 0 + }, + { + // check nesting limit even for ignored objects + "{}", + "false", + 0, + DeserializationError::TooDeep, + "null", + 0 + }, + { + // check nesting limit even for ignored objects + "{'hello':{}}", + "false", + 1, + DeserializationError::TooDeep, + "null", + 0 + }, + { + // check nesting limit even for ignored values in objects + "{'hello':{}}", + "{}", + 1, + DeserializationError::TooDeep, + "{}", + JSON_OBJECT_SIZE(0) + }, + { + // check nesting limit even for ignored arrays + "[]", + "false", + 0, + DeserializationError::TooDeep, + "null", + 0 + }, + { + // check nesting limit even for ignored arrays + "[[]]", + "false", + 1, + DeserializationError::TooDeep, + "null", + 0 + }, + { + // check nesting limit even for ignored values in arrays + "[[]]", + "[]", + 1, + DeserializationError::TooDeep, + "[]", + JSON_ARRAY_SIZE(0) + }, + { + // supports back-slash at the end of skipped string + "\"hell\\", + "false", + 1, + DeserializationError::IncompleteInput, + "null", + 0 + }, + { + // invalid comment at after an element in a skipped array + "[1/]", + "false", + 10, + DeserializationError::InvalidInput, + "null", + 0 + }, + { + // incomplete comment at after an element in a skipped array + "[1/*]", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, + { + // missing comma in a skipped array + "[1 2]", + "false", + 10, + DeserializationError::InvalidInput, + "null", + 0 + }, + { + // invalid comment at the beginning of array + "[/1]", + "[false]", + 10, + DeserializationError::InvalidInput, + "[]", + JSON_ARRAY_SIZE(0) + }, + { + // incomplete comment at the begining of an array + "[/*]", + "[false]", + 10, + DeserializationError::IncompleteInput, + "[]", + JSON_ARRAY_SIZE(0) + }, + { + // invalid comment before key + "{/1:2}", + "{}", + 10, + DeserializationError::InvalidInput, + "{}", + JSON_OBJECT_SIZE(0) + }, + { + // incomplete comment before key + "{/*:2}", + "{}", + 10, + DeserializationError::IncompleteInput, + "{}", + JSON_OBJECT_SIZE(0) + }, + { + // invalid comment after key + "{\"example\"/1:2}", + "{}", + 10, + DeserializationError::InvalidInput, + "{}", + JSON_OBJECT_SIZE(0) + 8 + }, + { + // incomplete comment after key + "{\"example\"/*:2}", + "{}", + 10, + DeserializationError::IncompleteInput, + "{}", + JSON_OBJECT_SIZE(0) + 8 + }, + { + // invalid comment after colon + "{\"example\":/12}", + "{}", + 10, + DeserializationError::InvalidInput, + "{}", + JSON_OBJECT_SIZE(0) + }, + { + // incomplete comment after colon + "{\"example\":/*2}", + "{}", + 10, + DeserializationError::IncompleteInput, + "{}", + JSON_OBJECT_SIZE(0) + }, + { + // comment next to an integer + "{\"ignore\":1//,\"example\":2\n}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{}", + JSON_OBJECT_SIZE(0) + }, + { + // invalid comment after opening brace of a skipped object + "{/1:2}", + "false", + 10, + DeserializationError::InvalidInput, + "null", + 0 + }, + { + // incomplete after opening brace of a skipped object + "{/*:2}", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, + { + // invalid comment after key of a skipped object + "{\"example\"/:2}", + "false", + 10, + DeserializationError::InvalidInput, + "null", + 0 + }, + { + // incomplete after after key of a skipped object + "{\"example\"/*:2}", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, + { + // invalid comment after value in a skipped object + "{\"example\":2/}", + "false", + 10, + DeserializationError::InvalidInput, + "null", + 0 + }, + { + // incomplete after after value of a skipped object + "{\"example\":2/*}", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, + }; // clang-format on + + for (size_t i = 0; i < sizeof(testCases) / sizeof(testCases[0]); i++) { + CAPTURE(i); + + DynamicJsonDocument filter(256); + DynamicJsonDocument doc(256); + TestCase& tc = testCases[i]; + + CAPTURE(tc.filter); + REQUIRE(deserializeJson(filter, tc.filter) == DeserializationError::Ok); + + CAPTURE(tc.input); + CAPTURE(tc.nestingLimit); + CHECK(deserializeJson(doc, tc.input, DeserializationOption::Filter(filter), + DeserializationOption::NestingLimit( + tc.nestingLimit)) == tc.error); + + CHECK(doc.as() == tc.output); + CHECK(doc.memoryUsage() == tc.memoryUsage); + } +} + +TEST_CASE("Overloads") { + StaticJsonDocument<256> doc; + StaticJsonDocument<256> filter; + + using namespace DeserializationOption; + + // deserializeJson(..., Filter) + + SECTION("const char*, Filter") { + deserializeJson(doc, "{}", Filter(filter)); + } + + SECTION("const char*, size_t, Filter") { + deserializeJson(doc, "{}", 2, Filter(filter)); + } + + SECTION("const std::string&, Filter") { + deserializeJson(doc, std::string("{}"), Filter(filter)); + } + + SECTION("std::istream&, Filter") { + std::stringstream s("{}"); + deserializeJson(doc, s, Filter(filter)); + } + +#ifdef HAS_VARIABLE_LENGTH_ARRAY + SECTION("char[n], Filter") { + int i = 4; + char vla[i]; + strcpy(vla, "{}"); + deserializeJson(doc, vla, Filter(filter)); + } +#endif + + // deserializeJson(..., Filter, NestingLimit) + + SECTION("const char*, Filter, NestingLimit") { + deserializeJson(doc, "{}", Filter(filter), NestingLimit(5)); + } + + SECTION("const char*, size_t, Filter, NestingLimit") { + deserializeJson(doc, "{}", 2, Filter(filter), NestingLimit(5)); + } + + SECTION("const std::string&, Filter, NestingLimit") { + deserializeJson(doc, std::string("{}"), Filter(filter), NestingLimit(5)); + } + + SECTION("std::istream&, Filter, NestingLimit") { + std::stringstream s("{}"); + deserializeJson(doc, s, Filter(filter), NestingLimit(5)); + } + +#ifdef HAS_VARIABLE_LENGTH_ARRAY + SECTION("char[n], Filter, NestingLimit") { + int i = 4; + char vla[i]; + strcpy(vla, "{}"); + deserializeJson(doc, vla, Filter(filter), NestingLimit(5)); + } +#endif + + // deserializeJson(..., NestingLimit, Filter) + + SECTION("const char*, NestingLimit, Filter") { + deserializeJson(doc, "{}", NestingLimit(5), Filter(filter)); + } + + SECTION("const char*, size_t, NestingLimit, Filter") { + deserializeJson(doc, "{}", 2, NestingLimit(5), Filter(filter)); + } + + SECTION("const std::string&, NestingLimit, Filter") { + deserializeJson(doc, std::string("{}"), NestingLimit(5), Filter(filter)); + } + + SECTION("std::istream&, NestingLimit, Filter") { + std::stringstream s("{}"); + deserializeJson(doc, s, NestingLimit(5), Filter(filter)); + } + +#ifdef HAS_VARIABLE_LENGTH_ARRAY + SECTION("char[n], NestingLimit, Filter") { + int i = 4; + char vla[i]; + strcpy(vla, "{}"); + deserializeJson(doc, vla, NestingLimit(5), Filter(filter)); + } +#endif +} + +TEST_CASE("StringMover::reclaim()") { + StaticJsonDocument<200> filter; + filter["a"] = true; + filter["c"] = true; + char input[] = "{\"a\":1,\"b\":2,\"c\":1}"; + + StaticJsonDocument<200> doc; + deserializeJson(doc, input, DeserializationOption::Filter(filter)); + + REQUIRE(doc.as() == "{\"a\":1,\"c\":1}"); + + CHECK(input[0] == 'a'); + CHECK(input[1] == 0); + CHECK(input[2] == 'c'); + CHECK(input[3] == 0); +} diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/incomplete_input.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/incomplete_input.cpp similarity index 79% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/incomplete_input.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/incomplete_input.cpp index 50bb28238..026612118 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/incomplete_input.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/incomplete_input.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #define ARDUINOJSON_DECODE_UNICODE 1 @@ -13,7 +13,9 @@ TEST_CASE("Truncated JSON input") { // true "t", "tr", "tru", // null - "n", "nu", "nul"}; + "n", "nu", "nul", + // object + "{", "{a", "{a:", "{a:1", "{a:1,", "{a:1,"}; const size_t testCount = sizeof(testCases) / sizeof(testCases[0]); DynamicJsonDocument doc(4096); diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/input_types.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/input_types.cpp similarity index 58% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/input_types.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/input_types.cpp index 9b7fe4732..d367e1ad2 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/input_types.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/input_types.cpp @@ -1,11 +1,13 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include #include #include +#include "CustomReader.hpp" + TEST_CASE("deserializeJson(const std::string&)") { DynamicJsonDocument doc(4096); @@ -39,7 +41,7 @@ TEST_CASE("deserializeJson(std::istream&)") { DynamicJsonDocument doc(4096); SECTION("array") { - std::istringstream json(" [ 42 /* comment */ ] "); + std::istringstream json(" [ 42 ] "); DeserializationError err = deserializeJson(doc, json); JsonArray arr = doc.as(); @@ -50,7 +52,7 @@ TEST_CASE("deserializeJson(std::istream&)") { } SECTION("object") { - std::istringstream json(" { hello : 'world' // comment\n }"); + std::istringstream json(" { hello : 'world' }"); DeserializationError err = deserializeJson(doc, json); JsonObject obj = doc.as(); @@ -113,3 +115,68 @@ TEST_CASE("deserializeJson(VLA)") { REQUIRE(err == DeserializationError::Ok); } #endif + +TEST_CASE("deserializeJson(CustomReader)") { + DynamicJsonDocument doc(4096); + CustomReader reader("[4,2]"); + DeserializationError err = deserializeJson(doc, reader); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(doc.size() == 2); + REQUIRE(doc[0] == 4); + REQUIRE(doc[1] == 2); +} + +TEST_CASE("deserializeJson(JsonDocument&, MemberProxy)") { + DynamicJsonDocument doc1(4096); + doc1["payload"] = "[4,2]"; + + DynamicJsonDocument doc2(4096); + DeserializationError err = deserializeJson(doc2, doc1["payload"]); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(doc2.size() == 2); + REQUIRE(doc2[0] == 4); + REQUIRE(doc2[1] == 2); +} + +TEST_CASE("deserializeJson(JsonDocument&, JsonVariant)") { + DynamicJsonDocument doc1(4096); + doc1["payload"] = "[4,2]"; + + DynamicJsonDocument doc2(4096); + DeserializationError err = + deserializeJson(doc2, doc1["payload"].as()); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(doc2.size() == 2); + REQUIRE(doc2[0] == 4); + REQUIRE(doc2[1] == 2); +} + +TEST_CASE("deserializeJson(JsonDocument&, JsonVariantConst)") { + DynamicJsonDocument doc1(4096); + doc1["payload"] = "[4,2]"; + + DynamicJsonDocument doc2(4096); + DeserializationError err = + deserializeJson(doc2, doc1["payload"].as()); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(doc2.size() == 2); + REQUIRE(doc2[0] == 4); + REQUIRE(doc2[1] == 2); +} + +TEST_CASE("deserializeJson(JsonDocument&, ElementProxy)") { + DynamicJsonDocument doc1(4096); + doc1[0] = "[4,2]"; + + DynamicJsonDocument doc2(4096); + DeserializationError err = deserializeJson(doc2, doc1[0]); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(doc2.size() == 2); + REQUIRE(doc2[0] == 4); + REQUIRE(doc2[1] == 2); +} diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/invalid_input.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/invalid_input.cpp similarity index 75% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/invalid_input.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/invalid_input.cpp index 8e5dec9be..ad7236da7 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/invalid_input.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/invalid_input.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #define ARDUINOJSON_DECODE_UNICODE 1 @@ -22,7 +22,14 @@ TEST_CASE("Invalid JSON input") { } TEST_CASE("Invalid JSON input that should pass") { - const char* testCases[] = {"nulL", "tru3", "fals3"}; + const char* testCases[] = { + "nulL", + "tru3", + "fals3", + "'\\ud83d'", // leading surrogate without a trailing surrogate + "'\\udda4'", // trailing surrogate without a leading surrogate + "'\\ud83d\\ud83d'", // two leading surrogates + }; const size_t testCount = sizeof(testCases) / sizeof(testCases[0]); DynamicJsonDocument doc(4096); diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/misc.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/misc.cpp similarity index 75% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/misc.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/misc.cpp index d8c6e010c..0fe0e9413 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/misc.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/misc.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -61,26 +61,6 @@ TEST_CASE("deserializeJson(DynamicJsonDocument&)") { } } - SECTION("Comments") { - SECTION("Just a trailing comment") { - DeserializationError err = deserializeJson(doc, "// comment"); - - REQUIRE(err == DeserializationError::IncompleteInput); - } - - SECTION("Just a block comment") { - DeserializationError err = deserializeJson(doc, "/*comment*/"); - - REQUIRE(err == DeserializationError::IncompleteInput); - } - - SECTION("Just a slash") { - DeserializationError err = deserializeJson(doc, "/"); - - REQUIRE(err == DeserializationError::InvalidInput); - } - } - SECTION("Premature null-terminator") { SECTION("In escape sequence") { DeserializationError err = deserializeJson(doc, "\"\\"); @@ -88,12 +68,6 @@ TEST_CASE("deserializeJson(DynamicJsonDocument&)") { REQUIRE(err == DeserializationError::IncompleteInput); } - SECTION("In block comment") { - DeserializationError err = deserializeJson(doc, "/* comment"); - - REQUIRE(err == DeserializationError::IncompleteInput); - } - SECTION("In double quoted string") { DeserializationError err = deserializeJson(doc, "\"hello"); @@ -114,12 +88,6 @@ TEST_CASE("deserializeJson(DynamicJsonDocument&)") { REQUIRE(err == DeserializationError::IncompleteInput); } - SECTION("In block comment") { - DeserializationError err = deserializeJson(doc, "/* comment */", 10); - - REQUIRE(err == DeserializationError::IncompleteInput); - } - SECTION("In double quoted string") { DeserializationError err = deserializeJson(doc, "\"hello\"", 6); diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/nestingLimit.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/nestingLimit.cpp similarity index 99% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/nestingLimit.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/nestingLimit.cpp index 9eb95b306..841a08b94 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/nestingLimit.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/nestingLimit.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/number.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/number.cpp similarity index 98% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/number.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/number.cpp index 45a946cb4..d0f1c6f51 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/number.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/number.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #define ARDUINOJSON_USE_LONG_LONG 0 diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/object.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/object.cpp similarity index 57% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/object.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/object.cpp index 739f6d6d5..d6981d417 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/object.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/object.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -277,212 +277,7 @@ TEST_CASE("deserialize JSON object") { DeserializationError err = deserializeJson(doc, "{a:{b:{c:1}},a:2}"); REQUIRE(err == DeserializationError::Ok); - } - } - - SECTION("Block comments") { - SECTION("Before opening brace") { - DeserializationError err = - deserializeJson(doc, "/*COMMENT*/ {\"hello\":\"world\"}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("After opening brace") { - DeserializationError err = - deserializeJson(doc, "{/*COMMENT*/\"hello\":\"world\"}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("Before colon") { - DeserializationError err = - deserializeJson(doc, "{\"hello\"/*COMMENT*/:\"world\"}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("After colon") { - DeserializationError err = - deserializeJson(doc, "{\"hello\":/*COMMENT*/\"world\"}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("Before closing brace") { - DeserializationError err = - deserializeJson(doc, "{\"hello\":\"world\"/*COMMENT*/}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("After closing brace") { - DeserializationError err = - deserializeJson(doc, "{\"hello\":\"world\"}/*COMMENT*/"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("Before comma") { - DeserializationError err = deserializeJson( - doc, "{\"hello\":\"world\"/*COMMENT*/,\"answer\":42}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - REQUIRE(obj["answer"] == 42); - } - - SECTION("After comma") { - DeserializationError err = deserializeJson( - doc, "{\"hello\":\"world\",/*COMMENT*/\"answer\":42}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - REQUIRE(obj["answer"] == 42); - } - } - - SECTION("Trailing comments") { - SECTION("Before opening brace") { - DeserializationError err = - deserializeJson(doc, "//COMMENT\n {\"hello\":\"world\"}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("After opening brace") { - DeserializationError err = - deserializeJson(doc, "{//COMMENT\n\"hello\":\"world\"}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("Before colon") { - DeserializationError err = - deserializeJson(doc, "{\"hello\"//COMMENT\n:\"world\"}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("After colon") { - DeserializationError err = - deserializeJson(doc, "{\"hello\"://COMMENT\n\"world\"}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("Before closing brace") { - DeserializationError err = - deserializeJson(doc, "{\"hello\":\"world\"//COMMENT\n}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("After closing brace") { - DeserializationError err = - deserializeJson(doc, "{\"hello\":\"world\"}//COMMENT\n"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("Before comma") { - DeserializationError err = deserializeJson( - doc, "{\"hello\":\"world\"//COMMENT\n,\"answer\":42}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - REQUIRE(obj["answer"] == 42); - } - - SECTION("After comma") { - DeserializationError err = deserializeJson( - doc, "{\"hello\":\"world\",//COMMENT\n\"answer\":42}"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - REQUIRE(obj["answer"] == 42); - } - } - - SECTION("Dangling slash") { - SECTION("Before opening brace") { - DeserializationError err = deserializeJson(doc, "/{\"hello\":\"world\"}"); - - REQUIRE(err == DeserializationError::InvalidInput); - } - - SECTION("After opening brace") { - DeserializationError err = deserializeJson(doc, "{/\"hello\":\"world\"}"); - - REQUIRE(err == DeserializationError::InvalidInput); - } - - SECTION("Before colon") { - DeserializationError err = deserializeJson(doc, "{\"hello\"/:\"world\"}"); - - REQUIRE(err == DeserializationError::InvalidInput); - } - - SECTION("After colon") { - DeserializationError err = deserializeJson(doc, "{\"hello\":/\"world\"}"); - - REQUIRE(err == DeserializationError::InvalidInput); - } - - SECTION("Before closing brace") { - DeserializationError err = deserializeJson(doc, "{\"hello\":\"world\"/}"); - - REQUIRE(err == DeserializationError::InvalidInput); - } - - SECTION("After closing brace") { - DeserializationError err = deserializeJson(doc, "{\"hello\":\"world\"}/"); - JsonObject obj = doc.as(); - - REQUIRE(err == DeserializationError::Ok); - REQUIRE(obj["hello"] == "world"); - } - - SECTION("Before comma") { - DeserializationError err = - deserializeJson(doc, "{\"hello\":\"world\"/,\"answer\":42}"); - - REQUIRE(err == DeserializationError::InvalidInput); - } - - SECTION("After comma") { - DeserializationError err = - deserializeJson(doc, "{\"hello\":\"world\",/\"answer\":42}"); - - REQUIRE(err == DeserializationError::InvalidInput); + REQUIRE(doc["a"] == 2); } } diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/object_static.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/object_static.cpp similarity index 97% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/object_static.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/object_static.cpp index 5d7346bcc..a83e58d1f 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/object_static.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/object_static.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonDeserializer/string.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/string.cpp similarity index 59% rename from lib/ArduinoJson-6.x/test/JsonDeserializer/string.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/string.cpp index 26bb43949..7b5fdbfb0 100644 --- a/lib/ArduinoJson-6.x/test/JsonDeserializer/string.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDeserializer/string.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #define ARDUINOJSON_DECODE_UNICODE 1 @@ -15,12 +15,23 @@ TEST_CASE("Valid JSON strings value") { TestCase testCases[] = { {"\"hello world\"", "hello world"}, {"\'hello world\'", "hello world"}, + {"'\"'", "\""}, + {"'\\\\'", "\\"}, + {"'\\/'", "/"}, + {"'\\b'", "\b"}, + {"'\\f'", "\f"}, + {"'\\n'", "\n"}, + {"'\\r'", "\r"}, + {"'\\t'", "\t"}, {"\"1\\\"2\\\\3\\/4\\b5\\f6\\n7\\r8\\t9\"", "1\"2\\3/4\b5\f6\n7\r8\t9"}, {"'\\u0041'", "A"}, - {"'\\u00e4'", "\xc3\xa4"}, // ä - {"'\\u00E4'", "\xc3\xa4"}, // ä - {"'\\u3042'", "\xe3\x81\x82"}, // あ - + {"'\\u00e4'", "\xc3\xa4"}, // ä + {"'\\u00E4'", "\xc3\xa4"}, // ä + {"'\\u3042'", "\xe3\x81\x82"}, // あ + {"'\\ud83d\\udda4'", "\xf0\x9f\x96\xa4"}, // 🖤 + {"'\\uF053'", "\xef\x81\x93"}, // issue #1173 + {"'\\uF015'", "\xef\x80\x95"}, // issue #1173 + {"'\\uF054'", "\xef\x81\x94"}, // issue #1173 }; const size_t testCount = sizeof(testCases) / sizeof(testCases[0]); @@ -30,8 +41,8 @@ TEST_CASE("Valid JSON strings value") { const TestCase& testCase = testCases[i]; CAPTURE(testCase.input); DeserializationError err = deserializeJson(doc, testCase.input); - REQUIRE(err == DeserializationError::Ok); - REQUIRE(doc.as() == testCase.expectedOutput); + CHECK(err == DeserializationError::Ok); + CHECK(doc.as() == testCase.expectedOutput); } } @@ -51,7 +62,7 @@ TEST_CASE("Truncated JSON string") { TEST_CASE("Invalid JSON string") { const char* testCases[] = {"'\\u'", "'\\u000g'", "'\\u000'", - "'\\u000G'", "'\\u000/'", "\\x1234"}; + "'\\u000G'", "'\\u000/'", "'\\x1234'"}; const size_t testCount = sizeof(testCases) / sizeof(testCases[0]); DynamicJsonDocument doc(4096); @@ -64,9 +75,15 @@ TEST_CASE("Invalid JSON string") { } TEST_CASE("Not enough room to duplicate the string") { - DynamicJsonDocument doc(4); + DynamicJsonDocument doc(JSON_OBJECT_SIZE(0)); - REQUIRE(deserializeJson(doc, "\"hello world!\"") == - DeserializationError::NoMemory); - REQUIRE(doc.isNull() == true); + SECTION("Quoted string") { + REQUIRE(deserializeJson(doc, "{\"example\":1}") == + DeserializationError::NoMemory); + } + + SECTION("Non-quoted string") { + REQUIRE(deserializeJson(doc, "{example:1}") == + DeserializationError::NoMemory); + } } diff --git a/lib/ArduinoJson-6.x/extras/tests/JsonDocument/BasicJsonDocument.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/BasicJsonDocument.cpp new file mode 100644 index 000000000..6f068f4d6 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/BasicJsonDocument.cpp @@ -0,0 +1,157 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include // malloc, free +#include +#include + +using ARDUINOJSON_NAMESPACE::addPadding; +using ARDUINOJSON_NAMESPACE::move; + +class SpyingAllocator { + public: + SpyingAllocator(const SpyingAllocator& src) : _log(src._log) {} + SpyingAllocator(std::ostream& log) : _log(log) {} + + void* allocate(size_t n) { + _log << "A" << n; + return malloc(n); + } + void deallocate(void* p) { + _log << "F"; + free(p); + } + + private: + SpyingAllocator& operator=(const SpyingAllocator& src); + + std::ostream& _log; +}; + +class ControllableAllocator { + public: + ControllableAllocator() : _enabled(true) {} + + void* allocate(size_t n) { + return _enabled ? malloc(n) : 0; + } + + void deallocate(void* p) { + free(p); + } + + void disable() { + _enabled = false; + } + + private: + bool _enabled; +}; + +TEST_CASE("BasicJsonDocument") { + std::stringstream log; + + SECTION("Construct/Destruct") { + { BasicJsonDocument doc(4096, log); } + REQUIRE(log.str() == "A4096F"); + } + + SECTION("Copy construct") { + { + BasicJsonDocument doc1(4096, log); + doc1.set(std::string("The size of this string is 32!!")); + + BasicJsonDocument doc2(doc1); + + REQUIRE(doc1.as() == "The size of this string is 32!!"); + REQUIRE(doc2.as() == "The size of this string is 32!!"); + REQUIRE(doc2.capacity() == 4096); + } + REQUIRE(log.str() == "A4096A4096FF"); + } + +#if ARDUINOJSON_HAS_RVALUE_REFERENCES + SECTION("Move construct") { + { + BasicJsonDocument doc1(4096, log); + doc1.set(std::string("The size of this string is 32!!")); + + BasicJsonDocument doc2(move(doc1)); + + REQUIRE(doc2.as() == "The size of this string is 32!!"); + REQUIRE(doc1.as() == "null"); + REQUIRE(doc1.capacity() == 0); + REQUIRE(doc2.capacity() == 4096); + } + REQUIRE(log.str() == "A4096F"); + } +#endif + + SECTION("Copy assign") { + { + BasicJsonDocument doc1(4096, log); + doc1.set(std::string("The size of this string is 32!!")); + BasicJsonDocument doc2(8, log); + + doc2 = doc1; + + REQUIRE(doc1.as() == "The size of this string is 32!!"); + REQUIRE(doc2.as() == "The size of this string is 32!!"); + REQUIRE(doc2.capacity() == 4096); + } + REQUIRE(log.str() == "A4096A8FA4096FF"); + } + +#if ARDUINOJSON_HAS_RVALUE_REFERENCES + SECTION("Move assign") { + { + BasicJsonDocument doc1(4096, log); + doc1.set(std::string("The size of this string is 32!!")); + BasicJsonDocument doc2(8, log); + + doc2 = move(doc1); + + REQUIRE(doc2.as() == "The size of this string is 32!!"); + REQUIRE(doc1.as() == "null"); + REQUIRE(doc1.capacity() == 0); + REQUIRE(doc2.capacity() == 4096); + } + REQUIRE(log.str() == "A4096A8FF"); + } +#endif + + SECTION("garbageCollect()") { + BasicJsonDocument doc(4096); + + SECTION("when allocation succeeds") { + deserializeJson(doc, "{\"blanket\":1,\"dancing\":2}"); + REQUIRE(doc.capacity() == 4096); + REQUIRE(doc.memoryUsage() == JSON_OBJECT_SIZE(2) + 16); + doc.remove("blanket"); + + bool result = doc.garbageCollect(); + + REQUIRE(result == true); + REQUIRE(doc.memoryUsage() == JSON_OBJECT_SIZE(1) + 8); + REQUIRE(doc.capacity() == 4096); + REQUIRE(doc.as() == "{\"dancing\":2}"); + } + + SECTION("when allocation fails") { + deserializeJson(doc, "{\"blanket\":1,\"dancing\":2}"); + REQUIRE(doc.capacity() == 4096); + REQUIRE(doc.memoryUsage() == JSON_OBJECT_SIZE(2) + 16); + doc.remove("blanket"); + doc.allocator().disable(); + + bool result = doc.garbageCollect(); + + REQUIRE(result == false); + REQUIRE(doc.memoryUsage() == JSON_OBJECT_SIZE(2) + 16); + REQUIRE(doc.capacity() == 4096); + REQUIRE(doc.as() == "{\"dancing\":2}"); + } + } +} diff --git a/lib/ArduinoJson-6.x/test/JsonDocument/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/CMakeLists.txt similarity index 78% rename from lib/ArduinoJson-6.x/test/JsonDocument/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/JsonDocument/CMakeLists.txt index 2bf05cf92..5a083a688 100644 --- a/lib/ArduinoJson-6.x/test/JsonDocument/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/CMakeLists.txt @@ -1,20 +1,21 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(JsonDocumentTests add.cpp BasicJsonDocument.cpp + compare.cpp containsKey.cpp createNested.cpp DynamicJsonDocument.cpp isNull.cpp nesting.cpp remove.cpp + shrinkToFit.cpp size.cpp StaticJsonDocument.cpp subscript.cpp ) -target_link_libraries(JsonDocumentTests catch) add_test(JsonDocument JsonDocumentTests) diff --git a/lib/ArduinoJson-6.x/test/JsonDocument/DynamicJsonDocument.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/DynamicJsonDocument.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/JsonDocument/DynamicJsonDocument.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDocument/DynamicJsonDocument.cpp index ddbdd4e77..6c71eb8e6 100644 --- a/lib/ArduinoJson-6.x/test/JsonDocument/DynamicJsonDocument.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/DynamicJsonDocument.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -91,7 +91,7 @@ TEST_CASE("DynamicJsonDocument constructor") { REQUIRE_JSON(doc2, "{\"hello\":\"world\"}"); - REQUIRE(doc2.capacity() == addPadding(doc1.memoryUsage())); + REQUIRE(doc2.capacity() == doc1.capacity()); } SECTION("Construct from StaticJsonDocument") { @@ -101,7 +101,7 @@ TEST_CASE("DynamicJsonDocument constructor") { DynamicJsonDocument doc2 = doc1; REQUIRE_JSON(doc2, "{\"hello\":\"world\"}"); - REQUIRE(doc2.capacity() == addPadding(doc1.memoryUsage())); + REQUIRE(doc2.capacity() == doc1.capacity()); } SECTION("Construct from JsonObject") { diff --git a/lib/ArduinoJson-6.x/test/JsonDocument/StaticJsonDocument.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/StaticJsonDocument.cpp similarity index 93% rename from lib/ArduinoJson-6.x/test/JsonDocument/StaticJsonDocument.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDocument/StaticJsonDocument.cpp index e393a3191..dc6a1d41a 100644 --- a/lib/ArduinoJson-6.x/test/JsonDocument/StaticJsonDocument.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/StaticJsonDocument.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -209,4 +209,16 @@ TEST_CASE("StaticJsonDocument") { REQUIRE_JSON(doc2, "42"); } } + + SECTION("garbageCollect()") { + StaticJsonDocument<256> doc; + doc[std::string("example")] = std::string("example"); + doc.remove("example"); + REQUIRE(doc.memoryUsage() == JSON_OBJECT_SIZE(1) + 16); + + doc.garbageCollect(); + + REQUIRE(doc.memoryUsage() == JSON_OBJECT_SIZE(0)); + REQUIRE_JSON(doc, "{}"); + } } diff --git a/lib/ArduinoJson-6.x/test/JsonDocument/add.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/add.cpp similarity index 90% rename from lib/ArduinoJson-6.x/test/JsonDocument/add.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDocument/add.cpp index 31ec53f20..8d85563cf 100644 --- a/lib/ArduinoJson-6.x/test/JsonDocument/add.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/add.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/JsonDocument/compare.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/compare.cpp new file mode 100644 index 000000000..d31570b6f --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/compare.cpp @@ -0,0 +1,77 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +TEST_CASE("DynamicJsonDocument::operator==(const DynamicJsonDocument&)") { + DynamicJsonDocument doc1(4096); + DynamicJsonDocument doc2(4096); + + SECTION("Empty") { + REQUIRE(doc1 == doc2); + REQUIRE_FALSE(doc1 != doc2); + } + + SECTION("With same object") { + doc1["hello"] = "world"; + doc2["hello"] = "world"; + REQUIRE(doc1 == doc2); + REQUIRE_FALSE(doc1 != doc2); + } + SECTION("With different object") { + doc1["hello"] = "world"; + doc2["world"] = "hello"; + REQUIRE_FALSE(doc1 == doc2); + REQUIRE(doc1 != doc2); + } +} + +TEST_CASE("DynamicJsonDocument::operator==(const StaticJsonDocument&)") { + DynamicJsonDocument doc1(4096); + StaticJsonDocument<256> doc2; + + SECTION("Empty") { + REQUIRE(doc1 == doc2); + REQUIRE_FALSE(doc1 != doc2); + } + + SECTION("With same object") { + doc1["hello"] = "world"; + doc2["hello"] = "world"; + REQUIRE(doc1 == doc2); + REQUIRE_FALSE(doc1 != doc2); + } + + SECTION("With different object") { + doc1["hello"] = "world"; + doc2["world"] = "hello"; + REQUIRE_FALSE(doc1 == doc2); + REQUIRE(doc1 != doc2); + } +} + +TEST_CASE("StaticJsonDocument::operator==(const DynamicJsonDocument&)") { + StaticJsonDocument<256> doc1; + DynamicJsonDocument doc2(4096); + + SECTION("Empty") { + REQUIRE(doc1 == doc2); + REQUIRE_FALSE(doc1 != doc2); + } + + SECTION("With same object") { + doc1["hello"] = "world"; + doc2["hello"] = "world"; + REQUIRE(doc1 == doc2); + REQUIRE_FALSE(doc1 != doc2); + } + + SECTION("With different object") { + doc1["hello"] = "world"; + doc2["world"] = "hello"; + REQUIRE_FALSE(doc1 == doc2); + REQUIRE(doc1 != doc2); + } +} diff --git a/lib/ArduinoJson-6.x/test/JsonDocument/containsKey.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/containsKey.cpp similarity index 95% rename from lib/ArduinoJson-6.x/test/JsonDocument/containsKey.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDocument/containsKey.cpp index 6b48831c3..b82c9a386 100644 --- a/lib/ArduinoJson-6.x/test/JsonDocument/containsKey.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/containsKey.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonDocument/createNested.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/createNested.cpp similarity index 97% rename from lib/ArduinoJson-6.x/test/JsonDocument/createNested.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDocument/createNested.cpp index 1e3adb968..a5e0afba8 100644 --- a/lib/ArduinoJson-6.x/test/JsonDocument/createNested.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/createNested.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonDocument/isNull.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/isNull.cpp similarity index 95% rename from lib/ArduinoJson-6.x/test/JsonDocument/isNull.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDocument/isNull.cpp index 47dc28685..8506187df 100644 --- a/lib/ArduinoJson-6.x/test/JsonDocument/isNull.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/isNull.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonDocument/nesting.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/nesting.cpp similarity index 93% rename from lib/ArduinoJson-6.x/test/JsonDocument/nesting.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDocument/nesting.cpp index 148b49daa..fe2f724e0 100644 --- a/lib/ArduinoJson-6.x/test/JsonDocument/nesting.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/nesting.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonDocument/remove.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/remove.cpp similarity index 95% rename from lib/ArduinoJson-6.x/test/JsonDocument/remove.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDocument/remove.cpp index 0c9b9e14b..ff2804e84 100644 --- a/lib/ArduinoJson-6.x/test/JsonDocument/remove.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/remove.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/JsonDocument/shrinkToFit.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/shrinkToFit.cpp new file mode 100644 index 000000000..615912a3b --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/shrinkToFit.cpp @@ -0,0 +1,154 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +#include // malloc, free +#include + +using ARDUINOJSON_NAMESPACE::addPadding; + +class ArmoredAllocator { + public: + ArmoredAllocator() : _ptr(0), _size(0) {} + + void* allocate(size_t size) { + _ptr = malloc(size); + _size = size; + return _ptr; + } + + void deallocate(void* ptr) { + REQUIRE(ptr == _ptr); + free(ptr); + _ptr = 0; + _size = 0; + } + + void* reallocate(void* ptr, size_t new_size) { + REQUIRE(ptr == _ptr); + // don't call realloc, instead alloc a new buffer and erase the old one + // this way we make sure we support relocation + void* new_ptr = malloc(new_size); + memcpy(new_ptr, _ptr, std::min(new_size, _size)); + memset(_ptr, '#', _size); // erase + free(_ptr); + _ptr = new_ptr; + return new_ptr; + } + + private: + void* _ptr; + size_t _size; +}; + +typedef BasicJsonDocument ShrinkToFitTestDocument; + +void testShrinkToFit(ShrinkToFitTestDocument& doc, std::string expected_json, + size_t expected_size) { + // test twice: shrinkToFit() should be idempotent + for (int i = 0; i < 2; i++) { + doc.shrinkToFit(); + + REQUIRE(doc.capacity() == expected_size); + REQUIRE(doc.memoryUsage() == expected_size); + + std::string json; + serializeJson(doc, json); + REQUIRE(json == expected_json); + } +} + +TEST_CASE("BasicJsonDocument::shrinkToFit()") { + ShrinkToFitTestDocument doc(4096); + + SECTION("null") { + testShrinkToFit(doc, "null", 0); + } + + SECTION("empty object") { + deserializeJson(doc, "{}"); + testShrinkToFit(doc, "{}", JSON_OBJECT_SIZE(0)); + } + + SECTION("empty array") { + deserializeJson(doc, "[]"); + testShrinkToFit(doc, "[]", JSON_ARRAY_SIZE(0)); + } + + SECTION("linked string") { + doc.set("hello"); + testShrinkToFit(doc, "\"hello\"", 0); + } + + SECTION("owned string") { + doc.set(std::string("abcdefg")); + testShrinkToFit(doc, "\"abcdefg\"", 8); + } + + SECTION("linked raw") { + doc.set(serialized("[{},123]")); + testShrinkToFit(doc, "[{},123]", 0); + } + + SECTION("owned raw") { + doc.set(serialized(std::string("[{},12]"))); + testShrinkToFit(doc, "[{},12]", 8); + } + + SECTION("linked key") { + doc["key"] = 42; + testShrinkToFit(doc, "{\"key\":42}", JSON_OBJECT_SIZE(1)); + } + + SECTION("owned key") { + doc[std::string("abcdefg")] = 42; + testShrinkToFit(doc, "{\"abcdefg\":42}", JSON_OBJECT_SIZE(1) + 8); + } + + SECTION("linked string in array") { + doc.add("hello"); + testShrinkToFit(doc, "[\"hello\"]", JSON_ARRAY_SIZE(1)); + } + + SECTION("owned string in array") { + doc.add(std::string("abcdefg")); + testShrinkToFit(doc, "[\"abcdefg\"]", JSON_ARRAY_SIZE(1) + 8); + } + + SECTION("linked string in object") { + doc["key"] = "hello"; + testShrinkToFit(doc, "{\"key\":\"hello\"}", JSON_OBJECT_SIZE(1)); + } + + SECTION("owned string in object") { + doc["key"] = std::string("abcdefg"); + testShrinkToFit(doc, "{\"key\":\"abcdefg\"}", JSON_ARRAY_SIZE(1) + 8); + } + + SECTION("unaligned") { + doc.add(std::string("?")); // two bytes in the string pool + REQUIRE(doc.memoryUsage() == JSON_OBJECT_SIZE(1) + 2); + + doc.shrinkToFit(); + + // the new capacity should be padded to align the pointers + REQUIRE(doc.capacity() == JSON_OBJECT_SIZE(1) + sizeof(void*)); + REQUIRE(doc.memoryUsage() == JSON_OBJECT_SIZE(1) + 2); + REQUIRE(doc[0] == "?"); + } +} + +TEST_CASE("DynamicJsonDocument::shrinkToFit()") { + DynamicJsonDocument doc(4096); + + deserializeJson(doc, "{\"hello\":[\"world\"]"); + + doc.shrinkToFit(); + + std::string json; + serializeJson(doc, json); + REQUIRE(json == "{\"hello\":[\"world\"]}"); +} diff --git a/lib/ArduinoJson-6.x/test/JsonDocument/size.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/size.cpp similarity index 91% rename from lib/ArduinoJson-6.x/test/JsonDocument/size.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDocument/size.cpp index 1366eb7b6..589f94f02 100644 --- a/lib/ArduinoJson-6.x/test/JsonDocument/size.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/size.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonDocument/subscript.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/subscript.cpp similarity index 83% rename from lib/ArduinoJson-6.x/test/JsonDocument/subscript.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonDocument/subscript.cpp index 3955bba66..a4554cd24 100644 --- a/lib/ArduinoJson-6.x/test/JsonDocument/subscript.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonDocument/subscript.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -43,3 +43,11 @@ TEST_CASE("JsonDocument automatically promotes to object") { REQUIRE(doc["one"]["two"]["three"] == 4); } + +TEST_CASE("JsonDocument automatically promotes to array") { + DynamicJsonDocument doc(4096); + + doc[2] = 2; + + REQUIRE(doc.as() == "[null,null,2]"); +} diff --git a/lib/ArduinoJson-6.x/test/JsonObject/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/JsonObject/CMakeLists.txt similarity index 79% rename from lib/ArduinoJson-6.x/test/JsonObject/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/CMakeLists.txt index d8df0c2da..5339f4441 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(JsonObjectTests @@ -19,5 +19,4 @@ add_executable(JsonObjectTests subscript.cpp ) -target_link_libraries(JsonObjectTests catch) add_test(JsonObject JsonObjectTests) diff --git a/lib/ArduinoJson-6.x/test/JsonObject/containsKey.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/containsKey.cpp similarity index 95% rename from lib/ArduinoJson-6.x/test/JsonObject/containsKey.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/containsKey.cpp index 0b838b229..b505a978e 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/containsKey.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/containsKey.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonObject/copy.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/copy.cpp similarity index 54% rename from lib/ArduinoJson-6.x/test/JsonObject/copy.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/copy.cpp index f008d1190..a78c7e74a 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/copy.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/copy.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -15,8 +15,9 @@ TEST_CASE("JsonObject::set()") { SECTION("doesn't copy static string in key or value") { obj1["hello"] = "world"; - obj2.set(obj1); + bool success = obj2.set(obj1); + REQUIRE(success == true); REQUIRE(doc1.memoryUsage() == doc2.memoryUsage()); REQUIRE(obj2["hello"] == std::string("world")); } @@ -24,8 +25,9 @@ TEST_CASE("JsonObject::set()") { SECTION("copy local string value") { obj1["hello"] = std::string("world"); - obj2.set(obj1); + bool success = obj2.set(obj1); + REQUIRE(success == true); REQUIRE(doc1.memoryUsage() == doc2.memoryUsage()); REQUIRE(obj2["hello"] == std::string("world")); } @@ -33,8 +35,9 @@ TEST_CASE("JsonObject::set()") { SECTION("copy local key") { obj1[std::string("hello")] = "world"; - obj2.set(obj1); + bool success = obj2.set(obj1); + REQUIRE(success == true); REQUIRE(doc1.memoryUsage() == doc2.memoryUsage()); REQUIRE(obj2["hello"] == std::string("world")); } @@ -42,8 +45,9 @@ TEST_CASE("JsonObject::set()") { SECTION("copy string from deserializeJson()") { deserializeJson(doc1, "{'hello':'world'}"); - obj2.set(obj1); + bool success = obj2.set(obj1); + REQUIRE(success == true); REQUIRE(doc1.memoryUsage() == doc2.memoryUsage()); REQUIRE(obj2["hello"] == std::string("world")); } @@ -51,8 +55,9 @@ TEST_CASE("JsonObject::set()") { SECTION("copy string from deserializeMsgPack()") { deserializeMsgPack(doc1, "\x81\xA5hello\xA5world"); - obj2.set(obj1); + bool success = obj2.set(obj1); + REQUIRE(success == true); REQUIRE(doc1.memoryUsage() == doc2.memoryUsage()); REQUIRE(obj2["hello"] == std::string("world")); } @@ -65,4 +70,46 @@ TEST_CASE("JsonObject::set()") { REQUIRE(doc1.memoryUsage() == doc2.memoryUsage()); REQUIRE(obj2["hello"] == std::string("world")); } + + SECTION("destination too small to store the key") { + StaticJsonDocument doc3; + JsonObject obj3 = doc3.to(); + + obj1[std::string("hello")] = "world"; + + bool success = obj3.set(obj1); + + REQUIRE(success == false); + REQUIRE(doc3.as() == "{}"); + } + + SECTION("destination too small to store the value") { + StaticJsonDocument doc3; + JsonObject obj3 = doc3.to(); + + obj1["hello"] = std::string("world"); + + bool success = obj3.set(obj1); + + REQUIRE(success == false); + REQUIRE(doc3.as() == "{\"hello\":null}"); + } + + SECTION("destination is null") { + JsonObject null; + obj1["hello"] = "world"; + + bool success = null.set(obj1); + + REQUIRE(success == false); + } + + SECTION("source is null") { + JsonObject null; + obj1["hello"] = "world"; + + bool success = obj1.set(null); + + REQUIRE(success == false); + } } diff --git a/lib/ArduinoJson-6.x/test/JsonObject/createNestedArray.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/createNestedArray.cpp similarity index 93% rename from lib/ArduinoJson-6.x/test/JsonObject/createNestedArray.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/createNestedArray.cpp index 05062c31f..55831f55d 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/createNestedArray.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/createNestedArray.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonObject/createNestedObject.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/createNestedObject.cpp similarity index 92% rename from lib/ArduinoJson-6.x/test/JsonObject/createNestedObject.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/createNestedObject.cpp index 68506bb38..1f2b6295b 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/createNestedObject.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/createNestedObject.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonObject/equals.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/equals.cpp similarity index 78% rename from lib/ArduinoJson-6.x/test/JsonObject/equals.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/equals.cpp index 0ea1e377e..a04c37b91 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/equals.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/equals.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -50,4 +50,18 @@ TEST_CASE("JsonObject::operator==()") { REQUIRE(obj1 == obj2); REQUIRE(obj1c == obj2c); } + + SECTION("should return false when RHS is null") { + JsonObject null; + + REQUIRE_FALSE(obj1 == null); + REQUIRE_FALSE(obj1c == null); + } + + SECTION("should return false when LHS is null") { + JsonObject null; + + REQUIRE_FALSE(null == obj2); + REQUIRE_FALSE(null == obj2c); + } } diff --git a/lib/ArduinoJson-6.x/test/JsonObject/invalid.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/invalid.cpp similarity index 94% rename from lib/ArduinoJson-6.x/test/JsonObject/invalid.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/invalid.cpp index 2b0fffbbb..e76ca3f11 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/invalid.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/invalid.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/JsonObject/isNull.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/isNull.cpp new file mode 100644 index 000000000..2b2baf533 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/isNull.cpp @@ -0,0 +1,58 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +TEST_CASE("JsonObject::isNull()") { + SECTION("returns true") { + JsonObject obj; + REQUIRE(obj.isNull() == true); + } + + SECTION("returns false") { + DynamicJsonDocument doc(4096); + JsonObject obj = doc.to(); + REQUIRE(obj.isNull() == false); + } +} + +TEST_CASE("JsonObjectConst::isNull()") { + SECTION("returns true") { + JsonObjectConst obj; + REQUIRE(obj.isNull() == true); + } + + SECTION("returns false") { + DynamicJsonDocument doc(4096); + JsonObjectConst obj = doc.to(); + REQUIRE(obj.isNull() == false); + } +} + +TEST_CASE("JsonObject::operator bool()") { + SECTION("returns false") { + JsonObject obj; + REQUIRE(static_cast(obj) == false); + } + + SECTION("returns true") { + DynamicJsonDocument doc(4096); + JsonObject obj = doc.to(); + REQUIRE(static_cast(obj) == true); + } +} + +TEST_CASE("JsonObjectConst::operator bool()") { + SECTION("returns false") { + JsonObjectConst obj; + REQUIRE(static_cast(obj) == false); + } + + SECTION("returns true") { + DynamicJsonDocument doc(4096); + JsonObjectConst obj = doc.to(); + REQUIRE(static_cast(obj) == true); + } +} diff --git a/lib/ArduinoJson-6.x/test/JsonObject/iterator.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/iterator.cpp similarity index 78% rename from lib/ArduinoJson-6.x/test/JsonObject/iterator.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/iterator.cpp index 3c5f1d87c..24cd9b2ce 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/iterator.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/iterator.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -30,6 +30,11 @@ TEST_CASE("JsonObject::begin()/end()") { REQUIRE(obj.end()->key().isNull()); REQUIRE(obj.end()->value().isNull()); } + + SECTION("null JsonObject") { + JsonObject null; + REQUIRE(null.begin() == null.end()); + } } TEST_CASE("JsonObjectConst::begin()/end()") { @@ -40,15 +45,18 @@ TEST_CASE("JsonObjectConst::begin()/end()") { JsonObjectConst cobj = obj; - SECTION("NonConstIterator") { + SECTION("Iteration") { JsonObjectConst::iterator it = cobj.begin(); REQUIRE(cobj.end() != it); REQUIRE(it->key() == "ab"); REQUIRE(12 == it->value()); + ++it; REQUIRE(cobj.end() != it); - REQUIRE(it->key() == "cd"); - REQUIRE(34 == it->value()); + JsonPairConst pair = *it; + REQUIRE(pair.key() == "cd"); + REQUIRE(34 == pair.value()); + ++it; REQUIRE(cobj.end() == it); } @@ -57,4 +65,9 @@ TEST_CASE("JsonObjectConst::begin()/end()") { REQUIRE(cobj.end()->key().isNull()); REQUIRE(cobj.end()->value().isNull()); } + + SECTION("null JsonObjectConst") { + JsonObjectConst null; + REQUIRE(null.begin() == null.end()); + } } diff --git a/lib/ArduinoJson-6.x/test/JsonObject/memoryUsage.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/memoryUsage.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/JsonObject/memoryUsage.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/memoryUsage.cpp index d4e96ddf2..230c134b1 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/memoryUsage.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/memoryUsage.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonObject/nesting.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/nesting.cpp similarity index 95% rename from lib/ArduinoJson-6.x/test/JsonObject/nesting.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/nesting.cpp index bd65e61a5..597ae4636 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/nesting.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/nesting.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonObject/remove.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/remove.cpp similarity index 91% rename from lib/ArduinoJson-6.x/test/JsonObject/remove.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/remove.cpp index b3ef611e3..dde57144b 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/remove.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/remove.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -69,4 +69,9 @@ TEST_CASE("JsonObject::remove()") { REQUIRE("{\"a\":0,\"c\":2}" == result); } #endif + + SECTION("should work on null object") { + JsonObject null; + null.remove("key"); + } } diff --git a/lib/ArduinoJson-6.x/test/JsonObject/size.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/size.cpp similarity index 95% rename from lib/ArduinoJson-6.x/test/JsonObject/size.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/size.cpp index ae3184bbe..8ad0af845 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/size.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/size.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonObject/std_string.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/std_string.cpp similarity index 98% rename from lib/ArduinoJson-6.x/test/JsonObject/std_string.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/std_string.cpp index 8c771fb61..5bc589ddd 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/std_string.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/std_string.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonObject/subscript.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonObject/subscript.cpp similarity index 97% rename from lib/ArduinoJson-6.x/test/JsonObject/subscript.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonObject/subscript.cpp index 3d21cb736..fec2928af 100644 --- a/lib/ArduinoJson-6.x/test/JsonObject/subscript.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonObject/subscript.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -107,43 +107,43 @@ TEST_CASE("JsonObject::operator[]") { SECTION("should duplicate char* value") { obj["hello"] = const_cast("world"); - const size_t expectedSize = JSON_OBJECT_SIZE(1) + JSON_STRING_SIZE(6); + const size_t expectedSize = JSON_OBJECT_SIZE(1) + JSON_STRING_SIZE(5); REQUIRE(expectedSize == doc.memoryUsage()); } SECTION("should duplicate char* key") { obj[const_cast("hello")] = "world"; - const size_t expectedSize = JSON_OBJECT_SIZE(1) + JSON_STRING_SIZE(6); + const size_t expectedSize = JSON_OBJECT_SIZE(1) + JSON_STRING_SIZE(5); REQUIRE(expectedSize == doc.memoryUsage()); } SECTION("should duplicate char* key&value") { obj[const_cast("hello")] = const_cast("world"); - const size_t expectedSize = JSON_OBJECT_SIZE(1) + 2 * JSON_STRING_SIZE(6); + const size_t expectedSize = JSON_OBJECT_SIZE(1) + 2 * JSON_STRING_SIZE(5); REQUIRE(expectedSize <= doc.memoryUsage()); } SECTION("should duplicate std::string value") { obj["hello"] = std::string("world"); - const size_t expectedSize = JSON_OBJECT_SIZE(1) + JSON_STRING_SIZE(6); + const size_t expectedSize = JSON_OBJECT_SIZE(1) + JSON_STRING_SIZE(5); REQUIRE(expectedSize == doc.memoryUsage()); } SECTION("should duplicate std::string key") { obj[std::string("hello")] = "world"; - const size_t expectedSize = JSON_OBJECT_SIZE(1) + JSON_STRING_SIZE(6); + const size_t expectedSize = JSON_OBJECT_SIZE(1) + JSON_STRING_SIZE(5); REQUIRE(expectedSize == doc.memoryUsage()); } SECTION("should duplicate std::string key&value") { obj[std::string("hello")] = std::string("world"); - const size_t expectedSize = JSON_OBJECT_SIZE(1) + 2 * JSON_STRING_SIZE(6); + const size_t expectedSize = JSON_OBJECT_SIZE(1) + 2 * JSON_STRING_SIZE(5); REQUIRE(expectedSize <= doc.memoryUsage()); } SECTION("should duplicate a non-static JsonString key") { obj[JsonString("hello", false)] = "world"; - const size_t expectedSize = JSON_OBJECT_SIZE(1) + JSON_STRING_SIZE(6); + const size_t expectedSize = JSON_OBJECT_SIZE(1) + JSON_STRING_SIZE(5); REQUIRE(expectedSize == doc.memoryUsage()); } diff --git a/lib/ArduinoJson-6.x/test/JsonSerializer/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/CMakeLists.txt similarity index 75% rename from lib/ArduinoJson-6.x/test/JsonSerializer/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/JsonSerializer/CMakeLists.txt index fb18c448e..2d0b390eb 100644 --- a/lib/ArduinoJson-6.x/test/JsonSerializer/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/CMakeLists.txt @@ -1,8 +1,9 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(JsonSerializerTests + CustomWriter.cpp JsonArray.cpp JsonArrayPretty.cpp JsonObject.cpp @@ -13,5 +14,4 @@ add_executable(JsonSerializerTests std_string.cpp ) -target_link_libraries(JsonSerializerTests catch) add_test(JsonSerializer JsonSerializerTests) diff --git a/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/CustomWriter.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/CustomWriter.cpp new file mode 100644 index 000000000..96d630d5b --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/CustomWriter.cpp @@ -0,0 +1,52 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +class CustomWriter { + public: + CustomWriter() {} + + size_t write(uint8_t c) { + _str.append(1, static_cast(c)); + return 1; + } + + size_t write(const uint8_t *s, size_t n) { + _str.append(reinterpret_cast(s), n); + return n; + } + + const std::string &str() const { + return _str; + } + + private: + CustomWriter(const CustomWriter &); // non-copiable + CustomWriter &operator=(const CustomWriter &); + + std::string _str; +}; + +TEST_CASE("CustomWriter") { + DynamicJsonDocument doc(4096); + JsonArray array = doc.to(); + array.add(4); + array.add(2); + + SECTION("serializeJson()") { + CustomWriter writer; + serializeJson(array, writer); + + REQUIRE("[4,2]" == writer.str()); + } + + SECTION("serializeJsonPretty") { + CustomWriter writer; + serializeJsonPretty(array, writer); + + REQUIRE("[\r\n 4,\r\n 2\r\n]" == writer.str()); + } +} diff --git a/lib/ArduinoJson-6.x/test/JsonSerializer/JsonArray.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonArray.cpp similarity index 98% rename from lib/ArduinoJson-6.x/test/JsonSerializer/JsonArray.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonArray.cpp index e61ef8a17..efc2c7a1a 100644 --- a/lib/ArduinoJson-6.x/test/JsonSerializer/JsonArray.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonArray.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonSerializer/JsonArrayPretty.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonArrayPretty.cpp similarity index 55% rename from lib/ArduinoJson-6.x/test/JsonSerializer/JsonArrayPretty.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonArrayPretty.cpp index 4122043c6..b2b43921d 100644 --- a/lib/ArduinoJson-6.x/test/JsonSerializer/JsonArrayPretty.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonArrayPretty.cpp @@ -1,11 +1,11 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include #include -static void check(JsonArray array, std::string expected) { +static void checkArray(JsonArray array, std::string expected) { std::string actual; size_t actualLen = serializeJsonPretty(array, actual); size_t measuredLen = measureJsonPretty(array); @@ -19,38 +19,38 @@ TEST_CASE("serializeJsonPretty(JsonArray)") { JsonArray array = doc.to(); SECTION("Empty") { - check(array, "[]"); + checkArray(array, "[]"); } SECTION("OneElement") { array.add(1); - check(array, - "[\r\n" - " 1\r\n" - "]"); + checkArray(array, + "[\r\n" + " 1\r\n" + "]"); } SECTION("TwoElements") { array.add(1); array.add(2); - check(array, - "[\r\n" - " 1,\r\n" - " 2\r\n" - "]"); + checkArray(array, + "[\r\n" + " 1,\r\n" + " 2\r\n" + "]"); } SECTION("EmptyNestedArrays") { array.createNestedArray(); array.createNestedArray(); - check(array, - "[\r\n" - " [],\r\n" - " []\r\n" - "]"); + checkArray(array, + "[\r\n" + " [],\r\n" + " []\r\n" + "]"); } SECTION("NestedArrays") { @@ -61,15 +61,15 @@ TEST_CASE("serializeJsonPretty(JsonArray)") { JsonObject nested2 = array.createNestedObject(); nested2["key"] = 3; - check(array, - "[\r\n" - " [\r\n" - " 1,\r\n" - " 2\r\n" - " ],\r\n" - " {\r\n" - " \"key\": 3\r\n" - " }\r\n" - "]"); + checkArray(array, + "[\r\n" + " [\r\n" + " 1,\r\n" + " 2\r\n" + " ],\r\n" + " {\r\n" + " \"key\": 3\r\n" + " }\r\n" + "]"); } } diff --git a/lib/ArduinoJson-6.x/test/JsonSerializer/JsonObject.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonObject.cpp similarity index 70% rename from lib/ArduinoJson-6.x/test/JsonSerializer/JsonObject.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonObject.cpp index 573b4ae6a..9e870ffc3 100644 --- a/lib/ArduinoJson-6.x/test/JsonSerializer/JsonObject.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonObject.cpp @@ -1,12 +1,12 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include #include #include -void check(const JsonObject obj, const std::string &expected) { +static void checkObject(const JsonObject obj, const std::string &expected) { char actual[256]; size_t actualLen = serializeJson(obj, actual); size_t measuredLen = measureJson(obj); @@ -21,14 +21,14 @@ TEST_CASE("serializeJson(JsonObject)") { JsonObject obj = doc.to(); SECTION("EmptyObject") { - check(obj, "{}"); + checkObject(obj, "{}"); } SECTION("TwoStrings") { obj["key1"] = "value1"; obj["key2"] = "value2"; - check(obj, "{\"key1\":\"value1\",\"key2\":\"value2\"}"); + checkObject(obj, "{\"key1\":\"value1\",\"key2\":\"value2\"}"); } SECTION("RemoveFirst") { @@ -36,7 +36,7 @@ TEST_CASE("serializeJson(JsonObject)") { obj["key2"] = "value2"; obj.remove("key1"); - check(obj, "{\"key2\":\"value2\"}"); + checkObject(obj, "{\"key2\":\"value2\"}"); } SECTION("RemoveLast") { @@ -44,7 +44,7 @@ TEST_CASE("serializeJson(JsonObject)") { obj["key2"] = "value2"; obj.remove("key2"); - check(obj, "{\"key1\":\"value1\"}"); + checkObject(obj, "{\"key1\":\"value1\"}"); } SECTION("RemoveUnexistingKey") { @@ -52,44 +52,44 @@ TEST_CASE("serializeJson(JsonObject)") { obj["key2"] = "value2"; obj.remove("key3"); - check(obj, "{\"key1\":\"value1\",\"key2\":\"value2\"}"); + checkObject(obj, "{\"key1\":\"value1\",\"key2\":\"value2\"}"); } SECTION("ReplaceExistingKey") { obj["key"] = "value1"; obj["key"] = "value2"; - check(obj, "{\"key\":\"value2\"}"); + checkObject(obj, "{\"key\":\"value2\"}"); } SECTION("TwoIntegers") { obj["a"] = 1; obj["b"] = 2; - check(obj, "{\"a\":1,\"b\":2}"); + checkObject(obj, "{\"a\":1,\"b\":2}"); } SECTION("serialized(const char*)") { obj["a"] = serialized("[1,2]"); obj["b"] = serialized("[4,5]"); - check(obj, "{\"a\":[1,2],\"b\":[4,5]}"); + checkObject(obj, "{\"a\":[1,2],\"b\":[4,5]}"); } SECTION("Two doubles") { obj["a"] = 12.34; obj["b"] = 56.78; - check(obj, "{\"a\":12.34,\"b\":56.78}"); + checkObject(obj, "{\"a\":12.34,\"b\":56.78}"); } SECTION("TwoNull") { obj["a"] = static_cast(0); obj["b"] = static_cast(0); - check(obj, "{\"a\":null,\"b\":null}"); + checkObject(obj, "{\"a\":null,\"b\":null}"); } SECTION("TwoBooleans") { obj["a"] = true; obj["b"] = false; - check(obj, "{\"a\":true,\"b\":false}"); + checkObject(obj, "{\"a\":true,\"b\":false}"); } SECTION("ThreeNestedArrays") { @@ -100,7 +100,7 @@ TEST_CASE("serializeJson(JsonObject)") { obj["b"] = b.to(); obj["c"] = c.to(); - check(obj, "{\"a\":[],\"b\":[],\"c\":[]}"); + checkObject(obj, "{\"a\":[],\"b\":[],\"c\":[]}"); } SECTION("ThreeNestedObjects") { @@ -111,6 +111,6 @@ TEST_CASE("serializeJson(JsonObject)") { obj["b"] = b.to(); obj["c"] = c.to(); - check(obj, "{\"a\":{},\"b\":{},\"c\":{}}"); + checkObject(obj, "{\"a\":{},\"b\":{},\"c\":{}}"); } } diff --git a/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonObjectPretty.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonObjectPretty.cpp new file mode 100644 index 000000000..4fe0c5070 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonObjectPretty.cpp @@ -0,0 +1,77 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include +#include + +static void checkObjectPretty(const JsonObject obj, + const std::string expected) { + char json[256]; + + size_t actualLen = serializeJsonPretty(obj, json); + size_t measuredLen = measureJsonPretty(obj); + + REQUIRE(json == expected); + REQUIRE(expected.size() == actualLen); + REQUIRE(expected.size() == measuredLen); +} + +TEST_CASE("serializeJsonPretty(JsonObject)") { + DynamicJsonDocument doc(4096); + JsonObject obj = doc.to(); + + SECTION("EmptyObject") { + checkObjectPretty(obj, "{}"); + } + + SECTION("OneMember") { + obj["key"] = "value"; + + checkObjectPretty(obj, + "{\r\n" + " \"key\": \"value\"\r\n" + "}"); + } + + SECTION("TwoMembers") { + obj["key1"] = "value1"; + obj["key2"] = "value2"; + + checkObjectPretty(obj, + "{\r\n" + " \"key1\": \"value1\",\r\n" + " \"key2\": \"value2\"\r\n" + "}"); + } + + SECTION("EmptyNestedContainers") { + obj.createNestedObject("key1"); + obj.createNestedArray("key2"); + + checkObjectPretty(obj, + "{\r\n" + " \"key1\": {},\r\n" + " \"key2\": []\r\n" + "}"); + } + + SECTION("NestedContainers") { + JsonObject nested1 = obj.createNestedObject("key1"); + nested1["a"] = 1; + + JsonArray nested2 = obj.createNestedArray("key2"); + nested2.add(2); + + checkObjectPretty(obj, + "{\r\n" + " \"key1\": {\r\n" + " \"a\": 1\r\n" + " },\r\n" + " \"key2\": [\r\n" + " 2\r\n" + " ]\r\n" + "}"); + } +} diff --git a/lib/ArduinoJson-6.x/test/JsonSerializer/JsonVariant.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonVariant.cpp similarity index 64% rename from lib/ArduinoJson-6.x/test/JsonSerializer/JsonVariant.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonVariant.cpp index f5e223b6e..0e14b5c9c 100644 --- a/lib/ArduinoJson-6.x/test/JsonSerializer/JsonVariant.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/JsonVariant.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -31,6 +31,38 @@ TEST_CASE("serializeJson(JsonVariant)") { SECTION("string") { check(std::string("hello"), "\"hello\""); + + SECTION("Escape quotation mark") { + check(std::string("hello \"world\""), "\"hello \\\"world\\\"\""); + } + + SECTION("Escape reverse solidus") { + check(std::string("hello\\world"), "\"hello\\\\world\""); + } + + SECTION("Don't escape solidus") { + check(std::string("fifty/fifty"), "\"fifty/fifty\""); + } + + SECTION("Escape backspace") { + check(std::string("hello\bworld"), "\"hello\\bworld\""); + } + + SECTION("Escape formfeed") { + check(std::string("hello\fworld"), "\"hello\\fworld\""); + } + + SECTION("Escape linefeed") { + check(std::string("hello\nworld"), "\"hello\\nworld\""); + } + + SECTION("Escape carriage return") { + check(std::string("hello\rworld"), "\"hello\\rworld\""); + } + + SECTION("Escape tab") { + check(std::string("hello\tworld"), "\"hello\\tworld\""); + } } SECTION("SerializedValue") { diff --git a/lib/ArduinoJson-6.x/test/JsonSerializer/misc.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/misc.cpp similarity index 71% rename from lib/ArduinoJson-6.x/test/JsonSerializer/misc.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonSerializer/misc.cpp index 1cf24d097..59c09ebac 100644 --- a/lib/ArduinoJson-6.x/test/JsonSerializer/misc.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/misc.cpp @@ -2,16 +2,6 @@ #include #include -template -void check(T value, const std::string &expected) { - DynamicJsonDocument doc(4096); - doc.to().set(value); - char buffer[256] = ""; - size_t returnValue = serializeJson(doc, buffer, sizeof(buffer)); - REQUIRE(expected == buffer); - REQUIRE(expected.size() == returnValue); -} - TEST_CASE("serializeJson(MemberProxy)") { DynamicJsonDocument doc(4096); deserializeJson(doc, "{\"hello\":42}"); diff --git a/lib/ArduinoJson-6.x/test/JsonSerializer/std_stream.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/std_stream.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/JsonSerializer/std_stream.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonSerializer/std_stream.cpp index 55c8755d3..6dce2e047 100644 --- a/lib/ArduinoJson-6.x/test/JsonSerializer/std_stream.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/std_stream.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonSerializer/std_string.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/std_string.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/JsonSerializer/std_string.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonSerializer/std_string.cpp index bb840b70f..544112ec2 100644 --- a/lib/ArduinoJson-6.x/test/JsonSerializer/std_string.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonSerializer/std_string.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/CMakeLists.txt similarity index 80% rename from lib/ArduinoJson-6.x/test/JsonVariant/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/CMakeLists.txt index 87ddd409b..2d4d7897a 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(JsonVariantTests @@ -24,5 +24,4 @@ add_executable(JsonVariantTests undefined.cpp ) -target_link_libraries(JsonVariantTests catch) add_test(JsonVariant JsonVariantTests) diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/add.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/add.cpp similarity index 88% rename from lib/ArduinoJson-6.x/test/JsonVariant/add.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/add.cpp index ce899034d..32ba78bbc 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/add.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/add.cpp @@ -1,13 +1,11 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include #include #include -static const char* null = 0; - TEST_CASE("JsonVariant::add()") { DynamicJsonDocument doc(4096); JsonVariant var = doc.to(); diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/as.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/as.cpp similarity index 88% rename from lib/ArduinoJson-6.x/test/JsonVariant/as.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/as.cpp index 21d2c9879..05cb7d47b 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/as.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/as.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -10,9 +10,11 @@ namespace my { using ARDUINOJSON_NAMESPACE::isinf; } // namespace my -static const char* null = 0; +enum MY_ENUM { ONE = 1, TWO = 2 }; TEST_CASE("JsonVariant::as()") { + static const char* null = 0; + DynamicJsonDocument doc(4096); JsonVariant variant = doc.to(); @@ -77,13 +79,8 @@ TEST_CASE("JsonVariant::as()") { SECTION("set(0L)") { variant.set(0L); - SECTION("as()") { - REQUIRE(false == variant.as()); - } - - SECTION("as()") { - REQUIRE(variant.as() == 0.0); - } + REQUIRE(variant.as() == false); + REQUIRE(variant.as() == 0.0); } SECTION("set(null)") { @@ -104,7 +101,7 @@ TEST_CASE("JsonVariant::as()") { SECTION("set(\"hello\")") { variant.set("hello"); - REQUIRE(variant.as() == false); + REQUIRE(variant.as() == true); REQUIRE(variant.as() == 0L); REQUIRE(variant.as() == std::string("hello")); REQUIRE(variant.as() == std::string("hello")); @@ -114,6 +111,7 @@ TEST_CASE("JsonVariant::as()") { SECTION("set(std::string(\"4.2\"))") { variant.set(std::string("4.2")); + REQUIRE(variant.as() == true); REQUIRE(variant.as() == 4L); REQUIRE(variant.as() == 4.2); REQUIRE(variant.as() == std::string("4.2")); @@ -130,6 +128,7 @@ TEST_CASE("JsonVariant::as()") { SECTION("set(-1e300)") { variant.set(-1e300); + REQUIRE(variant.as() == true); REQUIRE(variant.as() == -1e300); REQUIRE(variant.as() < 0); REQUIRE(my::isinf(variant.as())); @@ -138,14 +137,16 @@ TEST_CASE("JsonVariant::as()") { SECTION("set(1e300)") { variant.set(1e300); + REQUIRE(variant.as() == true); REQUIRE(variant.as() == 1e300); REQUIRE(variant.as() > 0); REQUIRE(my::isinf(variant.as())); } - SECTION("set(1e300)") { + SECTION("set(1e-300)") { variant.set(1e-300); + REQUIRE(variant.as() == true); REQUIRE(variant.as() == 1e-300); REQUIRE(variant.as() == 0); } @@ -154,6 +155,10 @@ TEST_CASE("JsonVariant::as()") { JsonObject obj = variant.to(); obj["key"] = "value"; + SECTION("as()") { + REQUIRE(variant.as() == true); + } + SECTION("as()") { REQUIRE(variant.as() == std::string("{\"key\":\"value\"}")); } @@ -170,6 +175,10 @@ TEST_CASE("JsonVariant::as()") { arr.add(4); arr.add(2); + SECTION("as()") { + REQUIRE(variant.as() == true); + } + SECTION("as()") { REQUIRE(variant.as() == std::string("[4,2]")); } @@ -199,10 +208,16 @@ TEST_CASE("JsonVariant::as()") { JsonVariantConst cvar = variant; - REQUIRE(cvar.as() == false); + REQUIRE(cvar.as() == true); REQUIRE(cvar.as() == 0L); REQUIRE(cvar.as() == std::string("hello")); REQUIRE(cvar.as() == std::string("hello")); // REQUIRE(cvar.as() == std::string("hello")); } + + SECTION("as()") { + variant.set(1); + + REQUIRE(variant.as() == ONE); + } } diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/clear.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/clear.cpp similarity index 86% rename from lib/ArduinoJson-6.x/test/JsonVariant/clear.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/clear.cpp index d62311623..5fba855a5 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/clear.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/clear.cpp @@ -1,13 +1,11 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include #include #include -static const char* null = 0; - TEST_CASE("JsonVariant::clear()") { DynamicJsonDocument doc(4096); JsonVariant var = doc.to(); diff --git a/lib/ArduinoJson-6.x/extras/tests/JsonVariant/compare.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/compare.cpp new file mode 100644 index 000000000..d021296ba --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/compare.cpp @@ -0,0 +1,280 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +// Most code is already covered by arithmeticCompare.cpp. +// Here, we're just filling the holes + +TEST_CASE("Compare JsonVariant with value") { + StaticJsonDocument<256> doc; + JsonVariant a = doc.addElement(); + + SECTION("null vs (char*)0") { + char* b = 0; + + CHECK(a == b); + CHECK(a <= b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } + + SECTION("42 vs 42") { + a.set(42); + int b = 42; + + CHECK(a == b); + CHECK(a <= b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } +} + +TEST_CASE("Compare JsonVariant with JsonVariant") { + StaticJsonDocument<256> doc; + JsonVariant a = doc.addElement(); + JsonVariant b = doc.addElement(); + + SECTION("'abc' vs 'abc'") { + a.set("abc"); + b.set("abc"); + + CHECK(a == b); + CHECK(a <= b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } + + SECTION("'abc' vs 'bcd'") { + a.set("abc"); + b.set("bcd"); + + CHECK(a != b); + CHECK(a < b); + CHECK(a <= b); + CHECK_FALSE(a == b); + CHECK_FALSE(a > b); + CHECK_FALSE(a >= b); + } + + SECTION("'bcd' vs 'abc'") { + a.set("bcd"); + b.set("abc"); + + CHECK(a != b); + CHECK(a > b); + CHECK(a >= b); + CHECK_FALSE(a < b); + CHECK_FALSE(a <= b); + CHECK_FALSE(a == b); + } + + SECTION("serialized('abc') vs serialized('abc')") { + a.set(serialized("abc")); + b.set(serialized("abc")); + + CHECK(a == b); + CHECK(a <= b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } + + SECTION("serialized('abc') vs serialized('bcd')") { + a.set(serialized("abc")); + b.set(serialized("bcd")); + + CHECK(a != b); + CHECK(a < b); + CHECK(a <= b); + CHECK_FALSE(a == b); + CHECK_FALSE(a > b); + CHECK_FALSE(a >= b); + } + + SECTION("serialized('bcd') vs serialized('abc')") { + a.set(serialized("bcd")); + b.set(serialized("abc")); + + 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); + + CHECK(a != b); + CHECK(a < b); + CHECK(a <= b); + CHECK_FALSE(a == b); + CHECK_FALSE(a > b); + CHECK_FALSE(a >= b); + } + + SECTION("false vs -1") { + a.set(false); + b.set(-1); + + CHECK(a != b); + CHECK(a > b); + CHECK(a >= b); + CHECK_FALSE(a < b); + CHECK_FALSE(a <= b); + CHECK_FALSE(a == b); + } + + SECTION("null vs null") { + CHECK(a == b); + CHECK(a <= b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } + + SECTION("42 vs 42") { + a.set(42); + b.set(42); + + CHECK(a == b); + CHECK(a <= b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } + + SECTION("42 vs 42.0") { + a.set(42); + b.set(42.0); + + CHECK(a == b); + CHECK(a <= b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } + + SECTION("42.0 vs 42") { + a.set(42.0); + b.set(42); + + CHECK(a == b); + CHECK(a <= b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } + + SECTION("-42 vs -42") { + a.set(-42); + b.set(-42); + + CHECK(a == b); + CHECK(a <= b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } + + SECTION("-42 vs 42") { + a.set(-42); + b.set(42); + + CHECK(a != b); + CHECK(a < b); + CHECK(a <= b); + CHECK_FALSE(a == b); + CHECK_FALSE(a > b); + CHECK_FALSE(a >= b); + } + + SECTION("42 vs -42") { + a.set(42); + b.set(-42); + + CHECK(a != b); + CHECK(a > b); + CHECK(a >= b); + CHECK_FALSE(a < b); + CHECK_FALSE(a <= b); + CHECK_FALSE(a == b); + } + + SECTION("42.0 vs -42") { + a.set(42.0); + b.set(-42); + + CHECK(a != b); + CHECK(a > b); + CHECK(a >= b); + CHECK_FALSE(a < b); + CHECK_FALSE(a <= b); + CHECK_FALSE(a == b); + } + + SECTION("[1] vs [1]") { + a.add(1); + b.add(1); + + CHECK(a <= b); + CHECK(a == b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } + + SECTION("[1] vs [2]") { + a.add(1); + b.add(2); + + CHECK(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a <= b); + CHECK_FALSE(a == b); + CHECK_FALSE(a > b); + CHECK_FALSE(a >= b); + } + + SECTION("{x:1} vs {x:1}") { + a["x"] = 1; + b["x"] = 1; + + CHECK(a <= b); + CHECK(a == b); + CHECK(a >= b); + CHECK_FALSE(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a > b); + } + + SECTION("{x:1} vs {x:2}") { + a["x"] = 1; + b["x"] = 2; + + CHECK(a != b); + CHECK_FALSE(a < b); + CHECK_FALSE(a <= b); + CHECK_FALSE(a == b); + CHECK_FALSE(a > b); + CHECK_FALSE(a >= b); + } +} diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/containsKey.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/containsKey.cpp similarity index 55% rename from lib/ArduinoJson-6.x/test/JsonVariant/containsKey.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/containsKey.cpp index aa51a2256..9314cd166 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/containsKey.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/containsKey.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -26,3 +26,19 @@ TEST_CASE("JsonVariant::containsKey()") { REQUIRE(var.containsKey(std::string("world")) == false); } } + +TEST_CASE("JsonVariantConst::containsKey()") { + DynamicJsonDocument doc(4096); + doc["hello"] = "world"; + JsonVariantConst cvar = doc.as(); + + SECTION("containsKey(const char*) returns true") { + REQUIRE(cvar.containsKey("hello") == true); + REQUIRE(cvar.containsKey("world") == false); + } + + SECTION("containsKey(std::string) returns true") { + REQUIRE(cvar.containsKey(std::string("hello")) == true); + REQUIRE(cvar.containsKey(std::string("world")) == false); + } +} diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/copy.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/copy.cpp similarity index 71% rename from lib/ArduinoJson-6.x/test/JsonVariant/copy.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/copy.cpp index 04a2d07c2..6222b9082 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/copy.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/copy.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -47,20 +47,20 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { var1.set(str); var2.set(var1); - REQUIRE(doc1.memoryUsage() == JSON_STRING_SIZE(8)); - REQUIRE(doc2.memoryUsage() == JSON_STRING_SIZE(8)); + REQUIRE(doc1.memoryUsage() == JSON_STRING_SIZE(7)); + REQUIRE(doc2.memoryUsage() == JSON_STRING_SIZE(7)); } SECTION("stores std::string by copy") { var1.set(std::string("hello!!")); var2.set(var1); - REQUIRE(doc1.memoryUsage() == JSON_STRING_SIZE(8)); - REQUIRE(doc2.memoryUsage() == JSON_STRING_SIZE(8)); + REQUIRE(doc1.memoryUsage() == JSON_STRING_SIZE(7)); + REQUIRE(doc2.memoryUsage() == JSON_STRING_SIZE(7)); } SECTION("stores Serialized by reference") { - var1.set(serialized("hello!!", JSON_STRING_SIZE(8))); + var1.set(serialized("hello!!", 8)); var2.set(var1); REQUIRE(doc1.memoryUsage() == 0); @@ -69,18 +69,18 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { SECTION("stores Serialized by copy") { char str[] = "hello!!"; - var1.set(serialized(str, 8)); + var1.set(serialized(str, 7)); var2.set(var1); - REQUIRE(doc1.memoryUsage() == JSON_STRING_SIZE(8)); - REQUIRE(doc2.memoryUsage() == JSON_STRING_SIZE(8)); + REQUIRE(doc1.memoryUsage() == JSON_STRING_SIZE(7)); + REQUIRE(doc2.memoryUsage() == JSON_STRING_SIZE(7)); } SECTION("stores Serialized by copy") { - var1.set(serialized(std::string("hello!!!"))); + var1.set(serialized(std::string("hello!!"))); var2.set(var1); - REQUIRE(doc1.memoryUsage() == JSON_STRING_SIZE(8)); - REQUIRE(doc2.memoryUsage() == JSON_STRING_SIZE(8)); + REQUIRE(doc1.memoryUsage() == JSON_STRING_SIZE(7)); + REQUIRE(doc2.memoryUsage() == JSON_STRING_SIZE(7)); } } diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/createNested.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/createNested.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/JsonVariant/createNested.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/createNested.cpp index 8db9d5af1..2964cc9e0 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/createNested.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/createNested.cpp @@ -1,13 +1,11 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include #include #include -static const char* null = 0; - TEST_CASE("JsonVariant::createNestedObject()") { DynamicJsonDocument doc(4096); JsonVariant variant = doc.to(); diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/is.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/is.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/JsonVariant/is.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/is.cpp index ec6756225..48b81d128 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/is.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/is.cpp @@ -1,10 +1,12 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include #include +enum MYENUM2 { ONE = 1, TWO = 2 }; + template void checkIsArray(TVariant var) { REQUIRE(var.template is()); @@ -80,6 +82,7 @@ void checkIsInteger(TVariant var) { REQUIRE(var.template is()); REQUIRE(var.template is()); REQUIRE(var.template is()); + REQUIRE(var.template is()); REQUIRE_FALSE(var.template is()); REQUIRE_FALSE(var.template is()); @@ -107,6 +110,7 @@ void checkIsString(TVariant var) { REQUIRE_FALSE(var.template is()); REQUIRE_FALSE(var.template is()); REQUIRE_FALSE(var.template is()); + REQUIRE_FALSE(var.template is()); REQUIRE_FALSE(var.template is()); REQUIRE_FALSE(var.template is()); } diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/isnull.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/isnull.cpp similarity index 97% rename from lib/ArduinoJson-6.x/test/JsonVariant/isnull.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/isnull.cpp index c3d865077..5c87593f9 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/isnull.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/isnull.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/memoryUsage.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/memoryUsage.cpp similarity index 95% rename from lib/ArduinoJson-6.x/test/JsonVariant/memoryUsage.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/memoryUsage.cpp index 56519588d..7731c82fa 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/memoryUsage.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/memoryUsage.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/misc.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/misc.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/JsonVariant/misc.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/misc.cpp index 06d78401d..183fe64f3 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/misc.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/misc.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/nesting.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/nesting.cpp similarity index 94% rename from lib/ArduinoJson-6.x/test/JsonVariant/nesting.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/nesting.cpp index 62d1f7a34..dd02aaf24 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/nesting.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/nesting.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/or.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/or.cpp similarity index 98% rename from lib/ArduinoJson-6.x/test/JsonVariant/or.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/or.cpp index a703485b8..de1cc6166 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/or.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/or.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/overflow.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/overflow.cpp similarity index 97% rename from lib/ArduinoJson-6.x/test/JsonVariant/overflow.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/overflow.cpp index 8c356c9c0..63a7a424e 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/overflow.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/overflow.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/remove.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/remove.cpp similarity index 94% rename from lib/ArduinoJson-6.x/test/JsonVariant/remove.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/remove.cpp index c91a6e656..430598632 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/remove.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/remove.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/set.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/set.cpp similarity index 76% rename from lib/ArduinoJson-6.x/test/JsonVariant/set.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/set.cpp index 1a15a814c..eeb9088be 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/set.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/set.cpp @@ -1,10 +1,12 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include #include +enum ErrorCode { ERROR_01 = 1, ERROR_10 = 10 }; + TEST_CASE("JsonVariant and strings") { DynamicJsonDocument doc(4096); JsonVariant variant = doc.to(); @@ -79,7 +81,7 @@ TEST_CASE("JsonVariant and strings") { variant.set(JsonString(str, true)); strcpy(str, "world"); - REQUIRE(variant == "hello"); + REQUIRE(variant == "world"); } SECTION("stores non-static JsonString by copy") { @@ -91,6 +93,15 @@ TEST_CASE("JsonVariant and strings") { REQUIRE(variant == "hello"); } + + SECTION("stores an enum as an integer") { + ErrorCode code = ERROR_10; + + variant.set(code); + + REQUIRE(variant.is() == true); + REQUIRE(variant.as() == 10); + } } TEST_CASE("JsonVariant with not enough memory") { @@ -108,3 +119,19 @@ TEST_CASE("JsonVariant with not enough memory") { REQUIRE(v.isNull()); } } + +TEST_CASE("JsonVariant::set(DynamicJsonDocument)") { + DynamicJsonDocument doc1(1024); + doc1["hello"] = "world"; + + DynamicJsonDocument doc2(1024); + JsonVariant v = doc2.to(); + + // Should copy the doc + v.set(doc1); + doc1.clear(); + + std::string json; + serializeJson(doc2, json); + REQUIRE(json == "{\"hello\":\"world\"}"); +} diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/subscript.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/subscript.cpp similarity index 97% rename from lib/ArduinoJson-6.x/test/JsonVariant/subscript.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/subscript.cpp index bdc3cf054..f16972ba3 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/subscript.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/subscript.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -43,10 +43,10 @@ TEST_CASE("JsonVariant::operator[]") { SECTION("set value") { array.add("hello"); - var[0] = "world"; + var[1] = "world"; - REQUIRE(1 == var.size()); - REQUIRE(std::string("world") == var[0]); + REQUIRE(var.size() == 2); + REQUIRE(std::string("world") == var[1]); } SECTION("set value in a nested object") { diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/types.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/types.cpp similarity index 98% rename from lib/ArduinoJson-6.x/test/JsonVariant/types.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/types.cpp index 484546109..3adf4cc82 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/types.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/types.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/JsonVariant/undefined.cpp b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/undefined.cpp similarity index 97% rename from lib/ArduinoJson-6.x/test/JsonVariant/undefined.cpp rename to lib/ArduinoJson-6.x/extras/tests/JsonVariant/undefined.cpp index cabf788cf..64f1d1412 100644 --- a/lib/ArduinoJson-6.x/test/JsonVariant/undefined.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/JsonVariant/undefined.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MemberProxy/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/CMakeLists.txt similarity index 70% rename from lib/ArduinoJson-6.x/test/MemberProxy/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/MemberProxy/CMakeLists.txt index e948c656b..6d4c0f6f7 100644 --- a/lib/ArduinoJson-6.x/test/MemberProxy/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/CMakeLists.txt @@ -1,10 +1,11 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(MemberProxyTests add.cpp clear.cpp + compare.cpp containsKey.cpp remove.cpp set.cpp @@ -12,5 +13,4 @@ add_executable(MemberProxyTests subscript.cpp ) -target_link_libraries(MemberProxyTests catch) add_test(MemberProxy MemberProxyTests) diff --git a/lib/ArduinoJson-6.x/test/MemberProxy/add.cpp b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/add.cpp similarity index 92% rename from lib/ArduinoJson-6.x/test/MemberProxy/add.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemberProxy/add.cpp index 2862d5056..6b7347464 100644 --- a/lib/ArduinoJson-6.x/test/MemberProxy/add.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/add.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MemberProxy/clear.cpp b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/clear.cpp similarity index 92% rename from lib/ArduinoJson-6.x/test/MemberProxy/clear.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemberProxy/clear.cpp index bb78042f8..f644df212 100644 --- a/lib/ArduinoJson-6.x/test/MemberProxy/clear.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/clear.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/MemberProxy/compare.cpp b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/compare.cpp new file mode 100644 index 000000000..2c3c3ef22 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/compare.cpp @@ -0,0 +1,48 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +using namespace ARDUINOJSON_NAMESPACE; + +TEST_CASE("MemberProxy::operator==()") { + DynamicJsonDocument doc(4096); + + SECTION("1 vs 1") { + doc["a"] = 1; + doc["b"] = 1; + + REQUIRE(doc["a"] <= doc["b"]); + REQUIRE(doc["a"] == doc["b"]); + REQUIRE(doc["a"] >= doc["b"]); + REQUIRE_FALSE(doc["a"] != doc["b"]); + REQUIRE_FALSE(doc["a"] < doc["b"]); + REQUIRE_FALSE(doc["a"] > doc["b"]); + } + + SECTION("1 vs 2") { + doc["a"] = 1; + doc["b"] = 2; + + REQUIRE(doc["a"] != doc["b"]); + REQUIRE(doc["a"] < doc["b"]); + REQUIRE(doc["a"] <= doc["b"]); + REQUIRE_FALSE(doc["a"] == doc["b"]); + REQUIRE_FALSE(doc["a"] > doc["b"]); + REQUIRE_FALSE(doc["a"] >= doc["b"]); + } + + SECTION("'abc' vs 'bcd'") { + doc["a"] = "abc"; + doc["b"] = "bcd"; + + REQUIRE(doc["a"] != doc["b"]); + REQUIRE(doc["a"] < doc["b"]); + REQUIRE(doc["a"] <= doc["b"]); + REQUIRE_FALSE(doc["a"] == doc["b"]); + REQUIRE_FALSE(doc["a"] > doc["b"]); + REQUIRE_FALSE(doc["a"] >= doc["b"]); + } +} diff --git a/lib/ArduinoJson-6.x/test/MemberProxy/containsKey.cpp b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/containsKey.cpp similarity index 94% rename from lib/ArduinoJson-6.x/test/MemberProxy/containsKey.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemberProxy/containsKey.cpp index c0acdc742..b07431ea3 100644 --- a/lib/ArduinoJson-6.x/test/MemberProxy/containsKey.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/containsKey.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MemberProxy/remove.cpp b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/remove.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/MemberProxy/remove.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemberProxy/remove.cpp index 10ffcd068..a790d2955 100644 --- a/lib/ArduinoJson-6.x/test/MemberProxy/remove.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/remove.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MemberProxy/set.cpp b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/set.cpp similarity index 69% rename from lib/ArduinoJson-6.x/test/MemberProxy/set.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemberProxy/set.cpp index 9fd372dcb..467361e45 100644 --- a/lib/ArduinoJson-6.x/test/MemberProxy/set.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/set.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -22,4 +22,12 @@ TEST_CASE("MemberProxy::set()") { REQUIRE(doc.as() == "{\"hello\":\"world\"}"); } + + SECTION("set(char[])") { // issue #1191 + char s[] = "world"; + mp.set(s); + strcpy(s, "!!!!!"); + + REQUIRE(doc.as() == "{\"hello\":\"world\"}"); + } } diff --git a/lib/ArduinoJson-6.x/test/MemberProxy/size.cpp b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/size.cpp similarity index 93% rename from lib/ArduinoJson-6.x/test/MemberProxy/size.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemberProxy/size.cpp index 639f125bb..8018b5c3b 100644 --- a/lib/ArduinoJson-6.x/test/MemberProxy/size.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/size.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MemberProxy/subscript.cpp b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/subscript.cpp similarity index 66% rename from lib/ArduinoJson-6.x/test/MemberProxy/subscript.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemberProxy/subscript.cpp index fcd883ba4..876a28e87 100644 --- a/lib/ArduinoJson-6.x/test/MemberProxy/subscript.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemberProxy/subscript.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -11,9 +11,15 @@ TEST_CASE("MemberProxy::operator[]") { DynamicJsonDocument doc(4096); MemberProxy mp = doc["hello"]; - SECTION("set integer") { + SECTION("set member") { mp["world"] = 42; REQUIRE(doc.as() == "{\"hello\":{\"world\":42}}"); } + + SECTION("set element") { + mp[2] = 42; + + REQUIRE(doc.as() == "{\"hello\":[null,null,42]}"); + } } diff --git a/lib/ArduinoJson-6.x/test/MemoryPool/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/CMakeLists.txt similarity index 70% rename from lib/ArduinoJson-6.x/test/MemoryPool/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/MemoryPool/CMakeLists.txt index e28e3d980..1ff0c0db2 100644 --- a/lib/ArduinoJson-6.x/test/MemoryPool/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(MemoryPoolTests @@ -10,5 +10,4 @@ add_executable(MemoryPoolTests StringBuilder.cpp ) -target_link_libraries(MemoryPoolTests catch) add_test(MemoryPool MemoryPoolTests) diff --git a/lib/ArduinoJson-6.x/test/MemoryPool/StringBuilder.cpp b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/StringBuilder.cpp similarity index 87% rename from lib/ArduinoJson-6.x/test/MemoryPool/StringBuilder.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemoryPool/StringBuilder.cpp index c9afdbfa4..57810ce63 100644 --- a/lib/ArduinoJson-6.x/test/MemoryPool/StringBuilder.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/StringBuilder.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -8,9 +8,9 @@ using namespace ARDUINOJSON_NAMESPACE; -static char buffer[4096]; - TEST_CASE("StringBuilder") { + char buffer[4096]; + SECTION("Works when buffer is big enough") { MemoryPool pool(buffer, addPadding(JSON_STRING_SIZE(6))); @@ -36,6 +36,6 @@ TEST_CASE("StringBuilder") { str.append('h'); str.complete(); - REQUIRE(JSON_STRING_SIZE(2) == pool.size()); + REQUIRE(JSON_STRING_SIZE(1) == pool.size()); } } diff --git a/lib/ArduinoJson-6.x/test/MemoryPool/allocString.cpp b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/allocString.cpp similarity index 97% rename from lib/ArduinoJson-6.x/test/MemoryPool/allocString.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemoryPool/allocString.cpp index 3f1d9d510..c93f45640 100644 --- a/lib/ArduinoJson-6.x/test/MemoryPool/allocString.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/allocString.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MemoryPool/allocVariant.cpp b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/allocVariant.cpp similarity index 94% rename from lib/ArduinoJson-6.x/test/MemoryPool/allocVariant.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemoryPool/allocVariant.cpp index 10f79d60a..ed4cf48b8 100644 --- a/lib/ArduinoJson-6.x/test/MemoryPool/allocVariant.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/allocVariant.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -7,9 +7,9 @@ using namespace ARDUINOJSON_NAMESPACE; -static char buffer[4096]; - TEST_CASE("MemoryPool::allocVariant()") { + char buffer[4096]; + SECTION("Returns different pointer") { MemoryPool pool(buffer, sizeof(buffer)); diff --git a/lib/ArduinoJson-6.x/test/MemoryPool/clear.cpp b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/clear.cpp similarity index 93% rename from lib/ArduinoJson-6.x/test/MemoryPool/clear.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemoryPool/clear.cpp index 482ecdbbf..2eb3b4871 100644 --- a/lib/ArduinoJson-6.x/test/MemoryPool/clear.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/clear.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MemoryPool/size.cpp b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/size.cpp similarity index 78% rename from lib/ArduinoJson-6.x/test/MemoryPool/size.cpp rename to lib/ArduinoJson-6.x/extras/tests/MemoryPool/size.cpp index 50163acaf..0ab6e9007 100644 --- a/lib/ArduinoJson-6.x/test/MemoryPool/size.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MemoryPool/size.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -7,15 +7,15 @@ using namespace ARDUINOJSON_NAMESPACE; -char buffer[4096]; - TEST_CASE("MemoryPool::capacity()") { + char buffer[4096]; const size_t capacity = 64; MemoryPool pool(buffer, capacity); REQUIRE(capacity == pool.capacity()); } TEST_CASE("MemoryPool::size()") { + char buffer[4096]; MemoryPool pool(buffer, sizeof(buffer)); SECTION("Initial size is 0") { @@ -30,19 +30,19 @@ TEST_CASE("MemoryPool::size()") { SECTION("Decreases after freezeString()") { StringSlot a = pool.allocExpandableString(); pool.freezeString(a, 1); - REQUIRE(pool.size() == JSON_STRING_SIZE(1)); + REQUIRE(pool.size() == 1); StringSlot b = pool.allocExpandableString(); pool.freezeString(b, 1); - REQUIRE(pool.size() == 2 * JSON_STRING_SIZE(1)); + REQUIRE(pool.size() == 2); } SECTION("Increases after allocFrozenString()") { - pool.allocFrozenString(0); - REQUIRE(pool.size() == JSON_STRING_SIZE(0)); + pool.allocFrozenString(1); + REQUIRE(pool.size() == 1); - pool.allocFrozenString(0); - REQUIRE(pool.size() == 2 * JSON_STRING_SIZE(0)); + pool.allocFrozenString(2); + REQUIRE(pool.size() == 3); } SECTION("Doesn't grow when memory pool is full") { diff --git a/lib/ArduinoJson-6.x/extras/tests/Misc/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/Misc/CMakeLists.txt new file mode 100644 index 000000000..042264a45 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/CMakeLists.txt @@ -0,0 +1,21 @@ +# ArduinoJson - arduinojson.org +# Copyright Benoit Blanchon 2014-2020 +# MIT License + +add_executable(MiscTests + arithmeticCompare.cpp + conflicts.cpp + FloatParts.cpp + Readers.cpp + StringAdapters.cpp + StringWriter.cpp + TypeTraits.cpp + unsigned_char.cpp + Utf8.cpp + Utf16.cpp + version.cpp +) + +set_target_properties(MiscTests PROPERTIES UNITY_BUILD OFF) + +add_test(Misc MiscTests) diff --git a/lib/ArduinoJson-6.x/test/Misc/FloatParts.cpp b/lib/ArduinoJson-6.x/extras/tests/Misc/FloatParts.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/Misc/FloatParts.cpp rename to lib/ArduinoJson-6.x/extras/tests/Misc/FloatParts.cpp index d204eebe9..c58e4b534 100644 --- a/lib/ArduinoJson-6.x/test/Misc/FloatParts.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/FloatParts.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/Misc/Readers.cpp b/lib/ArduinoJson-6.x/extras/tests/Misc/Readers.cpp new file mode 100644 index 000000000..d25685b31 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/Readers.cpp @@ -0,0 +1,225 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1 +#include +#include + +using namespace ARDUINOJSON_NAMESPACE; + +TEST_CASE("Reader") { + SECTION("read()") { + std::istringstream src("\x01\xFF"); + Reader reader(src); + + REQUIRE(reader.read() == 0x01); + REQUIRE(reader.read() == 0xFF); + REQUIRE(reader.read() == -1); + } + + SECTION("readBytes() all at once") { + std::istringstream src("ABC"); + Reader reader(src); + + char buffer[8] = "abcd"; + REQUIRE(reader.readBytes(buffer, 4) == 3); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'd'); + } + + SECTION("readBytes() in two parts") { + std::istringstream src("ABCDEF"); + Reader reader(src); + + char buffer[12] = "abcdefg"; + REQUIRE(reader.readBytes(buffer, 4) == 4); + REQUIRE(reader.readBytes(buffer + 4, 4) == 2); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'D'); + REQUIRE(buffer[4] == 'E'); + REQUIRE(buffer[5] == 'F'); + REQUIRE(buffer[6] == 'g'); + } +} + +TEST_CASE("BoundedReader") { + SECTION("read") { + BoundedReader reader("\x01\xFF", 2); + REQUIRE(reader.read() == 0x01); + REQUIRE(reader.read() == 0xFF); + REQUIRE(reader.read() == -1); + REQUIRE(reader.read() == -1); + } + + SECTION("readBytes() all at once") { + BoundedReader reader("ABCD", 3); + + char buffer[8] = "abcd"; + REQUIRE(reader.readBytes(buffer, 4) == 3); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'd'); + } + + SECTION("readBytes() in two parts") { + BoundedReader reader("ABCDEF", 6); + + char buffer[8] = "abcdefg"; + REQUIRE(reader.readBytes(buffer, 4) == 4); + REQUIRE(reader.readBytes(buffer + 4, 4) == 2); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'D'); + REQUIRE(buffer[4] == 'E'); + REQUIRE(buffer[5] == 'F'); + REQUIRE(buffer[6] == 'g'); + } +} + +TEST_CASE("Reader") { + SECTION("read()") { + Reader reader("\x01\xFF\x00\x12"); + REQUIRE(reader.read() == 0x01); + REQUIRE(reader.read() == 0xFF); + REQUIRE(reader.read() == 0); + REQUIRE(reader.read() == 0x12); + } + + SECTION("readBytes() all at once") { + Reader reader("ABCD"); + + char buffer[8] = "abcd"; + REQUIRE(reader.readBytes(buffer, 3) == 3); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'd'); + } + + SECTION("readBytes() in two parts") { + Reader reader("ABCDEF"); + + char buffer[8] = "abcdefg"; + REQUIRE(reader.readBytes(buffer, 4) == 4); + REQUIRE(reader.readBytes(buffer + 4, 2) == 2); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'D'); + REQUIRE(buffer[4] == 'E'); + REQUIRE(buffer[5] == 'F'); + REQUIRE(buffer[6] == 'g'); + } +} + +TEST_CASE("IteratorReader") { + SECTION("read()") { + std::string src("\x01\xFF"); + IteratorReader reader(src.begin(), src.end()); + + REQUIRE(reader.read() == 0x01); + REQUIRE(reader.read() == 0xFF); + REQUIRE(reader.read() == -1); + } + + SECTION("readBytes() all at once") { + std::string src("ABC"); + IteratorReader reader(src.begin(), src.end()); + + char buffer[8] = "abcd"; + REQUIRE(reader.readBytes(buffer, 4) == 3); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'd'); + } + + SECTION("readBytes() in two parts") { + std::string src("ABCDEF"); + IteratorReader reader(src.begin(), src.end()); + + char buffer[12] = "abcdefg"; + REQUIRE(reader.readBytes(buffer, 4) == 4); + REQUIRE(reader.readBytes(buffer + 4, 4) == 2); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'D'); + REQUIRE(buffer[4] == 'E'); + REQUIRE(buffer[5] == 'F'); + REQUIRE(buffer[6] == 'g'); + } +} + +class StreamStub : public Stream { + public: + StreamStub(const char* s) : _stream(s) {} + + int read() { + return _stream.get(); + } + + size_t readBytes(char* buffer, size_t length) { + _stream.read(buffer, static_cast(length)); + return static_cast(_stream.gcount()); + } + + private: + std::istringstream _stream; +}; + +TEST_CASE("Reader") { + SECTION("read()") { + StreamStub src("\x01\xFF"); + Reader reader(src); + + REQUIRE(reader.read() == 0x01); + REQUIRE(reader.read() == 0xFF); + REQUIRE(reader.read() == -1); + } + + SECTION("readBytes() all at once") { + StreamStub src("ABC"); + Reader reader(src); + + char buffer[8] = "abcd"; + REQUIRE(reader.readBytes(buffer, 4) == 3); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'd'); + } + + SECTION("readBytes() in two parts") { + StreamStub src("ABCDEF"); + Reader reader(src); + + char buffer[12] = "abcdefg"; + REQUIRE(reader.readBytes(buffer, 4) == 4); + REQUIRE(reader.readBytes(buffer + 4, 4) == 2); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'D'); + REQUIRE(buffer[4] == 'E'); + REQUIRE(buffer[5] == 'F'); + REQUIRE(buffer[6] == 'g'); + } +} diff --git a/lib/ArduinoJson-6.x/extras/tests/Misc/StringAdapters.cpp b/lib/ArduinoJson-6.x/extras/tests/Misc/StringAdapters.cpp new file mode 100644 index 000000000..c299bef96 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/StringAdapters.cpp @@ -0,0 +1,156 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include "custom_string.hpp" +#include "progmem_emulation.hpp" +#include "weird_strcmp.hpp" + +#include +#include +#include +#include + +#include + +using namespace ARDUINOJSON_NAMESPACE; + +TEST_CASE("ConstRamStringAdapter") { + SECTION("null") { + ConstRamStringAdapter adapter(NULL); + + CHECK(adapter.compare("bravo") < 0); + CHECK(adapter.compare(NULL) == 0); + + CHECK(adapter.equals(NULL)); + CHECK_FALSE(adapter.equals("charlie")); + + CHECK(adapter.size() == 0); + } + + SECTION("non-null") { + ConstRamStringAdapter adapter("bravo"); + + CHECK(adapter.compare(NULL) > 0); + CHECK(adapter.compare("alpha") > 0); + CHECK(adapter.compare("bravo") == 0); + CHECK(adapter.compare("charlie") < 0); + + CHECK(adapter.equals("bravo")); + CHECK_FALSE(adapter.equals("charlie")); + + CHECK(adapter.size() == 5); + } +} + +TEST_CASE("SizedRamStringAdapter") { + SECTION("null") { + SizedRamStringAdapter adapter(NULL, 10); + + CHECK(adapter.compare("bravo") < 0); + CHECK(adapter.compare(NULL) == 0); + + CHECK(adapter.equals(NULL)); + CHECK_FALSE(adapter.equals("charlie")); + + CHECK(adapter.size() == 10); + } + + SECTION("non-null") { + SizedRamStringAdapter adapter("bravo", 5); + + CHECK(adapter.compare(NULL) > 0); + CHECK(adapter.compare("alpha") > 0); + CHECK(adapter.compare("bravo") == 0); + CHECK(adapter.compare("charlie") < 0); + + CHECK(adapter.equals("bravo")); + CHECK_FALSE(adapter.equals("charlie")); + + CHECK(adapter.size() == 5); + } +} + +TEST_CASE("FlashStringAdapter") { + SECTION("null") { + FlashStringAdapter adapter(NULL); + + CHECK(adapter.compare("bravo") < 0); + CHECK(adapter.compare(NULL) == 0); + + CHECK(adapter.equals(NULL)); + CHECK_FALSE(adapter.equals("charlie")); + + CHECK(adapter.size() == 0); + } + + SECTION("non-null") { + FlashStringAdapter adapter = adaptString(F("bravo")); + + CHECK(adapter.compare(NULL) > 0); + CHECK(adapter.compare("alpha") > 0); + CHECK(adapter.compare("bravo") == 0); + CHECK(adapter.compare("charlie") < 0); + + CHECK(adapter.equals("bravo")); + CHECK_FALSE(adapter.equals("charlie")); + + CHECK(adapter.size() == 5); + } +} + +TEST_CASE("std::string") { + std::string str("bravo"); + StlStringAdapter adapter = adaptString(str); + + CHECK(adapter.compare(NULL) > 0); + CHECK(adapter.compare("alpha") > 0); + CHECK(adapter.compare("bravo") == 0); + CHECK(adapter.compare("charlie") < 0); + + CHECK(adapter.equals("bravo")); + CHECK_FALSE(adapter.equals("charlie")); + + CHECK(adapter.size() == 5); +} + +TEST_CASE("custom_string") { + custom_string str("bravo"); + StlStringAdapter adapter = adaptString(str); + + CHECK(adapter.compare(NULL) > 0); + CHECK(adapter.compare("alpha") > 0); + CHECK(adapter.compare("bravo") == 0); + CHECK(adapter.compare("charlie") < 0); + + CHECK(adapter.equals("bravo")); + CHECK_FALSE(adapter.equals("charlie")); + + CHECK(adapter.size() == 5); +} + +TEST_CASE("IsString") { + SECTION("std::string") { + CHECK(IsString::value == true); + } + + SECTION("basic_string") { + CHECK(IsString >::value == false); + } + + SECTION("custom_string") { + CHECK(IsString::value == true); + } + + SECTION("const __FlashStringHelper*") { + CHECK(IsString::value == true); + } + + SECTION("const char*") { + CHECK(IsString::value == true); + } + + SECTION("const char[]") { + CHECK(IsString::value == true); + } +} diff --git a/lib/ArduinoJson-6.x/extras/tests/Misc/StringWriter.cpp b/lib/ArduinoJson-6.x/extras/tests/Misc/StringWriter.cpp new file mode 100644 index 000000000..15ff9212d --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/StringWriter.cpp @@ -0,0 +1,118 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 +#define ARDUINOJSON_STRING_BUFFER_SIZE 5 +#include +#include +#include "custom_string.hpp" + +using namespace ARDUINOJSON_NAMESPACE; + +template +static size_t print(StringWriter& sb, const char* s) { + return sb.write(reinterpret_cast(s), strlen(s)); +} + +template +void common_tests(StringWriter& sb, const String& output) { + SECTION("InitialState") { + REQUIRE(std::string("") == output); + } + + SECTION("EmptyString") { + REQUIRE(0 == print(sb, "")); + REQUIRE(std::string("") == output); + } + + SECTION("OneString") { + REQUIRE(4 == print(sb, "ABCD")); + REQUIRE(std::string("ABCD") == output); + } + + SECTION("TwoStrings") { + REQUIRE(4 == print(sb, "ABCD")); + REQUIRE(4 == print(sb, "EFGH")); + REQUIRE(std::string("ABCDEFGH") == output); + } +} + +TEST_CASE("StaticStringWriter") { + char output[20]; + StaticStringWriter sb(output, sizeof(output)); + + common_tests(sb, static_cast(output)); + + SECTION("OverCapacity") { + REQUIRE(19 == print(sb, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")); + REQUIRE(0 == print(sb, "ABC")); + REQUIRE(std::string("ABCDEFGHIJKLMNOPQRS") == output); + } +} + +TEST_CASE("Writer") { + std::string output; + Writer sb(output); + common_tests(sb, output); +} + +TEST_CASE("Writer") { + ::String output; + Writer< ::String> sb(output); + + common_tests(sb, output); + + SECTION("Writes characters to temporary buffer") { + // accumulate in buffer + sb.write('a'); + sb.write('b'); + sb.write('c'); + REQUIRE(output == ""); + + // flush when full + sb.write('d'); + REQUIRE(output == "abcd"); + + // flush on destruction + sb.write('e'); + sb.~Writer(); + REQUIRE(output == "abcde"); + } + + SECTION("Writes strings to temporary buffer") { + // accumulate in buffer + print(sb, "abc"); + REQUIRE(output == ""); + + // flush when full, and continue to accumulate + print(sb, "de"); + REQUIRE(output == "abcd"); + + // flush on destruction + sb.~Writer(); + REQUIRE(output == "abcde"); + } +} + +TEST_CASE("Writer") { + custom_string output; + Writer sb(output); + + REQUIRE(4 == print(sb, "ABCD")); + REQUIRE("ABCD" == output); +} + +TEST_CASE("IsWriteableString") { + SECTION("std::string") { + REQUIRE(IsWriteableString::value == true); + } + + SECTION("custom_string") { + REQUIRE(IsWriteableString::value == true); + } + + SECTION("basic_string") { + REQUIRE(IsWriteableString >::value == false); + } +} diff --git a/lib/ArduinoJson-6.x/test/Misc/TypeTraits.cpp b/lib/ArduinoJson-6.x/extras/tests/Misc/TypeTraits.cpp similarity index 58% rename from lib/ArduinoJson-6.x/test/Misc/TypeTraits.cpp rename to lib/ArduinoJson-6.x/extras/tests/Misc/TypeTraits.cpp index 66f77fe54..59511ec48 100644 --- a/lib/ArduinoJson-6.x/test/Misc/TypeTraits.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/TypeTraits.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -7,6 +7,9 @@ using namespace ARDUINOJSON_NAMESPACE; +class EmptyClass {}; +enum EmptyEnum {}; + TEST_CASE("Polyfills/type_traits") { SECTION("is_base_of") { REQUIRE_FALSE( @@ -26,6 +29,24 @@ TEST_CASE("Polyfills/type_traits") { CHECK(is_const::value == true); } + SECTION("is_integral") { + CHECK(is_integral::value == false); + CHECK(is_integral::value == false); + + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + CHECK(is_integral::value == true); + + CHECK(is_integral::value == true); + } + SECTION("is_signed") { CHECK(is_signed::value == true); CHECK(is_signed::value == true); @@ -48,6 +69,30 @@ TEST_CASE("Polyfills/type_traits") { CHECK(is_unsigned::value == false); } + SECTION("is_convertible") { + CHECK((is_convertible::value == true)); + CHECK((is_convertible::value == true)); + CHECK((is_convertible::value == true)); + CHECK((is_convertible::value == false)); + CHECK((is_convertible::value == false)); + } + + SECTION("is_class") { + CHECK((is_class::value == false)); + CHECK((is_class::value == false)); + CHECK((is_class::value == false)); + CHECK((is_class::value == true)); + } + + SECTION("is_enum") { + CHECK(is_enum::value == false); + CHECK(is_enum::value == true); + CHECK(is_enum::value == false); + CHECK(is_enum::value == false); + CHECK(is_enum::value == false); + CHECK(is_enum::value == false); + } + SECTION("IsVisitable") { CHECK(IsVisitable::value == false); CHECK(IsVisitable::value == false); diff --git a/lib/ArduinoJson-6.x/extras/tests/Misc/Utf16.cpp b/lib/ArduinoJson-6.x/extras/tests/Misc/Utf16.cpp new file mode 100644 index 000000000..071ed1341 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/Utf16.cpp @@ -0,0 +1,68 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +using namespace ARDUINOJSON_NAMESPACE; + +static void testUtf16Codepoint(uint16_t codeunit, uint32_t expectedCodepoint) { + Utf16::Codepoint cp; + REQUIRE(cp.append(codeunit) == true); + REQUIRE(cp.value() == expectedCodepoint); +} + +static void testUtf16Codepoint(uint16_t codeunit1, uint16_t codeunit2, + uint32_t expectedCodepoint) { + Utf16::Codepoint cp; + REQUIRE(cp.append(codeunit1) == false); + REQUIRE(cp.append(codeunit2) == true); + REQUIRE(cp.value() == expectedCodepoint); +} + +TEST_CASE("Utf16::Codepoint()") { + SECTION("U+0000") { + testUtf16Codepoint(0x0000, 0x000000); + } + + SECTION("U+0001") { + testUtf16Codepoint(0x0001, 0x000001); + } + + SECTION("U+D7FF") { + testUtf16Codepoint(0xD7FF, 0x00D7FF); + } + + SECTION("U+E000") { + testUtf16Codepoint(0xE000, 0x00E000); + } + + SECTION("U+FFFF") { + testUtf16Codepoint(0xFFFF, 0x00FFFF); + } + + SECTION("U+010000") { + testUtf16Codepoint(0xD800, 0xDC00, 0x010000); + } + + SECTION("U+010001") { + testUtf16Codepoint(0xD800, 0xDC01, 0x010001); + } + + SECTION("U+0103FF") { + testUtf16Codepoint(0xD800, 0xDFFF, 0x0103FF); + } + + SECTION("U+010400") { + testUtf16Codepoint(0xD801, 0xDC00, 0x010400); + } + + SECTION("U+010400") { + testUtf16Codepoint(0xDBFF, 0xDC00, 0x10FC00); + } + + SECTION("U+10FFFF") { + testUtf16Codepoint(0xDBFF, 0xDFFF, 0x10FFFF); + } +} diff --git a/lib/ArduinoJson-6.x/extras/tests/Misc/Utf8.cpp b/lib/ArduinoJson-6.x/extras/tests/Misc/Utf8.cpp new file mode 100644 index 000000000..1c7e1b321 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/Utf8.cpp @@ -0,0 +1,59 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +#include + +using namespace ARDUINOJSON_NAMESPACE; + +static void testCodepoint(uint32_t codepoint, std::string expected) { + char buffer[4096]; + MemoryPool pool(buffer, 4096); + StringBuilder str(&pool); + + CAPTURE(codepoint); + Utf8::encodeCodepoint(codepoint, str); + + REQUIRE(str.complete() == expected); +} + +TEST_CASE("Utf8::encodeCodepoint()") { + SECTION("U+0000") { + testCodepoint(0x0000, ""); + } + + SECTION("U+0001") { + testCodepoint(0x0001, "\x01"); + } + + SECTION("U+007F") { + testCodepoint(0x007F, "\x7f"); + } + + SECTION("U+0080") { + testCodepoint(0x0080, "\xc2\x80"); + } + + SECTION("U+07FF") { + testCodepoint(0x07FF, "\xdf\xbf"); + } + + SECTION("U+0800") { + testCodepoint(0x0800, "\xe0\xa0\x80"); + } + + SECTION("U+FFFF") { + testCodepoint(0xFFFF, "\xef\xbf\xbf"); + } + + SECTION("U+10000") { + testCodepoint(0x10000, "\xf0\x90\x80\x80"); + } + + SECTION("U+10FFFF") { + testCodepoint(0x10FFFF, "\xf4\x8f\xbf\xbf"); + } +} diff --git a/lib/ArduinoJson-6.x/extras/tests/Misc/arithmeticCompare.cpp b/lib/ArduinoJson-6.x/extras/tests/Misc/arithmeticCompare.cpp new file mode 100644 index 000000000..90f4c1863 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/arithmeticCompare.cpp @@ -0,0 +1,103 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +using namespace ARDUINOJSON_NAMESPACE; + +TEST_CASE("arithmeticCompare()") { + SECTION("int vs uint8_t") { + CHECK((arithmeticCompare(256, 1) == COMPARE_RESULT_GREATER)); + CHECK((arithmeticCompare(41, 42) == COMPARE_RESULT_LESS)); + CHECK((arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompare(43, 42) == COMPARE_RESULT_GREATER)); + } + + SECTION("unsigned vs int") { + CHECK((arithmeticCompare(0, -1) == COMPARE_RESULT_GREATER)); + CHECK((arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER)); + CHECK((arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompare(42, 43) == COMPARE_RESULT_LESS)); + } + + SECTION("float vs int") { + CHECK((arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER)); + CHECK((arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompare(42, 43) == COMPARE_RESULT_LESS)); + } + + SECTION("int vs unsigned") { + CHECK((arithmeticCompare(-1, 0) == COMPARE_RESULT_LESS)); + CHECK((arithmeticCompare(0, 0) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompare(1, 0) == COMPARE_RESULT_GREATER)); + CHECK((arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER)); + CHECK((arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompare(42, 43) == COMPARE_RESULT_LESS)); + } + + SECTION("unsigned vs unsigned") { + CHECK((arithmeticCompare(42, 41) == + COMPARE_RESULT_GREATER)); + CHECK((arithmeticCompare(42, 42) == + COMPARE_RESULT_EQUAL)); + CHECK( + (arithmeticCompare(42, 43) == COMPARE_RESULT_LESS)); + } + + SECTION("bool vs bool") { + CHECK( + (arithmeticCompare(false, false) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompare(true, true) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompare(false, true) == COMPARE_RESULT_LESS)); + CHECK( + (arithmeticCompare(true, false) == COMPARE_RESULT_GREATER)); + } + + SECTION("bool vs int") { + CHECK((arithmeticCompare(false, -1) == COMPARE_RESULT_GREATER)); + CHECK((arithmeticCompare(false, 0) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompare(false, 1) == COMPARE_RESULT_LESS)); + CHECK((arithmeticCompare(true, 0) == COMPARE_RESULT_GREATER)); + CHECK((arithmeticCompare(true, 1) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompare(true, 2) == COMPARE_RESULT_LESS)); + } + + SECTION("bool vs int") { + CHECK((arithmeticCompare(0, false) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompare(1, true) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompare(1, false) == COMPARE_RESULT_GREATER)); + CHECK((arithmeticCompare(0, true) == COMPARE_RESULT_LESS)); + } +} + +TEST_CASE("arithmeticCompareNegateLeft()") { + SECTION("unsigned vs int") { + CHECK((arithmeticCompareNegateLeft(0, 1) == COMPARE_RESULT_LESS)); + CHECK((arithmeticCompareNegateLeft(42, -41) == COMPARE_RESULT_LESS)); + CHECK((arithmeticCompareNegateLeft(42, -42) == COMPARE_RESULT_EQUAL)); + CHECK( + (arithmeticCompareNegateLeft(42, -43) == COMPARE_RESULT_GREATER)); + } + + SECTION("unsigned vs unsigned") { + CHECK( + (arithmeticCompareNegateLeft(42, 42) == COMPARE_RESULT_LESS)); + } +} + +TEST_CASE("arithmeticCompareNegateRight()") { + SECTION("int vs unsigned") { + CHECK((arithmeticCompareNegateRight(1, 0) == COMPARE_RESULT_GREATER)); + CHECK( + (arithmeticCompareNegateRight(-41, 42) == COMPARE_RESULT_GREATER)); + CHECK((arithmeticCompareNegateRight(-42, 42) == COMPARE_RESULT_EQUAL)); + CHECK((arithmeticCompareNegateRight(-43, 42) == COMPARE_RESULT_LESS)); + } + + SECTION("unsigned vs unsigned") { + CHECK((arithmeticCompareNegateRight(42, 42) == + COMPARE_RESULT_GREATER)); + } +} diff --git a/lib/ArduinoJson-6.x/test/Misc/conflicts.cpp b/lib/ArduinoJson-6.x/extras/tests/Misc/conflicts.cpp similarity index 95% rename from lib/ArduinoJson-6.x/test/Misc/conflicts.cpp rename to lib/ArduinoJson-6.x/extras/tests/Misc/conflicts.cpp index 52f694d86..e4a3960f3 100644 --- a/lib/ArduinoJson-6.x/test/Misc/conflicts.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/conflicts.cpp @@ -1,11 +1,11 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License // Include any header that might use the conflicting macros #include -#include #include +#include // All cores #define bit() diff --git a/lib/ArduinoJson-6.x/extras/tests/Misc/custom_string.hpp b/lib/ArduinoJson-6.x/extras/tests/Misc/custom_string.hpp new file mode 100644 index 000000000..8ba892b0b --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/custom_string.hpp @@ -0,0 +1,12 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +struct custom_char_traits : std::char_traits {}; +struct custom_allocator : std::allocator {}; +typedef std::basic_string + custom_string; diff --git a/lib/ArduinoJson-6.x/test/Misc/unsigned_char.cpp b/lib/ArduinoJson-6.x/extras/tests/Misc/unsigned_char.cpp similarity index 74% rename from lib/ArduinoJson-6.x/test/Misc/unsigned_char.cpp rename to lib/ArduinoJson-6.x/extras/tests/Misc/unsigned_char.cpp index a09ad7888..87cd6a82d 100644 --- a/lib/ArduinoJson-6.x/test/Misc/unsigned_char.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/unsigned_char.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -28,6 +28,70 @@ TEST_CASE("unsigned char[]") { REQUIRE(err == DeserializationError::Ok); } + SECTION("serializeMsgPack(unsigned char[])") { + unsigned char buffer[32]; + StaticJsonDocument doc; + doc["hello"] = "world"; + + size_t n = serializeMsgPack(doc, buffer); + + REQUIRE(n == 13); + REQUIRE(memcmp(buffer, "\x81\xA5hello\xA5world", 13) == 0); + } + + SECTION("serializeMsgPack(unsigned char*)") { + unsigned char buffer[32]; + StaticJsonDocument doc; + doc["hello"] = "world"; + + size_t n = serializeMsgPack(doc, buffer, sizeof(buffer)); + + REQUIRE(n == 13); + REQUIRE(memcmp(buffer, "\x81\xA5hello\xA5world", 13) == 0); + } + + SECTION("serializeJson(unsigned char[])") { + unsigned char buffer[32]; + StaticJsonDocument doc; + doc["hello"] = "world"; + + size_t n = serializeJson(doc, buffer); + + REQUIRE(n == 17); + REQUIRE(memcmp(buffer, "{\"hello\":\"world\"}", n) == 0); + } + + SECTION("serializeJson(unsigned char*)") { + unsigned char buffer[32]; + StaticJsonDocument doc; + doc["hello"] = "world"; + + size_t n = serializeJson(doc, buffer, sizeof(buffer)); + + REQUIRE(n == 17); + REQUIRE(memcmp(buffer, "{\"hello\":\"world\"}", n) == 0); + } + + SECTION("serializeJsonPretty(unsigned char[])") { + unsigned char buffer[32]; + StaticJsonDocument doc; + doc["hello"] = "world"; + + size_t n = serializeJsonPretty(doc, buffer); + + REQUIRE(n == 24); + } + + SECTION("serializeJsonPretty(unsigned char*)") { + unsigned char buffer[32]; + StaticJsonDocument doc; + doc["hello"] = "world"; + + size_t n = serializeJsonPretty(doc, buffer, sizeof(buffer)); + + REQUIRE(n == 24); + } + SECTION("JsonVariant") { DynamicJsonDocument doc(4096); diff --git a/lib/ArduinoJson-6.x/test/Misc/version.cpp b/lib/ArduinoJson-6.x/extras/tests/Misc/version.cpp similarity index 91% rename from lib/ArduinoJson-6.x/test/Misc/version.cpp rename to lib/ArduinoJson-6.x/extras/tests/Misc/version.cpp index 3e8d87616..e4844c753 100644 --- a/lib/ArduinoJson-6.x/test/Misc/version.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/version.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/Misc/weird_strcmp.hpp b/lib/ArduinoJson-6.x/extras/tests/Misc/weird_strcmp.hpp new file mode 100644 index 000000000..3dbc0cf2d --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Misc/weird_strcmp.hpp @@ -0,0 +1,23 @@ +#include + +// Issue #1198: strcmp() implementation that returns a value larger than 8-bit + +namespace ARDUINOJSON_NAMESPACE { +int strcmp(const char* a, const char* b) { + int result = ::strcmp(a, b); + if (result > 0) + return 2147483647; + if (result < 0) + return -214748364; + return 0; +} + +int strncmp(const char* a, const char* b, size_t n) { + int result = ::strncmp(a, b, n); + if (result > 0) + return 2147483647; + if (result < 0) + return -214748364; + return 0; +} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/test/MixedConfiguration/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/CMakeLists.txt similarity index 64% rename from lib/ArduinoJson-6.x/test/MixedConfiguration/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/CMakeLists.txt index 038317d34..650b244cf 100644 --- a/lib/ArduinoJson-6.x/test/MixedConfiguration/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License # we need C++11 for 'long long' @@ -9,15 +9,21 @@ add_executable(MixedConfigurationTests cpp11.cpp decode_unicode_0.cpp decode_unicode_1.cpp + enable_alignment_0.cpp + enable_alignment_1.cpp + enable_comments_0.cpp + enable_comments_1.cpp enable_infinity_0.cpp enable_infinity_1.cpp enable_nan_0.cpp enable_nan_1.cpp + enable_progmem_1.cpp use_double_0.cpp use_double_1.cpp use_long_long_0.cpp use_long_long_1.cpp ) -target_link_libraries(MixedConfigurationTests catch) +set_target_properties(MixedConfigurationTests PROPERTIES UNITY_BUILD OFF) + add_test(MixedConfiguration MixedConfigurationTests) diff --git a/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/cpp11.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/cpp11.cpp new file mode 100644 index 000000000..df81e35c0 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/cpp11.cpp @@ -0,0 +1,94 @@ +#include + +#include + +#if __cplusplus >= 201103L + +TEST_CASE("nullptr") { + DynamicJsonDocument doc(4096); + JsonVariant variant = doc.to(); + + SECTION("JsonVariant == nullptr") { + REQUIRE((variant == nullptr)); + REQUIRE_FALSE((variant != nullptr)); + } + + SECTION("JsonVariant != nullptr") { + variant.set(42); + + REQUIRE_FALSE((variant == nullptr)); + REQUIRE((variant != nullptr)); + } + + SECTION("JsonVariant.set(nullptr)") { + variant.set(42); + variant.set(nullptr); + + REQUIRE(variant.isNull()); + } + + SECTION("JsonVariant.is()") { + variant.set(42); + REQUIRE(variant.is() == false); + + variant.clear(); + REQUIRE(variant.is() == true); + } +} + +TEST_CASE("Issue #1120") { + StaticJsonDocument<500> doc; + constexpr char str[] = + "{\"contents\":[{\"module\":\"Packet\"},{\"module\":\"Analog\"}]}"; + deserializeJson(doc, str); + + SECTION("MemberProxy::isNull()") { + SECTION("returns false") { + auto value = doc[std::string("contents")]; + CHECK(value.isNull() == false); + } + + SECTION("returns true") { + auto value = doc[std::string("zontents")]; + CHECK(value.isNull() == true); + } + } + + SECTION("ElementProxy >::isNull()") { + SECTION("returns false") { // Issue #1120 + auto value = doc["contents"][1]; + CHECK(value.isNull() == false); + } + + SECTION("returns true") { + auto value = doc["contents"][2]; + CHECK(value.isNull() == true); + } + } + + SECTION("MemberProxy, const char*>::isNull()") { + SECTION("returns false") { + auto value = doc["contents"][1]["module"]; + CHECK(value.isNull() == false); + } + + SECTION("returns true") { + auto value = doc["contents"][1]["zodule"]; + CHECK(value.isNull() == true); + } + } + + SECTION("MemberProxy, std::string>::isNull()") { + SECTION("returns false") { + auto value = doc["contents"][1][std::string("module")]; + CHECK(value.isNull() == false); + } + + SECTION("returns true") { + auto value = doc["contents"][1][std::string("zodule")]; + CHECK(value.isNull() == true); + } + } +} + +#endif diff --git a/lib/ArduinoJson-6.x/test/MixedConfiguration/decode_unicode_0.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/decode_unicode_0.cpp similarity index 100% rename from lib/ArduinoJson-6.x/test/MixedConfiguration/decode_unicode_0.cpp rename to lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/decode_unicode_0.cpp diff --git a/lib/ArduinoJson-6.x/test/MixedConfiguration/decode_unicode_1.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/decode_unicode_1.cpp similarity index 100% rename from lib/ArduinoJson-6.x/test/MixedConfiguration/decode_unicode_1.cpp rename to lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/decode_unicode_1.cpp diff --git a/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_alignment_0.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_alignment_0.cpp new file mode 100644 index 000000000..426f516a1 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_alignment_0.cpp @@ -0,0 +1,41 @@ +#define ARDUINOJSON_NAMESPACE ArduinoJson_NoAlignment +#define ARDUINOJSON_ENABLE_ALIGNMENT 0 +#include + +#include + +TEST_CASE("ARDUINOJSON_ENABLE_ALIGNMENT == 0") { + using namespace ARDUINOJSON_NAMESPACE; + + const size_t N = sizeof(void*); + + SECTION("isAligned()") { + CHECK(isAligned(0) == true); + CHECK(isAligned(1) == true); + CHECK(isAligned(N) == true); + CHECK(isAligned(N + 1) == true); + CHECK(isAligned(2 * N) == true); + CHECK(isAligned(2 * N + 1) == true); + } + + SECTION("addPadding()") { + CHECK(addPadding(0) == 0); + CHECK(addPadding(1) == 1); + CHECK(addPadding(N) == N); + CHECK(addPadding(N + 1) == N + 1); + } + + SECTION("AddPadding<>") { + const size_t a = AddPadding<0>::value; + CHECK(a == 0); + + const size_t b = AddPadding<1>::value; + CHECK(b == 1); + + const size_t c = AddPadding::value; + CHECK(c == N); + + const size_t d = AddPadding::value; + CHECK(d == N + 1); + } +} diff --git a/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_alignment_1.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_alignment_1.cpp new file mode 100644 index 000000000..9abf50c84 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_alignment_1.cpp @@ -0,0 +1,40 @@ +#define ARDUINOJSON_ENABLE_ALIGNMENT 1 +#include + +#include + +TEST_CASE("ARDUINOJSON_ENABLE_ALIGNMENT == 1") { + using namespace ARDUINOJSON_NAMESPACE; + + const size_t N = sizeof(void*); + + SECTION("isAligned()") { + CHECK(isAligned(0) == true); + CHECK(isAligned(1) == false); + CHECK(isAligned(N) == true); + CHECK(isAligned(N + 1) == false); + CHECK(isAligned(2 * N) == true); + CHECK(isAligned(2 * N + 1) == false); + } + + SECTION("addPadding()") { + CHECK(addPadding(0) == 0); + CHECK(addPadding(1) == N); + CHECK(addPadding(N) == N); + CHECK(addPadding(N + 1) == 2 * N); + } + + SECTION("AddPadding<>") { + const size_t a = AddPadding<0>::value; + CHECK(a == 0); + + const size_t b = AddPadding<1>::value; + CHECK(b == N); + + const size_t c = AddPadding::value; + CHECK(c == N); + + const size_t d = AddPadding::value; + CHECK(d == 2 * N); + } +} diff --git a/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_comments_0.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_comments_0.cpp new file mode 100644 index 000000000..8e98c7a22 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_comments_0.cpp @@ -0,0 +1,54 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#define ARDUINOJSON_ENABLE_COMMENTS 0 +#include + +#include + +TEST_CASE("Comments should produce InvalidInput") { + DynamicJsonDocument doc(2048); + + const char* testCases[] = { + "/*COMMENT*/ [\"hello\"]", + "[/*COMMENT*/ \"hello\"]", + "[\"hello\"/*COMMENT*/]", + "[\"hello\"/*COMMENT*/,\"world\"]", + "[\"hello\",/*COMMENT*/ \"world\"]", + "[/*/\n]", + "[/*COMMENT]", + "[/*COMMENT*]", + "//COMMENT\n\t[\"hello\"]", + "[//COMMENT\n\"hello\"]", + "[\"hello\"//COMMENT\r\n]", + "[\"hello\"//COMMENT\n,\"world\"]", + "[\"hello\",//COMMENT\n\"world\"]", + "[/COMMENT\n]", + "[//COMMENT", + "/*COMMENT*/ {\"hello\":\"world\"}", + "{/*COMMENT*/\"hello\":\"world\"}", + "{\"hello\"/*COMMENT*/:\"world\"}", + "{\"hello\":/*COMMENT*/\"world\"}", + "{\"hello\":\"world\"/*COMMENT*/}", + "//COMMENT\n {\"hello\":\"world\"}", + "{//COMMENT\n\"hello\":\"world\"}", + "{\"hello\"//COMMENT\n:\"world\"}", + "{\"hello\"://COMMENT\n\"world\"}", + "{\"hello\":\"world\"//COMMENT\n}", + "/{\"hello\":\"world\"}", + "{/\"hello\":\"world\"}", + "{\"hello\"/:\"world\"}", + "{\"hello\":/\"world\"}", + "{\"hello\":\"world\"/}", + "{\"hello\":\"world\"/,\"answer\":42}", + "{\"hello\":\"world\",/\"answer\":42}", + }; + const size_t testCount = sizeof(testCases) / sizeof(testCases[0]); + + for (size_t i = 0; i < testCount; i++) { + const char* input = testCases[i]; + CAPTURE(input); + REQUIRE(deserializeJson(doc, input) == DeserializationError::InvalidInput); + } +} diff --git a/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_comments_1.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_comments_1.cpp new file mode 100644 index 000000000..7e59bb03d --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_comments_1.cpp @@ -0,0 +1,405 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#define ARDUINOJSON_ENABLE_COMMENTS 1 +#include + +#include + +TEST_CASE("Comments in arrays") { + DynamicJsonDocument doc(2048); + + SECTION("Block comments") { + SECTION("Before opening bracket") { + DeserializationError err = + deserializeJson(doc, "/*COMMENT*/ [\"hello\"]"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(1 == arr.size()); + REQUIRE(arr[0] == "hello"); + } + + SECTION("After opening bracket") { + DeserializationError err = + deserializeJson(doc, "[/*COMMENT*/ \"hello\"]"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(1 == arr.size()); + REQUIRE(arr[0] == "hello"); + } + + SECTION("Before closing bracket") { + DeserializationError err = deserializeJson(doc, "[\"hello\"/*COMMENT*/]"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(1 == arr.size()); + REQUIRE(arr[0] == "hello"); + } + + SECTION("After closing bracket") { + DeserializationError err = deserializeJson(doc, "[\"hello\"]/*COMMENT*/"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(1 == arr.size()); + REQUIRE(arr[0] == "hello"); + } + + SECTION("Before comma") { + DeserializationError err = + deserializeJson(doc, "[\"hello\"/*COMMENT*/,\"world\"]"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(2 == arr.size()); + REQUIRE(arr[0] == "hello"); + REQUIRE(arr[1] == "world"); + } + + SECTION("After comma") { + DeserializationError err = + deserializeJson(doc, "[\"hello\",/*COMMENT*/ \"world\"]"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(2 == arr.size()); + REQUIRE(arr[0] == "hello"); + REQUIRE(arr[1] == "world"); + } + + SECTION("/*/") { + DeserializationError err = deserializeJson(doc, "[/*/\n]"); + REQUIRE(err == DeserializationError::IncompleteInput); + } + + SECTION("Unfinished comment") { + DeserializationError err = deserializeJson(doc, "[/*COMMENT]"); + REQUIRE(err == DeserializationError::IncompleteInput); + } + + SECTION("Final slash missing") { + DeserializationError err = deserializeJson(doc, "[/*COMMENT*]"); + REQUIRE(err == DeserializationError::IncompleteInput); + } + } + + SECTION("Trailing comments") { + SECTION("Before opening bracket") { + DeserializationError err = + deserializeJson(doc, "//COMMENT\n\t[\"hello\"]"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(1 == arr.size()); + REQUIRE(arr[0] == "hello"); + } + + SECTION("After opening bracket") { + DeserializationError err = deserializeJson(doc, "[//COMMENT\n\"hello\"]"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(1 == arr.size()); + REQUIRE(arr[0] == "hello"); + } + + SECTION("Before closing bracket") { + DeserializationError err = + deserializeJson(doc, "[\"hello\"//COMMENT\r\n]"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(1 == arr.size()); + REQUIRE(arr[0] == "hello"); + } + + SECTION("After closing bracket") { + DeserializationError err = deserializeJson(doc, "[\"hello\"]//COMMENT\n"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(1 == arr.size()); + REQUIRE(arr[0] == "hello"); + } + + SECTION("Before comma") { + DeserializationError err = + deserializeJson(doc, "[\"hello\"//COMMENT\n,\"world\"]"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(2 == arr.size()); + REQUIRE(arr[0] == "hello"); + REQUIRE(arr[1] == "world"); + } + + SECTION("After comma") { + DeserializationError err = + deserializeJson(doc, "[\"hello\",//COMMENT\n\"world\"]"); + JsonArray arr = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(2 == arr.size()); + REQUIRE(arr[0] == "hello"); + REQUIRE(arr[1] == "world"); + } + + SECTION("Invalid comment") { + DeserializationError err = deserializeJson(doc, "[/COMMENT\n]"); + REQUIRE(err == DeserializationError::InvalidInput); + } + + SECTION("End document with comment") { + DeserializationError err = deserializeJson(doc, "[//COMMENT"); + REQUIRE(err == DeserializationError::IncompleteInput); + } + } +} + +TEST_CASE("Comments in objects") { + DynamicJsonDocument doc(2048); + + SECTION("Block comments") { + SECTION("Before opening brace") { + DeserializationError err = + deserializeJson(doc, "/*COMMENT*/ {\"hello\":\"world\"}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("After opening brace") { + DeserializationError err = + deserializeJson(doc, "{/*COMMENT*/\"hello\":\"world\"}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("Before colon") { + DeserializationError err = + deserializeJson(doc, "{\"hello\"/*COMMENT*/:\"world\"}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("After colon") { + DeserializationError err = + deserializeJson(doc, "{\"hello\":/*COMMENT*/\"world\"}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("Before closing brace") { + DeserializationError err = + deserializeJson(doc, "{\"hello\":\"world\"/*COMMENT*/}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("After closing brace") { + DeserializationError err = + deserializeJson(doc, "{\"hello\":\"world\"}/*COMMENT*/"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("Before comma") { + DeserializationError err = deserializeJson( + doc, "{\"hello\":\"world\"/*COMMENT*/,\"answer\":42}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + REQUIRE(obj["answer"] == 42); + } + + SECTION("After comma") { + DeserializationError err = deserializeJson( + doc, "{\"hello\":\"world\",/*COMMENT*/\"answer\":42}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + REQUIRE(obj["answer"] == 42); + } + } + + SECTION("Trailing comments") { + SECTION("Before opening brace") { + DeserializationError err = + deserializeJson(doc, "//COMMENT\n {\"hello\":\"world\"}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("After opening brace") { + DeserializationError err = + deserializeJson(doc, "{//COMMENT\n\"hello\":\"world\"}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("Before colon") { + DeserializationError err = + deserializeJson(doc, "{\"hello\"//COMMENT\n:\"world\"}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("After colon") { + DeserializationError err = + deserializeJson(doc, "{\"hello\"://COMMENT\n\"world\"}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("Before closing brace") { + DeserializationError err = + deserializeJson(doc, "{\"hello\":\"world\"//COMMENT\n}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("After closing brace") { + DeserializationError err = + deserializeJson(doc, "{\"hello\":\"world\"}//COMMENT\n"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("Before comma") { + DeserializationError err = deserializeJson( + doc, "{\"hello\":\"world\"//COMMENT\n,\"answer\":42}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + REQUIRE(obj["answer"] == 42); + } + + SECTION("After comma") { + DeserializationError err = deserializeJson( + doc, "{\"hello\":\"world\",//COMMENT\n\"answer\":42}"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + REQUIRE(obj["answer"] == 42); + } + } + + SECTION("Dangling slash") { + SECTION("Before opening brace") { + DeserializationError err = deserializeJson(doc, "/{\"hello\":\"world\"}"); + + REQUIRE(err == DeserializationError::InvalidInput); + } + + SECTION("After opening brace") { + DeserializationError err = deserializeJson(doc, "{/\"hello\":\"world\"}"); + + REQUIRE(err == DeserializationError::InvalidInput); + } + + SECTION("Before colon") { + DeserializationError err = deserializeJson(doc, "{\"hello\"/:\"world\"}"); + + REQUIRE(err == DeserializationError::InvalidInput); + } + + SECTION("After colon") { + DeserializationError err = deserializeJson(doc, "{\"hello\":/\"world\"}"); + + REQUIRE(err == DeserializationError::InvalidInput); + } + + SECTION("Before closing brace") { + DeserializationError err = deserializeJson(doc, "{\"hello\":\"world\"/}"); + + REQUIRE(err == DeserializationError::InvalidInput); + } + + SECTION("After closing brace") { + DeserializationError err = deserializeJson(doc, "{\"hello\":\"world\"}/"); + JsonObject obj = doc.as(); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(obj["hello"] == "world"); + } + + SECTION("Before comma") { + DeserializationError err = + deserializeJson(doc, "{\"hello\":\"world\"/,\"answer\":42}"); + + REQUIRE(err == DeserializationError::InvalidInput); + } + + SECTION("After comma") { + DeserializationError err = + deserializeJson(doc, "{\"hello\":\"world\",/\"answer\":42}"); + + REQUIRE(err == DeserializationError::InvalidInput); + } + } +} + +TEST_CASE("Comments alone") { + DynamicJsonDocument doc(2048); + + SECTION("Just a trailing comment") { + DeserializationError err = deserializeJson(doc, "// comment"); + + REQUIRE(err == DeserializationError::IncompleteInput); + } + + SECTION("Just a block comment") { + DeserializationError err = deserializeJson(doc, "/*comment*/"); + + REQUIRE(err == DeserializationError::IncompleteInput); + } + + SECTION("Just a slash") { + DeserializationError err = deserializeJson(doc, "/"); + + REQUIRE(err == DeserializationError::InvalidInput); + } + + SECTION("Premature terminator") { + DeserializationError err = deserializeJson(doc, "/* comment"); + + REQUIRE(err == DeserializationError::IncompleteInput); + } + + SECTION("Premature end on sized input") { + DeserializationError err = deserializeJson(doc, "/* comment */", 10); + + REQUIRE(err == DeserializationError::IncompleteInput); + } +} diff --git a/lib/ArduinoJson-6.x/test/MixedConfiguration/enable_infinity_0.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_infinity_0.cpp similarity index 100% rename from lib/ArduinoJson-6.x/test/MixedConfiguration/enable_infinity_0.cpp rename to lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_infinity_0.cpp diff --git a/lib/ArduinoJson-6.x/test/MixedConfiguration/enable_infinity_1.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_infinity_1.cpp similarity index 100% rename from lib/ArduinoJson-6.x/test/MixedConfiguration/enable_infinity_1.cpp rename to lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_infinity_1.cpp diff --git a/lib/ArduinoJson-6.x/test/MixedConfiguration/enable_nan_0.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_nan_0.cpp similarity index 100% rename from lib/ArduinoJson-6.x/test/MixedConfiguration/enable_nan_0.cpp rename to lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_nan_0.cpp diff --git a/lib/ArduinoJson-6.x/test/MixedConfiguration/enable_nan_1.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_nan_1.cpp similarity index 100% rename from lib/ArduinoJson-6.x/test/MixedConfiguration/enable_nan_1.cpp rename to lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_nan_1.cpp diff --git a/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_progmem_1.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_progmem_1.cpp new file mode 100644 index 000000000..5f30b58b8 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/enable_progmem_1.cpp @@ -0,0 +1,167 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include "progmem_emulation.hpp" + +#define ARDUINOJSON_ENABLE_PROGMEM 1 +#include + +#include + +TEST_CASE("Flash strings") { + DynamicJsonDocument doc(2048); + + SECTION("deserializeJson()") { + DeserializationError err = deserializeJson(doc, F("{'hello':'world'}")); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(doc["hello"] == "world"); + } + + SECTION("JsonDocument::operator[]") { + doc[F("hello")] = F("world"); + + REQUIRE(doc["hello"] == "world"); + } + + SECTION("JsonDocument::add()") { + doc.add(F("world")); + + REQUIRE(doc[0] == "world"); + } + + SECTION("JsonVariant::set()") { + JsonVariant var = doc.to(); + + var.set(F("world")); + + REQUIRE(var == "world"); + } + + SECTION("MemberProxy::operator==") { + doc["hello"] = "world"; + + REQUIRE(doc["hello"] == F("world")); + } + + SECTION("ElementProxy::operator==") { + doc.add("world"); + + REQUIRE(doc[0] == F("world")); + } +} + +TEST_CASE("strlen_P") { + CHECK(strlen_P(FC("")) == 0); + CHECK(strlen_P(FC("a")) == 1); + CHECK(strlen_P(FC("ac")) == 2); +} + +TEST_CASE("strncmp_P") { + CHECK(strncmp_P("a", FC("b"), 0) == 0); + CHECK(strncmp_P("a", FC("b"), 1) == -1); + CHECK(strncmp_P("b", FC("a"), 1) == 1); + CHECK(strncmp_P("a", FC("a"), 0) == 0); + CHECK(strncmp_P("a", FC("b"), 2) == -1); + CHECK(strncmp_P("b", FC("a"), 2) == 1); + CHECK(strncmp_P("a", FC("a"), 2) == 0); +} + +TEST_CASE("strcmp_P") { + CHECK(strcmp_P("a", FC("b")) == -1); + CHECK(strcmp_P("b", FC("a")) == 1); + CHECK(strcmp_P("a", FC("a")) == 0); + CHECK(strcmp_P("aa", FC("ab")) == -1); + CHECK(strcmp_P("ab", FC("aa")) == 1); + CHECK(strcmp_P("aa", FC("aa")) == 0); +} + +TEST_CASE("memcpy_P") { + char dst[4]; + CHECK(memcpy_P(dst, FC("ABC"), 4) == dst); + CHECK(dst[0] == 'A'); + CHECK(dst[1] == 'B'); + CHECK(dst[2] == 'C'); + CHECK(dst[3] == 0); +} + +TEST_CASE("BoundedReader") { + using namespace ARDUINOJSON_NAMESPACE; + + SECTION("read") { + BoundedReader reader(F("\x01\xFF"), 2); + REQUIRE(reader.read() == 0x01); + REQUIRE(reader.read() == 0xFF); + REQUIRE(reader.read() == -1); + REQUIRE(reader.read() == -1); + } + + SECTION("readBytes() all at once") { + BoundedReader reader(F("ABCD"), 3); + + char buffer[8] = "abcd"; + REQUIRE(reader.readBytes(buffer, 4) == 3); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'd'); + } + + SECTION("readBytes() in two parts") { + BoundedReader reader(F("ABCDEF"), 6); + + char buffer[8] = "abcdefg"; + REQUIRE(reader.readBytes(buffer, 4) == 4); + REQUIRE(reader.readBytes(buffer + 4, 4) == 2); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'D'); + REQUIRE(buffer[4] == 'E'); + REQUIRE(buffer[5] == 'F'); + REQUIRE(buffer[6] == 'g'); + } +} + +TEST_CASE("Reader") { + using namespace ARDUINOJSON_NAMESPACE; + + SECTION("read()") { + Reader reader(F("\x01\xFF\x00\x12")); + REQUIRE(reader.read() == 0x01); + REQUIRE(reader.read() == 0xFF); + REQUIRE(reader.read() == 0); + REQUIRE(reader.read() == 0x12); + } + + SECTION("readBytes() all at once") { + Reader reader(F("ABCD")); + + char buffer[8] = "abcd"; + REQUIRE(reader.readBytes(buffer, 3) == 3); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'd'); + } + + SECTION("readBytes() in two parts") { + Reader reader(F("ABCDEF")); + + char buffer[8] = "abcdefg"; + REQUIRE(reader.readBytes(buffer, 4) == 4); + REQUIRE(reader.readBytes(buffer + 4, 2) == 2); + + REQUIRE(buffer[0] == 'A'); + REQUIRE(buffer[1] == 'B'); + REQUIRE(buffer[2] == 'C'); + REQUIRE(buffer[3] == 'D'); + REQUIRE(buffer[4] == 'E'); + REQUIRE(buffer[5] == 'F'); + REQUIRE(buffer[6] == 'g'); + } +} diff --git a/lib/ArduinoJson-6.x/test/MixedConfiguration/use_double_0.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/use_double_0.cpp similarity index 100% rename from lib/ArduinoJson-6.x/test/MixedConfiguration/use_double_0.cpp rename to lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/use_double_0.cpp diff --git a/lib/ArduinoJson-6.x/test/MixedConfiguration/use_double_1.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/use_double_1.cpp similarity index 100% rename from lib/ArduinoJson-6.x/test/MixedConfiguration/use_double_1.cpp rename to lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/use_double_1.cpp diff --git a/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/use_long_long_0.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/use_long_long_0.cpp new file mode 100644 index 000000000..f467aabdd --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/use_long_long_0.cpp @@ -0,0 +1,16 @@ +#define ARDUINOJSON_USE_LONG_LONG 0 +#include + +#include + +TEST_CASE("ARDUINOJSON_USE_LONG_LONG == 0") { + DynamicJsonDocument doc(4096); + + doc["A"] = 42; + doc["B"] = 84; + + std::string json; + serializeJson(doc, json); + + REQUIRE(json == "{\"A\":42,\"B\":84}"); +} diff --git a/lib/ArduinoJson-6.x/test/MixedConfiguration/use_long_long_1.cpp b/lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/use_long_long_1.cpp similarity index 100% rename from lib/ArduinoJson-6.x/test/MixedConfiguration/use_long_long_1.cpp rename to lib/ArduinoJson-6.x/extras/tests/MixedConfiguration/use_long_long_1.cpp diff --git a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/CMakeLists.txt similarity index 78% rename from lib/ArduinoJson-6.x/test/MsgPackDeserializer/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/CMakeLists.txt index 837a21d08..f3f52f086 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(MsgPackDeserializerTests @@ -14,5 +14,4 @@ add_executable(MsgPackDeserializerTests notSupported.cpp ) -target_link_libraries(MsgPackDeserializerTests catch) add_test(MsgPackDeserializer MsgPackDeserializerTests) diff --git a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeArray.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeArray.cpp similarity index 98% rename from lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeArray.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeArray.cpp index 2b9b4deb8..3aa56de9e 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeArray.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeArray.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeObject.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeObject.cpp similarity index 98% rename from lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeObject.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeObject.cpp index d5108575b..12df65ee9 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeObject.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeObject.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeStaticVariant.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeStaticVariant.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeStaticVariant.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeStaticVariant.cpp index d445100be..9ae14a861 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeStaticVariant.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeStaticVariant.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -7,9 +7,9 @@ template static void check(const char* input, DeserializationError expected) { - StaticJsonDocument variant; + StaticJsonDocument doc; - DeserializationError error = deserializeMsgPack(variant, input); + DeserializationError error = deserializeMsgPack(doc, input); CAPTURE(input); REQUIRE(error == expected); @@ -17,7 +17,7 @@ static void check(const char* input, DeserializationError expected) { template static void checkString(const char* input, DeserializationError expected) { - check(input, expected); + check(input, expected); } TEST_CASE("deserializeMsgPack(StaticJsonDocument&)") { diff --git a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeVariant.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeVariant.cpp similarity index 99% rename from lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeVariant.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeVariant.cpp index 1d8b6f08d..76cd01cc7 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/deserializeVariant.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/deserializeVariant.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/doubleToFloat.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/doubleToFloat.cpp similarity index 94% rename from lib/ArduinoJson-6.x/test/MsgPackDeserializer/doubleToFloat.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/doubleToFloat.cpp index 4d2955350..0c092eee7 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/doubleToFloat.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/doubleToFloat.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/incompleteInput.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/incompleteInput.cpp similarity index 95% rename from lib/ArduinoJson-6.x/test/MsgPackDeserializer/incompleteInput.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/incompleteInput.cpp index 883f7d9ab..a25cad2b8 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/incompleteInput.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/incompleteInput.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -46,6 +46,7 @@ TEST_CASE("deserializeMsgPack() returns IncompleteInput") { SECTION("map 32") { checkAllSizes("\xDF\x00\x00\x00\x01\xA3one\x01", 10); + checkAllSizes("\xDF\x00\x00\x00\x01\xd9\x03one\x01", 11); } SECTION("uint 8") { diff --git a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/input_types.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/input_types.cpp similarity index 84% rename from lib/ArduinoJson-6.x/test/MsgPackDeserializer/input_types.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/input_types.cpp index 3b20add45..afd370f91 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/input_types.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/input_types.cpp @@ -1,10 +1,12 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include #include +#include "CustomReader.hpp" + TEST_CASE("deserializeMsgPack(const std::string&)") { DynamicJsonDocument doc(4096); @@ -80,3 +82,14 @@ TEST_CASE("deserializeMsgPack(VLA)") { REQUIRE(err == DeserializationError::Ok); } #endif + +TEST_CASE("deserializeMsgPack(CustomReader)") { + DynamicJsonDocument doc(4096); + CustomReader reader("\x92\xA5Hello\xA5world"); + DeserializationError err = deserializeMsgPack(doc, reader); + + REQUIRE(err == DeserializationError::Ok); + REQUIRE(doc.size() == 2); + REQUIRE(doc[0] == "Hello"); + REQUIRE(doc[1] == "world"); +} diff --git a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/nestingLimit.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/nestingLimit.cpp similarity index 98% rename from lib/ArduinoJson-6.x/test/MsgPackDeserializer/nestingLimit.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/nestingLimit.cpp index 9084f14d7..9eee94b87 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/nestingLimit.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/nestingLimit.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/notSupported.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/notSupported.cpp similarity index 97% rename from lib/ArduinoJson-6.x/test/MsgPackDeserializer/notSupported.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/notSupported.cpp index b2857d105..165791250 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackDeserializer/notSupported.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackDeserializer/notSupported.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MsgPackSerializer/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/CMakeLists.txt similarity index 73% rename from lib/ArduinoJson-6.x/test/MsgPackSerializer/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/CMakeLists.txt index e4517bda9..ccb7cb6a0 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackSerializer/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(MsgPackSerializerTests @@ -11,5 +11,4 @@ add_executable(MsgPackSerializerTests serializeVariant.cpp ) -target_link_libraries(MsgPackSerializerTests catch) add_test(MsgPackSerializer MsgPackSerializerTests) diff --git a/lib/ArduinoJson-6.x/test/MsgPackSerializer/destination_types.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/destination_types.cpp similarity index 96% rename from lib/ArduinoJson-6.x/test/MsgPackSerializer/destination_types.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/destination_types.cpp index 6ea7b5a40..989c73cb1 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackSerializer/destination_types.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/destination_types.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MsgPackSerializer/measure.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/measure.cpp similarity index 87% rename from lib/ArduinoJson-6.x/test/MsgPackSerializer/measure.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/measure.cpp index c519199a7..a31e8efe4 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackSerializer/measure.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/measure.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MsgPackSerializer/misc.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/misc.cpp similarity index 100% rename from lib/ArduinoJson-6.x/test/MsgPackSerializer/misc.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/misc.cpp diff --git a/lib/ArduinoJson-6.x/test/MsgPackSerializer/serializeArray.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/serializeArray.cpp similarity index 97% rename from lib/ArduinoJson-6.x/test/MsgPackSerializer/serializeArray.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/serializeArray.cpp index dbc2d032c..8a4e3491e 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackSerializer/serializeArray.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/serializeArray.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/test/MsgPackSerializer/serializeObject.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/serializeObject.cpp similarity index 98% rename from lib/ArduinoJson-6.x/test/MsgPackSerializer/serializeObject.cpp rename to lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/serializeObject.cpp index 836539822..dbe746432 100644 --- a/lib/ArduinoJson-6.x/test/MsgPackSerializer/serializeObject.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/serializeObject.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/serializeVariant.cpp b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/serializeVariant.cpp new file mode 100644 index 000000000..22e8d0bfd --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/MsgPackSerializer/serializeVariant.cpp @@ -0,0 +1,141 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include + +template +static void checkVariant(T value, const char* expected_data, + size_t expected_len) { + DynamicJsonDocument doc(4096); + JsonVariant variant = doc.to(); + variant.set(value); + std::string expected(expected_data, expected_data + expected_len); + std::string actual; + size_t len = serializeMsgPack(variant, actual); + CAPTURE(variant); + REQUIRE(len == expected_len); + REQUIRE(actual == expected); +} + +template +static void checkVariant(T value, const char (&expected_data)[N]) { + const size_t expected_len = N - 1; + checkVariant(value, expected_data, expected_len); +} + +template +static void checkVariant(T value, const std::string& expected) { + checkVariant(value, expected.data(), expected.length()); +} + +TEST_CASE("serialize MsgPack value") { + SECTION("undefined") { + checkVariant(JsonVariant(), "\xC0"); // we represent undefined as nil + } + + SECTION("nil") { + const char* nil = 0; // ArduinoJson uses a string for null + checkVariant(nil, "\xC0"); + } + + SECTION("bool") { + checkVariant(false, "\xC2"); + checkVariant(true, "\xC3"); + } + + SECTION("positive fixint") { + checkVariant(0, "\x00"); + checkVariant(127, "\x7F"); + } + + SECTION("uint 8") { + checkVariant(128, "\xCC\x80"); + checkVariant(255, "\xCC\xFF"); + } + + SECTION("uint 16") { + checkVariant(256, "\xCD\x01\x00"); + checkVariant(0xFFFF, "\xCD\xFF\xFF"); + } + + SECTION("uint 32") { + checkVariant(0x00010000U, "\xCE\x00\x01\x00\x00"); + checkVariant(0x12345678U, "\xCE\x12\x34\x56\x78"); + checkVariant(0xFFFFFFFFU, "\xCE\xFF\xFF\xFF\xFF"); + } + +#if ARDUINOJSON_USE_LONG_LONG + SECTION("uint 64") { + checkVariant(0x0001000000000000U, "\xCF\x00\x01\x00\x00\x00\x00\x00\x00"); + checkVariant(0x123456789ABCDEF0U, "\xCF\x12\x34\x56\x78\x9A\xBC\xDE\xF0"); + checkVariant(0xFFFFFFFFFFFFFFFFU, "\xCF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"); + } +#endif + + SECTION("negative fixint") { + checkVariant(-1, "\xFF"); + checkVariant(-32, "\xE0"); + } + + SECTION("int 8") { + checkVariant(-33, "\xD0\xDF"); + checkVariant(-128, "\xD0\x80"); + } + + SECTION("int 16") { + checkVariant(-129, "\xD1\xFF\x7F"); + checkVariant(-32768, "\xD1\x80\x00"); + } + + SECTION("int 32") { + checkVariant(-32769, "\xD2\xFF\xFF\x7F\xFF"); + checkVariant(-2147483647 - 1, "\xD2\x80\x00\x00\x00"); + } + +#if ARDUINOJSON_USE_LONG_LONG + SECTION("int 64") { + checkVariant(int64_t(0xFEDCBA9876543210), + "\xD3\xFE\xDC\xBA\x98\x76\x54\x32\x10"); + } +#endif + + SECTION("float 32") { + checkVariant(1.25, "\xCA\x3F\xA0\x00\x00"); + } + + SECTION("float 64") { + checkVariant(3.1415, "\xCB\x40\x09\x21\xCA\xC0\x83\x12\x6F"); + } + + SECTION("fixstr") { + checkVariant("", "\xA0"); + checkVariant("hello world hello world hello !", + "\xBFhello world hello world hello !"); + } + + SECTION("str 8") { + checkVariant("hello world hello world hello !!", + "\xD9\x20hello world hello world hello !!"); + } + + SECTION("str 16") { + std::string shortest(256, '?'); + checkVariant(shortest.c_str(), std::string("\xDA\x01\x00", 3) + shortest); + + std::string longest(65535, '?'); + checkVariant(longest.c_str(), std::string("\xDA\xFF\xFF", 3) + longest); + } + + SECTION("str 32") { + std::string shortest(65536, '?'); + checkVariant(shortest.c_str(), + std::string("\xDB\x00\x01\x00\x00", 5) + shortest); + } + + SECTION("serialized(const char*)") { + checkVariant(serialized("\xDA\xFF\xFF"), "\xDA\xFF\xFF"); + checkVariant(serialized("\xDB\x00\x01\x00\x00", 5), "\xDB\x00\x01\x00\x00"); + } +} diff --git a/lib/ArduinoJson-6.x/test/Numbers/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/Numbers/CMakeLists.txt similarity index 66% rename from lib/ArduinoJson-6.x/test/Numbers/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/Numbers/CMakeLists.txt index 4e39bd9bf..50ab51353 100644 --- a/lib/ArduinoJson-6.x/test/Numbers/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/Numbers/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_executable(NumbersTests @@ -8,5 +8,5 @@ add_executable(NumbersTests parseNumber.cpp ) -target_link_libraries(NumbersTests catch) + add_test(Numbers NumbersTests) diff --git a/lib/ArduinoJson-6.x/extras/tests/Numbers/parseFloat.cpp b/lib/ArduinoJson-6.x/extras/tests/Numbers/parseFloat.cpp new file mode 100644 index 000000000..f79d69761 --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Numbers/parseFloat.cpp @@ -0,0 +1,172 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#define ARDUINOJSON_USE_DOUBLE 0 +#define ARDUINOJSON_ENABLE_NAN 1 +#define ARDUINOJSON_ENABLE_INFINITY 1 + +#include +#include + +using namespace ARDUINOJSON_NAMESPACE; + +template +void checkFloat(const char* input, T expected) { + CAPTURE(input); + REQUIRE(parseFloat(input) == Approx(expected)); +} + +template +void checkNaN(const char* input) { + CAPTURE(input); + T result = parseFloat(input); + REQUIRE(result != result); +} + +template +void checkInf(const char* input, bool negative) { + CAPTURE(input); + T x = parseFloat(input); + if (negative) + REQUIRE(x < 0); + else + REQUIRE(x > 0); + REQUIRE(x == x); // not a NaN + REQUIRE(x * 2 == x); // a property of infinity +} + +TEST_CASE("parseFloat()") { + SECTION("Float_Short_NoExponent") { + checkFloat("3.14", 3.14f); + checkFloat("-3.14", -3.14f); + checkFloat("+3.14", +3.14f); + } + + SECTION("Short_NoDot") { + checkFloat("1E+38", 1E+38f); + checkFloat("-1E+38", -1E+38f); + checkFloat("+1E-38", +1E-38f); + checkFloat("+1e+38", +1e+38f); + checkFloat("-1e-38", -1e-38f); + } + + SECTION("Max") { + checkFloat("340.2823e+36", 3.402823e+38f); + checkFloat("34.02823e+37", 3.402823e+38f); + checkFloat("3.402823e+38", 3.402823e+38f); + checkFloat("0.3402823e+39", 3.402823e+38f); + checkFloat("0.03402823e+40", 3.402823e+38f); + checkFloat("0.003402823e+41", 3.402823e+38f); + } + + SECTION("VeryLong") { + checkFloat("0.00000000000000000000000000000001", 1e-32f); + checkFloat("100000000000000000000000000000000.0", 1e+32f); + checkFloat( + "100000000000000000000000000000000.00000000000000000000000000000", + 1e+32f); + } + + SECTION("MantissaTooLongToFit") { + checkFloat("0.340282346638528861111111111111", 0.34028234663852886f); + checkFloat("34028234663852886.11111111111111", 34028234663852886.0f); + checkFloat("34028234.66385288611111111111111", 34028234.663852886f); + + checkFloat("-0.340282346638528861111111111111", + -0.34028234663852886f); + checkFloat("-34028234663852886.11111111111111", + -34028234663852886.0f); + checkFloat("-34028234.66385288611111111111111", + -34028234.663852886f); + } + + SECTION("ExponentTooBig") { + checkInf("1e39", false); + checkInf("-1e39", true); + checkInf("1e255", false); + checkFloat("1e-255", 0.0f); + } + + SECTION("NaN") { + checkNaN("NaN"); + checkNaN("nan"); + } + + SECTION("Infinity") { + checkInf("Infinity", false); + checkInf("+Infinity", false); + checkInf("-Infinity", true); + checkInf("inf", false); + checkInf("+inf", false); + checkInf("-inf", true); + + checkInf("1e300", false); + checkInf("-1e300", true); + } +} + +TEST_CASE("parseFloat()") { + SECTION("Short_NoExponent") { + checkFloat("3.14", 3.14); + checkFloat("-3.14", -3.14); + checkFloat("+3.14", +3.14); + } + + SECTION("Short_NoDot") { + checkFloat("1E+308", 1E+308); + checkFloat("-1E+308", -1E+308); + checkFloat("+1E-308", +1E-308); + checkFloat("+1e+308", +1e+308); + checkFloat("-1e-308", -1e-308); + } + + SECTION("Max") { + checkFloat(".017976931348623147e+310", 1.7976931348623147e+308); + checkFloat(".17976931348623147e+309", 1.7976931348623147e+308); + checkFloat("1.7976931348623147e+308", 1.7976931348623147e+308); + checkFloat("17.976931348623147e+307", 1.7976931348623147e+308); + checkFloat("179.76931348623147e+306", 1.7976931348623147e+308); + } + + SECTION("Min") { + checkFloat(".022250738585072014e-306", 2.2250738585072014e-308); + checkFloat(".22250738585072014e-307", 2.2250738585072014e-308); + checkFloat("2.2250738585072014e-308", 2.2250738585072014e-308); + checkFloat("22.250738585072014e-309", 2.2250738585072014e-308); + checkFloat("222.50738585072014e-310", 2.2250738585072014e-308); + } + + SECTION("VeryLong") { + checkFloat("0.00000000000000000000000000000001", 1e-32); + checkFloat("100000000000000000000000000000000.0", 1e+32); + checkFloat( + "100000000000000000000000000000000.00000000000000000000000000000", + 1e+32); + } + + SECTION("MantissaTooLongToFit") { + checkFloat("0.179769313486231571111111111111", 0.17976931348623157); + checkFloat("17976931348623157.11111111111111", 17976931348623157.0); + checkFloat("1797693.134862315711111111111111", 1797693.1348623157); + + checkFloat("-0.179769313486231571111111111111", + -0.17976931348623157); + checkFloat("-17976931348623157.11111111111111", + -17976931348623157.0); + checkFloat("-1797693.134862315711111111111111", + -1797693.1348623157); + } + + SECTION("ExponentTooBig") { + checkInf("1e309", false); + checkInf("-1e309", true); + checkInf("1e65535", false); + checkFloat("1e-65535", 0.0); + } + + SECTION("NaN") { + checkNaN("NaN"); + checkNaN("nan"); + } +} diff --git a/lib/ArduinoJson-6.x/extras/tests/Numbers/parseInteger.cpp b/lib/ArduinoJson-6.x/extras/tests/Numbers/parseInteger.cpp new file mode 100644 index 000000000..44f4a182b --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/Numbers/parseInteger.cpp @@ -0,0 +1,67 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include +#include +#include + +using namespace ARDUINOJSON_NAMESPACE; + +template +void checkInteger(const char* input, T expected) { + CAPTURE(input); + T actual = parseInteger(input); + REQUIRE(expected == actual); +} + +TEST_CASE("parseInteger()") { + checkInteger("-128", -128); + checkInteger("127", 127); + checkInteger("+127", 127); + checkInteger("3.14", 3); + checkInteger("x42", 0); + checkInteger("128", 0); // overflow + checkInteger("-129", 0); // overflow +} + +TEST_CASE("parseInteger()") { + checkInteger("-32768", -32768); + checkInteger("32767", 32767); + checkInteger("+32767", 32767); + checkInteger("3.14", 3); + checkInteger("x42", 0); + checkInteger("-32769", 0); // overflow + checkInteger("32768", 0); // overflow +} + +TEST_CASE("parseInteger()") { + checkInteger("-2147483648", (-2147483647 - 1)); + checkInteger("2147483647", 2147483647); + checkInteger("+2147483647", 2147483647); + checkInteger("3.14", 3); + checkInteger("x42", 0); + checkInteger("-2147483649", 0); // overflow + checkInteger("2147483648", 0); // overflow +} + +TEST_CASE("parseInteger()") { + checkInteger("0", 0); + checkInteger("255", 255); + checkInteger("+255", 255); + checkInteger("3.14", 3); + checkInteger("x42", 0); + checkInteger("-1", 0); + checkInteger("256", 0); +} + +TEST_CASE("parseInteger()") { + checkInteger("0", 0); + checkInteger("65535", 65535); + checkInteger("+65535", 65535); + checkInteger("3.14", 3); + // checkInteger(" 42", 0); + checkInteger("x42", 0); + checkInteger("-1", 0); + checkInteger("65536", 0); +} diff --git a/lib/ArduinoJson-6.x/test/Numbers/parseNumber.cpp b/lib/ArduinoJson-6.x/extras/tests/Numbers/parseNumber.cpp similarity index 94% rename from lib/ArduinoJson-6.x/test/Numbers/parseNumber.cpp rename to lib/ArduinoJson-6.x/extras/tests/Numbers/parseNumber.cpp index 320aed736..01b53cae6 100644 --- a/lib/ArduinoJson-6.x/test/Numbers/parseNumber.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/Numbers/parseNumber.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include diff --git a/lib/ArduinoJson-6.x/extras/tests/TextFormatter/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/TextFormatter/CMakeLists.txt new file mode 100644 index 000000000..41f5c97ca --- /dev/null +++ b/lib/ArduinoJson-6.x/extras/tests/TextFormatter/CMakeLists.txt @@ -0,0 +1,12 @@ +# ArduinoJson - arduinojson.org +# Copyright Benoit Blanchon 2014-2020 +# MIT License + +add_executable(TextFormatterTests + writeFloat.cpp + writeString.cpp +) + +set_target_properties(TextFormatterTests PROPERTIES UNITY_BUILD OFF) + +add_test(TextFormatter TextFormatterTests) diff --git a/lib/ArduinoJson-6.x/test/TextFormatter/writeFloat.cpp b/lib/ArduinoJson-6.x/extras/tests/TextFormatter/writeFloat.cpp similarity index 93% rename from lib/ArduinoJson-6.x/test/TextFormatter/writeFloat.cpp rename to lib/ArduinoJson-6.x/extras/tests/TextFormatter/writeFloat.cpp index 39abe98ee..e3cf6cf02 100644 --- a/lib/ArduinoJson-6.x/test/TextFormatter/writeFloat.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/TextFormatter/writeFloat.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include @@ -9,15 +9,15 @@ #define ARDUINOJSON_ENABLE_NAN 1 #define ARDUINOJSON_ENABLE_INFINITY 1 #include -#include +#include using namespace ARDUINOJSON_NAMESPACE; template void check(TFloat input, const std::string& expected) { std::string output; - DynamicStringWriter sb(output); - TextFormatter > writer(sb); + Writer sb(output); + TextFormatter > writer(sb); writer.writeFloat(input); REQUIRE(writer.bytesWritten() == output.size()); CHECK(expected == output); diff --git a/lib/ArduinoJson-6.x/test/TextFormatter/writeString.cpp b/lib/ArduinoJson-6.x/extras/tests/TextFormatter/writeString.cpp similarity index 87% rename from lib/ArduinoJson-6.x/test/TextFormatter/writeString.cpp rename to lib/ArduinoJson-6.x/extras/tests/TextFormatter/writeString.cpp index 8dbf2848d..8341b6cb3 100644 --- a/lib/ArduinoJson-6.x/test/TextFormatter/writeString.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/TextFormatter/writeString.cpp @@ -1,11 +1,11 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #include #include -#include +#include using namespace ARDUINOJSON_NAMESPACE; @@ -19,10 +19,6 @@ void check(const char* input, std::string expected) { } TEST_CASE("TextFormatter::writeString()") { - SECTION("Null") { - check(0, "null"); - } - SECTION("EmptyString") { check("", "\"\""); } diff --git a/lib/ArduinoJson-6.x/third-party/catch/CMakeLists.txt b/lib/ArduinoJson-6.x/extras/tests/catch/CMakeLists.txt similarity index 89% rename from lib/ArduinoJson-6.x/third-party/catch/CMakeLists.txt rename to lib/ArduinoJson-6.x/extras/tests/catch/CMakeLists.txt index b9817a877..42cf05a25 100644 --- a/lib/ArduinoJson-6.x/third-party/catch/CMakeLists.txt +++ b/lib/ArduinoJson-6.x/extras/tests/catch/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - arduinojson.org -# Copyright Benoit Blanchon 2014-2019 +# Copyright Benoit Blanchon 2014-2020 # MIT License add_library(catch diff --git a/lib/ArduinoJson-6.x/third-party/catch/catch.cpp b/lib/ArduinoJson-6.x/extras/tests/catch/catch.cpp similarity index 71% rename from lib/ArduinoJson-6.x/third-party/catch/catch.cpp rename to lib/ArduinoJson-6.x/extras/tests/catch/catch.cpp index 9b9214a64..8d052a75c 100644 --- a/lib/ArduinoJson-6.x/third-party/catch/catch.cpp +++ b/lib/ArduinoJson-6.x/extras/tests/catch/catch.cpp @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #define CATCH_CONFIG_MAIN diff --git a/lib/ArduinoJson-6.x/third-party/catch/catch.hpp b/lib/ArduinoJson-6.x/extras/tests/catch/catch.hpp similarity index 100% rename from lib/ArduinoJson-6.x/third-party/catch/catch.hpp rename to lib/ArduinoJson-6.x/extras/tests/catch/catch.hpp diff --git a/lib/ArduinoJson-6.x/keywords.txt b/lib/ArduinoJson-6.x/keywords.txt index 7dc2b8073..a0c8d3810 100644 --- a/lib/ArduinoJson-6.x/keywords.txt +++ b/lib/ArduinoJson-6.x/keywords.txt @@ -10,6 +10,9 @@ serialized KEYWORD2 serializeJson KEYWORD2 serializeJsonPretty KEYWORD2 serializeMsgPack KEYWORD2 +measureJson KEYWORD2 +measureJsonPretty KEYWORD2 +measureMsgPack KEYWORD2 # Methods add KEYWORD2 diff --git a/lib/ArduinoJson-6.x/library.json b/lib/ArduinoJson-6.x/library.json index 45c2d410f..a50d9cdf8 100644 --- a/lib/ArduinoJson-6.x/library.json +++ b/lib/ArduinoJson-6.x/library.json @@ -1,22 +1,20 @@ { "name": "ArduinoJson", "keywords": "json, rest, http, web", - "description": "An elegant and efficient JSON library for embedded systems", + "description": "A simple and efficient JSON library for embedded C++. ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, ✔ filtering, and more. It is the most popular Arduino library on GitHub ❤❤❤❤❤. Check out arduinojson.org for a comprehensive documentation.", "homepage": "https://arduinojson.org/?utm_source=meta&utm_medium=library.json", "repository": { "type": "git", "url": "https://github.com/bblanchon/ArduinoJson.git" }, - "version": "6.11.0", + "version": "6.15.2", "authors": { "name": "Benoit Blanchon", "url": "https://blog.benoitblanchon.fr" }, "exclude": [ - "fuzzing", - "scripts", - "test", - "third-party" + ".github", + "extras" ], "frameworks": "arduino", "platforms": "*" diff --git a/lib/ArduinoJson-6.x/library.properties b/lib/ArduinoJson-6.x/library.properties index a136f2f80..71e7c385f 100644 --- a/lib/ArduinoJson-6.x/library.properties +++ b/lib/ArduinoJson-6.x/library.properties @@ -1,9 +1,9 @@ name=ArduinoJson -version=6.11.0 +version=6.15.2 author=Benoit Blanchon maintainer=Benoit Blanchon -sentence=An efficient and elegant JSON library for Arduino. -paragraph=ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, and more. It is the most popular Arduino library on GitHub ❤❤❤❤❤. Check out arduinojson.org for a comprehensive documentation. +sentence=A simple and efficient JSON library for embedded C++. +paragraph=ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, ✔ filtering, and more. It is the most popular Arduino library on GitHub ❤❤❤❤❤. Check out arduinojson.org for a comprehensive documentation. category=Data Processing url=https://arduinojson.org/?utm_source=meta&utm_medium=library.properties architectures=* diff --git a/lib/ArduinoJson-6.x/scripts/build-single-header.sh b/lib/ArduinoJson-6.x/scripts/build-single-header.sh deleted file mode 100644 index b09e91f60..000000000 --- a/lib/ArduinoJson-6.x/scripts/build-single-header.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -TAG=$(git describe) -RE_INCLUDE='^#include[[:space:]]*["<](.*)[">]' -RE_EMPTY='^(#pragma[[:space:]]+once)?[[:space:]]*(//.*)?$' - -declare -A INCLUDED - -process() -{ - local PARENT=$1 - local FOLDER=$(dirname $1) - local SHOW_COMMENT=$2 - while IFS= read -r LINE; do - if [[ $LINE =~ $RE_INCLUDE ]]; then - local CHILD=${BASH_REMATCH[1]} - pushd "$FOLDER" > /dev/null - if [[ -e $CHILD ]]; then - local CHILD_PATH=$(realpath $CHILD) - if [[ ! ${INCLUDED[$CHILD_PATH]} ]]; then - #echo "// $PARENT -> $CHILD" - INCLUDED[$CHILD_PATH]=true - process "$CHILD" false - fi - else - if [[ ! ${INCLUDED[$CHILD]} ]]; then - echo "$LINE" - INCLUDED[$CHILD]=true - fi - fi - popd > /dev/null - elif [[ "${SHOW_COMMENT}" = "true" ]] ; then - echo "$LINE" - elif [[ ! $LINE =~ $RE_EMPTY ]]; then - echo "$LINE" - fi - done < $PARENT -} - -cd $(dirname $0)/../ -INCLUDED=() -process src/ArduinoJson.h true > ../ArduinoJson-$TAG.h -g++ -x c++ -c -o ../smoketest.o - < ../ArduinoJson-$TAG.hpp -g++ -x c++ -c -o ../smoketest.o - <> $HOME/.profile - echo "export CC='clang'" >> $HOME/.profile - echo "export CXX='clang++'" >> $HOME/.profile - echo "export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/" >> $HOME/.profile - - echo "Run /host/ArduinoJson/fuzzing/fuzz.sh" | sudo tee /etc/motd - SHELL -end diff --git a/lib/ArduinoJson-6.x/scripts/travis/build.sh b/lib/ArduinoJson-6.x/scripts/travis/build.sh deleted file mode 100644 index 34547bee6..000000000 --- a/lib/ArduinoJson-6.x/scripts/travis/build.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -ex - -export CC="$_CC" -export CXX="$_CXX" - -if [ -n "$SANITIZE" ]; then - export CXXFLAGS="-fsanitize=$SANITIZE" - BUILD_TYPE="Debug" -else - BUILD_TYPE="Release" -fi - -cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE . -cmake --build . diff --git a/lib/ArduinoJson-6.x/scripts/travis/test.sh b/lib/ArduinoJson-6.x/scripts/travis/test.sh deleted file mode 100644 index 031f3eed7..000000000 --- a/lib/ArduinoJson-6.x/scripts/travis/test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -ex - -"$(dirname "$0")/build.sh" -ctest --output-on-failure . diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson.h b/lib/ArduinoJson-6.x/src/ArduinoJson.h index 3e29f397c..e5aac0fed 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson.h +++ b/lib/ArduinoJson-6.x/src/ArduinoJson.h @@ -1,5 +1,5 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson.hpp index cb3704ee6..a5da7a2e1 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson.hpp @@ -1,10 +1,12 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#ifndef ARDUINOJSON_DEBUG +#include "ArduinoJson/Configuration.hpp" + +#if !ARDUINOJSON_DEBUG #ifdef __clang__ #pragma clang system_header #elif defined __GNUC__ @@ -12,8 +14,6 @@ #endif #endif -#include "ArduinoJson/Namespace.hpp" - #include "ArduinoJson/Array/ArrayRef.hpp" #include "ArduinoJson/Object/ObjectRef.hpp" #include "ArduinoJson/Variant/VariantRef.hpp" @@ -28,6 +28,7 @@ #include "ArduinoJson/Object/MemberProxy.hpp" #include "ArduinoJson/Object/ObjectImpl.hpp" #include "ArduinoJson/Variant/VariantAsImpl.hpp" +#include "ArduinoJson/Variant/VariantCompare.hpp" #include "ArduinoJson/Variant/VariantImpl.hpp" #include "ArduinoJson/Json/JsonDeserializer.hpp" @@ -46,6 +47,7 @@ typedef ARDUINOJSON_NAMESPACE::Integer JsonInteger; typedef ARDUINOJSON_NAMESPACE::ObjectConstRef JsonObjectConst; typedef ARDUINOJSON_NAMESPACE::ObjectRef JsonObject; typedef ARDUINOJSON_NAMESPACE::Pair JsonPair; +typedef ARDUINOJSON_NAMESPACE::PairConst JsonPairConst; typedef ARDUINOJSON_NAMESPACE::String JsonString; typedef ARDUINOJSON_NAMESPACE::UInt JsonUInt; typedef ARDUINOJSON_NAMESPACE::VariantConstRef JsonVariantConst; @@ -57,6 +59,7 @@ using ARDUINOJSON_NAMESPACE::deserializeJson; using ARDUINOJSON_NAMESPACE::deserializeMsgPack; using ARDUINOJSON_NAMESPACE::DynamicJsonDocument; using ARDUINOJSON_NAMESPACE::JsonDocument; +using ARDUINOJSON_NAMESPACE::measureJson; using ARDUINOJSON_NAMESPACE::serialized; using ARDUINOJSON_NAMESPACE::serializeJson; using ARDUINOJSON_NAMESPACE::serializeJsonPretty; @@ -64,6 +67,7 @@ using ARDUINOJSON_NAMESPACE::serializeMsgPack; using ARDUINOJSON_NAMESPACE::StaticJsonDocument; namespace DeserializationOption { +using ARDUINOJSON_NAMESPACE::Filter; using ARDUINOJSON_NAMESPACE::NestingLimit; -} +} // namespace DeserializationOption } // namespace ArduinoJson diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayFunctions.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayFunctions.hpp index ec0dedd4b..c8335d289 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayFunctions.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayFunctions.hpp @@ -1,15 +1,15 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#include "../Collection/CollectionData.hpp" +#include namespace ARDUINOJSON_NAMESPACE { inline VariantData *arrayAdd(CollectionData *arr, MemoryPool *pool) { - return arr ? arr->add(pool) : 0; + return arr ? arr->addElement(pool) : 0; } template @@ -21,9 +21,10 @@ inline void arrayAccept(const CollectionData *arr, Visitor &visitor) { } inline bool arrayEquals(const CollectionData *lhs, const CollectionData *rhs) { - if (lhs == rhs) return true; - if (!lhs || !rhs) return false; - + if (lhs == rhs) + return true; + if (!lhs || !rhs) + return false; return lhs->equalsArray(*rhs); } } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayImpl.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayImpl.hpp index df0149277..21fe43bca 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayImpl.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayImpl.hpp @@ -1,11 +1,11 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#include "../Object/ObjectRef.hpp" -#include "ArrayRef.hpp" +#include +#include namespace ARDUINOJSON_NAMESPACE { @@ -19,4 +19,10 @@ inline ObjectRef ArrayShortcuts::createNestedObject() const { return impl()->addElement().template to(); } +template +inline ElementProxy ArrayShortcuts::operator[]( + size_t index) const { + return ElementProxy(*impl(), index); +} + } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayIterator.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayIterator.hpp index c1d6096ff..cb158d2b0 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayIterator.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayIterator.hpp @@ -1,11 +1,11 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#include "../Variant/SlotFunctions.hpp" -#include "../Variant/VariantRef.hpp" +#include +#include namespace ARDUINOJSON_NAMESPACE { diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayRef.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayRef.hpp index e34b62335..bb2fbaa7c 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayRef.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayRef.hpp @@ -1,12 +1,12 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#include "../Variant/VariantData.hpp" -#include "ArrayFunctions.hpp" -#include "ArrayIterator.hpp" +#include +#include +#include // Returns the size (in bytes) of an array with n elements. // Can be very handy to determine the size of a StaticMemoryPool. @@ -36,6 +36,10 @@ class ArrayRefBase { return _data == 0; } + FORCE_INLINE operator bool() const { + return _data != 0; + } + FORCE_INLINE size_t memoryUsage() const { return _data ? _data->memoryUsage() : 0; } @@ -62,7 +66,8 @@ class ArrayConstRef : public ArrayRefBase, typedef ArrayConstRefIterator iterator; FORCE_INLINE iterator begin() const { - if (!_data) return iterator(); + if (!_data) + return iterator(); return iterator(_data->head()); } @@ -82,7 +87,7 @@ class ArrayConstRef : public ArrayRefBase, } FORCE_INLINE VariantConstRef getElement(size_t index) const { - return VariantConstRef(_data ? _data->get(index) : 0); + return VariantConstRef(_data ? _data->getElement(index) : 0); } }; @@ -112,7 +117,8 @@ class ArrayRef : public ArrayRefBase, } FORCE_INLINE iterator begin() const { - if (!_data) return iterator(); + if (!_data) + return iterator(); return iterator(_pool, _data->head()); } @@ -122,7 +128,8 @@ class ArrayRef : public ArrayRefBase, // Copy a ArrayRef FORCE_INLINE bool set(ArrayConstRef src) const { - if (!_data || !src._data) return false; + if (!_data || !src._data) + return false; return _data->copyFrom(*src._data, _pool); } @@ -130,21 +137,28 @@ class ArrayRef : public ArrayRefBase, return arrayEquals(_data, rhs._data); } + // Internal use + FORCE_INLINE VariantRef getOrAddElement(size_t index) const { + return VariantRef(_pool, _data ? _data->getOrAddElement(index, _pool) : 0); + } + // Gets the value at the specified index. FORCE_INLINE VariantRef getElement(size_t index) const { - return VariantRef(_pool, _data ? _data->get(index) : 0); + return VariantRef(_pool, _data ? _data->getElement(index) : 0); } // Removes element at specified position. FORCE_INLINE void remove(iterator it) const { - if (!_data) return; - _data->remove(it.internal()); + if (!_data) + return; + _data->removeSlot(it.internal()); } // Removes element at specified index. FORCE_INLINE void remove(size_t index) const { - if (!_data) return; - _data->remove(index); + if (!_data) + return; + _data->removeElement(index); } private: diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayShortcuts.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayShortcuts.hpp index 221f3fd1a..6f1021cd2 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayShortcuts.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ArrayShortcuts.hpp @@ -1,11 +1,11 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#include "../Polyfills/attributes.hpp" -#include "../Polyfills/type_traits.hpp" +#include +#include namespace ARDUINOJSON_NAMESPACE { // Forward declarations. @@ -16,7 +16,7 @@ template class ArrayShortcuts { public: // Returns the element at specified index if the variant is an array. - FORCE_INLINE ElementProxy operator[](size_t index) const; + FORCE_INLINE ElementProxy operator[](size_t index) const; FORCE_INLINE ObjectRef createNestedObject() const; diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ElementProxy.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ElementProxy.hpp index e1c784add..0d0c821e8 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ElementProxy.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/ElementProxy.hpp @@ -1,11 +1,13 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#include "../Configuration.hpp" -#include "../Operators/VariantOperators.hpp" +#include +#include +#include +#include #ifdef _MSC_VER #pragma warning(push) @@ -16,6 +18,7 @@ namespace ARDUINOJSON_NAMESPACE { template class ElementProxy : public VariantOperators >, + public VariantShortcuts >, public Visitable { typedef ElementProxy this_type; @@ -23,8 +26,11 @@ class ElementProxy : public VariantOperators >, FORCE_INLINE ElementProxy(TArray array, size_t index) : _array(array), _index(index) {} + FORCE_INLINE ElementProxy(const ElementProxy& src) + : _array(src._array), _index(src._index) {} + FORCE_INLINE this_type& operator=(const this_type& src) { - getUpstreamElement().set(src.as()); + getOrAddUpstreamElement().set(src.as()); return *this; } @@ -35,7 +41,7 @@ class ElementProxy : public VariantOperators >, // std::string, String, ArrayRef, ObjectRef template FORCE_INLINE this_type& operator=(const T& src) { - getUpstreamElement().set(src); + getOrAddUpstreamElement().set(src); return *this; } // @@ -43,7 +49,7 @@ class ElementProxy : public VariantOperators >, // TValue = char*, const char*, const __FlashStringHelper* template FORCE_INLINE this_type& operator=(T* src) { - getUpstreamElement().set(src); + getOrAddUpstreamElement().set(src); return *this; } @@ -60,6 +66,11 @@ class ElementProxy : public VariantOperators >, return getUpstreamElement().template as(); } + template + FORCE_INLINE operator T() const { + return getUpstreamElement(); + } + template FORCE_INLINE bool is() const { return getUpstreamElement().template is(); @@ -67,7 +78,7 @@ class ElementProxy : public VariantOperators >, template FORCE_INLINE typename VariantTo::type to() const { - return getUpstreamElement().template to(); + return getOrAddUpstreamElement().template to(); } // Replaces the value @@ -77,14 +88,14 @@ class ElementProxy : public VariantOperators >, // std::string, String, ArrayRef, ObjectRef template FORCE_INLINE bool set(const TValue& value) const { - return getUpstreamElement().set(value); + return getOrAddUpstreamElement().set(value); } // // bool set(TValue) // TValue = char*, const char*, const __FlashStringHelper* template FORCE_INLINE bool set(TValue* value) const { - return getUpstreamElement().set(value); + return getOrAddUpstreamElement().set(value); } template @@ -108,20 +119,20 @@ class ElementProxy : public VariantOperators >, template VariantRef getOrAddMember(TNestedKey* key) const { - return getUpstreamElement().getOrAddMember(key); + return getOrAddUpstreamElement().getOrAddMember(key); } template VariantRef getOrAddMember(const TNestedKey& key) const { - return getUpstreamElement().getOrAddMember(key); + return getOrAddUpstreamElement().getOrAddMember(key); } VariantRef addElement() const { - return getUpstreamElement().addElement(); + return getOrAddUpstreamElement().addElement(); } VariantRef getElement(size_t index) const { - return getUpstreamElement().getElement(index); + return getOrAddUpstreamElement().getElement(index); } FORCE_INLINE void remove(size_t index) const { @@ -148,16 +159,14 @@ class ElementProxy : public VariantOperators >, return _array.getElement(_index); } + FORCE_INLINE VariantRef getOrAddUpstreamElement() const { + return _array.getOrAddElement(_index); + } + TArray _array; const size_t _index; }; -template -inline ElementProxy ArrayShortcuts::operator[]( - size_t index) const { - return ElementProxy(*impl(), index); -} - } // namespace ARDUINOJSON_NAMESPACE #ifdef _MSC_VER diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/Utilities.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/Utilities.hpp index 495991604..a2895fd76 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Array/Utilities.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Array/Utilities.hpp @@ -1,10 +1,11 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#include "ArrayRef.hpp" +#include +#include namespace ARDUINOJSON_NAMESPACE { @@ -14,6 +15,12 @@ inline bool copyArray(T (&src)[N], ArrayRef dst) { return copyArray(src, N, dst); } +// Copy a 1D array to a JsonDocument +template +inline bool copyArray(T (&src)[N], JsonDocument& dst) { + return copyArray(src, dst.to()); +} + // Copy a 1D array to a JsonArray template inline bool copyArray(T* src, size_t len, ArrayRef dst) { @@ -24,6 +31,12 @@ inline bool copyArray(T* src, size_t len, ArrayRef dst) { return ok; } +// Copy a 1D array to a JsonDocument +template +inline bool copyArray(T* src, size_t len, JsonDocument& dst) { + return copyArray(src, len, dst.to()); +} + // Copy a 2D array to a JsonArray template inline bool copyArray(T (&src)[N1][N2], ArrayRef dst) { @@ -37,12 +50,24 @@ inline bool copyArray(T (&src)[N1][N2], ArrayRef dst) { return ok; } +// Copy a 2D array to a JsonDocument +template +inline bool copyArray(T (&src)[N1][N2], JsonDocument& dst) { + return copyArray(src, dst.to()); +} + // Copy a JsonArray to a 1D array template inline size_t copyArray(ArrayConstRef src, T (&dst)[N]) { return copyArray(src, dst, N); } +// Copy a JsonDocument to a 1D array +template +inline size_t copyArray(const JsonDocument& src, T (&dst)[N]) { + return copyArray(src.as(), dst, N); +} + // Copy a JsonArray to a 1D array template inline size_t copyArray(ArrayConstRef src, T* dst, size_t len) { @@ -63,4 +88,10 @@ inline void copyArray(ArrayConstRef src, T (&dst)[N1][N2]) { } } +// Copy a JsonDocument to a 2D array +template +inline void copyArray(const JsonDocument& src, T (&dst)[N1][N2]) { + copyArray(src.as(), dst); +} + } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Collection/CollectionData.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Collection/CollectionData.hpp index 6b37d533a..13fb78b24 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Collection/CollectionData.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Collection/CollectionData.hpp @@ -1,9 +1,14 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once +#include +#include + +#include // size_t + namespace ARDUINOJSON_NAMESPACE { class MemoryPool; @@ -20,44 +25,57 @@ class CollectionData { // - no destructor // - no virtual // - no inheritance - VariantSlot *addSlot(MemoryPool *); - VariantData *add(MemoryPool *pool); + // Array only + + VariantData *addElement(MemoryPool *pool); + + VariantData *getElement(size_t index) const; + + VariantData *getOrAddElement(size_t index, MemoryPool *pool); + + void removeElement(size_t index); + + bool equalsArray(const CollectionData &other) const; + + // Object only template - VariantData *add(TAdaptedString key, MemoryPool *pool); + VariantData *addMember(TAdaptedString key, MemoryPool *pool); - void clear(); + template + VariantData *getMember(TAdaptedString key) const; + + template + VariantData *getOrAddMember(TAdaptedString key, MemoryPool *pool); + + template + void removeMember(TAdaptedString key) { + removeSlot(getSlot(key)); + } template bool containsKey(const TAdaptedString &key) const; - bool copyFrom(const CollectionData &src, MemoryPool *pool); - - bool equalsArray(const CollectionData &other) const; bool equalsObject(const CollectionData &other) const; - VariantData *get(size_t index) const; + // Generic - template - VariantData *get(TAdaptedString key) const; + void clear(); + size_t memoryUsage() const; + size_t nesting() const; + size_t size() const; + + VariantSlot *addSlot(MemoryPool *); + void removeSlot(VariantSlot *slot); + + bool copyFrom(const CollectionData &src, MemoryPool *pool); VariantSlot *head() const { return _head; } - void remove(size_t index); - - template - void remove(TAdaptedString key) { - remove(getSlot(key)); - } - - void remove(VariantSlot *slot); - - size_t memoryUsage() const; - size_t nesting() const; - size_t size() const; + void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance); private: VariantSlot *getSlot(size_t index) const; diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Collection/CollectionImpl.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Collection/CollectionImpl.hpp index c6097e474..349754422 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Collection/CollectionImpl.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Collection/CollectionImpl.hpp @@ -1,17 +1,22 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#include "../Variant/VariantData.hpp" -#include "CollectionData.hpp" +#include +#include namespace ARDUINOJSON_NAMESPACE { +inline bool variantEquals(const VariantData* a, const VariantData* b) { + return variantCompare(a, b) == COMPARE_RESULT_EQUAL; +} + inline VariantSlot* CollectionData::addSlot(MemoryPool* pool) { VariantSlot* slot = pool->allocVariant(); - if (!slot) return 0; + if (!slot) + return 0; if (_tail) { _tail->setNextNotNull(slot); @@ -25,14 +30,18 @@ inline VariantSlot* CollectionData::addSlot(MemoryPool* pool) { return slot; } -inline VariantData* CollectionData::add(MemoryPool* pool) { +inline VariantData* CollectionData::addElement(MemoryPool* pool) { return slotData(addSlot(pool)); } template -inline VariantData* CollectionData::add(TAdaptedString key, MemoryPool* pool) { +inline VariantData* CollectionData::addMember(TAdaptedString key, + MemoryPool* pool) { VariantSlot* slot = addSlot(pool); - if (!slotSetKey(slot, key, pool)) return 0; + if (!slotSetKey(slot, key, pool)) { + removeSlot(slot); + return 0; + } return slot->data(); } @@ -53,14 +62,16 @@ inline bool CollectionData::copyFrom(const CollectionData& src, VariantData* var; if (s->key() != 0) { if (s->ownsKey()) - var = add(RamStringAdapter(s->key()), pool); + var = addMember(RamStringAdapter(s->key()), pool); else - var = add(ConstRamStringAdapter(s->key()), pool); + var = addMember(ConstRamStringAdapter(s->key()), pool); } else { - var = add(pool); + var = addElement(pool); } - if (!var) return false; - if (!var->copyFrom(*s->data(), pool)) return false; + if (!var) + return false; + if (!var->copyFrom(*s->data(), pool)) + return false; } return true; } @@ -69,8 +80,9 @@ inline bool CollectionData::equalsObject(const CollectionData& other) const { size_t count = 0; for (VariantSlot* slot = _head; slot; slot = slot->next()) { VariantData* v1 = slot->data(); - VariantData* v2 = other.get(adaptString(slot->key())); - if (!variantEquals(v1, v2)) return false; + VariantData* v2 = other.getMember(adaptString(slot->key())); + if (!variantEquals(v1, v2)) + return false; count++; } return count == other.size(); @@ -80,9 +92,12 @@ inline bool CollectionData::equalsArray(const CollectionData& other) const { VariantSlot* s1 = _head; VariantSlot* s2 = other._head; for (;;) { - if (s1 == s2) return true; - if (!s1 || !s2) return false; - if (!variantEquals(s1->data(), s2->data())) return false; + if (s1 == s2) + return true; + if (!s1 || !s2) + return false; + if (!variantEquals(s1->data(), s2->data())) + return false; s1 = s1->next(); s2 = s2->next(); } @@ -92,7 +107,8 @@ template inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const { VariantSlot* slot = _head; while (slot) { - if (key.equals(slot->key())) break; + if (key.equals(slot->key())) + break; slot = slot->next(); } return slot; @@ -106,43 +122,78 @@ inline VariantSlot* CollectionData::getPreviousSlot(VariantSlot* target) const { VariantSlot* current = _head; while (current) { VariantSlot* next = current->next(); - if (next == target) return current; + if (next == target) + return current; current = next; } return 0; } template -inline VariantData* CollectionData::get(TAdaptedString key) const { +inline VariantData* CollectionData::getMember(TAdaptedString key) const { VariantSlot* slot = getSlot(key); return slot ? slot->data() : 0; } -inline VariantData* CollectionData::get(size_t index) const { +template +inline VariantData* CollectionData::getOrAddMember(TAdaptedString key, + MemoryPool* pool) { + // ignore null key + if (key.isNull()) + return 0; + + // search a matching key + VariantSlot* slot = getSlot(key); + if (slot) + return slot->data(); + + return addMember(key, pool); +} + +inline VariantData* CollectionData::getElement(size_t index) const { VariantSlot* slot = getSlot(index); return slot ? slot->data() : 0; } -inline void CollectionData::remove(VariantSlot* slot) { - if (!slot) return; +inline VariantData* CollectionData::getOrAddElement(size_t index, + MemoryPool* pool) { + VariantSlot* slot = _head; + while (slot && index > 0) { + slot = slot->next(); + index--; + } + if (!slot) + index++; + while (index > 0) { + slot = addSlot(pool); + index--; + } + return slotData(slot); +} + +inline void CollectionData::removeSlot(VariantSlot* slot) { + if (!slot) + return; VariantSlot* prev = getPreviousSlot(slot); VariantSlot* next = slot->next(); if (prev) prev->setNext(next); else _head = next; - if (!next) _tail = prev; + if (!next) + _tail = prev; } -inline void CollectionData::remove(size_t index) { - remove(getSlot(index)); +inline void CollectionData::removeElement(size_t index) { + removeSlot(getSlot(index)); } inline size_t CollectionData::memoryUsage() const { size_t total = 0; for (VariantSlot* s = _head; s; s = s->next()) { total += sizeof(VariantSlot) + s->data()->memoryUsage(); - if (s->ownsKey()) total += strlen(s->key()) + 1; + if (s->ownsKey()) + total += strlen(s->key()) + 1; } return total; } @@ -151,7 +202,8 @@ inline size_t CollectionData::nesting() const { size_t maxChildNesting = 0; for (VariantSlot* s = _head; s; s = s->next()) { size_t childNesting = s->data()->nesting(); - if (childNesting > maxChildNesting) maxChildNesting = childNesting; + if (childNesting > maxChildNesting) + maxChildNesting = childNesting; } return maxChildNesting + 1; } @@ -160,4 +212,21 @@ inline size_t CollectionData::size() const { return slotSize(_head); } +template +inline void movePointer(T*& p, ptrdiff_t offset) { + if (!p) + return; + p = reinterpret_cast( + reinterpret_cast(reinterpret_cast(p) + offset)); + ARDUINOJSON_ASSERT(isAligned(p)); +} + +inline void CollectionData::movePointers(ptrdiff_t stringDistance, + ptrdiff_t variantDistance) { + movePointer(_head, variantDistance); + movePointer(_tail, variantDistance); + for (VariantSlot* slot = _head; slot; slot = slot->next()) + slot->movePointers(stringDistance, variantDistance); +} + } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Configuration.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Configuration.hpp index 6e97b15df..a73a2c5d5 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Configuration.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Configuration.hpp @@ -1,33 +1,61 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#if defined(_MSC_VER) +#if __cplusplus >= 201103L +#define ARDUINOJSON_HAS_LONG_LONG 1 +#define ARDUINOJSON_HAS_NULLPTR 1 +#define ARDUINOJSON_HAS_RVALUE_REFERENCES 1 +#else +#define ARDUINOJSON_HAS_LONG_LONG 0 +#define ARDUINOJSON_HAS_NULLPTR 0 +#define ARDUINOJSON_HAS_RVALUE_REFERENCES 0 +#endif + +#if defined(_MSC_VER) && !ARDUINOJSON_HAS_LONG_LONG #define ARDUINOJSON_HAS_INT64 1 #else #define ARDUINOJSON_HAS_INT64 0 #endif -#if __cplusplus >= 201103L -#define ARDUINOJSON_HAS_LONG_LONG 1 -#define ARDUINOJSON_HAS_NULLPTR 1 -#else -#define ARDUINOJSON_HAS_LONG_LONG 0 -#define ARDUINOJSON_HAS_NULLPTR 0 -#endif - // Small or big machine? #ifndef ARDUINOJSON_EMBEDDED_MODE -#if defined(ARDUINO) || defined(__IAR_SYSTEMS_ICC__) || defined(__XC) || \ - defined(__ARMCC_VERSION) +#if defined(ARDUINO) /* Arduino*/ \ + || defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \ + || defined(__XC) /* MPLAB XC compiler */ \ + || defined(__ARMCC_VERSION) /* Keil ARM Compiler */ \ + || defined(__AVR) /* Atmel AVR8/GNU C Compiler */ #define ARDUINOJSON_EMBEDDED_MODE 1 #else #define ARDUINOJSON_EMBEDDED_MODE 0 #endif #endif +// Auto enable std::stream if the right headers are here and no conflicting +// macro is defined +#if !defined(ARDUINOJSON_ENABLE_STD_STREAM) && defined(__has_include) +#if __has_include() && \ + __has_include() && \ + !defined(min) && \ + !defined(max) +#define ARDUINOJSON_ENABLE_STD_STREAM 1 +#else +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#endif +#endif + +// Auto enable std::string if the right header is here and no conflicting +// macro is defined +#if !defined(ARDUINOJSON_ENABLE_STD_STRING) && defined(__has_include) +#if __has_include() && !defined(min) && !defined(max) +#define ARDUINOJSON_ENABLE_STD_STRING 1 +#else +#define ARDUINOJSON_ENABLE_STD_STRING 0 +#endif +#endif + #if ARDUINOJSON_EMBEDDED_MODE // Store floats by default to reduce the memory usage (issue #134) @@ -90,6 +118,8 @@ #ifdef ARDUINO +#include + // Enable support for Arduino's String class #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 @@ -107,17 +137,17 @@ #else // ARDUINO -// Enable support for Arduino's String class +// Disable support for Arduino's String class #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING #define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 #endif -// Enable support for Arduino's Stream class +// Disable support for Arduino's Stream class #ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM #define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0 #endif -// Enable support for Arduino's Print class +// Disable support for Arduino's Print class #ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT #define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0 #endif @@ -137,6 +167,11 @@ #define ARDUINOJSON_DECODE_UNICODE 0 #endif +// Ignore comments in input +#ifndef ARDUINOJSON_ENABLE_COMMENTS +#define ARDUINOJSON_ENABLE_COMMENTS 0 +#endif + // Support NaN in JSON #ifndef ARDUINOJSON_ENABLE_NAN #define ARDUINOJSON_ENABLE_NAN 0 @@ -168,6 +203,26 @@ #endif #endif +#ifndef ARDUINOJSON_ENABLE_ALIGNMENT +#if defined(__AVR) +#define ARDUINOJSON_ENABLE_ALIGNMENT 0 +#else +#define ARDUINOJSON_ENABLE_ALIGNMENT 1 +#endif +#endif + #ifndef ARDUINOJSON_TAB #define ARDUINOJSON_TAB " " #endif + +#ifndef ARDUINOJSON_STRING_BUFFER_SIZE +#define ARDUINOJSON_STRING_BUFFER_SIZE 32 +#endif + +#ifndef ARDUINOJSON_DEBUG +#ifdef __PLATFORMIO_BUILD_DEBUG__ +#define ARDUINOJSON_DEBUG 1 +#else +#define ARDUINOJSON_DEBUG 0 +#endif +#endif diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp deleted file mode 100644 index 0551bd417..000000000 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/ArduinoStreamReader.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 -// MIT License - -#pragma once - -#if ARDUINOJSON_ENABLE_ARDUINO_STREAM - -#include - -namespace ARDUINOJSON_NAMESPACE { - -struct ArduinoStreamReader { - Stream& _stream; - - public: - explicit ArduinoStreamReader(Stream& stream) : _stream(stream) {} - - int read() { - // don't use _stream.read() as it ignores the timeout - uint8_t c; - return _stream.readBytes(&c, 1) ? c : -1; - } -}; - -inline ArduinoStreamReader makeReader(Stream& input) { - return ArduinoStreamReader(input); -} -} // namespace ARDUINOJSON_NAMESPACE - -#endif diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/CharPointerReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/CharPointerReader.hpp deleted file mode 100644 index 2de68d1a0..000000000 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/CharPointerReader.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 -// MIT License - -#pragma once - -namespace ARDUINOJSON_NAMESPACE { - -template -struct IsCharOrVoid { - static const bool value = - is_same::value || is_same::value || - is_same::value || is_same::value; -}; - -template -struct IsCharOrVoid : IsCharOrVoid {}; - -class UnsafeCharPointerReader { - const char* _ptr; - - public: - explicit UnsafeCharPointerReader(const char* ptr) - : _ptr(ptr ? ptr : reinterpret_cast("")) {} - - int read() { - return static_cast(*_ptr++); - } -}; - -class SafeCharPointerReader { - const char* _ptr; - const char* _end; - - public: - explicit SafeCharPointerReader(const char* ptr, size_t len) - : _ptr(ptr ? ptr : reinterpret_cast("")), _end(_ptr + len) {} - - int read() { - if (_ptr < _end) - return static_cast(*_ptr++); - else - return -1; - } -}; - -template -inline typename enable_if::value, - UnsafeCharPointerReader>::type -makeReader(TChar* input) { - return UnsafeCharPointerReader(reinterpret_cast(input)); -} - -template -inline - typename enable_if::value, SafeCharPointerReader>::type - makeReader(TChar* input, size_t n) { - return SafeCharPointerReader(reinterpret_cast(input), n); -} - -#if ARDUINOJSON_ENABLE_ARDUINO_STRING -inline SafeCharPointerReader makeReader(const ::String& input) { - return SafeCharPointerReader(input.c_str(), input.length()); -} -#endif - -} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/DeserializationError.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/DeserializationError.hpp index 8707b3b04..9ffd0de94 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/DeserializationError.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/DeserializationError.hpp @@ -1,9 +1,11 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once +#include + #if ARDUINOJSON_ENABLE_STD_STREAM #include #endif diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Filter.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Filter.hpp new file mode 100644 index 000000000..252488799 --- /dev/null +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Filter.hpp @@ -0,0 +1,66 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +class Filter { + public: + explicit Filter(VariantConstRef v) : _variant(v) {} + + bool allow() const { + return _variant; + } + + bool allowArray() const { + return _variant == true || _variant.is(); + } + + bool allowObject() const { + return _variant == true || _variant.is(); + } + + bool allowValue() const { + return _variant == true; + } + + template + Filter operator[](const TKey& key) const { + if (_variant == true) // "true" means "allow recursively" + return *this; + else + return Filter(_variant[key]); + } + + private: + VariantConstRef _variant; +}; + +struct AllowAllFilter { + bool allow() const { + return true; + } + + bool allowArray() const { + return true; + } + + bool allowObject() const { + return true; + } + + bool allowValue() const { + return true; + } + + template + AllowAllFilter operator[](const TKey&) const { + return AllowAllFilter(); + } +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/FlashStringReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/FlashStringReader.hpp deleted file mode 100644 index e8066ef60..000000000 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/FlashStringReader.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 -// MIT License - -#pragma once - -#if ARDUINOJSON_ENABLE_PROGMEM - -namespace ARDUINOJSON_NAMESPACE { -class UnsafeFlashStringReader { - const char* _ptr; - - public: - explicit UnsafeFlashStringReader(const __FlashStringHelper* ptr) - : _ptr(reinterpret_cast(ptr)) {} - - int read() { - return pgm_read_byte_near(_ptr++); - } -}; - -class SafeFlashStringReader { - const char* _ptr; - const char* _end; - - public: - explicit SafeFlashStringReader(const __FlashStringHelper* ptr, size_t size) - : _ptr(reinterpret_cast(ptr)), _end(_ptr + size) {} - - int read() { - if (_ptr < _end) - return pgm_read_byte_near(_ptr++); - else - return -1; - } -}; - -inline UnsafeFlashStringReader makeReader(const __FlashStringHelper* input) { - return UnsafeFlashStringReader(input); -} - -inline SafeFlashStringReader makeReader(const __FlashStringHelper* input, - size_t size) { - return SafeFlashStringReader(input, size); -} -} // namespace ARDUINOJSON_NAMESPACE - -#endif diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/IteratorReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/IteratorReader.hpp deleted file mode 100644 index f2605e48a..000000000 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/IteratorReader.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 -// MIT License - -#pragma once - -namespace ARDUINOJSON_NAMESPACE { - -template -class IteratorReader { - TIterator _ptr, _end; - - public: - explicit IteratorReader(TIterator begin, TIterator end) - : _ptr(begin), _end(end) {} - - int read() { - if (_ptr < _end) - return static_cast(*_ptr++); - else - return -1; - } -}; - -template -inline IteratorReader makeReader( - const TInput& input) { - return IteratorReader(input.begin(), - input.end()); -} -} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/NestingLimit.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/NestingLimit.hpp index f1f4a5bc1..8f33b6c7d 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/NestingLimit.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/NestingLimit.hpp @@ -1,17 +1,29 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#include "../Configuration.hpp" +#include +#include namespace ARDUINOJSON_NAMESPACE { -struct NestingLimit { - NestingLimit() : value(ARDUINOJSON_DEFAULT_NESTING_LIMIT) {} - explicit NestingLimit(uint8_t n) : value(n) {} +class NestingLimit { + public: + NestingLimit() : _value(ARDUINOJSON_DEFAULT_NESTING_LIMIT) {} + explicit NestingLimit(uint8_t n) : _value(n) {} - uint8_t value; + NestingLimit decrement() const { + ARDUINOJSON_ASSERT(_value > 0); + return NestingLimit(static_cast(_value - 1)); + } + + bool reached() const { + return _value == 0; + } + + private: + uint8_t _value; }; } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Reader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Reader.hpp new file mode 100644 index 000000000..da9a9f24b --- /dev/null +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Reader.hpp @@ -0,0 +1,56 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +#include // for size_t + +namespace ARDUINOJSON_NAMESPACE { + +// The default reader is a simple wrapper for Readers that are not copiable +template +struct Reader { + public: + Reader(TSource& source) : _source(&source) {} + + int read() { + return _source->read(); + } + + size_t readBytes(char* buffer, size_t length) { + return _source->readBytes(buffer, length); + } + + private: + TSource* _source; +}; + +template +struct BoundedReader { + // no default implementation because we need to pass the size to the + // constructor +}; +} // namespace ARDUINOJSON_NAMESPACE + +#include +#include +#include + +#if ARDUINOJSON_ENABLE_ARDUINO_STREAM +#include +#endif + +#if ARDUINOJSON_ENABLE_ARDUINO_STRING +#include +#endif + +#if ARDUINOJSON_ENABLE_PROGMEM +#include +#endif + +#if ARDUINOJSON_ENABLE_STD_STREAM +#include +#endif diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp new file mode 100644 index 000000000..06352585c --- /dev/null +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp @@ -0,0 +1,31 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader::value>::type> { + public: + explicit Reader(Stream& stream) : _stream(&stream) {} + + int read() { + // don't use _stream.read() as it ignores the timeout + char c; + return _stream->readBytes(&c, 1) ? static_cast(c) : -1; + } + + size_t readBytes(char* buffer, size_t length) { + return _stream->readBytes(buffer, length); + } + + private: + Stream* _stream; +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp new file mode 100644 index 000000000..5b6bcd2eb --- /dev/null +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp @@ -0,0 +1,17 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader::value>::type> + : BoundedReader { + explicit Reader(const ::String& s) + : BoundedReader(s.c_str(), s.length()) {} +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp new file mode 100644 index 000000000..36b7fde6d --- /dev/null +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp @@ -0,0 +1,53 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +namespace ARDUINOJSON_NAMESPACE { + +template <> +struct Reader { + const char* _ptr; + + public: + explicit Reader(const __FlashStringHelper* ptr) + : _ptr(reinterpret_cast(ptr)) {} + + int read() { + return pgm_read_byte(_ptr++); + } + + size_t readBytes(char* buffer, size_t length) { + memcpy_P(buffer, _ptr, length); + _ptr += length; + return length; + } +}; + +template <> +struct BoundedReader { + const char* _ptr; + const char* _end; + + public: + explicit BoundedReader(const __FlashStringHelper* ptr, size_t size) + : _ptr(reinterpret_cast(ptr)), _end(_ptr + size) {} + + int read() { + if (_ptr < _end) + return pgm_read_byte(_ptr++); + else + return -1; + } + + size_t readBytes(char* buffer, size_t length) { + size_t available = static_cast(_end - _ptr); + if (available < length) + length = available; + memcpy_P(buffer, _ptr, length); + _ptr += length; + return length; + } +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp new file mode 100644 index 000000000..2f07c3442 --- /dev/null +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp @@ -0,0 +1,43 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +namespace ARDUINOJSON_NAMESPACE { + +template +class IteratorReader { + TIterator _ptr, _end; + + public: + explicit IteratorReader(TIterator begin, TIterator end) + : _ptr(begin), _end(end) {} + + int read() { + if (_ptr < _end) + return static_cast(*_ptr++); + else + return -1; + } + + size_t readBytes(char* buffer, size_t length) { + size_t i = 0; + while (i < length && _ptr < _end) buffer[i++] = *_ptr++; + return i; + } +}; + +template +struct void_ { + typedef void type; +}; + +template +struct Reader::type> + : IteratorReader { + explicit Reader(const TSource& source) + : IteratorReader(source.begin(), + source.end()) {} +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/RamReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/RamReader.hpp new file mode 100644 index 000000000..5f238a1df --- /dev/null +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/RamReader.hpp @@ -0,0 +1,50 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct IsCharOrVoid { + static const bool value = + is_same::value || is_same::value || + is_same::value || is_same::value; +}; + +template +struct IsCharOrVoid : IsCharOrVoid {}; + +template +struct Reader::value>::type> { + const char* _ptr; + + public: + explicit Reader(const void* ptr) + : _ptr(ptr ? reinterpret_cast(ptr) : "") {} + + int read() { + return static_cast(*_ptr++); + } + + size_t readBytes(char* buffer, size_t length) { + for (size_t i = 0; i < length; i++) buffer[i] = *_ptr++; + return length; + } +}; + +template +struct BoundedReader::value>::type> + : public IteratorReader { + public: + explicit BoundedReader(const void* ptr, size_t len) + : IteratorReader(reinterpret_cast(ptr), + reinterpret_cast(ptr) + len) {} +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp new file mode 100644 index 000000000..1e7f83fd4 --- /dev/null +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp @@ -0,0 +1,29 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader::value>::type> { + public: + explicit Reader(std::istream& stream) : _stream(&stream) {} + + int read() { + return _stream->get(); + } + + size_t readBytes(char* buffer, size_t length) { + _stream->read(buffer, static_cast(length)); + return static_cast(_stream->gcount()); + } + + private: + std::istream* _stream; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp new file mode 100644 index 000000000..b06bd4a0a --- /dev/null +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp @@ -0,0 +1,34 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader, void> : Reader { + explicit Reader(const ElementProxy& x) + : Reader(x.template as()) {} +}; + +template +struct Reader, void> : Reader { + explicit Reader(const MemberProxy& x) + : Reader(x.template as()) {} +}; + +template <> +struct Reader : Reader { + explicit Reader(VariantRef x) : Reader(x.as()) {} +}; + +template <> +struct Reader : Reader { + explicit Reader(VariantConstRef x) + : Reader(x.as()) {} +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/StdStreamReader.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/StdStreamReader.hpp deleted file mode 100644 index 8996a77e1..000000000 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/StdStreamReader.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 -// MIT License - -#pragma once - -#if ARDUINOJSON_ENABLE_STD_STREAM - -#include - -namespace ARDUINOJSON_NAMESPACE { - -class StdStreamReader { - std::istream& _stream; - char _current; - - public: - explicit StdStreamReader(std::istream& stream) - : _stream(stream), _current(0) {} - - int read() { - return _stream.get(); - } - - private: - StdStreamReader& operator=(const StdStreamReader&); // Visual Studio C4512 -}; - -inline StdStreamReader makeReader(std::istream& input) { - return StdStreamReader(input); -} -} // namespace ARDUINOJSON_NAMESPACE - -#endif diff --git a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/deserialize.hpp b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/deserialize.hpp index 112d0823d..f80f587bf 100644 --- a/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/deserialize.hpp +++ b/lib/ArduinoJson-6.x/src/ArduinoJson/Deserialization/deserialize.hpp @@ -1,76 +1,71 @@ // ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2019 +// Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once -#include "../StringStorage/StringStorage.hpp" -#include "ArduinoStreamReader.hpp" -#include "CharPointerReader.hpp" -#include "DeserializationError.hpp" -#include "FlashStringReader.hpp" -#include "IteratorReader.hpp" -#include "NestingLimit.hpp" -#include "StdStreamReader.hpp" +#include +#include +#include +#include +#include namespace ARDUINOJSON_NAMESPACE { template