Compare commits

...

33 Commits

Author SHA1 Message Date
ddfe7d8b91 Set version to 6.14.0 2020-01-16 20:48:03 +01:00
4a657ca87f Update the features section of the README page 2020-01-16 20:46:25 +01:00
1e3d478998 Improved speed of serializeXxx() when writing to a String 2020-01-14 14:50:44 +01:00
3aebef6d0a Fixed value returned by serializeXxx() when writing to a String 2020-01-14 11:22:44 +01:00
25879466da Fixed variant.is<nullptr_t>() 2020-01-13 20:47:43 +01:00
27ec1afb7a Configure the "lock-threads" app 2020-01-13 18:23:30 +01:00
06a0d1a872 Added measureJson, measureJsonPretty, and measureMsgPack to keywords 2020-01-13 18:20:05 +01:00
04fe7e1a27 Added ARDUINOJSON_ENABLE_COMMENTS to enable support for comments 2020-01-13 18:16:02 +01:00
f9cfea244a Updated copyright notice 2020-01-09 15:48:38 +01:00
5ec062cc71 Reduced Unicode conversion code size (-122 bytes on AVR) 2020-01-09 15:39:45 +01:00
91b808381e Improved decoding of UTF-16 surrogate pairs (closes #1157) 2020-01-08 09:55:43 +01:00
8550418875 Auto enable std::string and stream on modern compilers (closes #1156) 2020-01-04 15:05:20 +01:00
00c391320c Added support for CMake's unity builds 2019-12-24 16:42:34 +01:00
9723682d20 AppVeyor: added Visual Studio 2019 2019-12-24 16:10:11 +01:00
8bf6f6e09f Added support uint8_t for serializeMsgPack() (closes #1142) 2019-12-13 14:15:30 +01:00
062c1c13b5 Added BasicJsonDocument::shrinkToFit() 2019-11-07 15:40:20 +01:00
1b8107094f Set version to 6.13.0 2019-11-01 10:32:45 +01:00
8721ac88b1 Reorganized writer classes 2019-10-31 19:27:23 +01:00
6da6f921cd Fixed dangling reference in MemberProxy and ElementProxy (fixes #1120) 2019-10-30 19:09:21 +01:00
ef63757b1a Fixed deserializer that stopped reading at the first 0xFF (closes #1118) 2019-10-29 14:17:11 +01:00
3a169df0a5 Added support for custom reader classes 2019-10-25 11:39:04 +02:00
d4f819f1f0 Added detection of Atmel AVR8/GNU C Compiler (fixes #1112) 2019-10-18 22:10:35 +02:00
16fe3c0acc Improved deserializeMsgPack() speed by reading several bytes at once 2019-10-14 12:02:26 +02:00
fd8f4eb3a6 Moved msgpack.org.md to github.com/bblanchon/ArduinoJson-msgpack.org 2019-10-11 09:07:25 +02:00
b261eca865 esp-idf make system 2019-10-07 09:00:31 +02:00
a37480eec9 Fixed deserializeJson() when input contains duplicate keys (fixes #1095) 2019-09-27 10:07:29 +02:00
713aaa3d68 Added msgpack.org.md
https://github.com/msgpack/website/blob/master/README.md#how-to-list-up-your-project-on-msgpackorg
2019-09-26 09:52:50 +02:00
7d1d0c4e67 Added conversion from JsonArray/JsonObject to bool 2019-09-24 09:38:00 +02:00
4ad05dbaef Replaced GitHub stars badge 2019-09-19 09:28:57 +02:00
38371aae62 Added OSS-Fuzz badge 2019-09-19 09:28:49 +02:00
498a2e4c1e Added support for custom writer classes (closes #1088) 2019-09-13 14:10:21 +02:00
2078871f36 Added missing #include <ArduinoJson/Namespace.hpp> 2019-09-13 12:09:07 +02:00
140525b7a0 Fix deployment scripts 2019-09-05 09:36:18 +02:00
318 changed files with 2908 additions and 1495 deletions

7
.github/lock.yml vendored Normal file
View 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

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include "src/ArduinoJson.h"

View File

@ -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)
-------

View File

@ -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
View File

@ -2,58 +2,88 @@
---
[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.12.0)](https://www.ardu-badge.com/ArduinoJson/6.12.0)
[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.14.0)](https://www.ardu-badge.com/ArduinoJson/6.14.0)
[![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:
* <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)!

View File

@ -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
View File

@ -0,0 +1 @@
COMPONENT_ADD_INCLUDEDIRS := src

View 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 store your project configuration in a file.

View 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.

View 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 parse a JSON document in an HTTP response.

View 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 deserialize a JSON document with ArduinoJson.

View 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 implement an HTTP server that sends a JSON document

View 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 send a JSON document to a UDP socket.

View 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 deserialize a MessagePack document with

View File

@ -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

View File

@ -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.

View File

@ -1,5 +1,5 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2019
# Copyright Benoit Blanchon 2014-2020
# MIT License
if(MSVC)

View File

@ -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

View File

@ -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

View File

@ -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"

View 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.

View 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 deserialize a JSON document with ArduinoJson.

View 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.

View File

@ -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)

View File

@ -1,5 +1,5 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2019
# Copyright Benoit Blanchon 2014-2020
# MIT License
add_executable(ElementProxyTests

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View 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&);
};

View 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;
};

View 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();
}

View File

@ -1,5 +1,5 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2019
# Copyright Benoit Blanchon 2014-2020
# MIT License
add_executable(IntegrationTests

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2019
# Copyright Benoit Blanchon 2014-2020
# MIT License
add_executable(JsonArrayTests

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -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);
}
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -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)

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -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, "[");

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#define ARDUINOJSON_DECODE_UNICODE 1

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -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

View File

@ -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);
}
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -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]);

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -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

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View 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\"]}");
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2019
# Copyright Benoit Blanchon 2014-2020
# MIT License
add_executable(JsonObjectTests

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -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);
}
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -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

View 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());
}
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2019
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>

View File

@ -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"
"]");
}
}

View File

@ -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