Compare commits

..

86 Commits

Author SHA1 Message Date
e22d4bf31f Set version to 6.17.3 2021-02-15 09:53:10 +01:00
21f7b90f03 PlatformIO: set framework compatibility to * (closes #1490) 2021-02-15 09:49:56 +01:00
769e8440f5 CI: skip Particle job for Pull Requests 2021-02-05 13:00:56 +01:00
33de2b6cf3 Added GitHub sponsors 2021-02-05 12:03:50 +01:00
3975b07371 Moved CI from Travis to GitHub Actions (fixes #1493) 2021-02-03 21:33:18 +01:00
abd64102aa Fixed compilation error on Clang 10 2021-02-03 12:56:26 +01:00
d2174d1580 Fixed compilation error when isdigit() is a macro (fixes #1487) 2021-02-02 10:08:10 +01:00
c72eccdd35 Added missing calls to client.stop() in JsonHttpClient.ino (fixes #1485) 2021-02-01 09:16:23 +01:00
ab902128dc Upgrade to Lock Threads 2 2021-01-31 11:00:05 +01:00
c70a491f59 Made JsonDocument's destructor protected (fixes #1480) 2021-01-27 10:00:10 +01:00
322d13de0d Examples: add a note about performance issues with streams (#1476) 2021-01-25 09:26:29 +01:00
97b7161d78 Update copyright notice for 2021 2021-01-25 09:14:15 +01:00
1360b6a396 Set version to 6.17.2 2020-11-14 10:38:21 +01:00
16e51b83ab Changed the default value of ARDUINOJSON_ENABLE_PROGMEM (fixes #1433)
It now checks that the pgm_read_XXX macros are defined before enabling PROGMEM.
2020-11-10 14:58:31 +01:00
aa7cc5351c Travis: added smoke test for Particle Argon 2020-11-10 14:46:45 +01:00
30da920135 Fixed invalid conversion in operator|(Variant, char*) (fixes #1432) 2020-11-09 09:21:19 +01:00
bcdf5b7e52 Set version to 6.17.1 2020-11-07 10:11:41 +01:00
c711fe592d Allowed more than 32767 values in non-embedded mode (fixes #1414) 2020-10-28 09:59:40 +01:00
9d5c1b3742 Added an assert to detect too large variants (issue #1414) 2020-10-24 09:39:03 +02:00
6b26cd0977 Add JsonDocument to keywords.txt
see #1413
2020-10-24 09:37:16 +02:00
10ec0f21b0 Fixed operator|(MemberProxy, JsonObject) (fixes #1415) 2020-10-23 10:48:33 +02:00
ff66182dc6 Gathered the tests of MemberProxy in one file 2020-10-22 09:37:05 +02:00
d02ce2f1bb Gathered the tests of ElementProxy in one file 2020-10-22 09:37:05 +02:00
2664a2d0da Fixed error "ambiguous overload for operator|" (fixes #1411) 2020-10-22 09:30:31 +02:00
1f7350658e Set version to 6.17.0 2020-10-19 11:35:09 +02:00
41132b701b Fixed error "no matching function for pgm_read<double>()" on AVR 2020-10-17 14:02:26 +02:00
712005219c Added filtering for MessagePack (closes #1298, closes #1394) 2020-10-13 09:40:39 +02:00
0bd17aff8a Coverage: use -O0 instead of -Og 2020-10-11 15:10:52 +02:00
f3f44d7812 Renamed StdStringAdapter to StlStringAdapter (internal use only) 2020-10-01 10:01:33 +02:00
8385d5fa3a Added wildcard key (*) for filters (closes #1309) 2020-09-28 21:11:38 +02:00
726f8be341 Added operator|(JsonVariantConst, JsonVariantConst) 2020-09-26 14:48:17 +02:00
fee029b86e Moved float tables to PROGMEM 2020-09-19 16:12:49 +02:00
c3504ddf0a Added tests for DeserializationError::f_str() 2020-09-18 19:06:21 +02:00
6a878ee444 Fixed error "No such file or directory WString.h" (fixes #1381) 2020-09-16 10:29:20 +02:00
c4ec2ba88f Added DeserializationError::f_str() (issue #846) 2020-09-14 18:40:00 +02:00
c907ca6e5d Added DeserializationError::EmptyInput 2020-09-13 10:27:29 +02:00
8993a093e9 Travis: run sanitizer on recent GCC version to avoid false positives 2020-09-13 10:25:34 +02:00
d04669d0cc Fixed result of JsonVariant::set((char*)0) (fixes #1368) 2020-09-05 17:33:47 +02:00
05fc136915 Disabled memory sanitizer with clang 6 2020-09-05 13:44:40 +02:00
8d37939086 Added JsonDocument::overflowed() (closes #1358) 2020-09-05 13:44:40 +02:00
6d2ad4539f Simplified the implementation of parseNumber() 2020-09-04 09:23:40 +02:00
5ab53f42b2 Added a return value to visitors 2020-08-29 18:40:27 +02:00
f448e805e9 Removed dead code 2020-08-25 14:36:14 +02:00
67aa8efd5a Added a build failure when nullptr is defined as a macro (closes #1355) 2020-08-23 09:31:40 +02:00
61a5273aea Set version to 6.16.1 2020-08-04 10:33:38 +02:00
35a39b8d8f Fixed deserializeJson() that stopped reading after {} (fixes #1335) 2020-08-04 09:52:42 +02:00
96b6571352 Fixed use-of-uninitialized-value in encodeCodepoint() 2020-08-03 13:44:45 +02:00
74e7dd053f Added memory sanitizer to fuzzers 2020-08-03 13:44:45 +02:00
1f8636d762 Fixed build-arduino-package.sh to ignore .vs/ 2020-08-01 15:35:04 +02:00
e4cfa701d8 Fixed publish.sh to commit CMakeLists.txt 2020-08-01 15:34:27 +02:00
b85181a6db Set version to 6.16.0 2020-08-01 15:17:39 +02:00
6841b80466 Added JsonString::operator!= 2020-07-31 14:02:20 +02:00
298864bafe Set ARDUINOJSON_DECODE_UNICODE to 1 by default 2020-07-30 09:49:09 +02:00
4d7f03836c Added a test that removes an element during iteration (#1332) 2020-07-30 09:20:31 +02:00
c63eb80b95 Shortened the name of the private namespace using hexadecimal digits 2020-07-30 09:18:08 +02:00
0c0bf80074 Suppress IAR compiler warning. 2020-07-28 10:12:41 +02:00
144ff3b06e Updated the change log. Closes #1210 and closes #1314. 2020-07-26 16:09:03 +02:00
d6c50c3596 Reduced stack usage when compiled with -Og (issue #1210)
This saves 128 bytes on ESP8266
2020-07-26 14:51:58 +02:00
51b177ce47 Reduced stack usage when compiled with -Og (issue #1210)
This saves 112 bytes on ESP8266
2020-07-26 12:58:12 +02:00
824b7a25ca Reduced stack usage when compiled with -Og (issue #1210)
This saves 96 bytes on ESP8266
2020-07-26 12:25:13 +02:00
2223d40640 Reduced stack usage when compiler aggressively inlines deserializeJson()
This saves 64 bytes on the recursive part.
2020-07-26 12:25:13 +02:00
4df29fbac1 Fixed "linked" strings incorrectly marked as "owned" (fixes #1318) 2020-07-24 22:25:56 +02:00
6dc36125c2 Added ElementProxy::getOrAddElement() (fixes #1311) 2020-07-23 10:58:47 +02:00
40085609e2 Fixed copyArray() not working with MemberProxy and ElementProxy 2020-07-22 21:08:18 +02:00
ebb6d80092 Fixed copyArray() not working with String 2020-07-22 20:02:33 +02:00
764ff2cd53 Added string deduplication (closes #1303) 2020-07-21 20:15:31 +02:00
8ef226bcb8 Travis: Added Clang 9. Removed Xcode 7.3 2020-07-15 15:27:39 +02:00
63606c0985 Added json_fuzzer and msgpack_fuzzer in test suite 2020-07-15 12:50:00 +02:00
1600d39693 Refactored StringBuilder into StringStorage 2020-07-11 17:51:45 +02:00
04c59985a1 Inverted dependency between MemoryPool and string adapters.
Inserted a null after each raw string in the pool.
2020-07-08 09:38:27 +02:00
7e58347fbe Added comparisons between JsonVariants 2020-07-02 15:28:34 +02:00
0e794a28a1 Simplified implementation of comparison operators 2020-06-13 15:42:04 +02:00
6fb52c3638 Set version to 6.15.2 2020-05-15 09:26:25 +02:00
b72ef09451 Fixed publish script 2020-05-15 09:26:06 +02:00
f7de027617 Break build if using 64-bit integers with ARDUINOJSON_USE_LONG_LONG==0 2020-05-14 10:25:10 +02:00
bc4c2dde33 Moved failing builds to a dedicated folder 2020-05-12 18:11:55 +02:00
95f05dad66 Added JsonVariant as an input type for deserializeXxx() 2020-05-05 13:16:32 +02:00
3bb0a7aa8e Added support for enums in as<T>() and is<T>() (fixes #1256) 2020-05-04 11:13:06 +02:00
dcf7eeef28 CMake: used link_libraries() instead of target_link_libraries() 2020-05-03 10:25:38 +02:00
3b923b6e4e Added support for JsonDocument to copyArray() (issue #1255) 2020-05-02 10:00:08 +02:00
8050f7404b CMake: gathered all build flags in a dedicated file 2020-04-28 16:02:59 +02:00
959b1d9e4c Fixed error C2766 with flag /Zc:__cplusplus on VS2017+ (fixes #1250) 2020-04-28 16:02:38 +02:00
daa279d57b CMake: made project arch-independent 2020-04-11 18:49:28 +02:00
ae9b7926a2 CMake: don't build tests when imported in another project 2020-04-11 18:49:28 +02:00
1f7a5e6943 Fixed links in README 2020-04-11 11:53:08 +02:00
9e354803de Changed publish.sh to update the CMake project version 2020-04-09 21:28:48 +02:00
368 changed files with 6737 additions and 3659 deletions

1
.github/FUNDING.yml vendored
View File

@ -1 +1,2 @@
github: bblanchon
custom: https://arduinojson.org/book/

7
.github/lock.yml vendored
View File

@ -1,7 +0,0 @@
# 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

253
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,253 @@
name: Continuous Integration
on: [push, pull_request]
jobs:
gcc:
name: GCC
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- gcc: '4.4'
- gcc: '4.6'
- gcc: '4.7'
- gcc: '4.8'
- gcc: '4.9'
- gcc: '5'
- gcc: '6'
- gcc: '7'
cxxflags: -fsanitize=leak
- gcc: '8'
cxxflags: -fsanitize=undefined
- gcc: '9'
cxxflags: -fsanitize=address
- gcc: '10'
steps:
- name: Install
run: |
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic universe'
sudo apt-get update
sudo apt-get install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }}
if: ${{ matrix.gcc < 7 }}
- name: Checkout
uses: actions/checkout@v2
- name: Configure
run: cmake -DCMAKE_BUILD_TYPE=Debug .
env:
CC: gcc-${{ matrix.gcc }}
CXX: g++-${{ matrix.gcc }}
CXXFLAGS: ${{ matrix.cxxflags }}
- name: Build
run: cmake --build .
- name: Test
run: ctest --output-on-failure -C Debug .
clang:
name: Clang
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- clang: '3.5'
- clang: '3.6'
- clang: '3.7'
- clang: '3.8'
- clang: '3.9'
- clang: '4.0'
- clang: '5.0'
- clang: '6.0'
- clang: '7'
- clang: '8'
cxxflags: -fsanitize=leak
- clang: '9'
cxxflags: -fsanitize=undefined
- clang: '10'
cxxflags: -fsanitize=address
steps:
- name: Install
run: |
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic universe'
sudo apt-get update
sudo apt-get install -y clang-${{ matrix.clang }}
if: ${{ matrix.clang < 8 }}
- name: Checkout
uses: actions/checkout@v2
- name: Configure
run: cmake -DCMAKE_BUILD_TYPE=Debug .
env:
CC: clang-${{ matrix.clang }}
CXX: clang++-${{ matrix.clang }}
CXXFLAGS: ${{ matrix.cxxflags }}
- name: Build
run: cmake --build .
- name: Test
run: ctest --output-on-failure -C Debug .
xcode:
name: XCode
needs: clang
runs-on: macos-10.15
strategy:
fail-fast: false
matrix:
include:
- xcode: '10.3'
- xcode: '11.7'
- xcode: '12.4'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Select XCode version
run: sudo xcode-select --switch /Applications/Xcode_${{ matrix.xcode }}.app
- name: Configure
run: cmake -DCMAKE_BUILD_TYPE=Debug .
- name: Build
run: cmake --build .
- name: Test
run: ctest --output-on-failure -C Debug .
# DISABLED: Running on AppVeyor instead because it supports older versions of the compiler
# msvc:
# name: Visual Studio
# strategy:
# fail-fast: false
# matrix:
# include:
# - os: windows-2016
# - os: windows-2019
# runs-on: ${{ matrix.os }}
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# - name: Configure
# run: cmake -DCMAKE_BUILD_TYPE=Debug .
# - name: Build
# run: cmake --build .
# - name: Test
# run: ctest --output-on-failure -C Debug .
arduino:
name: Arduino
needs: gcc
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- arduino: '1.6.7'
board: arduino:avr:uno
- arduino: '1.8.2'
board: arduino:samd:mkr1000
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: extras/ci/arduino.sh ${{ matrix.board }}
env:
BOARD: ${{ matrix.board }}
VERSION: ${{ matrix.arduino }}
platformio:
name: PlatformIO
needs: gcc
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- board: uno
- board: esp01
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install PlatformIO
run: pip install platformio
- name: Build
run: extras/ci/platformio.sh ${{ matrix.board }}
particle:
name: Particle
needs: gcc
runs-on: ubuntu-latest
if: github.event_name == 'push'
strategy:
fail-fast: false
matrix:
include:
- board: argon
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Particle CLI
run: sudo npm install -g particle-cli
- name: Login to Particle
run: particle login -t "${{ secrets.PARTICLE_TOKEN }}"
- name: Compile
run: extras/ci/particle.sh ${{ matrix.board }}
arm:
name: GCC for ARM processor
needs: gcc
runs-on: ubuntu-20.04
steps:
- name: Install
run: sudo apt-get install -y g++-arm-linux-gnueabihf
- name: Checkout
uses: actions/checkout@v2
- name: Configure
run: cmake .
env:
CC: arm-linux-gnueabihf-gcc
CXX: arm-linux-gnueabihf-g++
- name: Build
run: cmake --build .
coverage:
needs: gcc
name: Coverage
runs-on: ubuntu-20.04
steps:
- name: Install
run: sudo apt-get install -y lcov ninja-build
- name: Checkout
uses: actions/checkout@v2
- name: Configure
run: cmake -G Ninja -DCOVERAGE=true .
- name: Build
run: ninja
- name: Test
run: ninja test
- name: lcov --capture
run: lcov --capture --no-external --directory . --output-file coverage.info
- name: lcov --remove
run: lcov --remove coverage.info "$(pwd)/extras/*" --output-file coverage_filtered.info
- name: genhtml
run: mkdir coverage && genhtml coverage_filtered.info -o coverage -t ArduinoJson
- name: Upload HTML report
uses: actions/upload-artifact@v2
with:
name: coverage
path: coverage
- name: Upload to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage_filtered.info

14
.github/workflows/lock.yml vendored Normal file
View File

@ -0,0 +1,14 @@
name: 'Lock Threads'
on:
schedule:
- cron: '0 0 * * *'
jobs:
lock:
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v2
with:
github-token: ${{ github.token }}
issue-lock-inactive-days: 30

4
.gitignore vendored
View File

@ -10,3 +10,7 @@
/extras/fuzzing/*_fuzzer.options
/extras/fuzzing/*_fuzzer_seed_corpus.zip
.vs/
# Used by CI for Particle
/src/*.ino
/project.properties

View File

@ -1,137 +0,0 @@
sudo: false
language: cpp
matrix:
include:
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.4']
env: SCRIPT=test _CC=gcc-4.4 _CXX=g++-4.4
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.6']
env: SCRIPT=test _CC=gcc-4.6 _CXX=g++-4.6
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.7']
env: SCRIPT=test _CC=gcc-4.7 _CXX=g++-4.7
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.8']
env: SCRIPT=test _CC=gcc-4.8 _CXX=g++-4.8 SANITIZE=address
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.9']
env: SCRIPT=test _CC=gcc-4.9 _CXX=g++-4.9 SANITIZE=leak
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5']
env: SCRIPT=test _CC=gcc-5 _CXX=g++-5 # SANITIZE=undefined
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6']
env: SCRIPT=test _CC=gcc-6 _CXX=g++-6
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-7']
env: SCRIPT=test _CC=gcc-7 _CXX=g++-7
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-8']
env: SCRIPT=test _CC=gcc-8 _CXX=g++-8
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-9']
env: SCRIPT=test _CC=gcc-9 _CXX=g++-9
- addons:
apt:
packages: ['g++-arm-linux-gnueabihf']
env: SCRIPT=build _CC=arm-linux-gnueabihf-gcc _CXX=arm-linux-gnueabihf-g++
- env: SCRIPT=test _CC=clang _CXX=clang++
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-precise-3.5']
packages: ['clang-3.5']
env: SCRIPT=test _CC=clang-3.5 _CXX=clang++-3.5 SANITIZE=address
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-precise-3.6']
packages: ['clang-3.6']
env: SCRIPT=test _CC=clang-3.6 _CXX=clang++-3.6 SANITIZE=leak
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-precise-3.7']
packages: ['clang-3.7']
env: SCRIPT=test _CC=clang-3.7 _CXX=clang++-3.7
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-precise-3.8']
packages: ['clang-3.8']
env: SCRIPT=test _CC=clang-3.8 _CXX=clang++-3.8 SANITIZE=undefined
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-3.9']
packages: ['clang-3.9']
env: SCRIPT=test _CC=clang-3.9 _CXX=clang++-3.9
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-4.0']
packages: ['clang-4.0']
env: SCRIPT=test _CC=clang-4.0 _CXX=clang++-4.0
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['clang-5.0']
env: SCRIPT=test _CC=clang-5.0 _CXX=clang++-5.0
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['clang-6.0']
env: SCRIPT=test _CC=clang-6.0 _CXX=clang++-6.0
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-7']
packages: ['clang-7']
env: SCRIPT=test _CC=clang-7 _CXX=clang++-7
- addons:
apt:
sources: ['ubuntu-toolchain-r-test','llvm-toolchain-trusty-8']
packages: ['clang-8']
env: SCRIPT=test _CC=clang-8 _CXX=clang++-8
- env: SCRIPT=coverage
- os: osx
osx_image: xcode7.3
env: SCRIPT=test
- os: osx
osx_image: xcode8.3
env: SCRIPT=test
- os: osx
osx_image: xcode9.4
env: SCRIPT=test
- os: osx
osx_image: xcode10
env: SCRIPT=test SANITIZE=address
- env: SCRIPT=arduino VERSION=1.6.7 BOARD=arduino:avr:uno
- env: SCRIPT=arduino VERSION=1.8.2 BOARD=arduino:samd:mkr1000
- env: SCRIPT=platformio BOARD=uno
- env: SCRIPT=platformio BOARD=esp01
- addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['clang-6.0','llvm-6.0']
env: SCRIPT=fuzz CLANG=6.0
cache:
directories:
- "~/.platformio"
- "extras/fuzzing/json_corpus"
- "extras/fuzzing/msgpack_corpus"
script: extras/ci/$SCRIPT.sh

View File

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

View File

@ -1,6 +1,72 @@
ArduinoJson: change log
=======================
v6.17.3 (2021-02-15)
-------
* Made `JsonDocument`'s destructor protected (issue #1480)
* Added missing calls to `client.stop()` in `JsonHttpClient.ino` (issue #1485)
* Fixed error `expected ')' before 'char'` when `isdigit()` is a macro (issue #1487)
* Fixed error `definition of implicit copy constructor is deprecated` on Clang 10
* PlatformIO: set framework compatibility to `*` (PR #1490 by @maxgerhardt)
v6.17.2 (2020-11-14)
-------
* Fixed invalid conversion error in `operator|(JsonVariant, char*)` (issue #1432)
* Changed the default value of `ARDUINOJSON_ENABLE_PROGMEM` (issue #1433).
It now checks that the `pgm_read_XXX` macros are defined before enabling `PROGMEM`.
v6.17.1 (2020-11-07)
-------
* Fixed error `ambiguous overload for 'operator|'` (issue #1411)
* Fixed `operator|(MemberProxy, JsonObject)` (issue #1415)
* Allowed more than 32767 values in non-embedded mode (issue #1414)
v6.17.0 (2020-10-19)
-------
* Added a build failure when nullptr is defined as a macro (issue #1355)
* Added `JsonDocument::overflowed()` which tells if the memory pool was too small (issue #1358)
* Added `DeserializationError::EmptyInput` which tells if the input was empty
* Added `DeserializationError::f_str()` which returns a `const __FlashStringHelper*` (issue #846)
* Added `operator|(JsonVariantConst, JsonVariantConst)`
* Added filtering for MessagePack (issue #1298, PR #1394 by Luca Passarella)
* Moved float convertion tables to PROGMEM
* Fixed `JsonVariant::set((char*)0)` which returned false instead of true (issue #1368)
* Fixed error `No such file or directory #include <WString.h>` (issue #1381)
v6.16.1 (2020-08-04)
-------
* Fixed `deserializeJson()` that stopped reading after `{}` (issue #1335)
v6.16.0 (2020-08-01)
-------
* Added comparisons (`>`, `>=`, `==`, `!=`, `<`, and `<=`) between `JsonVariant`s
* Added string deduplication (issue #1303)
* Added `JsonString::operator!=`
* Added wildcard key (`*`) for filters (issue #1309)
* Set `ARDUINOJSON_DECODE_UNICODE` to `1` by default
* Fixed `copyArray()` not working with `String`, `ElementProxy`, and `MemberProxy`
* Fixed error `getOrAddElement is not a member of ElementProxy` (issue #1311)
* Fixed excessive stack usage when compiled with `-Og` (issues #1210 and #1314)
* Fixed `Warning[Pa093]: implicit conversion from floating point to integer` on IAR compiler (PR #1328 by @stawiski)
v6.15.2 (2020-05-15)
-------
* CMake: don't build tests when imported in another project
* CMake: made project arch-independent
* Visual Studio: fixed error C2766 with flag `/Zc:__cplusplus` (issue #1250)
* Added support for `JsonDocument` to `copyArray()` (issue #1255)
* Added support for `enum`s in `as<T>()` and `is<T>()` (issue #1256)
* Added `JsonVariant` as an input type for `deserializeXxx()`
For example, you can do: `deserializeJson(doc2, doc1["payload"])`
* Break the build if using 64-bit integers with ARDUINOJSON_USE_LONG_LONG==0
v6.15.1 (2020-04-08)
-------

View File

@ -1,44 +1,19 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2020
# Copyright Benoit Blanchon 2014-2021
# MIT License
cmake_minimum_required(VERSION 3.0)
project(ArduinoJson)
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)
project(ArduinoJson VERSION 6.17.3)
enable_testing()
add_definitions(-DARDUINOJSON_DEBUG=1)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8)
add_compile_options(-g -Og)
else()
add_compile_options(-g -O0)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0)
add_compile_options(-g -Og)
else()
add_compile_options(-g -O0)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0)
add_compile_options(-g -Og)
else()
add_compile_options(-g -O0)
endif()
endif()
if(${COVERAGE})
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
endif()
add_subdirectory(src)
add_subdirectory(extras/tests)
add_subdirectory(extras/fuzzing)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
include(extras/CompileOptions.cmake)
add_subdirectory(extras/tests)
add_subdirectory(extras/fuzzing)
endif()

View File

@ -6,6 +6,5 @@ You can submit changes via GitHub Pull Requests.
Please:
1. Unit test every change in behavior
1. Update the test suite for any change of behavior
2. Use clang-format in "file" mode to format the code
3. Consider using the Continuous Integration (Travis and AppVeyor)

View File

@ -1,7 +1,7 @@
The MIT License (MIT)
---------------------
Copyright © 2014-2020 Benoit BLANCHON
Copyright © 2014-2021 Benoit BLANCHON
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -2,9 +2,9 @@
---
[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.15.1)](https://www.ardu-badge.com/ArduinoJson/6.15.1)
[![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)
[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.17.3)](https://www.ardu-badge.com/ArduinoJson/6.17.3)
[![Continuous Integration](https://github.com/bblanchon/ArduinoJson/workflows/Continuous%20Integration/badge.svg?branch=6.x)](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x)
[![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
[![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)
[![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat)](https://github.com/bblanchon/ArduinoJson/stargazers)
@ -17,9 +17,9 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/?utm_source=github&utm_medium=readme)
* [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme)
* [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/?utm_source=github&utm_medium=readme)
* [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/#filtering?utm_source=github&utm_medium=readme)
* [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#filtering)
* Supports single quotes as a string delimiter
* Compatible with NDJSON and JSON Lines
* Compatible with [NDJSON](http://ndjson.org/) and [JSON Lines](https://jsonlines.org/)
* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme)
* [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme)
* [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/?utm_source=github&utm_medium=readme)
@ -31,12 +31,13 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme)
* [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/?utm_source=github&utm_medium=readme)
* [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/?utm_source=github&utm_medium=readme)
* Deduplicates strings
* Versatile
* [Supports custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/?utm_source=github&utm_medium=readme)
* Supports [Arduino's `String`](https://arduinojson.org/v6/api/config/enable_arduino_string/) and [STL's `std::string`](https://arduinojson.org/v6/api/config/enable_std_string/?utm_source=github&utm_medium=readme)
* Supports Arduino's `Stream` and [STL's `std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/?utm_source=github&utm_medium=readme)
* [Supports Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/?utm_source=github&utm_medium=readme)
* Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/#custom-writer?utm_source=github&utm_medium=readme)
* Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme#custom-writer)
* Portable
* Usable on any C++ project (not limited to Arduino)
* Compatible with C++98
@ -57,25 +58,27 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* [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)
* [Particle](https://www.particle.io/)
* [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)
* [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/RlZSKy17DjJ6HcdN)
* [CMake friendly](https://arduinojson.org/v6/how-to/use-arduinojson-with-cmake/?utm_source=github&utm_medium=readme)
* Well designed
* [Elegant API](http://127.0.0.1:4000/v6/example/)
* [Elegant API](http://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)
* [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety)
* Self-contained (no external dependency)
* `const` friendly
* [`for` friendly](https://arduinojson.org/v6/api/jsonobject/begin_end/?utm_source=github&utm_medium=readme)
* [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming)
* Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/#integer-overflows?utm_source=github&utm_medium=readme)
* Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/?utm_source=github&utm_medium=readme#integer-overflows)
* Well tested
* [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
* Continuously tested on
* [Visual Studio 2010, 2012, 2013, 2015, 2017, 2019](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
* [GCC 4.4, 4.6, 4.7, 4.8, 4.9, 5, 6, 7, 8](https://travis-ci.org/bblanchon/ArduinoJson)
* [Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8](https://travis-ci.org/bblanchon/ArduinoJson)
* [GCC 4.4, 4.6, 4.7, 4.8, 4.9, 5, 6, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
* [Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
* [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
* Well documented
* [Tutorials](https://arduinojson.org/v6/doc/deserialization/?utm_source=github&utm_medium=readme)
@ -83,6 +86,7 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* [How-tos](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)
* [FAQ](https://arduinojson.org/v6/faq/?utm_source=github&utm_medium=readme)
* [Book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme)
* [Changelog](changelog.md)
* 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)

View File

@ -1,4 +1,4 @@
version: 6.15.1.{build}
version: 6.17.3.{build}
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to store your project configuration in a file.
@ -140,6 +140,12 @@ void loop() {
// not used in this example
}
// Performance issue?
// ------------------
//
// File is an unbuffered stream, which is not optimal for ArduinoJson.
// See: https://arduinojson.org/v6/how-to/improve-speed/
// See also
// --------
//

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to use DeserializationOpion::Filter

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// 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-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to parse a JSON document in an HTTP response.
@ -53,6 +53,7 @@ void setup() {
client.println(F("Connection: close"));
if (client.println() == 0) {
Serial.println(F("Failed to send request"));
client.stop();
return;
}
@ -63,6 +64,7 @@ void setup() {
if (strcmp(status + 9, "200 OK") != 0) {
Serial.print(F("Unexpected response: "));
Serial.println(status);
client.stop();
return;
}
@ -70,6 +72,7 @@ void setup() {
char endOfHeaders[] = "\r\n\r\n";
if (!client.find(endOfHeaders)) {
Serial.println(F("Invalid response"));
client.stop();
return;
}
@ -82,7 +85,8 @@ void setup() {
DeserializationError error = deserializeJson(doc, client);
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
Serial.println(error.f_str());
client.stop();
return;
}
@ -101,6 +105,12 @@ void loop() {
// not used in this example
}
// Performance issue?
// ------------------
//
// EthernetClient is an unbuffered stream, which is not optimal for ArduinoJson.
// See: https://arduinojson.org/v6/how-to/improve-speed/
// See also
// --------
//

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to deserialize a JSON document with ArduinoJson.
@ -42,7 +42,7 @@ void setup() {
// Test if parsing succeeds.
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
Serial.println(error.f_str());
return;
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to implement an HTTP server that sends a JSON document
@ -46,7 +46,8 @@ void loop() {
EthernetClient client = server.available();
// Do we have a client?
if (!client) return;
if (!client)
return;
Serial.println(F("New client"));
@ -96,6 +97,12 @@ void loop() {
client.stop();
}
// Performance issue?
// ------------------
//
// EthernetClient is an unbuffered stream, which is not optimal for ArduinoJson.
// See: https://arduinojson.org/v6/how-to/improve-speed/
// See also
// --------
//

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to send a JSON document to a UDP socket.
@ -86,6 +86,12 @@ void loop() {
delay(10000);
}
// Performance issue?
// ------------------
//
// EthernetUDP is an unbuffered stream, which is not optimal for ArduinoJson.
// See: https://arduinojson.org/v6/how-to/improve-speed/
// See also
// --------
//

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to deserialize a MessagePack document with
@ -50,7 +50,7 @@ void setup() {
// Test if parsing succeeded.
if (error) {
Serial.print("deserializeMsgPack() failed: ");
Serial.println(error.c_str());
Serial.println(error.f_str());
return;
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// 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-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows the different ways you can use String with ArduinoJson.

100
extras/CompileOptions.cmake Normal file
View File

@ -0,0 +1,100 @@
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
add_compile_options(
-pedantic
-Wall
-Wcast-align
-Wcast-qual
-Wconversion
-Wctor-dtor-privacy
-Wdisabled-optimization
-Werror
-Wextra
-Wformat=2
-Winit-self
-Wmissing-include-dirs
-Wnon-virtual-dtor
-Wold-style-cast
-Woverloaded-virtual
-Wparentheses
-Wredundant-decls
-Wshadow
-Wsign-promo
-Wstrict-aliasing
-Wundef
)
if(NOT MINGW)
add_compile_options(
-std=c++98
)
endif()
if(${COVERAGE})
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) AND (NOT ${COVERAGE}))
add_compile_options(-g -Og)
else()
add_compile_options(-g -O0)
endif()
add_compile_options(
-Wstrict-null-sentinel
-Wno-vla # Allow VLA in tests
)
add_definitions(-DHAS_VARIABLE_LENGTH_ARRAY)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.5)
add_compile_options(-Wlogical-op) # the flag exists in 4.4 but is buggy
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6)
add_compile_options(-Wnoexcept)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(
-Wc++11-compat
-Wdeprecated-register
-Wno-vla-extension # Allow VLA in tests
)
add_definitions(
-DHAS_VARIABLE_LENGTH_ARRAY
-DSUBSCRIPT_CONFLICTS_WITH_BUILTIN_OPERATOR
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) AND (NOT ${COVERAGE}))
add_compile_options(-g -Og)
else()
add_compile_options(-g -O0)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) AND (NOT ${COVERAGE}))
add_compile_options(-g -Og)
else()
add_compile_options(-g -O0)
endif()
endif()
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_compile_options(
/W4 # Set warning level
/WX # Treats all compiler warnings as errors.
)
if (NOT MSVC_VERSION LESS 1910) # >= Visual Studio 2017
add_compile_options(
/Zc:__cplusplus # Enable updated __cplusplus macro
)
endif()
endif()

View File

@ -1,14 +0,0 @@
#!/bin/sh -ex
export CC="$_CC"
export CXX="$_CXX"
if [ -n "$SANITIZE" ]; then
export CXXFLAGS="-fsanitize=$SANITIZE"
BUILD_TYPE="Debug"
else
BUILD_TYPE="Release"
fi
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE .
cmake --build .

View File

@ -1,9 +0,0 @@
#!/bin/sh -eux
cmake -DCOVERAGE=true .
make
make test
pip install --user cpp-coveralls 'requests[security]'
pwd
coveralls --include 'src' --gcov-options '\-lp'

View File

@ -1,26 +0,0 @@
#!/bin/bash -eux
ROOT_DIR=$(dirname $0)/../../
INCLUDE_DIR=${ROOT_DIR}/src/
FUZZING_DIR=${ROOT_DIR}/extras/fuzzing/
CXXFLAGS="-g -fprofile-instr-generate -fcoverage-mapping -fsanitize=address,undefined,fuzzer -fno-sanitize-recover=all"
fuzz() {
NAME="$1"
FUZZER="${NAME}_fuzzer"
FUZZER_CPP="${FUZZING_DIR}/${NAME}_fuzzer.cpp"
CORPUS_DIR="${FUZZING_DIR}/${NAME}_corpus"
SEED_CORPUS_DIR="${FUZZING_DIR}/${NAME}_seed_corpus"
clang++-${CLANG} ${CXXFLAGS} -o ${FUZZER} -I$INCLUDE_DIR ${FUZZER_CPP}
export ASAN_OPTIONS="detect_leaks=0"
export LLVM_PROFILE_FILE="${FUZZER}.profraw"
./${FUZZER} "$CORPUS_DIR" "$SEED_CORPUS_DIR" -max_total_time=30 -timeout=1
llvm-profdata-${CLANG} merge -sparse ${LLVM_PROFILE_FILE} -o ${FUZZER}.profdata
llvm-cov-${CLANG} report ./${FUZZER} -instr-profile=${FUZZER}.profdata
}
fuzz json
fuzz msgpack

10
extras/ci/particle.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh -ex
BOARD=$1
cd "$(dirname "$0")/../../"
cp extras/particle/src/smocktest.ino src/
cp extras/particle/project.properties ./
particle compile "$BOARD"

View File

@ -1,6 +1,6 @@
#!/bin/sh -eux
pip install --user platformio
BOARD=$1
case $BOARD in
uno)

View File

@ -1,4 +0,0 @@
#!/bin/sh -ex
"$(dirname "$0")/build.sh"
ctest --output-on-failure .

View File

@ -1,23 +1,54 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2020
# Copyright Benoit Blanchon 2014-2021
# MIT License
if(MSVC)
add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
endif()
add_executable(msgpack_fuzzer
add_executable(msgpack_reproducer
msgpack_fuzzer.cpp
fuzzer_main.cpp
reproducer.cpp
)
target_link_libraries(msgpack_fuzzer
target_link_libraries(msgpack_reproducer
ArduinoJson
)
add_executable(json_fuzzer
add_executable(json_reproducer
json_fuzzer.cpp
fuzzer_main.cpp
reproducer.cpp
)
target_link_libraries(json_fuzzer
target_link_libraries(json_reproducer
ArduinoJson
)
macro(add_fuzzer name)
set(FUZZER "${name}_fuzzer")
set(CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_corpus")
set(SEED_CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_seed_corpus")
add_executable("${FUZZER}"
"${name}_fuzzer.cpp"
)
target_link_libraries("${FUZZER}"
ArduinoJson
)
set_target_properties("${FUZZER}"
PROPERTIES
COMPILE_FLAGS
"-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
LINK_FLAGS
"-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
)
add_test(
NAME
"${FUZZER}"
COMMAND
"${FUZZER}" "${CORPUS_DIR}" "${SEED_CORPUS_DIR}" -max_total_time=5 -timeout=1
)
endmacro()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6)
add_fuzzer(json)
add_fuzzer(msgpack)
endif()

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
// This file is NOT use by Google's OSS fuzz
@ -21,7 +21,7 @@ std::vector<uint8_t> read(const char* path) {
}
fseek(f, 0, SEEK_END);
size_t size = ftell(f);
size_t size = static_cast<size_t>(ftell(f));
fseek(f, 0, SEEK_SET);
std::vector<uint8_t> buffer(size);

View File

@ -0,0 +1 @@
name=ArduinoJsonCI

View File

@ -0,0 +1,5 @@
#include "ArduinoJson.h"
void setup() {}
void loop() {}

View File

@ -10,6 +10,7 @@ rm -f $OUTPUT
# create zip
7z a $OUTPUT \
-xr!.vs \
ArduinoJson/CHANGELOG.md \
ArduinoJson/examples \
ArduinoJson/src \

View File

@ -1,29 +0,0 @@
#!/bin/bash
export PATH="$PATH:/Applications/CMake.app/Contents/bin/"
cd $(dirname $0)/../..
ROOT=$(pwd)
mkdir "build"
cd build
BUILD=$(pwd)
build-env()
{
cd $BUILD
mkdir "$1"
cd "$1"
cmake "$ROOT" -G "$2"
}
if [[ $(uname) == MINGW* ]]
then
build-env "Make" "MinGW Makefiles"
build-env "SublimeText" "Sublime Text 2 - Ninja"
build-env "VisualStudio" "Visual Studio 14 2015"
else
build-env "SublimeText" "Sublime Text 2 - Ninja"
build-env "Make" "Unix Makefiles"
build-env "Xcode" "Xcode"
fi

View File

@ -14,19 +14,22 @@ update_version_in_source () {
UNDERLINE=$(printf -- '-%.0s' $(seq 1 ${#TAG}))
sed -i~ -bE "s/version=$VERSION_REGEX/version=$VERSION/; s|ardu-badge.com/ArduinoJson/$VERSION_REGEX|ardu-badge.com/ArduinoJson/$VERSION|; " README.md
rm README.md*~
rm README.md~
sed -i~ -bE "4s/HEAD/$TAG ($DATE)/; 5s/-+/$UNDERLINE/" CHANGELOG.md
rm CHANGELOG.md*~
rm CHANGELOG.md~
sed -i~ -bE "s/(project\\s*\\(ArduinoJson\\s+VERSION\\s+).*?\\)/\\1$MAJOR.$MINOR.$REVISION)/" CMakeLists.txt
rm CMakeLists.txt~
sed -i~ -bE "s/\"version\":.*$/\"version\": \"$VERSION\",/" library.json
rm library.json*~
rm library.json~
sed -i~ -bE "s/version=.*$/version=$VERSION/" library.properties
rm library.properties*~
rm library.properties~
sed -i~ -bE "s/version: .*$/version: $VERSION.{build}/" appveyor.yml
rm appveyor.yml*~
rm appveyor.yml~
sed -i~ -bE \
-e "s/ARDUINOJSON_VERSION .*$/ARDUINOJSON_VERSION \"$VERSION\"/" \
@ -38,7 +41,7 @@ update_version_in_source () {
}
commit_new_version () {
git add src/ArduinoJson/version.hpp README.md CHANGELOG.md library.json library.properties appveyor.yml
git add src/ArduinoJson/version.hpp README.md CHANGELOG.md library.json library.properties appveyor.yml CMakeLists.txt
git commit -m "Set version to $VERSION"
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// 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-2020
// Copyright Benoit Blanchon 2014-2021
// 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-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
//
// This example shows how to generate a JSON document with ArduinoJson.

View File

@ -1,79 +1,13 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2020
# Copyright Benoit Blanchon 2014-2021
# MIT License
add_subdirectory(catch)
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
add_compile_options(
-pedantic
-Wall
-Wcast-align
-Wcast-qual
-Wconversion
-Wctor-dtor-privacy
-Wdisabled-optimization
-Werror
-Wextra
-Wformat=2
-Winit-self
-Wmissing-include-dirs
-Wnon-virtual-dtor
-Wold-style-cast
-Woverloaded-virtual
-Wparentheses
-Wredundant-decls
-Wshadow
-Wsign-promo
-Wstrict-aliasing
-Wundef
)
if(NOT MINGW)
add_compile_options(
-std=c++98
)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options(
-Wstrict-null-sentinel
-Wno-vla # Allow VLA in tests
)
add_definitions(-DHAS_VARIABLE_LENGTH_ARRAY)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.5)
add_compile_options(-Wlogical-op) # the flag exists in 4.4 but is buggy
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6)
add_compile_options(-Wnoexcept)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(
-Wc++11-compat
-Wdeprecated-register
-Wno-vla-extension # Allow VLA in tests
)
add_definitions(
-DHAS_VARIABLE_LENGTH_ARRAY
-DSUBSCRIPT_CONFLICTS_WITH_BUILTIN_OPERATOR
)
endif()
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_compile_options(
/W4 # Set warning level
/WX # Treats all compiler warnings as errors.
)
endif()
link_libraries(ArduinoJson catch)
include_directories(Helpers)
add_subdirectory(ElementProxy)
add_subdirectory(FailingBuilds)
add_subdirectory(IntegrationTests)
add_subdirectory(JsonArray)
add_subdirectory(JsonDeserializer)
@ -81,7 +15,6 @@ add_subdirectory(JsonDocument)
add_subdirectory(JsonObject)
add_subdirectory(JsonSerializer)
add_subdirectory(JsonVariant)
add_subdirectory(MemberProxy)
add_subdirectory(MemoryPool)
add_subdirectory(Misc)
add_subdirectory(MixedConfiguration)

View File

@ -1,19 +0,0 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2020
# MIT License
add_executable(ElementProxyTests
add.cpp
clear.cpp
compare.cpp
remove.cpp
set.cpp
size.cpp
)
target_link_libraries(ElementProxyTests
ArduinoJson
catch
)
add_test(ElementProxy ElementProxyTests)

View File

@ -1,34 +0,0 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
TEST_CASE("ElementProxy::add()") {
DynamicJsonDocument doc(4096);
doc.addElement();
ElementProxy<JsonDocument&> ep = doc[0];
SECTION("add(int)") {
ep.add(42);
REQUIRE(doc.as<std::string>() == "[[42]]");
}
SECTION("add(const char*)") {
ep.add("world");
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
}
SECTION("set(char[])") {
char s[] = "world";
ep.add(s);
strcpy(s, "!!!!!");
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
}
}

View File

@ -1,28 +0,0 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
TEST_CASE("ElementProxy::clear()") {
DynamicJsonDocument doc(4096);
doc.addElement();
ElementProxy<JsonDocument&> ep = doc[0];
SECTION("size goes back to zero") {
ep.add(42);
ep.clear();
REQUIRE(ep.size() == 0);
}
SECTION("isNull() return true") {
ep.add("hello");
ep.clear();
REQUIRE(ep.isNull() == true);
}
}

View File

@ -1,28 +0,0 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
TEST_CASE("ElementProxy::operator==()") {
DynamicJsonDocument doc(4096);
SECTION("same value") {
doc.add(1);
doc.add(1);
REQUIRE(doc[0] == doc[1]);
REQUIRE_FALSE(doc[0] != doc[1]);
}
SECTION("different values") {
doc.add(1);
doc.add(2);
REQUIRE_FALSE(doc[0] == doc[1]);
REQUIRE(doc[0] != doc[1]);
}
}

View File

@ -1,56 +0,0 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
TEST_CASE("ElementProxy::remove()") {
DynamicJsonDocument doc(4096);
doc.addElement();
ElementProxy<JsonDocument&> ep = doc[0];
SECTION("remove(int)") {
ep.add(1);
ep.add(2);
ep.add(3);
ep.remove(1);
REQUIRE(ep.as<std::string>() == "[1,3]");
}
SECTION("remove(const char *)") {
ep["a"] = 1;
ep["b"] = 2;
ep.remove("a");
REQUIRE(ep.as<std::string>() == "{\"b\":2}");
}
SECTION("remove(std::string)") {
ep["a"] = 1;
ep["b"] = 2;
ep.remove(std::string("b"));
REQUIRE(ep.as<std::string>() == "{\"a\":1}");
}
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("remove(vla)") {
ep["a"] = 1;
ep["b"] = 2;
int i = 4;
char vla[i];
strcpy(vla, "b");
ep.remove(vla);
REQUIRE(ep.as<std::string>() == "{\"a\":1}");
}
#endif
}

View File

@ -1,33 +0,0 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
TEST_CASE("ElementProxy::set()") {
DynamicJsonDocument doc(4096);
ElementProxy<JsonDocument&> ep = doc[0];
SECTION("set(int)") {
ep.set(42);
REQUIRE(doc.as<std::string>() == "[42]");
}
SECTION("set(const char*)") {
ep.set("world");
REQUIRE(doc.as<std::string>() == "[\"world\"]");
}
SECTION("set(char[])") {
char s[] = "world";
ep.set(s);
strcpy(s, "!!!!!");
REQUIRE(doc.as<std::string>() == "[\"world\"]");
}
}

View File

@ -1,30 +0,0 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
TEST_CASE("ElementProxy::size()") {
DynamicJsonDocument doc(4096);
doc.addElement();
ElementProxy<JsonDocument&> ep = doc[0];
SECTION("returns 0") {
REQUIRE(ep.size() == 0);
}
SECTION("as an array, returns 2") {
ep.add(1);
ep.add(2);
REQUIRE(ep.size() == 2);
}
SECTION("as an object, returns 2") {
ep["a"] = 1;
ep["b"] = 2;
REQUIRE(ep.size() == 2);
}
}

View File

@ -1,25 +0,0 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
TEST_CASE("MemberProxy::operator[]") {
DynamicJsonDocument doc(4096);
ElementProxy<JsonDocument&> ep = doc[1];
SECTION("set member") {
ep["world"] = 42;
REQUIRE(doc.as<std::string>() == "[null,{\"world\":42}]");
}
SECTION("set element") {
ep[2] = 42;
REQUIRE(doc.as<std::string>() == "[null,[null,null,42]]");
}
}

View File

@ -0,0 +1,41 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# MIT License
macro(build_should_fail target)
set_target_properties(${target}
PROPERTIES
EXCLUDE_FROM_ALL TRUE
EXCLUDE_FROM_DEFAULT_BUILD TRUE
)
add_test(
NAME
${target}
COMMAND
${CMAKE_COMMAND} --build . --target ${target} --config $<CONFIGURATION>
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}
)
set_tests_properties(${target}
PROPERTIES
WILL_FAIL TRUE
)
endmacro()
add_executable(Issue978 Issue978.cpp)
build_should_fail(Issue978)
add_executable(Issue1189 Issue1189.cpp)
build_should_fail(Issue1189)
add_executable(read_long_long read_long_long.cpp)
set_property(TARGET read_long_long PROPERTY CXX_STANDARD 11)
build_should_fail(read_long_long)
add_executable(write_long_long write_long_long.cpp)
set_property(TARGET write_long_long PROPERTY CXX_STANDARD 11)
build_should_fail(write_long_long)
add_executable(delete_jsondocument delete_jsondocument.cpp)
build_should_fail(delete_jsondocument)

View File

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

View File

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

View File

@ -0,0 +1,12 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
struct Stream {};
int main() {
JsonDocument* doc = new DynamicJsonDocument(42);
delete doc;
}

View File

@ -0,0 +1,20 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#define ARDUINOJSON_USE_LONG_LONG 0
#include <ArduinoJson.h>
#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ >= 8
#error This test requires sizeof(long) < 8
#endif
#if !ARDUINOJSON_HAS_LONG_LONG
#error This test requires C++11
#endif
ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(long long)
int main() {
DynamicJsonDocument doc(1024);
doc["dummy"].as<long long>();
}

View File

@ -0,0 +1,19 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#define ARDUINOJSON_USE_LONG_LONG 0
#include <ArduinoJson.h>
#if defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ >= 8
#error This test requires sizeof(long) < 8
#endif
#if !ARDUINOJSON_HAS_LONG_LONG
#error This test requires C++11
#endif
int main() {
DynamicJsonDocument doc(1024);
doc["dummy"] = static_cast<long long>(42);
}

View File

@ -0,0 +1,8 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include "api/Stream.h"
#include "api/String.h"

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
@ -9,6 +9,9 @@
// Reproduces Arduino's String class
class String {
public:
String() {}
explicit String(const char* s) : _str(s) {}
String& operator+=(const char* rhs) {
_str += rhs;
return *this;

View File

@ -1,10 +1,12 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <stdint.h> // uint8_t
#include <string.h> // strcmp, strlen...
#define PROGMEM
class __FlashStringHelper;
inline const void* convertPtrToFlash(const void* s) {
@ -15,9 +17,26 @@ inline const void* convertFlashToPtr(const void* s) {
return reinterpret_cast<const char*>(s) - 42;
}
#define F(X) reinterpret_cast<const __FlashStringHelper*>(convertPtrToFlash(X))
#define FC(X) reinterpret_cast<const char*>(convertPtrToFlash(X))
#define PSTR(X) reinterpret_cast<const char*>(convertPtrToFlash(X))
#define F(X) reinterpret_cast<const __FlashStringHelper*>(PSTR(X))
inline uint8_t pgm_read_byte(const void* p) {
return *reinterpret_cast<const uint8_t*>(convertFlashToPtr(p));
}
inline void* pgm_read_ptr(const void* p) {
return *reinterpret_cast<void* const*>(convertFlashToPtr(p));
}
inline float pgm_read_float(const void* p) {
return *reinterpret_cast<const float*>(convertFlashToPtr(p));
}
inline uint32_t pgm_read_dword(const void* p) {
return *reinterpret_cast<const uint32_t*>(convertFlashToPtr(p));
}
#define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \
static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = value; \
static type const* name = reinterpret_cast<type const*>( \
convertPtrToFlash(ARDUINOJSON_CONCAT2(name, _progmem)));

View File

@ -1,5 +1,5 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2020
# Copyright Benoit Blanchon 2014-2021
# MIT License
add_executable(IntegrationTests
@ -16,9 +16,4 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
)
endif()
target_link_libraries(IntegrationTests
ArduinoJson
catch
)
add_test(IntegrationTests IntegrationTests)

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2020
# Copyright Benoit Blanchon 2014-2021
# MIT License
add_executable(JsonArrayTests
@ -19,9 +19,4 @@ add_executable(JsonArrayTests
undefined.cpp
)
target_link_libraries(JsonArrayTests
ArduinoJson
catch
)
add_test(JsonArray JsonArrayTests)

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
@ -102,13 +102,13 @@ TEST_CASE("JsonArray::add()") {
SECTION("should duplicate char*") {
array.add(const_cast<char*>("world"));
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(6);
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5);
REQUIRE(expectedSize == doc.memoryUsage());
}
SECTION("should duplicate std::string") {
array.add(std::string("world"));
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(6);
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5);
REQUIRE(expectedSize == doc.memoryUsage());
}

View File

@ -1,25 +1,62 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("copyArray()") {
SECTION("1D -> JsonArray") {
SECTION("int[] -> JsonArray") {
DynamicJsonDocument doc(4096);
JsonArray array = doc.to<JsonArray>();
char json[32];
int source[] = {1, 2, 3};
bool ok = copyArray(source, array);
REQUIRE(ok);
CHECK(ok);
serializeJson(array, json, sizeof(json));
REQUIRE(std::string("[1,2,3]") == json);
serializeJson(array, json);
CHECK(std::string("[1,2,3]") == json);
}
SECTION("1D -> JsonArray, but not enough memory") {
SECTION("std::string[] -> JsonArray") {
DynamicJsonDocument doc(4096);
JsonArray array = doc.to<JsonArray>();
char json[32];
std::string source[] = {"a", "b", "c"};
bool ok = copyArray(source, array);
CHECK(ok);
serializeJson(array, json);
CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
}
SECTION("int[] -> JsonDocument") {
DynamicJsonDocument doc(4096);
char json[32];
int source[] = {1, 2, 3};
bool ok = copyArray(source, doc);
CHECK(ok);
serializeJson(doc, json);
CHECK(std::string("[1,2,3]") == json);
}
SECTION("int[] -> MemberProxy") {
DynamicJsonDocument doc(4096);
char json[32];
int source[] = {1, 2, 3};
bool ok = copyArray(source, doc["data"]);
CHECK(ok);
serializeJson(doc, json);
CHECK(std::string("{\"data\":[1,2,3]}") == json);
}
SECTION("int[] -> JsonArray, but not enough memory") {
const size_t SIZE = JSON_ARRAY_SIZE(2);
StaticJsonDocument<SIZE> doc;
JsonArray array = doc.to<JsonArray>();
@ -29,24 +66,48 @@ TEST_CASE("copyArray()") {
bool ok = copyArray(source, array);
REQUIRE_FALSE(ok);
serializeJson(array, json, sizeof(json));
REQUIRE(std::string("[1,2]") == json);
serializeJson(array, json);
CHECK(std::string("[1,2]") == json);
}
SECTION("2D -> JsonArray") {
SECTION("int[][] -> JsonArray") {
DynamicJsonDocument doc(4096);
JsonArray array = doc.to<JsonArray>();
char json[32];
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
bool ok = copyArray(source, array);
REQUIRE(ok);
CHECK(ok);
serializeJson(array, json, sizeof(json));
REQUIRE(std::string("[[1,2,3],[4,5,6]]") == json);
serializeJson(array, json);
CHECK(std::string("[[1,2,3],[4,5,6]]") == json);
}
SECTION("2D -> JsonArray, but not enough memory") {
SECTION("int[][] -> MemberProxy") {
DynamicJsonDocument doc(4096);
char json[32];
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
bool ok = copyArray(source, doc["data"]);
CHECK(ok);
serializeJson(doc, json);
CHECK(std::string("{\"data\":[[1,2,3],[4,5,6]]}") == json);
}
SECTION("int[][] -> JsonDocument") {
DynamicJsonDocument doc(4096);
char json[32];
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
bool ok = copyArray(source, doc);
CHECK(ok);
serializeJson(doc, json);
CHECK(std::string("[[1,2,3],[4,5,6]]") == json);
}
SECTION("int[][] -> JsonArray, but not enough memory") {
const size_t SIZE =
JSON_ARRAY_SIZE(2) + JSON_ARRAY_SIZE(3) + JSON_ARRAY_SIZE(2);
StaticJsonDocument<SIZE> doc;
@ -60,58 +121,159 @@ TEST_CASE("copyArray()") {
CAPTURE(doc.memoryUsage());
CHECK_FALSE(ok);
serializeJson(array, json, sizeof(json));
REQUIRE(std::string("[[1,2,3],[4,5]]") == json);
serializeJson(array, json);
CHECK(std::string("[[1,2,3],[4,5]]") == json);
}
SECTION("JsonArray -> 1D, with more space than needed") {
SECTION("JsonArray -> int[], with more space than needed") {
DynamicJsonDocument doc(4096);
char json[] = "[1,2,3]";
DeserializationError err = deserializeJson(doc, json);
REQUIRE(err == DeserializationError::Ok);
CHECK(err == DeserializationError::Ok);
JsonArray array = doc.as<JsonArray>();
int destination[4] = {0};
size_t result = copyArray(array, destination);
REQUIRE(3 == result);
REQUIRE(1 == destination[0]);
REQUIRE(2 == destination[1]);
REQUIRE(3 == destination[2]);
REQUIRE(0 == destination[3]);
CHECK(3 == result);
CHECK(1 == destination[0]);
CHECK(2 == destination[1]);
CHECK(3 == destination[2]);
CHECK(0 == destination[3]);
}
SECTION("JsonArray -> 1D, without enough space") {
SECTION("JsonArray -> int[], without enough space") {
DynamicJsonDocument doc(4096);
char json[] = "[1,2,3]";
DeserializationError err = deserializeJson(doc, json);
REQUIRE(err == DeserializationError::Ok);
CHECK(err == DeserializationError::Ok);
JsonArray array = doc.as<JsonArray>();
int destination[2] = {0};
size_t result = copyArray(array, destination);
REQUIRE(2 == result);
REQUIRE(1 == destination[0]);
REQUIRE(2 == destination[1]);
CHECK(2 == result);
CHECK(1 == destination[0]);
CHECK(2 == destination[1]);
}
SECTION("JsonArray -> 2D") {
SECTION("JsonArray -> std::string[]") {
DynamicJsonDocument doc(4096);
char json[] = "[\"a\",\"b\",\"c\"]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
JsonArray array = doc.as<JsonArray>();
std::string destination[4];
size_t result = copyArray(array, destination);
CHECK(3 == result);
CHECK("a" == destination[0]);
CHECK("b" == destination[1]);
CHECK("c" == destination[2]);
CHECK("" == destination[3]);
}
SECTION("JsonDocument -> int[]") {
DynamicJsonDocument doc(4096);
char json[] = "[1,2,3]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
int destination[4] = {0};
size_t result = copyArray(doc, destination);
CHECK(3 == result);
CHECK(1 == destination[0]);
CHECK(2 == destination[1]);
CHECK(3 == destination[2]);
CHECK(0 == destination[3]);
}
SECTION("MemberProxy -> int[]") {
DynamicJsonDocument doc(4096);
char json[] = "{\"data\":[1,2,3]}";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
int destination[4] = {0};
size_t result = copyArray(doc["data"], destination);
CHECK(3 == result);
CHECK(1 == destination[0]);
CHECK(2 == destination[1]);
CHECK(3 == destination[2]);
CHECK(0 == destination[3]);
}
SECTION("ElementProxy -> int[]") {
DynamicJsonDocument doc(4096);
char json[] = "[[1,2,3]]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
int destination[4] = {0};
size_t result = copyArray(doc[0], destination);
CHECK(3 == result);
CHECK(1 == destination[0]);
CHECK(2 == destination[1]);
CHECK(3 == destination[2]);
CHECK(0 == destination[3]);
}
SECTION("JsonArray -> int[][]") {
DynamicJsonDocument doc(4096);
char json[] = "[[1,2],[3],[4]]";
DeserializationError err = deserializeJson(doc, json);
REQUIRE(err == DeserializationError::Ok);
CHECK(err == DeserializationError::Ok);
JsonArray array = doc.as<JsonArray>();
int destination[3][2] = {{0}};
copyArray(array, destination);
REQUIRE(1 == destination[0][0]);
REQUIRE(2 == destination[0][1]);
REQUIRE(3 == destination[1][0]);
REQUIRE(0 == destination[1][1]);
REQUIRE(4 == destination[2][0]);
REQUIRE(0 == destination[2][1]);
CHECK(1 == destination[0][0]);
CHECK(2 == destination[0][1]);
CHECK(3 == destination[1][0]);
CHECK(0 == destination[1][1]);
CHECK(4 == destination[2][0]);
CHECK(0 == destination[2][1]);
}
SECTION("JsonDocument -> int[][]") {
DynamicJsonDocument doc(4096);
char json[] = "[[1,2],[3],[4]]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
int destination[3][2] = {{0}};
copyArray(doc, destination);
CHECK(1 == destination[0][0]);
CHECK(2 == destination[0][1]);
CHECK(3 == destination[1][0]);
CHECK(0 == destination[1][1]);
CHECK(4 == destination[2][0]);
CHECK(0 == destination[2][1]);
}
SECTION("MemberProxy -> int[][]") {
DynamicJsonDocument doc(4096);
char json[] = "{\"data\":[[1,2],[3],[4]]}";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
int destination[3][2] = {{0}};
copyArray(doc["data"], destination);
CHECK(1 == destination[0][0]);
CHECK(2 == destination[0][1]);
CHECK(3 == destination[1][0]);
CHECK(0 == destination[1][1]);
CHECK(4 == destination[2][0]);
CHECK(0 == destination[2][1]);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
@ -65,4 +65,15 @@ TEST_CASE("JsonArray::remove()") {
REQUIRE(_array[0] == 1);
REQUIRE(_array[1] == 2);
}
SECTION("In a loop") {
for (JsonArray::iterator it = _array.begin(); it != _array.end(); ++it) {
if (*it == 2)
_array.remove(it);
}
REQUIRE(2 == _array.size());
REQUIRE(_array[0] == 1);
REQUIRE(_array[1] == 3);
}
}

View File

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

View File

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

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
@ -119,13 +119,13 @@ TEST_CASE("JsonArray::operator[]") {
SECTION("should duplicate char*") {
array[0] = const_cast<char*>("world");
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(6);
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5);
REQUIRE(expectedSize == doc.memoryUsage());
}
SECTION("should duplicate std::string") {
array[0] = std::string("world");
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(6);
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5);
REQUIRE(expectedSize == doc.memoryUsage());
}

View File

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

View File

@ -1,5 +1,5 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2020
# Copyright Benoit Blanchon 2014-2021
# MIT License
add_executable(JsonDeserializerTests
@ -18,11 +18,6 @@ add_executable(JsonDeserializerTests
string.cpp
)
target_link_libraries(JsonDeserializerTests
ArduinoJson
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-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
@ -30,20 +30,22 @@ void testBoolification(DeserializationError error, bool expected) {
TEST_CASE("DeserializationError") {
SECTION("c_str()") {
TEST_STRINGIFICATION(Ok);
TEST_STRINGIFICATION(TooDeep);
TEST_STRINGIFICATION(NoMemory);
TEST_STRINGIFICATION(InvalidInput);
TEST_STRINGIFICATION(EmptyInput);
TEST_STRINGIFICATION(IncompleteInput);
TEST_STRINGIFICATION(InvalidInput);
TEST_STRINGIFICATION(NoMemory);
TEST_STRINGIFICATION(NotSupported);
TEST_STRINGIFICATION(TooDeep);
}
SECTION("as boolean") {
TEST_BOOLIFICATION(Ok, false);
TEST_BOOLIFICATION(TooDeep, true);
TEST_BOOLIFICATION(NoMemory, true);
TEST_BOOLIFICATION(InvalidInput, true);
TEST_BOOLIFICATION(EmptyInput, true);
TEST_BOOLIFICATION(IncompleteInput, true);
TEST_BOOLIFICATION(InvalidInput, true);
TEST_BOOLIFICATION(NoMemory, true);
TEST_BOOLIFICATION(NotSupported, true);
TEST_BOOLIFICATION(TooDeep, true);
}
SECTION("ostream DeserializationError") {
@ -58,13 +60,6 @@ TEST_CASE("DeserializationError") {
REQUIRE(s.str() == "InvalidInput");
}
SECTION("out of range") {
int code = 666;
DeserializationError err(
*reinterpret_cast<DeserializationError::Code*>(&code));
REQUIRE(err.c_str() == std::string("???"));
}
SECTION("switch") {
DeserializationError err = DeserializationError::InvalidInput;
switch (err.code()) {

View File

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

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
@ -56,7 +56,7 @@ TEST_CASE("deserialize JSON array with a StaticJsonDocument") {
deserializeJson(doc, " [ \"1234567\" ] ");
REQUIRE(JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(8) == doc.memoryUsage());
REQUIRE(JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(7) == doc.memoryUsage());
// note: we use a string of 8 bytes to be sure that the StaticMemoryPool
// will not insert bytes to enforce alignement
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#define ARDUINOJSON_ENABLE_COMMENTS 1
@ -62,6 +62,15 @@ TEST_CASE("Filtering") {
"null",
0
},
{
// Member is a string, but filter wants an array
"{\"example\":\"example\"}",
"{\"example\":[true]}",
10,
DeserializationError::Ok,
"{\"example\":null}",
JSON_OBJECT_SIZE(1) + 8
},
{
// Input is an array, but filter wants an object
"[\"hello\",\"world\"]",
@ -214,6 +223,15 @@ TEST_CASE("Filtering") {
"{\"example\":{\"outcome\":42}}",
2 * JSON_OBJECT_SIZE(1) + 16
},
{
// wildcard
"{\"example\":{\"type\":\"int\",\"outcome\":42}}",
"{\"*\":{\"outcome\":true}}",
10,
DeserializationError::Ok,
"{\"example\":{\"outcome\":42}}",
2 * JSON_OBJECT_SIZE(1) + 16
},
{
// only the first element of array counts
"[1,2,3]",
@ -239,7 +257,7 @@ TEST_CASE("Filtering") {
10,
DeserializationError::Ok,
"[{\"example\":1},{\"example\":3}]",
JSON_ARRAY_SIZE(2) + 2 * JSON_OBJECT_SIZE(1) + 16
JSON_ARRAY_SIZE(2) + 2 * JSON_OBJECT_SIZE(1) + 8
},
{
"[',2,3]",
@ -525,7 +543,7 @@ TEST_CASE("Filtering") {
10,
DeserializationError::InvalidInput,
"{}",
JSON_OBJECT_SIZE(0) + 8
JSON_OBJECT_SIZE(0)
},
{
// incomplete comment after key
@ -534,7 +552,7 @@ TEST_CASE("Filtering") {
10,
DeserializationError::IncompleteInput,
"{}",
JSON_OBJECT_SIZE(0) + 8
JSON_OBJECT_SIZE(0)
},
{
// invalid comment after colon
@ -730,20 +748,3 @@ TEST_CASE("Overloads") {
}
#endif
}
TEST_CASE("StringMover::reclaim()") {
StaticJsonDocument<200> filter;
filter["a"] = true;
filter["c"] = true;
char input[] = "{\"a\":1,\"b\":2,\"c\":1}";
StaticJsonDocument<200> doc;
deserializeJson(doc, input, DeserializationOption::Filter(filter));
REQUIRE(doc.as<std::string>() == "{\"a\":1,\"c\":1}");
CHECK(input[0] == 'a');
CHECK(input[1] == 0);
CHECK(input[2] == 'c');
CHECK(input[3] == 0);
}

View File

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

View File

@ -1,13 +1,29 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
#include <sstream>
#include "CustomReader.hpp"
TEST_CASE("deserializeJson(char*)") {
StaticJsonDocument<1024> doc;
SECTION("should not duplicate strings") {
char input[] = "{\"hello\":\"world\"}";
DeserializationError err = deserializeJson(doc, input);
REQUIRE(err == DeserializationError::Ok);
CHECK(doc.memoryUsage() == JSON_OBJECT_SIZE(1));
CHECK(doc.as<JsonVariant>().memoryUsage() ==
JSON_OBJECT_SIZE(1)); // issue #1318
}
}
TEST_CASE("deserializeJson(const std::string&)") {
DynamicJsonDocument doc(4096);
@ -126,3 +142,57 @@ TEST_CASE("deserializeJson(CustomReader)") {
REQUIRE(doc[0] == 4);
REQUIRE(doc[1] == 2);
}
TEST_CASE("deserializeJson(JsonDocument&, MemberProxy)") {
DynamicJsonDocument doc1(4096);
doc1["payload"] = "[4,2]";
DynamicJsonDocument doc2(4096);
DeserializationError err = deserializeJson(doc2, doc1["payload"]);
REQUIRE(err == DeserializationError::Ok);
REQUIRE(doc2.size() == 2);
REQUIRE(doc2[0] == 4);
REQUIRE(doc2[1] == 2);
}
TEST_CASE("deserializeJson(JsonDocument&, JsonVariant)") {
DynamicJsonDocument doc1(4096);
doc1["payload"] = "[4,2]";
DynamicJsonDocument doc2(4096);
DeserializationError err =
deserializeJson(doc2, doc1["payload"].as<JsonVariant>());
REQUIRE(err == DeserializationError::Ok);
REQUIRE(doc2.size() == 2);
REQUIRE(doc2[0] == 4);
REQUIRE(doc2[1] == 2);
}
TEST_CASE("deserializeJson(JsonDocument&, JsonVariantConst)") {
DynamicJsonDocument doc1(4096);
doc1["payload"] = "[4,2]";
DynamicJsonDocument doc2(4096);
DeserializationError err =
deserializeJson(doc2, doc1["payload"].as<JsonVariantConst>());
REQUIRE(err == DeserializationError::Ok);
REQUIRE(doc2.size() == 2);
REQUIRE(doc2[0] == 4);
REQUIRE(doc2[1] == 2);
}
TEST_CASE("deserializeJson(JsonDocument&, ElementProxy)") {
DynamicJsonDocument doc1(4096);
doc1[0] = "[4,2]";
DynamicJsonDocument doc2(4096);
DeserializationError err = deserializeJson(doc2, doc1[0]);
REQUIRE(err == DeserializationError::Ok);
REQUIRE(doc2.size() == 2);
REQUIRE(doc2[0] == 4);
REQUIRE(doc2[1] == 2);
}

View File

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

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
@ -27,7 +27,13 @@ TEST_CASE("deserializeJson(DynamicJsonDocument&)") {
SECTION("Empty input") {
DeserializationError err = deserializeJson(doc, "");
REQUIRE(err == DeserializationError::IncompleteInput);
REQUIRE(err == DeserializationError::EmptyInput);
}
SECTION("Only spaces") {
DeserializationError err = deserializeJson(doc, " \t\n\r");
REQUIRE(err == DeserializationError::EmptyInput);
}
SECTION("issue #628") {

View File

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

View File

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

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
@ -290,4 +290,10 @@ TEST_CASE("deserialize JSON object") {
REQUIRE(obj.size() == 0);
REQUIRE(doc.memoryUsage() == JSON_OBJECT_SIZE(0));
}
SECTION("Issue #1335") {
std::string json("{\"a\":{},\"b\":{}}");
deserializeJson(doc, json);
CHECK(doc.as<std::string>() == json);
}
}

View File

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

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#define ARDUINOJSON_DECODE_UNICODE 1
@ -74,16 +74,16 @@ TEST_CASE("Invalid JSON string") {
}
}
TEST_CASE("Not enough room to duplicate the string") {
DynamicJsonDocument doc(JSON_OBJECT_SIZE(0));
TEST_CASE("Not enough room to save the key") {
DynamicJsonDocument doc(JSON_OBJECT_SIZE(1) + 8);
SECTION("Quoted string") {
REQUIRE(deserializeJson(doc, "{\"example\":1}") ==
REQUIRE(deserializeJson(doc, "{\"accuracy\":1}") ==
DeserializationError::NoMemory);
}
SECTION("Non-quoted string") {
REQUIRE(deserializeJson(doc, "{example:1}") ==
REQUIRE(deserializeJson(doc, "{accuracy:1}") ==
DeserializationError::NoMemory);
}
}

View File

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

View File

@ -1,5 +1,5 @@
# ArduinoJson - arduinojson.org
# Copyright Benoit Blanchon 2014-2020
# Copyright Benoit Blanchon 2014-2021
# MIT License
add_executable(JsonDocumentTests
@ -9,8 +9,11 @@ add_executable(JsonDocumentTests
containsKey.cpp
createNested.cpp
DynamicJsonDocument.cpp
ElementProxy.cpp
isNull.cpp
MemberProxy.cpp
nesting.cpp
overflowed.cpp
remove.cpp
shrinkToFit.cpp
size.cpp
@ -18,9 +21,4 @@ add_executable(JsonDocumentTests
subscript.cpp
)
target_link_libraries(JsonDocumentTests
ArduinoJson
catch
)
add_test(JsonDocument JsonDocumentTests)

View File

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

View File

@ -0,0 +1,206 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
TEST_CASE("ElementProxy::add()") {
DynamicJsonDocument doc(4096);
doc.addElement();
ElementProxy<JsonDocument&> ep = doc[0];
SECTION("add(int)") {
ep.add(42);
REQUIRE(doc.as<std::string>() == "[[42]]");
}
SECTION("add(const char*)") {
ep.add("world");
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
}
SECTION("set(char[])") {
char s[] = "world";
ep.add(s);
strcpy(s, "!!!!!");
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
}
}
TEST_CASE("ElementProxy::clear()") {
DynamicJsonDocument doc(4096);
doc.addElement();
ElementProxy<JsonDocument&> ep = doc[0];
SECTION("size goes back to zero") {
ep.add(42);
ep.clear();
REQUIRE(ep.size() == 0);
}
SECTION("isNull() return true") {
ep.add("hello");
ep.clear();
REQUIRE(ep.isNull() == true);
}
}
TEST_CASE("ElementProxy::operator==()") {
DynamicJsonDocument doc(4096);
SECTION("1 vs 1") {
doc.add(1);
doc.add(1);
REQUIRE(doc[0] <= doc[1]);
REQUIRE(doc[0] == doc[1]);
REQUIRE(doc[0] >= doc[1]);
REQUIRE_FALSE(doc[0] != doc[1]);
REQUIRE_FALSE(doc[0] < doc[1]);
REQUIRE_FALSE(doc[0] > doc[1]);
}
SECTION("1 vs 2") {
doc.add(1);
doc.add(2);
REQUIRE(doc[0] != doc[1]);
REQUIRE(doc[0] < doc[1]);
REQUIRE(doc[0] <= doc[1]);
REQUIRE_FALSE(doc[0] == doc[1]);
REQUIRE_FALSE(doc[0] > doc[1]);
REQUIRE_FALSE(doc[0] >= doc[1]);
}
SECTION("'abc' vs 'bcd'") {
doc.add("abc");
doc.add("bcd");
REQUIRE(doc[0] != doc[1]);
REQUIRE(doc[0] < doc[1]);
REQUIRE(doc[0] <= doc[1]);
REQUIRE_FALSE(doc[0] == doc[1]);
REQUIRE_FALSE(doc[0] > doc[1]);
REQUIRE_FALSE(doc[0] >= doc[1]);
}
}
TEST_CASE("ElementProxy::remove()") {
DynamicJsonDocument doc(4096);
doc.addElement();
ElementProxy<JsonDocument&> ep = doc[0];
SECTION("remove(int)") {
ep.add(1);
ep.add(2);
ep.add(3);
ep.remove(1);
REQUIRE(ep.as<std::string>() == "[1,3]");
}
SECTION("remove(const char *)") {
ep["a"] = 1;
ep["b"] = 2;
ep.remove("a");
REQUIRE(ep.as<std::string>() == "{\"b\":2}");
}
SECTION("remove(std::string)") {
ep["a"] = 1;
ep["b"] = 2;
ep.remove(std::string("b"));
REQUIRE(ep.as<std::string>() == "{\"a\":1}");
}
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("remove(vla)") {
ep["a"] = 1;
ep["b"] = 2;
int i = 4;
char vla[i];
strcpy(vla, "b");
ep.remove(vla);
REQUIRE(ep.as<std::string>() == "{\"a\":1}");
}
#endif
}
TEST_CASE("ElementProxy::set()") {
DynamicJsonDocument doc(4096);
ElementProxy<JsonDocument&> ep = doc[0];
SECTION("set(int)") {
ep.set(42);
REQUIRE(doc.as<std::string>() == "[42]");
}
SECTION("set(const char*)") {
ep.set("world");
REQUIRE(doc.as<std::string>() == "[\"world\"]");
}
SECTION("set(char[])") {
char s[] = "world";
ep.set(s);
strcpy(s, "!!!!!");
REQUIRE(doc.as<std::string>() == "[\"world\"]");
}
}
TEST_CASE("ElementProxy::size()") {
DynamicJsonDocument doc(4096);
doc.addElement();
ElementProxy<JsonDocument&> ep = doc[0];
SECTION("returns 0") {
REQUIRE(ep.size() == 0);
}
SECTION("as an array, returns 2") {
ep.add(1);
ep.add(2);
REQUIRE(ep.size() == 2);
}
SECTION("as an object, returns 2") {
ep["a"] = 1;
ep["b"] = 2;
REQUIRE(ep.size() == 2);
}
}
TEST_CASE("ElementProxy::operator[]") {
DynamicJsonDocument doc(4096);
ElementProxy<JsonDocument&> ep = doc[1];
SECTION("set member") {
ep["world"] = 42;
REQUIRE(doc.as<std::string>() == "[null,{\"world\":42}]");
}
SECTION("set element") {
ep[2] = 42;
REQUIRE(doc.as<std::string>() == "[null,[null,null,42]]");
}
}

View File

@ -0,0 +1,247 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace ARDUINOJSON_NAMESPACE;
TEST_CASE("MemberProxy::add()") {
DynamicJsonDocument doc(4096);
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
SECTION("add(int)") {
mp.add(42);
REQUIRE(doc.as<std::string>() == "{\"hello\":[42]}");
}
SECTION("add(const char*)") {
mp.add("world");
REQUIRE(doc.as<std::string>() == "{\"hello\":[\"world\"]}");
}
}
TEST_CASE("MemberProxy::clear()") {
DynamicJsonDocument doc(4096);
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
SECTION("size goes back to zero") {
mp.add(42);
mp.clear();
REQUIRE(mp.size() == 0);
}
SECTION("isNull() return true") {
mp.add("hello");
mp.clear();
REQUIRE(mp.isNull() == true);
}
}
TEST_CASE("MemberProxy::operator==()") {
DynamicJsonDocument doc(4096);
SECTION("1 vs 1") {
doc["a"] = 1;
doc["b"] = 1;
REQUIRE(doc["a"] <= doc["b"]);
REQUIRE(doc["a"] == doc["b"]);
REQUIRE(doc["a"] >= doc["b"]);
REQUIRE_FALSE(doc["a"] != doc["b"]);
REQUIRE_FALSE(doc["a"] < doc["b"]);
REQUIRE_FALSE(doc["a"] > doc["b"]);
}
SECTION("1 vs 2") {
doc["a"] = 1;
doc["b"] = 2;
REQUIRE(doc["a"] != doc["b"]);
REQUIRE(doc["a"] < doc["b"]);
REQUIRE(doc["a"] <= doc["b"]);
REQUIRE_FALSE(doc["a"] == doc["b"]);
REQUIRE_FALSE(doc["a"] > doc["b"]);
REQUIRE_FALSE(doc["a"] >= doc["b"]);
}
SECTION("'abc' vs 'bcd'") {
doc["a"] = "abc";
doc["b"] = "bcd";
REQUIRE(doc["a"] != doc["b"]);
REQUIRE(doc["a"] < doc["b"]);
REQUIRE(doc["a"] <= doc["b"]);
REQUIRE_FALSE(doc["a"] == doc["b"]);
REQUIRE_FALSE(doc["a"] > doc["b"]);
REQUIRE_FALSE(doc["a"] >= doc["b"]);
}
}
TEST_CASE("MemberProxy::containsKey()") {
DynamicJsonDocument doc(4096);
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
SECTION("containsKey(const char*)") {
mp["key"] = "value";
REQUIRE(mp.containsKey("key") == true);
REQUIRE(mp.containsKey("key") == true);
}
SECTION("containsKey(std::string)") {
mp["key"] = "value";
REQUIRE(mp.containsKey(std::string("key")) == true);
REQUIRE(mp.containsKey(std::string("key")) == true);
}
}
TEST_CASE("MemberProxy::operator|()") {
DynamicJsonDocument doc(4096);
SECTION("const char*") {
doc["a"] = "hello";
REQUIRE((doc["a"] | "world") == std::string("hello"));
REQUIRE((doc["b"] | "world") == std::string("world"));
}
SECTION("Issue #1411") {
doc["sensor"] = "gps";
const char *test = "test"; // <- the literal must be captured in a variable
// to trigger the bug
const char *sensor = doc["sensor"] | test; // "gps"
REQUIRE(sensor == std::string("gps"));
}
SECTION("Issue #1415") {
JsonObject object = doc.to<JsonObject>();
object["hello"] = "world";
StaticJsonDocument<0> emptyDoc;
JsonObject anotherObject = object["hello"] | emptyDoc.to<JsonObject>();
REQUIRE(anotherObject.isNull() == false);
REQUIRE(anotherObject.size() == 0);
}
}
TEST_CASE("MemberProxy::remove()") {
DynamicJsonDocument doc(4096);
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
SECTION("remove(int)") {
mp.add(1);
mp.add(2);
mp.add(3);
mp.remove(1);
REQUIRE(mp.as<std::string>() == "[1,3]");
}
SECTION("remove(const char *)") {
mp["a"] = 1;
mp["b"] = 2;
mp.remove("a");
REQUIRE(mp.as<std::string>() == "{\"b\":2}");
}
SECTION("remove(std::string)") {
mp["a"] = 1;
mp["b"] = 2;
mp.remove(std::string("b"));
REQUIRE(mp.as<std::string>() == "{\"a\":1}");
}
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("remove(vla)") {
mp["a"] = 1;
mp["b"] = 2;
int i = 4;
char vla[i];
strcpy(vla, "b");
mp.remove(vla);
REQUIRE(mp.as<std::string>() == "{\"a\":1}");
}
#endif
}
TEST_CASE("MemberProxy::set()") {
DynamicJsonDocument doc(4096);
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
SECTION("set(int)") {
mp.set(42);
REQUIRE(doc.as<std::string>() == "{\"hello\":42}");
}
SECTION("set(const char*)") {
mp.set("world");
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
}
SECTION("set(char[])") { // issue #1191
char s[] = "world";
mp.set(s);
strcpy(s, "!!!!!");
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
}
}
TEST_CASE("MemberProxy::size()") {
DynamicJsonDocument doc(4096);
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
SECTION("returns 0") {
REQUIRE(mp.size() == 0);
}
SECTION("as an array, return 2") {
mp.add(1);
mp.add(2);
REQUIRE(mp.size() == 2);
}
SECTION("as an object, return 2") {
mp["a"] = 1;
mp["b"] = 2;
REQUIRE(mp.size() == 2);
}
}
TEST_CASE("MemberProxy::operator[]") {
DynamicJsonDocument doc(4096);
MemberProxy<JsonDocument &, const char *> mp = doc["hello"];
SECTION("set member") {
mp["world"] = 42;
REQUIRE(doc.as<std::string>() == "{\"hello\":{\"world\":42}}");
}
SECTION("set element") {
mp[2] = 42;
REQUIRE(doc.as<std::string>() == "{\"hello\":[null,null,42]}");
}
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - arduinojson.org
// Copyright Benoit Blanchon 2014-2020
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
@ -212,7 +212,7 @@ TEST_CASE("StaticJsonDocument") {
SECTION("garbageCollect()") {
StaticJsonDocument<256> doc;
doc[std::string("example")] = std::string("example");
doc[std::string("example")] = std::string("jukebox");
doc.remove("example");
REQUIRE(doc.memoryUsage() == JSON_OBJECT_SIZE(1) + 16);

Some files were not shown because too many files have changed in this diff Show More