2016-08-04 20:51:08 +00:00
|
|
|
/*
|
|
|
|
__ _____ _____ _____
|
|
|
|
__| | __| | | | JSON for Modern C++ (test suite)
|
2020-06-14 15:16:45 +00:00
|
|
|
| | |__ | | | | | | version 3.8.0
|
2016-08-04 20:51:08 +00:00
|
|
|
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
|
|
|
|
|
|
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
2018-05-03 15:41:45 +00:00
|
|
|
SPDX-License-Identifier: MIT
|
2019-03-19 23:19:07 +00:00
|
|
|
Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>.
|
2016-08-04 20:51:08 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2019-01-13 16:41:21 +00:00
|
|
|
#include "doctest_compatibility.h"
|
2016-08-04 20:51:08 +00:00
|
|
|
|
2018-01-29 10:21:11 +00:00
|
|
|
#include <nlohmann/json.hpp>
|
2016-08-04 20:51:08 +00:00
|
|
|
using nlohmann::json;
|
|
|
|
|
|
|
|
TEST_CASE("other constructors and destructor")
|
|
|
|
{
|
|
|
|
SECTION("copy constructor")
|
|
|
|
{
|
|
|
|
SECTION("object")
|
|
|
|
{
|
|
|
|
json j {{"foo", 1}, {"bar", false}};
|
|
|
|
json k(j);
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("array")
|
|
|
|
{
|
|
|
|
json j {"foo", 1, 42.23, false};
|
|
|
|
json k(j);
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("null")
|
|
|
|
{
|
|
|
|
json j(nullptr);
|
|
|
|
json k(j);
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("boolean")
|
|
|
|
{
|
|
|
|
json j(true);
|
|
|
|
json k(j);
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("string")
|
|
|
|
{
|
|
|
|
json j("Hello world");
|
|
|
|
json k(j);
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("number (integer)")
|
|
|
|
{
|
|
|
|
json j(42);
|
|
|
|
json k(j);
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("number (unsigned)")
|
|
|
|
{
|
|
|
|
json j(42u);
|
|
|
|
json k(j);
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("number (floating-point)")
|
|
|
|
{
|
|
|
|
json j(42.23);
|
|
|
|
json k(j);
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
2020-05-09 11:46:24 +00:00
|
|
|
|
|
|
|
SECTION("binary")
|
|
|
|
{
|
2020-05-19 11:30:22 +00:00
|
|
|
json j = json::binary({1, 2, 3});
|
2020-05-09 11:46:24 +00:00
|
|
|
json k(j);
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
2016-08-04 20:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("move constructor")
|
|
|
|
{
|
|
|
|
json j {{"foo", "bar"}, {"baz", {1, 2, 3, 4}}, {"a", 42u}, {"b", 42.23}, {"c", nullptr}};
|
|
|
|
CHECK(j.type() == json::value_t::object);
|
|
|
|
json k(std::move(j));
|
|
|
|
CHECK(k.type() == json::value_t::object);
|
|
|
|
CHECK(j.type() == json::value_t::null);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("copy assignment")
|
|
|
|
{
|
|
|
|
SECTION("object")
|
|
|
|
{
|
|
|
|
json j {{"foo", 1}, {"bar", false}};
|
|
|
|
json k;
|
|
|
|
k = j;
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("array")
|
|
|
|
{
|
|
|
|
json j {"foo", 1, 42.23, false};
|
|
|
|
json k;
|
|
|
|
k = j;
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("null")
|
|
|
|
{
|
|
|
|
json j(nullptr);
|
|
|
|
json k;
|
|
|
|
k = j;
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("boolean")
|
|
|
|
{
|
|
|
|
json j(true);
|
|
|
|
json k;
|
|
|
|
k = j;
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("string")
|
|
|
|
{
|
|
|
|
json j("Hello world");
|
|
|
|
json k;
|
|
|
|
k = j;
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("number (integer)")
|
|
|
|
{
|
|
|
|
json j(42);
|
|
|
|
json k;
|
|
|
|
k = j;
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("number (unsigned)")
|
|
|
|
{
|
|
|
|
json j(42u);
|
|
|
|
json k;
|
|
|
|
k = j;
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("number (floating-point)")
|
|
|
|
{
|
|
|
|
json j(42.23);
|
|
|
|
json k;
|
|
|
|
k = j;
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
2020-05-09 11:46:24 +00:00
|
|
|
|
|
|
|
SECTION("binary")
|
|
|
|
{
|
2020-05-19 11:30:22 +00:00
|
|
|
json j = json::binary({1, 2, 3});
|
2020-05-09 11:46:24 +00:00
|
|
|
json k;
|
|
|
|
k = j;
|
|
|
|
CHECK(j == k);
|
|
|
|
}
|
2016-08-04 20:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("destructor")
|
|
|
|
{
|
|
|
|
SECTION("object")
|
|
|
|
{
|
|
|
|
auto j = new json {{"foo", 1}, {"bar", false}};
|
|
|
|
delete j;
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("array")
|
|
|
|
{
|
|
|
|
auto j = new json {"foo", 1, 1u, false, 23.42};
|
|
|
|
delete j;
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("string")
|
|
|
|
{
|
|
|
|
auto j = new json("Hello world");
|
|
|
|
delete j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|