diff --git a/.clang-format b/.clang-format index 25f529f5c..0853a7826 100644 --- a/.clang-format +++ b/.clang-format @@ -1,10 +1,12 @@ # http://clang.llvm.org/docs/ClangFormatStyleOptions.html BasedOnStyle: Google -Standard: Cpp03 +Standard: c++11 AllowShortFunctionsOnASingleLine: Empty IncludeBlocks: Preserve IndentPPDirectives: AfterHash +DerivePointerAlignment: false # Always break after if to get accurate coverage AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false diff --git a/.devcontainer/clang10/devcontainer.json b/.devcontainer/clang10/devcontainer.json new file mode 100644 index 000000000..7fa61307a --- /dev/null +++ b/.devcontainer/clang10/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "Clang 10", + "image": "conanio/clang10", + "runArgs": [ + "--name=ArduinoJson-clang10" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/clang5/devcontainer.json b/.devcontainer/clang5/devcontainer.json new file mode 100644 index 000000000..8844d1391 --- /dev/null +++ b/.devcontainer/clang5/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "Clang 5", + "image": "conanio/clang50", + "runArgs": [ + "--name=ArduinoJson-clang5" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/clang6/devcontainer.json b/.devcontainer/clang6/devcontainer.json new file mode 100644 index 000000000..e4a35f4f3 --- /dev/null +++ b/.devcontainer/clang6/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "Clang 6", + "image": "conanio/clang60", + "runArgs": [ + "--name=ArduinoJson-clang6" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/clang7/devcontainer.json b/.devcontainer/clang7/devcontainer.json new file mode 100644 index 000000000..1a8b55803 --- /dev/null +++ b/.devcontainer/clang7/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "Clang 7", + "image": "conanio/clang7", + "runArgs": [ + "--name=ArduinoJson-clang7" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/clang8/devcontainer.json b/.devcontainer/clang8/devcontainer.json new file mode 100644 index 000000000..7be768088 --- /dev/null +++ b/.devcontainer/clang8/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "Clang 8", + "image": "conanio/clang8", + "runArgs": [ + "--name=ArduinoJson-clang8" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/clang9/devcontainer.json b/.devcontainer/clang9/devcontainer.json new file mode 100644 index 000000000..46f07fc39 --- /dev/null +++ b/.devcontainer/clang9/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "Clang 9", + "image": "conanio/clang9", + "runArgs": [ + "--name=ArduinoJson-clang9" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/gcc10/devcontainer.json b/.devcontainer/gcc10/devcontainer.json new file mode 100644 index 000000000..d6dfba059 --- /dev/null +++ b/.devcontainer/gcc10/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "GCC 10", + "image": "conanio/gcc10", + "runArgs": [ + "--name=ArduinoJson-gcc10" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/gcc11/devcontainer.json b/.devcontainer/gcc11/devcontainer.json new file mode 100644 index 000000000..1edc308f7 --- /dev/null +++ b/.devcontainer/gcc11/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "GCC 11", + "image": "conanio/gcc11", + "runArgs": [ + "--name=ArduinoJson-gcc11" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/gcc5/devcontainer.json b/.devcontainer/gcc5/devcontainer.json new file mode 100644 index 000000000..20ce7c11d --- /dev/null +++ b/.devcontainer/gcc5/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "GCC 5", + "image": "conanio/gcc5", + "runArgs": [ + "--name=ArduinoJson-gcc5" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/gcc6/devcontainer.json b/.devcontainer/gcc6/devcontainer.json new file mode 100644 index 000000000..35fb5fa25 --- /dev/null +++ b/.devcontainer/gcc6/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "GCC 6", + "image": "conanio/gcc6", + "runArgs": [ + "--name=ArduinoJson-gcc6" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/gcc7/devcontainer.json b/.devcontainer/gcc7/devcontainer.json new file mode 100644 index 000000000..28bab2082 --- /dev/null +++ b/.devcontainer/gcc7/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "GCC 7", + "image": "conanio/gcc7", + "runArgs": [ + "--name=ArduinoJson-gcc7" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/gcc8/devcontainer.json b/.devcontainer/gcc8/devcontainer.json new file mode 100644 index 000000000..622d47219 --- /dev/null +++ b/.devcontainer/gcc8/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "GCC 8", + "image": "conanio/gcc8", + "runArgs": [ + "--name=ArduinoJson-gcc8" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.devcontainer/gcc9/devcontainer.json b/.devcontainer/gcc9/devcontainer.json new file mode 100644 index 000000000..f946d9fb8 --- /dev/null +++ b/.devcontainer/gcc9/devcontainer.json @@ -0,0 +1,18 @@ +{ + "name": "GCC 9", + "image": "conanio/gcc9", + "runArgs": [ + "--name=ArduinoJson-gcc9" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cmake-tools" + ], + "settings": { + "cmake.generator": "Unix Makefiles", + "cmake.buildDirectory": "/tmp/build" + } + } + } +} diff --git a/.gitattributes b/.gitattributes index 526c8a38d..efdba8764 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -*.sh text eol=lf \ No newline at end of file +* text=auto +*.sh text eol=lf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e03ec11cd..b9ce7d311 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,32 +5,34 @@ on: [push, pull_request] jobs: lint: name: Lint - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Install run: sudo apt-get install -y clang-format - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Symlinks run: find * -type l -printf "::error::%p is a symlink. This is forbidden by the Arduino Library Specification." -exec false {} + - name: Clang-format run: | find src/ extras/ -name '*.[ch]pp' | xargs clang-format -i --verbose --style=file git diff --exit-code + - name: Check URLs + run: | + grep -hREo "(http|https)://[a-zA-Z0-9./?=_%:-]*" src/ | sort -u | while read -r URL + do + STATUS=$(curl -s -o /dev/null -I -w "%{http_code}" "$URL") + [ "$STATUS" -ge 400 ] && echo "::warning title=HTTP $STATUS::$URL returned $STATUS" + done || true gcc: name: GCC needs: lint - runs-on: ubuntu-latest + runs-on: ubuntu-22.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" @@ -45,13 +47,13 @@ jobs: steps: - name: Install run: | - sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty main universe' - sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial main universe' + sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 3B4FE6ACC0B21F32 sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main universe' + sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ focal main universe' sudo apt-get update sudo apt-get install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }} - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Configure run: cmake -DCMAKE_BUILD_TYPE=Debug . env: @@ -61,7 +63,11 @@ jobs: - name: Build run: cmake --build . - name: Test - run: ctest --output-on-failure -C Debug . + run: | + echo "## CTest output" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + ctest --output-on-failure -C Debug . | tee -a $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY env: UBSAN_OPTIONS: print_stacktrace=1 @@ -73,12 +79,6 @@ jobs: fail-fast: false matrix: include: - - clang: "3.5" - cxxflags: "-stdlib=libc++" - - clang: "3.6" - cxxflags: "-stdlib=libc++" - - clang: "3.7" - cxxflags: "-stdlib=libc++" - clang: "3.8" cxxflags: "-stdlib=libc++" - clang: "3.9" @@ -97,8 +97,6 @@ jobs: 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' @@ -106,7 +104,7 @@ jobs: sudo apt-get update sudo apt-get install -y clang-${{ matrix.clang }} - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Configure run: cmake -DCMAKE_BUILD_TYPE=Debug . env: @@ -118,7 +116,11 @@ jobs: - name: Build run: cmake --build . - name: Test - run: ctest --output-on-failure -C Debug . + run: | + echo "## CTest output" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + ctest --output-on-failure -C Debug . | tee -a $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY env: UBSAN_OPTIONS: print_stacktrace=1 @@ -130,9 +132,11 @@ jobs: - name: Install run: | sudo apt-get update - sudo apt-get install -y g++-multilib + sudo apt-get install -y g++-multilib gcc-avr avr-libc - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 + - name: AVR + run: avr-g++ -std=c++11 -Isrc extras/conf_test/avr.cpp - name: GCC 32-bit run: g++ -std=c++11 -m32 -Isrc extras/conf_test/x86.cpp - name: GCC 64-bit @@ -148,7 +152,7 @@ jobs: needs: [gcc, clang] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: 32-bit run: | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars32.bat" @@ -163,17 +167,17 @@ jobs: xcode: name: XCode needs: clang - runs-on: macos-10.15 + runs-on: macos-11 strategy: fail-fast: false matrix: include: - - xcode: "10.3" - xcode: "11.7" - xcode: "12.4" + - xcode: "13.2.1" steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Select XCode version run: sudo xcode-select --switch /Applications/Xcode_${{ matrix.xcode }}.app - name: Configure @@ -195,7 +199,7 @@ jobs: # runs-on: ${{ matrix.os }} # steps: # - name: Checkout - # uses: actions/checkout@v2 + # uses: actions/checkout@v3 # - name: Configure # run: cmake -DCMAKE_BUILD_TYPE=Debug . # - name: Build @@ -217,9 +221,9 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install arduino-cli - run: brew update && brew install arduino-cli + run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh - name: Install core run: arduino-cli core install ${{ matrix.core }} - name: Install libraries @@ -290,14 +294,14 @@ jobs: conf_test: esp8266 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up cache for pip - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.cache/pip key: ${{ runner.os }}-pip - name: Set up Python 3.x - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: "3.x" - name: Install PlatformIO @@ -309,7 +313,7 @@ jobs: if: ${{ matrix.platform == 'nordicnrf52' }} run: find examples/ -name '*.ino' -exec sed -i 's/\(#include \)/\1\n#include /' {} + - name: Set up cache for platformio - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.platformio key: ${{ runner.os }}-platformio-${{ matrix.platform }} @@ -358,7 +362,7 @@ jobs: - board: argon steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install Particle CLI run: sudo npm install -g particle-cli - name: Login to Particle @@ -376,7 +380,7 @@ jobs: sudo apt-get update sudo apt-get install -y g++-arm-linux-gnueabihf - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Configure run: cmake . env: @@ -393,7 +397,7 @@ jobs: - name: Install run: sudo apt-get install -y lcov ninja-build - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Configure run: cmake -G Ninja -DCOVERAGE=true . - name: Build @@ -407,7 +411,7 @@ jobs: - name: genhtml run: mkdir coverage && genhtml coverage_filtered.info -o coverage -t ArduinoJson - name: Upload HTML report - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: Coverage report path: coverage @@ -427,7 +431,7 @@ jobs: sudo apt-get update sudo apt-get install -y valgrind ninja-build - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Configure run: cmake -G Ninja -D MEMORYCHECK_COMMAND_OPTIONS="--error-exitcode=1 --leak-check=full" . - name: Build @@ -447,7 +451,7 @@ jobs: - name: Install run: sudo apt-get install -y clang-tidy cmake ninja-build - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Configure run: cmake -G Ninja -DCMAKE_CXX_CLANG_TIDY="clang-tidy-10;--warnings-as-errors=*" -DCMAKE_BUILD_TYPE=Debug . env: @@ -462,7 +466,7 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Amalgamate id: amalgamate run: | @@ -474,7 +478,7 @@ jobs: INPUT=src/ArduinoJson.h OUTPUT=ArduinoJson-$VERSION.h extras/scripts/build-single-header.sh "$INPUT" "$OUTPUT" - echo ::set-output name=filename::${OUTPUT} + echo "filename=${OUTPUT}" >> $GITHUB_OUTPUT - name: Smoke test run: | g++ -x c++ - <> $GITHUB_OUTPUT - name: Smoke test run: | g++ -x c++ - <> $GITHUB_OUTPUT + echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Write release body id: body run: | FILENAME=RELEASE.md extras/scripts/get-release-body.sh ${{ steps.init.outputs.tag }} CHANGELOG.md | tee $FILENAME - echo ::set-output name=filename::$FILENAME + echo "filename=$FILENAME" >> $GITHUB_OUTPUT - name: Amalgamate ArduinoJson.h id: amalgamate_h run: | FILENAME=ArduinoJson-${{ steps.init.outputs.tag }}.h extras/scripts/build-single-header.sh src/ArduinoJson.h "$FILENAME" - echo ::set-output name=filename::$FILENAME + echo "filename=$FILENAME" >> $GITHUB_OUTPUT - name: Amalgamate ArduinoJson.hpp id: amalgamate_hpp run: | FILENAME=ArduinoJson-${{ steps.init.outputs.tag }}.hpp extras/scripts/build-single-header.sh src/ArduinoJson.hpp "$FILENAME" - echo ::set-output name=filename::$FILENAME + echo "filename=$FILENAME" >> $GITHUB_OUTPUT - name: Create Arduino package id: arduino run: | FILENAME=ArduinoJson-${{ steps.init.outputs.tag }}.zip extras/scripts/build-arduino-package.sh . "$FILENAME" - echo ::set-output name=filename::$FILENAME + echo "filename=$FILENAME" >> $GITHUB_OUTPUT - name: Create release uses: ncipollo/release-action@v1 with: bodyFile: ${{ steps.body.outputs.filename }} - draft: true name: ArduinoJson ${{ steps.init.outputs.version }} artifacts: ${{ steps.amalgamate_h.outputs.filename }},${{ steps.amalgamate_hpp.outputs.filename }},${{ steps.arduino.outputs.filename }} token: ${{ secrets.GITHUB_TOKEN }} + + idf: + name: IDF Component Registry + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Upload component to the component registry + uses: espressif/upload-components-ci-action@v1 + with: + name: ArduinoJson + namespace: bblanchon + api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} + + particle: + name: Particle + runs-on: ubuntu-latest + steps: + - name: Install + run: npm install -g particle-cli + - name: Checkout + uses: actions/checkout@v3 + - name: Login + run: particle login --token ${{ secrets.PARTICLE_TOKEN }} + timeout-minutes: 1 + - name: Publish + run: bash -eux extras/scripts/publish-particle-library.sh + timeout-minutes: 5 + + platformio: + name: PlatformIO + runs-on: ubuntu-latest + steps: + - name: Set up Python 3.x + uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install PlatformIO + run: pip install platformio + - name: Checkout + uses: actions/checkout@v3 + - name: Publish + run: pio pkg publish --no-interactive --no-notify + env: + PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }} diff --git a/.gitignore b/.gitignore index 2a5bc3001..b2b9c95c0 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ # Used by CI for Particle /src/*.ino /project.properties + +# Used by IDF +/dist/ diff --git a/.mbedignore b/.mbedignore index 9a8a814f5..c5da30d91 100644 --- a/.mbedignore +++ b/.mbedignore @@ -1,3 +1,4 @@ +.devcontainer/ .github/ examples/ -extras/ \ No newline at end of file +extras/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 28bb4eaaa..350c40014 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,22 +1,17 @@ { "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", - "cmake.generator": "Ninja", "git.inputValidationLength": 80, "git.inputValidationSubjectLength": 72, "files.insertFinalNewline": true, "files.trimFinalNewlines": true, - "files.associations": { - "fstream": "cpp", - "iomanip": "cpp", - "string": "cpp", - "system_error": "cpp", - "vector": "cpp", - "xlocmon": "cpp", - "xlocnum": "cpp", - "xloctime": "cpp", - "xstring": "cpp" - }, "search.exclude": { "/extras/tests/catch/*": true + }, + "C_Cpp.default.includePath": [ + "/src" + ], + "[cmake]": { + "editor.detectIndentation": false, + "editor.insertSpaces": false, } } diff --git a/ArduinoJson.h b/ArduinoJson.h index 7e3afa58a..15c218f48 100644 --- a/ArduinoJson.h +++ b/ArduinoJson.h @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include "src/ArduinoJson.h" diff --git a/CHANGELOG.md b/CHANGELOG.md index fe78ab06f..8366b8f2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,74 @@ ArduinoJson: change log HEAD ---- +* Improve error messages when using `char` or `char*` (issue #2043) +* Make string support even more generic (PR #2084 by @d-a-v) + +v6.21.5 (2024-01-10) +------- + +* Fix warning `function returns incomplete class type` on IAR (issue #2001) +* Fix `volatile bool` serialized as `1` or `0` instead of `true` or `false` (issue #2029) +* Remove unused files in the PlatformIO package + +v6.21.4 (2023-12-07) +------- + +* Fix error `'std::string' has not been declared` (issue #1967) +* Fix error `'std::string_view' has not been declared` (issue #1967) +* Fix error `no instance of overloaded function...` on recent IAR compilers (issue #2001) + +v6.21.3 (2023-07-23) +------- + +* Fix compatibility with the Blynk libary (issue #1914) +* Fix double lookup in `to()` +* Fix double call to `size()` in `serializeMsgPack()` +* Include `ARDUINOJSON_SLOT_OFFSET_SIZE` in the namespace name +* Show a link to the documentation when user passes an unsupported input type + +v6.21.2 (2023-04-12) +------- + +* Fix compatibility with the Zephyr Project (issue #1905) +* Allow using PROGMEM outside of Arduino (issue #1903) +* Set default for `ARDUINOJSON_ENABLE_PROGMEM` to `1` on AVR + +v6.21.1 (2023-03-27) +------- + +* Double speed of `DynamicJsonDocument::garbageCollect()` +* Fix compatibility with GCC 5.2 (issue #1897) + +v6.21.0 (2023-03-14) +------- + +* Drop support for C++98/C++03. Minimum required is C++11. +* Remove `ARDUINOJSON_NAMESPACE`; use `ArduinoJson` instead. +* Make string support generic (issue #1807) + +v6.20.1 (2023-02-08) +------- + +* Remove explicit exclusion of `as()` and `as()` (issue #1860) + If you try to call them, you'll now get the same error message as any unsupported type. + You could also add a custom converter for `char*` and `char`. + +v6.20.0 (2022-12-26) +------- + * Add `JsonVariant::shallowCopy()` (issue #1343) * Fix `9.22337e+18 is outside the range of representable values of type 'long'` * Fix comparison operators for `JsonArray`, `JsonArrayConst`, `JsonObject`, and `JsonObjectConst` +* Fix lax parsing of `true`, `false`, and `null` (issue #1781) * Remove undocumented `accept()` functions * Rename `addElement()` to `add()` * Remove `getElement()`, `getOrAddElement()`, `getMember()`, and `getOrAddMember()` +* Remove undocumented `JsonDocument::data()` and `JsonDocument::memoryPool()` +* Remove undocumented `JsonArrayIterator::internal()` and `JsonObjectIterator::internal()` +* Rename things in `ARDUINOJSON_NAMESPACE` to match the public names +* Add documentation to most public symbols +* Remove support for naked `char` (was deprecated since 6.18.0) > ### BREAKING CHANGES > @@ -25,9 +87,9 @@ HEAD > > // after > JsonVariant a = variant[idx]; -> JsonVariant b = variant[idx].to(); +> JsonVariant b = idx < variant.size() ? variant[idx] : variant[idx].to(); > JsonVariant c = variant[key]; -> JsonVariant d = variant[key].to(); +> JsonVariant d = variant.containsKey(key) ? variant[key] : variant[key].to(); > ``` v6.19.4 (2022-04-05) diff --git a/CMakeLists.txt b/CMakeLists.txt index f809a5893..71b3d5358 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,19 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License cmake_minimum_required(VERSION 3.15) if(ESP_PLATFORM) - # Build ArduinoJson as an ESP-IDF component - idf_component_register(INCLUDE_DIRS src) - return() + # Build ArduinoJson as an ESP-IDF component + idf_component_register(INCLUDE_DIRS src) + return() endif() -project(ArduinoJson VERSION 6.19.4) +project(ArduinoJson VERSION 6.21.5) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) - include(CTest) + include(CTest) endif() add_subdirectory(src) diff --git a/LICENSE.md b/LICENSE.txt similarity index 95% rename from LICENSE.md rename to LICENSE.txt index dee0b5ba4..15f1b9fbb 100644 --- a/LICENSE.md +++ b/LICENSE.txt @@ -1,10 +1,10 @@ -The MIT License (MIT) ---------------------- - -Copyright © 2014-2022, 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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +The MIT License (MIT) +--------------------- + +Copyright © 2014-2023, 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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index d4f09085a..96879e01e 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,18 @@ -![ArduinoJson](banner.svg) +

+ ArduinoJson +

