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#include <nlohmann/json.hpp>
12c5f01b2fSopenharmony_ciusing nlohmann::json;
13c5f01b2fSopenharmony_ci#ifdef JSON_TEST_NO_GLOBAL_UDLS
14c5f01b2fSopenharmony_ci    using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
15c5f01b2fSopenharmony_ci#endif
16c5f01b2fSopenharmony_ci
17c5f01b2fSopenharmony_ci#include <fstream>
18c5f01b2fSopenharmony_ci#include <sstream>
19c5f01b2fSopenharmony_ci#include <iomanip>
20c5f01b2fSopenharmony_ci#include <set>
21c5f01b2fSopenharmony_ci#include "make_test_data_available.hpp"
22c5f01b2fSopenharmony_ci#include "test_utils.hpp"
23c5f01b2fSopenharmony_ci
24c5f01b2fSopenharmony_cinamespace
25c5f01b2fSopenharmony_ci{
26c5f01b2fSopenharmony_ciclass SaxCountdown
27c5f01b2fSopenharmony_ci{
28c5f01b2fSopenharmony_ci  public:
29c5f01b2fSopenharmony_ci    explicit SaxCountdown(const int count) : events_left(count)
30c5f01b2fSopenharmony_ci    {}
31c5f01b2fSopenharmony_ci
32c5f01b2fSopenharmony_ci    bool null()
33c5f01b2fSopenharmony_ci    {
34c5f01b2fSopenharmony_ci        return events_left-- > 0;
35c5f01b2fSopenharmony_ci    }
36c5f01b2fSopenharmony_ci
37c5f01b2fSopenharmony_ci    bool boolean(bool /*unused*/)
38c5f01b2fSopenharmony_ci    {
39c5f01b2fSopenharmony_ci        return events_left-- > 0;
40c5f01b2fSopenharmony_ci    }
41c5f01b2fSopenharmony_ci
42c5f01b2fSopenharmony_ci    bool number_integer(json::number_integer_t /*unused*/)
43c5f01b2fSopenharmony_ci    {
44c5f01b2fSopenharmony_ci        return events_left-- > 0;
45c5f01b2fSopenharmony_ci    }
46c5f01b2fSopenharmony_ci
47c5f01b2fSopenharmony_ci    bool number_unsigned(json::number_unsigned_t /*unused*/)
48c5f01b2fSopenharmony_ci    {
49c5f01b2fSopenharmony_ci        return events_left-- > 0;
50c5f01b2fSopenharmony_ci    }
51c5f01b2fSopenharmony_ci
52c5f01b2fSopenharmony_ci    bool number_float(json::number_float_t /*unused*/, const std::string& /*unused*/)
53c5f01b2fSopenharmony_ci    {
54c5f01b2fSopenharmony_ci        return events_left-- > 0;
55c5f01b2fSopenharmony_ci    }
56c5f01b2fSopenharmony_ci
57c5f01b2fSopenharmony_ci    bool string(std::string& /*unused*/)
58c5f01b2fSopenharmony_ci    {
59c5f01b2fSopenharmony_ci        return events_left-- > 0;
60c5f01b2fSopenharmony_ci    }
61c5f01b2fSopenharmony_ci
62c5f01b2fSopenharmony_ci    bool binary(std::vector<std::uint8_t>& /*unused*/)
63c5f01b2fSopenharmony_ci    {
64c5f01b2fSopenharmony_ci        return events_left-- > 0;
65c5f01b2fSopenharmony_ci    }
66c5f01b2fSopenharmony_ci
67c5f01b2fSopenharmony_ci    bool start_object(std::size_t /*unused*/)
68c5f01b2fSopenharmony_ci    {
69c5f01b2fSopenharmony_ci        return events_left-- > 0;
70c5f01b2fSopenharmony_ci    }
71c5f01b2fSopenharmony_ci
72c5f01b2fSopenharmony_ci    bool key(std::string& /*unused*/)
73c5f01b2fSopenharmony_ci    {
74c5f01b2fSopenharmony_ci        return events_left-- > 0;
75c5f01b2fSopenharmony_ci    }
76c5f01b2fSopenharmony_ci
77c5f01b2fSopenharmony_ci    bool end_object()
78c5f01b2fSopenharmony_ci    {
79c5f01b2fSopenharmony_ci        return events_left-- > 0;
80c5f01b2fSopenharmony_ci    }
81c5f01b2fSopenharmony_ci
82c5f01b2fSopenharmony_ci    bool start_array(std::size_t /*unused*/)
83c5f01b2fSopenharmony_ci    {
84c5f01b2fSopenharmony_ci        return events_left-- > 0;
85c5f01b2fSopenharmony_ci    }
86c5f01b2fSopenharmony_ci
87c5f01b2fSopenharmony_ci    bool end_array()
88c5f01b2fSopenharmony_ci    {
89c5f01b2fSopenharmony_ci        return events_left-- > 0;
90c5f01b2fSopenharmony_ci    }
91c5f01b2fSopenharmony_ci
92c5f01b2fSopenharmony_ci    bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static)
93c5f01b2fSopenharmony_ci    {
94c5f01b2fSopenharmony_ci        return false;
95c5f01b2fSopenharmony_ci    }
96c5f01b2fSopenharmony_ci
97c5f01b2fSopenharmony_ci  private:
98c5f01b2fSopenharmony_ci    int events_left = 0;
99c5f01b2fSopenharmony_ci};
100c5f01b2fSopenharmony_ci} // namespace
101c5f01b2fSopenharmony_ci
102c5f01b2fSopenharmony_ciTEST_CASE("MessagePack")
103c5f01b2fSopenharmony_ci{
104c5f01b2fSopenharmony_ci    SECTION("individual values")
105c5f01b2fSopenharmony_ci    {
106c5f01b2fSopenharmony_ci        SECTION("discarded")
107c5f01b2fSopenharmony_ci        {
108c5f01b2fSopenharmony_ci            // discarded values are not serialized
109c5f01b2fSopenharmony_ci            json j = json::value_t::discarded;
110c5f01b2fSopenharmony_ci            const auto result = json::to_msgpack(j);
111c5f01b2fSopenharmony_ci            CHECK(result.empty());
112c5f01b2fSopenharmony_ci        }
113c5f01b2fSopenharmony_ci
114c5f01b2fSopenharmony_ci        SECTION("null")
115c5f01b2fSopenharmony_ci        {
116c5f01b2fSopenharmony_ci            json j = nullptr;
117c5f01b2fSopenharmony_ci            std::vector<uint8_t> expected = {0xc0};
118c5f01b2fSopenharmony_ci            const auto result = json::to_msgpack(j);
119c5f01b2fSopenharmony_ci            CHECK(result == expected);
120c5f01b2fSopenharmony_ci
121c5f01b2fSopenharmony_ci            // roundtrip
122c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(result) == j);
123c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(result, true, false) == j);
124c5f01b2fSopenharmony_ci        }
125c5f01b2fSopenharmony_ci
126c5f01b2fSopenharmony_ci        SECTION("boolean")
127c5f01b2fSopenharmony_ci        {
128c5f01b2fSopenharmony_ci            SECTION("true")
129c5f01b2fSopenharmony_ci            {
130c5f01b2fSopenharmony_ci                json j = true;
131c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {0xc3};
132c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
133c5f01b2fSopenharmony_ci                CHECK(result == expected);
134c5f01b2fSopenharmony_ci
135c5f01b2fSopenharmony_ci                // roundtrip
136c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
137c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
138c5f01b2fSopenharmony_ci            }
139c5f01b2fSopenharmony_ci
140c5f01b2fSopenharmony_ci            SECTION("false")
141c5f01b2fSopenharmony_ci            {
142c5f01b2fSopenharmony_ci                json j = false;
143c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {0xc2};
144c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
145c5f01b2fSopenharmony_ci                CHECK(result == expected);
146c5f01b2fSopenharmony_ci
147c5f01b2fSopenharmony_ci                // roundtrip
148c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
149c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
150c5f01b2fSopenharmony_ci            }
151c5f01b2fSopenharmony_ci        }
152c5f01b2fSopenharmony_ci
153c5f01b2fSopenharmony_ci        SECTION("number")
154c5f01b2fSopenharmony_ci        {
155c5f01b2fSopenharmony_ci            SECTION("signed")
156c5f01b2fSopenharmony_ci            {
157c5f01b2fSopenharmony_ci                SECTION("-32..-1 (negative fixnum)")
158c5f01b2fSopenharmony_ci                {
159c5f01b2fSopenharmony_ci                    for (auto i = -32; i <= -1; ++i)
160c5f01b2fSopenharmony_ci                    {
161c5f01b2fSopenharmony_ci                        CAPTURE(i)
162c5f01b2fSopenharmony_ci
163c5f01b2fSopenharmony_ci                        // create JSON value with integer number
164c5f01b2fSopenharmony_ci                        json j = i;
165c5f01b2fSopenharmony_ci
166c5f01b2fSopenharmony_ci                        // check type
167c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
168c5f01b2fSopenharmony_ci
169c5f01b2fSopenharmony_ci                        // create expected byte vector
170c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
171c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i));
172c5f01b2fSopenharmony_ci
173c5f01b2fSopenharmony_ci                        // compare result + size
174c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
175c5f01b2fSopenharmony_ci                        CHECK(result == expected);
176c5f01b2fSopenharmony_ci                        CHECK(result.size() == 1);
177c5f01b2fSopenharmony_ci
178c5f01b2fSopenharmony_ci                        // check individual bytes
179c5f01b2fSopenharmony_ci                        CHECK(static_cast<int8_t>(result[0]) == i);
180c5f01b2fSopenharmony_ci
181c5f01b2fSopenharmony_ci                        // roundtrip
182c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
183c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
184c5f01b2fSopenharmony_ci                    }
185c5f01b2fSopenharmony_ci                }
186c5f01b2fSopenharmony_ci
187c5f01b2fSopenharmony_ci                SECTION("0..127 (positive fixnum)")
188c5f01b2fSopenharmony_ci                {
189c5f01b2fSopenharmony_ci                    for (size_t i = 0; i <= 127; ++i)
190c5f01b2fSopenharmony_ci                    {
191c5f01b2fSopenharmony_ci                        CAPTURE(i)
192c5f01b2fSopenharmony_ci
193c5f01b2fSopenharmony_ci                        // create JSON value with integer number
194c5f01b2fSopenharmony_ci                        json j = -1;
195c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
196c5f01b2fSopenharmony_ci
197c5f01b2fSopenharmony_ci                        // check type
198c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
199c5f01b2fSopenharmony_ci
200c5f01b2fSopenharmony_ci                        // create expected byte vector
201c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
202c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i));
203c5f01b2fSopenharmony_ci
204c5f01b2fSopenharmony_ci                        // compare result + size
205c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
206c5f01b2fSopenharmony_ci                        CHECK(result == expected);
207c5f01b2fSopenharmony_ci                        CHECK(result.size() == 1);
208c5f01b2fSopenharmony_ci
209c5f01b2fSopenharmony_ci                        // check individual bytes
210c5f01b2fSopenharmony_ci                        CHECK(result[0] == i);
211c5f01b2fSopenharmony_ci
212c5f01b2fSopenharmony_ci                        // roundtrip
213c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
214c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
215c5f01b2fSopenharmony_ci                    }
216c5f01b2fSopenharmony_ci                }
217c5f01b2fSopenharmony_ci
218c5f01b2fSopenharmony_ci                SECTION("128..255 (int 8)")
219c5f01b2fSopenharmony_ci                {
220c5f01b2fSopenharmony_ci                    for (size_t i = 128; i <= 255; ++i)
221c5f01b2fSopenharmony_ci                    {
222c5f01b2fSopenharmony_ci                        CAPTURE(i)
223c5f01b2fSopenharmony_ci
224c5f01b2fSopenharmony_ci                        // create JSON value with integer number
225c5f01b2fSopenharmony_ci                        json j = -1;
226c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
227c5f01b2fSopenharmony_ci
228c5f01b2fSopenharmony_ci                        // check type
229c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
230c5f01b2fSopenharmony_ci
231c5f01b2fSopenharmony_ci                        // create expected byte vector
232c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
233c5f01b2fSopenharmony_ci                        expected.push_back(0xcc);
234c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i));
235c5f01b2fSopenharmony_ci
236c5f01b2fSopenharmony_ci                        // compare result + size
237c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
238c5f01b2fSopenharmony_ci                        CHECK(result == expected);
239c5f01b2fSopenharmony_ci                        CHECK(result.size() == 2);
240c5f01b2fSopenharmony_ci
241c5f01b2fSopenharmony_ci                        // check individual bytes
242c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xcc);
243c5f01b2fSopenharmony_ci                        auto restored = static_cast<uint8_t>(result[1]);
244c5f01b2fSopenharmony_ci                        CHECK(restored == i);
245c5f01b2fSopenharmony_ci
246c5f01b2fSopenharmony_ci                        // roundtrip
247c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
248c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
249c5f01b2fSopenharmony_ci                    }
250c5f01b2fSopenharmony_ci                }
251c5f01b2fSopenharmony_ci
252c5f01b2fSopenharmony_ci                SECTION("256..65535 (int 16)")
253c5f01b2fSopenharmony_ci                {
254c5f01b2fSopenharmony_ci                    for (size_t i = 256; i <= 65535; ++i)
255c5f01b2fSopenharmony_ci                    {
256c5f01b2fSopenharmony_ci                        CAPTURE(i)
257c5f01b2fSopenharmony_ci
258c5f01b2fSopenharmony_ci                        // create JSON value with integer number
259c5f01b2fSopenharmony_ci                        json j = -1;
260c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
261c5f01b2fSopenharmony_ci
262c5f01b2fSopenharmony_ci                        // check type
263c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
264c5f01b2fSopenharmony_ci
265c5f01b2fSopenharmony_ci                        // create expected byte vector
266c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
267c5f01b2fSopenharmony_ci                        expected.push_back(0xcd);
268c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
269c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
270c5f01b2fSopenharmony_ci
271c5f01b2fSopenharmony_ci                        // compare result + size
272c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
273c5f01b2fSopenharmony_ci                        CHECK(result == expected);
274c5f01b2fSopenharmony_ci                        CHECK(result.size() == 3);
275c5f01b2fSopenharmony_ci
276c5f01b2fSopenharmony_ci                        // check individual bytes
277c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xcd);
278c5f01b2fSopenharmony_ci                        auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
279c5f01b2fSopenharmony_ci                        CHECK(restored == i);
280c5f01b2fSopenharmony_ci
281c5f01b2fSopenharmony_ci                        // roundtrip
282c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
283c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
284c5f01b2fSopenharmony_ci                    }
285c5f01b2fSopenharmony_ci                }
286c5f01b2fSopenharmony_ci
287c5f01b2fSopenharmony_ci                SECTION("65536..4294967295 (int 32)")
288c5f01b2fSopenharmony_ci                {
289c5f01b2fSopenharmony_ci                    for (uint32_t i :
290c5f01b2fSopenharmony_ci                            {
291c5f01b2fSopenharmony_ci                                65536u, 77777u, 1048576u, 4294967295u
292c5f01b2fSopenharmony_ci                            })
293c5f01b2fSopenharmony_ci                    {
294c5f01b2fSopenharmony_ci                        CAPTURE(i)
295c5f01b2fSopenharmony_ci
296c5f01b2fSopenharmony_ci                        // create JSON value with integer number
297c5f01b2fSopenharmony_ci                        json j = -1;
298c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
299c5f01b2fSopenharmony_ci
300c5f01b2fSopenharmony_ci                        // check type
301c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
302c5f01b2fSopenharmony_ci
303c5f01b2fSopenharmony_ci                        // create expected byte vector
304c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
305c5f01b2fSopenharmony_ci                        expected.push_back(0xce);
306c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
307c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
308c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
309c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
310c5f01b2fSopenharmony_ci
311c5f01b2fSopenharmony_ci                        // compare result + size
312c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
313c5f01b2fSopenharmony_ci                        CHECK(result == expected);
314c5f01b2fSopenharmony_ci                        CHECK(result.size() == 5);
315c5f01b2fSopenharmony_ci
316c5f01b2fSopenharmony_ci                        // check individual bytes
317c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xce);
318c5f01b2fSopenharmony_ci                        uint32_t restored = (static_cast<uint32_t>(result[1]) << 030) +
319c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[2]) << 020) +
320c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[3]) << 010) +
321c5f01b2fSopenharmony_ci                                            static_cast<uint32_t>(result[4]);
322c5f01b2fSopenharmony_ci                        CHECK(restored == i);
323c5f01b2fSopenharmony_ci
324c5f01b2fSopenharmony_ci                        // roundtrip
325c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
326c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
327c5f01b2fSopenharmony_ci                    }
328c5f01b2fSopenharmony_ci                }
329c5f01b2fSopenharmony_ci
330c5f01b2fSopenharmony_ci                SECTION("4294967296..9223372036854775807 (int 64)")
331c5f01b2fSopenharmony_ci                {
332c5f01b2fSopenharmony_ci                    for (uint64_t i :
333c5f01b2fSopenharmony_ci                            {
334c5f01b2fSopenharmony_ci                                4294967296LU, 9223372036854775807LU
335c5f01b2fSopenharmony_ci                            })
336c5f01b2fSopenharmony_ci                    {
337c5f01b2fSopenharmony_ci                        CAPTURE(i)
338c5f01b2fSopenharmony_ci
339c5f01b2fSopenharmony_ci                        // create JSON value with integer number
340c5f01b2fSopenharmony_ci                        json j = -1;
341c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
342c5f01b2fSopenharmony_ci
343c5f01b2fSopenharmony_ci                        // check type
344c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
345c5f01b2fSopenharmony_ci
346c5f01b2fSopenharmony_ci                        // create expected byte vector
347c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
348c5f01b2fSopenharmony_ci                        expected.push_back(0xcf);
349c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 070) & 0xff));
350c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 060) & 0xff));
351c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 050) & 0xff));
352c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 040) & 0xff));
353c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 030) & 0xff));
354c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 020) & 0xff));
355c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 010) & 0xff));
356c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
357c5f01b2fSopenharmony_ci
358c5f01b2fSopenharmony_ci                        // compare result + size
359c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
360c5f01b2fSopenharmony_ci                        CHECK(result == expected);
361c5f01b2fSopenharmony_ci                        CHECK(result.size() == 9);
362c5f01b2fSopenharmony_ci
363c5f01b2fSopenharmony_ci                        // check individual bytes
364c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xcf);
365c5f01b2fSopenharmony_ci                        uint64_t restored = (static_cast<uint64_t>(result[1]) << 070) +
366c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[2]) << 060) +
367c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[3]) << 050) +
368c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[4]) << 040) +
369c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[5]) << 030) +
370c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[6]) << 020) +
371c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[7]) << 010) +
372c5f01b2fSopenharmony_ci                                            static_cast<uint64_t>(result[8]);
373c5f01b2fSopenharmony_ci                        CHECK(restored == i);
374c5f01b2fSopenharmony_ci
375c5f01b2fSopenharmony_ci                        // roundtrip
376c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
377c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
378c5f01b2fSopenharmony_ci                    }
379c5f01b2fSopenharmony_ci                }
380c5f01b2fSopenharmony_ci
381c5f01b2fSopenharmony_ci                SECTION("-128..-33 (int 8)")
382c5f01b2fSopenharmony_ci                {
383c5f01b2fSopenharmony_ci                    for (auto i = -128; i <= -33; ++i)
384c5f01b2fSopenharmony_ci                    {
385c5f01b2fSopenharmony_ci                        CAPTURE(i)
386c5f01b2fSopenharmony_ci
387c5f01b2fSopenharmony_ci                        // create JSON value with integer number
388c5f01b2fSopenharmony_ci                        json j = i;
389c5f01b2fSopenharmony_ci
390c5f01b2fSopenharmony_ci                        // check type
391c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
392c5f01b2fSopenharmony_ci
393c5f01b2fSopenharmony_ci                        // create expected byte vector
394c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
395c5f01b2fSopenharmony_ci                        expected.push_back(0xd0);
396c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i));
397c5f01b2fSopenharmony_ci
398c5f01b2fSopenharmony_ci                        // compare result + size
399c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
400c5f01b2fSopenharmony_ci                        CHECK(result == expected);
401c5f01b2fSopenharmony_ci                        CHECK(result.size() == 2);
402c5f01b2fSopenharmony_ci
403c5f01b2fSopenharmony_ci                        // check individual bytes
404c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xd0);
405c5f01b2fSopenharmony_ci                        CHECK(static_cast<int8_t>(result[1]) == i);
406c5f01b2fSopenharmony_ci
407c5f01b2fSopenharmony_ci                        // roundtrip
408c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
409c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
410c5f01b2fSopenharmony_ci                    }
411c5f01b2fSopenharmony_ci                }
412c5f01b2fSopenharmony_ci
413c5f01b2fSopenharmony_ci                SECTION("-9263 (int 16)")
414c5f01b2fSopenharmony_ci                {
415c5f01b2fSopenharmony_ci                    json j = -9263;
416c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {0xd1, 0xdb, 0xd1};
417c5f01b2fSopenharmony_ci
418c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
419c5f01b2fSopenharmony_ci                    CHECK(result == expected);
420c5f01b2fSopenharmony_ci
421c5f01b2fSopenharmony_ci                    auto restored = static_cast<int16_t>((result[1] << 8) + result[2]);
422c5f01b2fSopenharmony_ci                    CHECK(restored == -9263);
423c5f01b2fSopenharmony_ci
424c5f01b2fSopenharmony_ci                    // roundtrip
425c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
426c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
427c5f01b2fSopenharmony_ci                }
428c5f01b2fSopenharmony_ci
429c5f01b2fSopenharmony_ci                SECTION("-32768..-129 (int 16)")
430c5f01b2fSopenharmony_ci                {
431c5f01b2fSopenharmony_ci                    for (int16_t i = -32768; i <= static_cast<std::int16_t>(-129); ++i)
432c5f01b2fSopenharmony_ci                    {
433c5f01b2fSopenharmony_ci                        CAPTURE(i)
434c5f01b2fSopenharmony_ci
435c5f01b2fSopenharmony_ci                        // create JSON value with integer number
436c5f01b2fSopenharmony_ci                        json j = i;
437c5f01b2fSopenharmony_ci
438c5f01b2fSopenharmony_ci                        // check type
439c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
440c5f01b2fSopenharmony_ci
441c5f01b2fSopenharmony_ci                        // create expected byte vector
442c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
443c5f01b2fSopenharmony_ci                        expected.push_back(0xd1);
444c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
445c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
446c5f01b2fSopenharmony_ci
447c5f01b2fSopenharmony_ci                        // compare result + size
448c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
449c5f01b2fSopenharmony_ci                        CHECK(result == expected);
450c5f01b2fSopenharmony_ci                        CHECK(result.size() == 3);
451c5f01b2fSopenharmony_ci
452c5f01b2fSopenharmony_ci                        // check individual bytes
453c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xd1);
454c5f01b2fSopenharmony_ci                        auto restored = static_cast<int16_t>((result[1] << 8) + result[2]);
455c5f01b2fSopenharmony_ci                        CHECK(restored == i);
456c5f01b2fSopenharmony_ci
457c5f01b2fSopenharmony_ci                        // roundtrip
458c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
459c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
460c5f01b2fSopenharmony_ci                    }
461c5f01b2fSopenharmony_ci                }
462c5f01b2fSopenharmony_ci
463c5f01b2fSopenharmony_ci                SECTION("-32769..-2147483648")
464c5f01b2fSopenharmony_ci                {
465c5f01b2fSopenharmony_ci                    std::vector<int32_t> numbers;
466c5f01b2fSopenharmony_ci                    numbers.push_back(-32769);
467c5f01b2fSopenharmony_ci                    numbers.push_back(-65536);
468c5f01b2fSopenharmony_ci                    numbers.push_back(-77777);
469c5f01b2fSopenharmony_ci                    numbers.push_back(-1048576);
470c5f01b2fSopenharmony_ci                    numbers.push_back(-2147483648LL);
471c5f01b2fSopenharmony_ci                    for (auto i : numbers)
472c5f01b2fSopenharmony_ci                    {
473c5f01b2fSopenharmony_ci                        CAPTURE(i)
474c5f01b2fSopenharmony_ci
475c5f01b2fSopenharmony_ci                        // create JSON value with integer number
476c5f01b2fSopenharmony_ci                        json j = i;
477c5f01b2fSopenharmony_ci
478c5f01b2fSopenharmony_ci                        // check type
479c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
480c5f01b2fSopenharmony_ci
481c5f01b2fSopenharmony_ci                        // create expected byte vector
482c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
483c5f01b2fSopenharmony_ci                        expected.push_back(0xd2);
484c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
485c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
486c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
487c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
488c5f01b2fSopenharmony_ci
489c5f01b2fSopenharmony_ci                        // compare result + size
490c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
491c5f01b2fSopenharmony_ci                        CHECK(result == expected);
492c5f01b2fSopenharmony_ci                        CHECK(result.size() == 5);
493c5f01b2fSopenharmony_ci
494c5f01b2fSopenharmony_ci                        // check individual bytes
495c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xd2);
496c5f01b2fSopenharmony_ci                        uint32_t restored = (static_cast<uint32_t>(result[1]) << 030) +
497c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[2]) << 020) +
498c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[3]) << 010) +
499c5f01b2fSopenharmony_ci                                            static_cast<uint32_t>(result[4]);
500c5f01b2fSopenharmony_ci                        CHECK(static_cast<std::int32_t>(restored) == i);
501c5f01b2fSopenharmony_ci
502c5f01b2fSopenharmony_ci                        // roundtrip
503c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
504c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
505c5f01b2fSopenharmony_ci                    }
506c5f01b2fSopenharmony_ci                }
507c5f01b2fSopenharmony_ci
508c5f01b2fSopenharmony_ci                SECTION("-9223372036854775808..-2147483649 (int 64)")
509c5f01b2fSopenharmony_ci                {
510c5f01b2fSopenharmony_ci                    std::vector<int64_t> numbers;
511c5f01b2fSopenharmony_ci                    numbers.push_back(INT64_MIN);
512c5f01b2fSopenharmony_ci                    numbers.push_back(-2147483649LL);
513c5f01b2fSopenharmony_ci                    for (auto i : numbers)
514c5f01b2fSopenharmony_ci                    {
515c5f01b2fSopenharmony_ci                        CAPTURE(i)
516c5f01b2fSopenharmony_ci
517c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
518c5f01b2fSopenharmony_ci                        json j = i;
519c5f01b2fSopenharmony_ci
520c5f01b2fSopenharmony_ci                        // check type
521c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
522c5f01b2fSopenharmony_ci
523c5f01b2fSopenharmony_ci                        // create expected byte vector
524c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
525c5f01b2fSopenharmony_ci                        expected.push_back(0xd3);
526c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 070) & 0xff));
527c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 060) & 0xff));
528c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 050) & 0xff));
529c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 040) & 0xff));
530c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 030) & 0xff));
531c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 020) & 0xff));
532c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 010) & 0xff));
533c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
534c5f01b2fSopenharmony_ci
535c5f01b2fSopenharmony_ci                        // compare result + size
536c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
537c5f01b2fSopenharmony_ci                        CHECK(result == expected);
538c5f01b2fSopenharmony_ci                        CHECK(result.size() == 9);
539c5f01b2fSopenharmony_ci
540c5f01b2fSopenharmony_ci                        // check individual bytes
541c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xd3);
542c5f01b2fSopenharmony_ci                        int64_t restored = (static_cast<int64_t>(result[1]) << 070) +
543c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[2]) << 060) +
544c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[3]) << 050) +
545c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[4]) << 040) +
546c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[5]) << 030) +
547c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[6]) << 020) +
548c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[7]) << 010) +
549c5f01b2fSopenharmony_ci                                           static_cast<int64_t>(result[8]);
550c5f01b2fSopenharmony_ci                        CHECK(restored == i);
551c5f01b2fSopenharmony_ci
552c5f01b2fSopenharmony_ci                        // roundtrip
553c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
554c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
555c5f01b2fSopenharmony_ci                    }
556c5f01b2fSopenharmony_ci                }
557c5f01b2fSopenharmony_ci            }
558c5f01b2fSopenharmony_ci
559c5f01b2fSopenharmony_ci            SECTION("unsigned")
560c5f01b2fSopenharmony_ci            {
561c5f01b2fSopenharmony_ci                SECTION("0..127 (positive fixnum)")
562c5f01b2fSopenharmony_ci                {
563c5f01b2fSopenharmony_ci                    for (size_t i = 0; i <= 127; ++i)
564c5f01b2fSopenharmony_ci                    {
565c5f01b2fSopenharmony_ci                        CAPTURE(i)
566c5f01b2fSopenharmony_ci
567c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
568c5f01b2fSopenharmony_ci                        json j = i;
569c5f01b2fSopenharmony_ci
570c5f01b2fSopenharmony_ci                        // check type
571c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
572c5f01b2fSopenharmony_ci
573c5f01b2fSopenharmony_ci                        // create expected byte vector
574c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
575c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i));
576c5f01b2fSopenharmony_ci
577c5f01b2fSopenharmony_ci                        // compare result + size
578c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
579c5f01b2fSopenharmony_ci                        CHECK(result == expected);
580c5f01b2fSopenharmony_ci                        CHECK(result.size() == 1);
581c5f01b2fSopenharmony_ci
582c5f01b2fSopenharmony_ci                        // check individual bytes
583c5f01b2fSopenharmony_ci                        CHECK(result[0] == i);
584c5f01b2fSopenharmony_ci
585c5f01b2fSopenharmony_ci                        // roundtrip
586c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
587c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
588c5f01b2fSopenharmony_ci                    }
589c5f01b2fSopenharmony_ci                }
590c5f01b2fSopenharmony_ci
591c5f01b2fSopenharmony_ci                SECTION("128..255 (uint 8)")
592c5f01b2fSopenharmony_ci                {
593c5f01b2fSopenharmony_ci                    for (size_t i = 128; i <= 255; ++i)
594c5f01b2fSopenharmony_ci                    {
595c5f01b2fSopenharmony_ci                        CAPTURE(i)
596c5f01b2fSopenharmony_ci
597c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
598c5f01b2fSopenharmony_ci                        json j = i;
599c5f01b2fSopenharmony_ci
600c5f01b2fSopenharmony_ci                        // check type
601c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
602c5f01b2fSopenharmony_ci
603c5f01b2fSopenharmony_ci                        // create expected byte vector
604c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
605c5f01b2fSopenharmony_ci                        expected.push_back(0xcc);
606c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i));
607c5f01b2fSopenharmony_ci
608c5f01b2fSopenharmony_ci                        // compare result + size
609c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
610c5f01b2fSopenharmony_ci                        CHECK(result == expected);
611c5f01b2fSopenharmony_ci                        CHECK(result.size() == 2);
612c5f01b2fSopenharmony_ci
613c5f01b2fSopenharmony_ci                        // check individual bytes
614c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xcc);
615c5f01b2fSopenharmony_ci                        auto restored = static_cast<uint8_t>(result[1]);
616c5f01b2fSopenharmony_ci                        CHECK(restored == i);
617c5f01b2fSopenharmony_ci
618c5f01b2fSopenharmony_ci                        // roundtrip
619c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
620c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
621c5f01b2fSopenharmony_ci                    }
622c5f01b2fSopenharmony_ci                }
623c5f01b2fSopenharmony_ci
624c5f01b2fSopenharmony_ci                SECTION("256..65535 (uint 16)")
625c5f01b2fSopenharmony_ci                {
626c5f01b2fSopenharmony_ci                    for (size_t i = 256; i <= 65535; ++i)
627c5f01b2fSopenharmony_ci                    {
628c5f01b2fSopenharmony_ci                        CAPTURE(i)
629c5f01b2fSopenharmony_ci
630c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
631c5f01b2fSopenharmony_ci                        json j = i;
632c5f01b2fSopenharmony_ci
633c5f01b2fSopenharmony_ci                        // check type
634c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
635c5f01b2fSopenharmony_ci
636c5f01b2fSopenharmony_ci                        // create expected byte vector
637c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
638c5f01b2fSopenharmony_ci                        expected.push_back(0xcd);
639c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
640c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
641c5f01b2fSopenharmony_ci
642c5f01b2fSopenharmony_ci                        // compare result + size
643c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
644c5f01b2fSopenharmony_ci                        CHECK(result == expected);
645c5f01b2fSopenharmony_ci                        CHECK(result.size() == 3);
646c5f01b2fSopenharmony_ci
647c5f01b2fSopenharmony_ci                        // check individual bytes
648c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xcd);
649c5f01b2fSopenharmony_ci                        auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
650c5f01b2fSopenharmony_ci                        CHECK(restored == i);
651c5f01b2fSopenharmony_ci
652c5f01b2fSopenharmony_ci                        // roundtrip
653c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
654c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
655c5f01b2fSopenharmony_ci                    }
656c5f01b2fSopenharmony_ci                }
657c5f01b2fSopenharmony_ci
658c5f01b2fSopenharmony_ci                SECTION("65536..4294967295 (uint 32)")
659c5f01b2fSopenharmony_ci                {
660c5f01b2fSopenharmony_ci                    for (uint32_t i :
661c5f01b2fSopenharmony_ci                            {
662c5f01b2fSopenharmony_ci                                65536u, 77777u, 1048576u, 4294967295u
663c5f01b2fSopenharmony_ci                            })
664c5f01b2fSopenharmony_ci                    {
665c5f01b2fSopenharmony_ci                        CAPTURE(i)
666c5f01b2fSopenharmony_ci
667c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
668c5f01b2fSopenharmony_ci                        json j = i;
669c5f01b2fSopenharmony_ci
670c5f01b2fSopenharmony_ci                        // check type
671c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
672c5f01b2fSopenharmony_ci
673c5f01b2fSopenharmony_ci                        // create expected byte vector
674c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
675c5f01b2fSopenharmony_ci                        expected.push_back(0xce);
676c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
677c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
678c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
679c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
680c5f01b2fSopenharmony_ci
681c5f01b2fSopenharmony_ci                        // compare result + size
682c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
683c5f01b2fSopenharmony_ci                        CHECK(result == expected);
684c5f01b2fSopenharmony_ci                        CHECK(result.size() == 5);
685c5f01b2fSopenharmony_ci
686c5f01b2fSopenharmony_ci                        // check individual bytes
687c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xce);
688c5f01b2fSopenharmony_ci                        uint32_t restored = (static_cast<uint32_t>(result[1]) << 030) +
689c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[2]) << 020) +
690c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[3]) << 010) +
691c5f01b2fSopenharmony_ci                                            static_cast<uint32_t>(result[4]);
692c5f01b2fSopenharmony_ci                        CHECK(restored == i);
693c5f01b2fSopenharmony_ci
694c5f01b2fSopenharmony_ci                        // roundtrip
695c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
696c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
697c5f01b2fSopenharmony_ci                    }
698c5f01b2fSopenharmony_ci                }
699c5f01b2fSopenharmony_ci
700c5f01b2fSopenharmony_ci                SECTION("4294967296..18446744073709551615 (uint 64)")
701c5f01b2fSopenharmony_ci                {
702c5f01b2fSopenharmony_ci                    for (uint64_t i :
703c5f01b2fSopenharmony_ci                            {
704c5f01b2fSopenharmony_ci                                4294967296LU, 18446744073709551615LU
705c5f01b2fSopenharmony_ci                            })
706c5f01b2fSopenharmony_ci                    {
707c5f01b2fSopenharmony_ci                        CAPTURE(i)
708c5f01b2fSopenharmony_ci
709c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
710c5f01b2fSopenharmony_ci                        json j = i;
711c5f01b2fSopenharmony_ci
712c5f01b2fSopenharmony_ci                        // check type
713c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
714c5f01b2fSopenharmony_ci
715c5f01b2fSopenharmony_ci                        // create expected byte vector
716c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
717c5f01b2fSopenharmony_ci                        expected.push_back(0xcf);
718c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 070) & 0xff));
719c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 060) & 0xff));
720c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 050) & 0xff));
721c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 040) & 0xff));
722c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 030) & 0xff));
723c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 020) & 0xff));
724c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 010) & 0xff));
725c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
726c5f01b2fSopenharmony_ci
727c5f01b2fSopenharmony_ci                        // compare result + size
728c5f01b2fSopenharmony_ci                        const auto result = json::to_msgpack(j);
729c5f01b2fSopenharmony_ci                        CHECK(result == expected);
730c5f01b2fSopenharmony_ci                        CHECK(result.size() == 9);
731c5f01b2fSopenharmony_ci
732c5f01b2fSopenharmony_ci                        // check individual bytes
733c5f01b2fSopenharmony_ci                        CHECK(result[0] == 0xcf);
734c5f01b2fSopenharmony_ci                        uint64_t restored = (static_cast<uint64_t>(result[1]) << 070) +
735c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[2]) << 060) +
736c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[3]) << 050) +
737c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[4]) << 040) +
738c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[5]) << 030) +
739c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[6]) << 020) +
740c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[7]) << 010) +
741c5f01b2fSopenharmony_ci                                            static_cast<uint64_t>(result[8]);
742c5f01b2fSopenharmony_ci                        CHECK(restored == i);
743c5f01b2fSopenharmony_ci
744c5f01b2fSopenharmony_ci                        // roundtrip
745c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result) == j);
746c5f01b2fSopenharmony_ci                        CHECK(json::from_msgpack(result, true, false) == j);
747c5f01b2fSopenharmony_ci                    }
748c5f01b2fSopenharmony_ci                }
749c5f01b2fSopenharmony_ci            }
750c5f01b2fSopenharmony_ci
751c5f01b2fSopenharmony_ci            SECTION("float")
752c5f01b2fSopenharmony_ci            {
753c5f01b2fSopenharmony_ci                SECTION("3.1415925")
754c5f01b2fSopenharmony_ci                {
755c5f01b2fSopenharmony_ci                    double v = 3.1415925;
756c5f01b2fSopenharmony_ci                    json j = v;
757c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected =
758c5f01b2fSopenharmony_ci                    {
759c5f01b2fSopenharmony_ci                        0xcb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc
760c5f01b2fSopenharmony_ci                    };
761c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
762c5f01b2fSopenharmony_ci                    CHECK(result == expected);
763c5f01b2fSopenharmony_ci
764c5f01b2fSopenharmony_ci                    // roundtrip
765c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
766c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == v);
767c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
768c5f01b2fSopenharmony_ci                }
769c5f01b2fSopenharmony_ci
770c5f01b2fSopenharmony_ci                SECTION("1.0")
771c5f01b2fSopenharmony_ci                {
772c5f01b2fSopenharmony_ci                    double v = 1.0;
773c5f01b2fSopenharmony_ci                    json j = v;
774c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected =
775c5f01b2fSopenharmony_ci                    {
776c5f01b2fSopenharmony_ci                        0xca, 0x3f, 0x80, 0x00, 0x00
777c5f01b2fSopenharmony_ci                    };
778c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
779c5f01b2fSopenharmony_ci                    CHECK(result == expected);
780c5f01b2fSopenharmony_ci
781c5f01b2fSopenharmony_ci                    // roundtrip
782c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
783c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == v);
784c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
785c5f01b2fSopenharmony_ci                }
786c5f01b2fSopenharmony_ci
787c5f01b2fSopenharmony_ci                SECTION("128.128")
788c5f01b2fSopenharmony_ci                {
789c5f01b2fSopenharmony_ci                    double v = 128.1280059814453125;
790c5f01b2fSopenharmony_ci                    json j = v;
791c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected =
792c5f01b2fSopenharmony_ci                    {
793c5f01b2fSopenharmony_ci                        0xca, 0x43, 0x00, 0x20, 0xc5
794c5f01b2fSopenharmony_ci                    };
795c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
796c5f01b2fSopenharmony_ci                    CHECK(result == expected);
797c5f01b2fSopenharmony_ci
798c5f01b2fSopenharmony_ci                    // roundtrip
799c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
800c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == v);
801c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
802c5f01b2fSopenharmony_ci                }
803c5f01b2fSopenharmony_ci            }
804c5f01b2fSopenharmony_ci        }
805c5f01b2fSopenharmony_ci
806c5f01b2fSopenharmony_ci        SECTION("string")
807c5f01b2fSopenharmony_ci        {
808c5f01b2fSopenharmony_ci            SECTION("N = 0..31")
809c5f01b2fSopenharmony_ci            {
810c5f01b2fSopenharmony_ci                // explicitly enumerate the first byte for all 32 strings
811c5f01b2fSopenharmony_ci                const std::vector<uint8_t> first_bytes =
812c5f01b2fSopenharmony_ci                {
813c5f01b2fSopenharmony_ci                    0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8,
814c5f01b2fSopenharmony_ci                    0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1,
815c5f01b2fSopenharmony_ci                    0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba,
816c5f01b2fSopenharmony_ci                    0xbb, 0xbc, 0xbd, 0xbe, 0xbf
817c5f01b2fSopenharmony_ci                };
818c5f01b2fSopenharmony_ci
819c5f01b2fSopenharmony_ci                for (size_t N = 0; N < first_bytes.size(); ++N)
820c5f01b2fSopenharmony_ci                {
821c5f01b2fSopenharmony_ci                    CAPTURE(N)
822c5f01b2fSopenharmony_ci
823c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
824c5f01b2fSopenharmony_ci                    const auto s = std::string(N, 'x');
825c5f01b2fSopenharmony_ci                    json j = s;
826c5f01b2fSopenharmony_ci
827c5f01b2fSopenharmony_ci                    // create expected byte vector
828c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected;
829c5f01b2fSopenharmony_ci                    expected.push_back(first_bytes[N]);
830c5f01b2fSopenharmony_ci                    for (size_t i = 0; i < N; ++i)
831c5f01b2fSopenharmony_ci                    {
832c5f01b2fSopenharmony_ci                        expected.push_back('x');
833c5f01b2fSopenharmony_ci                    }
834c5f01b2fSopenharmony_ci
835c5f01b2fSopenharmony_ci                    // check first byte
836c5f01b2fSopenharmony_ci                    CHECK((first_bytes[N] & 0x1f) == N);
837c5f01b2fSopenharmony_ci
838c5f01b2fSopenharmony_ci                    // compare result + size
839c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
840c5f01b2fSopenharmony_ci                    CHECK(result == expected);
841c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 1);
842c5f01b2fSopenharmony_ci                    // check that no null byte is appended
843c5f01b2fSopenharmony_ci                    if (N > 0)
844c5f01b2fSopenharmony_ci                    {
845c5f01b2fSopenharmony_ci                        CHECK(result.back() != '\x00');
846c5f01b2fSopenharmony_ci                    }
847c5f01b2fSopenharmony_ci
848c5f01b2fSopenharmony_ci                    // roundtrip
849c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
850c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
851c5f01b2fSopenharmony_ci                }
852c5f01b2fSopenharmony_ci            }
853c5f01b2fSopenharmony_ci
854c5f01b2fSopenharmony_ci            SECTION("N = 32..255")
855c5f01b2fSopenharmony_ci            {
856c5f01b2fSopenharmony_ci                for (size_t N = 32; N <= 255; ++N)
857c5f01b2fSopenharmony_ci                {
858c5f01b2fSopenharmony_ci                    CAPTURE(N)
859c5f01b2fSopenharmony_ci
860c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
861c5f01b2fSopenharmony_ci                    const auto s = std::string(N, 'x');
862c5f01b2fSopenharmony_ci                    json j = s;
863c5f01b2fSopenharmony_ci
864c5f01b2fSopenharmony_ci                    // create expected byte vector
865c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected;
866c5f01b2fSopenharmony_ci                    expected.push_back(0xd9);
867c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<uint8_t>(N));
868c5f01b2fSopenharmony_ci                    for (size_t i = 0; i < N; ++i)
869c5f01b2fSopenharmony_ci                    {
870c5f01b2fSopenharmony_ci                        expected.push_back('x');
871c5f01b2fSopenharmony_ci                    }
872c5f01b2fSopenharmony_ci
873c5f01b2fSopenharmony_ci                    // compare result + size
874c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
875c5f01b2fSopenharmony_ci                    CHECK(result == expected);
876c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 2);
877c5f01b2fSopenharmony_ci                    // check that no null byte is appended
878c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
879c5f01b2fSopenharmony_ci
880c5f01b2fSopenharmony_ci                    // roundtrip
881c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
882c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
883c5f01b2fSopenharmony_ci                }
884c5f01b2fSopenharmony_ci            }
885c5f01b2fSopenharmony_ci
886c5f01b2fSopenharmony_ci            SECTION("N = 256..65535")
887c5f01b2fSopenharmony_ci            {
888c5f01b2fSopenharmony_ci                for (size_t N :
889c5f01b2fSopenharmony_ci                        {
890c5f01b2fSopenharmony_ci                            256u, 999u, 1025u, 3333u, 2048u, 65535u
891c5f01b2fSopenharmony_ci                        })
892c5f01b2fSopenharmony_ci                {
893c5f01b2fSopenharmony_ci                    CAPTURE(N)
894c5f01b2fSopenharmony_ci
895c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
896c5f01b2fSopenharmony_ci                    const auto s = std::string(N, 'x');
897c5f01b2fSopenharmony_ci                    json j = s;
898c5f01b2fSopenharmony_ci
899c5f01b2fSopenharmony_ci                    // create expected byte vector (hack: create string first)
900c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(N, 'x');
901c5f01b2fSopenharmony_ci                    // reverse order of commands, because we insert at begin()
902c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>(N & 0xff));
903c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 8) & 0xff));
904c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 0xda);
905c5f01b2fSopenharmony_ci
906c5f01b2fSopenharmony_ci                    // compare result + size
907c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
908c5f01b2fSopenharmony_ci                    CHECK(result == expected);
909c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 3);
910c5f01b2fSopenharmony_ci                    // check that no null byte is appended
911c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
912c5f01b2fSopenharmony_ci
913c5f01b2fSopenharmony_ci                    // roundtrip
914c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
915c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
916c5f01b2fSopenharmony_ci                }
917c5f01b2fSopenharmony_ci            }
918c5f01b2fSopenharmony_ci
919c5f01b2fSopenharmony_ci            SECTION("N = 65536..4294967295")
920c5f01b2fSopenharmony_ci            {
921c5f01b2fSopenharmony_ci                for (size_t N :
922c5f01b2fSopenharmony_ci                        {
923c5f01b2fSopenharmony_ci                            65536u, 77777u, 1048576u
924c5f01b2fSopenharmony_ci                        })
925c5f01b2fSopenharmony_ci                {
926c5f01b2fSopenharmony_ci                    CAPTURE(N)
927c5f01b2fSopenharmony_ci
928c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
929c5f01b2fSopenharmony_ci                    const auto s = std::string(N, 'x');
930c5f01b2fSopenharmony_ci                    json j = s;
931c5f01b2fSopenharmony_ci
932c5f01b2fSopenharmony_ci                    // create expected byte vector (hack: create string first)
933c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(N, 'x');
934c5f01b2fSopenharmony_ci                    // reverse order of commands, because we insert at begin()
935c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>(N & 0xff));
936c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 8) & 0xff));
937c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 16) & 0xff));
938c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 24) & 0xff));
939c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 0xdb);
940c5f01b2fSopenharmony_ci
941c5f01b2fSopenharmony_ci                    // compare result + size
942c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
943c5f01b2fSopenharmony_ci                    CHECK(result == expected);
944c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 5);
945c5f01b2fSopenharmony_ci                    // check that no null byte is appended
946c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
947c5f01b2fSopenharmony_ci
948c5f01b2fSopenharmony_ci                    // roundtrip
949c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
950c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
951c5f01b2fSopenharmony_ci                }
952c5f01b2fSopenharmony_ci            }
953c5f01b2fSopenharmony_ci        }
954c5f01b2fSopenharmony_ci
955c5f01b2fSopenharmony_ci        SECTION("array")
956c5f01b2fSopenharmony_ci        {
957c5f01b2fSopenharmony_ci            SECTION("empty")
958c5f01b2fSopenharmony_ci            {
959c5f01b2fSopenharmony_ci                json j = json::array();
960c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {0x90};
961c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
962c5f01b2fSopenharmony_ci                CHECK(result == expected);
963c5f01b2fSopenharmony_ci
964c5f01b2fSopenharmony_ci                // roundtrip
965c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
966c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
967c5f01b2fSopenharmony_ci            }
968c5f01b2fSopenharmony_ci
969c5f01b2fSopenharmony_ci            SECTION("[null]")
970c5f01b2fSopenharmony_ci            {
971c5f01b2fSopenharmony_ci                json j = {nullptr};
972c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {0x91, 0xc0};
973c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
974c5f01b2fSopenharmony_ci                CHECK(result == expected);
975c5f01b2fSopenharmony_ci
976c5f01b2fSopenharmony_ci                // roundtrip
977c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
978c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
979c5f01b2fSopenharmony_ci            }
980c5f01b2fSopenharmony_ci
981c5f01b2fSopenharmony_ci            SECTION("[1,2,3,4,5]")
982c5f01b2fSopenharmony_ci            {
983c5f01b2fSopenharmony_ci                json j = json::parse("[1,2,3,4,5]");
984c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {0x95, 0x01, 0x02, 0x03, 0x04, 0x05};
985c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
986c5f01b2fSopenharmony_ci                CHECK(result == expected);
987c5f01b2fSopenharmony_ci
988c5f01b2fSopenharmony_ci                // roundtrip
989c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
990c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
991c5f01b2fSopenharmony_ci            }
992c5f01b2fSopenharmony_ci
993c5f01b2fSopenharmony_ci            SECTION("[[[[]]]]")
994c5f01b2fSopenharmony_ci            {
995c5f01b2fSopenharmony_ci                json j = json::parse("[[[[]]]]");
996c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {0x91, 0x91, 0x91, 0x90};
997c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
998c5f01b2fSopenharmony_ci                CHECK(result == expected);
999c5f01b2fSopenharmony_ci
1000c5f01b2fSopenharmony_ci                // roundtrip
1001c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
1002c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
1003c5f01b2fSopenharmony_ci            }
1004c5f01b2fSopenharmony_ci
1005c5f01b2fSopenharmony_ci            SECTION("array 16")
1006c5f01b2fSopenharmony_ci            {
1007c5f01b2fSopenharmony_ci                json j(16, nullptr);
1008c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected(j.size() + 3, 0xc0); // all null
1009c5f01b2fSopenharmony_ci                expected[0] = 0xdc; // array 16
1010c5f01b2fSopenharmony_ci                expected[1] = 0x00; // size (0x0010), byte 0
1011c5f01b2fSopenharmony_ci                expected[2] = 0x10; // size (0x0010), byte 1
1012c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
1013c5f01b2fSopenharmony_ci                CHECK(result == expected);
1014c5f01b2fSopenharmony_ci
1015c5f01b2fSopenharmony_ci                // roundtrip
1016c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
1017c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
1018c5f01b2fSopenharmony_ci            }
1019c5f01b2fSopenharmony_ci
1020c5f01b2fSopenharmony_ci            SECTION("array 32")
1021c5f01b2fSopenharmony_ci            {
1022c5f01b2fSopenharmony_ci                json j(65536, nullptr);
1023c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected(j.size() + 5, 0xc0); // all null
1024c5f01b2fSopenharmony_ci                expected[0] = 0xdd; // array 32
1025c5f01b2fSopenharmony_ci                expected[1] = 0x00; // size (0x00100000), byte 0
1026c5f01b2fSopenharmony_ci                expected[2] = 0x01; // size (0x00100000), byte 1
1027c5f01b2fSopenharmony_ci                expected[3] = 0x00; // size (0x00100000), byte 2
1028c5f01b2fSopenharmony_ci                expected[4] = 0x00; // size (0x00100000), byte 3
1029c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
1030c5f01b2fSopenharmony_ci                //CHECK(result == expected);
1031c5f01b2fSopenharmony_ci
1032c5f01b2fSopenharmony_ci                CHECK(result.size() == expected.size());
1033c5f01b2fSopenharmony_ci                for (size_t i = 0; i < expected.size(); ++i)
1034c5f01b2fSopenharmony_ci                {
1035c5f01b2fSopenharmony_ci                    CAPTURE(i)
1036c5f01b2fSopenharmony_ci                    CHECK(result[i] == expected[i]);
1037c5f01b2fSopenharmony_ci                }
1038c5f01b2fSopenharmony_ci
1039c5f01b2fSopenharmony_ci                // roundtrip
1040c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
1041c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
1042c5f01b2fSopenharmony_ci            }
1043c5f01b2fSopenharmony_ci        }
1044c5f01b2fSopenharmony_ci
1045c5f01b2fSopenharmony_ci        SECTION("object")
1046c5f01b2fSopenharmony_ci        {
1047c5f01b2fSopenharmony_ci            SECTION("empty")
1048c5f01b2fSopenharmony_ci            {
1049c5f01b2fSopenharmony_ci                json j = json::object();
1050c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {0x80};
1051c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
1052c5f01b2fSopenharmony_ci                CHECK(result == expected);
1053c5f01b2fSopenharmony_ci
1054c5f01b2fSopenharmony_ci                // roundtrip
1055c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
1056c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
1057c5f01b2fSopenharmony_ci            }
1058c5f01b2fSopenharmony_ci
1059c5f01b2fSopenharmony_ci            SECTION("{\"\":null}")
1060c5f01b2fSopenharmony_ci            {
1061c5f01b2fSopenharmony_ci                json j = {{"", nullptr}};
1062c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {0x81, 0xa0, 0xc0};
1063c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
1064c5f01b2fSopenharmony_ci                CHECK(result == expected);
1065c5f01b2fSopenharmony_ci
1066c5f01b2fSopenharmony_ci                // roundtrip
1067c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
1068c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
1069c5f01b2fSopenharmony_ci            }
1070c5f01b2fSopenharmony_ci
1071c5f01b2fSopenharmony_ci            SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
1072c5f01b2fSopenharmony_ci            {
1073c5f01b2fSopenharmony_ci                json j = json::parse(R"({"a": {"b": {"c": {}}}})");
1074c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected =
1075c5f01b2fSopenharmony_ci                {
1076c5f01b2fSopenharmony_ci                    0x81, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0x81, 0xa1, 0x63, 0x80
1077c5f01b2fSopenharmony_ci                };
1078c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
1079c5f01b2fSopenharmony_ci                CHECK(result == expected);
1080c5f01b2fSopenharmony_ci
1081c5f01b2fSopenharmony_ci                // roundtrip
1082c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
1083c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
1084c5f01b2fSopenharmony_ci            }
1085c5f01b2fSopenharmony_ci
1086c5f01b2fSopenharmony_ci            SECTION("map 16")
1087c5f01b2fSopenharmony_ci            {
1088c5f01b2fSopenharmony_ci                json j = R"({"00": null, "01": null, "02": null, "03": null,
1089c5f01b2fSopenharmony_ci                             "04": null, "05": null, "06": null, "07": null,
1090c5f01b2fSopenharmony_ci                             "08": null, "09": null, "10": null, "11": null,
1091c5f01b2fSopenharmony_ci                             "12": null, "13": null, "14": null, "15": null})"_json;
1092c5f01b2fSopenharmony_ci
1093c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
1094c5f01b2fSopenharmony_ci
1095c5f01b2fSopenharmony_ci                // Checking against an expected vector byte by byte is
1096c5f01b2fSopenharmony_ci                // difficult, because no assumption on the order of key/value
1097c5f01b2fSopenharmony_ci                // pairs are made. We therefore only check the prefix (type and
1098c5f01b2fSopenharmony_ci                // size and the overall size. The rest is then handled in the
1099c5f01b2fSopenharmony_ci                // roundtrip check.
1100c5f01b2fSopenharmony_ci                CHECK(result.size() == 67); // 1 type, 2 size, 16*4 content
1101c5f01b2fSopenharmony_ci                CHECK(result[0] == 0xde); // map 16
1102c5f01b2fSopenharmony_ci                CHECK(result[1] == 0x00); // byte 0 of size (0x0010)
1103c5f01b2fSopenharmony_ci                CHECK(result[2] == 0x10); // byte 1 of size (0x0010)
1104c5f01b2fSopenharmony_ci
1105c5f01b2fSopenharmony_ci                // roundtrip
1106c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
1107c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
1108c5f01b2fSopenharmony_ci            }
1109c5f01b2fSopenharmony_ci
1110c5f01b2fSopenharmony_ci            SECTION("map 32")
1111c5f01b2fSopenharmony_ci            {
1112c5f01b2fSopenharmony_ci                json j;
1113c5f01b2fSopenharmony_ci                for (auto i = 0; i < 65536; ++i)
1114c5f01b2fSopenharmony_ci                {
1115c5f01b2fSopenharmony_ci                    // format i to a fixed width of 5
1116c5f01b2fSopenharmony_ci                    // each entry will need 7 bytes: 6 for fixstr, 1 for null
1117c5f01b2fSopenharmony_ci                    std::stringstream ss;
1118c5f01b2fSopenharmony_ci                    ss << std::setw(5) << std::setfill('0') << i;
1119c5f01b2fSopenharmony_ci                    j.emplace(ss.str(), nullptr);
1120c5f01b2fSopenharmony_ci                }
1121c5f01b2fSopenharmony_ci
1122c5f01b2fSopenharmony_ci                const auto result = json::to_msgpack(j);
1123c5f01b2fSopenharmony_ci
1124c5f01b2fSopenharmony_ci                // Checking against an expected vector byte by byte is
1125c5f01b2fSopenharmony_ci                // difficult, because no assumption on the order of key/value
1126c5f01b2fSopenharmony_ci                // pairs are made. We therefore only check the prefix (type and
1127c5f01b2fSopenharmony_ci                // size and the overall size. The rest is then handled in the
1128c5f01b2fSopenharmony_ci                // roundtrip check.
1129c5f01b2fSopenharmony_ci                CHECK(result.size() == 458757); // 1 type, 4 size, 65536*7 content
1130c5f01b2fSopenharmony_ci                CHECK(result[0] == 0xdf); // map 32
1131c5f01b2fSopenharmony_ci                CHECK(result[1] == 0x00); // byte 0 of size (0x00010000)
1132c5f01b2fSopenharmony_ci                CHECK(result[2] == 0x01); // byte 1 of size (0x00010000)
1133c5f01b2fSopenharmony_ci                CHECK(result[3] == 0x00); // byte 2 of size (0x00010000)
1134c5f01b2fSopenharmony_ci                CHECK(result[4] == 0x00); // byte 3 of size (0x00010000)
1135c5f01b2fSopenharmony_ci
1136c5f01b2fSopenharmony_ci                // roundtrip
1137c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result) == j);
1138c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(result, true, false) == j);
1139c5f01b2fSopenharmony_ci            }
1140c5f01b2fSopenharmony_ci        }
1141c5f01b2fSopenharmony_ci
1142c5f01b2fSopenharmony_ci        SECTION("extension")
1143c5f01b2fSopenharmony_ci        {
1144c5f01b2fSopenharmony_ci            SECTION("N = 0..255")
1145c5f01b2fSopenharmony_ci            {
1146c5f01b2fSopenharmony_ci                for (size_t N = 0; N <= 0xFF; ++N)
1147c5f01b2fSopenharmony_ci                {
1148c5f01b2fSopenharmony_ci                    CAPTURE(N)
1149c5f01b2fSopenharmony_ci
1150c5f01b2fSopenharmony_ci                    // create JSON value with byte array containing of N * 'x'
1151c5f01b2fSopenharmony_ci                    const auto s = std::vector<uint8_t>(N, 'x');
1152c5f01b2fSopenharmony_ci                    json j = json::binary(s);
1153c5f01b2fSopenharmony_ci                    std::uint8_t subtype = 42;
1154c5f01b2fSopenharmony_ci                    j.get_binary().set_subtype(subtype);
1155c5f01b2fSopenharmony_ci
1156c5f01b2fSopenharmony_ci                    // create expected byte vector
1157c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected;
1158c5f01b2fSopenharmony_ci                    switch (N)
1159c5f01b2fSopenharmony_ci                    {
1160c5f01b2fSopenharmony_ci                        case 1:
1161c5f01b2fSopenharmony_ci                            expected.push_back(static_cast<std::uint8_t>(0xD4));
1162c5f01b2fSopenharmony_ci                            break;
1163c5f01b2fSopenharmony_ci                        case 2:
1164c5f01b2fSopenharmony_ci                            expected.push_back(static_cast<std::uint8_t>(0xD5));
1165c5f01b2fSopenharmony_ci                            break;
1166c5f01b2fSopenharmony_ci                        case 4:
1167c5f01b2fSopenharmony_ci                            expected.push_back(static_cast<std::uint8_t>(0xD6));
1168c5f01b2fSopenharmony_ci                            break;
1169c5f01b2fSopenharmony_ci                        case 8:
1170c5f01b2fSopenharmony_ci                            expected.push_back(static_cast<std::uint8_t>(0xD7));
1171c5f01b2fSopenharmony_ci                            break;
1172c5f01b2fSopenharmony_ci                        case 16:
1173c5f01b2fSopenharmony_ci                            expected.push_back(static_cast<std::uint8_t>(0xD8));
1174c5f01b2fSopenharmony_ci                            break;
1175c5f01b2fSopenharmony_ci                        default:
1176c5f01b2fSopenharmony_ci                            expected.push_back(static_cast<std::uint8_t>(0xC7));
1177c5f01b2fSopenharmony_ci                            expected.push_back(static_cast<std::uint8_t>(N));
1178c5f01b2fSopenharmony_ci                            break;
1179c5f01b2fSopenharmony_ci                    }
1180c5f01b2fSopenharmony_ci                    expected.push_back(subtype);
1181c5f01b2fSopenharmony_ci
1182c5f01b2fSopenharmony_ci                    for (size_t i = 0; i < N; ++i)
1183c5f01b2fSopenharmony_ci                    {
1184c5f01b2fSopenharmony_ci                        expected.push_back(0x78);
1185c5f01b2fSopenharmony_ci                    }
1186c5f01b2fSopenharmony_ci
1187c5f01b2fSopenharmony_ci                    // compare result + size
1188c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
1189c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1190c5f01b2fSopenharmony_ci                    switch (N)
1191c5f01b2fSopenharmony_ci                    {
1192c5f01b2fSopenharmony_ci                        case 1:
1193c5f01b2fSopenharmony_ci                        case 2:
1194c5f01b2fSopenharmony_ci                        case 4:
1195c5f01b2fSopenharmony_ci                        case 8:
1196c5f01b2fSopenharmony_ci                        case 16:
1197c5f01b2fSopenharmony_ci                            CHECK(result.size() == N + 2);
1198c5f01b2fSopenharmony_ci                            break;
1199c5f01b2fSopenharmony_ci                        default:
1200c5f01b2fSopenharmony_ci                            CHECK(result.size() == N + 3);
1201c5f01b2fSopenharmony_ci                            break;
1202c5f01b2fSopenharmony_ci                    }
1203c5f01b2fSopenharmony_ci
1204c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1205c5f01b2fSopenharmony_ci                    if (N > 0)
1206c5f01b2fSopenharmony_ci                    {
1207c5f01b2fSopenharmony_ci                        CHECK(result.back() != '\x00');
1208c5f01b2fSopenharmony_ci                    }
1209c5f01b2fSopenharmony_ci
1210c5f01b2fSopenharmony_ci                    // roundtrip
1211c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
1212c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
1213c5f01b2fSopenharmony_ci                }
1214c5f01b2fSopenharmony_ci            }
1215c5f01b2fSopenharmony_ci
1216c5f01b2fSopenharmony_ci            SECTION("N = 256..65535")
1217c5f01b2fSopenharmony_ci            {
1218c5f01b2fSopenharmony_ci                for (std::size_t N :
1219c5f01b2fSopenharmony_ci                        {
1220c5f01b2fSopenharmony_ci                            256u, 999u, 1025u, 3333u, 2048u, 65535u
1221c5f01b2fSopenharmony_ci                        })
1222c5f01b2fSopenharmony_ci                {
1223c5f01b2fSopenharmony_ci                    CAPTURE(N)
1224c5f01b2fSopenharmony_ci
1225c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
1226c5f01b2fSopenharmony_ci                    const auto s = std::vector<uint8_t>(N, 'x');
1227c5f01b2fSopenharmony_ci                    json j = json::binary(s);
1228c5f01b2fSopenharmony_ci                    std::uint8_t subtype = 42;
1229c5f01b2fSopenharmony_ci                    j.get_binary().set_subtype(subtype);
1230c5f01b2fSopenharmony_ci
1231c5f01b2fSopenharmony_ci                    // create expected byte vector (hack: create string first)
1232c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(N, 'x');
1233c5f01b2fSopenharmony_ci                    // reverse order of commands, because we insert at begin()
1234c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), subtype);
1235c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>(N & 0xff));
1236c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 8) & 0xff));
1237c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 0xC8);
1238c5f01b2fSopenharmony_ci
1239c5f01b2fSopenharmony_ci                    // compare result + size
1240c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
1241c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1242c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 4);
1243c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1244c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1245c5f01b2fSopenharmony_ci
1246c5f01b2fSopenharmony_ci                    // roundtrip
1247c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
1248c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
1249c5f01b2fSopenharmony_ci                }
1250c5f01b2fSopenharmony_ci            }
1251c5f01b2fSopenharmony_ci
1252c5f01b2fSopenharmony_ci            SECTION("N = 65536..4294967295")
1253c5f01b2fSopenharmony_ci            {
1254c5f01b2fSopenharmony_ci                for (std::size_t N :
1255c5f01b2fSopenharmony_ci                        {
1256c5f01b2fSopenharmony_ci                            65536u, 77777u, 1048576u
1257c5f01b2fSopenharmony_ci                        })
1258c5f01b2fSopenharmony_ci                {
1259c5f01b2fSopenharmony_ci                    CAPTURE(N)
1260c5f01b2fSopenharmony_ci
1261c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
1262c5f01b2fSopenharmony_ci                    const auto s = std::vector<uint8_t>(N, 'x');
1263c5f01b2fSopenharmony_ci                    json j = json::binary(s);
1264c5f01b2fSopenharmony_ci                    std::uint8_t subtype = 42;
1265c5f01b2fSopenharmony_ci                    j.get_binary().set_subtype(subtype);
1266c5f01b2fSopenharmony_ci
1267c5f01b2fSopenharmony_ci                    // create expected byte vector (hack: create string first)
1268c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(N, 'x');
1269c5f01b2fSopenharmony_ci                    // reverse order of commands, because we insert at begin()
1270c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), subtype);
1271c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>(N & 0xff));
1272c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 8) & 0xff));
1273c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 16) & 0xff));
1274c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 24) & 0xff));
1275c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 0xC9);
1276c5f01b2fSopenharmony_ci
1277c5f01b2fSopenharmony_ci                    // compare result + size
1278c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
1279c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1280c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 6);
1281c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1282c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1283c5f01b2fSopenharmony_ci
1284c5f01b2fSopenharmony_ci                    // roundtrip
1285c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
1286c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
1287c5f01b2fSopenharmony_ci                }
1288c5f01b2fSopenharmony_ci            }
1289c5f01b2fSopenharmony_ci        }
1290c5f01b2fSopenharmony_ci
1291c5f01b2fSopenharmony_ci        SECTION("binary")
1292c5f01b2fSopenharmony_ci        {
1293c5f01b2fSopenharmony_ci            SECTION("N = 0..255")
1294c5f01b2fSopenharmony_ci            {
1295c5f01b2fSopenharmony_ci                for (std::size_t N = 0; N <= 0xFF; ++N)
1296c5f01b2fSopenharmony_ci                {
1297c5f01b2fSopenharmony_ci                    CAPTURE(N)
1298c5f01b2fSopenharmony_ci
1299c5f01b2fSopenharmony_ci                    // create JSON value with byte array containing of N * 'x'
1300c5f01b2fSopenharmony_ci                    const auto s = std::vector<uint8_t>(N, 'x');
1301c5f01b2fSopenharmony_ci                    json j = json::binary(s);
1302c5f01b2fSopenharmony_ci
1303c5f01b2fSopenharmony_ci                    // create expected byte vector
1304c5f01b2fSopenharmony_ci                    std::vector<std::uint8_t> expected;
1305c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>(0xC4));
1306c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>(N));
1307c5f01b2fSopenharmony_ci                    for (size_t i = 0; i < N; ++i)
1308c5f01b2fSopenharmony_ci                    {
1309c5f01b2fSopenharmony_ci                        expected.push_back(0x78);
1310c5f01b2fSopenharmony_ci                    }
1311c5f01b2fSopenharmony_ci
1312c5f01b2fSopenharmony_ci                    // compare result + size
1313c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
1314c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1315c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 2);
1316c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1317c5f01b2fSopenharmony_ci                    if (N > 0)
1318c5f01b2fSopenharmony_ci                    {
1319c5f01b2fSopenharmony_ci                        CHECK(result.back() != '\x00');
1320c5f01b2fSopenharmony_ci                    }
1321c5f01b2fSopenharmony_ci
1322c5f01b2fSopenharmony_ci                    // roundtrip
1323c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
1324c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
1325c5f01b2fSopenharmony_ci                }
1326c5f01b2fSopenharmony_ci            }
1327c5f01b2fSopenharmony_ci
1328c5f01b2fSopenharmony_ci            SECTION("N = 256..65535")
1329c5f01b2fSopenharmony_ci            {
1330c5f01b2fSopenharmony_ci                for (std::size_t N :
1331c5f01b2fSopenharmony_ci                        {
1332c5f01b2fSopenharmony_ci                            256u, 999u, 1025u, 3333u, 2048u, 65535u
1333c5f01b2fSopenharmony_ci                        })
1334c5f01b2fSopenharmony_ci                {
1335c5f01b2fSopenharmony_ci                    CAPTURE(N)
1336c5f01b2fSopenharmony_ci
1337c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
1338c5f01b2fSopenharmony_ci                    const auto s = std::vector<std::uint8_t>(N, 'x');
1339c5f01b2fSopenharmony_ci                    json j = json::binary(s);
1340c5f01b2fSopenharmony_ci
1341c5f01b2fSopenharmony_ci                    // create expected byte vector (hack: create string first)
1342c5f01b2fSopenharmony_ci                    std::vector<std::uint8_t> expected(N, 'x');
1343c5f01b2fSopenharmony_ci                    // reverse order of commands, because we insert at begin()
1344c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<std::uint8_t>(N & 0xff));
1345c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<std::uint8_t>((N >> 8) & 0xff));
1346c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 0xC5);
1347c5f01b2fSopenharmony_ci
1348c5f01b2fSopenharmony_ci                    // compare result + size
1349c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
1350c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1351c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 3);
1352c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1353c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1354c5f01b2fSopenharmony_ci
1355c5f01b2fSopenharmony_ci                    // roundtrip
1356c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
1357c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
1358c5f01b2fSopenharmony_ci                }
1359c5f01b2fSopenharmony_ci            }
1360c5f01b2fSopenharmony_ci
1361c5f01b2fSopenharmony_ci            SECTION("N = 65536..4294967295")
1362c5f01b2fSopenharmony_ci            {
1363c5f01b2fSopenharmony_ci                for (std::size_t N :
1364c5f01b2fSopenharmony_ci                        {
1365c5f01b2fSopenharmony_ci                            65536u, 77777u, 1048576u
1366c5f01b2fSopenharmony_ci                        })
1367c5f01b2fSopenharmony_ci                {
1368c5f01b2fSopenharmony_ci                    CAPTURE(N)
1369c5f01b2fSopenharmony_ci
1370c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
1371c5f01b2fSopenharmony_ci                    const auto s = std::vector<std::uint8_t>(N, 'x');
1372c5f01b2fSopenharmony_ci                    json j = json::binary(s);
1373c5f01b2fSopenharmony_ci
1374c5f01b2fSopenharmony_ci                    // create expected byte vector (hack: create string first)
1375c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(N, 'x');
1376c5f01b2fSopenharmony_ci                    // reverse order of commands, because we insert at begin()
1377c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<std::uint8_t>(N & 0xff));
1378c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<std::uint8_t>((N >> 8) & 0xff));
1379c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<std::uint8_t>((N >> 16) & 0xff));
1380c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<std::uint8_t>((N >> 24) & 0xff));
1381c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 0xC6);
1382c5f01b2fSopenharmony_ci
1383c5f01b2fSopenharmony_ci                    // compare result + size
1384c5f01b2fSopenharmony_ci                    const auto result = json::to_msgpack(j);
1385c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1386c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 5);
1387c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1388c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1389c5f01b2fSopenharmony_ci
1390c5f01b2fSopenharmony_ci                    // roundtrip
1391c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result) == j);
1392c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(result, true, false) == j);
1393c5f01b2fSopenharmony_ci                }
1394c5f01b2fSopenharmony_ci            }
1395c5f01b2fSopenharmony_ci        }
1396c5f01b2fSopenharmony_ci    }
1397c5f01b2fSopenharmony_ci
1398c5f01b2fSopenharmony_ci    SECTION("from float32")
1399c5f01b2fSopenharmony_ci    {
1400c5f01b2fSopenharmony_ci        auto given = std::vector<uint8_t>({0xca, 0x41, 0xc8, 0x00, 0x01});
1401c5f01b2fSopenharmony_ci        json j = json::from_msgpack(given);
1402c5f01b2fSopenharmony_ci        CHECK(j.get<double>() == Approx(25.0000019073486));
1403c5f01b2fSopenharmony_ci    }
1404c5f01b2fSopenharmony_ci
1405c5f01b2fSopenharmony_ci    SECTION("errors")
1406c5f01b2fSopenharmony_ci    {
1407c5f01b2fSopenharmony_ci        SECTION("empty byte vector")
1408c5f01b2fSopenharmony_ci        {
1409c5f01b2fSopenharmony_ci            json _;
1410c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>()), "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&);
1411c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>(), true, false).is_discarded());
1412c5f01b2fSopenharmony_ci        }
1413c5f01b2fSopenharmony_ci
1414c5f01b2fSopenharmony_ci        SECTION("too short byte vector")
1415c5f01b2fSopenharmony_ci        {
1416c5f01b2fSopenharmony_ci            json _;
1417c5f01b2fSopenharmony_ci
1418c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x87})),
1419c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input", json::parse_error&);
1420c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcc})),
1421c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1422c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcd})),
1423c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1424c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})),
1425c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1426c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce})),
1427c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1428c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00})),
1429c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1430c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00})),
1431c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1432c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00})),
1433c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1434c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf})),
1435c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1436c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00})),
1437c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1438c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00})),
1439c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1440c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00})),
1441c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1442c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00})),
1443c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1444c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})),
1445c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1446c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
1447c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1448c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
1449c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
1450c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65})),
1451c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack string: unexpected end of input", json::parse_error&);
1452c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x92, 0x01})),
1453c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&);
1454c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xa1, 0x61})),
1455c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&);
1456c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xc4, 0x02})),
1457c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack binary: unexpected end of input", json::parse_error&);
1458c5f01b2fSopenharmony_ci
1459c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0x87}), true, false).is_discarded());
1460c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xcc}), true, false).is_discarded());
1461c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xcd}), true, false).is_discarded());
1462c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00}), true, false).is_discarded());
1463c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xce}), true, false).is_discarded());
1464c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00}), true, false).is_discarded());
1465c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00}), true, false).is_discarded());
1466c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00}), true, false).is_discarded());
1467c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf}), true, false).is_discarded());
1468c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00}), true, false).is_discarded());
1469c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00}), true, false).is_discarded());
1470c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00}), true, false).is_discarded());
1471c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
1472c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
1473c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
1474c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
1475c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65}), true, false).is_discarded());
1476c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0x92, 0x01}), true, false).is_discarded());
1477c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0x81, 0xA1, 0x61}), true, false).is_discarded());
1478c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xc4, 0x02}), true, false).is_discarded());
1479c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0xc4}), true, false).is_discarded());
1480c5f01b2fSopenharmony_ci        }
1481c5f01b2fSopenharmony_ci
1482c5f01b2fSopenharmony_ci        SECTION("unsupported bytes")
1483c5f01b2fSopenharmony_ci        {
1484c5f01b2fSopenharmony_ci            SECTION("concrete examples")
1485c5f01b2fSopenharmony_ci            {
1486c5f01b2fSopenharmony_ci                json _;
1487c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xc1})), "[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing MessagePack value: invalid byte: 0xC1", json::parse_error&);
1488c5f01b2fSopenharmony_ci            }
1489c5f01b2fSopenharmony_ci
1490c5f01b2fSopenharmony_ci            SECTION("all unsupported bytes")
1491c5f01b2fSopenharmony_ci            {
1492c5f01b2fSopenharmony_ci                for (auto byte :
1493c5f01b2fSopenharmony_ci                        {
1494c5f01b2fSopenharmony_ci                            // never used
1495c5f01b2fSopenharmony_ci                            0xc1
1496c5f01b2fSopenharmony_ci                        })
1497c5f01b2fSopenharmony_ci                {
1498c5f01b2fSopenharmony_ci                    json _;
1499c5f01b2fSopenharmony_ci                    CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
1500c5f01b2fSopenharmony_ci                    CHECK(json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)}), true, false).is_discarded());
1501c5f01b2fSopenharmony_ci                }
1502c5f01b2fSopenharmony_ci            }
1503c5f01b2fSopenharmony_ci        }
1504c5f01b2fSopenharmony_ci
1505c5f01b2fSopenharmony_ci        SECTION("invalid string in map")
1506c5f01b2fSopenharmony_ci        {
1507c5f01b2fSopenharmony_ci            json _;
1508c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01})), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing MessagePack string: expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0xFF", json::parse_error&);
1509c5f01b2fSopenharmony_ci            CHECK(json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01}), true, false).is_discarded());
1510c5f01b2fSopenharmony_ci        }
1511c5f01b2fSopenharmony_ci
1512c5f01b2fSopenharmony_ci        SECTION("strict mode")
1513c5f01b2fSopenharmony_ci        {
1514c5f01b2fSopenharmony_ci            std::vector<uint8_t> vec = {0xc0, 0xc0};
1515c5f01b2fSopenharmony_ci            SECTION("non-strict mode")
1516c5f01b2fSopenharmony_ci            {
1517c5f01b2fSopenharmony_ci                const auto result = json::from_msgpack(vec, false);
1518c5f01b2fSopenharmony_ci                CHECK(result == json());
1519c5f01b2fSopenharmony_ci            }
1520c5f01b2fSopenharmony_ci
1521c5f01b2fSopenharmony_ci            SECTION("strict mode")
1522c5f01b2fSopenharmony_ci            {
1523c5f01b2fSopenharmony_ci                json _;
1524c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack value: expected end of input; last byte: 0xC0", json::parse_error&);
1525c5f01b2fSopenharmony_ci                CHECK(json::from_msgpack(vec, true, false).is_discarded());
1526c5f01b2fSopenharmony_ci            }
1527c5f01b2fSopenharmony_ci        }
1528c5f01b2fSopenharmony_ci    }
1529c5f01b2fSopenharmony_ci
1530c5f01b2fSopenharmony_ci    SECTION("SAX aborts")
1531c5f01b2fSopenharmony_ci    {
1532c5f01b2fSopenharmony_ci        SECTION("start_array(len)")
1533c5f01b2fSopenharmony_ci        {
1534c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {0x93, 0x01, 0x02, 0x03};
1535c5f01b2fSopenharmony_ci            SaxCountdown scp(0);
1536c5f01b2fSopenharmony_ci            CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
1537c5f01b2fSopenharmony_ci        }
1538c5f01b2fSopenharmony_ci
1539c5f01b2fSopenharmony_ci        SECTION("start_object(len)")
1540c5f01b2fSopenharmony_ci        {
1541c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2};
1542c5f01b2fSopenharmony_ci            SaxCountdown scp(0);
1543c5f01b2fSopenharmony_ci            CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
1544c5f01b2fSopenharmony_ci        }
1545c5f01b2fSopenharmony_ci
1546c5f01b2fSopenharmony_ci        SECTION("key()")
1547c5f01b2fSopenharmony_ci        {
1548c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2};
1549c5f01b2fSopenharmony_ci            SaxCountdown scp(1);
1550c5f01b2fSopenharmony_ci            CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
1551c5f01b2fSopenharmony_ci        }
1552c5f01b2fSopenharmony_ci    }
1553c5f01b2fSopenharmony_ci}
1554c5f01b2fSopenharmony_ci
1555c5f01b2fSopenharmony_ci// use this testcase outside [hide] to run it with Valgrind
1556c5f01b2fSopenharmony_ciTEST_CASE("single MessagePack roundtrip")
1557c5f01b2fSopenharmony_ci{
1558c5f01b2fSopenharmony_ci    SECTION("sample.json")
1559c5f01b2fSopenharmony_ci    {
1560c5f01b2fSopenharmony_ci        std::string filename = TEST_DATA_DIRECTORY "/json_testsuite/sample.json";
1561c5f01b2fSopenharmony_ci
1562c5f01b2fSopenharmony_ci        // parse JSON file
1563c5f01b2fSopenharmony_ci        std::ifstream f_json(filename);
1564c5f01b2fSopenharmony_ci        json j1 = json::parse(f_json);
1565c5f01b2fSopenharmony_ci
1566c5f01b2fSopenharmony_ci        // parse MessagePack file
1567c5f01b2fSopenharmony_ci        auto packed = utils::read_binary_file(filename + ".msgpack");
1568c5f01b2fSopenharmony_ci        json j2;
1569c5f01b2fSopenharmony_ci        CHECK_NOTHROW(j2 = json::from_msgpack(packed));
1570c5f01b2fSopenharmony_ci
1571c5f01b2fSopenharmony_ci        // compare parsed JSON values
1572c5f01b2fSopenharmony_ci        CHECK(j1 == j2);
1573c5f01b2fSopenharmony_ci
1574c5f01b2fSopenharmony_ci        SECTION("roundtrips")
1575c5f01b2fSopenharmony_ci        {
1576c5f01b2fSopenharmony_ci            SECTION("std::ostringstream")
1577c5f01b2fSopenharmony_ci            {
1578c5f01b2fSopenharmony_ci                std::basic_ostringstream<std::uint8_t> ss;
1579c5f01b2fSopenharmony_ci                json::to_msgpack(j1, ss);
1580c5f01b2fSopenharmony_ci                json j3 = json::from_msgpack(ss.str());
1581c5f01b2fSopenharmony_ci                CHECK(j1 == j3);
1582c5f01b2fSopenharmony_ci            }
1583c5f01b2fSopenharmony_ci
1584c5f01b2fSopenharmony_ci            SECTION("std::string")
1585c5f01b2fSopenharmony_ci            {
1586c5f01b2fSopenharmony_ci                std::string s;
1587c5f01b2fSopenharmony_ci                json::to_msgpack(j1, s);
1588c5f01b2fSopenharmony_ci                json j3 = json::from_msgpack(s);
1589c5f01b2fSopenharmony_ci                CHECK(j1 == j3);
1590c5f01b2fSopenharmony_ci            }
1591c5f01b2fSopenharmony_ci        }
1592c5f01b2fSopenharmony_ci
1593c5f01b2fSopenharmony_ci        // check with different start index
1594c5f01b2fSopenharmony_ci        packed.insert(packed.begin(), 5, 0xff);
1595c5f01b2fSopenharmony_ci        CHECK(j1 == json::from_msgpack(packed.begin() + 5, packed.end()));
1596c5f01b2fSopenharmony_ci    }
1597c5f01b2fSopenharmony_ci}
1598c5f01b2fSopenharmony_ci
1599c5f01b2fSopenharmony_ciTEST_CASE("MessagePack roundtrips" * doctest::skip())
1600c5f01b2fSopenharmony_ci{
1601c5f01b2fSopenharmony_ci    SECTION("input from msgpack-python")
1602c5f01b2fSopenharmony_ci    {
1603c5f01b2fSopenharmony_ci        // most of these are excluded due to differences in key order (not a real problem)
1604c5f01b2fSopenharmony_ci        std::set<std::string> exclude_packed;
1605c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/1.json");
1606c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/2.json");
1607c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/3.json");
1608c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/4.json");
1609c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/5.json");
1610c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/json_testsuite/sample.json"); // kills AppVeyor
1611c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/json_tests/pass1.json");
1612c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/regression/working_file.json");
1613c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json");
1614c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json");
1615c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json");
1616c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json");
1617c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json");
1618c5f01b2fSopenharmony_ci        exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json");
1619c5f01b2fSopenharmony_ci
1620c5f01b2fSopenharmony_ci        for (std::string filename :
1621c5f01b2fSopenharmony_ci                {
1622c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json",
1623c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json.org/1.json",
1624c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json.org/2.json",
1625c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json.org/3.json",
1626c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json.org/4.json",
1627c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json.org/5.json",
1628c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json",
1629c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json",
1630c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json",
1631c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json",
1632c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json",
1633c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json",
1634c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json",
1635c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json",
1636c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json",
1637c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json",
1638c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json",
1639c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json",
1640c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json",
1641c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json",
1642c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json",
1643c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json",
1644c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json",
1645c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json",
1646c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json",
1647c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json",
1648c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json",
1649c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json",
1650c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json",
1651c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json",
1652c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json",
1653c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json",
1654c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json",
1655c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json",
1656c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json",
1657c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json",
1658c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json",
1659c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json",
1660c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor
1661c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_tests/pass1.json",
1662c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_tests/pass2.json",
1663c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_tests/pass3.json",
1664c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/regression/floats.json",
1665c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/regression/signed_ints.json",
1666c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/regression/unsigned_ints.json",
1667c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/regression/working_file.json",
1668c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json",
1669c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json",
1670c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json",
1671c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json",
1672c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json",
1673c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json",
1674c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json",
1675c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json",
1676c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json",
1677c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json",
1678c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json",
1679c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json",
1680c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json",
1681c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json",
1682c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json",
1683c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json",
1684c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json",
1685c5f01b2fSopenharmony_ci                    //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json",
1686c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json",
1687c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json",
1688c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json",
1689c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json",
1690c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json",
1691c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json",
1692c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json",
1693c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json",
1694c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json",
1695c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json",
1696c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json",
1697c5f01b2fSopenharmony_ci                    //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json",
1698c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json",
1699c5f01b2fSopenharmony_ci                    //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json",
1700c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json",
1701c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json",
1702c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json",
1703c5f01b2fSopenharmony_ci                    //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json",
1704c5f01b2fSopenharmony_ci                    //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json",
1705c5f01b2fSopenharmony_ci                    //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json",
1706c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json",
1707c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json",
1708c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
1709c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json",
1710c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json",
1711c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json",
1712c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json",
1713c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json",
1714c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json",
1715c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json",
1716c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json",
1717c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json",
1718c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json",
1719c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json",
1720c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json",
1721c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json",
1722c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json",
1723c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json",
1724c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json",
1725c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json",
1726c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json",
1727c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json",
1728c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json",
1729c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json",
1730c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json",
1731c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json",
1732c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json",
1733c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json",
1734c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json",
1735c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json",
1736c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json",
1737c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json",
1738c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json",
1739c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json",
1740c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json",
1741c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json",
1742c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json",
1743c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json",
1744c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json",
1745c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json",
1746c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json",
1747c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json",
1748c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json",
1749c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json",
1750c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json",
1751c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json",
1752c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json",
1753c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json",
1754c5f01b2fSopenharmony_ci                    // TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json",
1755c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json",
1756c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json",
1757c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json",
1758c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json",
1759c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json",
1760c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json",
1761c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json",
1762c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json",
1763c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json",
1764c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json",
1765c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json",
1766c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"
1767c5f01b2fSopenharmony_ci                })
1768c5f01b2fSopenharmony_ci        {
1769c5f01b2fSopenharmony_ci            CAPTURE(filename)
1770c5f01b2fSopenharmony_ci
1771c5f01b2fSopenharmony_ci            {
1772c5f01b2fSopenharmony_ci                INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
1773c5f01b2fSopenharmony_ci                // parse JSON file
1774c5f01b2fSopenharmony_ci                std::ifstream f_json(filename);
1775c5f01b2fSopenharmony_ci                json j1 = json::parse(f_json);
1776c5f01b2fSopenharmony_ci
1777c5f01b2fSopenharmony_ci                // parse MessagePack file
1778c5f01b2fSopenharmony_ci                auto packed = utils::read_binary_file(filename + ".msgpack");
1779c5f01b2fSopenharmony_ci                json j2;
1780c5f01b2fSopenharmony_ci                CHECK_NOTHROW(j2 = json::from_msgpack(packed));
1781c5f01b2fSopenharmony_ci
1782c5f01b2fSopenharmony_ci                // compare parsed JSON values
1783c5f01b2fSopenharmony_ci                CHECK(j1 == j2);
1784c5f01b2fSopenharmony_ci            }
1785c5f01b2fSopenharmony_ci
1786c5f01b2fSopenharmony_ci            {
1787c5f01b2fSopenharmony_ci                INFO_WITH_TEMP(filename + ": std::ifstream");
1788c5f01b2fSopenharmony_ci                // parse JSON file
1789c5f01b2fSopenharmony_ci                std::ifstream f_json(filename);
1790c5f01b2fSopenharmony_ci                json j1 = json::parse(f_json);
1791c5f01b2fSopenharmony_ci
1792c5f01b2fSopenharmony_ci                // parse MessagePack file
1793c5f01b2fSopenharmony_ci                std::ifstream f_msgpack(filename + ".msgpack", std::ios::binary);
1794c5f01b2fSopenharmony_ci                json j2;
1795c5f01b2fSopenharmony_ci                CHECK_NOTHROW(j2 = json::from_msgpack(f_msgpack));
1796c5f01b2fSopenharmony_ci
1797c5f01b2fSopenharmony_ci                // compare parsed JSON values
1798c5f01b2fSopenharmony_ci                CHECK(j1 == j2);
1799c5f01b2fSopenharmony_ci            }
1800c5f01b2fSopenharmony_ci
1801c5f01b2fSopenharmony_ci            {
1802c5f01b2fSopenharmony_ci                INFO_WITH_TEMP(filename + ": uint8_t* and size");
1803c5f01b2fSopenharmony_ci                // parse JSON file
1804c5f01b2fSopenharmony_ci                std::ifstream f_json(filename);
1805c5f01b2fSopenharmony_ci                json j1 = json::parse(f_json);
1806c5f01b2fSopenharmony_ci
1807c5f01b2fSopenharmony_ci                // parse MessagePack file
1808c5f01b2fSopenharmony_ci                auto packed = utils::read_binary_file(filename + ".msgpack");
1809c5f01b2fSopenharmony_ci                json j2;
1810c5f01b2fSopenharmony_ci                CHECK_NOTHROW(j2 = json::from_msgpack({packed.data(), packed.size()}));
1811c5f01b2fSopenharmony_ci
1812c5f01b2fSopenharmony_ci                // compare parsed JSON values
1813c5f01b2fSopenharmony_ci                CHECK(j1 == j2);
1814c5f01b2fSopenharmony_ci            }
1815c5f01b2fSopenharmony_ci
1816c5f01b2fSopenharmony_ci            {
1817c5f01b2fSopenharmony_ci                INFO_WITH_TEMP(filename + ": output to output adapters");
1818c5f01b2fSopenharmony_ci                // parse JSON file
1819c5f01b2fSopenharmony_ci                std::ifstream f_json(filename);
1820c5f01b2fSopenharmony_ci                json j1 = json::parse(f_json);
1821c5f01b2fSopenharmony_ci
1822c5f01b2fSopenharmony_ci                // parse MessagePack file
1823c5f01b2fSopenharmony_ci                auto packed = utils::read_binary_file(filename + ".msgpack");
1824c5f01b2fSopenharmony_ci
1825c5f01b2fSopenharmony_ci                if (exclude_packed.count(filename) == 0u)
1826c5f01b2fSopenharmony_ci                {
1827c5f01b2fSopenharmony_ci                    {
1828c5f01b2fSopenharmony_ci                        INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
1829c5f01b2fSopenharmony_ci                        std::vector<uint8_t> vec;
1830c5f01b2fSopenharmony_ci                        json::to_msgpack(j1, vec);
1831c5f01b2fSopenharmony_ci                        CHECK(vec == packed);
1832c5f01b2fSopenharmony_ci                    }
1833c5f01b2fSopenharmony_ci                }
1834c5f01b2fSopenharmony_ci            }
1835c5f01b2fSopenharmony_ci        }
1836c5f01b2fSopenharmony_ci    }
1837c5f01b2fSopenharmony_ci}
1838