mirror of
https://github.com/nlohmann/json.git
synced 2026-10-03 13:10:33 +00:00
* Fix CI configuration broken by recent merges and tool updates - gcc_flags.cmake: drop -Wexperimental-fmv-target, which GCC 16 accepts only on aarch64; amd64 rejects it, so every GCC job failed while checking the compiler. - ci_get_cmake: add VERBATIM so the checksum pipeline is passed to the shell intact (the unescaped `$'` broke the generated Makefile and build.ninja, failing ci_cmake_flags and ci_module_cpp20); match the SHA-256 entry case-insensitively, as CMake 3.5.0 lists the archive as "Linux-x86_64"; and unpack with --strip-components, as that archive's top-level directory is spelled "Linux" too. - ci_single_binaries: compile json.hpp's TU without IWYU's --error, as the comment above the gate already intends. - tests: restore -Wno-deprecated-declarations for all non-MSVC compilers (#5737 kept it for GCC only), as several tests call deprecated functions on purpose; include thirdparty/fifo_map as SYSTEM. - .clang-tidy: set misc-use-internal-linkage.AnalyzeTypes to false; clang-tidy 22.1 extended the check to classes and enums and flagged 100 test helper types. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Fix library warnings and a JSON_DIAGNOSTICS parent bug - binary_reader: pass integers to sax->number_integer() through conditional_static_cast<number_integer_t>, making the existing narrowing for a narrow number_integer_t explicit (MSVC C4244 and GCC -Wconversion/-Warith-conversion with the int16_t test from #5694); mark two Infer DEAD_STORE false positives with @infer-ignore. - to_json: set the parents of an array built from a C++20 range view after all elements are in place; a reallocating push_back moved the earlier elements and left their parent pointers stale, failing the JSON_DIAGNOSTICS invariant assertion. - json.hpp: suppress MSVC C4127 for the new is_ordered_map check in diff(), like the three existing ones; spell out std::formatter::parse's return and iterator types for clang-tidy 22.1. - number_parse: make the Eisel-Lemire digit counter unsigned (GCC -Wstrict-overflow). - string_utils: take encode_utf8's callable by const reference (cppcoreguidelines-missing-std-forward) and drop a \u from its doc comment (-Wdocumentation-unknown-command). - ordered_map: include <memory> for std::allocator (cpplint). Ran make amalgamate. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Fix tests failing in CI on develop - unit-allocator: skip the #5640 test under MSVC STL iterator debugging, where containers allocate a debug proxy in noexcept move constructors and a failing allocation terminates; move a decrement out of an if condition (bugprone-inc-dec-in-conditions). - unit-conversions: expect the "(/0)" path with JSON_DIAGNOSTICS; compare strict enums via get<>() rather than through the noexcept operator==(ScalarType, json), which bugprone-exception-escape flags. - unit-alt-string: suppress -Wexit-time-destructors for the strict enum macro and misc-use-internal-linkage for its enum. - unit-bjdata: call the static lookup functions through the type and pass unsigned char (-Wsign-conversion on amd64). - Mark Infer false positives with @infer-ignore in unit-diagnostics, unit-pointer_access, unit-udt, and unit-conversions. - Smaller clang-tidy 22.1 findings in unit-class_parser, unit-constructor2, unit-custom-base-class, unit-locale-cpp, and unit-noexcept. Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
484 lines
21 KiB
C++
484 lines
21 KiB
C++
// __ _____ _____ _____
|
|
// __| | __| | | | JSON for Modern C++ (supporting code)
|
|
// | | |__ | | | | | | version 3.12.0
|
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
//
|
|
// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include "doctest_compatibility.h"
|
|
|
|
#include <nlohmann/json.hpp>
|
|
using nlohmann::json;
|
|
|
|
TEST_CASE("pointer access")
|
|
{
|
|
SECTION("pointer access to object_t")
|
|
{
|
|
using test_type = json::object_t;
|
|
json value = {{"one", 1}, {"two", 2}};
|
|
|
|
// check if pointers are returned correctly
|
|
const test_type* p1 = value.get_ptr<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<json::object_t*>() != nullptr);
|
|
CHECK(value.get_ptr<json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::binary_t*>() == nullptr);
|
|
}
|
|
|
|
SECTION("pointer access to const object_t")
|
|
{
|
|
using test_type = const json::object_t;
|
|
const json value = {{"one", 1}, {"two", 2}};
|
|
|
|
// check if pointers are returned correctly
|
|
test_type* p1 = value.get_ptr<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<const json::object_t*>() != nullptr);
|
|
CHECK(value.get_ptr<const json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
|
|
}
|
|
|
|
SECTION("pointer access to array_t")
|
|
{
|
|
using test_type = json::array_t;
|
|
json value = {1, 2, 3, 4};
|
|
|
|
// check if pointers are returned correctly
|
|
const test_type* p1 = value.get_ptr<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
// false positive: p1 is non-null, as value has type test_type
|
|
// @infer-ignore NULLPTR_DEREFERENCE
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::array_t*>() != nullptr);
|
|
CHECK(value.get_ptr<json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::binary_t*>() == 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<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
// false positive: p1 is non-null, as value has type test_type
|
|
// @infer-ignore NULLPTR_DEREFERENCE
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<const json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::array_t*>() != nullptr);
|
|
CHECK(value.get_ptr<const json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
|
|
}
|
|
|
|
SECTION("pointer access to string_t")
|
|
{
|
|
using test_type = json::string_t;
|
|
json value = "hello";
|
|
|
|
// check if pointers are returned correctly
|
|
const test_type* p1 = value.get_ptr<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::string_t*>() != nullptr);
|
|
CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::binary_t*>() == 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<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<const json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::string_t*>() != nullptr);
|
|
CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
|
|
}
|
|
|
|
SECTION("pointer access to boolean_t")
|
|
{
|
|
using test_type = json::boolean_t;
|
|
json value = false;
|
|
|
|
// check if pointers are returned correctly
|
|
const test_type* p1 = value.get_ptr<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::boolean_t*>() != nullptr);
|
|
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::binary_t*>() == 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<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
//CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<const json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::boolean_t*>() != nullptr);
|
|
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
|
|
}
|
|
|
|
SECTION("pointer access to number_integer_t")
|
|
{
|
|
using test_type = json::number_integer_t;
|
|
json value = 23;
|
|
|
|
// check if pointers are returned correctly
|
|
const test_type* p1 = value.get_ptr<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_integer_t*>() != nullptr);
|
|
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::binary_t*>() == 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<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<const json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_integer_t*>() != nullptr);
|
|
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
|
|
}
|
|
|
|
SECTION("pointer access to number_unsigned_t")
|
|
{
|
|
using test_type = json::number_unsigned_t;
|
|
json value = 23u;
|
|
|
|
// check if pointers are returned correctly
|
|
const test_type* p1 = value.get_ptr<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_unsigned_t*>() != nullptr);
|
|
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::binary_t*>() == 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<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<const json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_unsigned_t*>() != nullptr);
|
|
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
|
|
}
|
|
|
|
SECTION("pointer access to number_float_t")
|
|
{
|
|
using test_type = json::number_float_t;
|
|
json value = 42.23;
|
|
|
|
// check if pointers are returned correctly
|
|
const test_type* p1 = value.get_ptr<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == Approx(value.get<test_type>()));
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == Approx(value.get<test_type>()));
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == Approx(value.get<test_type>()));
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<json::number_float_t*>() != nullptr);
|
|
CHECK(value.get_ptr<json::binary_t*>() == 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<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == Approx(value.get<test_type>()));
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == Approx(value.get<test_type>()));
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == Approx(value.get<test_type>()));
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<const json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_float_t*>() != nullptr);
|
|
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
|
|
}
|
|
|
|
SECTION("pointer access to const binary_t")
|
|
{
|
|
using test_type = const json::binary_t;
|
|
const json value = json::binary({1, 2, 3});
|
|
|
|
// check if pointers are returned correctly
|
|
test_type* p1 = value.get_ptr<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<const json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::binary_t*>() != nullptr);
|
|
}
|
|
|
|
SECTION("pointer access to const binary_t")
|
|
{
|
|
using test_type = const json::binary_t;
|
|
const json value = json::binary({});
|
|
|
|
// check if pointers are returned correctly
|
|
test_type* p1 = value.get_ptr<test_type*>();
|
|
CHECK(p1 == value.get_ptr<test_type*>());
|
|
CHECK(*p1 == value.get<test_type>());
|
|
|
|
const test_type* p2 = value.get_ptr<const test_type*>();
|
|
CHECK(p2 == value.get_ptr<const test_type*>());
|
|
CHECK(*p2 == value.get<test_type>());
|
|
|
|
const test_type* const p3 = value.get_ptr<const test_type* const>();
|
|
CHECK(p3 == value.get_ptr<const test_type* const>());
|
|
CHECK(*p3 == value.get<test_type>());
|
|
|
|
// check if null pointers are returned correctly
|
|
CHECK(value.get_ptr<const json::object_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::array_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::string_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_unsigned_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
|
|
CHECK(value.get_ptr<const json::binary_t*>() != nullptr);
|
|
}
|
|
}
|