1c5f01b2fSopenharmony_ci//     __ _____ _____ _____
2c5f01b2fSopenharmony_ci//  __|  |   __|     |   | |  JSON for Modern C++ (supporting code)
3c5f01b2fSopenharmony_ci// |  |  |__   |  |  | | | |  version 3.11.2
4c5f01b2fSopenharmony_ci// |_____|_____|_____|_|___|  https://github.com/nlohmann/json
5c5f01b2fSopenharmony_ci//
6c5f01b2fSopenharmony_ci// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
7c5f01b2fSopenharmony_ci// SPDX-License-Identifier: MIT
8c5f01b2fSopenharmony_ci
9c5f01b2fSopenharmony_ci#include "doctest_compatibility.h"
10c5f01b2fSopenharmony_ci
11c5f01b2fSopenharmony_ci// disable -Wnoexcept due to struct pod_bis
12c5f01b2fSopenharmony_ciDOCTEST_GCC_SUPPRESS_WARNING_PUSH
13c5f01b2fSopenharmony_ciDOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
14c5f01b2fSopenharmony_ci
15c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp>
16c5f01b2fSopenharmony_ci
17c5f01b2fSopenharmony_ciusing nlohmann::json;
18c5f01b2fSopenharmony_ci
19c5f01b2fSopenharmony_cinamespace
20c5f01b2fSopenharmony_ci{
21c5f01b2fSopenharmony_cienum test
22c5f01b2fSopenharmony_ci{
23c5f01b2fSopenharmony_ci};
24c5f01b2fSopenharmony_ci
25c5f01b2fSopenharmony_cistruct pod {};
26c5f01b2fSopenharmony_cistruct pod_bis {};
27c5f01b2fSopenharmony_ci
28c5f01b2fSopenharmony_civoid to_json(json& /*unused*/, pod /*unused*/) noexcept;
29c5f01b2fSopenharmony_civoid to_json(json& /*unused*/, pod_bis /*unused*/);
30c5f01b2fSopenharmony_civoid from_json(const json& /*unused*/, pod /*unused*/) noexcept;
31c5f01b2fSopenharmony_civoid from_json(const json& /*unused*/, pod_bis /*unused*/);
32c5f01b2fSopenharmony_civoid to_json(json& /*unused*/, pod /*unused*/) noexcept {}
33c5f01b2fSopenharmony_civoid to_json(json& /*unused*/, pod_bis /*unused*/) {}
34c5f01b2fSopenharmony_civoid from_json(const json& /*unused*/, pod /*unused*/) noexcept {}
35c5f01b2fSopenharmony_civoid from_json(const json& /*unused*/, pod_bis /*unused*/) {}
36c5f01b2fSopenharmony_ci
37c5f01b2fSopenharmony_cijson* j = nullptr;
38c5f01b2fSopenharmony_ci
39c5f01b2fSopenharmony_cistatic_assert(noexcept(json{}), "");
40c5f01b2fSopenharmony_cistatic_assert(noexcept(nlohmann::to_json(*j, 2)), "");
41c5f01b2fSopenharmony_cistatic_assert(noexcept(nlohmann::to_json(*j, 2.5)), "");
42c5f01b2fSopenharmony_cistatic_assert(noexcept(nlohmann::to_json(*j, true)), "");
43c5f01b2fSopenharmony_cistatic_assert(noexcept(nlohmann::to_json(*j, test{})), "");
44c5f01b2fSopenharmony_cistatic_assert(noexcept(nlohmann::to_json(*j, pod{})), "");
45c5f01b2fSopenharmony_cistatic_assert(!noexcept(nlohmann::to_json(*j, pod_bis{})), "");
46c5f01b2fSopenharmony_cistatic_assert(noexcept(json(2)), "");
47c5f01b2fSopenharmony_cistatic_assert(noexcept(json(test{})), "");
48c5f01b2fSopenharmony_cistatic_assert(noexcept(json(pod{})), "");
49c5f01b2fSopenharmony_cistatic_assert(noexcept(j->get<pod>()), "");
50c5f01b2fSopenharmony_cistatic_assert(!noexcept(j->get<pod_bis>()), "");
51c5f01b2fSopenharmony_cistatic_assert(noexcept(json(pod{})), "");
52c5f01b2fSopenharmony_ci} // namespace
53c5f01b2fSopenharmony_ci
54c5f01b2fSopenharmony_ciTEST_CASE("runtime checks")
55c5f01b2fSopenharmony_ci{
56c5f01b2fSopenharmony_ci    SECTION("nothrow-copy-constructible exceptions")
57c5f01b2fSopenharmony_ci    {
58c5f01b2fSopenharmony_ci        // for ERR60-CPP (https://github.com/nlohmann/json/issues/531):
59c5f01b2fSopenharmony_ci        // Exceptions should be nothrow-copy-constructible. However, compilers
60c5f01b2fSopenharmony_ci        // treat std::runtime_exception differently in this regard. Therefore,
61c5f01b2fSopenharmony_ci        // we can only demand nothrow-copy-constructibility for our exceptions
62c5f01b2fSopenharmony_ci        // if std::runtime_exception is.
63c5f01b2fSopenharmony_ci        CHECK(std::is_nothrow_copy_constructible<json::exception>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
64c5f01b2fSopenharmony_ci        CHECK(std::is_nothrow_copy_constructible<json::parse_error>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
65c5f01b2fSopenharmony_ci        CHECK(std::is_nothrow_copy_constructible<json::invalid_iterator>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
66c5f01b2fSopenharmony_ci        CHECK(std::is_nothrow_copy_constructible<json::type_error>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
67c5f01b2fSopenharmony_ci        CHECK(std::is_nothrow_copy_constructible<json::out_of_range>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
68c5f01b2fSopenharmony_ci        CHECK(std::is_nothrow_copy_constructible<json::other_error>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
69c5f01b2fSopenharmony_ci    }
70c5f01b2fSopenharmony_ci
71c5f01b2fSopenharmony_ci    SECTION("silence -Wunneeded-internal-declaration errors")
72c5f01b2fSopenharmony_ci    {
73c5f01b2fSopenharmony_ci        j = nullptr;
74c5f01b2fSopenharmony_ci        json j2;
75c5f01b2fSopenharmony_ci        to_json(j2, pod());
76c5f01b2fSopenharmony_ci        to_json(j2, pod_bis());
77c5f01b2fSopenharmony_ci        from_json(j2, pod());
78c5f01b2fSopenharmony_ci        from_json(j2, pod_bis());
79c5f01b2fSopenharmony_ci    }
80c5f01b2fSopenharmony_ci}
81c5f01b2fSopenharmony_ci
82c5f01b2fSopenharmony_ciDOCTEST_GCC_SUPPRESS_WARNING_POP
83