--- -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/bblanchon/ArduinoJson/Continuous%20Integration?logo=github)](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x) +[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bblanchon/ArduinoJson/ci.yml?branch=6.x&logo=github)](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) -[![LGTM Grade](https://img.shields.io/lgtm/grade/cpp/github/bblanchon/ArduinoJson?label=quality&logo=lgtm)](https://lgtm.com/projects/g/bblanchon/ArduinoJson/) [![Coveralls branch](https://img.shields.io/coveralls/github/bblanchon/ArduinoJson/6.x?logo=coveralls)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) -[![Arduino Library Manager](https://img.shields.io/static/v1?label=Arduino&message=v6.19.4&logo=arduino&logoColor=white&color=blue)](https://www.ardu-badge.com/ArduinoJson/6.19.4) -[![PlatformIO Registry](https://badges.registry.platformio.org/packages/bblanchon/library/ArduinoJson.svg?version=6.19.4)](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.19.4) -[![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat&logo=github)](https://github.com/bblanchon/ArduinoJson/stargazers) -[![GitHub Sponsors](https://img.shields.io/github/sponsors/bblanchon?logo=github)](https://github.com/sponsors/bblanchon) +[![Arduino Library Manager](https://img.shields.io/static/v1?label=Arduino&message=v6.21.5&logo=arduino&logoColor=white&color=blue)](https://www.ardu-badge.com/ArduinoJson/6.21.5) +[![PlatformIO Registry](https://badges.registry.platformio.org/packages/bblanchon/library/ArduinoJson.svg?version=6.21.5)](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.5) +[![ESP IDF](https://img.shields.io/static/v1?label=ESP+IDF&message=v6.21.5&logo=cpu&logoColor=white&color=blue)](https://components.espressif.com/components/bblanchon/arduinojson) +[![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat&logo=github&color=orange)](https://github.com/bblanchon/ArduinoJson/stargazers) +[![GitHub Sponsors](https://img.shields.io/github/sponsors/bblanchon?logo=github&color=orange)](https://github.com/sponsors/bblanchon) ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). @@ -44,7 +46,8 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). * Supports [custom converters](https://arduinojson.org/news/2021/05/04/version-6-18-0/) * Portable * Usable on any C++ project (not limited to Arduino) - * Compatible with C++98, C++11, C++14 and C++17 + * Compatible with C++11, C++14 and C++17 + * Support for C++98/C++03 available on [ArduinoJson 6.20.x](https://github.com/bblanchon/ArduinoJson/tree/6.20.x) * Zero warnings with `-Wall -Wextra -pedantic` and `/W4` * [Header-only library](https://en.wikipedia.org/wiki/Header-only) * Works with virtually any board @@ -81,9 +84,9 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). * 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, 2022](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, 9, 10, 11](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) + * [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) + * [GCC 5, 6, 7, 8, 9, 10, 11](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) + * [Clang 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) * Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/) * Well documented @@ -98,7 +101,6 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). * Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories) * [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) - * [Discord server](https://discord.gg/DzN6hHHD4h) ## Quickstart @@ -118,7 +120,7 @@ double latitude = doc["data"][0]; double longitude = doc["data"][1]; ``` -See the [tutorial on arduinojson.org](https://arduinojson.org/doc/decoding/) +See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/deserialization/) ### Serialization @@ -137,16 +139,13 @@ serializeJson(doc, Serial); // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} ``` -See the [tutorial on arduinojson.org](https://arduinojson.org/doc/encoding/) +See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/serialization/) ## Sponsors ArduinoJson is thankful to its sponsors. Please give them a visit; they deserve it!

- - Tech Explorations - Programming Electronics Academy diff --git a/appveyor.yml b/appveyor.yml index 6e3e458f1..8a6a332b5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 6.19.4.{build} +version: 6.21.5.{build} environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 @@ -7,15 +7,6 @@ environment: 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 - CMAKE_GENERATOR: Visual Studio 14 2015 - - CMAKE_GENERATOR: Visual Studio 12 2013 - - CMAKE_GENERATOR: Visual Studio 11 2012 - - CMAKE_GENERATOR: Visual Studio 10 2010 - - CMAKE_GENERATOR: Ninja - MINGW: MinGW # MinGW 32-bit 5.3.0 - - CMAKE_GENERATOR: Ninja - MINGW32: i686-5.3.0-posix-dwarf-rt_v4-rev0 # MinGW-w64 5.3.0 - CMAKE_GENERATOR: Ninja MINGW32: i686-6.3.0-posix-dwarf-rt_v5-rev1 # MinGW-w64 6.3.0 i686 - CMAKE_GENERATOR: Ninja diff --git a/banner.svg b/banner.svg deleted file mode 100644 index 517609625..000000000 --- a/banner.svg +++ /dev/null @@ -1,367 +0,0 @@ - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/JsonConfigFile/JsonConfigFile.ino b/examples/JsonConfigFile/JsonConfigFile.ino index 3443ba729..b2819d553 100644 --- a/examples/JsonConfigFile/JsonConfigFile.ino +++ b/examples/JsonConfigFile/JsonConfigFile.ino @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows how to store your project configuration in a file. diff --git a/examples/JsonFilterExample/JsonFilterExample.ino b/examples/JsonFilterExample/JsonFilterExample.ino index f50187a62..6937a00df 100644 --- a/examples/JsonFilterExample/JsonFilterExample.ino +++ b/examples/JsonFilterExample/JsonFilterExample.ino @@ -1,8 +1,8 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // -// This example shows how to use DeserializationOpion::Filter +// This example shows how to use DeserializationOption::Filter // // https://arduinojson.org/v6/example/filter/ @@ -14,7 +14,7 @@ void setup() { while (!Serial) continue; // The huge input: an extract from OpenWeatherMap response - const __FlashStringHelper* input_json = F( + auto input_json = F( "{\"cod\":\"200\",\"message\":0,\"list\":[{\"dt\":1581498000,\"main\":{" "\"temp\":3.23,\"feels_like\":-3.63,\"temp_min\":3.23,\"temp_max\":4.62," "\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1010,\"humidity\":" diff --git a/examples/JsonGeneratorExample/JsonGeneratorExample.ino b/examples/JsonGeneratorExample/JsonGeneratorExample.ino index ae1c0e25a..cf4ab0d94 100644 --- a/examples/JsonGeneratorExample/JsonGeneratorExample.ino +++ b/examples/JsonGeneratorExample/JsonGeneratorExample.ino @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows how to generate a JSON document with ArduinoJson. diff --git a/examples/JsonHttpClient/JsonHttpClient.ino b/examples/JsonHttpClient/JsonHttpClient.ino index 8e2e6d7ba..72f311fea 100644 --- a/examples/JsonHttpClient/JsonHttpClient.ino +++ b/examples/JsonHttpClient/JsonHttpClient.ino @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows how to parse a JSON document in an HTTP response. diff --git a/examples/JsonParserExample/JsonParserExample.ino b/examples/JsonParserExample/JsonParserExample.ino index 10f141994..a9d8b6d7b 100644 --- a/examples/JsonParserExample/JsonParserExample.ino +++ b/examples/JsonParserExample/JsonParserExample.ino @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows how to deserialize a JSON document with ArduinoJson. diff --git a/examples/JsonServer/JsonServer.ino b/examples/JsonServer/JsonServer.ino index 52d55c5bd..a897fce6d 100644 --- a/examples/JsonServer/JsonServer.ino +++ b/examples/JsonServer/JsonServer.ino @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows how to implement an HTTP server that sends a JSON document diff --git a/examples/JsonUdpBeacon/JsonUdpBeacon.ino b/examples/JsonUdpBeacon/JsonUdpBeacon.ino index 87965a3cc..6c369faa4 100644 --- a/examples/JsonUdpBeacon/JsonUdpBeacon.ino +++ b/examples/JsonUdpBeacon/JsonUdpBeacon.ino @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows how to send a JSON document to a UDP socket. diff --git a/examples/MsgPackParser/MsgPackParser.ino b/examples/MsgPackParser/MsgPackParser.ino index a14245b5d..1a54c3b3a 100644 --- a/examples/MsgPackParser/MsgPackParser.ino +++ b/examples/MsgPackParser/MsgPackParser.ino @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows how to deserialize a MessagePack document with diff --git a/examples/ProgmemExample/ProgmemExample.ino b/examples/ProgmemExample/ProgmemExample.ino index 1a13ea00b..68b8ec562 100644 --- a/examples/ProgmemExample/ProgmemExample.ino +++ b/examples/ProgmemExample/ProgmemExample.ino @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows the different ways you can use Flash strings with diff --git a/examples/StringExample/StringExample.ino b/examples/StringExample/StringExample.ino index 3d8f9e4ae..3e51b915b 100644 --- a/examples/StringExample/StringExample.ino +++ b/examples/StringExample/StringExample.ino @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows the different ways you can use String with ArduinoJson. diff --git a/extras/CompileOptions.cmake b/extras/CompileOptions.cmake index 82a750a12..0cbd576c2 100644 --- a/extras/CompileOptions.cmake +++ b/extras/CompileOptions.cmake @@ -27,11 +27,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") 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})) +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) @@ -65,7 +64,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) AND (NOT ${COVERAGE})) + if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) AND(NOT ${COVERAGE})) add_compile_options(-g -Og) else() add_compile_options(-g -O0) @@ -73,7 +72,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) AND (NOT ${COVERAGE})) + if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) AND(NOT ${COVERAGE})) add_compile_options(-g -Og) else() add_compile_options(-g -O0) @@ -85,17 +84,12 @@ if(MSVC) add_compile_options( /W4 # Set warning level /WX # Treats all compiler warnings as errors. + /Zc:__cplusplus # Enable updated __cplusplus macro ) - - if (NOT MSVC_VERSION LESS 1910) # >= Visual Studio 2017 - add_compile_options( - /Zc:__cplusplus # Enable updated __cplusplus macro - ) - endif() endif() if(MINGW) - # Static link on MinGW to avoid linking with the wrong DLLs when multiple + # Static link on MinGW to avoid linking with the wrong DLLs when multiple # versions are installed. add_link_options(-static) endif() diff --git a/extras/ci/espidf/CMakeLists.txt b/extras/ci/espidf/CMakeLists.txt index e3c4475a4..3b878969a 100644 --- a/extras/ci/espidf/CMakeLists.txt +++ b/extras/ci/espidf/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License cmake_minimum_required(VERSION 3.5) diff --git a/extras/ci/espidf/main/CMakeLists.txt b/extras/ci/espidf/main/CMakeLists.txt index f06bfda64..3e10ef8f8 100644 --- a/extras/ci/espidf/main/CMakeLists.txt +++ b/extras/ci/espidf/main/CMakeLists.txt @@ -1,6 +1,8 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License -idf_component_register(SRCS "main.cpp" - INCLUDE_DIRS "") +idf_component_register( + SRCS "main.cpp" + INCLUDE_DIRS "" +) diff --git a/extras/ci/espidf/main/main.cpp b/extras/ci/espidf/main/main.cpp index 50d7ec072..4818a6792 100644 --- a/extras/ci/espidf/main/main.cpp +++ b/extras/ci/espidf/main/main.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/conf_test/avr.cpp b/extras/conf_test/avr.cpp index cd0b4bdc4..b2b105e39 100644 --- a/extras/conf_test/avr.cpp +++ b/extras/conf_test/avr.cpp @@ -1,5 +1,7 @@ #include +static_assert(ARDUINOJSON_ENABLE_PROGMEM == 1, "ARDUINOJSON_ENABLE_PROGMEM"); + static_assert(ARDUINOJSON_USE_LONG_LONG == 0, "ARDUINOJSON_USE_LONG_LONG"); static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 1, @@ -9,7 +11,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN"); static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE"); -static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 8, +static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 8, "sizeof(VariantSlot)"); void setup() {} diff --git a/extras/conf_test/esp8266.cpp b/extras/conf_test/esp8266.cpp index bb9988bd7..caf70b2a3 100644 --- a/extras/conf_test/esp8266.cpp +++ b/extras/conf_test/esp8266.cpp @@ -9,7 +9,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN"); static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE"); -static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 16, +static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16, "sizeof(VariantSlot)"); void setup() {} diff --git a/extras/conf_test/x64.cpp b/extras/conf_test/x64.cpp index 8cd6c06e0..97838e34e 100644 --- a/extras/conf_test/x64.cpp +++ b/extras/conf_test/x64.cpp @@ -9,7 +9,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN"); static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE"); -static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 32, +static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 32, "sizeof(VariantSlot)"); int main() {} diff --git a/extras/conf_test/x86.cpp b/extras/conf_test/x86.cpp index dab9da610..f3dab30ff 100644 --- a/extras/conf_test/x86.cpp +++ b/extras/conf_test/x86.cpp @@ -9,7 +9,7 @@ static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN"); static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE"); -static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 16, +static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16, "sizeof(VariantSlot)"); int main() {} diff --git a/extras/fuzzing/CMakeLists.txt b/extras/fuzzing/CMakeLists.txt index e5d6a36e6..1d439f46b 100644 --- a/extras/fuzzing/CMakeLists.txt +++ b/extras/fuzzing/CMakeLists.txt @@ -1,7 +1,10 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + if(MSVC) add_compile_options(-D_CRT_SECURE_NO_WARNINGS) endif() @@ -22,7 +25,7 @@ target_link_libraries(json_reproducer ArduinoJson ) -macro(add_fuzzer name) +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") @@ -33,27 +36,23 @@ macro(add_fuzzer name) 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" + 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 + NAME "${FUZZER}" + COMMAND "${FUZZER}" "${CORPUS_DIR}" "${SEED_CORPUS_DIR}" -max_total_time=5 -timeout=1 ) set_tests_properties("${FUZZER}" PROPERTIES - LABELS "Fuzzing" + LABELS "Fuzzing" ) endmacro() -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6) +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6) add_fuzzer(json) add_fuzzer(msgpack) endif() diff --git a/extras/fuzzing/Makefile b/extras/fuzzing/Makefile index d3c574e18..81fc41257 100644 --- a/extras/fuzzing/Makefile +++ b/extras/fuzzing/Makefile @@ -1,6 +1,6 @@ # CAUTION: this file is invoked by https://github.com/google/oss-fuzz -CXXFLAGS += -I../../src -DARDUINOJSON_DEBUG=1 +CXXFLAGS += -I../../src -DARDUINOJSON_DEBUG=1 -std=c++11 all: \ $(OUT)/json_fuzzer \ diff --git a/extras/fuzzing/json_fuzzer.cpp b/extras/fuzzing/json_fuzzer.cpp index db9a3d6c1..043cd426e 100644 --- a/extras/fuzzing/json_fuzzer.cpp +++ b/extras/fuzzing/json_fuzzer.cpp @@ -1,6 +1,6 @@ #include -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { DynamicJsonDocument doc(4096); DeserializationError error = deserializeJson(doc, data, size); if (!error) { diff --git a/extras/fuzzing/msgpack_fuzzer.cpp b/extras/fuzzing/msgpack_fuzzer.cpp index e62359114..b6ab14147 100644 --- a/extras/fuzzing/msgpack_fuzzer.cpp +++ b/extras/fuzzing/msgpack_fuzzer.cpp @@ -1,6 +1,6 @@ #include -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { DynamicJsonDocument doc(4096); DeserializationError error = deserializeMsgPack(doc, data, size); if (!error) { diff --git a/extras/fuzzing/reproducer.cpp b/extras/fuzzing/reproducer.cpp index 86818012f..a004d01ee 100644 --- a/extras/fuzzing/reproducer.cpp +++ b/extras/fuzzing/reproducer.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // This file is NOT use by Google's OSS fuzz diff --git a/extras/scripts/build-arduino-package.sh b/extras/scripts/build-arduino-package.sh index 339db2f62..09f6efb30 100755 --- a/extras/scripts/build-arduino-package.sh +++ b/extras/scripts/build-arduino-package.sh @@ -18,6 +18,6 @@ rm -f "$OUTPUT" src \ keywords.txt \ library.properties \ - LICENSE.md \ + LICENSE.txt \ README.md \ ArduinoJson.h diff --git a/extras/scripts/build-single-header.sh b/extras/scripts/build-single-header.sh index 09d91d419..00292e307 100755 --- a/extras/scripts/build-single-header.sh +++ b/extras/scripts/build-single-header.sh @@ -53,7 +53,8 @@ process() } simplify_namespaces() { - perl -p0i -e 's|\} // namespace ARDUINOJSON_NAMESPACE\r?\nnamespace ARDUINOJSON_NAMESPACE \{\r?\n||igs' "$1" + perl -p0i -e 's|ARDUINOJSON_END_PUBLIC_NAMESPACE\r?\nARDUINOJSON_BEGIN_PUBLIC_NAMESPACE\r?\n||igs' "$1" + perl -p0i -e 's|ARDUINOJSON_END_PRIVATE_NAMESPACE\r?\nARDUINOJSON_BEGIN_PRIVATE_NAMESPACE\r?\n||igs' "$1" rm -f "$1.bak" } diff --git a/extras/scripts/get-release-page.sh b/extras/scripts/get-release-page.sh index 2acb8d8e4..9bf943ef0 100755 --- a/extras/scripts/get-release-page.sh +++ b/extras/scripts/get-release-page.sh @@ -4,14 +4,14 @@ set -eu VERSION="$1" CHANGELOG="$2" -FRONTMATTER="$3" +ARDUINOJSON_H="$3" cat << END --- branch: v6 version: $VERSION date: '$(date +'%Y-%m-%d')' -$(cat "$FRONTMATTER") +$(extras/scripts/wandbox/publish.sh "$ARDUINOJSON_H") --- $(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' "$CHANGELOG") diff --git a/extras/scripts/publish-particle-library.sh b/extras/scripts/publish-particle-library.sh index 62c3140f5..3ee7f9122 100755 --- a/extras/scripts/publish-particle-library.sh +++ b/extras/scripts/publish-particle-library.sh @@ -9,10 +9,10 @@ trap 'rm -rf "$WORK_DIR"' EXIT cp "$SOURCE_DIR/README.md" "$WORK_DIR/README.md" cp "$SOURCE_DIR/CHANGELOG.md" "$WORK_DIR/CHANGELOG.md" cp "$SOURCE_DIR/library.properties" "$WORK_DIR/library.properties" -cp "$SOURCE_DIR/LICENSE.md" "$WORK_DIR/LICENSE.txt" +cp "$SOURCE_DIR/LICENSE.txt" "$WORK_DIR/LICENSE.txt" cp -r "$SOURCE_DIR/src" "$WORK_DIR/" cp -r "$SOURCE_DIR/examples" "$WORK_DIR/" cd "$WORK_DIR" -particle library upload -particle library publish +particle library upload -v +particle library publish -v diff --git a/extras/scripts/publish.sh b/extras/scripts/publish.sh index c5a4eefd3..af9546a6a 100755 --- a/extras/scripts/publish.sh +++ b/extras/scripts/publish.sh @@ -38,17 +38,21 @@ update_version_in_source () { sed -i~ -bE "s/version: .*$/version: $VERSION.{build}/" appveyor.yml rm appveyor.yml~ + sed -i~ -bE "s/^version: .*$/version: \"$VERSION\"/" idf_component.yml + rm idf_component.yml~ + sed -i~ -bE \ -e "s/ARDUINOJSON_VERSION .*$/ARDUINOJSON_VERSION \"$VERSION\"/" \ -e "s/ARDUINOJSON_VERSION_MAJOR .*$/ARDUINOJSON_VERSION_MAJOR $MAJOR/" \ -e "s/ARDUINOJSON_VERSION_MINOR .*$/ARDUINOJSON_VERSION_MINOR $MINOR/" \ -e "s/ARDUINOJSON_VERSION_REVISION .*$/ARDUINOJSON_VERSION_REVISION $REVISION/" \ + -e "s/ARDUINOJSON_VERSION_MACRO .*$/ARDUINOJSON_VERSION_MACRO V$MAJOR$MINOR$REVISION/" \ src/ArduinoJson/version.hpp rm src/ArduinoJson/version.hpp*~ } commit_new_version () { - git add src/ArduinoJson/version.hpp README.md CHANGELOG.md library.json library.properties appveyor.yml CMakeLists.txt + git add src/ArduinoJson/version.hpp README.md CHANGELOG.md library.json library.properties appveyor.yml CMakeLists.txt idf_component.yml git commit -m "Set version to $VERSION" } @@ -69,7 +73,6 @@ push extras/scripts/build-arduino-package.sh . "../ArduinoJson-$TAG.zip" extras/scripts/build-single-header.sh "src/ArduinoJson.h" "../ArduinoJson-$TAG.h" extras/scripts/build-single-header.sh "src/ArduinoJson.hpp" "../ArduinoJson-$TAG.hpp" -extras/scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h" > "../ArduinoJson-$TAG-wandbox.txt" || echo "Wandbox failed!" -extras/scripts/get-release-page.sh "$VERSION" "CHANGELOG.md" "../ArduinoJson-$TAG-wandbox.txt" > "../ArduinoJson-$TAG.md" +extras/scripts/get-release-page.sh "$VERSION" "CHANGELOG.md" "../ArduinoJson-$TAG.h" > "../ArduinoJson-$TAG.md" echo "You can now copy ../ArduinoJson-$TAG.md into arduinojson.org/collections/_versions/$VERSION.md" diff --git a/extras/scripts/wandbox/JsonGeneratorExample.cpp b/extras/scripts/wandbox/JsonGeneratorExample.cpp index 0090c849f..474a0c309 100644 --- a/extras/scripts/wandbox/JsonGeneratorExample.cpp +++ b/extras/scripts/wandbox/JsonGeneratorExample.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows how to generate a JSON document with ArduinoJson. @@ -20,11 +20,6 @@ int main() { // // DynamicJsonDocument doc(200); - // StaticJsonObject allocates memory on the stack, it can be - // replaced by DynamicJsonDocument which allocates in the heap. - // - // DynamicJsonDocument doc(200); - // Add values in the document // doc["sensor"] = "gps"; diff --git a/extras/scripts/wandbox/JsonParserExample.cpp b/extras/scripts/wandbox/JsonParserExample.cpp index f513caff2..396f98cb0 100644 --- a/extras/scripts/wandbox/JsonParserExample.cpp +++ b/extras/scripts/wandbox/JsonParserExample.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows how to deserialize a JSON document with ArduinoJson. diff --git a/extras/scripts/wandbox/MsgPackParserExample.cpp b/extras/scripts/wandbox/MsgPackParserExample.cpp index 186816e61..763de84e6 100644 --- a/extras/scripts/wandbox/MsgPackParserExample.cpp +++ b/extras/scripts/wandbox/MsgPackParserExample.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // // This example shows how to generate a JSON document with ArduinoJson. diff --git a/extras/scripts/wandbox/publish.sh b/extras/scripts/wandbox/publish.sh index 0900cb009..b3f7077fe 100755 --- a/extras/scripts/wandbox/publish.sh +++ b/extras/scripts/wandbox/publish.sh @@ -14,8 +14,8 @@ compile() { { "code":$(read_string "$FILE_PATH"), "codes": [{"file":"ArduinoJson.h","code":$(read_string "$ARDUINOJSON_H")}], - "options": "warning", - "compiler": "gcc-4.9.4", + "options": "warning,c++11", + "compiler": "gcc-5.5.0", "save": true } END diff --git a/extras/tests/CMakeLists.txt b/extras/tests/CMakeLists.txt index faf4cd9a6..c62401f97 100644 --- a/extras/tests/CMakeLists.txt +++ b/extras/tests/CMakeLists.txt @@ -1,8 +1,8 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License -set(CMAKE_CXX_STANDARD 98) +set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_subdirectory(catch) @@ -10,7 +10,6 @@ add_subdirectory(catch) link_libraries(ArduinoJson catch) include_directories(Helpers) -add_subdirectory(Cpp11) add_subdirectory(Cpp17) add_subdirectory(Cpp20) add_subdirectory(FailingBuilds) diff --git a/extras/tests/Cpp11/CMakeLists.txt b/extras/tests/Cpp11/CMakeLists.txt deleted file mode 100644 index 18e54baf9..000000000 --- a/extras/tests/Cpp11/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON -# MIT License - -if("cxx_nullptr" IN_LIST CMAKE_CXX_COMPILE_FEATURES) - list(APPEND SOURCES nullptr.cpp) - add_definitions(-DARDUINOJSON_HAS_NULLPTR=1) -endif() - -if("cxx_auto_type" IN_LIST CMAKE_CXX_COMPILE_FEATURES AND "cxx_constexpr" IN_LIST CMAKE_CXX_COMPILE_FEATURES) - list(APPEND SOURCES issue1120.cpp) -endif() - -if("cxx_long_long_type" IN_LIST CMAKE_CXX_COMPILE_FEATURES) - list(APPEND SOURCES use_long_long_0.cpp use_long_long_1.cpp) -endif() - -if(NOT SOURCES) - return() -endif() - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -add_executable(Cpp11Tests ${SOURCES}) - -add_test(Cpp11 Cpp11Tests) - -set_tests_properties(Cpp11 - PROPERTIES - LABELS "Catch" -) diff --git a/extras/tests/Cpp17/CMakeLists.txt b/extras/tests/Cpp17/CMakeLists.txt index 05af20076..62f2784ff 100644 --- a/extras/tests/Cpp17/CMakeLists.txt +++ b/extras/tests/Cpp17/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License if(MSVC_VERSION LESS 1910) @@ -25,5 +25,5 @@ add_test(Cpp17 Cpp17Tests) set_tests_properties(Cpp17 PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/Cpp17/string_view.cpp b/extras/tests/Cpp17/string_view.cpp index 729c59ae9..7ef656269 100644 --- a/extras/tests/Cpp17/string_view.cpp +++ b/extras/tests/Cpp17/string_view.cpp @@ -1,7 +1,15 @@ -#include +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2023, Benoit BLANCHON +// MIT License + +// we expect ArduinoJson.h to include +// but we don't want it to included accidentally +#undef ARDUINO +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#define ARDUINOJSON_ENABLE_STD_STRING 0 +#include #include -#include #if !ARDUINOJSON_ENABLE_STRING_VIEW # error ARDUINOJSON_ENABLE_STRING_VIEW must be set to 1 @@ -19,7 +27,7 @@ TEST_CASE("string_view") { SECTION("JsonDocument::set()") { doc.set(std::string_view("123", 2)); - REQUIRE(doc.as() == "12"); + REQUIRE(doc.as() == "12"); } SECTION("JsonDocument::operator[]() const") { @@ -86,7 +94,7 @@ TEST_CASE("string_view") { } } -using ARDUINOJSON_NAMESPACE::adaptString; +using ArduinoJson::detail::adaptString; TEST_CASE("StringViewAdapter") { std::string_view str("bravoXXX", 5); diff --git a/extras/tests/Cpp20/CMakeLists.txt b/extras/tests/Cpp20/CMakeLists.txt index 2c9a72b05..e993e974b 100644 --- a/extras/tests/Cpp20/CMakeLists.txt +++ b/extras/tests/Cpp20/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License if(MSVC_VERSION LESS 1910) @@ -25,5 +25,5 @@ add_test(Cpp20 Cpp20Tests) set_tests_properties(Cpp20 PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/FailingBuilds/CMakeLists.txt b/extras/tests/FailingBuilds/CMakeLists.txt index dc76c9108..0464908c9 100644 --- a/extras/tests/FailingBuilds/CMakeLists.txt +++ b/extras/tests/FailingBuilds/CMakeLists.txt @@ -1,29 +1,25 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License macro(build_should_fail target) set_target_properties(${target} PROPERTIES - EXCLUDE_FROM_ALL TRUE - EXCLUDE_FROM_DEFAULT_BUILD TRUE + EXCLUDE_FROM_ALL TRUE + EXCLUDE_FROM_DEFAULT_BUILD TRUE ) add_test( - NAME - ${target} - COMMAND - ${CMAKE_COMMAND} --build . --target ${target} --config $ - WORKING_DIRECTORY - ${CMAKE_BINARY_DIR} + NAME ${target} + COMMAND ${CMAKE_COMMAND} --build . --target ${target} --config $ + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) - set_tests_properties(${target} + set_tests_properties(${target} PROPERTIES - WILL_FAIL TRUE - LABELS "WillFail;Catch" + WILL_FAIL TRUE + LABELS "WillFail;Catch" ) endmacro() - add_executable(Issue978 Issue978.cpp) build_should_fail(Issue978) @@ -31,11 +27,9 @@ 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) diff --git a/extras/tests/FailingBuilds/Issue1189.cpp b/extras/tests/FailingBuilds/Issue1189.cpp index e86bb9926..40cb59f8f 100644 --- a/extras/tests/FailingBuilds/Issue1189.cpp +++ b/extras/tests/FailingBuilds/Issue1189.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/FailingBuilds/Issue978.cpp b/extras/tests/FailingBuilds/Issue978.cpp index 112d36d82..d85aaa0c8 100644 --- a/extras/tests/FailingBuilds/Issue978.cpp +++ b/extras/tests/FailingBuilds/Issue978.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/FailingBuilds/assign_char.cpp b/extras/tests/FailingBuilds/assign_char.cpp index 633b54de3..b9d897f77 100644 --- a/extras/tests/FailingBuilds/assign_char.cpp +++ b/extras/tests/FailingBuilds/assign_char.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/FailingBuilds/delete_jsondocument.cpp b/extras/tests/FailingBuilds/delete_jsondocument.cpp index ef2b0e86b..174b80a5d 100644 --- a/extras/tests/FailingBuilds/delete_jsondocument.cpp +++ b/extras/tests/FailingBuilds/delete_jsondocument.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/FailingBuilds/read_long_long.cpp b/extras/tests/FailingBuilds/read_long_long.cpp index d900a7f34..6fe5992a1 100644 --- a/extras/tests/FailingBuilds/read_long_long.cpp +++ b/extras/tests/FailingBuilds/read_long_long.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_USE_LONG_LONG 0 @@ -9,10 +9,6 @@ # 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); diff --git a/extras/tests/FailingBuilds/variant_as_char.cpp b/extras/tests/FailingBuilds/variant_as_char.cpp index 41885cf6f..1a9e8342f 100644 --- a/extras/tests/FailingBuilds/variant_as_char.cpp +++ b/extras/tests/FailingBuilds/variant_as_char.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/FailingBuilds/write_long_long.cpp b/extras/tests/FailingBuilds/write_long_long.cpp index 2213a4dc0..6ff835651 100644 --- a/extras/tests/FailingBuilds/write_long_long.cpp +++ b/extras/tests/FailingBuilds/write_long_long.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_USE_LONG_LONG 0 @@ -9,10 +9,6 @@ # error This test requires sizeof(long) < 8 #endif -#if !ARDUINOJSON_HAS_LONG_LONG -# error This test requires C++11 -#endif - int main() { DynamicJsonDocument doc(1024); doc["dummy"] = static_cast(42); diff --git a/extras/tests/Helpers/Arduino.h b/extras/tests/Helpers/Arduino.h index 4f24b263e..ef3640d9c 100644 --- a/extras/tests/Helpers/Arduino.h +++ b/extras/tests/Helpers/Arduino.h @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #pragma once @@ -7,6 +7,7 @@ #include "api/Print.h" #include "api/Stream.h" #include "api/String.h" -#include "progmem_emulation.hpp" +#include "avr/pgmspace.h" +#define ARDUINO #define ARDUINO_H_INCLUDED 1 diff --git a/extras/tests/Helpers/CustomReader.hpp b/extras/tests/Helpers/CustomReader.hpp index 8a97b5034..66525a25b 100644 --- a/extras/tests/Helpers/CustomReader.hpp +++ b/extras/tests/Helpers/CustomReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #pragma once @@ -7,20 +7,18 @@ #include class CustomReader { - std::stringstream _stream; + std::stringstream stream_; public: - CustomReader(const char* input) : _stream(input) {} + CustomReader(const char* input) : stream_(input) {} + CustomReader(const CustomReader&) = delete; int read() { - return _stream.get(); + return stream_.get(); } size_t readBytes(char* buffer, size_t length) { - _stream.read(buffer, static_cast(length)); - return static_cast(_stream.gcount()); + stream_.read(buffer, static_cast(length)); + return static_cast(stream_.gcount()); } - - private: - CustomReader(const CustomReader&); }; diff --git a/extras/tests/Helpers/api/Print.h b/extras/tests/Helpers/api/Print.h index 864fb41a0..d3c27ccfe 100644 --- a/extras/tests/Helpers/api/Print.h +++ b/extras/tests/Helpers/api/Print.h @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #pragma once diff --git a/extras/tests/Helpers/api/Stream.h b/extras/tests/Helpers/api/Stream.h index 8cc18d2b4..387940bb8 100644 --- a/extras/tests/Helpers/api/Stream.h +++ b/extras/tests/Helpers/api/Stream.h @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #pragma once diff --git a/extras/tests/Helpers/api/String.h b/extras/tests/Helpers/api/String.h index b2d5ac5f8..64c763f94 100644 --- a/extras/tests/Helpers/api/String.h +++ b/extras/tests/Helpers/api/String.h @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #pragma once @@ -62,7 +62,7 @@ class String { size_t _maxCapacity; }; -class StringSumHelper; +class StringSumHelper : public ::String {}; inline bool operator==(const std::string& lhs, const ::String& rhs) { return lhs == rhs.c_str(); diff --git a/extras/tests/Helpers/progmem_emulation.hpp b/extras/tests/Helpers/avr/pgmspace.h similarity index 76% rename from extras/tests/Helpers/progmem_emulation.hpp rename to extras/tests/Helpers/avr/pgmspace.h index 41597dca8..378065da3 100644 --- a/extras/tests/Helpers/progmem_emulation.hpp +++ b/extras/tests/Helpers/avr/pgmspace.h @@ -1,7 +1,9 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License +#pragma once + #include // uint8_t #define PROGMEM @@ -23,7 +25,7 @@ inline uint8_t pgm_read_byte(const void* p) { return *reinterpret_cast(convertFlashToPtr(p)); } -#define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value) \ - static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = value; \ - static type const* name = reinterpret_cast( \ +#define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, ...) \ + static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = __VA_ARGS__; \ + static type const* name = reinterpret_cast( \ convertPtrToFlash(ARDUINOJSON_CONCAT2(name, _progmem))); diff --git a/extras/tests/IntegrationTests/CMakeLists.txt b/extras/tests/IntegrationTests/CMakeLists.txt index 88b5ba689..9ee858d88 100644 --- a/extras/tests/IntegrationTests/CMakeLists.txt +++ b/extras/tests/IntegrationTests/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License add_executable(IntegrationTests @@ -9,10 +9,10 @@ add_executable(IntegrationTests openweathermap.cpp ) -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6) target_compile_options(IntegrationTests PUBLIC - -fsingle-precision-constant # issue 544 + -fsingle-precision-constant # issue 544 ) endif() @@ -20,5 +20,5 @@ add_test(IntegrationTests IntegrationTests) set_tests_properties(IntegrationTests PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/IntegrationTests/gbathree.cpp b/extras/tests/IntegrationTests/gbathree.cpp index 2190eb10d..34c4d0d84 100644 --- a/extras/tests/IntegrationTests/gbathree.cpp +++ b/extras/tests/IntegrationTests/gbathree.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/IntegrationTests/issue772.cpp b/extras/tests/IntegrationTests/issue772.cpp index 4984b43a6..dd85a085a 100644 --- a/extras/tests/IntegrationTests/issue772.cpp +++ b/extras/tests/IntegrationTests/issue772.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/IntegrationTests/openweathermap.cpp b/extras/tests/IntegrationTests/openweathermap.cpp index 44e2f7605..e91ac0a8a 100644 --- a/extras/tests/IntegrationTests/openweathermap.cpp +++ b/extras/tests/IntegrationTests/openweathermap.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/IntegrationTests/round_trip.cpp b/extras/tests/IntegrationTests/round_trip.cpp index edc553855..ede311d00 100644 --- a/extras/tests/IntegrationTests/round_trip.cpp +++ b/extras/tests/IntegrationTests/round_trip.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/CMakeLists.txt b/extras/tests/JsonArray/CMakeLists.txt index 9f897992a..d97a2b16f 100644 --- a/extras/tests/JsonArray/CMakeLists.txt +++ b/extras/tests/JsonArray/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License add_executable(JsonArrayTests @@ -24,5 +24,5 @@ add_test(JsonArray JsonArrayTests) set_tests_properties(JsonArray PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/JsonArray/add.cpp b/extras/tests/JsonArray/add.cpp index 369bcf2da..2708c7d44 100644 --- a/extras/tests/JsonArray/add.cpp +++ b/extras/tests/JsonArray/add.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/clear.cpp b/extras/tests/JsonArray/clear.cpp index baeb02229..3a593c5ad 100644 --- a/extras/tests/JsonArray/clear.cpp +++ b/extras/tests/JsonArray/clear.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/compare.cpp b/extras/tests/JsonArray/compare.cpp index 4d1c9d079..1e64e166c 100644 --- a/extras/tests/JsonArray/compare.cpp +++ b/extras/tests/JsonArray/compare.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/copyArray.cpp b/extras/tests/JsonArray/copyArray.cpp index 599821df8..7973c375c 100644 --- a/extras/tests/JsonArray/copyArray.cpp +++ b/extras/tests/JsonArray/copyArray.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -165,7 +165,7 @@ TEST_CASE("copyArray()") { char json[32] = ""; int source[][3] = {{1, 2, 3}, {4, 5, 6}}; - CAPTURE(SIZE) + CAPTURE(SIZE); bool ok = copyArray(source, array); CAPTURE(doc.memoryUsage()); diff --git a/extras/tests/JsonArray/createNested.cpp b/extras/tests/JsonArray/createNested.cpp index dbc4c304f..4801dbe0e 100644 --- a/extras/tests/JsonArray/createNested.cpp +++ b/extras/tests/JsonArray/createNested.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/equals.cpp b/extras/tests/JsonArray/equals.cpp index f4f9b521a..4998d388f 100644 --- a/extras/tests/JsonArray/equals.cpp +++ b/extras/tests/JsonArray/equals.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/isNull.cpp b/extras/tests/JsonArray/isNull.cpp index ad953b916..0da13be8d 100644 --- a/extras/tests/JsonArray/isNull.cpp +++ b/extras/tests/JsonArray/isNull.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/iterator.cpp b/extras/tests/JsonArray/iterator.cpp index 435a5bb9d..50eb27631 100644 --- a/extras/tests/JsonArray/iterator.cpp +++ b/extras/tests/JsonArray/iterator.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/memoryUsage.cpp b/extras/tests/JsonArray/memoryUsage.cpp index 05b743f1c..9f4ea09b3 100644 --- a/extras/tests/JsonArray/memoryUsage.cpp +++ b/extras/tests/JsonArray/memoryUsage.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/nesting.cpp b/extras/tests/JsonArray/nesting.cpp index 2118f5f75..fc1be8c6a 100644 --- a/extras/tests/JsonArray/nesting.cpp +++ b/extras/tests/JsonArray/nesting.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/remove.cpp b/extras/tests/JsonArray/remove.cpp index b9e86fdda..f75efda31 100644 --- a/extras/tests/JsonArray/remove.cpp +++ b/extras/tests/JsonArray/remove.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/size.cpp b/extras/tests/JsonArray/size.cpp index 68b10de7a..6edd4db86 100644 --- a/extras/tests/JsonArray/size.cpp +++ b/extras/tests/JsonArray/size.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/std_string.cpp b/extras/tests/JsonArray/std_string.cpp index b7de0efb0..7d3ec9f45 100644 --- a/extras/tests/JsonArray/std_string.cpp +++ b/extras/tests/JsonArray/std_string.cpp @@ -1,13 +1,14 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -static void eraseString(std::string &str) { - char *p = const_cast(str.c_str()); - while (*p) *p++ = '*'; +static void eraseString(std::string& str) { + char* p = const_cast(str.c_str()); + while (*p) + *p++ = '*'; } TEST_CASE("std::string") { diff --git a/extras/tests/JsonArray/subscript.cpp b/extras/tests/JsonArray/subscript.cpp index 57bbe140d..3079d2f98 100644 --- a/extras/tests/JsonArray/subscript.cpp +++ b/extras/tests/JsonArray/subscript.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonArray/unbound.cpp b/extras/tests/JsonArray/unbound.cpp index 792feec3e..0e21310b1 100644 --- a/extras/tests/JsonArray/unbound.cpp +++ b/extras/tests/JsonArray/unbound.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDeserializer/CMakeLists.txt b/extras/tests/JsonDeserializer/CMakeLists.txt index 429c37552..f60ad4161 100644 --- a/extras/tests/JsonDeserializer/CMakeLists.txt +++ b/extras/tests/JsonDeserializer/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License add_executable(JsonDeserializerTests @@ -24,5 +24,5 @@ add_test(JsonDeserializer JsonDeserializerTests) set_tests_properties(JsonDeserializer PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/JsonDeserializer/DeserializationError.cpp b/extras/tests/JsonDeserializer/DeserializationError.cpp index 01ddaf69e..fd1b18854 100644 --- a/extras/tests/JsonDeserializer/DeserializationError.cpp +++ b/extras/tests/JsonDeserializer/DeserializationError.cpp @@ -1,10 +1,12 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include +#include + void testStringification(DeserializationError error, std::string expected) { REQUIRE(error.c_str() == expected); } diff --git a/extras/tests/JsonDeserializer/array.cpp b/extras/tests/JsonDeserializer/array.cpp index 2e0038ee4..b30269c19 100644 --- a/extras/tests/JsonDeserializer/array.cpp +++ b/extras/tests/JsonDeserializer/array.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDeserializer/array_static.cpp b/extras/tests/JsonDeserializer/array_static.cpp index d828518fc..2d1f538d7 100644 --- a/extras/tests/JsonDeserializer/array_static.cpp +++ b/extras/tests/JsonDeserializer/array_static.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDeserializer/filter.cpp b/extras/tests/JsonDeserializer/filter.cpp index 9cf85d27a..f1c6e2e4c 100644 --- a/extras/tests/JsonDeserializer/filter.cpp +++ b/extras/tests/JsonDeserializer/filter.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_ENABLE_COMMENTS 1 @@ -71,6 +71,15 @@ TEST_CASE("Filtering") { "{\"example\":null}", JSON_OBJECT_SIZE(1) + 8 }, + { + // Member is a number, but filter wants an array + "{\"example\":42}", + "{\"example\":[true]}", + 10, + DeserializationError::Ok, + "{\"example\":null}", + JSON_OBJECT_SIZE(1) + 8 + }, { // Input is an array, but filter wants an object "[\"hello\",\"world\"]", @@ -117,7 +126,7 @@ TEST_CASE("Filtering") { JSON_OBJECT_SIZE(1) + 8 }, { - // can skip a boolean + // skip false "{\"a_bool\":false,example:42}", "{\"example\":true}", 10, @@ -125,6 +134,24 @@ TEST_CASE("Filtering") { "{\"example\":42}", JSON_OBJECT_SIZE(1) + 8 }, + { + // skip true + "{\"a_bool\":true,example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, + { + // skip null + "{\"a_bool\":null,example:42}", + "{\"example\":true}", + 10, + DeserializationError::Ok, + "{\"example\":42}", + JSON_OBJECT_SIZE(1) + 8 + }, { // can skip a double-quoted string "{\"a_double_quoted_string\":\"hello\",example:42}", @@ -618,7 +645,7 @@ TEST_CASE("Filtering") { 0 }, { - // incomplete after after key of a skipped object + // incomplete comment after key of a skipped object "{\"example\"/*:2}", "false", 10, @@ -636,7 +663,7 @@ TEST_CASE("Filtering") { 0 }, { - // incomplete after after value of a skipped object + // incomplete comment after value of a skipped object "{\"example\":2/*}", "false", 10, @@ -644,6 +671,15 @@ TEST_CASE("Filtering") { "null", 0 }, + { + // incomplete comment after comma in skipped object + "{\"example\":2,/*}", + "false", + 10, + DeserializationError::IncompleteInput, + "null", + 0 + }, }; // clang-format on for (size_t i = 0; i < sizeof(testCases) / sizeof(testCases[0]); i++) { diff --git a/extras/tests/JsonDeserializer/incomplete_input.cpp b/extras/tests/JsonDeserializer/incomplete_input.cpp index 4e5bcdbd3..a34aede64 100644 --- a/extras/tests/JsonDeserializer/incomplete_input.cpp +++ b/extras/tests/JsonDeserializer/incomplete_input.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_DECODE_UNICODE 1 diff --git a/extras/tests/JsonDeserializer/input_types.cpp b/extras/tests/JsonDeserializer/input_types.cpp index 04054c6a7..788319f46 100644 --- a/extras/tests/JsonDeserializer/input_types.cpp +++ b/extras/tests/JsonDeserializer/input_types.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -24,6 +24,30 @@ TEST_CASE("deserializeJson(char*)") { } } +TEST_CASE("deserializeJson(unsigned char*, unsigned int)") { // issue #1897 + StaticJsonDocument<1024> doc; + + unsigned char input[] = "{\"hello\":\"world\"}"; + unsigned char* input_ptr = input; + unsigned int size = sizeof(input); + + DeserializationError err = deserializeJson(doc, input_ptr, size); + + REQUIRE(err == DeserializationError::Ok); +} + +TEST_CASE("deserializeJson(uint8_t*, size_t)") { // issue #1898 + StaticJsonDocument<1024> doc; + + uint8_t input[] = "{\"hello\":\"world\"}"; + uint8_t* input_ptr = input; + size_t size = sizeof(input); + + DeserializationError err = deserializeJson(doc, input_ptr, size); + + REQUIRE(err == DeserializationError::Ok); +} + TEST_CASE("deserializeJson(const std::string&)") { DynamicJsonDocument doc(4096); diff --git a/extras/tests/JsonDeserializer/invalid_input.cpp b/extras/tests/JsonDeserializer/invalid_input.cpp index f35800862..52b503834 100644 --- a/extras/tests/JsonDeserializer/invalid_input.cpp +++ b/extras/tests/JsonDeserializer/invalid_input.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_DECODE_UNICODE 1 @@ -9,7 +9,8 @@ TEST_CASE("Invalid JSON input") { const char* testCases[] = {"'\\u'", "'\\u000g'", "'\\u000'", "'\\u000G'", "'\\u000/'", "\\x1234", "6a9", "1,", - "2]", "3}"}; + "nulL", "tru3", "fals3", "2]", + "3}"}; const size_t testCount = sizeof(testCases) / sizeof(testCases[0]); DynamicJsonDocument doc(4096); @@ -23,9 +24,6 @@ TEST_CASE("Invalid JSON input") { TEST_CASE("Invalid JSON input that should pass") { 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 diff --git a/extras/tests/JsonDeserializer/misc.cpp b/extras/tests/JsonDeserializer/misc.cpp index dc8083c47..4f22de15f 100644 --- a/extras/tests/JsonDeserializer/misc.cpp +++ b/extras/tests/JsonDeserializer/misc.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDeserializer/nestingLimit.cpp b/extras/tests/JsonDeserializer/nestingLimit.cpp index 0cdcb3e54..cf55dc850 100644 --- a/extras/tests/JsonDeserializer/nestingLimit.cpp +++ b/extras/tests/JsonDeserializer/nestingLimit.cpp @@ -1,10 +1,12 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include +#include + #define SHOULD_WORK(expression) REQUIRE(DeserializationError::Ok == expression); #define SHOULD_FAIL(expression) \ REQUIRE(DeserializationError::TooDeep == expression); diff --git a/extras/tests/JsonDeserializer/number.cpp b/extras/tests/JsonDeserializer/number.cpp index 44e24cbed..05cf89e80 100644 --- a/extras/tests/JsonDeserializer/number.cpp +++ b/extras/tests/JsonDeserializer/number.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_USE_LONG_LONG 0 @@ -11,8 +11,8 @@ #include namespace my { -using ARDUINOJSON_NAMESPACE::isinf; -using ARDUINOJSON_NAMESPACE::isnan; +using ArduinoJson::detail::isinf; +using ArduinoJson::detail::isnan; } // namespace my TEST_CASE("deserialize an integer") { diff --git a/extras/tests/JsonDeserializer/object.cpp b/extras/tests/JsonDeserializer/object.cpp index e5d5de7f4..814258ecd 100644 --- a/extras/tests/JsonDeserializer/object.cpp +++ b/extras/tests/JsonDeserializer/object.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -100,7 +100,7 @@ TEST_CASE("deserialize JSON object") { REQUIRE(obj["key"] == "value"); } - SECTION("Before the colon") { + SECTION("Before the comma") { DeserializationError err = deserializeJson(doc, "{\"key1\":\"value1\" ,\"key2\":\"value2\"}"); JsonObject obj = doc.as(); @@ -112,9 +112,9 @@ TEST_CASE("deserialize JSON object") { REQUIRE(obj["key2"] == "value2"); } - SECTION("After the colon") { + SECTION("After the comma") { DeserializationError err = - deserializeJson(doc, "{\"key1\":\"value1\" ,\"key2\":\"value2\"}"); + deserializeJson(doc, "{\"key1\":\"value1\", \"key2\":\"value2\"}"); JsonObject obj = doc.as(); REQUIRE(err == DeserializationError::Ok); diff --git a/extras/tests/JsonDeserializer/object_static.cpp b/extras/tests/JsonDeserializer/object_static.cpp index a326afe60..b198ea74f 100644 --- a/extras/tests/JsonDeserializer/object_static.cpp +++ b/extras/tests/JsonDeserializer/object_static.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDeserializer/string.cpp b/extras/tests/JsonDeserializer/string.cpp index 8f93ac63d..2379d4554 100644 --- a/extras/tests/JsonDeserializer/string.cpp +++ b/extras/tests/JsonDeserializer/string.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_DECODE_UNICODE 1 diff --git a/extras/tests/JsonDocument/BasicJsonDocument.cpp b/extras/tests/JsonDocument/BasicJsonDocument.cpp index d2074401a..348fd94cf 100644 --- a/extras/tests/JsonDocument/BasicJsonDocument.cpp +++ b/extras/tests/JsonDocument/BasicJsonDocument.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -8,34 +8,31 @@ #include #include -using ARDUINOJSON_NAMESPACE::addPadding; - class SpyingAllocator { public: - SpyingAllocator(const SpyingAllocator& src) : _log(src._log) {} - SpyingAllocator(std::ostream& log) : _log(log) {} + SpyingAllocator(const SpyingAllocator& src) : log_(src.log_) {} + SpyingAllocator(std::ostream& log) : log_(log) {} + SpyingAllocator& operator=(const SpyingAllocator& src) = delete; void* allocate(size_t n) { - _log << "A" << n; + log_ << "A" << n; return malloc(n); } void deallocate(void* p) { - _log << "F"; + log_ << "F"; free(p); } private: - SpyingAllocator& operator=(const SpyingAllocator& src); - - std::ostream& _log; + std::ostream& log_; }; class ControllableAllocator { public: - ControllableAllocator() : _enabled(true) {} + ControllableAllocator() : enabled_(true) {} void* allocate(size_t n) { - return _enabled ? malloc(n) : 0; + return enabled_ ? malloc(n) : 0; } void deallocate(void* p) { @@ -43,11 +40,11 @@ class ControllableAllocator { } void disable() { - _enabled = false; + enabled_ = false; } private: - bool _enabled; + bool enabled_; }; TEST_CASE("BasicJsonDocument") { @@ -72,7 +69,6 @@ TEST_CASE("BasicJsonDocument") { REQUIRE(log.str() == "A4096A4096FF"); } -#if ARDUINOJSON_HAS_RVALUE_REFERENCES SECTION("Move construct") { { BasicJsonDocument doc1(4096, log); @@ -87,7 +83,6 @@ TEST_CASE("BasicJsonDocument") { } REQUIRE(log.str() == "A4096F"); } -#endif SECTION("Copy assign larger") { { @@ -134,7 +129,6 @@ TEST_CASE("BasicJsonDocument") { REQUIRE(log.str() == "A1024A1024FF"); } -#if ARDUINOJSON_HAS_RVALUE_REFERENCES SECTION("Move assign") { { BasicJsonDocument doc1(4096, log); @@ -150,7 +144,6 @@ TEST_CASE("BasicJsonDocument") { } REQUIRE(log.str() == "A4096A8FF"); } -#endif SECTION("garbageCollect()") { BasicJsonDocument doc(4096); diff --git a/extras/tests/JsonDocument/CMakeLists.txt b/extras/tests/JsonDocument/CMakeLists.txt index 535678033..3e9b46835 100644 --- a/extras/tests/JsonDocument/CMakeLists.txt +++ b/extras/tests/JsonDocument/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License add_executable(JsonDocumentTests @@ -12,6 +12,7 @@ add_executable(JsonDocumentTests DynamicJsonDocument.cpp ElementProxy.cpp isNull.cpp + issue1120.cpp MemberProxy.cpp nesting.cpp overflowed.cpp @@ -27,5 +28,5 @@ add_test(JsonDocument JsonDocumentTests) set_tests_properties(JsonDocument PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/JsonDocument/DynamicJsonDocument.cpp b/extras/tests/JsonDocument/DynamicJsonDocument.cpp index ce050f17b..397f8c5dc 100644 --- a/extras/tests/JsonDocument/DynamicJsonDocument.cpp +++ b/extras/tests/JsonDocument/DynamicJsonDocument.cpp @@ -1,11 +1,11 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using ARDUINOJSON_NAMESPACE::addPadding; +using ArduinoJson::detail::addPadding; static void REQUIRE_JSON(JsonDocument& doc, const std::string& expected) { std::string json; diff --git a/extras/tests/JsonDocument/ElementProxy.cpp b/extras/tests/JsonDocument/ElementProxy.cpp index 0f4292f0d..00fcdda26 100644 --- a/extras/tests/JsonDocument/ElementProxy.cpp +++ b/extras/tests/JsonDocument/ElementProxy.cpp @@ -1,16 +1,16 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +typedef ArduinoJson::detail::ElementProxy ElementProxy; TEST_CASE("ElementProxy::add()") { DynamicJsonDocument doc(4096); doc.add(); - ElementProxy ep = doc[0]; + ElementProxy ep = doc[0]; SECTION("add(int)") { ep.add(42); @@ -36,7 +36,7 @@ TEST_CASE("ElementProxy::add()") { TEST_CASE("ElementProxy::clear()") { DynamicJsonDocument doc(4096); doc.add(); - ElementProxy ep = doc[0]; + ElementProxy ep = doc[0]; SECTION("size goes back to zero") { ep.add(42); @@ -96,7 +96,7 @@ TEST_CASE("ElementProxy::operator==()") { TEST_CASE("ElementProxy::remove()") { DynamicJsonDocument doc(4096); doc.add(); - ElementProxy ep = doc[0]; + ElementProxy ep = doc[0]; SECTION("remove(int)") { ep.add(1); @@ -143,7 +143,7 @@ TEST_CASE("ElementProxy::remove()") { TEST_CASE("ElementProxy::set()") { DynamicJsonDocument doc(4096); - ElementProxy ep = doc[0]; + ElementProxy ep = doc[0]; SECTION("set(int)") { ep.set(42); @@ -169,7 +169,7 @@ TEST_CASE("ElementProxy::set()") { TEST_CASE("ElementProxy::size()") { DynamicJsonDocument doc(4096); doc.add(); - ElementProxy ep = doc[0]; + ElementProxy ep = doc[0]; SECTION("returns 0") { REQUIRE(ep.size() == 0); @@ -191,7 +191,7 @@ TEST_CASE("ElementProxy::size()") { TEST_CASE("ElementProxy::memoryUsage()") { DynamicJsonDocument doc(4096); doc.add(); - ElementProxy ep = doc[0]; + ElementProxy ep = doc[0]; SECTION("returns 0 for null") { REQUIRE(ep.memoryUsage() == 0); @@ -205,7 +205,7 @@ TEST_CASE("ElementProxy::memoryUsage()") { TEST_CASE("ElementProxy::operator[]") { DynamicJsonDocument doc(4096); - ElementProxy ep = doc[1]; + ElementProxy ep = doc[1]; SECTION("set member") { ep["world"] = 42; @@ -224,7 +224,7 @@ TEST_CASE("ElementProxy cast to JsonVariantConst") { DynamicJsonDocument doc(4096); doc[0] = "world"; - const ElementProxy ep = doc[0]; + const ElementProxy ep = doc[0]; JsonVariantConst var = ep; @@ -235,7 +235,7 @@ TEST_CASE("ElementProxy cast to JsonVariant") { DynamicJsonDocument doc(4096); doc[0] = "world"; - ElementProxy ep = doc[0]; + ElementProxy ep = doc[0]; JsonVariant var = ep; diff --git a/extras/tests/JsonDocument/MemberProxy.cpp b/extras/tests/JsonDocument/MemberProxy.cpp index b9e2b749b..a3707b03e 100644 --- a/extras/tests/JsonDocument/MemberProxy.cpp +++ b/extras/tests/JsonDocument/MemberProxy.cpp @@ -1,15 +1,16 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +typedef ArduinoJson::detail::MemberProxy + MemberProxy; TEST_CASE("MemberProxy::add()") { DynamicJsonDocument doc(4096); - MemberProxy mp = doc["hello"]; + MemberProxy mp = doc["hello"]; SECTION("add(int)") { mp.add(42); @@ -26,7 +27,7 @@ TEST_CASE("MemberProxy::add()") { TEST_CASE("MemberProxy::clear()") { DynamicJsonDocument doc(4096); - MemberProxy mp = doc["hello"]; + MemberProxy mp = doc["hello"]; SECTION("size goes back to zero") { mp.add(42); @@ -85,7 +86,7 @@ TEST_CASE("MemberProxy::operator==()") { TEST_CASE("MemberProxy::containsKey()") { DynamicJsonDocument doc(4096); - MemberProxy mp = doc["hello"]; + MemberProxy mp = doc["hello"]; SECTION("containsKey(const char*)") { mp["key"] = "value"; @@ -115,9 +116,9 @@ TEST_CASE("MemberProxy::operator|()") { SECTION("Issue #1411") { doc["sensor"] = "gps"; - const char *test = "test"; // <- the literal must be captured in a variable + const char* test = "test"; // <- the literal must be captured in a variable // to trigger the bug - const char *sensor = doc["sensor"] | test; // "gps" + const char* sensor = doc["sensor"] | test; // "gps" REQUIRE(sensor == std::string("gps")); } @@ -136,7 +137,7 @@ TEST_CASE("MemberProxy::operator|()") { TEST_CASE("MemberProxy::remove()") { DynamicJsonDocument doc(4096); - MemberProxy mp = doc["hello"]; + MemberProxy mp = doc["hello"]; SECTION("remove(int)") { mp.add(1); @@ -183,7 +184,7 @@ TEST_CASE("MemberProxy::remove()") { TEST_CASE("MemberProxy::set()") { DynamicJsonDocument doc(4096); - MemberProxy mp = doc["hello"]; + MemberProxy mp = doc["hello"]; SECTION("set(int)") { mp.set(42); @@ -208,7 +209,7 @@ TEST_CASE("MemberProxy::set()") { TEST_CASE("MemberProxy::size()") { DynamicJsonDocument doc(4096); - MemberProxy mp = doc["hello"]; + MemberProxy mp = doc["hello"]; SECTION("returns 0") { REQUIRE(mp.size() == 0); @@ -231,7 +232,7 @@ TEST_CASE("MemberProxy::size()") { TEST_CASE("MemberProxy::memoryUsage()") { DynamicJsonDocument doc(4096); - MemberProxy mp = doc["hello"]; + MemberProxy mp = doc["hello"]; SECTION("returns 0 when null") { REQUIRE(mp.memoryUsage() == 0); @@ -245,7 +246,7 @@ TEST_CASE("MemberProxy::memoryUsage()") { TEST_CASE("MemberProxy::operator[]") { DynamicJsonDocument doc(4096); - MemberProxy mp = doc["hello"]; + MemberProxy mp = doc["hello"]; SECTION("set member") { mp["world"] = 42; @@ -264,7 +265,7 @@ TEST_CASE("MemberProxy cast to JsonVariantConst") { DynamicJsonDocument doc(4096); doc["hello"] = "world"; - const MemberProxy mp = doc["hello"]; + const MemberProxy mp = doc["hello"]; JsonVariantConst var = mp; @@ -275,7 +276,7 @@ TEST_CASE("MemberProxy cast to JsonVariant") { DynamicJsonDocument doc(4096); doc["hello"] = "world"; - MemberProxy mp = doc["hello"]; + MemberProxy mp = doc["hello"]; JsonVariant var = mp; diff --git a/extras/tests/JsonDocument/StaticJsonDocument.cpp b/extras/tests/JsonDocument/StaticJsonDocument.cpp index fe193e4b1..0d4089bc2 100644 --- a/extras/tests/JsonDocument/StaticJsonDocument.cpp +++ b/extras/tests/JsonDocument/StaticJsonDocument.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDocument/add.cpp b/extras/tests/JsonDocument/add.cpp index 109bd08bc..5843ac967 100644 --- a/extras/tests/JsonDocument/add.cpp +++ b/extras/tests/JsonDocument/add.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDocument/cast.cpp b/extras/tests/JsonDocument/cast.cpp index e538f4bbf..253e1fc76 100644 --- a/extras/tests/JsonDocument/cast.cpp +++ b/extras/tests/JsonDocument/cast.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDocument/compare.cpp b/extras/tests/JsonDocument/compare.cpp index 7e9b95008..d834b2262 100644 --- a/extras/tests/JsonDocument/compare.cpp +++ b/extras/tests/JsonDocument/compare.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDocument/containsKey.cpp b/extras/tests/JsonDocument/containsKey.cpp index 693604375..8274fc76b 100644 --- a/extras/tests/JsonDocument/containsKey.cpp +++ b/extras/tests/JsonDocument/containsKey.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDocument/createNested.cpp b/extras/tests/JsonDocument/createNested.cpp index 258f05179..0c9435757 100644 --- a/extras/tests/JsonDocument/createNested.cpp +++ b/extras/tests/JsonDocument/createNested.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDocument/isNull.cpp b/extras/tests/JsonDocument/isNull.cpp index cfb70dd62..d5aaae022 100644 --- a/extras/tests/JsonDocument/isNull.cpp +++ b/extras/tests/JsonDocument/isNull.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/Cpp11/issue1120.cpp b/extras/tests/JsonDocument/issue1120.cpp similarity index 100% rename from extras/tests/Cpp11/issue1120.cpp rename to extras/tests/JsonDocument/issue1120.cpp diff --git a/extras/tests/JsonDocument/nesting.cpp b/extras/tests/JsonDocument/nesting.cpp index 3284dd1c2..7ac7e7685 100644 --- a/extras/tests/JsonDocument/nesting.cpp +++ b/extras/tests/JsonDocument/nesting.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDocument/overflowed.cpp b/extras/tests/JsonDocument/overflowed.cpp index cea0db9d5..e46d21b09 100644 --- a/extras/tests/JsonDocument/overflowed.cpp +++ b/extras/tests/JsonDocument/overflowed.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDocument/remove.cpp b/extras/tests/JsonDocument/remove.cpp index b77707339..724b324d5 100644 --- a/extras/tests/JsonDocument/remove.cpp +++ b/extras/tests/JsonDocument/remove.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDocument/shrinkToFit.cpp b/extras/tests/JsonDocument/shrinkToFit.cpp index 0eb34e816..a44233404 100644 --- a/extras/tests/JsonDocument/shrinkToFit.cpp +++ b/extras/tests/JsonDocument/shrinkToFit.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -8,40 +8,38 @@ #include // malloc, free #include -using ARDUINOJSON_NAMESPACE::addPadding; - class ArmoredAllocator { public: - ArmoredAllocator() : _ptr(0), _size(0) {} + ArmoredAllocator() : ptr_(0), size_(0) {} void* allocate(size_t size) { - _ptr = malloc(size); - _size = size; - return _ptr; + ptr_ = malloc(size); + size_ = size; + return ptr_; } void deallocate(void* ptr) { - REQUIRE(ptr == _ptr); + REQUIRE(ptr == ptr_); free(ptr); - _ptr = 0; - _size = 0; + ptr_ = 0; + size_ = 0; } void* reallocate(void* ptr, size_t new_size) { - REQUIRE(ptr == _ptr); + 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; + 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; + void* ptr_; + size_t size_; }; typedef BasicJsonDocument ShrinkToFitTestDocument; diff --git a/extras/tests/JsonDocument/size.cpp b/extras/tests/JsonDocument/size.cpp index 4fbb6e23c..b3205a146 100644 --- a/extras/tests/JsonDocument/size.cpp +++ b/extras/tests/JsonDocument/size.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonDocument/subscript.cpp b/extras/tests/JsonDocument/subscript.cpp index 4ba6ff846..f4186f85d 100644 --- a/extras/tests/JsonDocument/subscript.cpp +++ b/extras/tests/JsonDocument/subscript.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/CMakeLists.txt b/extras/tests/JsonObject/CMakeLists.txt index 033e73ea7..8676811ca 100644 --- a/extras/tests/JsonObject/CMakeLists.txt +++ b/extras/tests/JsonObject/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License add_executable(JsonObjectTests @@ -25,5 +25,5 @@ add_test(JsonObject JsonObjectTests) set_tests_properties(JsonObject PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/JsonObject/clear.cpp b/extras/tests/JsonObject/clear.cpp index da17b2cff..e112a8dcd 100644 --- a/extras/tests/JsonObject/clear.cpp +++ b/extras/tests/JsonObject/clear.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/compare.cpp b/extras/tests/JsonObject/compare.cpp index ffdb9aa2f..9b747e3bf 100644 --- a/extras/tests/JsonObject/compare.cpp +++ b/extras/tests/JsonObject/compare.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/containsKey.cpp b/extras/tests/JsonObject/containsKey.cpp index 4f37f7e64..85335a889 100644 --- a/extras/tests/JsonObject/containsKey.cpp +++ b/extras/tests/JsonObject/containsKey.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/copy.cpp b/extras/tests/JsonObject/copy.cpp index c5514a21f..a4d5b5fa9 100644 --- a/extras/tests/JsonObject/copy.cpp +++ b/extras/tests/JsonObject/copy.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/createNestedArray.cpp b/extras/tests/JsonObject/createNestedArray.cpp index 4d43038fa..26c1a8605 100644 --- a/extras/tests/JsonObject/createNestedArray.cpp +++ b/extras/tests/JsonObject/createNestedArray.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/createNestedObject.cpp b/extras/tests/JsonObject/createNestedObject.cpp index 29f4d39df..9ea067a73 100644 --- a/extras/tests/JsonObject/createNestedObject.cpp +++ b/extras/tests/JsonObject/createNestedObject.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/equals.cpp b/extras/tests/JsonObject/equals.cpp index 101c61262..02d451f96 100644 --- a/extras/tests/JsonObject/equals.cpp +++ b/extras/tests/JsonObject/equals.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/invalid.cpp b/extras/tests/JsonObject/invalid.cpp index 199c8f03e..0695b4814 100644 --- a/extras/tests/JsonObject/invalid.cpp +++ b/extras/tests/JsonObject/invalid.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/isNull.cpp b/extras/tests/JsonObject/isNull.cpp index 44403481f..9fdff955f 100644 --- a/extras/tests/JsonObject/isNull.cpp +++ b/extras/tests/JsonObject/isNull.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/iterator.cpp b/extras/tests/JsonObject/iterator.cpp index e9f2cd293..c48de5f6e 100644 --- a/extras/tests/JsonObject/iterator.cpp +++ b/extras/tests/JsonObject/iterator.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/memoryUsage.cpp b/extras/tests/JsonObject/memoryUsage.cpp index 835ee4a7e..406bcda4f 100644 --- a/extras/tests/JsonObject/memoryUsage.cpp +++ b/extras/tests/JsonObject/memoryUsage.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/nesting.cpp b/extras/tests/JsonObject/nesting.cpp index 7937c289e..2ba98adf6 100644 --- a/extras/tests/JsonObject/nesting.cpp +++ b/extras/tests/JsonObject/nesting.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/remove.cpp b/extras/tests/JsonObject/remove.cpp index f1cb20cb7..1dbd4bd53 100644 --- a/extras/tests/JsonObject/remove.cpp +++ b/extras/tests/JsonObject/remove.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/size.cpp b/extras/tests/JsonObject/size.cpp index 0d82cfb8c..d9c7bb785 100644 --- a/extras/tests/JsonObject/size.cpp +++ b/extras/tests/JsonObject/size.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonObject/std_string.cpp b/extras/tests/JsonObject/std_string.cpp index e985421e9..8a93d3f08 100644 --- a/extras/tests/JsonObject/std_string.cpp +++ b/extras/tests/JsonObject/std_string.cpp @@ -1,13 +1,14 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -static void eraseString(std::string &str) { - char *p = const_cast(str.c_str()); - while (*p) *p++ = '*'; +static void eraseString(std::string& str) { + char* p = const_cast(str.c_str()); + while (*p) + *p++ = '*'; } TEST_CASE("std::string") { diff --git a/extras/tests/JsonObject/subscript.cpp b/extras/tests/JsonObject/subscript.cpp index e8242f632..afc567a6e 100644 --- a/extras/tests/JsonObject/subscript.cpp +++ b/extras/tests/JsonObject/subscript.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonSerializer/CMakeLists.txt b/extras/tests/JsonSerializer/CMakeLists.txt index ece6dbc25..0ec4937fb 100644 --- a/extras/tests/JsonSerializer/CMakeLists.txt +++ b/extras/tests/JsonSerializer/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License add_executable(JsonSerializerTests @@ -18,5 +18,5 @@ add_test(JsonSerializer JsonSerializerTests) set_tests_properties(JsonSerializer PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/JsonSerializer/CustomWriter.cpp b/extras/tests/JsonSerializer/CustomWriter.cpp index 05d870409..a84657a72 100644 --- a/extras/tests/JsonSerializer/CustomWriter.cpp +++ b/extras/tests/JsonSerializer/CustomWriter.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -8,26 +8,25 @@ class CustomWriter { public: CustomWriter() {} + CustomWriter(const CustomWriter&) = delete; + CustomWriter& operator=(const CustomWriter&) = delete; size_t write(uint8_t c) { - _str.append(1, static_cast(c)); + str_.append(1, static_cast(c)); return 1; } - size_t write(const uint8_t *s, size_t n) { - _str.append(reinterpret_cast(s), n); + size_t write(const uint8_t* s, size_t n) { + str_.append(reinterpret_cast(s), n); return n; } - const std::string &str() const { - return _str; + const std::string& str() const { + return str_; } private: - CustomWriter(const CustomWriter &); // non-copiable - CustomWriter &operator=(const CustomWriter &); - - std::string _str; + std::string str_; }; TEST_CASE("CustomWriter") { diff --git a/extras/tests/JsonSerializer/JsonArray.cpp b/extras/tests/JsonSerializer/JsonArray.cpp index e018de73c..1fad69ddc 100644 --- a/extras/tests/JsonSerializer/JsonArray.cpp +++ b/extras/tests/JsonSerializer/JsonArray.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -23,7 +23,7 @@ TEST_CASE("serializeJson(JsonArray)") { } SECTION("Null") { - array.add(static_cast(0)); + array.add(static_cast(0)); check(array, "[null]"); } diff --git a/extras/tests/JsonSerializer/JsonArrayPretty.cpp b/extras/tests/JsonSerializer/JsonArrayPretty.cpp index 8c319fc0b..9abeb0151 100644 --- a/extras/tests/JsonSerializer/JsonArrayPretty.cpp +++ b/extras/tests/JsonSerializer/JsonArrayPretty.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonSerializer/JsonObject.cpp b/extras/tests/JsonSerializer/JsonObject.cpp index b457c6656..9ba21141d 100644 --- a/extras/tests/JsonSerializer/JsonObject.cpp +++ b/extras/tests/JsonSerializer/JsonObject.cpp @@ -1,12 +1,12 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include #include -static void checkObject(const JsonObject obj, const std::string &expected) { +static void checkObject(const JsonObject obj, const std::string& expected) { char actual[256]; memset(actual, '!', sizeof(actual)); @@ -84,8 +84,8 @@ TEST_CASE("serializeJson(JsonObject)") { } SECTION("TwoNull") { - obj["a"] = static_cast(0); - obj["b"] = static_cast(0); + obj["a"] = static_cast(0); + obj["b"] = static_cast(0); checkObject(obj, "{\"a\":null,\"b\":null}"); } diff --git a/extras/tests/JsonSerializer/JsonObjectPretty.cpp b/extras/tests/JsonSerializer/JsonObjectPretty.cpp index ec4ae71b8..4e8d113e2 100644 --- a/extras/tests/JsonSerializer/JsonObjectPretty.cpp +++ b/extras/tests/JsonSerializer/JsonObjectPretty.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonSerializer/JsonVariant.cpp b/extras/tests/JsonSerializer/JsonVariant.cpp index 18d51f585..81553d315 100644 --- a/extras/tests/JsonSerializer/JsonVariant.cpp +++ b/extras/tests/JsonSerializer/JsonVariant.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -7,7 +7,7 @@ #include template -void check(T value, const std::string &expected) { +void check(T value, const std::string& expected) { DynamicJsonDocument doc(4096); doc.to().set(value); char buffer[256] = ""; @@ -22,7 +22,7 @@ TEST_CASE("serializeJson(JsonVariant)") { } SECTION("Null string") { - check(static_cast(0), "null"); + check(static_cast(0), "null"); } SECTION("const char*") { diff --git a/extras/tests/JsonSerializer/std_stream.cpp b/extras/tests/JsonSerializer/std_stream.cpp index 74520286a..411f47924 100644 --- a/extras/tests/JsonSerializer/std_stream.cpp +++ b/extras/tests/JsonSerializer/std_stream.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonSerializer/std_string.cpp b/extras/tests/JsonSerializer/std_string.cpp index 7a145da8e..af0d8096e 100644 --- a/extras/tests/JsonSerializer/std_string.cpp +++ b/extras/tests/JsonSerializer/std_string.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/CMakeLists.txt b/extras/tests/JsonVariant/CMakeLists.txt index 1a0d14a93..d43a971c1 100644 --- a/extras/tests/JsonVariant/CMakeLists.txt +++ b/extras/tests/JsonVariant/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License add_executable(JsonVariantTests @@ -16,12 +16,14 @@ add_executable(JsonVariantTests memoryUsage.cpp misc.cpp nesting.cpp + nullptr.cpp or.cpp overflow.cpp remove.cpp set.cpp shallowCopy.cpp size.cpp + stl_containers.cpp subscript.cpp types.cpp unbound.cpp @@ -31,5 +33,5 @@ add_test(JsonVariant JsonVariantTests) set_tests_properties(JsonVariant PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/JsonVariant/add.cpp b/extras/tests/JsonVariant/add.cpp index 526e914d8..6907ae3ed 100644 --- a/extras/tests/JsonVariant/add.cpp +++ b/extras/tests/JsonVariant/add.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/as.cpp b/extras/tests/JsonVariant/as.cpp index c9956778b..01e263e9c 100644 --- a/extras/tests/JsonVariant/as.cpp +++ b/extras/tests/JsonVariant/as.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -7,7 +7,7 @@ #include namespace my { -using ARDUINOJSON_NAMESPACE::isinf; +using ArduinoJson::detail::isinf; } // namespace my enum MY_ENUM { ONE = 1, TWO = 2 }; diff --git a/extras/tests/JsonVariant/clear.cpp b/extras/tests/JsonVariant/clear.cpp index 2b40e324d..d516ca6c1 100644 --- a/extras/tests/JsonVariant/clear.cpp +++ b/extras/tests/JsonVariant/clear.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/compare.cpp b/extras/tests/JsonVariant/compare.cpp index 2cbdaa3d5..1922df034 100644 --- a/extras/tests/JsonVariant/compare.cpp +++ b/extras/tests/JsonVariant/compare.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/containsKey.cpp b/extras/tests/JsonVariant/containsKey.cpp index fca684ee1..d003d11df 100644 --- a/extras/tests/JsonVariant/containsKey.cpp +++ b/extras/tests/JsonVariant/containsKey.cpp @@ -1,13 +1,11 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include #include -static const char* null = 0; - TEST_CASE("JsonVariant::containsKey()") { DynamicJsonDocument doc(4096); JsonVariant var = doc.to(); diff --git a/extras/tests/JsonVariant/converters.cpp b/extras/tests/JsonVariant/converters.cpp index 785289e17..4cca990d4 100644 --- a/extras/tests/JsonVariant/converters.cpp +++ b/extras/tests/JsonVariant/converters.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -74,37 +74,37 @@ TEST_CASE("Custom converter with overloading") { class Complex { public: - explicit Complex(double r, double i) : _real(r), _imag(i) {} + explicit Complex(double r, double i) : real_(r), imag_(i) {} double real() const { - return _real; + return real_; } double imag() const { - return _imag; + return imag_; } private: - double _real, _imag; + double real_, imag_; }; -namespace ARDUINOJSON_NAMESPACE { +namespace ArduinoJson { template <> struct Converter { - static void toJson(const Complex& src, VariantRef dst) { + static void toJson(const Complex& src, JsonVariant dst) { dst["real"] = src.real(); dst["imag"] = src.imag(); } - static Complex fromJson(VariantConstRef src) { + static Complex fromJson(JsonVariantConst src) { return Complex(src["real"], src["imag"]); } - static bool checkJson(VariantConstRef src) { + static bool checkJson(JsonVariantConst src) { return src["real"].is() && src["imag"].is(); } }; -} // namespace ARDUINOJSON_NAMESPACE +} // namespace ArduinoJson TEST_CASE("Custom converter with specialization") { DynamicJsonDocument doc(4096); @@ -142,7 +142,7 @@ TEST_CASE("Custom converter with specialization") { } TEST_CASE("ConverterNeedsWriteableRef") { - using namespace ARDUINOJSON_NAMESPACE; + using namespace ArduinoJson::detail; CHECK(ConverterNeedsWriteableRef::value == false); CHECK(ConverterNeedsWriteableRef::value == false); CHECK(ConverterNeedsWriteableRef::value == true); @@ -152,3 +152,30 @@ TEST_CASE("ConverterNeedsWriteableRef") { CHECK(ConverterNeedsWriteableRef::value == true); CHECK(ConverterNeedsWriteableRef::value == false); } + +namespace ArduinoJson { +template <> +struct Converter { + static void toJson(char c, JsonVariant var) { + char buf[] = {c, 0}; + var.set(buf); + } + + static char fromJson(JsonVariantConst src) { + auto p = src.as(); + return p ? p[0] : 0; + } +}; +} // namespace ArduinoJson + +TEST_CASE("Convert char to string") { // issue #1922 + StaticJsonDocument<64> doc; + doc.set('a'); + REQUIRE(doc.as() == "a"); +} + +TEST_CASE("Convert string to char") { // issue #1963 + StaticJsonDocument<64> doc; + doc.set("a"); + REQUIRE(doc.as() == 'a'); +} diff --git a/extras/tests/JsonVariant/copy.cpp b/extras/tests/JsonVariant/copy.cpp index 7784f0cad..0d96bf9fa 100644 --- a/extras/tests/JsonVariant/copy.cpp +++ b/extras/tests/JsonVariant/copy.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/createNested.cpp b/extras/tests/JsonVariant/createNested.cpp index efd750158..e3958231e 100644 --- a/extras/tests/JsonVariant/createNested.cpp +++ b/extras/tests/JsonVariant/createNested.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/is.cpp b/extras/tests/JsonVariant/is.cpp index 6d04f0afe..6a414a42f 100644 --- a/extras/tests/JsonVariant/is.cpp +++ b/extras/tests/JsonVariant/is.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -19,7 +19,7 @@ TEST_CASE("JsonVariant::is()") { CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); - CHECK(variant.is() == false); + CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); @@ -34,7 +34,7 @@ TEST_CASE("JsonVariant::is()") { CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); - CHECK(variant.is() == false); + CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); @@ -50,7 +50,7 @@ TEST_CASE("JsonVariant::is()") { CHECK(variant.is() == true); CHECK(variant.is() == false); CHECK(variant.is() == false); - CHECK(variant.is() == false); + CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); @@ -66,7 +66,7 @@ TEST_CASE("JsonVariant::is()") { CHECK(variant.is() == true); CHECK(variant.is() == false); CHECK(variant.is() == false); - CHECK(variant.is() == false); + CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); @@ -88,7 +88,7 @@ TEST_CASE("JsonVariant::is()") { CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); - CHECK(variant.is() == false); + CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); } @@ -103,7 +103,7 @@ TEST_CASE("JsonVariant::is()") { CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); - CHECK(variant.is() == false); + CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); @@ -113,8 +113,8 @@ TEST_CASE("JsonVariant::is()") { SECTION("const char*") { variant.set("4.2"); - CHECK(variant.is() == true); - CHECK(variant.is() == true); + CHECK(variant.is() == true); + CHECK(variant.is() == true); CHECK(variant.is() == true); CHECK(variant.is() == true); CHECK(variant.is() == true); @@ -140,7 +140,7 @@ TEST_CASE("JsonVariant::is()") { CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); - CHECK(variant.is() == false); + CHECK(variant.is() == false); CHECK(variant.is() == false); } @@ -156,7 +156,7 @@ TEST_CASE("JsonVariant::is()") { CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == false); - CHECK(variant.is() == false); + CHECK(variant.is() == false); CHECK(variant.is() == false); CHECK(variant.is() == true); CHECK(variant.is() == true); @@ -178,7 +178,7 @@ TEST_CASE("JsonVariantConst::is()") { CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); - CHECK(cvariant.is() == false); + CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); @@ -192,7 +192,7 @@ TEST_CASE("JsonVariantConst::is()") { CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); - CHECK(cvariant.is() == false); + CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); @@ -208,7 +208,7 @@ TEST_CASE("JsonVariantConst::is()") { CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); - CHECK(cvariant.is() == false); + CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); @@ -224,7 +224,7 @@ TEST_CASE("JsonVariantConst::is()") { CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); - CHECK(cvariant.is() == false); + CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); @@ -246,7 +246,7 @@ TEST_CASE("JsonVariantConst::is()") { CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); - CHECK(cvariant.is() == false); + CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); } @@ -261,7 +261,7 @@ TEST_CASE("JsonVariantConst::is()") { CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); - CHECK(cvariant.is() == false); + CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); @@ -271,8 +271,8 @@ TEST_CASE("JsonVariantConst::is()") { SECTION("const char*") { variant.set("4.2"); - CHECK(cvariant.is() == true); - CHECK(cvariant.is() == true); + CHECK(cvariant.is() == true); + CHECK(cvariant.is() == true); CHECK(cvariant.is() == true); CHECK(cvariant.is() == true); CHECK(cvariant.is() == false); @@ -297,7 +297,7 @@ TEST_CASE("JsonVariantConst::is()") { CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); - CHECK(cvariant.is() == false); + CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); } @@ -313,7 +313,7 @@ TEST_CASE("JsonVariantConst::is()") { CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); - CHECK(cvariant.is() == false); + CHECK(cvariant.is() == false); CHECK(cvariant.is() == false); } } diff --git a/extras/tests/JsonVariant/isnull.cpp b/extras/tests/JsonVariant/isnull.cpp index 1ec6f3539..bb9de714b 100644 --- a/extras/tests/JsonVariant/isnull.cpp +++ b/extras/tests/JsonVariant/isnull.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/memoryUsage.cpp b/extras/tests/JsonVariant/memoryUsage.cpp index 59587dbba..808acb3a2 100644 --- a/extras/tests/JsonVariant/memoryUsage.cpp +++ b/extras/tests/JsonVariant/memoryUsage.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/misc.cpp b/extras/tests/JsonVariant/misc.cpp index 05976c377..7089f6405 100644 --- a/extras/tests/JsonVariant/misc.cpp +++ b/extras/tests/JsonVariant/misc.cpp @@ -1,10 +1,15 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include +TEST_CASE("VariantData") { + REQUIRE(std::is_standard_layout::value == + true); +} + TEST_CASE("JsonVariant from JsonArray") { SECTION("JsonArray is null") { JsonArray arr; diff --git a/extras/tests/JsonVariant/nesting.cpp b/extras/tests/JsonVariant/nesting.cpp index 3e936fbe4..1028a2838 100644 --- a/extras/tests/JsonVariant/nesting.cpp +++ b/extras/tests/JsonVariant/nesting.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/Cpp11/nullptr.cpp b/extras/tests/JsonVariant/nullptr.cpp similarity index 75% rename from extras/tests/Cpp11/nullptr.cpp rename to extras/tests/JsonVariant/nullptr.cpp index 813b9cc2a..e26d9306d 100644 --- a/extras/tests/Cpp11/nullptr.cpp +++ b/extras/tests/JsonVariant/nullptr.cpp @@ -2,24 +2,20 @@ #include -#if !ARDUINOJSON_HAS_NULLPTR -# error ARDUINOJSON_HAS_NULLPTR must be set to 1 -#endif - TEST_CASE("nullptr") { DynamicJsonDocument doc(4096); JsonVariant variant = doc.to(); SECTION("JsonVariant == nullptr") { - REQUIRE((variant == nullptr)); - REQUIRE_FALSE((variant != nullptr)); + REQUIRE(variant == nullptr); + REQUIRE_FALSE(variant != nullptr); } SECTION("JsonVariant != nullptr") { variant.set(42); - REQUIRE_FALSE((variant == nullptr)); - REQUIRE((variant != nullptr)); + REQUIRE_FALSE(variant == nullptr); + REQUIRE(variant != nullptr); } SECTION("JsonVariant.set(nullptr)") { diff --git a/extras/tests/JsonVariant/or.cpp b/extras/tests/JsonVariant/or.cpp index 7d1c190b8..01ec4701c 100644 --- a/extras/tests/JsonVariant/or.cpp +++ b/extras/tests/JsonVariant/or.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/overflow.cpp b/extras/tests/JsonVariant/overflow.cpp index ff0e3aa50..1123e98b8 100644 --- a/extras/tests/JsonVariant/overflow.cpp +++ b/extras/tests/JsonVariant/overflow.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/remove.cpp b/extras/tests/JsonVariant/remove.cpp index c744e19bb..0835bf0ee 100644 --- a/extras/tests/JsonVariant/remove.cpp +++ b/extras/tests/JsonVariant/remove.cpp @@ -1,13 +1,11 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include #include -static const char* null = 0; - TEST_CASE("JsonVariant::remove()") { DynamicJsonDocument doc(4096); JsonVariant var = doc.to(); diff --git a/extras/tests/JsonVariant/set.cpp b/extras/tests/JsonVariant/set.cpp index 899ef6a55..4743afb97 100644 --- a/extras/tests/JsonVariant/set.cpp +++ b/extras/tests/JsonVariant/set.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -15,7 +15,7 @@ TEST_CASE("JsonVariant::set() when there is enough memory") { char str[16]; strcpy(str, "hello"); - bool result = variant.set(static_cast(str)); + bool result = variant.set(static_cast(str)); strcpy(str, "world"); REQUIRE(result == true); @@ -23,7 +23,7 @@ TEST_CASE("JsonVariant::set() when there is enough memory") { } SECTION("(const char*)0") { - bool result = variant.set(static_cast(0)); + bool result = variant.set(static_cast(0)); REQUIRE(result == true); REQUIRE(variant.isNull()); @@ -41,7 +41,7 @@ TEST_CASE("JsonVariant::set() when there is enough memory") { } SECTION("(char*)0") { - bool result = variant.set(static_cast(0)); + bool result = variant.set(static_cast(0)); REQUIRE(result == true); REQUIRE(variant.isNull()); @@ -51,7 +51,7 @@ TEST_CASE("JsonVariant::set() when there is enough memory") { char str[16]; strcpy(str, "hello"); - bool result = variant.set(reinterpret_cast(str)); + bool result = variant.set(reinterpret_cast(str)); strcpy(str, "world"); REQUIRE(result == true); @@ -62,7 +62,7 @@ TEST_CASE("JsonVariant::set() when there is enough memory") { char str[16]; strcpy(str, "hello"); - bool result = variant.set(reinterpret_cast(str)); + bool result = variant.set(reinterpret_cast(str)); strcpy(str, "world"); REQUIRE(result == true); diff --git a/extras/tests/JsonVariant/shallowCopy.cpp b/extras/tests/JsonVariant/shallowCopy.cpp index c7c334b73..28aa38c60 100644 --- a/extras/tests/JsonVariant/shallowCopy.cpp +++ b/extras/tests/JsonVariant/shallowCopy.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/size.cpp b/extras/tests/JsonVariant/size.cpp index 73d9ced80..3a4ec4676 100644 --- a/extras/tests/JsonVariant/size.cpp +++ b/extras/tests/JsonVariant/size.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/stl_containers.cpp b/extras/tests/JsonVariant/stl_containers.cpp new file mode 100644 index 000000000..d6b9b60bc --- /dev/null +++ b/extras/tests/JsonVariant/stl_containers.cpp @@ -0,0 +1,138 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2023, Benoit BLANCHON +// MIT License + +#include +#include +#include + +#include +#include +#include + +namespace ArduinoJson { +template +struct Converter> { + static void toJson(const std::vector& src, JsonVariant dst) { + JsonArray array = dst.to(); + for (T item : src) + array.add(item); + } + + static std::vector fromJson(JsonVariantConst src) { + std::vector dst; + for (T item : src.as()) + dst.push_back(item); + return dst; + } + + static bool checkJson(JsonVariantConst src) { + JsonArrayConst array = src; + bool result = array; + for (JsonVariantConst item : array) + result &= item.is(); + return result; + } +}; + +template +struct Converter> { + static void toJson(const std::array& src, JsonVariant dst) { + JsonArray array = dst.to(); + for (T item : src) + array.add(item); + } + + static std::array fromJson(JsonVariantConst src) { + std::array dst; + dst.fill(0); + size_t idx = 0; + for (T item : src.as()) + dst[idx++] = item; + return dst; + } + + static bool checkJson(JsonVariantConst src) { + JsonArrayConst array = src; + bool result = array; + size_t size = 0; + for (JsonVariantConst item : array) { + result &= item.is(); + size++; + } + return result && size == N; + } +}; +} // namespace ArduinoJson + +TEST_CASE("vector") { + SECTION("toJson") { + std::vector v = {1, 2}; + + StaticJsonDocument<128> doc; + doc.set(v); + REQUIRE(doc.as() == "[1,2]"); + } + + SECTION("fromJson") { + StaticJsonDocument<128> doc; + doc.add(1); + doc.add(2); + + auto v = doc.as>(); + REQUIRE(v.size() == 2); + CHECK(v[0] == 1); + CHECK(v[1] == 2); + } + + SECTION("checkJson") { + StaticJsonDocument<128> doc; + CHECK(doc.is>() == false); + + doc.add(1); + doc.add(2); + CHECK(doc.is>() == true); + + doc.add("foo"); + CHECK(doc.is>() == false); + } +} + +TEST_CASE("array") { + typedef std::array array_type; + + SECTION("toJson") { + array_type v; + v[0] = 1; + v[1] = 2; + + StaticJsonDocument<128> doc; + doc.set(v); + REQUIRE(doc.as() == "[1,2]"); + } + + SECTION("fromJson") { + StaticJsonDocument<128> doc; + doc.add(1); + doc.add(2); + + auto v = doc.as(); + REQUIRE(v.size() == 2); + CHECK(v[0] == 1); + CHECK(v[1] == 2); + } + + SECTION("checkJson") { + StaticJsonDocument<128> doc; + CHECK(doc.is() == false); + + doc.add(1); + CHECK(doc.is() == false); + + doc.add(2); + CHECK(doc.is() == true); + + doc[0] = "foo"; + CHECK(doc.is() == false); + } +} diff --git a/extras/tests/JsonVariant/subscript.cpp b/extras/tests/JsonVariant/subscript.cpp index f466cd275..93f759b8b 100644 --- a/extras/tests/JsonVariant/subscript.cpp +++ b/extras/tests/JsonVariant/subscript.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/JsonVariant/types.cpp b/extras/tests/JsonVariant/types.cpp index 448d41aba..91b4c1e2a 100644 --- a/extras/tests/JsonVariant/types.cpp +++ b/extras/tests/JsonVariant/types.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -17,9 +17,9 @@ void checkValue(T expected) { } template -void checkReference(T &expected) { +void checkReference(T& expected) { JsonVariant variant = expected; - REQUIRE(expected == variant.as()); + REQUIRE(expected == variant.as()); } template @@ -46,10 +46,10 @@ TEST_CASE("JsonVariant set()/get()") { #endif SECTION("Null") { - checkValue(NULL); + checkValue(NULL); } SECTION("const char*") { - checkValue("hello"); + checkValue("hello"); } SECTION("std::string") { checkValue("hello"); @@ -140,6 +140,13 @@ TEST_CASE("volatile") { DynamicJsonDocument doc(4096); JsonVariant variant = doc.to(); + SECTION("volatile bool") { // issue #2029 + volatile bool f = true; + variant.set(f); + CHECK(variant.is() == true); + CHECK(variant.as() == true); + } + SECTION("volatile int") { volatile int f = 42; variant.set(f); diff --git a/extras/tests/JsonVariant/unbound.cpp b/extras/tests/JsonVariant/unbound.cpp index 8089e1cca..902032363 100644 --- a/extras/tests/JsonVariant/unbound.cpp +++ b/extras/tests/JsonVariant/unbound.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/MemoryPool/CMakeLists.txt b/extras/tests/MemoryPool/CMakeLists.txt index 80ba3c6de..2f809cc26 100644 --- a/extras/tests/MemoryPool/CMakeLists.txt +++ b/extras/tests/MemoryPool/CMakeLists.txt @@ -1,8 +1,8 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License -add_executable(MemoryPoolTests +add_executable(MemoryPoolTests allocVariant.cpp clear.cpp saveString.cpp @@ -14,5 +14,5 @@ add_test(MemoryPool MemoryPoolTests) set_tests_properties(MemoryPool PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/MemoryPool/StringCopier.cpp b/extras/tests/MemoryPool/StringCopier.cpp index ba39cfd98..0342bc4fc 100644 --- a/extras/tests/MemoryPool/StringCopier.cpp +++ b/extras/tests/MemoryPool/StringCopier.cpp @@ -1,18 +1,18 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; TEST_CASE("StringCopier") { char buffer[4096]; SECTION("Works when buffer is big enough") { MemoryPool pool(buffer, addPadding(JSON_STRING_SIZE(5))); - StringCopier str(pool); + StringCopier str(&pool); str.startString(); str.append("hello"); @@ -24,7 +24,7 @@ TEST_CASE("StringCopier") { SECTION("Returns null when too small") { MemoryPool pool(buffer, sizeof(void*)); - StringCopier str(pool); + StringCopier str(&pool); str.startString(); str.append("hello world!"); @@ -35,7 +35,7 @@ TEST_CASE("StringCopier") { SECTION("Increases size of memory pool") { MemoryPool pool(buffer, addPadding(JSON_STRING_SIZE(6))); - StringCopier str(pool); + StringCopier str(&pool); str.startString(); str.save(); @@ -46,7 +46,7 @@ TEST_CASE("StringCopier") { SECTION("Works when memory pool is 0 bytes") { MemoryPool pool(buffer, 0); - StringCopier str(pool); + StringCopier str(&pool); str.startString(); REQUIRE(str.isValid() == false); @@ -55,7 +55,7 @@ TEST_CASE("StringCopier") { } static const char* addStringToPool(MemoryPool& pool, const char* s) { - StringCopier str(pool); + StringCopier str(&pool); str.startString(); str.append(s); return str.save().c_str(); diff --git a/extras/tests/MemoryPool/allocVariant.cpp b/extras/tests/MemoryPool/allocVariant.cpp index 606d6d7b9..5123a4e25 100644 --- a/extras/tests/MemoryPool/allocVariant.cpp +++ b/extras/tests/MemoryPool/allocVariant.cpp @@ -1,11 +1,11 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; TEST_CASE("MemoryPool::allocVariant()") { char buffer[4096]; diff --git a/extras/tests/MemoryPool/clear.cpp b/extras/tests/MemoryPool/clear.cpp index f4ab796c5..9e33b4718 100644 --- a/extras/tests/MemoryPool/clear.cpp +++ b/extras/tests/MemoryPool/clear.cpp @@ -1,12 +1,12 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; static const size_t poolCapacity = 512; @@ -22,7 +22,7 @@ TEST_CASE("MemoryPool::clear()") { } SECTION("Discards allocated strings") { - pool.saveString(adaptString(const_cast("123456789"))); + pool.saveString(adaptString(const_cast("123456789"))); REQUIRE(pool.size() == 10); pool.clear(); diff --git a/extras/tests/MemoryPool/saveString.cpp b/extras/tests/MemoryPool/saveString.cpp index 0c16b6775..ba8d5b91b 100644 --- a/extras/tests/MemoryPool/saveString.cpp +++ b/extras/tests/MemoryPool/saveString.cpp @@ -1,18 +1,18 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; -static const char *saveString(MemoryPool &pool, const char *s) { - return pool.saveString(adaptString(const_cast(s))); +static const char* saveString(MemoryPool& pool, const char* s) { + return pool.saveString(adaptString(const_cast(s))); } -static const char *saveString(MemoryPool &pool, const char *s, size_t n) { +static const char* saveString(MemoryPool& pool, const char* s, size_t n) { return pool.saveString(adaptString(s, n)); } @@ -21,36 +21,36 @@ TEST_CASE("MemoryPool::saveString()") { MemoryPool pool(buffer, 32); SECTION("Duplicates different strings") { - const char *a = saveString(pool, "hello"); - const char *b = saveString(pool, "world"); + const char* a = saveString(pool, "hello"); + const char* b = saveString(pool, "world"); REQUIRE(a != b); REQUIRE(pool.size() == 6 + 6); } SECTION("Deduplicates identical strings") { - const char *a = saveString(pool, "hello"); - const char *b = saveString(pool, "hello"); + const char* a = saveString(pool, "hello"); + const char* b = saveString(pool, "hello"); REQUIRE(a == b); REQUIRE(pool.size() == 6); } SECTION("Deduplicates identical strings that contain NUL") { - const char *a = saveString(pool, "hello\0world", 11); - const char *b = saveString(pool, "hello\0world", 11); + const char* a = saveString(pool, "hello\0world", 11); + const char* b = saveString(pool, "hello\0world", 11); REQUIRE(a == b); REQUIRE(pool.size() == 12); } SECTION("Reuse part of a string if it ends with NUL") { - const char *a = saveString(pool, "hello\0world", 11); - const char *b = saveString(pool, "hello"); + const char* a = saveString(pool, "hello\0world", 11); + const char* b = saveString(pool, "hello"); REQUIRE(a == b); REQUIRE(pool.size() == 12); } SECTION("Don't stop on first NUL") { - const char *a = saveString(pool, "hello"); - const char *b = saveString(pool, "hello\0world", 11); + const char* a = saveString(pool, "hello"); + const char* b = saveString(pool, "hello\0world", 11); REQUIRE(a != b); REQUIRE(pool.size() == 18); } @@ -58,16 +58,16 @@ TEST_CASE("MemoryPool::saveString()") { SECTION("Returns NULL when full") { REQUIRE(pool.capacity() == 32); - const void *p1 = saveString(pool, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + const void* p1 = saveString(pool, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); REQUIRE(p1 != 0); REQUIRE(pool.size() == 32); - const void *p2 = saveString(pool, "b"); + const void* p2 = saveString(pool, "b"); REQUIRE(p2 == 0); } SECTION("Returns NULL when pool is too small") { - const void *p = saveString(pool, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + const void* p = saveString(pool, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); REQUIRE(0 == p); } @@ -82,15 +82,15 @@ TEST_CASE("MemoryPool::saveString()") { } SECTION("Returns same address after clear()") { - const void *a = saveString(pool, "hello"); + const void* a = saveString(pool, "hello"); pool.clear(); - const void *b = saveString(pool, "world"); + const void* b = saveString(pool, "world"); REQUIRE(a == b); } SECTION("Can use full capacity when fresh") { - const void *a = saveString(pool, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + const void* a = saveString(pool, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); REQUIRE(a != 0); } @@ -99,7 +99,7 @@ TEST_CASE("MemoryPool::saveString()") { saveString(pool, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); pool.clear(); - const void *a = saveString(pool, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); + const void* a = saveString(pool, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); REQUIRE(a != 0); } diff --git a/extras/tests/MemoryPool/size.cpp b/extras/tests/MemoryPool/size.cpp index 47603fe28..057f4ab30 100644 --- a/extras/tests/MemoryPool/size.cpp +++ b/extras/tests/MemoryPool/size.cpp @@ -1,11 +1,11 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; TEST_CASE("MemoryPool::capacity()") { char buffer[4096]; @@ -25,7 +25,8 @@ TEST_CASE("MemoryPool::size()") { SECTION("Doesn't grow when memory pool is full") { const size_t variantCount = sizeof(buffer) / sizeof(VariantSlot); - for (size_t i = 0; i < variantCount; i++) pool.allocVariant(); + for (size_t i = 0; i < variantCount; i++) + pool.allocVariant(); size_t size = pool.size(); pool.allocVariant(); diff --git a/extras/tests/Misc/CMakeLists.txt b/extras/tests/Misc/CMakeLists.txt index 114ebb746..3a1eb898e 100644 --- a/extras/tests/Misc/CMakeLists.txt +++ b/extras/tests/Misc/CMakeLists.txt @@ -1,12 +1,12 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License add_executable(MiscTests arithmeticCompare.cpp conflicts.cpp - deprecated.cpp FloatParts.cpp + issue1967.cpp JsonString.cpp NoArduinoHeader.cpp printable.cpp @@ -26,5 +26,5 @@ add_test(Misc MiscTests) set_tests_properties(Misc PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/Misc/FloatParts.cpp b/extras/tests/Misc/FloatParts.cpp index 736b176cb..8e3d82e15 100644 --- a/extras/tests/Misc/FloatParts.cpp +++ b/extras/tests/Misc/FloatParts.cpp @@ -1,11 +1,11 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; TEST_CASE("FloatParts") { SECTION("1.7976931348623157E+308") { diff --git a/extras/tests/Misc/JsonString.cpp b/extras/tests/Misc/JsonString.cpp index 557f99366..c3dca1728 100644 --- a/extras/tests/Misc/JsonString.cpp +++ b/extras/tests/Misc/JsonString.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/Misc/NoArduinoHeader.cpp b/extras/tests/Misc/NoArduinoHeader.cpp index 43a82b249..4b0218bff 100644 --- a/extras/tests/Misc/NoArduinoHeader.cpp +++ b/extras/tests/Misc/NoArduinoHeader.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINO 1 diff --git a/extras/tests/Misc/Readers.cpp b/extras/tests/Misc/Readers.cpp index e46ad1e72..0b8f4d502 100644 --- a/extras/tests/Misc/Readers.cpp +++ b/extras/tests/Misc/Readers.cpp @@ -1,12 +1,14 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include #include -using namespace ARDUINOJSON_NAMESPACE; +#include + +using namespace ArduinoJson::detail; TEST_CASE("Reader") { SECTION("read()") { @@ -168,19 +170,19 @@ TEST_CASE("IteratorReader") { class StreamStub : public Stream { public: - StreamStub(const char* s) : _stream(s) {} + StreamStub(const char* s) : stream_(s) {} int read() { - return _stream.get(); + return stream_.get(); } size_t readBytes(char* buffer, size_t length) { - _stream.read(buffer, static_cast(length)); - return static_cast(_stream.gcount()); + stream_.read(buffer, static_cast(length)); + return static_cast(stream_.gcount()); } private: - std::istringstream _stream; + std::istringstream stream_; }; TEST_CASE("Reader") { diff --git a/extras/tests/Misc/StringAdapters.cpp b/extras/tests/Misc/StringAdapters.cpp index 82139eecf..1c77e08bf 100644 --- a/extras/tests/Misc/StringAdapters.cpp +++ b/extras/tests/Misc/StringAdapters.cpp @@ -1,18 +1,18 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License -#define ARDUINOJSON_ENABLE_PROGMEM 1 -#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 - -#include "custom_string.hpp" -#include "weird_strcmp.hpp" +#include +#include #include #include -using namespace ARDUINOJSON_NAMESPACE; +#include "custom_string.hpp" +#include "weird_strcmp.hpp" + +using namespace ArduinoJson::detail; TEST_CASE("ZeroTerminatedRamString") { SECTION("null") { @@ -85,30 +85,18 @@ TEST_CASE("custom_string") { CHECK(s.size() == 5); } -TEST_CASE("IsString") { - SECTION("std::string") { - CHECK(IsString::value == true); - } - - SECTION("basic_string") { - CHECK(IsString >::value == false); - } - - SECTION("custom_string") { - CHECK(IsString::value == true); - } - - SECTION("const __FlashStringHelper*") { - CHECK(IsString::value == true); - } +struct EmptyStruct {}; - SECTION("const char*") { - CHECK(IsString::value == true); - } - - SECTION("const char[]") { - CHECK(IsString::value == true); - } +TEST_CASE("IsString") { + CHECK(IsString::value == true); + CHECK(IsString>::value == false); + CHECK(IsString::value == true); + CHECK(IsString::value == true); + CHECK(IsString::value == true); + CHECK(IsString::value == true); + CHECK(IsString<::String>::value == true); + CHECK(IsString<::StringSumHelper>::value == true); + CHECK(IsString::value == false); } TEST_CASE("stringCompare") { diff --git a/extras/tests/Misc/StringWriter.cpp b/extras/tests/Misc/StringWriter.cpp index bdb5bdb1f..81cb88e92 100644 --- a/extras/tests/Misc/StringWriter.cpp +++ b/extras/tests/Misc/StringWriter.cpp @@ -1,14 +1,17 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License -#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 +#include + #define ARDUINOJSON_STRING_BUFFER_SIZE 5 #include + #include + #include "custom_string.hpp" -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; template static size_t print(StringWriter& writer, const char* s) { @@ -65,7 +68,7 @@ TEST_CASE("Writer") { TEST_CASE("Writer") { ::String output; - Writer< ::String> writer(output); + Writer<::String> writer(output); SECTION("write(char)") { SECTION("writes to temporary buffer") { diff --git a/extras/tests/Misc/TypeTraits.cpp b/extras/tests/Misc/TypeTraits.cpp index 5f861afa6..10b6168b5 100644 --- a/extras/tests/Misc/TypeTraits.cpp +++ b/extras/tests/Misc/TypeTraits.cpp @@ -1,11 +1,13 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +#include + +using namespace ArduinoJson::detail; class EmptyClass {}; enum EmptyEnum {}; @@ -19,9 +21,9 @@ TEST_CASE("Polyfills/type_traits") { } SECTION("is_array") { - REQUIRE_FALSE((is_array::value)); - REQUIRE((is_array::value)); - REQUIRE((is_array::value)); + REQUIRE_FALSE(is_array::value); + REQUIRE(is_array::value); + REQUIRE(is_array::value); } SECTION("is_const") { @@ -80,7 +82,7 @@ TEST_CASE("Polyfills/type_traits") { CHECK(is_integral::value == true); CHECK(is_integral::value == true); - CHECK(is_integral::value == true); + CHECK(is_integral::value == true); } SECTION("is_signed") { @@ -172,36 +174,35 @@ TEST_CASE("Polyfills/type_traits") { } SECTION("is_convertible") { - CHECK((is_convertible::value == true)); - CHECK((is_convertible::value == true)); - CHECK((is_convertible::value == true)); - CHECK((is_convertible::value == false)); - CHECK((is_convertible::value == false)); - - CHECK((is_convertible::value == - false)); - CHECK((is_convertible::value == false)); - CHECK((is_convertible::value == true)); - CHECK((is_convertible::value == true)); - CHECK((is_convertible::value == true)); - CHECK((is_convertible, JsonVariantConst>::value == - true)); - CHECK((is_convertible::value == true)); - CHECK((is_convertible::value == true)); - CHECK((is_convertible, - JsonVariantConst>::value == true)); - CHECK((is_convertible::value == true)); - CHECK( - (is_convertible::value == true)); - CHECK((is_convertible, JsonVariantConst>::value == - true)); + CHECK(is_convertible::value == true); + CHECK(is_convertible::value == true); + CHECK(is_convertible::value == true); + CHECK(is_convertible::value == false); + CHECK(is_convertible::value == false); + + CHECK(is_convertible::value == + false); + CHECK(is_convertible::value == false); + CHECK(is_convertible::value == true); + CHECK(is_convertible::value == true); + CHECK(is_convertible::value == true); + CHECK(is_convertible, JsonVariantConst>::value == + true); + CHECK(is_convertible::value == true); + CHECK(is_convertible::value == true); + CHECK(is_convertible, + JsonVariantConst>::value == true); + CHECK(is_convertible::value == true); + CHECK(is_convertible::value == true); + CHECK(is_convertible, JsonVariantConst>::value == + true); } SECTION("is_class") { - CHECK((is_class::value == false)); - CHECK((is_class::value == false)); - CHECK((is_class::value == false)); - CHECK((is_class::value == true)); + CHECK(is_class::value == false); + CHECK(is_class::value == false); + CHECK(is_class::value == false); + CHECK(is_class::value == true); } SECTION("is_enum") { diff --git a/extras/tests/Misc/Utf16.cpp b/extras/tests/Misc/Utf16.cpp index 31ab7ec5e..3a5959105 100644 --- a/extras/tests/Misc/Utf16.cpp +++ b/extras/tests/Misc/Utf16.cpp @@ -1,11 +1,11 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; static void testUtf16Codepoint(uint16_t codeunit, uint32_t expectedCodepoint) { Utf16::Codepoint cp; diff --git a/extras/tests/Misc/Utf8.cpp b/extras/tests/Misc/Utf8.cpp index 38e839ac3..0c62033d2 100644 --- a/extras/tests/Misc/Utf8.cpp +++ b/extras/tests/Misc/Utf8.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -7,12 +7,12 @@ #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; static void testCodepoint(uint32_t codepoint, std::string expected) { char buffer[4096]; MemoryPool pool(buffer, 4096); - StringCopier str(pool); + StringCopier str(&pool); str.startString(); CAPTURE(codepoint); diff --git a/extras/tests/Misc/arithmeticCompare.cpp b/extras/tests/Misc/arithmeticCompare.cpp index a67943e8a..2d51754a1 100644 --- a/extras/tests/Misc/arithmeticCompare.cpp +++ b/extras/tests/Misc/arithmeticCompare.cpp @@ -1,103 +1,97 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; TEST_CASE("arithmeticCompare()") { SECTION("int vs uint8_t") { - CHECK((arithmeticCompare(256, 1) == COMPARE_RESULT_GREATER)); - CHECK((arithmeticCompare(41, 42) == COMPARE_RESULT_LESS)); - CHECK((arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompare(43, 42) == COMPARE_RESULT_GREATER)); + CHECK(arithmeticCompare(256, 1) == COMPARE_RESULT_GREATER); + CHECK(arithmeticCompare(41, 42) == COMPARE_RESULT_LESS); + CHECK(arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(43, 42) == COMPARE_RESULT_GREATER); } SECTION("unsigned vs int") { - CHECK((arithmeticCompare(0, -1) == COMPARE_RESULT_GREATER)); - CHECK((arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER)); - CHECK((arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompare(42, 43) == COMPARE_RESULT_LESS)); + CHECK(arithmeticCompare(0, -1) == COMPARE_RESULT_GREATER); + CHECK(arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER); + CHECK(arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(42, 43) == COMPARE_RESULT_LESS); } SECTION("float vs int") { - CHECK((arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER)); - CHECK((arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompare(42, 43) == COMPARE_RESULT_LESS)); + CHECK(arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER); + CHECK(arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(42, 43) == COMPARE_RESULT_LESS); } SECTION("int vs unsigned") { - CHECK((arithmeticCompare(-1, 0) == COMPARE_RESULT_LESS)); - CHECK((arithmeticCompare(0, 0) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompare(1, 0) == COMPARE_RESULT_GREATER)); - CHECK((arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER)); - CHECK((arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompare(42, 43) == COMPARE_RESULT_LESS)); + CHECK(arithmeticCompare(-1, 0) == COMPARE_RESULT_LESS); + CHECK(arithmeticCompare(0, 0) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(1, 0) == COMPARE_RESULT_GREATER); + CHECK(arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER); + CHECK(arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(42, 43) == COMPARE_RESULT_LESS); } SECTION("unsigned vs unsigned") { - CHECK((arithmeticCompare(42, 41) == - COMPARE_RESULT_GREATER)); - CHECK((arithmeticCompare(42, 42) == - COMPARE_RESULT_EQUAL)); - CHECK( - (arithmeticCompare(42, 43) == COMPARE_RESULT_LESS)); + CHECK(arithmeticCompare(42, 41) == + COMPARE_RESULT_GREATER); + CHECK(arithmeticCompare(42, 42) == + COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(42, 43) == COMPARE_RESULT_LESS); } SECTION("bool vs bool") { - CHECK( - (arithmeticCompare(false, false) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompare(true, true) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompare(false, true) == COMPARE_RESULT_LESS)); - CHECK( - (arithmeticCompare(true, false) == COMPARE_RESULT_GREATER)); + CHECK(arithmeticCompare(false, false) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(true, true) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(false, true) == COMPARE_RESULT_LESS); + CHECK(arithmeticCompare(true, false) == COMPARE_RESULT_GREATER); } SECTION("bool vs int") { - CHECK((arithmeticCompare(false, -1) == COMPARE_RESULT_GREATER)); - CHECK((arithmeticCompare(false, 0) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompare(false, 1) == COMPARE_RESULT_LESS)); - CHECK((arithmeticCompare(true, 0) == COMPARE_RESULT_GREATER)); - CHECK((arithmeticCompare(true, 1) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompare(true, 2) == COMPARE_RESULT_LESS)); + CHECK(arithmeticCompare(false, -1) == COMPARE_RESULT_GREATER); + CHECK(arithmeticCompare(false, 0) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(false, 1) == COMPARE_RESULT_LESS); + CHECK(arithmeticCompare(true, 0) == COMPARE_RESULT_GREATER); + CHECK(arithmeticCompare(true, 1) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(true, 2) == COMPARE_RESULT_LESS); } SECTION("bool vs int") { - CHECK((arithmeticCompare(0, false) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompare(1, true) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompare(1, false) == COMPARE_RESULT_GREATER)); - CHECK((arithmeticCompare(0, true) == COMPARE_RESULT_LESS)); + CHECK(arithmeticCompare(0, false) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(1, true) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompare(1, false) == COMPARE_RESULT_GREATER); + CHECK(arithmeticCompare(0, true) == COMPARE_RESULT_LESS); } } TEST_CASE("arithmeticCompareNegateLeft()") { SECTION("unsigned vs int") { - CHECK((arithmeticCompareNegateLeft(0, 1) == COMPARE_RESULT_LESS)); - CHECK((arithmeticCompareNegateLeft(42, -41) == COMPARE_RESULT_LESS)); - CHECK((arithmeticCompareNegateLeft(42, -42) == COMPARE_RESULT_EQUAL)); - CHECK( - (arithmeticCompareNegateLeft(42, -43) == COMPARE_RESULT_GREATER)); + CHECK(arithmeticCompareNegateLeft(0, 1) == COMPARE_RESULT_LESS); + CHECK(arithmeticCompareNegateLeft(42, -41) == COMPARE_RESULT_LESS); + CHECK(arithmeticCompareNegateLeft(42, -42) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompareNegateLeft(42, -43) == COMPARE_RESULT_GREATER); } SECTION("unsigned vs unsigned") { - CHECK( - (arithmeticCompareNegateLeft(42, 42) == COMPARE_RESULT_LESS)); + CHECK(arithmeticCompareNegateLeft(42, 42) == COMPARE_RESULT_LESS); } } TEST_CASE("arithmeticCompareNegateRight()") { SECTION("int vs unsigned") { - CHECK((arithmeticCompareNegateRight(1, 0) == COMPARE_RESULT_GREATER)); - CHECK( - (arithmeticCompareNegateRight(-41, 42) == COMPARE_RESULT_GREATER)); - CHECK((arithmeticCompareNegateRight(-42, 42) == COMPARE_RESULT_EQUAL)); - CHECK((arithmeticCompareNegateRight(-43, 42) == COMPARE_RESULT_LESS)); + CHECK(arithmeticCompareNegateRight(1, 0) == COMPARE_RESULT_GREATER); + CHECK(arithmeticCompareNegateRight(-41, 42) == COMPARE_RESULT_GREATER); + CHECK(arithmeticCompareNegateRight(-42, 42) == COMPARE_RESULT_EQUAL); + CHECK(arithmeticCompareNegateRight(-43, 42) == COMPARE_RESULT_LESS); } SECTION("unsigned vs unsigned") { - CHECK((arithmeticCompareNegateRight(42, 42) == - COMPARE_RESULT_GREATER)); + CHECK(arithmeticCompareNegateRight(42, 42) == + COMPARE_RESULT_GREATER); } } diff --git a/extras/tests/Misc/conflicts.cpp b/extras/tests/Misc/conflicts.cpp index 991a94ef7..75c6c11df 100644 --- a/extras/tests/Misc/conflicts.cpp +++ b/extras/tests/Misc/conflicts.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License // Include any header that might use the conflicting macros @@ -52,5 +52,11 @@ #define BLOCKSIZE #define CAPACITY +// issue #1905 +#define _current + +// issue #1914 +#define V6 6 + // catch.hpp mutes several warnings, this file also allows to detect them #include "ArduinoJson.h" diff --git a/extras/tests/Misc/custom_string.hpp b/extras/tests/Misc/custom_string.hpp index 3c5b7c145..4a6a5a735 100644 --- a/extras/tests/Misc/custom_string.hpp +++ b/extras/tests/Misc/custom_string.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #pragma once diff --git a/extras/tests/Misc/deprecated.cpp b/extras/tests/Misc/deprecated.cpp deleted file mode 100644 index 646ca0566..000000000 --- a/extras/tests/Misc/deprecated.cpp +++ /dev/null @@ -1,115 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON -// MIT License - -#define ARDUINOJSON_DEPRECATED(msg) // nothing - -#include -#include - -TEST_CASE("Deprecated features") { - StaticJsonDocument<256> doc; - const char* s = "hello"; - doc["s"] = s; - doc["c"] = 42; - doc["a"].add(s); - doc["a"].add(42); - - SECTION("JsonVariant::add(char)") { - JsonVariant v = doc.to(); - v.add('*'); - REQUIRE(v[0] == 42); - } - - SECTION("JsonVariant::as()") { - JsonVariant v = doc["s"]; - REQUIRE(v.as() == s); - } - - SECTION("JsonVariant::as()") { - JsonVariant v = doc["c"]; - REQUIRE(v.as() == '*'); - } - - SECTION("JsonVariant::is()") { - JsonVariant v = doc["s"]; - REQUIRE(v.is() == true); - } - - SECTION("JsonVariant::is()") { - JsonVariant v = doc["c"]; - REQUIRE(v.is() == true); - } - - SECTION("JsonVariant::set(char)") { - JsonVariant v = doc.to(); - v.set('*'); - REQUIRE(v.as() == 42); - } - - SECTION("JsonVariantConst::as()") { - JsonVariantConst v = doc["s"]; - REQUIRE(v.as() == s); - } - - SECTION("JsonVariantConst::as()") { - JsonVariantConst v = doc["c"]; - REQUIRE(v.as() == '*'); - } - - SECTION("JsonVariantConst::is()") { - JsonVariantConst v = doc["s"]; - REQUIRE(v.is() == true); - } - - SECTION("JsonVariantConst::is()") { - JsonVariantConst v = doc["c"]; - REQUIRE(v.is() == true); - } - - SECTION("MemberProxy::as()") { - REQUIRE(doc["s"].as() == s); - } - - SECTION("MemberProxy::as()") { - REQUIRE(doc["c"].as() == '*'); - } - - SECTION("MemberProxy::as()") { - doc["x"].set('*'); - REQUIRE(doc["x"] == 42); - } - - SECTION("MemberProxy::is()") { - REQUIRE(doc["s"].is() == true); - REQUIRE(doc["c"].is() == false); - } - - SECTION("MemberProxy::is()") { - REQUIRE(doc["c"].is() == true); - REQUIRE(doc["s"].is() == false); - } - - SECTION("ElementProxy::as()") { - REQUIRE(doc["a"][0].as() == s); - } - - SECTION("ElementProxy::as()") { - REQUIRE(doc["a"][1].as() == '*'); - } - - SECTION("ElementProxy::as()") { - doc["a"][0].set('*'); - REQUIRE(doc["a"][0] == 42); - } - - SECTION("ElementProxy::is()") { - REQUIRE(doc["a"][0].is() == true); - REQUIRE(doc["a"][1].is() == false); - } - - SECTION("ElementProxy::is()") { - REQUIRE(doc["a"][1].is() == true); - REQUIRE(doc["a"][0].is() == false); - } -} diff --git a/extras/tests/Misc/issue1967.cpp b/extras/tests/Misc/issue1967.cpp new file mode 100644 index 000000000..a8d6b948d --- /dev/null +++ b/extras/tests/Misc/issue1967.cpp @@ -0,0 +1,13 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2023, Benoit BLANCHON +// MIT License + +// we expect ArduinoJson.h to include +#define ARDUINOJSON_ENABLE_STD_STRING 1 + +// but we don't want it to included accidentally +#undef ARDUINO +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#define ARDUINOJSON_ENABLE_STRING_VIEW 0 + +#include diff --git a/extras/tests/Misc/printable.cpp b/extras/tests/Misc/printable.cpp index 7cec8f934..09c23ad18 100644 --- a/extras/tests/Misc/printable.cpp +++ b/extras/tests/Misc/printable.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -29,21 +29,21 @@ struct PrintAllAtOnce { template struct PrintableString : public Printable { - PrintableString(const char* s) : _str(s), _total(0) {} + PrintableString(const char* s) : str_(s), total_(0) {} virtual size_t printTo(Print& p) const { - size_t result = PrintPolicy::printStringTo(_str, p); - _total += result; + size_t result = PrintPolicy::printStringTo(str_, p); + total_ += result; return result; } size_t totalBytesWritten() const { - return _total; + return total_; } private: - std::string _str; - mutable size_t _total; + std::string str_; + mutable size_t total_; }; TEST_CASE("Printable") { diff --git a/extras/tests/Misc/unsigned_char.cpp b/extras/tests/Misc/unsigned_char.cpp index 7a5e3eefa..d3ee492a3 100644 --- a/extras/tests/Misc/unsigned_char.cpp +++ b/extras/tests/Misc/unsigned_char.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/Misc/version.cpp b/extras/tests/Misc/version.cpp index 486a86702..a91f159a1 100644 --- a/extras/tests/Misc/version.cpp +++ b/extras/tests/Misc/version.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/Misc/weird_strcmp.hpp b/extras/tests/Misc/weird_strcmp.hpp index ff755ef54..5463d7ec2 100644 --- a/extras/tests/Misc/weird_strcmp.hpp +++ b/extras/tests/Misc/weird_strcmp.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -8,7 +8,8 @@ // Issue #1198: strcmp() implementation that returns a value larger than 8-bit -namespace ARDUINOJSON_NAMESPACE { +ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE + int strcmp(const char* a, const char* b) { int result = ::strcmp(a, b); if (result > 0) @@ -26,4 +27,5 @@ int strncmp(const char* a, const char* b, size_t n) { return -214748364; return 0; } -} // namespace ARDUINOJSON_NAMESPACE + +ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/extras/tests/MixedConfiguration/CMakeLists.txt b/extras/tests/MixedConfiguration/CMakeLists.txt index 01d1216e3..c2c9dc5ca 100644 --- a/extras/tests/MixedConfiguration/CMakeLists.txt +++ b/extras/tests/MixedConfiguration/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License add_executable(MixedConfigurationTests @@ -19,6 +19,8 @@ add_executable(MixedConfigurationTests issue1707.cpp use_double_0.cpp use_double_1.cpp + use_long_long_0.cpp + use_long_long_1.cpp ) set_target_properties(MixedConfigurationTests PROPERTIES UNITY_BUILD OFF) @@ -27,5 +29,5 @@ add_test(MixedConfiguration MixedConfigurationTests) set_tests_properties(MixedConfiguration PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/MixedConfiguration/enable_alignment_0.cpp b/extras/tests/MixedConfiguration/enable_alignment_0.cpp index 426f516a1..569f84aa5 100644 --- a/extras/tests/MixedConfiguration/enable_alignment_0.cpp +++ b/extras/tests/MixedConfiguration/enable_alignment_0.cpp @@ -1,11 +1,11 @@ -#define ARDUINOJSON_NAMESPACE ArduinoJson_NoAlignment +#define ARDUINOJSON_VERSION_NAMESPACE NoAlignment #define ARDUINOJSON_ENABLE_ALIGNMENT 0 #include #include TEST_CASE("ARDUINOJSON_ENABLE_ALIGNMENT == 0") { - using namespace ARDUINOJSON_NAMESPACE; + using namespace ArduinoJson::detail; const size_t N = sizeof(void*); diff --git a/extras/tests/MixedConfiguration/enable_alignment_1.cpp b/extras/tests/MixedConfiguration/enable_alignment_1.cpp index 9abf50c84..56d48169a 100644 --- a/extras/tests/MixedConfiguration/enable_alignment_1.cpp +++ b/extras/tests/MixedConfiguration/enable_alignment_1.cpp @@ -4,7 +4,7 @@ #include TEST_CASE("ARDUINOJSON_ENABLE_ALIGNMENT == 1") { - using namespace ARDUINOJSON_NAMESPACE; + using namespace ArduinoJson::detail; const size_t N = sizeof(void*); diff --git a/extras/tests/MixedConfiguration/enable_comments_0.cpp b/extras/tests/MixedConfiguration/enable_comments_0.cpp index 6329021ae..a3ada5ea1 100644 --- a/extras/tests/MixedConfiguration/enable_comments_0.cpp +++ b/extras/tests/MixedConfiguration/enable_comments_0.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_ENABLE_COMMENTS 0 diff --git a/extras/tests/MixedConfiguration/enable_comments_1.cpp b/extras/tests/MixedConfiguration/enable_comments_1.cpp index 18462922d..5e0831c5b 100644 --- a/extras/tests/MixedConfiguration/enable_comments_1.cpp +++ b/extras/tests/MixedConfiguration/enable_comments_1.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_ENABLE_COMMENTS 1 diff --git a/extras/tests/MixedConfiguration/enable_infinity_1.cpp b/extras/tests/MixedConfiguration/enable_infinity_1.cpp index 19e0d5bfd..28a3461fb 100644 --- a/extras/tests/MixedConfiguration/enable_infinity_1.cpp +++ b/extras/tests/MixedConfiguration/enable_infinity_1.cpp @@ -5,7 +5,7 @@ #include namespace my { -using ARDUINOJSON_NAMESPACE::isinf; +using ArduinoJson::detail::isinf; } // namespace my TEST_CASE("ARDUINOJSON_ENABLE_INFINITY == 1") { diff --git a/extras/tests/MixedConfiguration/enable_nan_1.cpp b/extras/tests/MixedConfiguration/enable_nan_1.cpp index 34d94fcae..f9ae04a6b 100644 --- a/extras/tests/MixedConfiguration/enable_nan_1.cpp +++ b/extras/tests/MixedConfiguration/enable_nan_1.cpp @@ -5,7 +5,7 @@ #include namespace my { -using ARDUINOJSON_NAMESPACE::isnan; +using ArduinoJson::detail::isnan; } // namespace my TEST_CASE("ARDUINOJSON_ENABLE_NAN == 1") { diff --git a/extras/tests/MixedConfiguration/enable_progmem_1.cpp b/extras/tests/MixedConfiguration/enable_progmem_1.cpp index 9ddf7f263..2cc683d7c 100644 --- a/extras/tests/MixedConfiguration/enable_progmem_1.cpp +++ b/extras/tests/MixedConfiguration/enable_progmem_1.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_ENABLE_PROGMEM 1 @@ -51,7 +51,7 @@ TEST_CASE("Flash strings") { } TEST_CASE("parseNumber()") { // tables are in Flash - using ARDUINOJSON_NAMESPACE::parseNumber; + using ArduinoJson::detail::parseNumber; CHECK(parseNumber("1") == 1.f); CHECK(parseNumber("1.23") == 1.23f); @@ -93,7 +93,7 @@ TEST_CASE("memcpy_P") { } TEST_CASE("BoundedReader") { - using namespace ARDUINOJSON_NAMESPACE; + using namespace ArduinoJson::detail; SECTION("read") { BoundedReader reader(F("\x01\xFF"), 2); @@ -133,7 +133,7 @@ TEST_CASE("BoundedReader") { } TEST_CASE("Reader") { - using namespace ARDUINOJSON_NAMESPACE; + using namespace ArduinoJson::detail; SECTION("read()") { Reader reader(F("\x01\xFF\x00\x12")); diff --git a/extras/tests/MixedConfiguration/enable_string_deduplication_0.cpp b/extras/tests/MixedConfiguration/enable_string_deduplication_0.cpp index d9ca166e2..7277af945 100644 --- a/extras/tests/MixedConfiguration/enable_string_deduplication_0.cpp +++ b/extras/tests/MixedConfiguration/enable_string_deduplication_0.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 diff --git a/extras/tests/MixedConfiguration/enable_string_deduplication_1.cpp b/extras/tests/MixedConfiguration/enable_string_deduplication_1.cpp index 27fc18d68..d3b2285e3 100644 --- a/extras/tests/MixedConfiguration/enable_string_deduplication_1.cpp +++ b/extras/tests/MixedConfiguration/enable_string_deduplication_1.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 diff --git a/extras/tests/MixedConfiguration/issue1707.cpp b/extras/tests/MixedConfiguration/issue1707.cpp index befdee536..f8ca566b5 100644 --- a/extras/tests/MixedConfiguration/issue1707.cpp +++ b/extras/tests/MixedConfiguration/issue1707.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINO diff --git a/extras/tests/Cpp11/use_long_long_0.cpp b/extras/tests/MixedConfiguration/use_long_long_0.cpp similarity index 100% rename from extras/tests/Cpp11/use_long_long_0.cpp rename to extras/tests/MixedConfiguration/use_long_long_0.cpp diff --git a/extras/tests/Cpp11/use_long_long_1.cpp b/extras/tests/MixedConfiguration/use_long_long_1.cpp similarity index 100% rename from extras/tests/Cpp11/use_long_long_1.cpp rename to extras/tests/MixedConfiguration/use_long_long_1.cpp diff --git a/extras/tests/MsgPackDeserializer/CMakeLists.txt b/extras/tests/MsgPackDeserializer/CMakeLists.txt index f2435279c..a5442076a 100644 --- a/extras/tests/MsgPackDeserializer/CMakeLists.txt +++ b/extras/tests/MsgPackDeserializer/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License add_executable(MsgPackDeserializerTests @@ -20,5 +20,5 @@ add_test(MsgPackDeserializer MsgPackDeserializerTests) set_tests_properties(MsgPackDeserializer PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/MsgPackDeserializer/deserializeArray.cpp b/extras/tests/MsgPackDeserializer/deserializeArray.cpp index 4540bd052..356a9fe47 100644 --- a/extras/tests/MsgPackDeserializer/deserializeArray.cpp +++ b/extras/tests/MsgPackDeserializer/deserializeArray.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/MsgPackDeserializer/deserializeObject.cpp b/extras/tests/MsgPackDeserializer/deserializeObject.cpp index 7a0e7b842..4aeb5532a 100644 --- a/extras/tests/MsgPackDeserializer/deserializeObject.cpp +++ b/extras/tests/MsgPackDeserializer/deserializeObject.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/MsgPackDeserializer/deserializeStaticVariant.cpp b/extras/tests/MsgPackDeserializer/deserializeStaticVariant.cpp index 2d4093ca4..0e126ff29 100644 --- a/extras/tests/MsgPackDeserializer/deserializeStaticVariant.cpp +++ b/extras/tests/MsgPackDeserializer/deserializeStaticVariant.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/MsgPackDeserializer/deserializeVariant.cpp b/extras/tests/MsgPackDeserializer/deserializeVariant.cpp index be20b9cae..87f38d6e2 100644 --- a/extras/tests/MsgPackDeserializer/deserializeVariant.cpp +++ b/extras/tests/MsgPackDeserializer/deserializeVariant.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/MsgPackDeserializer/doubleToFloat.cpp b/extras/tests/MsgPackDeserializer/doubleToFloat.cpp index b0470de5b..794a37ed0 100644 --- a/extras/tests/MsgPackDeserializer/doubleToFloat.cpp +++ b/extras/tests/MsgPackDeserializer/doubleToFloat.cpp @@ -1,11 +1,11 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; template static void check(const char* input, T expected) { @@ -13,7 +13,7 @@ static void check(const char* input, T expected) { uint8_t* f = reinterpret_cast(&actual); const uint8_t* d = reinterpret_cast(input); doubleToFloat(d, f); - fixEndianess(actual); + fixEndianness(actual); CHECK(actual == expected); } diff --git a/extras/tests/MsgPackDeserializer/filter.cpp b/extras/tests/MsgPackDeserializer/filter.cpp index 57dd7bea9..78700db64 100644 --- a/extras/tests/MsgPackDeserializer/filter.cpp +++ b/extras/tests/MsgPackDeserializer/filter.cpp @@ -1,11 +1,13 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +#include + +using namespace ArduinoJson::detail; TEST_CASE("deserializeMsgPack() filter") { StaticJsonDocument<4096> doc; diff --git a/extras/tests/MsgPackDeserializer/incompleteInput.cpp b/extras/tests/MsgPackDeserializer/incompleteInput.cpp index 029facfc0..6a5638825 100644 --- a/extras/tests/MsgPackDeserializer/incompleteInput.cpp +++ b/extras/tests/MsgPackDeserializer/incompleteInput.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/MsgPackDeserializer/input_types.cpp b/extras/tests/MsgPackDeserializer/input_types.cpp index f46d4691e..783aaa2c1 100644 --- a/extras/tests/MsgPackDeserializer/input_types.cpp +++ b/extras/tests/MsgPackDeserializer/input_types.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/MsgPackDeserializer/misc.cpp b/extras/tests/MsgPackDeserializer/misc.cpp index 071717164..25137b358 100644 --- a/extras/tests/MsgPackDeserializer/misc.cpp +++ b/extras/tests/MsgPackDeserializer/misc.cpp @@ -1,10 +1,12 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include +#include + TEST_CASE("deserializeMsgPack() returns EmptyInput") { StaticJsonDocument<100> doc; diff --git a/extras/tests/MsgPackDeserializer/nestingLimit.cpp b/extras/tests/MsgPackDeserializer/nestingLimit.cpp index 6005f55bb..2936415a5 100644 --- a/extras/tests/MsgPackDeserializer/nestingLimit.cpp +++ b/extras/tests/MsgPackDeserializer/nestingLimit.cpp @@ -1,10 +1,12 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include +#include + #define SHOULD_WORK(expression) REQUIRE(DeserializationError::Ok == expression); #define SHOULD_FAIL(expression) \ REQUIRE(DeserializationError::TooDeep == expression); diff --git a/extras/tests/MsgPackDeserializer/notSupported.cpp b/extras/tests/MsgPackDeserializer/notSupported.cpp index 5e204cdf0..2be0f1ec5 100644 --- a/extras/tests/MsgPackDeserializer/notSupported.cpp +++ b/extras/tests/MsgPackDeserializer/notSupported.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/MsgPackSerializer/CMakeLists.txt b/extras/tests/MsgPackSerializer/CMakeLists.txt index 9a7721e9d..2f3d8cc76 100644 --- a/extras/tests/MsgPackSerializer/CMakeLists.txt +++ b/extras/tests/MsgPackSerializer/CMakeLists.txt @@ -1,5 +1,5 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License add_executable(MsgPackSerializerTests @@ -15,5 +15,5 @@ add_test(MsgPackSerializer MsgPackSerializerTests) set_tests_properties(MsgPackSerializer PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/MsgPackSerializer/destination_types.cpp b/extras/tests/MsgPackSerializer/destination_types.cpp index ae5806361..8b0dffa00 100644 --- a/extras/tests/MsgPackSerializer/destination_types.cpp +++ b/extras/tests/MsgPackSerializer/destination_types.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -9,7 +9,7 @@ TEST_CASE("serialize MsgPack to various destination types") { DynamicJsonDocument doc(4096); JsonObject object = doc.to(); object["hello"] = "world"; - const char *expected_result = "\x81\xA5hello\xA5world"; + const char* expected_result = "\x81\xA5hello\xA5world"; const size_t expected_length = 13; SECTION("std::string") { diff --git a/extras/tests/MsgPackSerializer/measure.cpp b/extras/tests/MsgPackSerializer/measure.cpp index d49bcd9ba..a6a4fc9dc 100644 --- a/extras/tests/MsgPackSerializer/measure.cpp +++ b/extras/tests/MsgPackSerializer/measure.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/MsgPackSerializer/misc.cpp b/extras/tests/MsgPackSerializer/misc.cpp index 52c53a7bd..4753dbf4e 100644 --- a/extras/tests/MsgPackSerializer/misc.cpp +++ b/extras/tests/MsgPackSerializer/misc.cpp @@ -3,7 +3,7 @@ #include template -void check(T value, const std::string &expected) { +void check(T value, const std::string& expected) { DynamicJsonDocument doc(4096); doc.to().set(value); char buffer[256] = ""; diff --git a/extras/tests/MsgPackSerializer/serializeArray.cpp b/extras/tests/MsgPackSerializer/serializeArray.cpp index 74de8f173..a8ec639c9 100644 --- a/extras/tests/MsgPackSerializer/serializeArray.cpp +++ b/extras/tests/MsgPackSerializer/serializeArray.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -41,7 +41,8 @@ TEST_CASE("serialize MsgPack array") { } SECTION("array 16") { - for (int i = 0; i < 16; i++) array.add(i); + for (int i = 0; i < 16; i++) + array.add(i); check(array, "\xDC\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D" @@ -50,7 +51,8 @@ TEST_CASE("serialize MsgPack array") { SECTION("array 32") { const char* nil = 0; - for (int i = 0; i < 65536; i++) array.add(nil); + for (int i = 0; i < 65536; i++) + array.add(nil); check(array, std::string("\xDD\x00\x01\x00\x00", 5) + std::string(65536, '\xc0')); diff --git a/extras/tests/MsgPackSerializer/serializeObject.cpp b/extras/tests/MsgPackSerializer/serializeObject.cpp index e5c167a61..881730743 100644 --- a/extras/tests/MsgPackSerializer/serializeObject.cpp +++ b/extras/tests/MsgPackSerializer/serializeObject.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/MsgPackSerializer/serializeVariant.cpp b/extras/tests/MsgPackSerializer/serializeVariant.cpp index c09195901..b8a021f92 100644 --- a/extras/tests/MsgPackSerializer/serializeVariant.cpp +++ b/extras/tests/MsgPackSerializer/serializeVariant.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include diff --git a/extras/tests/Numbers/CMakeLists.txt b/extras/tests/Numbers/CMakeLists.txt index 05e1e8949..48cf8c0f1 100644 --- a/extras/tests/Numbers/CMakeLists.txt +++ b/extras/tests/Numbers/CMakeLists.txt @@ -1,10 +1,7 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED OFF) - add_executable(NumbersTests convertNumber.cpp parseFloat.cpp @@ -13,10 +10,9 @@ add_executable(NumbersTests parseNumber.cpp ) - add_test(Numbers NumbersTests) set_tests_properties(Numbers PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/Numbers/convertNumber.cpp b/extras/tests/Numbers/convertNumber.cpp index 8c193dc30..ca0cc5e03 100644 --- a/extras/tests/Numbers/convertNumber.cpp +++ b/extras/tests/Numbers/convertNumber.cpp @@ -1,136 +1,131 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; TEST_CASE("canConvertNumber()") { SECTION("int8_t -> int8_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(127)) == true); - CHECK((canConvertNumber(-128)) == true); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(127) == true); + CHECK(canConvertNumber(-128) == true); } SECTION("int8_t -> int16_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(127)) == true); - CHECK((canConvertNumber(-128)) == true); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(127) == true); + CHECK(canConvertNumber(-128) == true); } SECTION("int8_t -> uint8_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(127)) == true); - CHECK((canConvertNumber(-128)) == false); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(127) == true); + CHECK(canConvertNumber(-128) == false); } SECTION("int8_t -> uint16_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(127)) == true); - CHECK((canConvertNumber(-128)) == false); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(127) == true); + CHECK(canConvertNumber(-128) == false); } SECTION("int16_t -> int8_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(127)) == true); - CHECK((canConvertNumber(128)) == false); - CHECK((canConvertNumber(-128)) == true); - CHECK((canConvertNumber(-129)) == false); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(127) == true); + CHECK(canConvertNumber(128) == false); + CHECK(canConvertNumber(-128) == true); + CHECK(canConvertNumber(-129) == false); } SECTION("int16_t -> uint8_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(255)) == true); - CHECK((canConvertNumber(256)) == false); - CHECK((canConvertNumber(-1)) == false); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(255) == true); + CHECK(canConvertNumber(256) == false); + CHECK(canConvertNumber(-1) == false); } SECTION("uint8_t -> int8_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(127)) == true); - CHECK((canConvertNumber(128)) == false); - CHECK((canConvertNumber(255)) == false); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(127) == true); + CHECK(canConvertNumber(128) == false); + CHECK(canConvertNumber(255) == false); } SECTION("uint8_t -> int16_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(127)) == true); - CHECK((canConvertNumber(128)) == true); - CHECK((canConvertNumber(255)) == true); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(127) == true); + CHECK(canConvertNumber(128) == true); + CHECK(canConvertNumber(255) == true); } SECTION("uint8_t -> uint8_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(127)) == true); - CHECK((canConvertNumber(128)) == true); - CHECK((canConvertNumber(255)) == true); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(127) == true); + CHECK(canConvertNumber(128) == true); + CHECK(canConvertNumber(255) == true); } SECTION("uint8_t -> uint16_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(127)) == true); - CHECK((canConvertNumber(128)) == true); - CHECK((canConvertNumber(255)) == true); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(127) == true); + CHECK(canConvertNumber(128) == true); + CHECK(canConvertNumber(255) == true); } SECTION("float -> int32_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(-2.147483904e9f)) == false); - CHECK((canConvertNumber(-2.147483648e+9f)) == true); - CHECK((canConvertNumber(2.14748352e+9f)) == true); - CHECK((canConvertNumber(2.14748365e+9f)) == false); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(-2.147483904e9f) == false); + CHECK(canConvertNumber(-2.147483648e+9f) == true); + CHECK(canConvertNumber(2.14748352e+9f) == true); + CHECK(canConvertNumber(2.14748365e+9f) == false); } SECTION("double -> int32_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(-2.147483649e+9)) == false); - CHECK((canConvertNumber(-2.147483648e+9)) == true); - CHECK((canConvertNumber(2.147483647e+9)) == true); - CHECK((canConvertNumber(2.147483648e+9)) == false); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(-2.147483649e+9) == false); + CHECK(canConvertNumber(-2.147483648e+9) == true); + CHECK(canConvertNumber(2.147483647e+9) == true); + CHECK(canConvertNumber(2.147483648e+9) == false); } SECTION("float -> uint32_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(-1.401298e-45f)) == false); - CHECK((canConvertNumber(4.29496704e+9f)) == true); - CHECK((canConvertNumber(4.294967296e+9f)) == false); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(-1.401298e-45f) == false); + CHECK(canConvertNumber(4.29496704e+9f) == true); + CHECK(canConvertNumber(4.294967296e+9f) == false); } -#if ARDUINOJSON_HAS_LONG_LONG SECTION("float -> int64_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(-9.22337204e+18f)) == true); - CHECK((canConvertNumber(9.22337149e+18f)) == true); - CHECK((canConvertNumber(9.22337204e+18f)) == false); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(-9.22337204e+18f) == true); + CHECK(canConvertNumber(9.22337149e+18f) == true); + CHECK(canConvertNumber(9.22337204e+18f) == false); } SECTION("double -> int64_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(-9.2233720368547758e+18)) == true); - CHECK((canConvertNumber(9.2233720368547748e+18)) == true); - CHECK((canConvertNumber(9.2233720368547758e+18)) == false); + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(-9.2233720368547758e+18) == true); + CHECK(canConvertNumber(9.2233720368547748e+18) == true); + CHECK(canConvertNumber(9.2233720368547758e+18) == false); } SECTION("float -> uint64_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(-1.401298e-45f)) == false); - CHECK((canConvertNumber(1.844674297419792384e+19f)) == - true); - CHECK((canConvertNumber(1.8446744073709551616e+19f)) == + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(-1.401298e-45f) == false); + CHECK(canConvertNumber(1.84467429741979238e+19f) == true); + CHECK(canConvertNumber(1.844674407370955161e+19f) == false); } SECTION("double -> uint64_t") { - CHECK((canConvertNumber(0)) == true); - CHECK((canConvertNumber(-4.94065645841247e-324)) == - false); - CHECK((canConvertNumber(1.8446744073709549568e+19)) == - true); - CHECK((canConvertNumber(1.8446744073709551616e+19)) == + CHECK(canConvertNumber(0) == true); + CHECK(canConvertNumber(-4.9406564584124e-324) == false); + CHECK(canConvertNumber(1.844674407370954958e+19) == true); + CHECK(canConvertNumber(1.844674407370955166e+19) == false); } -#endif } diff --git a/extras/tests/Numbers/parseDouble.cpp b/extras/tests/Numbers/parseDouble.cpp index 1ce9a02e7..301aa0ce0 100644 --- a/extras/tests/Numbers/parseDouble.cpp +++ b/extras/tests/Numbers/parseDouble.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_USE_DOUBLE 1 @@ -9,7 +9,7 @@ #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; void checkDouble(const char* input, double expected) { CAPTURE(input); diff --git a/extras/tests/Numbers/parseFloat.cpp b/extras/tests/Numbers/parseFloat.cpp index ec69cab9f..4e9c1d477 100644 --- a/extras/tests/Numbers/parseFloat.cpp +++ b/extras/tests/Numbers/parseFloat.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #define ARDUINOJSON_USE_DOUBLE 0 @@ -9,7 +9,7 @@ #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; void checkFloat(const char* input, float expected) { CAPTURE(input); diff --git a/extras/tests/Numbers/parseInteger.cpp b/extras/tests/Numbers/parseInteger.cpp index aae66e808..880da7640 100644 --- a/extras/tests/Numbers/parseInteger.cpp +++ b/extras/tests/Numbers/parseInteger.cpp @@ -1,12 +1,12 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; template void checkInteger(const char* input, T expected) { diff --git a/extras/tests/Numbers/parseNumber.cpp b/extras/tests/Numbers/parseNumber.cpp index eb52f3a5a..48163c150 100644 --- a/extras/tests/Numbers/parseNumber.cpp +++ b/extras/tests/Numbers/parseNumber.cpp @@ -1,19 +1,18 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson; +using namespace ArduinoJson::detail; TEST_CASE("Test unsigned integer overflow") { VariantData first, second; - first.init(); - second.init(); // Avoids MSVC warning C4127 (conditional expression is constant) - size_t integerSize = sizeof(Integer); + size_t integerSize = sizeof(JsonInteger); if (integerSize == 8) { parseNumber("18446744073709551615", first); @@ -29,11 +28,9 @@ TEST_CASE("Test unsigned integer overflow") { TEST_CASE("Test signed integer overflow") { VariantData first, second; - first.init(); - second.init(); // Avoids MSVC warning C4127 (conditional expression is constant) - size_t integerSize = sizeof(Integer); + size_t integerSize = sizeof(JsonInteger); if (integerSize == 8) { parseNumber("-9223372036854775808", first); @@ -49,7 +46,6 @@ TEST_CASE("Test signed integer overflow") { TEST_CASE("Invalid value") { VariantData result; - result.init(); parseNumber("6a3", result); diff --git a/extras/tests/TextFormatter/CMakeLists.txt b/extras/tests/TextFormatter/CMakeLists.txt index 57a3f85b2..2bc4a899d 100644 --- a/extras/tests/TextFormatter/CMakeLists.txt +++ b/extras/tests/TextFormatter/CMakeLists.txt @@ -1,8 +1,8 @@ # ArduinoJson - https://arduinojson.org -# Copyright © 2014-2022, Benoit BLANCHON +# Copyright © 2014-2023, Benoit BLANCHON # MIT License -add_executable(TextFormatterTests +add_executable(TextFormatterTests writeFloat.cpp writeInteger.cpp writeString.cpp @@ -14,5 +14,5 @@ add_test(TextFormatter TextFormatterTests) set_tests_properties(TextFormatter PROPERTIES - LABELS "Catch" + LABELS "Catch" ) diff --git a/extras/tests/TextFormatter/writeFloat.cpp b/extras/tests/TextFormatter/writeFloat.cpp index 87eef3d94..8e4bd7e78 100644 --- a/extras/tests/TextFormatter/writeFloat.cpp +++ b/extras/tests/TextFormatter/writeFloat.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -11,13 +11,13 @@ #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; template void check(TFloat input, const std::string& expected) { std::string output; Writer sb(output); - TextFormatter > writer(sb); + TextFormatter> writer(sb); writer.writeFloat(input); REQUIRE(writer.bytesWritten() == output.size()); CHECK(expected == output); diff --git a/extras/tests/TextFormatter/writeInteger.cpp b/extras/tests/TextFormatter/writeInteger.cpp index cc29fc0ff..20cbd29fa 100644 --- a/extras/tests/TextFormatter/writeInteger.cpp +++ b/extras/tests/TextFormatter/writeInteger.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -9,7 +9,7 @@ #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; template void checkWriteInteger(T value, std::string expected) { diff --git a/extras/tests/TextFormatter/writeString.cpp b/extras/tests/TextFormatter/writeString.cpp index 67b12b502..2be9191cf 100644 --- a/extras/tests/TextFormatter/writeString.cpp +++ b/extras/tests/TextFormatter/writeString.cpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2022, Benoit BLANCHON +// Copyright © 2014-2023, Benoit BLANCHON // MIT License #include @@ -7,7 +7,7 @@ #include #include -using namespace ARDUINOJSON_NAMESPACE; +using namespace ArduinoJson::detail; void check(const char* input, std::string expected) { char output[64] = {0}; diff --git a/extras/tests/catch/CMakeLists.txt b/extras/tests/catch/CMakeLists.txt index 776a07a00..c5fb5fb83 100644 --- a/extras/tests/catch/CMakeLists.txt +++ b/extras/tests/catch/CMakeLists.txt @@ -2,7 +2,7 @@ # Copyright Benoit Blanchon 2014-2021 # MIT License -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED OFF) add_library(catch @@ -12,10 +12,10 @@ add_library(catch target_include_directories(catch PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} ) -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - # prevent "xxx will change in GCC x.x" with arm-linux-gnueabihf-gcc - target_compile_options(catch PRIVATE -Wno-psabi) +if(MINGW) + # prevent "too many sections (32837)" with MinGW + target_compile_options(catch PRIVATE -Wa,-mbig-obj) endif() diff --git a/extras/tests/catch/catch.hpp b/extras/tests/catch/catch.hpp index fdb046fe4..9b309bddc 100644 --- a/extras/tests/catch/catch.hpp +++ b/extras/tests/catch/catch.hpp @@ -1,17 +1,21 @@ /* - * Catch v1.12.2 - * Generated: 2018-05-14 15:10:01.112442 + * Catch v2.13.10 + * Generated: 2022-10-16 11:01:23.452308 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly - * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. + * Copyright (c) 2022 Two Blue Cubes Ltd. All rights reserved. * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +// start catch.hpp -#define TWOBLUECUBES_CATCH_HPP_INCLUDED + +#define CATCH_VERSION_MAJOR 2 +#define CATCH_VERSION_MINOR 13 +#define CATCH_VERSION_PATCH 10 #ifdef __clang__ # pragma clang system_header @@ -19,36 +23,69 @@ # pragma GCC system_header #endif -// #included from: internal/catch_suppress_warnings.h +// start catch_suppress_warnings.h #ifdef __clang__ # ifdef __ICC // icpc defines the __clang__ macro # pragma warning(push) # pragma warning(disable: 161 1682) # else // __ICC -# pragma clang diagnostic ignored "-Wglobal-constructors" -# pragma clang diagnostic ignored "-Wvariadic-macros" -# pragma clang diagnostic ignored "-Wc99-extensions" -# pragma clang diagnostic ignored "-Wunused-variable" # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wpadded" -# pragma clang diagnostic ignored "-Wc++98-compat" -# pragma clang diagnostic ignored "-Wc++98-compat-pedantic" # pragma clang diagnostic ignored "-Wswitch-enum" # pragma clang diagnostic ignored "-Wcovered-switch-default" # endif #elif defined __GNUC__ -# pragma GCC diagnostic ignored "-Wvariadic-macros" -# pragma GCC diagnostic ignored "-Wunused-variable" -# pragma GCC diagnostic ignored "-Wparentheses" + // Because REQUIREs trigger GCC's -Wparentheses, and because still + // supported version of g++ have only buggy support for _Pragmas, + // Wparentheses have to be suppressed globally. +# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details # pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-variable" # pragma GCC diagnostic ignored "-Wpadded" #endif +// end catch_suppress_warnings.h #if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) # define CATCH_IMPL +# define CATCH_CONFIG_ALL_PARTS +#endif + +// In the impl file, we want to have access to all parts of the headers +// Can also be used to sanely support PCHs +#if defined(CATCH_CONFIG_ALL_PARTS) +# define CATCH_CONFIG_EXTERNAL_INTERFACES +# if defined(CATCH_CONFIG_DISABLE_MATCHERS) +# undef CATCH_CONFIG_DISABLE_MATCHERS +# endif +# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +# endif +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) +// start catch_platform.h + +// See e.g.: +// https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html +#ifdef __APPLE__ +# include +# if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \ + (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1) +# define CATCH_PLATFORM_MAC +# elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1) +# define CATCH_PLATFORM_IPHONE +# endif + +#elif defined(linux) || defined(__linux) || defined(__linux__) +# define CATCH_PLATFORM_LINUX + +#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) +# define CATCH_PLATFORM_WINDOWS #endif +// end catch_platform.h + #ifdef CATCH_IMPL # ifndef CLARA_CONFIG_MAIN # define CLARA_CONFIG_MAIN_NOT_DEFINED @@ -56,93 +93,106 @@ # endif #endif -// #included from: internal/catch_notimplemented_exception.h -#define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED +// start catch_user_interfaces.h -// #included from: catch_common.h -#define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED +namespace Catch { + unsigned int rngSeed(); +} + +// end catch_user_interfaces.h +// start catch_tag_alias_autoregistrar.h -// #included from: catch_compiler_capabilities.h -#define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED +// start catch_common.h -// Detect a number of compiler features - mostly C++11/14 conformance - by compiler +// start catch_compiler_capabilities.h + +// Detect a number of compiler features - by compiler // The following features are defined: // -// CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported? -// CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported? -// CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods -// CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported? -// CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported -// CATCH_CONFIG_CPP11_LONG_LONG : is long long supported? -// CATCH_CONFIG_CPP11_OVERRIDE : is override supported? -// CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr) -// CATCH_CONFIG_CPP11_SHUFFLE : is std::shuffle supported? -// CATCH_CONFIG_CPP11_TYPE_TRAITS : are type_traits and enable_if supported? - -// CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported? - -// CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported? // CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? +// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? // **************** // Note to maintainers: if new toggles are added please document them // in configuration.md, too // **************** // In general each macro has a _NO_ form -// (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature. +// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. // Many features, at point of detection, define an _INTERNAL_ macro, so they // can be combined, en-mass, with the _NO_ forms later. -// All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11 - #ifdef __cplusplus -# if __cplusplus >= 201103L -# define CATCH_CPP11_OR_GREATER +# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) +# define CATCH_CPP14_OR_GREATER # endif -# if __cplusplus >= 201402L -# define CATCH_CPP14_OR_GREATER +# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +# define CATCH_CPP17_OR_GREATER # endif #endif -#ifdef __clang__ +// Only GCC compiler should be used in this block, so other compilers trying to +// mask themselves as GCC should be ignored. +#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) -# if __has_feature(cxx_nullptr) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# endif +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) + +#endif -# if __has_feature(cxx_noexcept) -# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT +#if defined(__clang__) + +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) + +// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug +// which results in calls to destructors being emitted for each temporary, +// without a matching initialization. In practice, this can result in something +// like `std::string::~string` being called on an uninitialized value. +// +// For example, this code will likely segfault under IBM XL: +// ``` +// REQUIRE(std::string("12") + "34" == "1234") +// ``` +// +// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented. +# if !defined(__ibmxl__) && !defined(__CUDACC__) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */ # endif -# if defined(CATCH_CPP11_OR_GREATER) -# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ - _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) -# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \ - _Pragma( "clang diagnostic pop" ) - -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ - _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) -# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ - _Pragma( "clang diagnostic pop" ) -# endif +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ + _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") + +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) + +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) #endif // __clang__ //////////////////////////////////////////////////////////////////////////////// -// We know some environments not to support full POSIX signals -#if defined(__CYGWIN__) || defined(__QNX__) - -# if !defined(CATCH_CONFIG_POSIX_SIGNALS) -# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS -# endif +// Assume that non-Windows platforms support posix signals by default +#if !defined(CATCH_PLATFORM_WINDOWS) + #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS +#endif +//////////////////////////////////////////////////////////////////////////////// +// We know some environments not to support full POSIX signals +#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) + #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS #endif #ifdef __OS400__ @@ -150,6 +200,25 @@ # define CATCH_CONFIG_COLOUR_NONE #endif +//////////////////////////////////////////////////////////////////////////////// +// Android somehow still does not support std::to_string +#if defined(__ANDROID__) +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING +# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Not all Windows environments support SEH properly +#if defined(__MINGW32__) +# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH +#endif + +//////////////////////////////////////////////////////////////////////////////// +// PS4 +#if defined(__ORBIS__) +# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE +#endif + //////////////////////////////////////////////////////////////////////////////// // Cygwin #ifdef __CYGWIN__ @@ -157,219 +226,245 @@ // Required for some versions of Cygwin to declare gettimeofday // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin # define _BSD_SOURCE +// some versions of cygwin (most) do not support std::to_string. Use the libstd check. +// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 +# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ + && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) -#endif // __CYGWIN__ - -//////////////////////////////////////////////////////////////////////////////// -// Borland -#ifdef __BORLANDC__ +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING -#endif // __BORLANDC__ +# endif +#endif // __CYGWIN__ //////////////////////////////////////////////////////////////////////////////// -// EDG -#ifdef __EDG_VERSION__ - -#endif // __EDG_VERSION__ +// Visual C++ +#if defined(_MSC_VER) -//////////////////////////////////////////////////////////////////////////////// -// Digital Mars -#ifdef __DMC__ +// Universal Windows platform does not support SEH +// Or console colours (or console at all...) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +# define CATCH_CONFIG_COLOUR_NONE +# else +# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH +# endif -#endif // __DMC__ +# if !defined(__clang__) // Handle Clang masquerading for msvc -//////////////////////////////////////////////////////////////////////////////// -// GCC -#ifdef __GNUC__ +// MSVC traditional preprocessor needs some workaround for __VA_ARGS__ +// _MSVC_TRADITIONAL == 0 means new conformant preprocessor +// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor +# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) +# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +# endif // MSVC_TRADITIONAL -# if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# endif +// Only do this if we're not using clang on Windows, which uses `diagnostic push` & `diagnostic pop` +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) +# endif // __clang__ -// - otherwise more recent versions define __cplusplus >= 201103L -// and will get picked up below +#endif // _MSC_VER -#endif // __GNUC__ +#if defined(_REENTRANT) || defined(_MSC_VER) +// Enable async processing, as -pthread is specified or no additional linking is required +# define CATCH_INTERNAL_CONFIG_USE_ASYNC +#endif // _MSC_VER //////////////////////////////////////////////////////////////////////////////// -// Visual C++ -#ifdef _MSC_VER - -#define CATCH_INTERNAL_CONFIG_WINDOWS_SEH - -#if (_MSC_VER >= 1600) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR +// Check if we are compiled with -fno-exceptions or equivalent +#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) +# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED #endif -#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) -#define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -#define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -#define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE -#define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS -#endif - -#endif // _MSC_VER - //////////////////////////////////////////////////////////////////////////////// +// DJGPP +#ifdef __DJGPP__ +# define CATCH_INTERNAL_CONFIG_NO_WCHAR +#endif // __DJGPP__ -// Use variadic macros if the compiler supports them -#if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \ - ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \ - ( defined __GNUC__ && __GNUC__ >= 3 ) || \ - ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L ) - -#define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS - +//////////////////////////////////////////////////////////////////////////////// +// Embarcadero C++Build +#if defined(__BORLANDC__) + #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN #endif -// Use __COUNTER__ if the compiler supports it -#if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \ - ( defined __GNUC__ && ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3 )) ) || \ - ( defined __clang__ && __clang_major__ >= 3 ) +//////////////////////////////////////////////////////////////////////////////// -// Use of __COUNTER__ is suppressed during code analysis in CLion/AppCode 2017.2.x and former, -// because __COUNTER__ is not properly handled by it. -// This does not affect compilation -#if ( !defined __JETBRAINS_IDE__ || __JETBRAINS_IDE__ >= 20170300L ) +// Use of __COUNTER__ is suppressed during code analysis in +// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly +// handled by it. +// Otherwise all supported compilers support COUNTER macro, +// but user still might want to turn it off +#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) #define CATCH_INTERNAL_CONFIG_COUNTER #endif -#endif - //////////////////////////////////////////////////////////////////////////////// -// C++ language feature support -// catch all support for C++11 -#if defined(CATCH_CPP11_OR_GREATER) - -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) -# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR -# endif +// RTX is a special version of Windows that is real time. +// This means that it is detected as Windows, but does not provide +// the same set of capabilities as real Windows does. +#if defined(UNDER_RTSS) || defined(RTX64_BUILD) + #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH + #define CATCH_INTERNAL_CONFIG_NO_ASYNC + #define CATCH_CONFIG_COLOUR_NONE +#endif -# ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT -# endif +#if !defined(_GLIBCXX_USE_C99_MATH_TR1) +#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER +#endif -# ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -# define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS -# endif +// Various stdlib support checks that require __has_include +#if defined(__has_include) + // Check if string_view is available and usable + #if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW + #endif + + // Check if optional is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if byte is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # include + # if defined(__cpp_lib_byte) && (__cpp_lib_byte > 0) + # define CATCH_INTERNAL_CONFIG_CPP17_BYTE + # endif + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if variant is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # if defined(__clang__) && (__clang_major__ < 8) + // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 + // fix should be in clang 8, workaround in libstdc++ 8.2 + # include + # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # define CATCH_CONFIG_NO_CPP17_VARIANT + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__clang__) && (__clang_major__ < 8) + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) +#endif // defined(__has_include) -# ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM -# define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM -# endif +#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) +# define CATCH_CONFIG_COUNTER +#endif +#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH) +# define CATCH_CONFIG_WINDOWS_SEH +#endif +// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. +#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_CONFIG_POSIX_SIGNALS +#endif +// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. +#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) +# define CATCH_CONFIG_WCHAR +#endif -# ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE -# define CATCH_INTERNAL_CONFIG_CPP11_TUPLE -# endif +#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) +# define CATCH_CONFIG_CPP11_TO_STRING +#endif -# ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS -# define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS -# endif +#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) +# define CATCH_CONFIG_CPP17_OPTIONAL +#endif -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) -# define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG -# endif +#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) +# define CATCH_CONFIG_CPP17_STRING_VIEW +#endif -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) -# define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE -# endif -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) -# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR -# endif -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) -# define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE -# endif -# if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) -# define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS -# endif +#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) +# define CATCH_CONFIG_CPP17_VARIANT +#endif -#endif // __cplusplus >= 201103L +#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) +# define CATCH_CONFIG_CPP17_BYTE +#endif -// Now set the actual defines based on the above + anything the user has configured -#if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_NULLPTR +#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) +# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_NOEXCEPT + +#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE) +# define CATCH_CONFIG_NEW_CAPTURE #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_GENERATED_METHODS + +#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +# define CATCH_CONFIG_DISABLE_EXCEPTIONS #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_NO_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_IS_ENUM + +#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) +# define CATCH_CONFIG_POLYFILL_ISNAN #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_TUPLE + +#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) +# define CATCH_CONFIG_USE_ASYNC #endif -#if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS) -# define CATCH_CONFIG_VARIADIC_MACROS + +#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) +# define CATCH_CONFIG_ANDROID_LOGWRITE #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_LONG_LONG + +#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) +# define CATCH_CONFIG_GLOBAL_NEXTAFTER #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_OVERRIDE + +// Even if we do not think the compiler has that warning, we still have +// to provide a macro that can be used by the code. +#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_UNIQUE_PTR +#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION #endif -#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) -# define CATCH_CONFIG_COUNTER +#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_SHUFFLE +#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS #endif -# if defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_NO_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_NO_CPP11) -# define CATCH_CONFIG_CPP11_TYPE_TRAITS -# endif -#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) -# define CATCH_CONFIG_WINDOWS_SEH +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS #endif -// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. -#if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) -# define CATCH_CONFIG_POSIX_SIGNALS +#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS #endif -#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS -# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS -#endif -#if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS -# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS +// The goal of this macro is to avoid evaluation of the arguments, but +// still have the compiler warn on problems inside... +#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) #endif -// noexcept support: -#if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT) -# define CATCH_NOEXCEPT noexcept -# define CATCH_NOEXCEPT_IS(x) noexcept(x) -#else -# define CATCH_NOEXCEPT throw() -# define CATCH_NOEXCEPT_IS(x) +#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#elif defined(__clang__) && (__clang_major__ < 5) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS #endif -// nullptr support -#ifdef CATCH_CONFIG_CPP11_NULLPTR -# define CATCH_NULL nullptr -#else -# define CATCH_NULL NULL +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS #endif -// override support -#ifdef CATCH_CONFIG_CPP11_OVERRIDE -# define CATCH_OVERRIDE override +#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +#define CATCH_TRY if ((true)) +#define CATCH_CATCH_ALL if ((false)) +#define CATCH_CATCH_ANON(type) if ((false)) #else -# define CATCH_OVERRIDE +#define CATCH_TRY try +#define CATCH_CATCH_ALL catch (...) +#define CATCH_CATCH_ANON(type) catch (type) #endif -// unique_ptr support -#ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR -# define CATCH_AUTO_PTR( T ) std::unique_ptr -#else -# define CATCH_AUTO_PTR( T ) std::auto_ptr +#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) +#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR #endif +// end catch_compiler_capabilities.h #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) #ifdef CATCH_CONFIG_COUNTER @@ -378,95 +473,48 @@ # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) #endif -#define INTERNAL_CATCH_STRINGIFY2( expr ) #expr -#define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) +#include +#include +#include -#include -#include +// We need a dummy global operator<< so we can bring it into Catch namespace later +struct Catch_global_namespace_dummy {}; +std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); namespace Catch { - struct IConfig; - struct CaseSensitive { enum Choice { Yes, No }; }; class NonCopyable { -#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS NonCopyable( NonCopyable const& ) = delete; NonCopyable( NonCopyable && ) = delete; NonCopyable& operator = ( NonCopyable const& ) = delete; NonCopyable& operator = ( NonCopyable && ) = delete; -#else - NonCopyable( NonCopyable const& info ); - NonCopyable& operator = ( NonCopyable const& ); -#endif protected: - NonCopyable() {} + NonCopyable(); virtual ~NonCopyable(); }; - class SafeBool { - public: - typedef void (SafeBool::*type)() const; - - static type makeSafe( bool value ) { - return value ? &SafeBool::trueValue : 0; - } - private: - void trueValue() const {} - }; - - template - void deleteAll( ContainerT& container ) { - typename ContainerT::const_iterator it = container.begin(); - typename ContainerT::const_iterator itEnd = container.end(); - for(; it != itEnd; ++it ) - delete *it; - } - template - void deleteAllValues( AssociativeContainerT& container ) { - typename AssociativeContainerT::const_iterator it = container.begin(); - typename AssociativeContainerT::const_iterator itEnd = container.end(); - for(; it != itEnd; ++it ) - delete it->second; - } - - bool startsWith( std::string const& s, std::string const& prefix ); - bool startsWith( std::string const& s, char prefix ); - bool endsWith( std::string const& s, std::string const& suffix ); - bool endsWith( std::string const& s, char suffix ); - bool contains( std::string const& s, std::string const& infix ); - void toLowerInPlace( std::string& s ); - std::string toLower( std::string const& s ); - std::string trim( std::string const& str ); - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); - - struct pluralise { - pluralise( std::size_t count, std::string const& label ); - - friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); + struct SourceLineInfo { - std::size_t m_count; - std::string m_label; - }; + SourceLineInfo() = delete; + SourceLineInfo( char const* _file, std::size_t _line ) noexcept + : file( _file ), + line( _line ) + {} - struct SourceLineInfo { + SourceLineInfo( SourceLineInfo const& other ) = default; + SourceLineInfo& operator = ( SourceLineInfo const& ) = default; + SourceLineInfo( SourceLineInfo&& ) noexcept = default; + SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default; - SourceLineInfo(); - SourceLineInfo( char const* _file, std::size_t _line ); -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - SourceLineInfo(SourceLineInfo const& other) = default; - SourceLineInfo( SourceLineInfo && ) = default; - SourceLineInfo& operator = ( SourceLineInfo const& ) = default; - SourceLineInfo& operator = ( SourceLineInfo && ) = default; -# endif - bool empty() const; - bool operator == ( SourceLineInfo const& other ) const; - bool operator < ( SourceLineInfo const& other ) const; + bool empty() const noexcept { return file[0] == '\0'; } + bool operator == ( SourceLineInfo const& other ) const noexcept; + bool operator < ( SourceLineInfo const& other ) const noexcept; char const* file; std::size_t line; @@ -474,24 +522,17 @@ namespace Catch { std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); - // This is just here to avoid compiler warnings with macro constants and boolean literals - inline bool isTrue( bool value ){ return value; } - inline bool alwaysTrue() { return true; } - inline bool alwaysFalse() { return false; } - - void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ); - - void seedRng( IConfig const& config ); - unsigned int rngSeed(); + // Bring in operator<< from global namespace into Catch namespace + // This is necessary because the overload of operator<< above makes + // lookup stop at namespace Catch + using ::operator<<; // Use this in variadic streaming macros to allow // >> +StreamEndStop // as well as // >> stuff +StreamEndStop struct StreamEndStop { - std::string operator+() { - return std::string(); - } + std::string operator+() const; }; template T const& operator + ( T const& value, StreamEndStop ) { @@ -499,363 +540,812 @@ namespace Catch { } } -#define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) -#define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO ); +#define CATCH_INTERNAL_LINEINFO \ + ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) +// end catch_common.h namespace Catch { - class NotImplementedException : public std::exception - { - public: - NotImplementedException( SourceLineInfo const& lineInfo ); - - virtual ~NotImplementedException() CATCH_NOEXCEPT {} - - virtual const char* what() const CATCH_NOEXCEPT; - - private: - std::string m_what; - SourceLineInfo m_lineInfo; + struct RegistrarForTagAliases { + RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); }; } // end namespace Catch -/////////////////////////////////////////////////////////////////////////////// -#define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) +#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION -// #included from: internal/catch_context.h -#define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED +// end catch_tag_alias_autoregistrar.h +// start catch_test_registry.h -// #included from: catch_interfaces_generators.h -#define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED +// start catch_interfaces_testcase.h -#include +#include namespace Catch { - struct IGeneratorInfo { - virtual ~IGeneratorInfo(); - virtual bool moveNext() = 0; - virtual std::size_t getCurrentIndex() const = 0; + class TestSpec; + + struct ITestInvoker { + virtual void invoke () const = 0; + virtual ~ITestInvoker(); }; - struct IGeneratorsForTest { - virtual ~IGeneratorsForTest(); + class TestCase; + struct IConfig; - virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0; - virtual bool moveNext() = 0; + struct ITestCaseRegistry { + virtual ~ITestCaseRegistry(); + virtual std::vector const& getAllTests() const = 0; + virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; }; - IGeneratorsForTest* createGeneratorsForTest(); + bool isThrowSafe( TestCase const& testCase, IConfig const& config ); + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); -} // end namespace Catch +} -// #included from: catch_ptr.hpp -#define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED +// end catch_interfaces_testcase.h +// start catch_stringref.h -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpadded" -#endif +#include +#include +#include +#include namespace Catch { - // An intrusive reference counting smart pointer. - // T must implement addRef() and release() methods - // typically implementing the IShared interface - template - class Ptr { + /// A non-owning string class (similar to the forthcoming std::string_view) + /// Note that, because a StringRef may be a substring of another string, + /// it may not be null terminated. + class StringRef { public: - Ptr() : m_p( CATCH_NULL ){} - Ptr( T* p ) : m_p( p ){ - if( m_p ) - m_p->addRef(); - } - Ptr( Ptr const& other ) : m_p( other.m_p ){ - if( m_p ) - m_p->addRef(); - } - ~Ptr(){ - if( m_p ) - m_p->release(); - } - void reset() { - if( m_p ) - m_p->release(); - m_p = CATCH_NULL; - } - Ptr& operator = ( T* p ){ - Ptr temp( p ); - swap( temp ); - return *this; - } - Ptr& operator = ( Ptr const& other ){ - Ptr temp( other ); - swap( temp ); - return *this; - } - void swap( Ptr& other ) { std::swap( m_p, other.m_p ); } - T* get() const{ return m_p; } - T& operator*() const { return *m_p; } - T* operator->() const { return m_p; } - bool operator !() const { return m_p == CATCH_NULL; } - operator SafeBool::type() const { return SafeBool::makeSafe( m_p != CATCH_NULL ); } + using size_type = std::size_t; + using const_iterator = const char*; private: - T* m_p; - }; + static constexpr char const* const s_empty = ""; - struct IShared : NonCopyable { - virtual ~IShared(); - virtual void addRef() const = 0; - virtual void release() const = 0; - }; + char const* m_start = s_empty; + size_type m_size = 0; + + public: // construction + constexpr StringRef() noexcept = default; - template - struct SharedImpl : T { + StringRef( char const* rawChars ) noexcept; - SharedImpl() : m_rc( 0 ){} + constexpr StringRef( char const* rawChars, size_type size ) noexcept + : m_start( rawChars ), + m_size( size ) + {} + + StringRef( std::string const& stdString ) noexcept + : m_start( stdString.c_str() ), + m_size( stdString.size() ) + {} - virtual void addRef() const { - ++m_rc; + explicit operator std::string() const { + return std::string(m_start, m_size); } - virtual void release() const { - if( --m_rc == 0 ) - delete this; + + public: // operators + auto operator == ( StringRef const& other ) const noexcept -> bool; + auto operator != (StringRef const& other) const noexcept -> bool { + return !(*this == other); } - mutable unsigned int m_rc; - }; + auto operator[] ( size_type index ) const noexcept -> char { + assert(index < m_size); + return m_start[index]; + } -} // end namespace Catch + public: // named queries + constexpr auto empty() const noexcept -> bool { + return m_size == 0; + } + constexpr auto size() const noexcept -> size_type { + return m_size; + } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif + // Returns the current start pointer. If the StringRef is not + // null-terminated, throws std::domain_exception + auto c_str() const -> char const*; -namespace Catch { + public: // substrings and searches + // Returns a substring of [start, start + length). + // If start + length > size(), then the substring is [start, size()). + // If start > size(), then the substring is empty. + auto substr( size_type start, size_type length ) const noexcept -> StringRef; - class TestCase; - class Stream; - struct IResultCapture; - struct IRunner; - struct IGeneratorsForTest; - struct IConfig; + // Returns the current start pointer. May not be null-terminated. + auto data() const noexcept -> char const*; - struct IContext - { - virtual ~IContext(); + constexpr auto isNullTerminated() const noexcept -> bool { + return m_start[m_size] == '\0'; + } - virtual IResultCapture* getResultCapture() = 0; - virtual IRunner* getRunner() = 0; - virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0; - virtual bool advanceGeneratorsForCurrentTest() = 0; - virtual Ptr getConfig() const = 0; + public: // iterators + constexpr const_iterator begin() const { return m_start; } + constexpr const_iterator end() const { return m_start + m_size; } }; - struct IMutableContext : IContext - { - virtual ~IMutableContext(); - virtual void setResultCapture( IResultCapture* resultCapture ) = 0; - virtual void setRunner( IRunner* runner ) = 0; - virtual void setConfig( Ptr const& config ) = 0; - }; + auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; + auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; - IContext& getCurrentContext(); - IMutableContext& getCurrentMutableContext(); - void cleanUpContext(); - Stream createStream( std::string const& streamName ); + constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { + return StringRef( rawChars, size ); + } +} // namespace Catch +constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { + return Catch::StringRef( rawChars, size ); } -// #included from: internal/catch_test_registry.hpp -#define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED +// end catch_stringref.h +// start catch_preprocessor.hpp -// #included from: catch_interfaces_testcase.h -#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED -#include +#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ +#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) -namespace Catch { +#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ +// MSVC needs more evaluations +#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) +#else +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) +#endif - class TestSpec; +#define CATCH_REC_END(...) +#define CATCH_REC_OUT + +#define CATCH_EMPTY() +#define CATCH_DEFER(id) id CATCH_EMPTY() + +#define CATCH_REC_GET_END2() 0, CATCH_REC_END +#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 +#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 +#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT +#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) +#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) + +#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) + +#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) + +// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, +// and passes userdata as the first parameter to each invocation, +// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) +#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param) +#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ +#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ +#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) +#else +// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) +#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) +#endif - struct ITestCase : IShared { - virtual void invoke () const = 0; - protected: - virtual ~ITestCase(); - }; +#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ +#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) - class TestCase; - struct IConfig; +#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) - struct ITestCaseRegistry { - virtual ~ITestCaseRegistry(); - virtual std::vector const& getAllTests() const = 0; - virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) +#else +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) +#endif + +#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ + CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) + +#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) +#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) +#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) +#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3) +#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4) +#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5) +#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6) +#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7) +#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8) +#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9) +#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) + +#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N + +#define INTERNAL_CATCH_TYPE_GEN\ + template struct TypeList {};\ + template\ + constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ + template class...> struct TemplateTypeList{};\ + template class...Cs>\ + constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ + template\ + struct append;\ + template\ + struct rewrap;\ + template class, typename...>\ + struct create;\ + template class, typename>\ + struct convert;\ + \ + template \ + struct append { using type = T; };\ + template< template class L1, typename...E1, template class L2, typename...E2, typename...Rest>\ + struct append, L2, Rest...> { using type = typename append, Rest...>::type; };\ + template< template class L1, typename...E1, typename...Rest>\ + struct append, TypeList, Rest...> { using type = L1; };\ + \ + template< template class Container, template class List, typename...elems>\ + struct rewrap, List> { using type = TypeList>; };\ + template< template class Container, template class List, class...Elems, typename...Elements>\ + struct rewrap, List, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\ + \ + template