diff --git a/.gitignore b/.gitignore index b82214e9..c7e847c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,16 @@ json_unit json_benchmarks - fuzz-testing *.dSYM +*.o +*.gcno +*.gcda working -html +doc/xml +doc/html me.nlohmann.json.docset -android -doc/xml - benchmarks/files/numbers/*.json - -*.o diff --git a/.travis.yml b/.travis.yml index 929095be..ad1d12d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,175 +1,290 @@ +######################### +# project configuration # +######################### + +# C++ project language: cpp dist: trusty sudo: required + +################### +# global settings # +################### + env: global: # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created # via the "travis encrypt" command using the project repo's public key - secure: "m89SSgE+ASLO38rSKx7MTXK3n5NkP9bIx95jwY71YEiuFzib30PDJ/DifKnXxBjvy/AkCGztErQRk/8ZCvq+4HXozU2knEGnL/RUitvlwbhzfh2D4lmS3BvWBGS3N3NewoPBrRmdcvnT0xjOGXxtZaJ3P74TkB9GBnlz/HmKORA=" -# from http://stackoverflow.com/a/32127147/266378 + +################ +# build matrix # +################ + matrix: include: - - os: linux - compiler: gcc - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: ['g++-4.9', 'valgrind', 'python-pip', 'python-yaml'] - before_script: - - pip install --user git+git://github.com/eddyxu/cpp-coveralls.git - after_success: - - make clean - - touch src/json.hpp - - make json_unit CXXFLAGS="-fprofile-arcs -ftest-coverage -std=c++11 -lstdc++" CXX=$COMPILER - - test/json_unit "*" - - coveralls --build-root test --exclude src/catch.hpp --exclude src/unit-algorithms.cpp --exclude src/unit-allocator.cpp --exclude src/unit-capacity.cpp --exclude src/unit-class_const_iterator.cpp --exclude src/unit-class_iterator.cpp --exclude src/unit-class_lexer.cpp --exclude src/unit-class_parser.cpp --exclude src/unit-comparison.cpp --exclude src/unit-concepts.cpp --exclude src/unit-constructor1.cpp --exclude src/unit-constructor2.cpp --exclude src/unit-convenience.cpp --exclude src/unit-conversions.cpp --exclude src/unit-deserialization.cpp --exclude src/unit-element_access1.cpp --exclude src/unit-element_access2.cpp --exclude src/unit-inspection.cpp --exclude src/unit-iterator_wrapper.cpp --exclude src/unit-iterators1.cpp --exclude src/unit-iterators2.cpp --exclude src/unit-json_patch.cpp --exclude src/unit-json_pointer.cpp --exclude src/unit-modifiers.cpp --exclude src/unit-pointer_access.cpp --exclude src/unit-readme.cpp --exclude src/unit-reference_access.cpp --exclude src/unit-regression.cpp --exclude src/unit-serialization.cpp --exclude src/unit-testsuites.cpp --exclude src/unit-unicode.cpp --include ../src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9' - env: COMPILER=g++-4.9 - - os: linux - compiler: gcc - before_install: echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: ['g++-5', 'valgrind'] - coverity_scan: - project: - name: "nlohmann/json" - description: "Build submitted via Travis CI" - notification_email: niels.lohmann@gmail.com - build_command_prepend: "make clean ; sudo cp $(which g++-5) $(which g++)" - build_command: "make" - branch_pattern: coverity_scan - env: COMPILER=g++-5 + # Valgrind - - os: linux - compiler: gcc - addons: - apt: - sources: ['ubuntu-toolchain-r-test'] - packages: ['g++-6', 'valgrind'] - env: COMPILER=g++-6 + - os: linux + compiler: gcc + env: + - COMPILER=g++-4.9 + - SPECIAL=valgrind + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: [g++-4.9, valgrind] + after_success: + - valgrind --error-exitcode=1 --leak-check=full test/json_unit - # from https://github.com/travis-ci/travis-ci/issues/6120 - - os: linux - env: - - LLVM_VERSION=3.8.0 - - LLVM_ARCHIVE_PATH=$HOME/clang+llvm.tar.xz - - COMPILER=clang++ - - CPPFLAGS="-I $HOME/clang-$LLVM_VERSION/include/c++/v1" - - LDFLAGS=-lc++ - - PATH=$HOME/clang-$LLVM_VERSION/bin:$PATH - - LD_LIBRARY_PATH=$HOME/clang-$LLVM_VERSION/lib:$LD_LIBRARY_PATH - before_install: - - wget http://llvm.org/releases/$LLVM_VERSION/clang+llvm-$LLVM_VERSION-x86_64-linux-gnu-ubuntu-14.04.tar.xz -O $LLVM_ARCHIVE_PATH - - mkdir $HOME/clang-$LLVM_VERSION - - tar xf $LLVM_ARCHIVE_PATH -C $HOME/clang-$LLVM_VERSION --strip-components 1 + # Coveralls (http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/) - # Clang 3.5 is not able to compile the code, - # see https://travis-ci.org/nlohmann/json/jobs/126720186 + - os: linux + compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: ['g++-4.9', 'ruby'] + before_script: + - wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz + - tar xf lcov_1.11.orig.tar.gz + - sudo make -C lcov-1.11/ install + - gem install coveralls-lcov + after_success: + - make clean + - CXXFLAGS="--coverage -g -O0" CPPFLAGS="-DNDEBUG" make + - test/json_unit "*" + - coveralls --build-root test --exclude src/catch.hpp --exclude src/unit-algorithms.cpp --exclude src/unit-allocator.cpp --exclude src/unit-capacity.cpp --exclude src/unit-class_const_iterator.cpp --exclude src/unit-class_iterator.cpp --exclude src/unit-class_lexer.cpp --exclude src/unit-class_parser.cpp --exclude src/unit-comparison.cpp --exclude src/unit-concepts.cpp --exclude src/unit-constructor1.cpp --exclude src/unit-constructor2.cpp --exclude src/unit-convenience.cpp --exclude src/unit-conversions.cpp --exclude src/unit-deserialization.cpp --exclude src/unit-element_access1.cpp --exclude src/unit-element_access2.cpp --exclude src/unit-inspection.cpp --exclude src/unit-iterator_wrapper.cpp --exclude src/unit-iterators1.cpp --exclude src/unit-iterators2.cpp --exclude src/unit-json_patch.cpp --exclude src/unit-json_pointer.cpp --exclude src/unit-modifiers.cpp --exclude src/unit-pointer_access.cpp --exclude src/unit-readme.cpp --exclude src/unit-reference_access.cpp --exclude src/unit-regression.cpp --exclude src/unit-serialization.cpp --exclude src/unit-testsuites.cpp --exclude src/unit-unicode.cpp --include ../src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9' + - lcov --directory src --directory test/src --capture --output-file coverage.info --rc lcov_branch_coverage=1 --no-external + - lcov --remove coverage.info 'test/src/*' --output-file coverage.info --rc lcov_branch_coverage=1 + - lcov --list coverage.info --rc lcov_branch_coverage=1 + - coveralls-lcov --repo-token F9bs4Nop10JRgqPQXRcifyQKYhb3FczkS coverage.info + env: + - COMPILER=g++-4.9 + - SPECIAL=coveralls -# - os: linux -# compiler: clang -# addons: -# apt: -# sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6'] -# packages: ['clang-3.6', 'valgrind'] -# env: COMPILER=clang++-3.6 -# -# - os: linux -# compiler: clang -# addons: -# apt: -# sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7'] -# packages: ['clang-3.7', 'valgrind'] -# env: COMPILER=clang++-3.7 -# -# - os: linux -# compiler: clang -# addons: -# apt: -# sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.8'] -# packages: ['clang-3.8', 'valgrind'] -# env: COMPILER=clang++-3.8 + # Coverity (only for branch coverity_scan) - # - os: linux - # compiler: clang - # addons: - # apt: - # sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise'] - # packages: ['clang-3.9', 'valgrind'] - # env: COMPILER=clang++-3.9 + - os: linux + compiler: gcc + before_install: echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: ['g++-5', 'valgrind'] + coverity_scan: + project: + name: "nlohmann/json" + description: "Build submitted via Travis CI" + notification_email: niels.lohmann@gmail.com + build_command_prepend: "make clean ; sudo cp $(which g++-5) $(which g++)" + build_command: "make" + branch_pattern: coverity_scan + env: + - COMPILER=g++-5 + - SPECIAL=coverity - - os: osx - osx_image: beta-xcode6.1 - compiler: clang - env: - - COMPILER=clang - - CXXFLAGS=-lstdc++ + # OSX / Clang - - os: osx - osx_image: beta-xcode6.2 - compiler: clang - env: - - COMPILER=clang - - CXXFLAGS=-lstdc++ + - os: osx + osx_image: beta-xcode6.1 - - os: osx - osx_image: beta-xcode6.3 - compiler: clang - env: - - COMPILER=clang - - CXXFLAGS=-lstdc++ + - os: osx + osx_image: beta-xcode6.2 - - os: osx - osx_image: xcode6.4 - compiler: clang - env: - - COMPILER=clang - - CXXFLAGS=-lstdc++ + - os: osx + osx_image: beta-xcode6.3 - - os: osx - osx_image: xcode7.1 - compiler: clang - env: - - COMPILER=clang - - CXXFLAGS=-lstdc++ - - - os: osx - osx_image: xcode7.2 - compiler: clang - env: - - COMPILER=clang - - CXXFLAGS=-lstdc++ + - os: osx + osx_image: xcode6.4 - - os: osx - osx_image: xcode7.3 - compiler: clang - env: - - COMPILER=clang - - CXXFLAGS=-lstdc++ + - os: osx + osx_image: xcode7.1 - - os: osx - osx_image: xcode8 - compiler: clang - env: - - COMPILER=clang - - CXXFLAGS=-lstdc++ + - os: osx + osx_image: xcode7.2 + + - os: osx + osx_image: xcode7.3 + + - os: osx + osx_image: xcode8 + + # Linux / GCC + + - os: linux + compiler: gcc + env: COMPILER=g++-4.9 + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-4.9 + + - os: linux + compiler: gcc + env: COMPILER=g++-5 + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-5 + + - os: linux + compiler: gcc + env: COMPILER=g++-6 + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-6 + + # Linux / Clang + + - os: linux + env: LLVM_VERSION=3.6.0 + compiler: clang + + - os: linux + env: LLVM_VERSION=3.6.1 + compiler: clang + + - os: linux + env: LLVM_VERSION=3.6.2 + compiler: clang + + - os: linux + env: LLVM_VERSION=3.7.0 + compiler: clang + + - os: linux + env: LLVM_VERSION=3.7.1 + compiler: clang + + - os: linux + env: LLVM_VERSION=3.8.0 + compiler: clang + + - os: linux + env: LLVM_VERSION=3.8.1 + compiler: clang + +##################### +# installation step # +##################### + +# set directories to cache +cache: + directories: + - ${TRAVIS_BUILD_DIR}/deps/llvm-3.6.2 + - ${TRAVIS_BUILD_DIR}/deps/llvm-3.6.1 + - ${TRAVIS_BUILD_DIR}/deps/llvm-3.6.0 + - ${TRAVIS_BUILD_DIR}/deps/llvm-3.7.0 + - ${TRAVIS_BUILD_DIR}/deps/llvm-3.7.1 + - ${TRAVIS_BUILD_DIR}/deps/llvm-3.8.0 + - ${TRAVIS_BUILD_DIR}/deps/llvm-3.8.1 + + +install: + # create deps dir if not existing + - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" + - mkdir -p ${DEPS_DIR} + + # make sure CXX is correctly set + - if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi + + # install LLVM/clang when LLVM_VERSION is set + - | + if [[ "${LLVM_VERSION}" != "" ]]; then + LLVM_DIR=${DEPS_DIR}/llvm-${LLVM_VERSION} + if [[ -z "$(ls -A ${LLVM_DIR})" ]]; then + LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz" + LIBCXX_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxx-${LLVM_VERSION}.src.tar.xz" + LIBCXXABI_URL="http://llvm.org/releases/${LLVM_VERSION}/libcxxabi-${LLVM_VERSION}.src.tar.xz" + CLANG_URL="http://llvm.org/releases/${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-14.04.tar.xz" + mkdir -p ${LLVM_DIR} ${LLVM_DIR}/build ${LLVM_DIR}/projects/libcxx ${LLVM_DIR}/projects/libcxxabi ${LLVM_DIR}/clang + travis_retry wget --quiet -O - ${LLVM_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR} + travis_retry wget --quiet -O - ${LIBCXX_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR}/projects/libcxx + travis_retry wget --quiet -O - ${LIBCXXABI_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR}/projects/libcxxabi + travis_retry wget --quiet -O - ${CLANG_URL} | tar --strip-components=1 -xJ -C ${LLVM_DIR}/clang + (cd ${LLVM_DIR}/build && cmake .. -DCMAKE_INSTALL_PREFIX=${LLVM_DIR}/install -DCMAKE_CXX_COMPILER=clang++) + (cd ${LLVM_DIR}/build/projects/libcxx && make install -j2) + (cd ${LLVM_DIR}/build/projects/libcxxabi && make install -j2) + fi + export CXXFLAGS="-nostdinc++ -isystem ${LLVM_DIR}/install/include/c++/v1" + export LDFLAGS="-L ${LLVM_DIR}/install/lib -l c++ -l c++abi" + export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${LLVM_DIR}/install/lib" + export PATH="${LLVM_DIR}/clang/bin:${PATH}" + fi + +################ +# build script # +################ script: + # show OS/compiler version - uname -a - - $COMPILER --version - - make CXX=$COMPILER + - $CXX --version + + # compile + - make + + # execute unit tests - test/json_unit "*" - - if [ `which valgrind` ]; then - valgrind --error-exitcode=1 --leak-check=full test/json_unit ; - fi + + # check if homebrew works (only checks develop branch) - if [ `which brew` ]; then brew update ; brew tap nlohmann/json ; brew install nlohmann_json --HEAD ; brew test nlohmann_json ; fi + +#language: cpp +# +#dist: trusty +#sudo: required +# +#env: +# global: +# # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created +# # via the "travis encrypt" command using the project repo's public key +# - secure: "m89SSgE+ASLO38rSKx7MTXK3n5NkP9bIx95jwY71YEiuFzib30PDJ/DifKnXxBjvy/AkCGztErQRk/8ZCvq+4HXozU2knEGnL/RUitvlwbhzfh2D4lmS3BvWBGS3N3NewoPBrRmdcvnT0xjOGXxtZaJ3P74TkB9GBnlz/HmKORA=" +# +## from http://stackoverflow.com/a/32127147/266378 +#matrix: +# include: +# - os: linux +# compiler: gcc +# addons: +# apt: +# sources: ['ubuntu-toolchain-r-test'] +# packages: ['g++-4.9', 'valgrind', 'python-pip', 'python-yaml'] +# before_script: +# - pip install --user git+git://github.com/eddyxu/cpp-coveralls.git +# after_success: +# - make clean +# - touch src/json.hpp +# - make json_unit CXXFLAGS="-fprofile-arcs -ftest-coverage -std=c++11 -lstdc++" CXX=$COMPILER +# - test/json_unit "*" +# - coveralls --build-root test --exclude src/catch.hpp --exclude src/unit-algorithms.cpp --exclude src/unit-allocator.cpp --exclude src/unit-capacity.cpp --exclude src/unit-class_const_iterator.cpp --exclude src/unit-class_iterator.cpp --exclude src/unit-class_lexer.cpp --exclude src/unit-class_parser.cpp --exclude src/unit-comparison.cpp --exclude src/unit-concepts.cpp --exclude src/unit-constructor1.cpp --exclude src/unit-constructor2.cpp --exclude src/unit-convenience.cpp --exclude src/unit-conversions.cpp --exclude src/unit-deserialization.cpp --exclude src/unit-element_access1.cpp --exclude src/unit-element_access2.cpp --exclude src/unit-inspection.cpp --exclude src/unit-iterator_wrapper.cpp --exclude src/unit-iterators1.cpp --exclude src/unit-iterators2.cpp --exclude src/unit-json_patch.cpp --exclude src/unit-json_pointer.cpp --exclude src/unit-modifiers.cpp --exclude src/unit-pointer_access.cpp --exclude src/unit-readme.cpp --exclude src/unit-reference_access.cpp --exclude src/unit-regression.cpp --exclude src/unit-serialization.cpp --exclude src/unit-testsuites.cpp --exclude src/unit-unicode.cpp --include ../src/json.hpp --gcov-options '\-lp' --gcov 'gcov-4.9' +# env: COMPILER=g++-4.9 +# +# - os: linux +# compiler: gcc +# before_install: echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt +# addons: +# apt: +# sources: ['ubuntu-toolchain-r-test'] +# packages: ['g++-5', 'valgrind'] +# coverity_scan: +# project: +# name: "nlohmann/json" +# description: "Build submitted via Travis CI" +# notification_email: niels.lohmann@gmail.com +# build_command_prepend: "make clean ; sudo cp $(which g++-5) $(which g++)" +# build_command: "make" +# branch_pattern: coverity_scan +# env: COMPILER=g++-5 +# diff --git a/README.md b/README.md index 722bf880..c6fa73b4 100644 --- a/README.md +++ b/README.md @@ -416,7 +416,13 @@ The following compilers are currently used in continuous integration at [Travis] | GCC 4.9.3 | Ubuntu 14.04.4 LTS | g++-4.9 (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3 | | GCC 5.3.0 | Ubuntu 14.04.4 LTS | g++-5 (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204 | | GCC 6.1.1 | Ubuntu 14.04.4 LTS | g++-6 (Ubuntu 6.1.1-3ubuntu11~14.04.1) 6.1.1 20160511 | +| Clang 3.6.0 | Ubuntu 14.04.4 LTS | clang version 3.6.0 (tags/RELEASE_360/final) | +| Clang 3.6.1 | Ubuntu 14.04.4 LTS | clang version 3.6.1 (tags/RELEASE_361/final) | +| Clang 3.6.2 | Ubuntu 14.04.4 LTS | clang version 3.6.2 (tags/RELEASE_362/final) | +| Clang 3.7.0 | Ubuntu 14.04.4 LTS | clang version 3.7.0 (tags/RELEASE_370/final) | +| Clang 3.7.1 | Ubuntu 14.04.4 LTS | clang version 3.7.1 (tags/RELEASE_371/final) | | Clang 3.8.0 | Ubuntu 14.04.4 LTS | clang version 3.8.0 (tags/RELEASE_380/final) | +| Clang 3.8.1 | Ubuntu 14.04.4 LTS | clang version 3.8.1 (tags/RELEASE_381/final) | | Clang Xcode 6.1 | Darwin Kernel Version 13.4.0 (OSX 10.9.5) | Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) | | Clang Xcode 6.2 | Darwin Kernel Version 13.4.0 (OSX 10.9.5) | Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn) | | Clang Xcode 6.3 | Darwin Kernel Version 14.3.0 (OSX 10.10.3) | Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn) | @@ -504,7 +510,7 @@ To compile and run the tests, you need to execute $ make check =============================================================================== -All tests passed (8905012 assertions in 32 test cases) +All tests passed (8905099 assertions in 32 test cases) ``` For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml). diff --git a/test/Makefile b/test/Makefile index 7bc8274f..ead1f073 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,7 +3,7 @@ ########################################################################## # additional flags -CXXFLAGS += -std=c++11 -Wall -Wextra -pedantic -Weffc++ -Wcast-align -Wcast-qual -Wno-ctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch -Wundef -Wno-unused -Wnon-virtual-dtor -Wreorder -Wdeprecated -Wno-keyword-macro -Wno-float-equal +CXXFLAGS += -std=c++11 -Wall -Wextra -pedantic -Weffc++ -Wcast-align -Wcast-qual -Wno-ctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch -Wundef -Wno-unused -Wnon-virtual-dtor -Wreorder -Wdeprecated -Wno-float-equal CPPFLAGS += -I ../src -I . SOURCES = src/unit.cpp \ @@ -51,4 +51,4 @@ json_unit: $(OBJECTS) ../src/json.hpp src/catch.hpp @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@ clean: - rm -fr json_unit $(OBJECTS) + rm -fr json_unit $(OBJECTS) $(SOURCES:.cpp=.gcno) $(SOURCES:.cpp=.gcda) diff --git a/test/src/unit-pointer_access.cpp b/test/src/unit-pointer_access.cpp index bae9ee4c..9353b5b0 100644 --- a/test/src/unit-pointer_access.cpp +++ b/test/src/unit-pointer_access.cpp @@ -79,18 +79,30 @@ TEST_CASE("pointer access") SECTION("pointer access to const object_t") { - using test_type = json::object_t; + using test_type = const json::object_t; const json value = {{"one", 1}, {"two", 2}}; - // this should not compile - // test_type* p1 = value.get_ptr(); - // check if pointers are returned correctly + test_type* p1 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p1 == value.get()); + const test_type* p2 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); CHECK(*p2 == value.get()); const test_type* const p3 = value.get_ptr(); - CHECK(p2 == p3); + CHECK(p1 == value.get_ptr()); + CHECK(*p3 == value.get()); + + // check if null pointers are returned correctly + CHECK(value.get_ptr() != nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); } SECTION("pointer access to array_t") @@ -121,6 +133,34 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); } + SECTION("pointer access to const array_t") + { + using test_type = const json::array_t; + const json value = {1, 2, 3, 4}; + + // check if pointers are returned correctly + test_type* p1 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p1 == value.get()); + + const test_type* p2 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p2 == value.get()); + + const test_type* const p3 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p3 == value.get()); + + // check if null pointers are returned correctly + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() != nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + } + SECTION("pointer access to string_t") { using test_type = json::string_t; @@ -149,6 +189,34 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); } + SECTION("pointer access to const string_t") + { + using test_type = const json::string_t; + const json value = "hello"; + + // check if pointers are returned correctly + test_type* p1 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p1 == value.get()); + + const test_type* p2 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p2 == value.get()); + + const test_type* const p3 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p3 == value.get()); + + // check if null pointers are returned correctly + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() != nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + } + SECTION("pointer access to boolean_t") { using test_type = json::boolean_t; @@ -177,6 +245,34 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); } + SECTION("pointer access to const boolean_t") + { + using test_type = const json::boolean_t; + const json value = false; + + // check if pointers are returned correctly + test_type* p1 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + //CHECK(*p1 == value.get()); + + const test_type* p2 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + //CHECK(*p2 == value.get()); + + const test_type* const p3 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + //CHECK(*p3 == value.get()); + + // check if null pointers are returned correctly + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() != nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + } + SECTION("pointer access to number_integer_t") { using test_type = json::number_integer_t; @@ -205,6 +301,34 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); } + SECTION("pointer access to const number_integer_t") + { + using test_type = const json::number_integer_t; + const json value = 23; + + // check if pointers are returned correctly + test_type* p1 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p1 == value.get()); + + const test_type* p2 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p2 == value.get()); + + const test_type* const p3 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p3 == value.get()); + + // check if null pointers are returned correctly + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() != nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + } + SECTION("pointer access to number_unsigned_t") { using test_type = json::number_unsigned_t; @@ -233,6 +357,34 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); } + SECTION("pointer access to const number_unsigned_t") + { + using test_type = const json::number_unsigned_t; + const json value = 23u; + + // check if pointers are returned correctly + test_type* p1 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p1 == value.get()); + + const test_type* p2 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p2 == value.get()); + + const test_type* const p3 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p3 == value.get()); + + // check if null pointers are returned correctly + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() != nullptr); + CHECK(value.get_ptr() != nullptr); + CHECK(value.get_ptr() == nullptr); + } + SECTION("pointer access to number_float_t") { using test_type = json::number_float_t; @@ -260,4 +412,32 @@ TEST_CASE("pointer access") CHECK(value.get_ptr() == nullptr); CHECK(value.get_ptr() != nullptr); } + + SECTION("pointer access to const number_float_t") + { + using test_type = const json::number_float_t; + const json value = 42.23; + + // check if pointers are returned correctly + test_type* p1 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p1 == Approx(value.get())); + + const test_type* p2 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p2 == Approx(value.get())); + + const test_type* const p3 = value.get_ptr(); + CHECK(p1 == value.get_ptr()); + CHECK(*p3 == Approx(value.get())); + + // check if null pointers are returned correctly + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() == nullptr); + CHECK(value.get_ptr() != nullptr); + } }