2022-07-20 12:38:07 +02:00
|
|
|
// __ _____ _____ _____
|
|
|
|
// __| | __| | | | JSON for Modern C++ (supporting code)
|
2022-08-12 15:04:06 +02:00
|
|
|
// | | |__ | | | | | | version 3.11.2
|
2022-07-20 12:38:07 +02:00
|
|
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
|
|
//
|
|
|
|
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
|
|
|
// SPDX-License-Identifier: MIT
|
2017-01-28 16:03:35 +01:00
|
|
|
|
2019-01-13 17:41:21 +01:00
|
|
|
#include "doctest_compatibility.h"
|
|
|
|
|
2021-08-17 14:43:43 +02:00
|
|
|
// disable -Wnoexcept due to struct pod_bis
|
|
|
|
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
|
|
|
|
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
|
|
|
|
|
2018-01-29 11:21:11 +01:00
|
|
|
#include <nlohmann/json.hpp>
|
2017-01-14 02:20:53 +01:00
|
|
|
|
|
|
|
using nlohmann::json;
|
|
|
|
|
2019-04-04 08:56:36 +02:00
|
|
|
namespace
|
|
|
|
{
|
2017-01-14 02:20:53 +01:00
|
|
|
enum test
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pod {};
|
|
|
|
struct pod_bis {};
|
|
|
|
|
2021-03-24 07:15:18 +01:00
|
|
|
void to_json(json& /*unused*/, pod /*unused*/) noexcept;
|
|
|
|
void to_json(json& /*unused*/, pod_bis /*unused*/);
|
|
|
|
void from_json(const json& /*unused*/, pod /*unused*/) noexcept;
|
|
|
|
void from_json(const json& /*unused*/, pod_bis /*unused*/);
|
|
|
|
void to_json(json& /*unused*/, pod /*unused*/) noexcept {}
|
|
|
|
void to_json(json& /*unused*/, pod_bis /*unused*/) {}
|
|
|
|
void from_json(const json& /*unused*/, pod /*unused*/) noexcept {}
|
|
|
|
void from_json(const json& /*unused*/, pod_bis /*unused*/) {}
|
2020-05-16 14:26:17 +02:00
|
|
|
|
2021-03-24 07:15:18 +01:00
|
|
|
json* j = nullptr;
|
2017-01-14 02:20:53 +01:00
|
|
|
|
|
|
|
static_assert(noexcept(json{}), "");
|
2020-05-08 12:32:28 +02:00
|
|
|
static_assert(noexcept(nlohmann::to_json(*j, 2)), "");
|
|
|
|
static_assert(noexcept(nlohmann::to_json(*j, 2.5)), "");
|
|
|
|
static_assert(noexcept(nlohmann::to_json(*j, true)), "");
|
|
|
|
static_assert(noexcept(nlohmann::to_json(*j, test{})), "");
|
|
|
|
static_assert(noexcept(nlohmann::to_json(*j, pod{})), "");
|
2020-06-03 21:22:07 +02:00
|
|
|
static_assert(!noexcept(nlohmann::to_json(*j, pod_bis{})), "");
|
2017-01-14 02:20:53 +01:00
|
|
|
static_assert(noexcept(json(2)), "");
|
|
|
|
static_assert(noexcept(json(test{})), "");
|
|
|
|
static_assert(noexcept(json(pod{})), "");
|
2020-05-08 12:32:28 +02:00
|
|
|
static_assert(noexcept(j->get<pod>()), "");
|
2020-06-03 21:22:07 +02:00
|
|
|
static_assert(!noexcept(j->get<pod_bis>()), "");
|
2017-01-16 21:59:47 +01:00
|
|
|
static_assert(noexcept(json(pod{})), "");
|
2021-03-24 07:15:18 +01:00
|
|
|
} // namespace
|
2017-03-25 16:22:52 +01:00
|
|
|
|
2017-03-25 17:35:57 +01:00
|
|
|
TEST_CASE("runtime checks")
|
|
|
|
{
|
|
|
|
SECTION("nothrow-copy-constructible exceptions")
|
|
|
|
{
|
2017-03-25 23:31:03 +01:00
|
|
|
// for ERR60-CPP (https://github.com/nlohmann/json/issues/531):
|
|
|
|
// Exceptions should be nothrow-copy-constructible. However, compilers
|
|
|
|
// treat std::runtime_exception differently in this regard. Therefore,
|
|
|
|
// we can only demand nothrow-copy-constructibility for our exceptions
|
|
|
|
// if std::runtime_exception is.
|
|
|
|
CHECK(std::is_nothrow_copy_constructible<json::exception>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
|
|
|
|
CHECK(std::is_nothrow_copy_constructible<json::parse_error>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
|
|
|
|
CHECK(std::is_nothrow_copy_constructible<json::invalid_iterator>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
|
|
|
|
CHECK(std::is_nothrow_copy_constructible<json::type_error>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
|
|
|
|
CHECK(std::is_nothrow_copy_constructible<json::out_of_range>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
|
|
|
|
CHECK(std::is_nothrow_copy_constructible<json::other_error>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
|
2017-03-25 17:35:57 +01:00
|
|
|
}
|
2020-05-16 14:26:17 +02:00
|
|
|
|
|
|
|
SECTION("silence -Wunneeded-internal-declaration errors")
|
|
|
|
{
|
|
|
|
j = nullptr;
|
|
|
|
json j2;
|
|
|
|
to_json(j2, pod());
|
|
|
|
to_json(j2, pod_bis());
|
|
|
|
from_json(j2, pod());
|
|
|
|
from_json(j2, pod_bis());
|
|
|
|
}
|
2017-03-25 17:35:57 +01:00
|
|
|
}
|
2021-08-17 14:43:43 +02:00
|
|
|
|
|
|
|
DOCTEST_GCC_SUPPRESS_WARNING_POP
|