forked from bblanchon/ArduinoJson
Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
ddfe7d8b91 | |||
4a657ca87f | |||
1e3d478998 | |||
3aebef6d0a | |||
25879466da | |||
27ec1afb7a | |||
06a0d1a872 | |||
04fe7e1a27 | |||
f9cfea244a | |||
5ec062cc71 | |||
91b808381e | |||
8550418875 | |||
00c391320c | |||
9723682d20 | |||
8bf6f6e09f | |||
062c1c13b5 | |||
1b8107094f | |||
8721ac88b1 | |||
6da6f921cd | |||
ef63757b1a | |||
3a169df0a5 | |||
d4f819f1f0 | |||
16fe3c0acc | |||
fd8f4eb3a6 | |||
b261eca865 | |||
a37480eec9 | |||
713aaa3d68 | |||
7d1d0c4e67 | |||
4ad05dbaef | |||
38371aae62 | |||
498a2e4c1e | |||
2078871f36 | |||
140525b7a0 |
7
.github/lock.yml
vendored
Normal file
7
.github/lock.yml
vendored
Normal file
@ -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
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include "src/ArduinoJson.h"
|
||||
|
40
CHANGELOG.md
40
CHANGELOG.md
@ -1,6 +1,46 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
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<nullptr_t>()`
|
||||
* 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 <ArduinoJson.h>
|
||||
> ```
|
||||
|
||||
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)
|
||||
-------
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2019
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# MIT License
|
||||
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
|
129
README.md
129
README.md
@ -2,58 +2,88 @@
|
||||
|
||||
---
|
||||
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.12.0)
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.14.0)
|
||||
[](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||
[](https://travis-ci.org/bblanchon/ArduinoJson)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||
[](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||
[](https://github.com/bblanchon/ArduinoJson)
|
||||
[](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:
|
||||
|
||||
* <img src="https://www.arduino.cc/favicon.ico" height="16" width="16"> 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)...
|
||||
* <img src="http://espressif.com/sites/all/themes/espressif/favicon.ico" height="16" width="16"> Espressif chips: [ESP8266](https://en.wikipedia.org/wiki/ESP8266), [ESP32](https://en.wikipedia.org/wiki/ESP32)
|
||||
* <img src="https://www.wemos.cc/themes/martin-materialize-parallax/assets/favicon.ico" height="16" width="16"> WeMos boards: [D1](https://wiki.wemos.cc/products:d1:d1), [D1 mini](https://wiki.wemos.cc/products:d1:d1_mini), ...
|
||||
* <img src="http://redbearlab.com/favicon.ico" height="16" width="16"> 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)...
|
||||
* <img src="https://www.pjrc.com/favicon.ico" height="16" width="16"> [Teensy](https://www.pjrc.com/teensy/) boards
|
||||
* <img src="https://software.intel.com/sites/all/themes/zero/favicon.ico" height="16" width="16"> Intel boards: Edison, Galileo...
|
||||
* <img src="https://www-assets.particle.io/images/favicon.png" height="16" width="16"> Particle boards: [Photon](https://www.particle.io/products/hardware/photon-wifi-dev-kit), [Electron](https://www.particle.io/products/hardware/electron-cellular-dev-kit)...
|
||||
* <img src="http://www.ti.com/favicon.ico" height="16" width="16"> 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:
|
||||
|
||||
* <img src="https://www.arduino.cc/favicon.ico" height="16" width="16"> [Arduino IDE](https://www.arduino.cc/en/Main/Software)
|
||||
* <img src="http://cdn.platformio.org/favicon.ico" height="16" width="16"> [PlatformIO](http://platformio.org/)
|
||||
* <img src="http://energia.nu/img/favicon.ico" height="16" width="16"> [Energia](http://energia.nu/)
|
||||
* <img src="http://www.visualmicro.com/pics/arduino-visual-studio-ld.png" height="16" width="16"> [Visual Micro](http://www.visualmicro.com/)
|
||||
* <img src="http://www.atmel.com/Images/favicon.ico" height="16" width="16"> [Atmel Studio](http://www.atmel.com/microsite/atmel-studio/)
|
||||
* <img src="https://www.iar.com/favicon.ico" height="16" width="16"> [IAR Embedded Workbench](https://www.iar.com/iar-embedded-workbench/)
|
||||
* <img src="http://www.st.com/etc/clientlibs/st-site/media/app/images/favicon.png" height="16" width="16"> [Atollic TrueSTUDIO](https://atollic.com/truestudio/)
|
||||
* <img src="http://www.keil.com/favicon.ico" height="16" width="16"> [Keil uVision](http://www.keil.com/)
|
||||
* <img src="http://www.microchip.com/favicon.ico" height="16" width="16"> [MPLAB X IDE](http://www.microchip.com/mplab/mplab-x-ide)
|
||||
* <img src="https://gcc.gnu.org/favicon.ico" height="16" width="16"> [GCC](https://gcc.gnu.org/)
|
||||
* <img src="https://clang.llvm.org/favicon.ico" height="16" width="16"> [Clang](https://clang.llvm.org/)
|
||||
* <img src="https://www.visualstudio.com/favicon.ico" height="16" width="16"> [Visual Studio](https://www.visualstudio.com/)
|
||||
* [JSON deserialization](https://arduinojson.org/v6/api/json/deserializejson/)
|
||||
* [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/)
|
||||
* [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/)
|
||||
* [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/)
|
||||
* Supports single quotes as a string delimiter
|
||||
* Compatible with NDJSON and JSON Lines
|
||||
* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/)
|
||||
* [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/)
|
||||
* [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/)
|
||||
* [MessagePack serialization](https://arduinojson.org/v6/api/msgpack/serializemsgpack/)
|
||||
* [MessagePack deserialization](https://arduinojson.org/v6/api/msgpack/deserializemsgpack/)
|
||||
* Efficient
|
||||
* [Twice smaller than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||
* [Almost 10% faster than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||
* [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||
* [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/)
|
||||
* [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/)
|
||||
* Versatile
|
||||
* [Supports custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/)
|
||||
* 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/)
|
||||
* Supports Arduino's `Stream` and [STL's `std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/)
|
||||
* [Supports Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/)
|
||||
* 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)
|
||||
* Well designed
|
||||
* [Elegant API](http://127.0.0.1:4000/v6/example/)
|
||||
* [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety)
|
||||
* Self-contained (no external dependency)
|
||||
* `const` friendly
|
||||
* `for` friendly
|
||||
* [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming)
|
||||
* 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/)
|
||||
* [Examples](https://arduinojson.org/v6/example/)
|
||||
* [How-tos](https://arduinojson.org/v6/example/)
|
||||
* [FAQ](https://arduinojson.org/v6/faq/)
|
||||
* [Book](https://arduinojson.org/book/)
|
||||
* 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
|
||||
|
||||
@ -96,16 +126,7 @@ 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)!
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
version: 6.12.0.{build}
|
||||
version: 6.14.0.{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
|
||||
|
1
component.mk
Normal file
1
component.mk
Normal file
@ -0,0 +1 @@
|
||||
COMPONENT_ADD_INCLUDEDIRS := src
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2019
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# MIT License
|
||||
|
||||
if(MSVC)
|
||||
|
@ -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
|
||||
|
@ -57,7 +57,7 @@ simplify_namespaces() {
|
||||
perl -p0i -e 's|\} // namespace ARDUINOJSON_NAMESPACE\r?\nnamespace ARDUINOJSON_NAMESPACE \{\r?\n||igs' "$1"
|
||||
}
|
||||
|
||||
cd $(dirname $0)/../
|
||||
cd $(dirname $0)/../..
|
||||
INCLUDED=()
|
||||
process src/ArduinoJson.h true > ../ArduinoJson-$TAG.h
|
||||
simplify_namespaces ../ArduinoJson-$TAG.h
|
||||
|
@ -56,6 +56,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"
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2019
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# MIT License
|
||||
|
||||
add_subdirectory(catch)
|
||||
@ -72,6 +72,7 @@ if(MSVC)
|
||||
)
|
||||
endif()
|
||||
|
||||
include_directories(Helpers)
|
||||
add_subdirectory(ElementProxy)
|
||||
add_subdirectory(IntegrationTests)
|
||||
add_subdirectory(JsonArray)
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2019
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# MIT License
|
||||
|
||||
add_executable(ElementProxyTests
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
26
extras/tests/Helpers/CustomReader.hpp
Normal file
26
extras/tests/Helpers/CustomReader.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
|
||||
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<std::streamsize>(length));
|
||||
return static_cast<size_t>(_stream.gcount());
|
||||
}
|
||||
|
||||
private:
|
||||
CustomReader(const CustomReader&);
|
||||
};
|
14
extras/tests/Helpers/Stream.h
Normal file
14
extras/tests/Helpers/Stream.h
Normal file
@ -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;
|
||||
};
|
42
extras/tests/Helpers/WString.h
Normal file
42
extras/tests/Helpers/WString.h
Normal file
@ -0,0 +1,42 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// 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();
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2019
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# MIT License
|
||||
|
||||
add_executable(IntegrationTests
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2019
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# MIT License
|
||||
|
||||
add_executable(JsonArrayTests
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,34 +1,58 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonArray::isNull()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
|
||||
SECTION("returns true") {
|
||||
JsonArray arr;
|
||||
REQUIRE(arr.isNull() == true);
|
||||
}
|
||||
|
||||
SECTION("returns false") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
REQUIRE(arr.isNull() == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArrayConst::isNull()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
|
||||
SECTION("returns true") {
|
||||
JsonArrayConst arr;
|
||||
REQUIRE(arr.isNull() == true);
|
||||
}
|
||||
|
||||
SECTION("returns false") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArrayConst arr = doc.to<JsonArray>();
|
||||
REQUIRE(arr.isNull() == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArray::operator bool()") {
|
||||
SECTION("returns false") {
|
||||
JsonArray arr;
|
||||
REQUIRE(static_cast<bool>(arr) == false);
|
||||
}
|
||||
|
||||
SECTION("returns true") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
REQUIRE(static_cast<bool>(arr) == true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArrayConst::operator bool()") {
|
||||
SECTION("returns false") {
|
||||
JsonArrayConst arr;
|
||||
REQUIRE(static_cast<bool>(arr) == false);
|
||||
}
|
||||
|
||||
SECTION("returns true") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArrayConst arr = doc.to<JsonArray>();
|
||||
REQUIRE(static_cast<bool>(arr) == true);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2019
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# MIT License
|
||||
|
||||
add_executable(JsonDeserializerTests
|
||||
@ -18,4 +18,6 @@ add_executable(JsonDeserializerTests
|
||||
)
|
||||
|
||||
target_link_libraries(JsonDeserializerTests catch)
|
||||
set_target_properties(JsonDeserializerTests PROPERTIES UNITY_BUILD OFF)
|
||||
|
||||
add_test(JsonDeserializer JsonDeserializerTests)
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
@ -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<JsonArray>();
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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, "[");
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#define ARDUINOJSON_DECODE_UNICODE 1
|
||||
|
@ -1,11 +1,13 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#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<JsonArray>();
|
||||
@ -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<JsonObject>();
|
||||
@ -113,3 +115,14 @@ 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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
@ -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);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -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
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
@ -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<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(obj["hello"] == "world");
|
||||
}
|
||||
|
||||
SECTION("After opening brace") {
|
||||
DeserializationError err =
|
||||
deserializeJson(doc, "{/*COMMENT*/\"hello\":\"world\"}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(obj["hello"] == "world");
|
||||
}
|
||||
|
||||
SECTION("Before colon") {
|
||||
DeserializationError err =
|
||||
deserializeJson(doc, "{\"hello\"/*COMMENT*/:\"world\"}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(obj["hello"] == "world");
|
||||
}
|
||||
|
||||
SECTION("After colon") {
|
||||
DeserializationError err =
|
||||
deserializeJson(doc, "{\"hello\":/*COMMENT*/\"world\"}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(obj["hello"] == "world");
|
||||
}
|
||||
|
||||
SECTION("Before closing brace") {
|
||||
DeserializationError err =
|
||||
deserializeJson(doc, "{\"hello\":\"world\"/*COMMENT*/}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(obj["hello"] == "world");
|
||||
}
|
||||
|
||||
SECTION("After closing brace") {
|
||||
DeserializationError err =
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}/*COMMENT*/");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(obj["hello"] == "world");
|
||||
}
|
||||
|
||||
SECTION("Before comma") {
|
||||
DeserializationError err = deserializeJson(
|
||||
doc, "{\"hello\":\"world\"/*COMMENT*/,\"answer\":42}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
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<JsonObject>();
|
||||
|
||||
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<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(obj["hello"] == "world");
|
||||
}
|
||||
|
||||
SECTION("After opening brace") {
|
||||
DeserializationError err =
|
||||
deserializeJson(doc, "{//COMMENT\n\"hello\":\"world\"}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(obj["hello"] == "world");
|
||||
}
|
||||
|
||||
SECTION("Before colon") {
|
||||
DeserializationError err =
|
||||
deserializeJson(doc, "{\"hello\"//COMMENT\n:\"world\"}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(obj["hello"] == "world");
|
||||
}
|
||||
|
||||
SECTION("After colon") {
|
||||
DeserializationError err =
|
||||
deserializeJson(doc, "{\"hello\"://COMMENT\n\"world\"}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(obj["hello"] == "world");
|
||||
}
|
||||
|
||||
SECTION("Before closing brace") {
|
||||
DeserializationError err =
|
||||
deserializeJson(doc, "{\"hello\":\"world\"//COMMENT\n}");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(obj["hello"] == "world");
|
||||
}
|
||||
|
||||
SECTION("After closing brace") {
|
||||
DeserializationError err =
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}//COMMENT\n");
|
||||
JsonObject obj = doc.as<JsonObject>();
|
||||
|
||||
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<JsonObject>();
|
||||
|
||||
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<JsonObject>();
|
||||
|
||||
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<JsonObject>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#define ARDUINOJSON_DECODE_UNICODE 1
|
||||
@ -17,10 +17,10 @@ TEST_CASE("Valid JSON strings value") {
|
||||
{"\'hello world\'", "hello world"},
|
||||
{"\"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"}, // 🖤
|
||||
};
|
||||
const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2019
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# MIT License
|
||||
|
||||
add_executable(JsonDocumentTests
|
||||
@ -12,6 +12,7 @@ add_executable(JsonDocumentTests
|
||||
isNull.cpp
|
||||
nesting.cpp
|
||||
remove.cpp
|
||||
shrinkToFit.cpp
|
||||
size.cpp
|
||||
StaticJsonDocument.cpp
|
||||
subscript.cpp
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
151
extras/tests/JsonDocument/shrinkToFit.cpp
Normal file
151
extras/tests/JsonDocument/shrinkToFit.cpp
Normal file
@ -0,0 +1,151 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <stdlib.h> // malloc, free
|
||||
#include <string>
|
||||
|
||||
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<ArmoredAllocator> ShrinkToFitTestDocument;
|
||||
|
||||
void testShrinkToFit(ShrinkToFitTestDocument& doc, std::string expected_json,
|
||||
size_t expected_size) {
|
||||
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("[{},123]")));
|
||||
testShrinkToFit(doc, "[{},123]", 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\"]}");
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - arduinojson.org
|
||||
# Copyright Benoit Blanchon 2014-2019
|
||||
# Copyright Benoit Blanchon 2014-2020
|
||||
# MIT License
|
||||
|
||||
add_executable(JsonObjectTests
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,34 +1,58 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonObject::isNull()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
|
||||
SECTION("returns true") {
|
||||
JsonObject obj;
|
||||
REQUIRE(obj.isNull() == true);
|
||||
}
|
||||
|
||||
SECTION("returns false") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
REQUIRE(obj.isNull() == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObjectConst::isNull()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
|
||||
SECTION("returns true") {
|
||||
JsonObjectConst obj;
|
||||
REQUIRE(obj.isNull() == true);
|
||||
}
|
||||
|
||||
SECTION("returns false") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObjectConst obj = doc.to<JsonObject>();
|
||||
REQUIRE(obj.isNull() == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObject::operator bool()") {
|
||||
SECTION("returns false") {
|
||||
JsonObject obj;
|
||||
REQUIRE(static_cast<bool>(obj) == false);
|
||||
}
|
||||
|
||||
SECTION("returns true") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
REQUIRE(static_cast<bool>(obj) == true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObjectConst::operator bool()") {
|
||||
SECTION("returns false") {
|
||||
JsonObjectConst obj;
|
||||
REQUIRE(static_cast<bool>(obj) == false);
|
||||
}
|
||||
|
||||
SECTION("returns true") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonObjectConst obj = doc.to<JsonObject>();
|
||||
REQUIRE(static_cast<bool>(obj) == true);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -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
|
||||
|
52
extras/tests/JsonSerializer/CustomWriter.cpp
Normal file
52
extras/tests/JsonSerializer/CustomWriter.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
class CustomWriter {
|
||||
public:
|
||||
CustomWriter() {}
|
||||
|
||||
size_t write(uint8_t c) {
|
||||
_str.append(1, static_cast<char>(c));
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t write(const uint8_t *s, size_t n) {
|
||||
_str.append(reinterpret_cast<const char *>(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<JsonArray>();
|
||||
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());
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
@ -1,11 +1,11 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
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<JsonArray>();
|
||||
|
||||
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"
|
||||
"]");
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
// ArduinoJson - arduinojson.org
|
||||
// Copyright Benoit Blanchon 2014-2019
|
||||
// Copyright Benoit Blanchon 2014-2020
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
#include <string>
|
||||
|
||||
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<JsonObject>();
|
||||
|
||||
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<char *>(0);
|
||||
obj["b"] = static_cast<char *>(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<JsonArray>();
|
||||
obj["c"] = c.to<JsonArray>();
|
||||
|
||||
check(obj, "{\"a\":[],\"b\":[],\"c\":[]}");
|
||||
checkObject(obj, "{\"a\":[],\"b\":[],\"c\":[]}");
|
||||
}
|
||||
|
||||
SECTION("ThreeNestedObjects") {
|
||||
@ -111,6 +111,6 @@ TEST_CASE("serializeJson(JsonObject)") {
|
||||
obj["b"] = b.to<JsonObject>();
|
||||
obj["c"] = c.to<JsonObject>();
|
||||
|
||||
check(obj, "{\"a\":{},\"b\":{},\"c\":{}}");
|
||||
checkObject(obj, "{\"a\":{},\"b\":{},\"c\":{}}");
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user