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#define JSON_TESTS_PRIVATE
12c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp>
13c5f01b2fSopenharmony_ciusing nlohmann::json;
14c5f01b2fSopenharmony_ci
15c5f01b2fSopenharmony_ci#include <algorithm>
16c5f01b2fSopenharmony_ci#include <climits>
17c5f01b2fSopenharmony_ci#include <limits>
18c5f01b2fSopenharmony_ci#include <iostream>
19c5f01b2fSopenharmony_ci#include <fstream>
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_ci// at some point in the future, a unit test dedicated to type traits might be a good idea
103c5f01b2fSopenharmony_citemplate <typename OfType, typename T, bool MinInRange, bool MaxInRange>
104c5f01b2fSopenharmony_cistruct trait_test_arg
105c5f01b2fSopenharmony_ci{
106c5f01b2fSopenharmony_ci    using of_type = OfType;
107c5f01b2fSopenharmony_ci    using type = T;
108c5f01b2fSopenharmony_ci    static constexpr bool min_in_range = MinInRange;
109c5f01b2fSopenharmony_ci    static constexpr bool max_in_range = MaxInRange;
110c5f01b2fSopenharmony_ci};
111c5f01b2fSopenharmony_ci
112c5f01b2fSopenharmony_ciTEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test)
113c5f01b2fSopenharmony_ci{
114c5f01b2fSopenharmony_ci    using nlohmann::detail::value_in_range_of;
115c5f01b2fSopenharmony_ci
116c5f01b2fSopenharmony_ci    using of_type = typename T::of_type;
117c5f01b2fSopenharmony_ci    using type = typename T::type;
118c5f01b2fSopenharmony_ci    constexpr bool min_in_range = T::min_in_range;
119c5f01b2fSopenharmony_ci    constexpr bool max_in_range = T::max_in_range;
120c5f01b2fSopenharmony_ci
121c5f01b2fSopenharmony_ci    type val_min = std::numeric_limits<type>::min();
122c5f01b2fSopenharmony_ci    type val_min2 = val_min + 1;
123c5f01b2fSopenharmony_ci    type val_max = std::numeric_limits<type>::max();
124c5f01b2fSopenharmony_ci    type val_max2 = val_max - 1;
125c5f01b2fSopenharmony_ci
126c5f01b2fSopenharmony_ci    REQUIRE(CHAR_BIT == 8);
127c5f01b2fSopenharmony_ci
128c5f01b2fSopenharmony_ci    std::string of_type_str;
129c5f01b2fSopenharmony_ci    if (std::is_unsigned<of_type>::value)
130c5f01b2fSopenharmony_ci    {
131c5f01b2fSopenharmony_ci        of_type_str += "u";
132c5f01b2fSopenharmony_ci    }
133c5f01b2fSopenharmony_ci    of_type_str += "int";
134c5f01b2fSopenharmony_ci    of_type_str += std::to_string(sizeof(of_type) * 8);
135c5f01b2fSopenharmony_ci
136c5f01b2fSopenharmony_ci    INFO("of_type := ", of_type_str);
137c5f01b2fSopenharmony_ci
138c5f01b2fSopenharmony_ci    std::string type_str;
139c5f01b2fSopenharmony_ci    if (std::is_unsigned<type>::value)
140c5f01b2fSopenharmony_ci    {
141c5f01b2fSopenharmony_ci        type_str += "u";
142c5f01b2fSopenharmony_ci    }
143c5f01b2fSopenharmony_ci    type_str += "int";
144c5f01b2fSopenharmony_ci    type_str += std::to_string(sizeof(type) * 8);
145c5f01b2fSopenharmony_ci
146c5f01b2fSopenharmony_ci    INFO("type := ", type_str);
147c5f01b2fSopenharmony_ci
148c5f01b2fSopenharmony_ci    CAPTURE(val_min);
149c5f01b2fSopenharmony_ci    CAPTURE(min_in_range);
150c5f01b2fSopenharmony_ci    CAPTURE(val_max);
151c5f01b2fSopenharmony_ci    CAPTURE(max_in_range);
152c5f01b2fSopenharmony_ci
153c5f01b2fSopenharmony_ci    if (min_in_range)
154c5f01b2fSopenharmony_ci    {
155c5f01b2fSopenharmony_ci        CHECK(value_in_range_of<of_type>(val_min));
156c5f01b2fSopenharmony_ci        CHECK(value_in_range_of<of_type>(val_min2));
157c5f01b2fSopenharmony_ci    }
158c5f01b2fSopenharmony_ci    else
159c5f01b2fSopenharmony_ci    {
160c5f01b2fSopenharmony_ci        CHECK_FALSE(value_in_range_of<of_type>(val_min));
161c5f01b2fSopenharmony_ci        CHECK_FALSE(value_in_range_of<of_type>(val_min2));
162c5f01b2fSopenharmony_ci    }
163c5f01b2fSopenharmony_ci
164c5f01b2fSopenharmony_ci    if (max_in_range)
165c5f01b2fSopenharmony_ci    {
166c5f01b2fSopenharmony_ci        CHECK(value_in_range_of<of_type>(val_max));
167c5f01b2fSopenharmony_ci        CHECK(value_in_range_of<of_type>(val_max2));
168c5f01b2fSopenharmony_ci    }
169c5f01b2fSopenharmony_ci    else
170c5f01b2fSopenharmony_ci    {
171c5f01b2fSopenharmony_ci        CHECK_FALSE(value_in_range_of<of_type>(val_max));
172c5f01b2fSopenharmony_ci        CHECK_FALSE(value_in_range_of<of_type>(val_max2));
173c5f01b2fSopenharmony_ci    }
174c5f01b2fSopenharmony_ci}
175c5f01b2fSopenharmony_ci
176c5f01b2fSopenharmony_ciTEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, \
177c5f01b2fSopenharmony_ci                          trait_test_arg<std::int32_t, std::int32_t, true, true>, \
178c5f01b2fSopenharmony_ci                          trait_test_arg<std::int32_t, std::uint32_t, true, false>, \
179c5f01b2fSopenharmony_ci                          trait_test_arg<std::uint32_t, std::int32_t, false, true>, \
180c5f01b2fSopenharmony_ci                          trait_test_arg<std::uint32_t, std::uint32_t, true, true>, \
181c5f01b2fSopenharmony_ci                          trait_test_arg<std::int32_t, std::int64_t, false, false>, \
182c5f01b2fSopenharmony_ci                          trait_test_arg<std::int32_t, std::uint64_t, true, false>, \
183c5f01b2fSopenharmony_ci                          trait_test_arg<std::uint32_t, std::int64_t, false, false>, \
184c5f01b2fSopenharmony_ci                          trait_test_arg<std::uint32_t, std::uint64_t, true, false>, \
185c5f01b2fSopenharmony_ci                          trait_test_arg<std::int64_t, std::int32_t, true, true>, \
186c5f01b2fSopenharmony_ci                          trait_test_arg<std::int64_t, std::uint32_t, true, true>, \
187c5f01b2fSopenharmony_ci                          trait_test_arg<std::uint64_t, std::int32_t, false, true>, \
188c5f01b2fSopenharmony_ci                          trait_test_arg<std::uint64_t, std::uint32_t, true, true>, \
189c5f01b2fSopenharmony_ci                          trait_test_arg<std::int64_t, std::int64_t, true, true>, \
190c5f01b2fSopenharmony_ci                          trait_test_arg<std::int64_t, std::uint64_t, true, false>, \
191c5f01b2fSopenharmony_ci                          trait_test_arg<std::uint64_t, std::int64_t, false, true>, \
192c5f01b2fSopenharmony_ci                          trait_test_arg<std::uint64_t, std::uint64_t, true, true>);
193c5f01b2fSopenharmony_ci
194c5f01b2fSopenharmony_ci#if SIZE_MAX == 0xffffffff
195c5f01b2fSopenharmony_ciTEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, \
196c5f01b2fSopenharmony_ci                          trait_test_arg<std::size_t, std::int32_t, false, true>, \
197c5f01b2fSopenharmony_ci                          trait_test_arg<std::size_t, std::uint32_t, true, true>, \
198c5f01b2fSopenharmony_ci                          trait_test_arg<std::size_t, std::int64_t, false, false>, \
199c5f01b2fSopenharmony_ci                          trait_test_arg<std::size_t, std::uint64_t, true, false>);
200c5f01b2fSopenharmony_ci#else
201c5f01b2fSopenharmony_ciTEST_CASE_TEMPLATE_INVOKE(value_in_range_of_test, \
202c5f01b2fSopenharmony_ci                          trait_test_arg<std::size_t, std::int32_t, false, true>, \
203c5f01b2fSopenharmony_ci                          trait_test_arg<std::size_t, std::uint32_t, true, true>, \
204c5f01b2fSopenharmony_ci                          trait_test_arg<std::size_t, std::int64_t, false, true>, \
205c5f01b2fSopenharmony_ci                          trait_test_arg<std::size_t, std::uint64_t, true, true>);
206c5f01b2fSopenharmony_ci#endif
207c5f01b2fSopenharmony_ci
208c5f01b2fSopenharmony_ciTEST_CASE("BJData")
209c5f01b2fSopenharmony_ci{
210c5f01b2fSopenharmony_ci    SECTION("binary_reader BJData LUT arrays are sorted")
211c5f01b2fSopenharmony_ci    {
212c5f01b2fSopenharmony_ci        std::vector<std::uint8_t> data;
213c5f01b2fSopenharmony_ci        auto ia = nlohmann::detail::input_adapter(data);
214c5f01b2fSopenharmony_ci        // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
215c5f01b2fSopenharmony_ci        nlohmann::detail::binary_reader<json, decltype(ia)> br{std::move(ia), json::input_format_t::bjdata};
216c5f01b2fSopenharmony_ci
217c5f01b2fSopenharmony_ci        CHECK(std::is_sorted(br.bjd_optimized_type_markers.begin(), br.bjd_optimized_type_markers.end()));
218c5f01b2fSopenharmony_ci        CHECK(std::is_sorted(br.bjd_types_map.begin(), br.bjd_types_map.end()));
219c5f01b2fSopenharmony_ci    }
220c5f01b2fSopenharmony_ci
221c5f01b2fSopenharmony_ci    SECTION("individual values")
222c5f01b2fSopenharmony_ci    {
223c5f01b2fSopenharmony_ci        SECTION("discarded")
224c5f01b2fSopenharmony_ci        {
225c5f01b2fSopenharmony_ci            // discarded values are not serialized
226c5f01b2fSopenharmony_ci            json j = json::value_t::discarded;
227c5f01b2fSopenharmony_ci            const auto result = json::to_bjdata(j);
228c5f01b2fSopenharmony_ci            CHECK(result.empty());
229c5f01b2fSopenharmony_ci        }
230c5f01b2fSopenharmony_ci
231c5f01b2fSopenharmony_ci        SECTION("null")
232c5f01b2fSopenharmony_ci        {
233c5f01b2fSopenharmony_ci            json j = nullptr;
234c5f01b2fSopenharmony_ci            std::vector<uint8_t> expected = {'Z'};
235c5f01b2fSopenharmony_ci            const auto result = json::to_bjdata(j);
236c5f01b2fSopenharmony_ci            CHECK(result == expected);
237c5f01b2fSopenharmony_ci
238c5f01b2fSopenharmony_ci            // roundtrip
239c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(result) == j);
240c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(result, true, false) == j);
241c5f01b2fSopenharmony_ci        }
242c5f01b2fSopenharmony_ci
243c5f01b2fSopenharmony_ci        SECTION("boolean")
244c5f01b2fSopenharmony_ci        {
245c5f01b2fSopenharmony_ci            SECTION("true")
246c5f01b2fSopenharmony_ci            {
247c5f01b2fSopenharmony_ci                json j = true;
248c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'T'};
249c5f01b2fSopenharmony_ci                const auto result = json::to_bjdata(j);
250c5f01b2fSopenharmony_ci                CHECK(result == expected);
251c5f01b2fSopenharmony_ci
252c5f01b2fSopenharmony_ci                // roundtrip
253c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(result) == j);
254c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(result, true, false) == j);
255c5f01b2fSopenharmony_ci            }
256c5f01b2fSopenharmony_ci
257c5f01b2fSopenharmony_ci            SECTION("false")
258c5f01b2fSopenharmony_ci            {
259c5f01b2fSopenharmony_ci                json j = false;
260c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'F'};
261c5f01b2fSopenharmony_ci                const auto result = json::to_bjdata(j);
262c5f01b2fSopenharmony_ci                CHECK(result == expected);
263c5f01b2fSopenharmony_ci
264c5f01b2fSopenharmony_ci                // roundtrip
265c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(result) == j);
266c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(result, true, false) == j);
267c5f01b2fSopenharmony_ci            }
268c5f01b2fSopenharmony_ci        }
269c5f01b2fSopenharmony_ci
270c5f01b2fSopenharmony_ci        SECTION("number")
271c5f01b2fSopenharmony_ci        {
272c5f01b2fSopenharmony_ci            SECTION("signed")
273c5f01b2fSopenharmony_ci            {
274c5f01b2fSopenharmony_ci                SECTION("-9223372036854775808..-2147483649 (int64)")
275c5f01b2fSopenharmony_ci                {
276c5f01b2fSopenharmony_ci                    std::vector<int64_t> numbers;
277c5f01b2fSopenharmony_ci                    numbers.push_back((std::numeric_limits<int64_t>::min)());
278c5f01b2fSopenharmony_ci                    numbers.push_back(-1000000000000000000LL);
279c5f01b2fSopenharmony_ci                    numbers.push_back(-100000000000000000LL);
280c5f01b2fSopenharmony_ci                    numbers.push_back(-10000000000000000LL);
281c5f01b2fSopenharmony_ci                    numbers.push_back(-1000000000000000LL);
282c5f01b2fSopenharmony_ci                    numbers.push_back(-100000000000000LL);
283c5f01b2fSopenharmony_ci                    numbers.push_back(-10000000000000LL);
284c5f01b2fSopenharmony_ci                    numbers.push_back(-1000000000000LL);
285c5f01b2fSopenharmony_ci                    numbers.push_back(-100000000000LL);
286c5f01b2fSopenharmony_ci                    numbers.push_back(-10000000000LL);
287c5f01b2fSopenharmony_ci                    numbers.push_back(-2147483649LL);
288c5f01b2fSopenharmony_ci                    for (auto i : numbers)
289c5f01b2fSopenharmony_ci                    {
290c5f01b2fSopenharmony_ci                        CAPTURE(i)
291c5f01b2fSopenharmony_ci
292c5f01b2fSopenharmony_ci                        // create JSON value with integer number
293c5f01b2fSopenharmony_ci                        json j = i;
294c5f01b2fSopenharmony_ci
295c5f01b2fSopenharmony_ci                        // check type
296c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
297c5f01b2fSopenharmony_ci
298c5f01b2fSopenharmony_ci                        // create expected byte vector
299c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
300c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>('L'));
301c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
302c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
303c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
304c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
305c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 32) & 0xff));
306c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 40) & 0xff));
307c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 48) & 0xff));
308c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 56) & 0xff));
309c5f01b2fSopenharmony_ci
310c5f01b2fSopenharmony_ci                        // compare result + size
311c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
312c5f01b2fSopenharmony_ci                        CHECK(result == expected);
313c5f01b2fSopenharmony_ci                        CHECK(result.size() == 9);
314c5f01b2fSopenharmony_ci
315c5f01b2fSopenharmony_ci                        // check individual bytes
316c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'L');
317c5f01b2fSopenharmony_ci                        int64_t restored = (static_cast<int64_t>(result[8]) << 070) +
318c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[7]) << 060) +
319c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[6]) << 050) +
320c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[5]) << 040) +
321c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[4]) << 030) +
322c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[3]) << 020) +
323c5f01b2fSopenharmony_ci                                           (static_cast<int64_t>(result[2]) << 010) +
324c5f01b2fSopenharmony_ci                                           static_cast<int64_t>(result[1]);
325c5f01b2fSopenharmony_ci                        CHECK(restored == i);
326c5f01b2fSopenharmony_ci
327c5f01b2fSopenharmony_ci                        // roundtrip
328c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
329c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
330c5f01b2fSopenharmony_ci                    }
331c5f01b2fSopenharmony_ci                }
332c5f01b2fSopenharmony_ci
333c5f01b2fSopenharmony_ci                SECTION("-2147483648..-32769 (int32)")
334c5f01b2fSopenharmony_ci                {
335c5f01b2fSopenharmony_ci                    std::vector<int32_t> numbers;
336c5f01b2fSopenharmony_ci                    numbers.push_back(-32769);
337c5f01b2fSopenharmony_ci                    numbers.push_back(-100000);
338c5f01b2fSopenharmony_ci                    numbers.push_back(-1000000);
339c5f01b2fSopenharmony_ci                    numbers.push_back(-10000000);
340c5f01b2fSopenharmony_ci                    numbers.push_back(-100000000);
341c5f01b2fSopenharmony_ci                    numbers.push_back(-1000000000);
342c5f01b2fSopenharmony_ci                    numbers.push_back(-2147483647 - 1); // https://stackoverflow.com/a/29356002/266378
343c5f01b2fSopenharmony_ci                    for (auto i : numbers)
344c5f01b2fSopenharmony_ci                    {
345c5f01b2fSopenharmony_ci                        CAPTURE(i)
346c5f01b2fSopenharmony_ci
347c5f01b2fSopenharmony_ci                        // create JSON value with integer number
348c5f01b2fSopenharmony_ci                        json j = i;
349c5f01b2fSopenharmony_ci
350c5f01b2fSopenharmony_ci                        // check type
351c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
352c5f01b2fSopenharmony_ci
353c5f01b2fSopenharmony_ci                        // create expected byte vector
354c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
355c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>('l'));
356c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
357c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
358c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
359c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
360c5f01b2fSopenharmony_ci
361c5f01b2fSopenharmony_ci                        // compare result + size
362c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
363c5f01b2fSopenharmony_ci                        CHECK(result == expected);
364c5f01b2fSopenharmony_ci                        CHECK(result.size() == 5);
365c5f01b2fSopenharmony_ci
366c5f01b2fSopenharmony_ci                        // check individual bytes
367c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'l');
368c5f01b2fSopenharmony_ci                        int32_t restored = (static_cast<int32_t>(result[4]) << 030) +
369c5f01b2fSopenharmony_ci                                           (static_cast<int32_t>(result[3]) << 020) +
370c5f01b2fSopenharmony_ci                                           (static_cast<int32_t>(result[2]) << 010) +
371c5f01b2fSopenharmony_ci                                           static_cast<int32_t>(result[1]);
372c5f01b2fSopenharmony_ci                        CHECK(restored == i);
373c5f01b2fSopenharmony_ci
374c5f01b2fSopenharmony_ci                        // roundtrip
375c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
376c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
377c5f01b2fSopenharmony_ci                    }
378c5f01b2fSopenharmony_ci                }
379c5f01b2fSopenharmony_ci
380c5f01b2fSopenharmony_ci                SECTION("-32768..-129 (int16)")
381c5f01b2fSopenharmony_ci                {
382c5f01b2fSopenharmony_ci                    for (int32_t i = -32768; i <= -129; ++i)
383c5f01b2fSopenharmony_ci                    {
384c5f01b2fSopenharmony_ci                        CAPTURE(i)
385c5f01b2fSopenharmony_ci
386c5f01b2fSopenharmony_ci                        // create JSON value with integer number
387c5f01b2fSopenharmony_ci                        json j = i;
388c5f01b2fSopenharmony_ci
389c5f01b2fSopenharmony_ci                        // check type
390c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
391c5f01b2fSopenharmony_ci
392c5f01b2fSopenharmony_ci                        // create expected byte vector
393c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
394c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>('I'));
395c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
396c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
397c5f01b2fSopenharmony_ci
398c5f01b2fSopenharmony_ci                        // compare result + size
399c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
400c5f01b2fSopenharmony_ci                        CHECK(result == expected);
401c5f01b2fSopenharmony_ci                        CHECK(result.size() == 3);
402c5f01b2fSopenharmony_ci
403c5f01b2fSopenharmony_ci                        // check individual bytes
404c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'I');
405c5f01b2fSopenharmony_ci                        auto restored = static_cast<int16_t>(((result[2] << 8) + result[1]));
406c5f01b2fSopenharmony_ci                        CHECK(restored == i);
407c5f01b2fSopenharmony_ci
408c5f01b2fSopenharmony_ci                        // roundtrip
409c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
410c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
411c5f01b2fSopenharmony_ci                    }
412c5f01b2fSopenharmony_ci                }
413c5f01b2fSopenharmony_ci
414c5f01b2fSopenharmony_ci                SECTION("-9263 (int16)")
415c5f01b2fSopenharmony_ci                {
416c5f01b2fSopenharmony_ci                    json j = -9263;
417c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'I', 0xd1, 0xdb};
418c5f01b2fSopenharmony_ci
419c5f01b2fSopenharmony_ci                    // compare result + size
420c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
421c5f01b2fSopenharmony_ci                    CHECK(result == expected);
422c5f01b2fSopenharmony_ci                    CHECK(result.size() == 3);
423c5f01b2fSopenharmony_ci
424c5f01b2fSopenharmony_ci                    // check individual bytes
425c5f01b2fSopenharmony_ci                    CHECK(result[0] == 'I');
426c5f01b2fSopenharmony_ci                    auto restored = static_cast<int16_t>(((result[2] << 8) + result[1]));
427c5f01b2fSopenharmony_ci                    CHECK(restored == -9263);
428c5f01b2fSopenharmony_ci
429c5f01b2fSopenharmony_ci                    // roundtrip
430c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
431c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
432c5f01b2fSopenharmony_ci                }
433c5f01b2fSopenharmony_ci
434c5f01b2fSopenharmony_ci                SECTION("-128..-1 (int8)")
435c5f01b2fSopenharmony_ci                {
436c5f01b2fSopenharmony_ci                    for (auto i = -128; i <= -1; ++i)
437c5f01b2fSopenharmony_ci                    {
438c5f01b2fSopenharmony_ci                        CAPTURE(i)
439c5f01b2fSopenharmony_ci
440c5f01b2fSopenharmony_ci                        // create JSON value with integer number
441c5f01b2fSopenharmony_ci                        json j = i;
442c5f01b2fSopenharmony_ci
443c5f01b2fSopenharmony_ci                        // check type
444c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
445c5f01b2fSopenharmony_ci
446c5f01b2fSopenharmony_ci                        // create expected byte vector
447c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
448c5f01b2fSopenharmony_ci                        expected.push_back('i');
449c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i));
450c5f01b2fSopenharmony_ci
451c5f01b2fSopenharmony_ci                        // compare result + size
452c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
453c5f01b2fSopenharmony_ci                        CHECK(result == expected);
454c5f01b2fSopenharmony_ci                        CHECK(result.size() == 2);
455c5f01b2fSopenharmony_ci
456c5f01b2fSopenharmony_ci                        // check individual bytes
457c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'i');
458c5f01b2fSopenharmony_ci                        CHECK(static_cast<int8_t>(result[1]) == i);
459c5f01b2fSopenharmony_ci
460c5f01b2fSopenharmony_ci                        // roundtrip
461c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
462c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
463c5f01b2fSopenharmony_ci                    }
464c5f01b2fSopenharmony_ci                }
465c5f01b2fSopenharmony_ci
466c5f01b2fSopenharmony_ci                SECTION("0..127 (int8)")
467c5f01b2fSopenharmony_ci                {
468c5f01b2fSopenharmony_ci                    for (size_t i = 0; i <= 127; ++i)
469c5f01b2fSopenharmony_ci                    {
470c5f01b2fSopenharmony_ci                        CAPTURE(i)
471c5f01b2fSopenharmony_ci
472c5f01b2fSopenharmony_ci                        // create JSON value with integer number
473c5f01b2fSopenharmony_ci                        json j = -1;
474c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
475c5f01b2fSopenharmony_ci
476c5f01b2fSopenharmony_ci                        // check type
477c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
478c5f01b2fSopenharmony_ci
479c5f01b2fSopenharmony_ci                        // create expected byte vector
480c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
481c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>('i'));
482c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i));
483c5f01b2fSopenharmony_ci
484c5f01b2fSopenharmony_ci                        // compare result + size
485c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
486c5f01b2fSopenharmony_ci                        CHECK(result == expected);
487c5f01b2fSopenharmony_ci                        CHECK(result.size() == 2);
488c5f01b2fSopenharmony_ci
489c5f01b2fSopenharmony_ci                        // check individual bytes
490c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'i');
491c5f01b2fSopenharmony_ci                        CHECK(result[1] == i);
492c5f01b2fSopenharmony_ci
493c5f01b2fSopenharmony_ci                        // roundtrip
494c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
495c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
496c5f01b2fSopenharmony_ci                    }
497c5f01b2fSopenharmony_ci                }
498c5f01b2fSopenharmony_ci
499c5f01b2fSopenharmony_ci                SECTION("128..255 (uint8)")
500c5f01b2fSopenharmony_ci                {
501c5f01b2fSopenharmony_ci                    for (size_t i = 128; i <= 255; ++i)
502c5f01b2fSopenharmony_ci                    {
503c5f01b2fSopenharmony_ci                        CAPTURE(i)
504c5f01b2fSopenharmony_ci
505c5f01b2fSopenharmony_ci                        // create JSON value with integer number
506c5f01b2fSopenharmony_ci                        json j = -1;
507c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
508c5f01b2fSopenharmony_ci
509c5f01b2fSopenharmony_ci                        // check type
510c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
511c5f01b2fSopenharmony_ci
512c5f01b2fSopenharmony_ci                        // create expected byte vector
513c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
514c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>('U'));
515c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i));
516c5f01b2fSopenharmony_ci
517c5f01b2fSopenharmony_ci                        // compare result + size
518c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
519c5f01b2fSopenharmony_ci                        CHECK(result == expected);
520c5f01b2fSopenharmony_ci                        CHECK(result.size() == 2);
521c5f01b2fSopenharmony_ci
522c5f01b2fSopenharmony_ci                        // check individual bytes
523c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'U');
524c5f01b2fSopenharmony_ci                        CHECK(result[1] == i);
525c5f01b2fSopenharmony_ci
526c5f01b2fSopenharmony_ci                        // roundtrip
527c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
528c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
529c5f01b2fSopenharmony_ci                    }
530c5f01b2fSopenharmony_ci                }
531c5f01b2fSopenharmony_ci
532c5f01b2fSopenharmony_ci                SECTION("256..32767 (int16)")
533c5f01b2fSopenharmony_ci                {
534c5f01b2fSopenharmony_ci                    for (size_t i = 256; i <= 32767; ++i)
535c5f01b2fSopenharmony_ci                    {
536c5f01b2fSopenharmony_ci                        CAPTURE(i)
537c5f01b2fSopenharmony_ci
538c5f01b2fSopenharmony_ci                        // create JSON value with integer number
539c5f01b2fSopenharmony_ci                        json j = -1;
540c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
541c5f01b2fSopenharmony_ci
542c5f01b2fSopenharmony_ci                        // check type
543c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
544c5f01b2fSopenharmony_ci
545c5f01b2fSopenharmony_ci                        // create expected byte vector
546c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
547c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>('I'));
548c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
549c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
550c5f01b2fSopenharmony_ci
551c5f01b2fSopenharmony_ci                        // compare result + size
552c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
553c5f01b2fSopenharmony_ci                        CHECK(result == expected);
554c5f01b2fSopenharmony_ci                        CHECK(result.size() == 3);
555c5f01b2fSopenharmony_ci
556c5f01b2fSopenharmony_ci                        // check individual bytes
557c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'I');
558c5f01b2fSopenharmony_ci                        auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
559c5f01b2fSopenharmony_ci                        CHECK(restored == i);
560c5f01b2fSopenharmony_ci
561c5f01b2fSopenharmony_ci                        // roundtrip
562c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
563c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
564c5f01b2fSopenharmony_ci                    }
565c5f01b2fSopenharmony_ci                }
566c5f01b2fSopenharmony_ci
567c5f01b2fSopenharmony_ci                SECTION("32768..65535 (uint16)")
568c5f01b2fSopenharmony_ci                {
569c5f01b2fSopenharmony_ci                    for (uint32_t i :
570c5f01b2fSopenharmony_ci                            {
571c5f01b2fSopenharmony_ci                                32768u, 55555u, 65535u
572c5f01b2fSopenharmony_ci                            })
573c5f01b2fSopenharmony_ci                    {
574c5f01b2fSopenharmony_ci                        CAPTURE(i)
575c5f01b2fSopenharmony_ci
576c5f01b2fSopenharmony_ci                        // create JSON value with integer number
577c5f01b2fSopenharmony_ci                        json j = -1;
578c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
579c5f01b2fSopenharmony_ci
580c5f01b2fSopenharmony_ci                        // check type
581c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
582c5f01b2fSopenharmony_ci
583c5f01b2fSopenharmony_ci                        // create expected byte vector
584c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
585c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>('u'));
586c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
587c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
588c5f01b2fSopenharmony_ci
589c5f01b2fSopenharmony_ci                        // compare result + size
590c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
591c5f01b2fSopenharmony_ci                        CHECK(result == expected);
592c5f01b2fSopenharmony_ci                        CHECK(result.size() == 3);
593c5f01b2fSopenharmony_ci
594c5f01b2fSopenharmony_ci                        // check individual bytes
595c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'u');
596c5f01b2fSopenharmony_ci                        auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
597c5f01b2fSopenharmony_ci                        CHECK(restored == i);
598c5f01b2fSopenharmony_ci
599c5f01b2fSopenharmony_ci                        // roundtrip
600c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
601c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
602c5f01b2fSopenharmony_ci                    }
603c5f01b2fSopenharmony_ci                }
604c5f01b2fSopenharmony_ci
605c5f01b2fSopenharmony_ci                SECTION("65536..2147483647 (int32)")
606c5f01b2fSopenharmony_ci                {
607c5f01b2fSopenharmony_ci                    for (uint32_t i :
608c5f01b2fSopenharmony_ci                            {
609c5f01b2fSopenharmony_ci                                65536u, 77777u, 2147483647u
610c5f01b2fSopenharmony_ci                            })
611c5f01b2fSopenharmony_ci                    {
612c5f01b2fSopenharmony_ci                        CAPTURE(i)
613c5f01b2fSopenharmony_ci
614c5f01b2fSopenharmony_ci                        // create JSON value with integer number
615c5f01b2fSopenharmony_ci                        json j = -1;
616c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
617c5f01b2fSopenharmony_ci
618c5f01b2fSopenharmony_ci                        // check type
619c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
620c5f01b2fSopenharmony_ci
621c5f01b2fSopenharmony_ci                        // create expected byte vector
622c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
623c5f01b2fSopenharmony_ci                        expected.push_back('l');
624c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
625c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
626c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
627c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
628c5f01b2fSopenharmony_ci
629c5f01b2fSopenharmony_ci                        // compare result + size
630c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
631c5f01b2fSopenharmony_ci                        CHECK(result == expected);
632c5f01b2fSopenharmony_ci                        CHECK(result.size() == 5);
633c5f01b2fSopenharmony_ci
634c5f01b2fSopenharmony_ci                        // check individual bytes
635c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'l');
636c5f01b2fSopenharmony_ci                        uint32_t restored = (static_cast<uint32_t>(result[4]) << 030) +
637c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[3]) << 020) +
638c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[2]) << 010) +
639c5f01b2fSopenharmony_ci                                            static_cast<uint32_t>(result[1]);
640c5f01b2fSopenharmony_ci                        CHECK(restored == i);
641c5f01b2fSopenharmony_ci
642c5f01b2fSopenharmony_ci                        // roundtrip
643c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
644c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
645c5f01b2fSopenharmony_ci                    }
646c5f01b2fSopenharmony_ci                }
647c5f01b2fSopenharmony_ci
648c5f01b2fSopenharmony_ci                SECTION("2147483648..4294967295 (uint32)")
649c5f01b2fSopenharmony_ci                {
650c5f01b2fSopenharmony_ci                    for (uint32_t i :
651c5f01b2fSopenharmony_ci                            {
652c5f01b2fSopenharmony_ci                                2147483648u, 3333333333u, 4294967295u
653c5f01b2fSopenharmony_ci                            })
654c5f01b2fSopenharmony_ci                    {
655c5f01b2fSopenharmony_ci                        CAPTURE(i)
656c5f01b2fSopenharmony_ci
657c5f01b2fSopenharmony_ci                        // create JSON value with integer number
658c5f01b2fSopenharmony_ci                        json j = -1;
659c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
660c5f01b2fSopenharmony_ci
661c5f01b2fSopenharmony_ci                        // check type
662c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
663c5f01b2fSopenharmony_ci
664c5f01b2fSopenharmony_ci                        // create expected byte vector
665c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
666c5f01b2fSopenharmony_ci                        expected.push_back('m');
667c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
668c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
669c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
670c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
671c5f01b2fSopenharmony_ci
672c5f01b2fSopenharmony_ci                        // compare result + size
673c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
674c5f01b2fSopenharmony_ci                        CHECK(result == expected);
675c5f01b2fSopenharmony_ci                        CHECK(result.size() == 5);
676c5f01b2fSopenharmony_ci
677c5f01b2fSopenharmony_ci                        // check individual bytes
678c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'm');
679c5f01b2fSopenharmony_ci                        uint32_t restored = (static_cast<uint32_t>(result[4]) << 030) +
680c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[3]) << 020) +
681c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[2]) << 010) +
682c5f01b2fSopenharmony_ci                                            static_cast<uint32_t>(result[1]);
683c5f01b2fSopenharmony_ci                        CHECK(restored == i);
684c5f01b2fSopenharmony_ci
685c5f01b2fSopenharmony_ci                        // roundtrip
686c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
687c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
688c5f01b2fSopenharmony_ci                    }
689c5f01b2fSopenharmony_ci                }
690c5f01b2fSopenharmony_ci
691c5f01b2fSopenharmony_ci                SECTION("4294967296..9223372036854775807 (int64)")
692c5f01b2fSopenharmony_ci                {
693c5f01b2fSopenharmony_ci                    std::vector<uint64_t> v = {4294967296LU, 9223372036854775807LU};
694c5f01b2fSopenharmony_ci                    for (uint64_t i : v)
695c5f01b2fSopenharmony_ci                    {
696c5f01b2fSopenharmony_ci                        CAPTURE(i)
697c5f01b2fSopenharmony_ci
698c5f01b2fSopenharmony_ci                        // create JSON value with integer number
699c5f01b2fSopenharmony_ci                        json j = -1;
700c5f01b2fSopenharmony_ci                        j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
701c5f01b2fSopenharmony_ci
702c5f01b2fSopenharmony_ci                        // check type
703c5f01b2fSopenharmony_ci                        CHECK(j.is_number_integer());
704c5f01b2fSopenharmony_ci
705c5f01b2fSopenharmony_ci                        // create expected byte vector
706c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
707c5f01b2fSopenharmony_ci                        expected.push_back('L');
708c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
709c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 010) & 0xff));
710c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 020) & 0xff));
711c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 030) & 0xff));
712c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 040) & 0xff));
713c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 050) & 0xff));
714c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 060) & 0xff));
715c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 070) & 0xff));
716c5f01b2fSopenharmony_ci
717c5f01b2fSopenharmony_ci                        // compare result + size
718c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
719c5f01b2fSopenharmony_ci                        CHECK(result == expected);
720c5f01b2fSopenharmony_ci                        CHECK(result.size() == 9);
721c5f01b2fSopenharmony_ci
722c5f01b2fSopenharmony_ci                        // check individual bytes
723c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'L');
724c5f01b2fSopenharmony_ci                        uint64_t restored = (static_cast<uint64_t>(result[8]) << 070) +
725c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[7]) << 060) +
726c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[6]) << 050) +
727c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[5]) << 040) +
728c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[4]) << 030) +
729c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[3]) << 020) +
730c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[2]) << 010) +
731c5f01b2fSopenharmony_ci                                            static_cast<uint64_t>(result[1]);
732c5f01b2fSopenharmony_ci                        CHECK(restored == i);
733c5f01b2fSopenharmony_ci
734c5f01b2fSopenharmony_ci                        // roundtrip
735c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
736c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
737c5f01b2fSopenharmony_ci                    }
738c5f01b2fSopenharmony_ci                }
739c5f01b2fSopenharmony_ci
740c5f01b2fSopenharmony_ci                SECTION("9223372036854775808..18446744073709551615 (uint64)")
741c5f01b2fSopenharmony_ci                {
742c5f01b2fSopenharmony_ci                    std::vector<uint64_t> v = {9223372036854775808ull, 18446744073709551615ull};
743c5f01b2fSopenharmony_ci                    for (uint64_t i : v)
744c5f01b2fSopenharmony_ci                    {
745c5f01b2fSopenharmony_ci                        CAPTURE(i)
746c5f01b2fSopenharmony_ci
747c5f01b2fSopenharmony_ci                        // create JSON value with integer number
748c5f01b2fSopenharmony_ci                        json j = i;
749c5f01b2fSopenharmony_ci
750c5f01b2fSopenharmony_ci                        // check type
751c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
752c5f01b2fSopenharmony_ci
753c5f01b2fSopenharmony_ci                        // create expected byte vector
754c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
755c5f01b2fSopenharmony_ci                        expected.push_back('M');
756c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
757c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 010) & 0xff));
758c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 020) & 0xff));
759c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 030) & 0xff));
760c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 040) & 0xff));
761c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 050) & 0xff));
762c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 060) & 0xff));
763c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 070) & 0xff));
764c5f01b2fSopenharmony_ci
765c5f01b2fSopenharmony_ci                        // compare result + size
766c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
767c5f01b2fSopenharmony_ci                        CHECK(result == expected);
768c5f01b2fSopenharmony_ci                        CHECK(result.size() == 9);
769c5f01b2fSopenharmony_ci
770c5f01b2fSopenharmony_ci                        // check individual bytes
771c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'M');
772c5f01b2fSopenharmony_ci                        uint64_t restored = (static_cast<uint64_t>(result[8]) << 070) +
773c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[7]) << 060) +
774c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[6]) << 050) +
775c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[5]) << 040) +
776c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[4]) << 030) +
777c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[3]) << 020) +
778c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[2]) << 010) +
779c5f01b2fSopenharmony_ci                                            static_cast<uint64_t>(result[1]);
780c5f01b2fSopenharmony_ci                        CHECK(restored == i);
781c5f01b2fSopenharmony_ci
782c5f01b2fSopenharmony_ci                        // roundtrip
783c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
784c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
785c5f01b2fSopenharmony_ci                    }
786c5f01b2fSopenharmony_ci                }
787c5f01b2fSopenharmony_ci            }
788c5f01b2fSopenharmony_ci
789c5f01b2fSopenharmony_ci            SECTION("unsigned")
790c5f01b2fSopenharmony_ci            {
791c5f01b2fSopenharmony_ci                SECTION("0..127 (int8)")
792c5f01b2fSopenharmony_ci                {
793c5f01b2fSopenharmony_ci                    for (size_t i = 0; i <= 127; ++i)
794c5f01b2fSopenharmony_ci                    {
795c5f01b2fSopenharmony_ci                        CAPTURE(i)
796c5f01b2fSopenharmony_ci
797c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
798c5f01b2fSopenharmony_ci                        json j = i;
799c5f01b2fSopenharmony_ci
800c5f01b2fSopenharmony_ci                        // check type
801c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
802c5f01b2fSopenharmony_ci
803c5f01b2fSopenharmony_ci                        // create expected byte vector
804c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
805c5f01b2fSopenharmony_ci                        expected.push_back('i');
806c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i));
807c5f01b2fSopenharmony_ci
808c5f01b2fSopenharmony_ci                        // compare result + size
809c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
810c5f01b2fSopenharmony_ci                        CHECK(result == expected);
811c5f01b2fSopenharmony_ci                        CHECK(result.size() == 2);
812c5f01b2fSopenharmony_ci
813c5f01b2fSopenharmony_ci                        // check individual bytes
814c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'i');
815c5f01b2fSopenharmony_ci                        auto restored = static_cast<uint8_t>(result[1]);
816c5f01b2fSopenharmony_ci                        CHECK(restored == i);
817c5f01b2fSopenharmony_ci
818c5f01b2fSopenharmony_ci                        // roundtrip
819c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
820c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
821c5f01b2fSopenharmony_ci                    }
822c5f01b2fSopenharmony_ci                }
823c5f01b2fSopenharmony_ci
824c5f01b2fSopenharmony_ci                SECTION("128..255 (uint8)")
825c5f01b2fSopenharmony_ci                {
826c5f01b2fSopenharmony_ci                    for (size_t i = 128; i <= 255; ++i)
827c5f01b2fSopenharmony_ci                    {
828c5f01b2fSopenharmony_ci                        CAPTURE(i)
829c5f01b2fSopenharmony_ci
830c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
831c5f01b2fSopenharmony_ci                        json j = i;
832c5f01b2fSopenharmony_ci
833c5f01b2fSopenharmony_ci                        // check type
834c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
835c5f01b2fSopenharmony_ci
836c5f01b2fSopenharmony_ci                        // create expected byte vector
837c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
838c5f01b2fSopenharmony_ci                        expected.push_back('U');
839c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i));
840c5f01b2fSopenharmony_ci
841c5f01b2fSopenharmony_ci                        // compare result + size
842c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
843c5f01b2fSopenharmony_ci                        CHECK(result == expected);
844c5f01b2fSopenharmony_ci                        CHECK(result.size() == 2);
845c5f01b2fSopenharmony_ci
846c5f01b2fSopenharmony_ci                        // check individual bytes
847c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'U');
848c5f01b2fSopenharmony_ci                        auto restored = static_cast<uint8_t>(result[1]);
849c5f01b2fSopenharmony_ci                        CHECK(restored == i);
850c5f01b2fSopenharmony_ci
851c5f01b2fSopenharmony_ci                        // roundtrip
852c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
853c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
854c5f01b2fSopenharmony_ci                    }
855c5f01b2fSopenharmony_ci                }
856c5f01b2fSopenharmony_ci
857c5f01b2fSopenharmony_ci                SECTION("256..32767 (int16)")
858c5f01b2fSopenharmony_ci                {
859c5f01b2fSopenharmony_ci                    for (size_t i = 256; i <= 32767; ++i)
860c5f01b2fSopenharmony_ci                    {
861c5f01b2fSopenharmony_ci                        CAPTURE(i)
862c5f01b2fSopenharmony_ci
863c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
864c5f01b2fSopenharmony_ci                        json j = i;
865c5f01b2fSopenharmony_ci
866c5f01b2fSopenharmony_ci                        // check type
867c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
868c5f01b2fSopenharmony_ci
869c5f01b2fSopenharmony_ci                        // create expected byte vector
870c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
871c5f01b2fSopenharmony_ci                        expected.push_back('I');
872c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
873c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
874c5f01b2fSopenharmony_ci
875c5f01b2fSopenharmony_ci                        // compare result + size
876c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
877c5f01b2fSopenharmony_ci                        CHECK(result == expected);
878c5f01b2fSopenharmony_ci                        CHECK(result.size() == 3);
879c5f01b2fSopenharmony_ci
880c5f01b2fSopenharmony_ci                        // check individual bytes
881c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'I');
882c5f01b2fSopenharmony_ci                        auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
883c5f01b2fSopenharmony_ci                        CHECK(restored == i);
884c5f01b2fSopenharmony_ci
885c5f01b2fSopenharmony_ci                        // roundtrip
886c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
887c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
888c5f01b2fSopenharmony_ci                    }
889c5f01b2fSopenharmony_ci                }
890c5f01b2fSopenharmony_ci
891c5f01b2fSopenharmony_ci                SECTION("32768..65535 (uint16)")
892c5f01b2fSopenharmony_ci                {
893c5f01b2fSopenharmony_ci                    for (uint32_t i :
894c5f01b2fSopenharmony_ci                            {
895c5f01b2fSopenharmony_ci                                32768u, 55555u, 65535u
896c5f01b2fSopenharmony_ci                            })
897c5f01b2fSopenharmony_ci                    {
898c5f01b2fSopenharmony_ci                        CAPTURE(i)
899c5f01b2fSopenharmony_ci
900c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
901c5f01b2fSopenharmony_ci                        json j = i;
902c5f01b2fSopenharmony_ci
903c5f01b2fSopenharmony_ci                        // check type
904c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
905c5f01b2fSopenharmony_ci
906c5f01b2fSopenharmony_ci                        // create expected byte vector
907c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
908c5f01b2fSopenharmony_ci                        expected.push_back('u');
909c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
910c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
911c5f01b2fSopenharmony_ci
912c5f01b2fSopenharmony_ci                        // compare result + size
913c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
914c5f01b2fSopenharmony_ci                        CHECK(result == expected);
915c5f01b2fSopenharmony_ci                        CHECK(result.size() == 3);
916c5f01b2fSopenharmony_ci
917c5f01b2fSopenharmony_ci                        // check individual bytes
918c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'u');
919c5f01b2fSopenharmony_ci                        auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
920c5f01b2fSopenharmony_ci                        CHECK(restored == i);
921c5f01b2fSopenharmony_ci
922c5f01b2fSopenharmony_ci                        // roundtrip
923c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
924c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
925c5f01b2fSopenharmony_ci                    }
926c5f01b2fSopenharmony_ci                }
927c5f01b2fSopenharmony_ci                SECTION("65536..2147483647 (int32)")
928c5f01b2fSopenharmony_ci                {
929c5f01b2fSopenharmony_ci                    for (uint32_t i :
930c5f01b2fSopenharmony_ci                            {
931c5f01b2fSopenharmony_ci                                65536u, 77777u, 2147483647u
932c5f01b2fSopenharmony_ci                            })
933c5f01b2fSopenharmony_ci                    {
934c5f01b2fSopenharmony_ci                        CAPTURE(i)
935c5f01b2fSopenharmony_ci
936c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
937c5f01b2fSopenharmony_ci                        json j = i;
938c5f01b2fSopenharmony_ci
939c5f01b2fSopenharmony_ci                        // check type
940c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
941c5f01b2fSopenharmony_ci
942c5f01b2fSopenharmony_ci                        // create expected byte vector
943c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
944c5f01b2fSopenharmony_ci                        expected.push_back('l');
945c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
946c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
947c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
948c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
949c5f01b2fSopenharmony_ci
950c5f01b2fSopenharmony_ci                        // compare result + size
951c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
952c5f01b2fSopenharmony_ci                        CHECK(result == expected);
953c5f01b2fSopenharmony_ci                        CHECK(result.size() == 5);
954c5f01b2fSopenharmony_ci
955c5f01b2fSopenharmony_ci                        // check individual bytes
956c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'l');
957c5f01b2fSopenharmony_ci                        uint32_t restored = (static_cast<uint32_t>(result[4]) << 030) +
958c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[3]) << 020) +
959c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[2]) << 010) +
960c5f01b2fSopenharmony_ci                                            static_cast<uint32_t>(result[1]);
961c5f01b2fSopenharmony_ci                        CHECK(restored == i);
962c5f01b2fSopenharmony_ci
963c5f01b2fSopenharmony_ci                        // roundtrip
964c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
965c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
966c5f01b2fSopenharmony_ci                    }
967c5f01b2fSopenharmony_ci                }
968c5f01b2fSopenharmony_ci
969c5f01b2fSopenharmony_ci                SECTION("2147483648..4294967295 (uint32)")
970c5f01b2fSopenharmony_ci                {
971c5f01b2fSopenharmony_ci                    for (uint32_t i :
972c5f01b2fSopenharmony_ci                            {
973c5f01b2fSopenharmony_ci                                2147483648u, 3333333333u, 4294967295u
974c5f01b2fSopenharmony_ci                            })
975c5f01b2fSopenharmony_ci                    {
976c5f01b2fSopenharmony_ci                        CAPTURE(i)
977c5f01b2fSopenharmony_ci
978c5f01b2fSopenharmony_ci                        // create JSON value with unsigned integer number
979c5f01b2fSopenharmony_ci                        json j = i;
980c5f01b2fSopenharmony_ci
981c5f01b2fSopenharmony_ci                        // check type
982c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
983c5f01b2fSopenharmony_ci
984c5f01b2fSopenharmony_ci                        // create expected byte vector
985c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
986c5f01b2fSopenharmony_ci                        expected.push_back('m');
987c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
988c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
989c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
990c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
991c5f01b2fSopenharmony_ci
992c5f01b2fSopenharmony_ci                        // compare result + size
993c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
994c5f01b2fSopenharmony_ci                        CHECK(result == expected);
995c5f01b2fSopenharmony_ci                        CHECK(result.size() == 5);
996c5f01b2fSopenharmony_ci
997c5f01b2fSopenharmony_ci                        // check individual bytes
998c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'm');
999c5f01b2fSopenharmony_ci                        uint32_t restored = (static_cast<uint32_t>(result[4]) << 030) +
1000c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[3]) << 020) +
1001c5f01b2fSopenharmony_ci                                            (static_cast<uint32_t>(result[2]) << 010) +
1002c5f01b2fSopenharmony_ci                                            static_cast<uint32_t>(result[1]);
1003c5f01b2fSopenharmony_ci                        CHECK(restored == i);
1004c5f01b2fSopenharmony_ci
1005c5f01b2fSopenharmony_ci                        // roundtrip
1006c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
1007c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
1008c5f01b2fSopenharmony_ci                    }
1009c5f01b2fSopenharmony_ci                }
1010c5f01b2fSopenharmony_ci
1011c5f01b2fSopenharmony_ci                SECTION("4294967296..9223372036854775807 (int64)")
1012c5f01b2fSopenharmony_ci                {
1013c5f01b2fSopenharmony_ci                    std::vector<uint64_t> v = {4294967296ul, 9223372036854775807ul};
1014c5f01b2fSopenharmony_ci                    for (uint64_t i : v)
1015c5f01b2fSopenharmony_ci                    {
1016c5f01b2fSopenharmony_ci                        CAPTURE(i)
1017c5f01b2fSopenharmony_ci
1018c5f01b2fSopenharmony_ci                        // create JSON value with integer number
1019c5f01b2fSopenharmony_ci                        json j = i;
1020c5f01b2fSopenharmony_ci
1021c5f01b2fSopenharmony_ci                        // check type
1022c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
1023c5f01b2fSopenharmony_ci
1024c5f01b2fSopenharmony_ci                        // create expected byte vector
1025c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
1026c5f01b2fSopenharmony_ci                        expected.push_back('L');
1027c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
1028c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 010) & 0xff));
1029c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 020) & 0xff));
1030c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 030) & 0xff));
1031c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 040) & 0xff));
1032c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 050) & 0xff));
1033c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 060) & 0xff));
1034c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 070) & 0xff));
1035c5f01b2fSopenharmony_ci
1036c5f01b2fSopenharmony_ci                        // compare result + size
1037c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
1038c5f01b2fSopenharmony_ci                        CHECK(result == expected);
1039c5f01b2fSopenharmony_ci                        CHECK(result.size() == 9);
1040c5f01b2fSopenharmony_ci
1041c5f01b2fSopenharmony_ci                        // check individual bytes
1042c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'L');
1043c5f01b2fSopenharmony_ci                        uint64_t restored = (static_cast<uint64_t>(result[8]) << 070) +
1044c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[7]) << 060) +
1045c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[6]) << 050) +
1046c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[5]) << 040) +
1047c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[4]) << 030) +
1048c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[3]) << 020) +
1049c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[2]) << 010) +
1050c5f01b2fSopenharmony_ci                                            static_cast<uint64_t>(result[1]);
1051c5f01b2fSopenharmony_ci                        CHECK(restored == i);
1052c5f01b2fSopenharmony_ci
1053c5f01b2fSopenharmony_ci                        // roundtrip
1054c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
1055c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
1056c5f01b2fSopenharmony_ci                    }
1057c5f01b2fSopenharmony_ci                }
1058c5f01b2fSopenharmony_ci
1059c5f01b2fSopenharmony_ci                SECTION("9223372036854775808..18446744073709551615 (uint64)")
1060c5f01b2fSopenharmony_ci                {
1061c5f01b2fSopenharmony_ci                    std::vector<uint64_t> v = {9223372036854775808ull, 18446744073709551615ull};
1062c5f01b2fSopenharmony_ci                    for (uint64_t i : v)
1063c5f01b2fSopenharmony_ci                    {
1064c5f01b2fSopenharmony_ci                        CAPTURE(i)
1065c5f01b2fSopenharmony_ci
1066c5f01b2fSopenharmony_ci                        // create JSON value with integer number
1067c5f01b2fSopenharmony_ci                        json j = i;
1068c5f01b2fSopenharmony_ci
1069c5f01b2fSopenharmony_ci                        // check type
1070c5f01b2fSopenharmony_ci                        CHECK(j.is_number_unsigned());
1071c5f01b2fSopenharmony_ci
1072c5f01b2fSopenharmony_ci                        // create expected byte vector
1073c5f01b2fSopenharmony_ci                        std::vector<uint8_t> expected;
1074c5f01b2fSopenharmony_ci                        expected.push_back('M');
1075c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>(i & 0xff));
1076c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 010) & 0xff));
1077c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 020) & 0xff));
1078c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 030) & 0xff));
1079c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 040) & 0xff));
1080c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 050) & 0xff));
1081c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 060) & 0xff));
1082c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<uint8_t>((i >> 070) & 0xff));
1083c5f01b2fSopenharmony_ci
1084c5f01b2fSopenharmony_ci                        // compare result + size
1085c5f01b2fSopenharmony_ci                        const auto result = json::to_bjdata(j);
1086c5f01b2fSopenharmony_ci                        CHECK(result == expected);
1087c5f01b2fSopenharmony_ci                        CHECK(result.size() == 9);
1088c5f01b2fSopenharmony_ci
1089c5f01b2fSopenharmony_ci                        // check individual bytes
1090c5f01b2fSopenharmony_ci                        CHECK(result[0] == 'M');
1091c5f01b2fSopenharmony_ci                        uint64_t restored = (static_cast<uint64_t>(result[8]) << 070) +
1092c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[7]) << 060) +
1093c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[6]) << 050) +
1094c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[5]) << 040) +
1095c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[4]) << 030) +
1096c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[3]) << 020) +
1097c5f01b2fSopenharmony_ci                                            (static_cast<uint64_t>(result[2]) << 010) +
1098c5f01b2fSopenharmony_ci                                            static_cast<uint64_t>(result[1]);
1099c5f01b2fSopenharmony_ci                        CHECK(restored == i);
1100c5f01b2fSopenharmony_ci
1101c5f01b2fSopenharmony_ci                        // roundtrip
1102c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result) == j);
1103c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(result, true, false) == j);
1104c5f01b2fSopenharmony_ci                    }
1105c5f01b2fSopenharmony_ci                }
1106c5f01b2fSopenharmony_ci            }
1107c5f01b2fSopenharmony_ci            SECTION("float64")
1108c5f01b2fSopenharmony_ci            {
1109c5f01b2fSopenharmony_ci                SECTION("3.1415925")
1110c5f01b2fSopenharmony_ci                {
1111c5f01b2fSopenharmony_ci                    double v = 3.1415925;
1112c5f01b2fSopenharmony_ci                    json j = v;
1113c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected =
1114c5f01b2fSopenharmony_ci                    {
1115c5f01b2fSopenharmony_ci                        'D', 0xfc, 0xde, 0xa6, 0x3f, 0xfb, 0x21, 0x09, 0x40
1116c5f01b2fSopenharmony_ci                    };
1117c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1118c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1119c5f01b2fSopenharmony_ci
1120c5f01b2fSopenharmony_ci                    // roundtrip
1121c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1122c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == v);
1123c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1124c5f01b2fSopenharmony_ci                }
1125c5f01b2fSopenharmony_ci            }
1126c5f01b2fSopenharmony_ci
1127c5f01b2fSopenharmony_ci            SECTION("half-precision float")
1128c5f01b2fSopenharmony_ci            {
1129c5f01b2fSopenharmony_ci                SECTION("simple half floats")
1130c5f01b2fSopenharmony_ci                {
1131c5f01b2fSopenharmony_ci                    CHECK(json::parse("0.0") == json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x00})));
1132c5f01b2fSopenharmony_ci                    CHECK(json::parse("-0.0") == json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x80})));
1133c5f01b2fSopenharmony_ci                    CHECK(json::parse("1.0") == json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x3c})));
1134c5f01b2fSopenharmony_ci                    CHECK(json::parse("1.5") == json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x3e})));
1135c5f01b2fSopenharmony_ci                    CHECK(json::parse("65504.0") == json::from_bjdata(std::vector<uint8_t>({'h', 0xff, 0x7b})));
1136c5f01b2fSopenharmony_ci                }
1137c5f01b2fSopenharmony_ci
1138c5f01b2fSopenharmony_ci                SECTION("errors")
1139c5f01b2fSopenharmony_ci                {
1140c5f01b2fSopenharmony_ci                    SECTION("no byte follows")
1141c5f01b2fSopenharmony_ci                    {
1142c5f01b2fSopenharmony_ci                        json _;
1143c5f01b2fSopenharmony_ci                        std::vector<uint8_t> vec0 = {'h'};
1144c5f01b2fSopenharmony_ci                        CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec0), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
1145c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(vec0, true, false).is_discarded());
1146c5f01b2fSopenharmony_ci                    }
1147c5f01b2fSopenharmony_ci
1148c5f01b2fSopenharmony_ci                    SECTION("only one byte follows")
1149c5f01b2fSopenharmony_ci                    {
1150c5f01b2fSopenharmony_ci                        json _;
1151c5f01b2fSopenharmony_ci                        std::vector<uint8_t> vec1 = {'h', 0x00};
1152c5f01b2fSopenharmony_ci                        CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec1), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
1153c5f01b2fSopenharmony_ci                        CHECK(json::from_bjdata(vec1, true, false).is_discarded());
1154c5f01b2fSopenharmony_ci                    }
1155c5f01b2fSopenharmony_ci                }
1156c5f01b2fSopenharmony_ci            }
1157c5f01b2fSopenharmony_ci
1158c5f01b2fSopenharmony_ci            SECTION("half-precision float (edge cases)")
1159c5f01b2fSopenharmony_ci            {
1160c5f01b2fSopenharmony_ci                SECTION("exp = 0b00000")
1161c5f01b2fSopenharmony_ci                {
1162c5f01b2fSopenharmony_ci                    SECTION("0 (0 00000 0000000000)")
1163c5f01b2fSopenharmony_ci                    {
1164c5f01b2fSopenharmony_ci                        json j = json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x00}));
1165c5f01b2fSopenharmony_ci                        json::number_float_t d{j};
1166c5f01b2fSopenharmony_ci                        CHECK(d == 0.0);
1167c5f01b2fSopenharmony_ci                    }
1168c5f01b2fSopenharmony_ci
1169c5f01b2fSopenharmony_ci                    SECTION("-0 (1 00000 0000000000)")
1170c5f01b2fSopenharmony_ci                    {
1171c5f01b2fSopenharmony_ci                        json j = json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x80}));
1172c5f01b2fSopenharmony_ci                        json::number_float_t d{j};
1173c5f01b2fSopenharmony_ci                        CHECK(d == -0.0);
1174c5f01b2fSopenharmony_ci                    }
1175c5f01b2fSopenharmony_ci
1176c5f01b2fSopenharmony_ci                    SECTION("2**-24 (0 00000 0000000001)")
1177c5f01b2fSopenharmony_ci                    {
1178c5f01b2fSopenharmony_ci                        json j = json::from_bjdata(std::vector<uint8_t>({'h', 0x01, 0x00}));
1179c5f01b2fSopenharmony_ci                        json::number_float_t d{j};
1180c5f01b2fSopenharmony_ci                        CHECK(d == std::pow(2.0, -24.0));
1181c5f01b2fSopenharmony_ci                    }
1182c5f01b2fSopenharmony_ci                }
1183c5f01b2fSopenharmony_ci
1184c5f01b2fSopenharmony_ci                SECTION("exp = 0b11111")
1185c5f01b2fSopenharmony_ci                {
1186c5f01b2fSopenharmony_ci                    SECTION("infinity (0 11111 0000000000)")
1187c5f01b2fSopenharmony_ci                    {
1188c5f01b2fSopenharmony_ci                        json j = json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x7c}));
1189c5f01b2fSopenharmony_ci                        json::number_float_t d{j};
1190c5f01b2fSopenharmony_ci                        CHECK(d == std::numeric_limits<json::number_float_t>::infinity());
1191c5f01b2fSopenharmony_ci                        CHECK(j.dump() == "null");
1192c5f01b2fSopenharmony_ci                    }
1193c5f01b2fSopenharmony_ci
1194c5f01b2fSopenharmony_ci                    SECTION("-infinity (1 11111 0000000000)")
1195c5f01b2fSopenharmony_ci                    {
1196c5f01b2fSopenharmony_ci                        json j = json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0xfc}));
1197c5f01b2fSopenharmony_ci                        json::number_float_t d{j};
1198c5f01b2fSopenharmony_ci                        CHECK(d == -std::numeric_limits<json::number_float_t>::infinity());
1199c5f01b2fSopenharmony_ci                        CHECK(j.dump() == "null");
1200c5f01b2fSopenharmony_ci                    }
1201c5f01b2fSopenharmony_ci                }
1202c5f01b2fSopenharmony_ci
1203c5f01b2fSopenharmony_ci                SECTION("other values from https://en.wikipedia.org/wiki/Half-precision_floating-point_format")
1204c5f01b2fSopenharmony_ci                {
1205c5f01b2fSopenharmony_ci                    SECTION("1 (0 01111 0000000000)")
1206c5f01b2fSopenharmony_ci                    {
1207c5f01b2fSopenharmony_ci                        json j = json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x3c}));
1208c5f01b2fSopenharmony_ci                        json::number_float_t d{j};
1209c5f01b2fSopenharmony_ci                        CHECK(d == 1);
1210c5f01b2fSopenharmony_ci                    }
1211c5f01b2fSopenharmony_ci
1212c5f01b2fSopenharmony_ci                    SECTION("-2 (1 10000 0000000000)")
1213c5f01b2fSopenharmony_ci                    {
1214c5f01b2fSopenharmony_ci                        json j = json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0xc0}));
1215c5f01b2fSopenharmony_ci                        json::number_float_t d{j};
1216c5f01b2fSopenharmony_ci                        CHECK(d == -2);
1217c5f01b2fSopenharmony_ci                    }
1218c5f01b2fSopenharmony_ci
1219c5f01b2fSopenharmony_ci                    SECTION("65504 (0 11110 1111111111)")
1220c5f01b2fSopenharmony_ci                    {
1221c5f01b2fSopenharmony_ci                        json j = json::from_bjdata(std::vector<uint8_t>({'h', 0xff, 0x7b}));
1222c5f01b2fSopenharmony_ci                        json::number_float_t d{j};
1223c5f01b2fSopenharmony_ci                        CHECK(d == 65504);
1224c5f01b2fSopenharmony_ci                    }
1225c5f01b2fSopenharmony_ci                }
1226c5f01b2fSopenharmony_ci
1227c5f01b2fSopenharmony_ci                SECTION("infinity")
1228c5f01b2fSopenharmony_ci                {
1229c5f01b2fSopenharmony_ci                    json j = json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x7c}));
1230c5f01b2fSopenharmony_ci                    json::number_float_t d{j};
1231c5f01b2fSopenharmony_ci                    CHECK_FALSE(std::isfinite(d));
1232c5f01b2fSopenharmony_ci                    CHECK(j.dump() == "null");
1233c5f01b2fSopenharmony_ci                }
1234c5f01b2fSopenharmony_ci
1235c5f01b2fSopenharmony_ci                SECTION("NaN")
1236c5f01b2fSopenharmony_ci                {
1237c5f01b2fSopenharmony_ci                    json j = json::from_bjdata(std::vector<uint8_t>({'h', 0x00, 0x7e }));
1238c5f01b2fSopenharmony_ci                    json::number_float_t d{j};
1239c5f01b2fSopenharmony_ci                    CHECK(std::isnan(d));
1240c5f01b2fSopenharmony_ci                    CHECK(j.dump() == "null");
1241c5f01b2fSopenharmony_ci                }
1242c5f01b2fSopenharmony_ci            }
1243c5f01b2fSopenharmony_ci
1244c5f01b2fSopenharmony_ci            SECTION("high-precision number")
1245c5f01b2fSopenharmony_ci            {
1246c5f01b2fSopenharmony_ci                SECTION("unsigned integer number")
1247c5f01b2fSopenharmony_ci                {
1248c5f01b2fSopenharmony_ci                    std::vector<uint8_t> vec = {'H', 'i', 0x14, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
1249c5f01b2fSopenharmony_ci                    const auto j = json::from_bjdata(vec);
1250c5f01b2fSopenharmony_ci                    CHECK(j.is_number_unsigned());
1251c5f01b2fSopenharmony_ci                    CHECK(j.dump() == "12345678901234567890");
1252c5f01b2fSopenharmony_ci                }
1253c5f01b2fSopenharmony_ci
1254c5f01b2fSopenharmony_ci                SECTION("signed integer number")
1255c5f01b2fSopenharmony_ci                {
1256c5f01b2fSopenharmony_ci                    std::vector<uint8_t> vec = {'H', 'i', 0x13, '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8'};
1257c5f01b2fSopenharmony_ci                    const auto j = json::from_bjdata(vec);
1258c5f01b2fSopenharmony_ci                    CHECK(j.is_number_integer());
1259c5f01b2fSopenharmony_ci                    CHECK(j.dump() == "-123456789012345678");
1260c5f01b2fSopenharmony_ci                }
1261c5f01b2fSopenharmony_ci
1262c5f01b2fSopenharmony_ci                SECTION("floating-point number")
1263c5f01b2fSopenharmony_ci                {
1264c5f01b2fSopenharmony_ci                    std::vector<uint8_t> vec = {'H', 'i', 0x16, '3', '.', '1', '4', '1', '5', '9',  '2', '6', '5', '3', '5', '8', '9',  '7', '9', '3', '2', '3', '8', '4',  '6'};
1265c5f01b2fSopenharmony_ci                    const auto j = json::from_bjdata(vec);
1266c5f01b2fSopenharmony_ci                    CHECK(j.is_number_float());
1267c5f01b2fSopenharmony_ci                    CHECK(j.dump() == "3.141592653589793");
1268c5f01b2fSopenharmony_ci                }
1269c5f01b2fSopenharmony_ci
1270c5f01b2fSopenharmony_ci                SECTION("errors")
1271c5f01b2fSopenharmony_ci                {
1272c5f01b2fSopenharmony_ci                    // error while parsing length
1273c5f01b2fSopenharmony_ci                    std::vector<uint8_t> vec0 = {'H', 'i'};
1274c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(vec0, true, false).is_discarded());
1275c5f01b2fSopenharmony_ci                    // error while parsing string
1276c5f01b2fSopenharmony_ci                    std::vector<uint8_t> vec1 = {'H', 'i', '1'};
1277c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(vec1, true, false).is_discarded());
1278c5f01b2fSopenharmony_ci
1279c5f01b2fSopenharmony_ci                    json _;
1280c5f01b2fSopenharmony_ci                    std::vector<uint8_t> vec2 = {'H', 'i', 2, '1', 'A', '3'};
1281c5f01b2fSopenharmony_ci                    CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec2), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing BJData high-precision number: invalid number text: 1A", json::parse_error);
1282c5f01b2fSopenharmony_ci                    std::vector<uint8_t> vec3 = {'H', 'i', 2, '1', '.'};
1283c5f01b2fSopenharmony_ci                    CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec3), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing BJData high-precision number: invalid number text: 1.", json::parse_error);
1284c5f01b2fSopenharmony_ci                    std::vector<uint8_t> vec4 = {'H', 2, '1', '0'};
1285c5f01b2fSopenharmony_ci                    CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec4), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x02", json::parse_error);
1286c5f01b2fSopenharmony_ci                }
1287c5f01b2fSopenharmony_ci            }
1288c5f01b2fSopenharmony_ci        }
1289c5f01b2fSopenharmony_ci
1290c5f01b2fSopenharmony_ci        SECTION("string")
1291c5f01b2fSopenharmony_ci        {
1292c5f01b2fSopenharmony_ci            SECTION("N = 0..127")
1293c5f01b2fSopenharmony_ci            {
1294c5f01b2fSopenharmony_ci                for (size_t N = 0; N <= 127; ++N)
1295c5f01b2fSopenharmony_ci                {
1296c5f01b2fSopenharmony_ci                    CAPTURE(N)
1297c5f01b2fSopenharmony_ci
1298c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
1299c5f01b2fSopenharmony_ci                    const auto s = std::string(N, 'x');
1300c5f01b2fSopenharmony_ci                    json j = s;
1301c5f01b2fSopenharmony_ci
1302c5f01b2fSopenharmony_ci                    // create expected byte vector
1303c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected;
1304c5f01b2fSopenharmony_ci                    expected.push_back('S');
1305c5f01b2fSopenharmony_ci                    expected.push_back('i');
1306c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<uint8_t>(N));
1307c5f01b2fSopenharmony_ci                    for (size_t i = 0; i < N; ++i)
1308c5f01b2fSopenharmony_ci                    {
1309c5f01b2fSopenharmony_ci                        expected.push_back('x');
1310c5f01b2fSopenharmony_ci                    }
1311c5f01b2fSopenharmony_ci
1312c5f01b2fSopenharmony_ci                    // compare result + size
1313c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1314c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1315c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 3);
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_bjdata(result) == j);
1324c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1325c5f01b2fSopenharmony_ci                }
1326c5f01b2fSopenharmony_ci            }
1327c5f01b2fSopenharmony_ci
1328c5f01b2fSopenharmony_ci            SECTION("N = 128..255")
1329c5f01b2fSopenharmony_ci            {
1330c5f01b2fSopenharmony_ci                for (size_t N = 128; N <= 255; ++N)
1331c5f01b2fSopenharmony_ci                {
1332c5f01b2fSopenharmony_ci                    CAPTURE(N)
1333c5f01b2fSopenharmony_ci
1334c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
1335c5f01b2fSopenharmony_ci                    const auto s = std::string(N, 'x');
1336c5f01b2fSopenharmony_ci                    json j = s;
1337c5f01b2fSopenharmony_ci
1338c5f01b2fSopenharmony_ci                    // create expected byte vector
1339c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected;
1340c5f01b2fSopenharmony_ci                    expected.push_back('S');
1341c5f01b2fSopenharmony_ci                    expected.push_back('U');
1342c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<uint8_t>(N));
1343c5f01b2fSopenharmony_ci                    for (size_t i = 0; i < N; ++i)
1344c5f01b2fSopenharmony_ci                    {
1345c5f01b2fSopenharmony_ci                        expected.push_back('x');
1346c5f01b2fSopenharmony_ci                    }
1347c5f01b2fSopenharmony_ci
1348c5f01b2fSopenharmony_ci                    // compare result + size
1349c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(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_bjdata(result) == j);
1357c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1358c5f01b2fSopenharmony_ci                }
1359c5f01b2fSopenharmony_ci            }
1360c5f01b2fSopenharmony_ci
1361c5f01b2fSopenharmony_ci            SECTION("N = 256..32767")
1362c5f01b2fSopenharmony_ci            {
1363c5f01b2fSopenharmony_ci                for (size_t N :
1364c5f01b2fSopenharmony_ci                        {
1365c5f01b2fSopenharmony_ci                            256u, 999u, 1025u, 3333u, 2048u, 32767u
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::string(N, 'x');
1372c5f01b2fSopenharmony_ci                    json j = 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<uint8_t>((N >> 8) & 0xff));
1378c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>(N & 0xff));
1379c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 'I');
1380c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 'S');
1381c5f01b2fSopenharmony_ci
1382c5f01b2fSopenharmony_ci                    // compare result + size
1383c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1384c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1385c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 4);
1386c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1387c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1388c5f01b2fSopenharmony_ci
1389c5f01b2fSopenharmony_ci                    // roundtrip
1390c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1391c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1392c5f01b2fSopenharmony_ci                }
1393c5f01b2fSopenharmony_ci            }
1394c5f01b2fSopenharmony_ci
1395c5f01b2fSopenharmony_ci            SECTION("N = 32768..65535")
1396c5f01b2fSopenharmony_ci            {
1397c5f01b2fSopenharmony_ci                for (size_t N :
1398c5f01b2fSopenharmony_ci                        {
1399c5f01b2fSopenharmony_ci                            32768u, 55555u, 65535u
1400c5f01b2fSopenharmony_ci                        })
1401c5f01b2fSopenharmony_ci                {
1402c5f01b2fSopenharmony_ci                    CAPTURE(N)
1403c5f01b2fSopenharmony_ci
1404c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
1405c5f01b2fSopenharmony_ci                    const auto s = std::string(N, 'x');
1406c5f01b2fSopenharmony_ci                    json j = s;
1407c5f01b2fSopenharmony_ci
1408c5f01b2fSopenharmony_ci                    // create expected byte vector (hack: create string first)
1409c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(N, 'x');
1410c5f01b2fSopenharmony_ci                    // reverse order of commands, because we insert at begin()
1411c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 8) & 0xff));
1412c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>(N & 0xff));
1413c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 'u');
1414c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 'S');
1415c5f01b2fSopenharmony_ci
1416c5f01b2fSopenharmony_ci                    // compare result + size
1417c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1418c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1419c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 4);
1420c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1421c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1422c5f01b2fSopenharmony_ci
1423c5f01b2fSopenharmony_ci                    // roundtrip
1424c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1425c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1426c5f01b2fSopenharmony_ci                }
1427c5f01b2fSopenharmony_ci            }
1428c5f01b2fSopenharmony_ci
1429c5f01b2fSopenharmony_ci            SECTION("N = 65536..2147483647")
1430c5f01b2fSopenharmony_ci            {
1431c5f01b2fSopenharmony_ci                for (size_t N :
1432c5f01b2fSopenharmony_ci                        {
1433c5f01b2fSopenharmony_ci                            65536u, 77777u, 1048576u
1434c5f01b2fSopenharmony_ci                        })
1435c5f01b2fSopenharmony_ci                {
1436c5f01b2fSopenharmony_ci                    CAPTURE(N)
1437c5f01b2fSopenharmony_ci
1438c5f01b2fSopenharmony_ci                    // create JSON value with string containing of N * 'x'
1439c5f01b2fSopenharmony_ci                    const auto s = std::string(N, 'x');
1440c5f01b2fSopenharmony_ci                    json j = s;
1441c5f01b2fSopenharmony_ci
1442c5f01b2fSopenharmony_ci                    // create expected byte vector (hack: create string first)
1443c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(N, 'x');
1444c5f01b2fSopenharmony_ci                    // reverse order of commands, because we insert at begin()
1445c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 24) & 0xff));
1446c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 16) & 0xff));
1447c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>((N >> 8) & 0xff));
1448c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), static_cast<uint8_t>(N & 0xff));
1449c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 'l');
1450c5f01b2fSopenharmony_ci                    expected.insert(expected.begin(), 'S');
1451c5f01b2fSopenharmony_ci
1452c5f01b2fSopenharmony_ci                    // compare result + size
1453c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1454c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1455c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 6);
1456c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1457c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1458c5f01b2fSopenharmony_ci
1459c5f01b2fSopenharmony_ci                    // roundtrip
1460c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1461c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1462c5f01b2fSopenharmony_ci                }
1463c5f01b2fSopenharmony_ci            }
1464c5f01b2fSopenharmony_ci        }
1465c5f01b2fSopenharmony_ci
1466c5f01b2fSopenharmony_ci
1467c5f01b2fSopenharmony_ci        SECTION("binary")
1468c5f01b2fSopenharmony_ci        {
1469c5f01b2fSopenharmony_ci            SECTION("N = 0..127")
1470c5f01b2fSopenharmony_ci            {
1471c5f01b2fSopenharmony_ci                for (std::size_t N = 0; N <= 127; ++N)
1472c5f01b2fSopenharmony_ci                {
1473c5f01b2fSopenharmony_ci                    CAPTURE(N)
1474c5f01b2fSopenharmony_ci
1475c5f01b2fSopenharmony_ci                    // create JSON value with byte array containing of N * 'x'
1476c5f01b2fSopenharmony_ci                    const auto s = std::vector<std::uint8_t>(N, 'x');
1477c5f01b2fSopenharmony_ci                    json j = json::binary(s);
1478c5f01b2fSopenharmony_ci
1479c5f01b2fSopenharmony_ci                    // create expected byte vector
1480c5f01b2fSopenharmony_ci                    std::vector<std::uint8_t> expected;
1481c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('['));
1482c5f01b2fSopenharmony_ci                    if (N != 0)
1483c5f01b2fSopenharmony_ci                    {
1484c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<std::uint8_t>('$'));
1485c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<std::uint8_t>('U'));
1486c5f01b2fSopenharmony_ci                    }
1487c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('#'));
1488c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('i'));
1489c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>(N));
1490c5f01b2fSopenharmony_ci                    for (size_t i = 0; i < N; ++i)
1491c5f01b2fSopenharmony_ci                    {
1492c5f01b2fSopenharmony_ci                        expected.push_back(0x78);
1493c5f01b2fSopenharmony_ci                    }
1494c5f01b2fSopenharmony_ci
1495c5f01b2fSopenharmony_ci                    // compare result + size
1496c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, true);
1497c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1498c5f01b2fSopenharmony_ci                    if (N == 0)
1499c5f01b2fSopenharmony_ci                    {
1500c5f01b2fSopenharmony_ci                        CHECK(result.size() == N + 4);
1501c5f01b2fSopenharmony_ci                    }
1502c5f01b2fSopenharmony_ci                    else
1503c5f01b2fSopenharmony_ci                    {
1504c5f01b2fSopenharmony_ci                        CHECK(result.size() == N + 6);
1505c5f01b2fSopenharmony_ci                    }
1506c5f01b2fSopenharmony_ci
1507c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1508c5f01b2fSopenharmony_ci                    if (N > 0)
1509c5f01b2fSopenharmony_ci                    {
1510c5f01b2fSopenharmony_ci                        CHECK(result.back() != '\x00');
1511c5f01b2fSopenharmony_ci                    }
1512c5f01b2fSopenharmony_ci
1513c5f01b2fSopenharmony_ci                    // roundtrip only works to an array of numbers
1514c5f01b2fSopenharmony_ci                    json j_out = s;
1515c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j_out);
1516c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j_out);
1517c5f01b2fSopenharmony_ci                }
1518c5f01b2fSopenharmony_ci            }
1519c5f01b2fSopenharmony_ci
1520c5f01b2fSopenharmony_ci            SECTION("N = 128..255")
1521c5f01b2fSopenharmony_ci            {
1522c5f01b2fSopenharmony_ci                for (std::size_t N = 128; N <= 255; ++N)
1523c5f01b2fSopenharmony_ci                {
1524c5f01b2fSopenharmony_ci                    CAPTURE(N)
1525c5f01b2fSopenharmony_ci
1526c5f01b2fSopenharmony_ci                    // create JSON value with byte array containing of N * 'x'
1527c5f01b2fSopenharmony_ci                    const auto s = std::vector<std::uint8_t>(N, 'x');
1528c5f01b2fSopenharmony_ci                    json j = json::binary(s);
1529c5f01b2fSopenharmony_ci
1530c5f01b2fSopenharmony_ci                    // create expected byte vector
1531c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected;
1532c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('['));
1533c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('$'));
1534c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('U'));
1535c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('#'));
1536c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('U'));
1537c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>(N));
1538c5f01b2fSopenharmony_ci                    for (size_t i = 0; i < N; ++i)
1539c5f01b2fSopenharmony_ci                    {
1540c5f01b2fSopenharmony_ci                        expected.push_back(0x78);
1541c5f01b2fSopenharmony_ci                    }
1542c5f01b2fSopenharmony_ci
1543c5f01b2fSopenharmony_ci                    // compare result + size
1544c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, true);
1545c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1546c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 6);
1547c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1548c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1549c5f01b2fSopenharmony_ci
1550c5f01b2fSopenharmony_ci                    // roundtrip only works to an array of numbers
1551c5f01b2fSopenharmony_ci                    json j_out = s;
1552c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j_out);
1553c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j_out);
1554c5f01b2fSopenharmony_ci                }
1555c5f01b2fSopenharmony_ci            }
1556c5f01b2fSopenharmony_ci
1557c5f01b2fSopenharmony_ci            SECTION("N = 256..32767")
1558c5f01b2fSopenharmony_ci            {
1559c5f01b2fSopenharmony_ci                for (std::size_t N :
1560c5f01b2fSopenharmony_ci                        {
1561c5f01b2fSopenharmony_ci                            256u, 999u, 1025u, 3333u, 2048u, 32767u
1562c5f01b2fSopenharmony_ci                        })
1563c5f01b2fSopenharmony_ci                {
1564c5f01b2fSopenharmony_ci                    CAPTURE(N)
1565c5f01b2fSopenharmony_ci
1566c5f01b2fSopenharmony_ci                    // create JSON value with byte array containing of N * 'x'
1567c5f01b2fSopenharmony_ci                    const auto s = std::vector<std::uint8_t>(N, 'x');
1568c5f01b2fSopenharmony_ci                    json j = json::binary(s);
1569c5f01b2fSopenharmony_ci
1570c5f01b2fSopenharmony_ci                    // create expected byte vector
1571c5f01b2fSopenharmony_ci                    std::vector<std::uint8_t> expected(N + 7, 'x');
1572c5f01b2fSopenharmony_ci                    expected[0] = '[';
1573c5f01b2fSopenharmony_ci                    expected[1] = '$';
1574c5f01b2fSopenharmony_ci                    expected[2] = 'U';
1575c5f01b2fSopenharmony_ci                    expected[3] = '#';
1576c5f01b2fSopenharmony_ci                    expected[4] = 'I';
1577c5f01b2fSopenharmony_ci                    expected[5] = static_cast<std::uint8_t>(N & 0xFF);
1578c5f01b2fSopenharmony_ci                    expected[6] = static_cast<std::uint8_t>((N >> 8) & 0xFF);
1579c5f01b2fSopenharmony_ci
1580c5f01b2fSopenharmony_ci                    // compare result + size
1581c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, true);
1582c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1583c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 7);
1584c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1585c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1586c5f01b2fSopenharmony_ci
1587c5f01b2fSopenharmony_ci                    // roundtrip only works to an array of numbers
1588c5f01b2fSopenharmony_ci                    json j_out = s;
1589c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j_out);
1590c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j_out);
1591c5f01b2fSopenharmony_ci                }
1592c5f01b2fSopenharmony_ci            }
1593c5f01b2fSopenharmony_ci
1594c5f01b2fSopenharmony_ci            SECTION("N = 32768..65535")
1595c5f01b2fSopenharmony_ci            {
1596c5f01b2fSopenharmony_ci                for (std::size_t N :
1597c5f01b2fSopenharmony_ci                        {
1598c5f01b2fSopenharmony_ci                            32768u, 55555u, 65535u
1599c5f01b2fSopenharmony_ci                        })
1600c5f01b2fSopenharmony_ci                {
1601c5f01b2fSopenharmony_ci                    CAPTURE(N)
1602c5f01b2fSopenharmony_ci
1603c5f01b2fSopenharmony_ci                    // create JSON value with byte array containing of N * 'x'
1604c5f01b2fSopenharmony_ci                    const auto s = std::vector<std::uint8_t>(N, 'x');
1605c5f01b2fSopenharmony_ci                    json j = json::binary(s);
1606c5f01b2fSopenharmony_ci
1607c5f01b2fSopenharmony_ci                    // create expected byte vector
1608c5f01b2fSopenharmony_ci                    std::vector<std::uint8_t> expected(N + 7, 'x');
1609c5f01b2fSopenharmony_ci                    expected[0] = '[';
1610c5f01b2fSopenharmony_ci                    expected[1] = '$';
1611c5f01b2fSopenharmony_ci                    expected[2] = 'U';
1612c5f01b2fSopenharmony_ci                    expected[3] = '#';
1613c5f01b2fSopenharmony_ci                    expected[4] = 'u';
1614c5f01b2fSopenharmony_ci                    expected[5] = static_cast<std::uint8_t>(N & 0xFF);
1615c5f01b2fSopenharmony_ci                    expected[6] = static_cast<std::uint8_t>((N >> 8) & 0xFF);
1616c5f01b2fSopenharmony_ci
1617c5f01b2fSopenharmony_ci                    // compare result + size
1618c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, true);
1619c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1620c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 7);
1621c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1622c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1623c5f01b2fSopenharmony_ci
1624c5f01b2fSopenharmony_ci                    // roundtrip only works to an array of numbers
1625c5f01b2fSopenharmony_ci                    json j_out = s;
1626c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j_out);
1627c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j_out);
1628c5f01b2fSopenharmony_ci                }
1629c5f01b2fSopenharmony_ci            }
1630c5f01b2fSopenharmony_ci
1631c5f01b2fSopenharmony_ci            SECTION("N = 65536..2147483647")
1632c5f01b2fSopenharmony_ci            {
1633c5f01b2fSopenharmony_ci                for (std::size_t N :
1634c5f01b2fSopenharmony_ci                        {
1635c5f01b2fSopenharmony_ci                            65536u, 77777u, 1048576u
1636c5f01b2fSopenharmony_ci                        })
1637c5f01b2fSopenharmony_ci                {
1638c5f01b2fSopenharmony_ci                    CAPTURE(N)
1639c5f01b2fSopenharmony_ci
1640c5f01b2fSopenharmony_ci                    // create JSON value with byte array containing of N * 'x'
1641c5f01b2fSopenharmony_ci                    const auto s = std::vector<std::uint8_t>(N, 'x');
1642c5f01b2fSopenharmony_ci                    json j = json::binary(s);
1643c5f01b2fSopenharmony_ci
1644c5f01b2fSopenharmony_ci                    // create expected byte vector
1645c5f01b2fSopenharmony_ci                    std::vector<std::uint8_t> expected(N + 9, 'x');
1646c5f01b2fSopenharmony_ci                    expected[0] = '[';
1647c5f01b2fSopenharmony_ci                    expected[1] = '$';
1648c5f01b2fSopenharmony_ci                    expected[2] = 'U';
1649c5f01b2fSopenharmony_ci                    expected[3] = '#';
1650c5f01b2fSopenharmony_ci                    expected[4] = 'l';
1651c5f01b2fSopenharmony_ci                    expected[5] = static_cast<std::uint8_t>(N & 0xFF);
1652c5f01b2fSopenharmony_ci                    expected[6] = static_cast<std::uint8_t>((N >> 8) & 0xFF);
1653c5f01b2fSopenharmony_ci                    expected[7] = static_cast<std::uint8_t>((N >> 16) & 0xFF);
1654c5f01b2fSopenharmony_ci                    expected[8] = static_cast<std::uint8_t>((N >> 24) & 0xFF);
1655c5f01b2fSopenharmony_ci
1656c5f01b2fSopenharmony_ci                    // compare result + size
1657c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, true);
1658c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1659c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 9);
1660c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1661c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1662c5f01b2fSopenharmony_ci
1663c5f01b2fSopenharmony_ci                    // roundtrip only works to an array of numbers
1664c5f01b2fSopenharmony_ci                    json j_out = s;
1665c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j_out);
1666c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j_out);
1667c5f01b2fSopenharmony_ci                }
1668c5f01b2fSopenharmony_ci            }
1669c5f01b2fSopenharmony_ci
1670c5f01b2fSopenharmony_ci            SECTION("Other Serializations")
1671c5f01b2fSopenharmony_ci            {
1672c5f01b2fSopenharmony_ci                const std::size_t N = 10;
1673c5f01b2fSopenharmony_ci                const auto s = std::vector<std::uint8_t>(N, 'x');
1674c5f01b2fSopenharmony_ci                json j = json::binary(s);
1675c5f01b2fSopenharmony_ci
1676c5f01b2fSopenharmony_ci                SECTION("No Count No Type")
1677c5f01b2fSopenharmony_ci                {
1678c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected;
1679c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('['));
1680c5f01b2fSopenharmony_ci                    for (std::size_t i = 0; i < N; ++i)
1681c5f01b2fSopenharmony_ci                    {
1682c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<std::uint8_t>('U'));
1683c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<std::uint8_t>(0x78));
1684c5f01b2fSopenharmony_ci                    }
1685c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>(']'));
1686c5f01b2fSopenharmony_ci
1687c5f01b2fSopenharmony_ci                    // compare result + size
1688c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, false, false);
1689c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1690c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 12);
1691c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1692c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1693c5f01b2fSopenharmony_ci
1694c5f01b2fSopenharmony_ci                    // roundtrip only works to an array of numbers
1695c5f01b2fSopenharmony_ci                    json j_out = s;
1696c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j_out);
1697c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j_out);
1698c5f01b2fSopenharmony_ci                }
1699c5f01b2fSopenharmony_ci
1700c5f01b2fSopenharmony_ci                SECTION("Yes Count No Type")
1701c5f01b2fSopenharmony_ci                {
1702c5f01b2fSopenharmony_ci                    std::vector<std::uint8_t> expected;
1703c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('['));
1704c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('#'));
1705c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>('i'));
1706c5f01b2fSopenharmony_ci                    expected.push_back(static_cast<std::uint8_t>(N));
1707c5f01b2fSopenharmony_ci
1708c5f01b2fSopenharmony_ci                    for (size_t i = 0; i < N; ++i)
1709c5f01b2fSopenharmony_ci                    {
1710c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<std::uint8_t>('U'));
1711c5f01b2fSopenharmony_ci                        expected.push_back(static_cast<std::uint8_t>(0x78));
1712c5f01b2fSopenharmony_ci                    }
1713c5f01b2fSopenharmony_ci
1714c5f01b2fSopenharmony_ci                    // compare result + size
1715c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, false);
1716c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1717c5f01b2fSopenharmony_ci                    CHECK(result.size() == N + 14);
1718c5f01b2fSopenharmony_ci                    // check that no null byte is appended
1719c5f01b2fSopenharmony_ci                    CHECK(result.back() != '\x00');
1720c5f01b2fSopenharmony_ci
1721c5f01b2fSopenharmony_ci                    // roundtrip only works to an array of numbers
1722c5f01b2fSopenharmony_ci                    json j_out = s;
1723c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j_out);
1724c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j_out);
1725c5f01b2fSopenharmony_ci                }
1726c5f01b2fSopenharmony_ci            }
1727c5f01b2fSopenharmony_ci        }
1728c5f01b2fSopenharmony_ci        SECTION("array")
1729c5f01b2fSopenharmony_ci        {
1730c5f01b2fSopenharmony_ci            SECTION("empty")
1731c5f01b2fSopenharmony_ci            {
1732c5f01b2fSopenharmony_ci                SECTION("size=false type=false")
1733c5f01b2fSopenharmony_ci                {
1734c5f01b2fSopenharmony_ci                    json j = json::array();
1735c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', ']'};
1736c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1737c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1738c5f01b2fSopenharmony_ci
1739c5f01b2fSopenharmony_ci                    // roundtrip
1740c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1741c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1742c5f01b2fSopenharmony_ci                }
1743c5f01b2fSopenharmony_ci
1744c5f01b2fSopenharmony_ci                SECTION("size=true type=false")
1745c5f01b2fSopenharmony_ci                {
1746c5f01b2fSopenharmony_ci                    json j = json::array();
1747c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', '#', 'i', 0};
1748c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true);
1749c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1750c5f01b2fSopenharmony_ci
1751c5f01b2fSopenharmony_ci                    // roundtrip
1752c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1753c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1754c5f01b2fSopenharmony_ci                }
1755c5f01b2fSopenharmony_ci
1756c5f01b2fSopenharmony_ci                SECTION("size=true type=true")
1757c5f01b2fSopenharmony_ci                {
1758c5f01b2fSopenharmony_ci                    json j = json::array();
1759c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', '#', 'i', 0};
1760c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, true);
1761c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1762c5f01b2fSopenharmony_ci
1763c5f01b2fSopenharmony_ci                    // roundtrip
1764c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1765c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1766c5f01b2fSopenharmony_ci                }
1767c5f01b2fSopenharmony_ci            }
1768c5f01b2fSopenharmony_ci
1769c5f01b2fSopenharmony_ci            SECTION("[null]")
1770c5f01b2fSopenharmony_ci            {
1771c5f01b2fSopenharmony_ci                SECTION("size=false type=false")
1772c5f01b2fSopenharmony_ci                {
1773c5f01b2fSopenharmony_ci                    json j = {nullptr};
1774c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', 'Z', ']'};
1775c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1776c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1777c5f01b2fSopenharmony_ci
1778c5f01b2fSopenharmony_ci                    // roundtrip
1779c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1780c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1781c5f01b2fSopenharmony_ci                }
1782c5f01b2fSopenharmony_ci
1783c5f01b2fSopenharmony_ci                SECTION("size=true type=false")
1784c5f01b2fSopenharmony_ci                {
1785c5f01b2fSopenharmony_ci                    json j = {nullptr};
1786c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', '#', 'i', 1, 'Z'};
1787c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true);
1788c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1789c5f01b2fSopenharmony_ci
1790c5f01b2fSopenharmony_ci                    // roundtrip
1791c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1792c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1793c5f01b2fSopenharmony_ci                }
1794c5f01b2fSopenharmony_ci
1795c5f01b2fSopenharmony_ci                SECTION("size=true type=true")
1796c5f01b2fSopenharmony_ci                {
1797c5f01b2fSopenharmony_ci                    json j = {nullptr};
1798c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', '#', 'i', 1, 'Z'};
1799c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, true);
1800c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1801c5f01b2fSopenharmony_ci
1802c5f01b2fSopenharmony_ci                    // roundtrip
1803c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1804c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1805c5f01b2fSopenharmony_ci                }
1806c5f01b2fSopenharmony_ci            }
1807c5f01b2fSopenharmony_ci
1808c5f01b2fSopenharmony_ci            SECTION("[1,2,3,4,5]")
1809c5f01b2fSopenharmony_ci            {
1810c5f01b2fSopenharmony_ci                SECTION("size=false type=false")
1811c5f01b2fSopenharmony_ci                {
1812c5f01b2fSopenharmony_ci                    json j = json::parse("[1,2,3,4,5]");
1813c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', 'i', 1, 'i', 2, 'i', 3, 'i', 4, 'i', 5, ']'};
1814c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1815c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1816c5f01b2fSopenharmony_ci
1817c5f01b2fSopenharmony_ci                    // roundtrip
1818c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1819c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1820c5f01b2fSopenharmony_ci                }
1821c5f01b2fSopenharmony_ci
1822c5f01b2fSopenharmony_ci                SECTION("size=true type=false")
1823c5f01b2fSopenharmony_ci                {
1824c5f01b2fSopenharmony_ci                    json j = json::parse("[1,2,3,4,5]");
1825c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', '#', 'i', 5, 'i', 1, 'i', 2, 'i', 3, 'i', 4, 'i', 5};
1826c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true);
1827c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1828c5f01b2fSopenharmony_ci
1829c5f01b2fSopenharmony_ci                    // roundtrip
1830c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1831c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1832c5f01b2fSopenharmony_ci                }
1833c5f01b2fSopenharmony_ci
1834c5f01b2fSopenharmony_ci                SECTION("size=true type=true")
1835c5f01b2fSopenharmony_ci                {
1836c5f01b2fSopenharmony_ci                    json j = json::parse("[1,2,3,4,5]");
1837c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', '$', 'i', '#', 'i', 5, 1, 2, 3, 4, 5};
1838c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, true);
1839c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1840c5f01b2fSopenharmony_ci
1841c5f01b2fSopenharmony_ci                    // roundtrip
1842c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1843c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1844c5f01b2fSopenharmony_ci                }
1845c5f01b2fSopenharmony_ci            }
1846c5f01b2fSopenharmony_ci
1847c5f01b2fSopenharmony_ci            SECTION("[[[[]]]]")
1848c5f01b2fSopenharmony_ci            {
1849c5f01b2fSopenharmony_ci                SECTION("size=false type=false")
1850c5f01b2fSopenharmony_ci                {
1851c5f01b2fSopenharmony_ci                    json j = json::parse("[[[[]]]]");
1852c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', '[', '[', '[', ']', ']', ']', ']'};
1853c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1854c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1855c5f01b2fSopenharmony_ci
1856c5f01b2fSopenharmony_ci                    // roundtrip
1857c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1858c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1859c5f01b2fSopenharmony_ci                }
1860c5f01b2fSopenharmony_ci
1861c5f01b2fSopenharmony_ci                SECTION("size=true type=false")
1862c5f01b2fSopenharmony_ci                {
1863c5f01b2fSopenharmony_ci                    json j = json::parse("[[[[]]]]");
1864c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 0};
1865c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true);
1866c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1867c5f01b2fSopenharmony_ci
1868c5f01b2fSopenharmony_ci                    // roundtrip
1869c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1870c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1871c5f01b2fSopenharmony_ci                }
1872c5f01b2fSopenharmony_ci
1873c5f01b2fSopenharmony_ci                SECTION("size=true type=true")
1874c5f01b2fSopenharmony_ci                {
1875c5f01b2fSopenharmony_ci                    json j = json::parse("[[[[]]]]");
1876c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 0};
1877c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, true);
1878c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1879c5f01b2fSopenharmony_ci
1880c5f01b2fSopenharmony_ci                    // roundtrip
1881c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1882c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1883c5f01b2fSopenharmony_ci                }
1884c5f01b2fSopenharmony_ci            }
1885c5f01b2fSopenharmony_ci
1886c5f01b2fSopenharmony_ci            SECTION("array with int16_t elements")
1887c5f01b2fSopenharmony_ci            {
1888c5f01b2fSopenharmony_ci                SECTION("size=false type=false")
1889c5f01b2fSopenharmony_ci                {
1890c5f01b2fSopenharmony_ci                    json j(257, nullptr);
1891c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null
1892c5f01b2fSopenharmony_ci                    expected[0] = '['; // opening array
1893c5f01b2fSopenharmony_ci                    expected[258] = ']'; // closing array
1894c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1895c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1896c5f01b2fSopenharmony_ci
1897c5f01b2fSopenharmony_ci                    // roundtrip
1898c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1899c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1900c5f01b2fSopenharmony_ci                }
1901c5f01b2fSopenharmony_ci
1902c5f01b2fSopenharmony_ci                SECTION("size=true type=false")
1903c5f01b2fSopenharmony_ci                {
1904c5f01b2fSopenharmony_ci                    json j(257, nullptr);
1905c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(j.size() + 5, 'Z'); // all null
1906c5f01b2fSopenharmony_ci                    expected[0] = '['; // opening array
1907c5f01b2fSopenharmony_ci                    expected[1] = '#'; // array size
1908c5f01b2fSopenharmony_ci                    expected[2] = 'I'; // int16
1909c5f01b2fSopenharmony_ci                    expected[3] = 0x01; // 0x0101, first byte
1910c5f01b2fSopenharmony_ci                    expected[4] = 0x01; // 0x0101, second byte
1911c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true);
1912c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1913c5f01b2fSopenharmony_ci
1914c5f01b2fSopenharmony_ci                    // roundtrip
1915c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1916c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1917c5f01b2fSopenharmony_ci                }
1918c5f01b2fSopenharmony_ci            }
1919c5f01b2fSopenharmony_ci
1920c5f01b2fSopenharmony_ci            SECTION("array with uint16_t elements")
1921c5f01b2fSopenharmony_ci            {
1922c5f01b2fSopenharmony_ci                SECTION("size=false type=false")
1923c5f01b2fSopenharmony_ci                {
1924c5f01b2fSopenharmony_ci                    json j(32768, nullptr);
1925c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null
1926c5f01b2fSopenharmony_ci                    expected[0] = '['; // opening array
1927c5f01b2fSopenharmony_ci                    expected[32769] = ']'; // closing array
1928c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1929c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1930c5f01b2fSopenharmony_ci
1931c5f01b2fSopenharmony_ci                    // roundtrip
1932c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1933c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1934c5f01b2fSopenharmony_ci                }
1935c5f01b2fSopenharmony_ci
1936c5f01b2fSopenharmony_ci                SECTION("size=true type=false")
1937c5f01b2fSopenharmony_ci                {
1938c5f01b2fSopenharmony_ci                    json j(32768, nullptr);
1939c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(j.size() + 5, 'Z'); // all null
1940c5f01b2fSopenharmony_ci                    expected[0] = '['; // opening array
1941c5f01b2fSopenharmony_ci                    expected[1] = '#'; // array size
1942c5f01b2fSopenharmony_ci                    expected[2] = 'u'; // int16
1943c5f01b2fSopenharmony_ci                    expected[3] = 0x00; // 0x0101, first byte
1944c5f01b2fSopenharmony_ci                    expected[4] = 0x80; // 0x0101, second byte
1945c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true);
1946c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1947c5f01b2fSopenharmony_ci
1948c5f01b2fSopenharmony_ci                    // roundtrip
1949c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1950c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1951c5f01b2fSopenharmony_ci                }
1952c5f01b2fSopenharmony_ci            }
1953c5f01b2fSopenharmony_ci
1954c5f01b2fSopenharmony_ci            SECTION("array with int32_t elements")
1955c5f01b2fSopenharmony_ci            {
1956c5f01b2fSopenharmony_ci                SECTION("size=false type=false")
1957c5f01b2fSopenharmony_ci                {
1958c5f01b2fSopenharmony_ci                    json j(65793, nullptr);
1959c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(j.size() + 2, 'Z'); // all null
1960c5f01b2fSopenharmony_ci                    expected[0] = '['; // opening array
1961c5f01b2fSopenharmony_ci                    expected[65794] = ']'; // closing array
1962c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
1963c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1964c5f01b2fSopenharmony_ci
1965c5f01b2fSopenharmony_ci                    // roundtrip
1966c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1967c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1968c5f01b2fSopenharmony_ci                }
1969c5f01b2fSopenharmony_ci
1970c5f01b2fSopenharmony_ci                SECTION("size=true type=false")
1971c5f01b2fSopenharmony_ci                {
1972c5f01b2fSopenharmony_ci                    json j(65793, nullptr);
1973c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected(j.size() + 7, 'Z'); // all null
1974c5f01b2fSopenharmony_ci                    expected[0] = '['; // opening array
1975c5f01b2fSopenharmony_ci                    expected[1] = '#'; // array size
1976c5f01b2fSopenharmony_ci                    expected[2] = 'l'; // int32
1977c5f01b2fSopenharmony_ci                    expected[3] = 0x01; // 0x00010101, fourth byte
1978c5f01b2fSopenharmony_ci                    expected[4] = 0x01; // 0x00010101, third byte
1979c5f01b2fSopenharmony_ci                    expected[5] = 0x01; // 0x00010101, second byte
1980c5f01b2fSopenharmony_ci                    expected[6] = 0x00; // 0x00010101, first byte
1981c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true);
1982c5f01b2fSopenharmony_ci                    CHECK(result == expected);
1983c5f01b2fSopenharmony_ci
1984c5f01b2fSopenharmony_ci                    // roundtrip
1985c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
1986c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
1987c5f01b2fSopenharmony_ci                }
1988c5f01b2fSopenharmony_ci            }
1989c5f01b2fSopenharmony_ci        }
1990c5f01b2fSopenharmony_ci
1991c5f01b2fSopenharmony_ci        SECTION("object")
1992c5f01b2fSopenharmony_ci        {
1993c5f01b2fSopenharmony_ci            SECTION("empty")
1994c5f01b2fSopenharmony_ci            {
1995c5f01b2fSopenharmony_ci                SECTION("size=false type=false")
1996c5f01b2fSopenharmony_ci                {
1997c5f01b2fSopenharmony_ci                    json j = json::object();
1998c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'{', '}'};
1999c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
2000c5f01b2fSopenharmony_ci                    CHECK(result == expected);
2001c5f01b2fSopenharmony_ci
2002c5f01b2fSopenharmony_ci                    // roundtrip
2003c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
2004c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
2005c5f01b2fSopenharmony_ci                }
2006c5f01b2fSopenharmony_ci
2007c5f01b2fSopenharmony_ci                SECTION("size=true type=false")
2008c5f01b2fSopenharmony_ci                {
2009c5f01b2fSopenharmony_ci                    json j = json::object();
2010c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'{', '#', 'i', 0};
2011c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true);
2012c5f01b2fSopenharmony_ci                    CHECK(result == expected);
2013c5f01b2fSopenharmony_ci
2014c5f01b2fSopenharmony_ci                    // roundtrip
2015c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
2016c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
2017c5f01b2fSopenharmony_ci                }
2018c5f01b2fSopenharmony_ci
2019c5f01b2fSopenharmony_ci                SECTION("size=true type=true")
2020c5f01b2fSopenharmony_ci                {
2021c5f01b2fSopenharmony_ci                    json j = json::object();
2022c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'{', '#', 'i', 0};
2023c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, true);
2024c5f01b2fSopenharmony_ci                    CHECK(result == expected);
2025c5f01b2fSopenharmony_ci
2026c5f01b2fSopenharmony_ci                    // roundtrip
2027c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
2028c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
2029c5f01b2fSopenharmony_ci                }
2030c5f01b2fSopenharmony_ci            }
2031c5f01b2fSopenharmony_ci
2032c5f01b2fSopenharmony_ci            SECTION("{\"\":null}")
2033c5f01b2fSopenharmony_ci            {
2034c5f01b2fSopenharmony_ci                SECTION("size=false type=false")
2035c5f01b2fSopenharmony_ci                {
2036c5f01b2fSopenharmony_ci                    json j = {{"", nullptr}};
2037c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'{', 'i', 0, 'Z', '}'};
2038c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
2039c5f01b2fSopenharmony_ci                    CHECK(result == expected);
2040c5f01b2fSopenharmony_ci
2041c5f01b2fSopenharmony_ci                    // roundtrip
2042c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
2043c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
2044c5f01b2fSopenharmony_ci                }
2045c5f01b2fSopenharmony_ci
2046c5f01b2fSopenharmony_ci                SECTION("size=true type=false")
2047c5f01b2fSopenharmony_ci                {
2048c5f01b2fSopenharmony_ci                    json j = {{"", nullptr}};
2049c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected = {'{', '#', 'i', 1, 'i', 0, 'Z'};
2050c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true);
2051c5f01b2fSopenharmony_ci                    CHECK(result == expected);
2052c5f01b2fSopenharmony_ci
2053c5f01b2fSopenharmony_ci                    // roundtrip
2054c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
2055c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
2056c5f01b2fSopenharmony_ci                }
2057c5f01b2fSopenharmony_ci            }
2058c5f01b2fSopenharmony_ci
2059c5f01b2fSopenharmony_ci            SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
2060c5f01b2fSopenharmony_ci            {
2061c5f01b2fSopenharmony_ci                SECTION("size=false type=false")
2062c5f01b2fSopenharmony_ci                {
2063c5f01b2fSopenharmony_ci                    json j = json::parse(R"({"a": {"b": {"c": {}}}})");
2064c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected =
2065c5f01b2fSopenharmony_ci                    {
2066c5f01b2fSopenharmony_ci                        '{', 'i', 1, 'a', '{', 'i', 1, 'b', '{', 'i', 1, 'c', '{', '}', '}', '}', '}'
2067c5f01b2fSopenharmony_ci                    };
2068c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j);
2069c5f01b2fSopenharmony_ci                    CHECK(result == expected);
2070c5f01b2fSopenharmony_ci
2071c5f01b2fSopenharmony_ci                    // roundtrip
2072c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
2073c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
2074c5f01b2fSopenharmony_ci                }
2075c5f01b2fSopenharmony_ci
2076c5f01b2fSopenharmony_ci                SECTION("size=true type=false")
2077c5f01b2fSopenharmony_ci                {
2078c5f01b2fSopenharmony_ci                    json j = json::parse(R"({"a": {"b": {"c": {}}}})");
2079c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected =
2080c5f01b2fSopenharmony_ci                    {
2081c5f01b2fSopenharmony_ci                        '{', '#', 'i', 1, 'i', 1, 'a', '{', '#', 'i', 1, 'i', 1, 'b', '{', '#', 'i', 1, 'i', 1, 'c', '{', '#', 'i', 0
2082c5f01b2fSopenharmony_ci                    };
2083c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true);
2084c5f01b2fSopenharmony_ci                    CHECK(result == expected);
2085c5f01b2fSopenharmony_ci
2086c5f01b2fSopenharmony_ci                    // roundtrip
2087c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
2088c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
2089c5f01b2fSopenharmony_ci                }
2090c5f01b2fSopenharmony_ci
2091c5f01b2fSopenharmony_ci                SECTION("size=true type=true ignore object type marker")
2092c5f01b2fSopenharmony_ci                {
2093c5f01b2fSopenharmony_ci                    json j = json::parse(R"({"a": {"b": {"c": {}}}})");
2094c5f01b2fSopenharmony_ci                    std::vector<uint8_t> expected =
2095c5f01b2fSopenharmony_ci                    {
2096c5f01b2fSopenharmony_ci                        '{', '#', 'i', 1, 'i', 1, 'a', '{', '#', 'i', 1, 'i', 1, 'b', '{', '#', 'i', 1, 'i', 1, 'c', '{', '#', 'i', 0
2097c5f01b2fSopenharmony_ci                    };
2098c5f01b2fSopenharmony_ci                    const auto result = json::to_bjdata(j, true, true);
2099c5f01b2fSopenharmony_ci                    CHECK(result == expected);
2100c5f01b2fSopenharmony_ci
2101c5f01b2fSopenharmony_ci                    // roundtrip
2102c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result) == j);
2103c5f01b2fSopenharmony_ci                    CHECK(json::from_bjdata(result, true, false) == j);
2104c5f01b2fSopenharmony_ci                }
2105c5f01b2fSopenharmony_ci            }
2106c5f01b2fSopenharmony_ci        }
2107c5f01b2fSopenharmony_ci    }
2108c5f01b2fSopenharmony_ci
2109c5f01b2fSopenharmony_ci    SECTION("errors")
2110c5f01b2fSopenharmony_ci    {
2111c5f01b2fSopenharmony_ci        SECTION("strict mode")
2112c5f01b2fSopenharmony_ci        {
2113c5f01b2fSopenharmony_ci            std::vector<uint8_t> vec = {'Z', 'Z'};
2114c5f01b2fSopenharmony_ci            SECTION("non-strict mode")
2115c5f01b2fSopenharmony_ci            {
2116c5f01b2fSopenharmony_ci                const auto result = json::from_bjdata(vec, false);
2117c5f01b2fSopenharmony_ci                CHECK(result == json());
2118c5f01b2fSopenharmony_ci            }
2119c5f01b2fSopenharmony_ci
2120c5f01b2fSopenharmony_ci            SECTION("strict mode")
2121c5f01b2fSopenharmony_ci            {
2122c5f01b2fSopenharmony_ci                json _;
2123c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec),
2124c5f01b2fSopenharmony_ci                                     "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData value: expected end of input; last byte: 0x5A", json::parse_error&);
2125c5f01b2fSopenharmony_ci            }
2126c5f01b2fSopenharmony_ci        }
2127c5f01b2fSopenharmony_ci    }
2128c5f01b2fSopenharmony_ci
2129c5f01b2fSopenharmony_ci    SECTION("SAX aborts")
2130c5f01b2fSopenharmony_ci    {
2131c5f01b2fSopenharmony_ci        SECTION("start_array()")
2132c5f01b2fSopenharmony_ci        {
2133c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', 'T', 'F', ']'};
2134c5f01b2fSopenharmony_ci            SaxCountdown scp(0);
2135c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2136c5f01b2fSopenharmony_ci        }
2137c5f01b2fSopenharmony_ci
2138c5f01b2fSopenharmony_ci        SECTION("start_object()")
2139c5f01b2fSopenharmony_ci        {
2140c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'};
2141c5f01b2fSopenharmony_ci            SaxCountdown scp(0);
2142c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2143c5f01b2fSopenharmony_ci        }
2144c5f01b2fSopenharmony_ci
2145c5f01b2fSopenharmony_ci        SECTION("key() in object")
2146c5f01b2fSopenharmony_ci        {
2147c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'};
2148c5f01b2fSopenharmony_ci            SaxCountdown scp(1);
2149c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2150c5f01b2fSopenharmony_ci        }
2151c5f01b2fSopenharmony_ci
2152c5f01b2fSopenharmony_ci        SECTION("start_array(len)")
2153c5f01b2fSopenharmony_ci        {
2154c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '#', 'i', '2', 'T', 'F'};
2155c5f01b2fSopenharmony_ci            SaxCountdown scp(0);
2156c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2157c5f01b2fSopenharmony_ci        }
2158c5f01b2fSopenharmony_ci
2159c5f01b2fSopenharmony_ci        SECTION("start_object(len)")
2160c5f01b2fSopenharmony_ci        {
2161c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'{', '#', 'i', '1', 3, 'f', 'o', 'o', 'F'};
2162c5f01b2fSopenharmony_ci            SaxCountdown scp(0);
2163c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2164c5f01b2fSopenharmony_ci        }
2165c5f01b2fSopenharmony_ci
2166c5f01b2fSopenharmony_ci        SECTION("key() in object with length")
2167c5f01b2fSopenharmony_ci        {
2168c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'};
2169c5f01b2fSopenharmony_ci            SaxCountdown scp(1);
2170c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2171c5f01b2fSopenharmony_ci        }
2172c5f01b2fSopenharmony_ci
2173c5f01b2fSopenharmony_ci        SECTION("start_array() in ndarray _ArraySize_")
2174c5f01b2fSopenharmony_ci        {
2175c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 2, 1, 1, 2};
2176c5f01b2fSopenharmony_ci            SaxCountdown scp(2);
2177c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2178c5f01b2fSopenharmony_ci        }
2179c5f01b2fSopenharmony_ci
2180c5f01b2fSopenharmony_ci        SECTION("number_integer() in ndarray _ArraySize_")
2181c5f01b2fSopenharmony_ci        {
2182c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 1, 1, 2};
2183c5f01b2fSopenharmony_ci            SaxCountdown scp(3);
2184c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2185c5f01b2fSopenharmony_ci        }
2186c5f01b2fSopenharmony_ci
2187c5f01b2fSopenharmony_ci        SECTION("key() in ndarray _ArrayType_")
2188c5f01b2fSopenharmony_ci        {
2189c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4};
2190c5f01b2fSopenharmony_ci            SaxCountdown scp(6);
2191c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2192c5f01b2fSopenharmony_ci        }
2193c5f01b2fSopenharmony_ci
2194c5f01b2fSopenharmony_ci        SECTION("string() in ndarray _ArrayType_")
2195c5f01b2fSopenharmony_ci        {
2196c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4};
2197c5f01b2fSopenharmony_ci            SaxCountdown scp(7);
2198c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2199c5f01b2fSopenharmony_ci        }
2200c5f01b2fSopenharmony_ci
2201c5f01b2fSopenharmony_ci        SECTION("key() in ndarray _ArrayData_")
2202c5f01b2fSopenharmony_ci        {
2203c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4};
2204c5f01b2fSopenharmony_ci            SaxCountdown scp(8);
2205c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2206c5f01b2fSopenharmony_ci        }
2207c5f01b2fSopenharmony_ci
2208c5f01b2fSopenharmony_ci        SECTION("string() in ndarray _ArrayData_")
2209c5f01b2fSopenharmony_ci        {
2210c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4};
2211c5f01b2fSopenharmony_ci            SaxCountdown scp(9);
2212c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2213c5f01b2fSopenharmony_ci        }
2214c5f01b2fSopenharmony_ci
2215c5f01b2fSopenharmony_ci        SECTION("string() in ndarray _ArrayType_")
2216c5f01b2fSopenharmony_ci        {
2217c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 3, 2, 6, 5, 4, 3, 2, 1};
2218c5f01b2fSopenharmony_ci            SaxCountdown scp(11);
2219c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2220c5f01b2fSopenharmony_ci        }
2221c5f01b2fSopenharmony_ci
2222c5f01b2fSopenharmony_ci        SECTION("start_array() in ndarray _ArrayData_")
2223c5f01b2fSopenharmony_ci        {
2224c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '$', 'U', '#', '[', 'i', 2, 'i', 3, ']', 6, 5, 4, 3, 2, 1};
2225c5f01b2fSopenharmony_ci            SaxCountdown scp(13);
2226c5f01b2fSopenharmony_ci            CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata));
2227c5f01b2fSopenharmony_ci        }
2228c5f01b2fSopenharmony_ci    }
2229c5f01b2fSopenharmony_ci
2230c5f01b2fSopenharmony_ci    SECTION("parsing values")
2231c5f01b2fSopenharmony_ci    {
2232c5f01b2fSopenharmony_ci        SECTION("strings")
2233c5f01b2fSopenharmony_ci        {
2234c5f01b2fSopenharmony_ci            // create a single-character string for all number types
2235c5f01b2fSopenharmony_ci            std::vector<uint8_t> s_i = {'S', 'i', 1, 'a'};
2236c5f01b2fSopenharmony_ci            std::vector<uint8_t> s_U = {'S', 'U', 1, 'a'};
2237c5f01b2fSopenharmony_ci            std::vector<uint8_t> s_I = {'S', 'I', 1, 0, 'a'};
2238c5f01b2fSopenharmony_ci            std::vector<uint8_t> s_u = {'S', 'u', 1, 0, 'a'};
2239c5f01b2fSopenharmony_ci            std::vector<uint8_t> s_l = {'S', 'l', 1, 0, 0, 0, 'a'};
2240c5f01b2fSopenharmony_ci            std::vector<uint8_t> s_m = {'S', 'm', 1, 0, 0, 0, 'a'};
2241c5f01b2fSopenharmony_ci            std::vector<uint8_t> s_L = {'S', 'L', 1, 0, 0, 0, 0, 0, 0, 0, 'a'};
2242c5f01b2fSopenharmony_ci            std::vector<uint8_t> s_M = {'S', 'M', 1, 0, 0, 0, 0, 0, 0, 0, 'a'};
2243c5f01b2fSopenharmony_ci
2244c5f01b2fSopenharmony_ci            // check if string is parsed correctly to "a"
2245c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(s_i) == "a");
2246c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(s_U) == "a");
2247c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(s_I) == "a");
2248c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(s_u) == "a");
2249c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(s_l) == "a");
2250c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(s_m) == "a");
2251c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(s_L) == "a");
2252c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(s_M) == "a");
2253c5f01b2fSopenharmony_ci
2254c5f01b2fSopenharmony_ci            // roundtrip: output should be optimized
2255c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(json::from_bjdata(s_i)) == s_i);
2256c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(json::from_bjdata(s_U)) == s_i);
2257c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(json::from_bjdata(s_I)) == s_i);
2258c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(json::from_bjdata(s_u)) == s_i);
2259c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(json::from_bjdata(s_l)) == s_i);
2260c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(json::from_bjdata(s_m)) == s_i);
2261c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(json::from_bjdata(s_L)) == s_i);
2262c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(json::from_bjdata(s_M)) == s_i);
2263c5f01b2fSopenharmony_ci        }
2264c5f01b2fSopenharmony_ci
2265c5f01b2fSopenharmony_ci        SECTION("number")
2266c5f01b2fSopenharmony_ci        {
2267c5f01b2fSopenharmony_ci            SECTION("float")
2268c5f01b2fSopenharmony_ci            {
2269c5f01b2fSopenharmony_ci                // float32
2270c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_d = {'d', 0xd0, 0x0f, 0x49, 0x40};
2271c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_d) == 3.14159f);
2272c5f01b2fSopenharmony_ci
2273c5f01b2fSopenharmony_ci                // float64
2274c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_D = {'D', 0x6e, 0x86, 0x1b, 0xf0, 0xf9, 0x21, 0x09, 0x40};
2275c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_D) == 3.14159);
2276c5f01b2fSopenharmony_ci
2277c5f01b2fSopenharmony_ci                // float32 is serialized as float64 as the library does not support float32
2278c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_d)) == json::to_bjdata(3.14159f));
2279c5f01b2fSopenharmony_ci            }
2280c5f01b2fSopenharmony_ci        }
2281c5f01b2fSopenharmony_ci
2282c5f01b2fSopenharmony_ci        SECTION("array")
2283c5f01b2fSopenharmony_ci        {
2284c5f01b2fSopenharmony_ci            SECTION("optimized version (length only)")
2285c5f01b2fSopenharmony_ci            {
2286c5f01b2fSopenharmony_ci                // create vector with two elements of the same type
2287c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_TU = {'[', '#', 'U', 2, 'T', 'T'};
2288c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_T = {'[', '#', 'i', 2, 'T', 'T'};
2289c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_F = {'[', '#', 'i', 2, 'F', 'F'};
2290c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_Z = {'[', '#', 'i', 2, 'Z', 'Z'};
2291c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_i = {'[', '#', 'i', 2, 'i', 0x7F, 'i', 0x7F};
2292c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_U = {'[', '#', 'i', 2, 'U', 0xFF, 'U', 0xFF};
2293c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_I = {'[', '#', 'i', 2, 'I', 0xFF, 0x7F, 'I', 0xFF, 0x7F};
2294c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_u = {'[', '#', 'i', 2, 'u', 0x0F, 0xA7, 'u', 0x0F, 0xA7};
2295c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_l = {'[', '#', 'i', 2, 'l', 0xFF, 0xFF, 0xFF, 0x7F, 'l', 0xFF, 0xFF, 0xFF, 0x7F};
2296c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_m = {'[', '#', 'i', 2, 'm', 0xFF, 0xC9, 0x9A, 0xBB, 'm', 0xFF, 0xC9, 0x9A, 0xBB};
2297c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_L = {'[', '#', 'i', 2, 'L', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 'L', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F};
2298c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_M = {'[', '#', 'i', 2, 'M', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 'M', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D};
2299c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_D = {'[', '#', 'i', 2, 'D', 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 'D', 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40};
2300c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_S = {'[', '#', 'i', 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'};
2301c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_C = {'[', '#', 'i', 2, 'C', 'a', 'C', 'a'};
2302c5f01b2fSopenharmony_ci
2303c5f01b2fSopenharmony_ci                // check if vector is parsed correctly
2304c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_TU) == json({true, true}));
2305c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_T) == json({true, true}));
2306c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_F) == json({false, false}));
2307c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_Z) == json({nullptr, nullptr}));
2308c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_i) == json({127, 127}));
2309c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_U) == json({255, 255}));
2310c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_I) == json({32767, 32767}));
2311c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_u) == json({42767, 42767}));
2312c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_l) == json({2147483647, 2147483647}));
2313c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_m) == json({3147483647, 3147483647}));
2314c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_L) == json({9223372036854775807, 9223372036854775807}));
2315c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_M) == json({10223372036854775807ull, 10223372036854775807ull}));
2316c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_D) == json({3.1415926, 3.1415926}));
2317c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_S) == json({"a", "a"}));
2318c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_C) == json({"a", "a"}));
2319c5f01b2fSopenharmony_ci
2320c5f01b2fSopenharmony_ci                // roundtrip: output should be optimized
2321c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_T), true) == v_T);
2322c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_F), true) == v_F);
2323c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_Z), true) == v_Z);
2324c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_i), true) == v_i);
2325c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_U), true) == v_U);
2326c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_I), true) == v_I);
2327c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_u), true) == v_u);
2328c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_l), true) == v_l);
2329c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_m), true) == v_m);
2330c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_L), true) == v_L);
2331c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_M), true) == v_M);
2332c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_D), true) == v_D);
2333c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_S), true) == v_S);
2334c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_C), true) == v_S); // char is serialized to string
2335c5f01b2fSopenharmony_ci            }
2336c5f01b2fSopenharmony_ci
2337c5f01b2fSopenharmony_ci            SECTION("optimized version (type and length)")
2338c5f01b2fSopenharmony_ci            {
2339c5f01b2fSopenharmony_ci                // create vector with two elements of the same type
2340c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_i = {'[', '$', 'i', '#', 'i', 2, 0x7F, 0x7F};
2341c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_U = {'[', '$', 'U', '#', 'i', 2, 0xFF, 0xFF};
2342c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_I = {'[', '$', 'I', '#', 'i', 2, 0xFF, 0x7F, 0xFF, 0x7F};
2343c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_u = {'[', '$', 'u', '#', 'i', 2, 0x0F, 0xA7, 0x0F, 0xA7};
2344c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_l = {'[', '$', 'l', '#', 'i', 2, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F};
2345c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_m = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB};
2346c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_L = {'[', '$', 'L', '#', 'i', 2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F};
2347c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_M = {'[', '$', 'M', '#', 'i', 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D};
2348c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_D = {'[', '$', 'D', '#', 'i', 2, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40};
2349c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_S = {'[', '#', 'i', 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'};
2350c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_C = {'[', '$', 'C', '#', 'i', 2, 'a', 'a'};
2351c5f01b2fSopenharmony_ci
2352c5f01b2fSopenharmony_ci                // check if vector is parsed correctly
2353c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_i) == json({127, 127}));
2354c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_U) == json({255, 255}));
2355c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_I) == json({32767, 32767}));
2356c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_u) == json({42767, 42767}));
2357c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_l) == json({2147483647, 2147483647}));
2358c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_m) == json({3147483647, 3147483647}));
2359c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_L) == json({9223372036854775807, 9223372036854775807}));
2360c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_M) == json({10223372036854775807ull, 10223372036854775807ull}));
2361c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_D) == json({3.1415926, 3.1415926}));
2362c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_S) == json({"a", "a"}));
2363c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_C) == json({"a", "a"}));
2364c5f01b2fSopenharmony_ci
2365c5f01b2fSopenharmony_ci                // roundtrip: output should be optimized
2366c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_empty = {'[', '#', 'i', 0};
2367c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_i), true, true) == v_i);
2368c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_U), true, true) == v_U);
2369c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_I), true, true) == v_I);
2370c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_u), true, true) == v_u);
2371c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_l), true, true) == v_l);
2372c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_m), true, true) == v_m);
2373c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_L), true, true) == v_L);
2374c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_M), true, true) == v_M);
2375c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_D), true, true) == v_D);
2376c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_S), true, true) == v_S);
2377c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_C), true, true) == v_S); // char is serialized to string
2378c5f01b2fSopenharmony_ci            }
2379c5f01b2fSopenharmony_ci
2380c5f01b2fSopenharmony_ci            SECTION("optimized ndarray (type and vector-size as optimized 1D array)")
2381c5f01b2fSopenharmony_ci            {
2382c5f01b2fSopenharmony_ci                // create vector with two elements of the same type
2383c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_0 = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 1, 0};
2384c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_1 = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 1, 2, 0x7F, 0x7F};
2385c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_i = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0x7F, 0x7F};
2386c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_U = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF};
2387c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_I = {'[', '$', 'I', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0x7F, 0xFF, 0x7F};
2388c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_u = {'[', '$', 'u', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0x0F, 0xA7, 0x0F, 0xA7};
2389c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_l = {'[', '$', 'l', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F};
2390c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_m = {'[', '$', 'm', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB};
2391c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_L = {'[', '$', 'L', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F};
2392c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_M = {'[', '$', 'M', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D};
2393c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_D = {'[', '$', 'D', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40};
2394c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_S = {'[', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'};
2395c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_C = {'[', '$', 'C', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 'a', 'a'};
2396c5f01b2fSopenharmony_ci
2397c5f01b2fSopenharmony_ci                // check if vector is parsed correctly
2398c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_0) == json::array());
2399c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_1) == json({127, 127}));
2400c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_i) == json({127, 127}));
2401c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_U) == json({255, 255}));
2402c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_I) == json({32767, 32767}));
2403c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_u) == json({42767, 42767}));
2404c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_l) == json({2147483647, 2147483647}));
2405c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_m) == json({3147483647, 3147483647}));
2406c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_L) == json({9223372036854775807, 9223372036854775807}));
2407c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_M) == json({10223372036854775807ull, 10223372036854775807ull}));
2408c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_D) == json({3.1415926, 3.1415926}));
2409c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_S) == json({"a", "a"}));
2410c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_C) == json({"a", "a"}));
2411c5f01b2fSopenharmony_ci            }
2412c5f01b2fSopenharmony_ci
2413c5f01b2fSopenharmony_ci            SECTION("optimized ndarray (type and vector-size ndarray with JData annotations)")
2414c5f01b2fSopenharmony_ci            {
2415c5f01b2fSopenharmony_ci                // create vector with 0, 1, 2 elements of the same type
2416c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_e = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 1, 0xFE, 0xFF};
2417c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_U = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
2418c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_i = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
2419c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_u = {'[', '$', 'u', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00};
2420c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_I = {'[', '$', 'I', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00};
2421c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_m = {'[', '$', 'm', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00};
2422c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_l = {'[', '$', 'l', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00};
2423c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_M = {'[', '$', 'M', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2424c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_L = {'[', '$', 'L', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2425c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_d = {'[', '$', 'd', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0xA0, 0x40, 0x00, 0x00, 0xC0, 0x40};
2426c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_D = {'[', '$', 'D', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40};
2427c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_C = {'[', '$', 'C', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 'a', 'b', 'c', 'd', 'e', 'f'};
2428c5f01b2fSopenharmony_ci
2429c5f01b2fSopenharmony_ci                // check if vector is parsed correctly
2430c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_e) == json({{"_ArrayData_", {254, 255}}, {"_ArraySize_", {2, 1}}, {"_ArrayType_", "uint8"}}));
2431c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_U) == json({{"_ArrayData_", {1, 2, 3, 4, 5, 6}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "uint8"}}));
2432c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_i) == json({{"_ArrayData_", {1, 2, 3, 4, 5, 6}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "int8"}}));
2433c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_i) == json({{"_ArrayData_", {1, 2, 3, 4, 5, 6}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "int8"}}));
2434c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_u) == json({{"_ArrayData_", {1, 2, 3, 4, 5, 6}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "uint16"}}));
2435c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_I) == json({{"_ArrayData_", {1, 2, 3, 4, 5, 6}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "int16"}}));
2436c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_m) == json({{"_ArrayData_", {1, 2, 3, 4, 5, 6}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "uint32"}}));
2437c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_l) == json({{"_ArrayData_", {1, 2, 3, 4, 5, 6}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "int32"}}));
2438c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_M) == json({{"_ArrayData_", {1, 2, 3, 4, 5, 6}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "uint64"}}));
2439c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_L) == json({{"_ArrayData_", {1, 2, 3, 4, 5, 6}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "int64"}}));
2440c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_d) == json({{"_ArrayData_", {1.f, 2.f, 3.f, 4.f, 5.f, 6.f}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "single"}}));
2441c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_D) == json({{"_ArrayData_", {1., 2., 3., 4., 5., 6.}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "double"}}));
2442c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_C) == json({{"_ArrayData_", {'a', 'b', 'c', 'd', 'e', 'f'}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "char"}}));
2443c5f01b2fSopenharmony_ci
2444c5f01b2fSopenharmony_ci                // roundtrip: output should be optimized
2445c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_e), true, true) == v_e);
2446c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_U), true, true) == v_U);
2447c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_i), true, true) == v_i);
2448c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_u), true, true) == v_u);
2449c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_I), true, true) == v_I);
2450c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_m), true, true) == v_m);
2451c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_l), true, true) == v_l);
2452c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_M), true, true) == v_M);
2453c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_L), true, true) == v_L);
2454c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_d), true, true) == v_d);
2455c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_D), true, true) == v_D);
2456c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(json::from_bjdata(v_C), true, true) == v_C);
2457c5f01b2fSopenharmony_ci            }
2458c5f01b2fSopenharmony_ci
2459c5f01b2fSopenharmony_ci            SECTION("optimized ndarray (type and vector-size as 1D array)")
2460c5f01b2fSopenharmony_ci            {
2461c5f01b2fSopenharmony_ci                // create vector with two elements of the same type
2462c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_0 = {'[', '$', 'i', '#', '[', ']'};
2463c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_E = {'[', '$', 'i', '#', '[', 'i', 2, 'i', 0, ']'};
2464c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_i = {'[', '$', 'i', '#', '[', 'i', 1, 'i', 2, ']', 0x7F, 0x7F};
2465c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_U = {'[', '$', 'U', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF};
2466c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_I = {'[', '$', 'I', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0x7F, 0xFF, 0x7F};
2467c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_u = {'[', '$', 'u', '#', '[', 'i', 1, 'i', 2, ']', 0x0F, 0xA7, 0x0F, 0xA7};
2468c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_l = {'[', '$', 'l', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F};
2469c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_m = {'[', '$', 'm', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB};
2470c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_L = {'[', '$', 'L', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F};
2471c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_M = {'[', '$', 'M', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D};
2472c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_D = {'[', '$', 'D', '#', '[', 'i', 1, 'i', 2, ']', 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40};
2473c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_S = {'[', '#', '[', 'i', 1, 'i', 2, ']', 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'};
2474c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_C = {'[', '$', 'C', '#', '[', 'i', 1, 'i', 2, ']', 'a', 'a'};
2475c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_R = {'[', '#', '[', 'i', 2, ']', 'i', 6, 'U', 7};
2476c5f01b2fSopenharmony_ci
2477c5f01b2fSopenharmony_ci                // check if vector is parsed correctly
2478c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_0) == json::array());
2479c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_E) == json::array());
2480c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_i) == json({127, 127}));
2481c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_U) == json({255, 255}));
2482c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_I) == json({32767, 32767}));
2483c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_u) == json({42767, 42767}));
2484c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_l) == json({2147483647, 2147483647}));
2485c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_m) == json({3147483647, 3147483647}));
2486c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_L) == json({9223372036854775807, 9223372036854775807}));
2487c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_M) == json({10223372036854775807ull, 10223372036854775807ull}));
2488c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_D) == json({3.1415926, 3.1415926}));
2489c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_S) == json({"a", "a"}));
2490c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_C) == json({"a", "a"}));
2491c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_R) == json({6, 7}));
2492c5f01b2fSopenharmony_ci            }
2493c5f01b2fSopenharmony_ci
2494c5f01b2fSopenharmony_ci            SECTION("optimized ndarray (type and vector-size as size-optimized array)")
2495c5f01b2fSopenharmony_ci            {
2496c5f01b2fSopenharmony_ci                // create vector with two elements of the same type
2497c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_i = {'[', '$', 'i', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0x7F, 0x7F};
2498c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_U = {'[', '$', 'U', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF};
2499c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_I = {'[', '$', 'I', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0x7F, 0xFF, 0x7F};
2500c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_u = {'[', '$', 'u', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0x0F, 0xA7, 0x0F, 0xA7};
2501c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_l = {'[', '$', 'l', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F};
2502c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_m = {'[', '$', 'm', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB};
2503c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_L = {'[', '$', 'L', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F};
2504c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_M = {'[', '$', 'M', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D};
2505c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_D = {'[', '$', 'D', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40};
2506c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_S = {'[', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'};
2507c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_C = {'[', '$', 'C', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 'a', 'a'};
2508c5f01b2fSopenharmony_ci
2509c5f01b2fSopenharmony_ci                // check if vector is parsed correctly
2510c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_i) == json({127, 127}));
2511c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_U) == json({255, 255}));
2512c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_I) == json({32767, 32767}));
2513c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_u) == json({42767, 42767}));
2514c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_l) == json({2147483647, 2147483647}));
2515c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_m) == json({3147483647, 3147483647}));
2516c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_L) == json({9223372036854775807, 9223372036854775807}));
2517c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_M) == json({10223372036854775807ull, 10223372036854775807ull}));
2518c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_D) == json({3.1415926, 3.1415926}));
2519c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_S) == json({"a", "a"}));
2520c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_C) == json({"a", "a"}));
2521c5f01b2fSopenharmony_ci            }
2522c5f01b2fSopenharmony_ci
2523c5f01b2fSopenharmony_ci            SECTION("invalid ndarray annotations remains as object")
2524c5f01b2fSopenharmony_ci            {
2525c5f01b2fSopenharmony_ci                // check if invalid ND array annotations stay as object
2526c5f01b2fSopenharmony_ci                json j_type = json({{"_ArrayData_", {1, 2, 3, 4, 5, 6}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "invalidtype"}});
2527c5f01b2fSopenharmony_ci                json j_size = json({{"_ArrayData_", {1, 2, 3, 4, 5}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "uint8"}});
2528c5f01b2fSopenharmony_ci
2529c5f01b2fSopenharmony_ci                // roundtrip: output should stay as object
2530c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(json::to_bjdata(j_type), true, true) == j_type);
2531c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(json::to_bjdata(j_size), true, true) == j_size);
2532c5f01b2fSopenharmony_ci            }
2533c5f01b2fSopenharmony_ci        }
2534c5f01b2fSopenharmony_ci    }
2535c5f01b2fSopenharmony_ci
2536c5f01b2fSopenharmony_ci    SECTION("parse errors")
2537c5f01b2fSopenharmony_ci    {
2538c5f01b2fSopenharmony_ci        SECTION("empty byte vector")
2539c5f01b2fSopenharmony_ci        {
2540c5f01b2fSopenharmony_ci            json _;
2541c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(std::vector<uint8_t>()),
2542c5f01b2fSopenharmony_ci                                 "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2543c5f01b2fSopenharmony_ci        }
2544c5f01b2fSopenharmony_ci
2545c5f01b2fSopenharmony_ci        SECTION("char")
2546c5f01b2fSopenharmony_ci        {
2547c5f01b2fSopenharmony_ci            SECTION("eof after C byte")
2548c5f01b2fSopenharmony_ci            {
2549c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'C'};
2550c5f01b2fSopenharmony_ci                json _;
2551c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData char: unexpected end of input", json::parse_error&);
2552c5f01b2fSopenharmony_ci            }
2553c5f01b2fSopenharmony_ci
2554c5f01b2fSopenharmony_ci            SECTION("byte out of range")
2555c5f01b2fSopenharmony_ci            {
2556c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'C', 130};
2557c5f01b2fSopenharmony_ci                json _;
2558c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH(_ = json::from_bjdata(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing BJData char: byte after 'C' must be in range 0x00..0x7F; last byte: 0x82");
2559c5f01b2fSopenharmony_ci            }
2560c5f01b2fSopenharmony_ci        }
2561c5f01b2fSopenharmony_ci
2562c5f01b2fSopenharmony_ci        SECTION("strings")
2563c5f01b2fSopenharmony_ci        {
2564c5f01b2fSopenharmony_ci            SECTION("eof after S byte")
2565c5f01b2fSopenharmony_ci            {
2566c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'S'};
2567c5f01b2fSopenharmony_ci                json _;
2568c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2569c5f01b2fSopenharmony_ci            }
2570c5f01b2fSopenharmony_ci
2571c5f01b2fSopenharmony_ci            SECTION("invalid byte")
2572c5f01b2fSopenharmony_ci            {
2573c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'S', '1', 'a'};
2574c5f01b2fSopenharmony_ci                json _;
2575c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing BJData string: expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x31", json::parse_error&);
2576c5f01b2fSopenharmony_ci            }
2577c5f01b2fSopenharmony_ci
2578c5f01b2fSopenharmony_ci            SECTION("parse bjdata markers in ubjson")
2579c5f01b2fSopenharmony_ci            {
2580c5f01b2fSopenharmony_ci                // create a single-character string for all number types
2581c5f01b2fSopenharmony_ci                std::vector<uint8_t> s_u = {'S', 'u', 1, 0, 'a'};
2582c5f01b2fSopenharmony_ci                std::vector<uint8_t> s_m = {'S', 'm', 1, 0, 0, 0, 'a'};
2583c5f01b2fSopenharmony_ci                std::vector<uint8_t> s_M = {'S', 'M', 1, 0, 0, 0, 0, 0, 0, 0, 'a'};
2584c5f01b2fSopenharmony_ci
2585c5f01b2fSopenharmony_ci                json _;
2586c5f01b2fSopenharmony_ci                // check if string is parsed correctly to "a"
2587c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_ubjson(s_u), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON string: expected length type specification (U, i, I, l, L); last byte: 0x75", json::parse_error&);
2588c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_ubjson(s_m), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON string: expected length type specification (U, i, I, l, L); last byte: 0x6D", json::parse_error&);
2589c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_ubjson(s_M), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON string: expected length type specification (U, i, I, l, L); last byte: 0x4D", json::parse_error&);
2590c5f01b2fSopenharmony_ci            }
2591c5f01b2fSopenharmony_ci        }
2592c5f01b2fSopenharmony_ci
2593c5f01b2fSopenharmony_ci        SECTION("array")
2594c5f01b2fSopenharmony_ci        {
2595c5f01b2fSopenharmony_ci            SECTION("optimized array: no size following type")
2596c5f01b2fSopenharmony_ci            {
2597c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'[', '$', 'i', 2};
2598c5f01b2fSopenharmony_ci                json _;
2599c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing BJData size: expected '#' after type information; last byte: 0x02", json::parse_error&);
2600c5f01b2fSopenharmony_ci            }
2601c5f01b2fSopenharmony_ci
2602c5f01b2fSopenharmony_ci            SECTION("optimized array: negative size")
2603c5f01b2fSopenharmony_ci            {
2604c5f01b2fSopenharmony_ci                std::vector<uint8_t> v1 = {'[', '#', 'i', 0xF1};
2605c5f01b2fSopenharmony_ci                std::vector<uint8_t> v2 = {'[', '$', 'I', '#', 'i', 0xF2};
2606c5f01b2fSopenharmony_ci                std::vector<uint8_t> v3 = {'[', '$', 'I', '#', '[', 'i', 0xF4, 'i', 0x02, ']'};
2607c5f01b2fSopenharmony_ci                std::vector<uint8_t> v4 = {'[', '$', 0xF6, '#', 'i', 0xF7};
2608c5f01b2fSopenharmony_ci                std::vector<uint8_t> v5 = {'[', '$', 'I', '#', '[', 'i', 0xF5, 'i', 0xF1, ']'};
2609c5f01b2fSopenharmony_ci                std::vector<uint8_t> v6 = {'[', '#', '[', 'i', 0xF3, 'i', 0x02, ']'};
2610c5f01b2fSopenharmony_ci
2611c5f01b2fSopenharmony_ci                std::vector<uint8_t> vI = {'[', '#', 'I', 0x00, 0xF1};
2612c5f01b2fSopenharmony_ci                std::vector<uint8_t> vl = {'[', '#', 'l', 0x00, 0x00, 0x00, 0xF2};
2613c5f01b2fSopenharmony_ci                std::vector<uint8_t> vL = {'[', '#', 'L', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF3};
2614c5f01b2fSopenharmony_ci                std::vector<uint8_t> vM = {'[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']'};
2615c5f01b2fSopenharmony_ci                std::vector<uint8_t> vMX = {'[', '$', 'U', '#', '[', 'M', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 'U', 0x01, ']'};
2616c5f01b2fSopenharmony_ci
2617c5f01b2fSopenharmony_ci                json _;
2618c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v1), "[json.exception.parse_error.113] parse error at byte 4: syntax error while parsing BJData size: count in an optimized container must be positive", json::parse_error&);
2619c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v1, true, false).is_discarded());
2620c5f01b2fSopenharmony_ci
2621c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v2), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: count in an optimized container must be positive", json::parse_error&);
2622c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v2, true, false).is_discarded());
2623c5f01b2fSopenharmony_ci
2624c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v3), "[json.exception.parse_error.113] parse error at byte 7: syntax error while parsing BJData size: count in an optimized container must be positive", json::parse_error&);
2625c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v3, true, false).is_discarded());
2626c5f01b2fSopenharmony_ci
2627c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v4), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: count in an optimized container must be positive", json::parse_error&);
2628c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v4, true, false).is_discarded());
2629c5f01b2fSopenharmony_ci
2630c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v5), "[json.exception.parse_error.113] parse error at byte 7: syntax error while parsing BJData size: count in an optimized container must be positive", json::parse_error&);
2631c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v5, true, false).is_discarded());
2632c5f01b2fSopenharmony_ci
2633c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v6), "[json.exception.parse_error.113] parse error at byte 5: syntax error while parsing BJData size: count in an optimized container must be positive", json::parse_error&);
2634c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v6, true, false).is_discarded());
2635c5f01b2fSopenharmony_ci
2636c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vI), "[json.exception.parse_error.113] parse error at byte 5: syntax error while parsing BJData size: count in an optimized container must be positive", json::parse_error&);
2637c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(vI, true, false).is_discarded());
2638c5f01b2fSopenharmony_ci
2639c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vl), "[json.exception.parse_error.113] parse error at byte 7: syntax error while parsing BJData size: count in an optimized container must be positive", json::parse_error&);
2640c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(vl, true, false).is_discarded());
2641c5f01b2fSopenharmony_ci
2642c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL), "[json.exception.parse_error.113] parse error at byte 11: syntax error while parsing BJData size: count in an optimized container must be positive", json::parse_error&);
2643c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(vL, true, false).is_discarded());
2644c5f01b2fSopenharmony_ci
2645c5f01b2fSopenharmony_ci#if SIZE_MAX != 0xffffffff
2646c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.out_of_range.408] syntax error while parsing BJData size: excessive ndarray size caused overflow", json::out_of_range&);
2647c5f01b2fSopenharmony_ci#else
2648c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
2649c5f01b2fSopenharmony_ci#endif
2650c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(vM, true, false).is_discarded());
2651c5f01b2fSopenharmony_ci
2652c5f01b2fSopenharmony_ci#if SIZE_MAX != 0xffffffff
2653c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vMX), "[json.exception.out_of_range.408] syntax error while parsing BJData size: excessive ndarray size caused overflow", json::out_of_range&);
2654c5f01b2fSopenharmony_ci#else
2655c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vMX), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
2656c5f01b2fSopenharmony_ci#endif
2657c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(vMX, true, false).is_discarded());
2658c5f01b2fSopenharmony_ci            }
2659c5f01b2fSopenharmony_ci
2660c5f01b2fSopenharmony_ci            SECTION("optimized array: integer value overflow")
2661c5f01b2fSopenharmony_ci            {
2662c5f01b2fSopenharmony_ci                std::vector<uint8_t> vL = {'[', '#', 'L', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F};
2663c5f01b2fSopenharmony_ci                std::vector<uint8_t> vM = {'[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']'};
2664c5f01b2fSopenharmony_ci
2665c5f01b2fSopenharmony_ci                json _;
2666c5f01b2fSopenharmony_ci#if SIZE_MAX == 0xffffffff
2667c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
2668c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(vL, true, false).is_discarded());
2669c5f01b2fSopenharmony_ci#endif
2670c5f01b2fSopenharmony_ci
2671c5f01b2fSopenharmony_ci#if SIZE_MAX == 0xffffffff
2672c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
2673c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(vM, true, false).is_discarded());
2674c5f01b2fSopenharmony_ci#endif
2675c5f01b2fSopenharmony_ci            }
2676c5f01b2fSopenharmony_ci
2677c5f01b2fSopenharmony_ci            SECTION("do not accept NTFZ markers in ndarray optimized type (with count)")
2678c5f01b2fSopenharmony_ci            {
2679c5f01b2fSopenharmony_ci                json _;
2680c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_N = {'[', '$', 'N', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2};
2681c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_T = {'[', '$', 'T', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2};
2682c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_F = {'[', '$', 'F', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2};
2683c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_Z = {'[', '$', 'Z', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2};
2684c5f01b2fSopenharmony_ci
2685c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v_N), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x4E is not a permitted optimized array type", json::parse_error&);
2686c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_N, true, false).is_discarded());
2687c5f01b2fSopenharmony_ci
2688c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v_T), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x54 is not a permitted optimized array type", json::parse_error&);
2689c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_T, true, false).is_discarded());
2690c5f01b2fSopenharmony_ci
2691c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v_F), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x46 is not a permitted optimized array type", json::parse_error&);
2692c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_F, true, false).is_discarded());
2693c5f01b2fSopenharmony_ci
2694c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v_Z), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x5A is not a permitted optimized array type", json::parse_error&);
2695c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_Z, true, false).is_discarded());
2696c5f01b2fSopenharmony_ci            }
2697c5f01b2fSopenharmony_ci
2698c5f01b2fSopenharmony_ci            SECTION("do not accept NTFZ markers in ndarray optimized type (without count)")
2699c5f01b2fSopenharmony_ci            {
2700c5f01b2fSopenharmony_ci                json _;
2701c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_N = {'[', '$', 'N', '#', '[', 'i', 1, 'i', 2, ']'};
2702c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_T = {'[', '$', 'T', '#', '[', 'i', 1, 'i', 2, ']'};
2703c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_F = {'[', '$', 'F', '#', '[', 'i', 1, 'i', 2, ']'};
2704c5f01b2fSopenharmony_ci                std::vector<uint8_t> v_Z = {'[', '$', 'Z', '#', '[', 'i', 1, 'i', 2, ']'};
2705c5f01b2fSopenharmony_ci
2706c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v_N), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x4E is not a permitted optimized array type", json::parse_error&);
2707c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_N, true, false).is_discarded());
2708c5f01b2fSopenharmony_ci
2709c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v_T), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x54 is not a permitted optimized array type", json::parse_error&);
2710c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_T, true, false).is_discarded());
2711c5f01b2fSopenharmony_ci
2712c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v_F), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x46 is not a permitted optimized array type", json::parse_error&);
2713c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_F, true, false).is_discarded());
2714c5f01b2fSopenharmony_ci
2715c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v_Z), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x5A is not a permitted optimized array type", json::parse_error&);
2716c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v_Z, true, false).is_discarded());
2717c5f01b2fSopenharmony_ci            }
2718c5f01b2fSopenharmony_ci        }
2719c5f01b2fSopenharmony_ci
2720c5f01b2fSopenharmony_ci        SECTION("strings")
2721c5f01b2fSopenharmony_ci        {
2722c5f01b2fSopenharmony_ci            std::vector<uint8_t> vS = {'S'};
2723c5f01b2fSopenharmony_ci            json _;
2724c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vS), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2725c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vS, true, false).is_discarded());
2726c5f01b2fSopenharmony_ci
2727c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'S', 'i', '2', 'a'};
2728c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing BJData string: unexpected end of input", json::parse_error&);
2729c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v, true, false).is_discarded());
2730c5f01b2fSopenharmony_ci
2731c5f01b2fSopenharmony_ci            std::vector<uint8_t> vC = {'C'};
2732c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vC), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData char: unexpected end of input", json::parse_error&);
2733c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vC, true, false).is_discarded());
2734c5f01b2fSopenharmony_ci        }
2735c5f01b2fSopenharmony_ci
2736c5f01b2fSopenharmony_ci        SECTION("sizes")
2737c5f01b2fSopenharmony_ci        {
2738c5f01b2fSopenharmony_ci            std::vector<uint8_t> vU = {'[', '#', 'U'};
2739c5f01b2fSopenharmony_ci            json _;
2740c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vU), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2741c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vU, true, false).is_discarded());
2742c5f01b2fSopenharmony_ci
2743c5f01b2fSopenharmony_ci            std::vector<uint8_t> vi = {'[', '#', 'i'};
2744c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2745c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vi, true, false).is_discarded());
2746c5f01b2fSopenharmony_ci
2747c5f01b2fSopenharmony_ci            std::vector<uint8_t> vI = {'[', '#', 'I'};
2748c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vI), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2749c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vI, true, false).is_discarded());
2750c5f01b2fSopenharmony_ci
2751c5f01b2fSopenharmony_ci            std::vector<uint8_t> vu = {'[', '#', 'u'};
2752c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vu), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2753c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vu, true, false).is_discarded());
2754c5f01b2fSopenharmony_ci
2755c5f01b2fSopenharmony_ci            std::vector<uint8_t> vl = {'[', '#', 'l'};
2756c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vl), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2757c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vl, true, false).is_discarded());
2758c5f01b2fSopenharmony_ci
2759c5f01b2fSopenharmony_ci            std::vector<uint8_t> vm = {'[', '#', 'm'};
2760c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vm), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2761c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vm, true, false).is_discarded());
2762c5f01b2fSopenharmony_ci
2763c5f01b2fSopenharmony_ci            std::vector<uint8_t> vL = {'[', '#', 'L'};
2764c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2765c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vL, true, false).is_discarded());
2766c5f01b2fSopenharmony_ci
2767c5f01b2fSopenharmony_ci            std::vector<uint8_t> vM = {'[', '#', 'M'};
2768c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2769c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vM, true, false).is_discarded());
2770c5f01b2fSopenharmony_ci
2771c5f01b2fSopenharmony_ci            std::vector<uint8_t> v0 = {'[', '#', 'T', ']'};
2772c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH(_ = json::from_bjdata(v0), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x54");
2773c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v0, true, false).is_discarded());
2774c5f01b2fSopenharmony_ci        }
2775c5f01b2fSopenharmony_ci
2776c5f01b2fSopenharmony_ci        SECTION("parse bjdata markers as array size in ubjson")
2777c5f01b2fSopenharmony_ci        {
2778c5f01b2fSopenharmony_ci            json _;
2779c5f01b2fSopenharmony_ci            std::vector<uint8_t> vu = {'[', '#', 'u'};
2780c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vu), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x75", json::parse_error&);
2781c5f01b2fSopenharmony_ci            CHECK(json::from_ubjson(vu, true, false).is_discarded());
2782c5f01b2fSopenharmony_ci
2783c5f01b2fSopenharmony_ci            std::vector<uint8_t> vm = {'[', '#', 'm'};
2784c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vm), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x6D", json::parse_error&);
2785c5f01b2fSopenharmony_ci            CHECK(json::from_ubjson(vm, true, false).is_discarded());
2786c5f01b2fSopenharmony_ci
2787c5f01b2fSopenharmony_ci            std::vector<uint8_t> vM = {'[', '#', 'M'};
2788c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vM), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x4D", json::parse_error&);
2789c5f01b2fSopenharmony_ci            CHECK(json::from_ubjson(vM, true, false).is_discarded());
2790c5f01b2fSopenharmony_ci
2791c5f01b2fSopenharmony_ci            std::vector<uint8_t> v0 = {'[', '#', '['};
2792c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v0), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x5B", json::parse_error&);
2793c5f01b2fSopenharmony_ci            CHECK(json::from_ubjson(v0, true, false).is_discarded());
2794c5f01b2fSopenharmony_ci        }
2795c5f01b2fSopenharmony_ci
2796c5f01b2fSopenharmony_ci        SECTION("types")
2797c5f01b2fSopenharmony_ci        {
2798c5f01b2fSopenharmony_ci            std::vector<uint8_t> v0 = {'[', '$'};
2799c5f01b2fSopenharmony_ci            json _;
2800c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v0), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing BJData type: unexpected end of input", json::parse_error&);
2801c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v0, true, false).is_discarded());
2802c5f01b2fSopenharmony_ci
2803c5f01b2fSopenharmony_ci            std::vector<uint8_t> vi = {'[', '$', '#'};
2804c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2805c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vi, true, false).is_discarded());
2806c5f01b2fSopenharmony_ci
2807c5f01b2fSopenharmony_ci            std::vector<uint8_t> vU = {'[', '$', 'U'};
2808c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vU), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2809c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vU, true, false).is_discarded());
2810c5f01b2fSopenharmony_ci
2811c5f01b2fSopenharmony_ci            std::vector<uint8_t> v1 = {'[', '$', '['};
2812c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v1), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x5B is not a permitted optimized array type", json::parse_error&);
2813c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v1, true, false).is_discarded());
2814c5f01b2fSopenharmony_ci        }
2815c5f01b2fSopenharmony_ci
2816c5f01b2fSopenharmony_ci        SECTION("arrays")
2817c5f01b2fSopenharmony_ci        {
2818c5f01b2fSopenharmony_ci            std::vector<uint8_t> vST = {'[', '$', 'i', '#', 'i', 2, 1};
2819c5f01b2fSopenharmony_ci            json _;
2820c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vST), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2821c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vST, true, false).is_discarded());
2822c5f01b2fSopenharmony_ci
2823c5f01b2fSopenharmony_ci            std::vector<uint8_t> vS = {'[', '#', 'i', 2, 'i', 1};
2824c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vS), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2825c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vS, true, false).is_discarded());
2826c5f01b2fSopenharmony_ci
2827c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', 'i', 2, 'i', 1};
2828c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2829c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v, true, false).is_discarded());
2830c5f01b2fSopenharmony_ci        }
2831c5f01b2fSopenharmony_ci
2832c5f01b2fSopenharmony_ci        SECTION("ndarrays")
2833c5f01b2fSopenharmony_ci        {
2834c5f01b2fSopenharmony_ci            std::vector<uint8_t> vST = {'[', '$', 'i', '#', '[', '$', 'i', '#'};
2835c5f01b2fSopenharmony_ci            json _;
2836c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vST), "[json.exception.parse_error.113] parse error at byte 9: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0xFF", json::parse_error&);
2837c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vST, true, false).is_discarded());
2838c5f01b2fSopenharmony_ci
2839c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 1, 2};
2840c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 13: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2841c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v, true, false).is_discarded());
2842c5f01b2fSopenharmony_ci
2843c5f01b2fSopenharmony_ci            std::vector<uint8_t> vS0 = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 1};
2844c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vS0), "[json.exception.parse_error.110] parse error at byte 12: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2845c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vS0, true, false).is_discarded());
2846c5f01b2fSopenharmony_ci
2847c5f01b2fSopenharmony_ci            std::vector<uint8_t> vS = {'[', '$', 'i', '#', '[', '#', 'i', 2, 1, 2, 1};
2848c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vS), "[json.exception.parse_error.113] parse error at byte 9: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x01", json::parse_error&);
2849c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vS, true, false).is_discarded());
2850c5f01b2fSopenharmony_ci
2851c5f01b2fSopenharmony_ci            std::vector<uint8_t> vT = {'[', '$', 'i', '#', '[', 'i', 2, 'i'};
2852c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vT), "[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2853c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vT, true, false).is_discarded());
2854c5f01b2fSopenharmony_ci
2855c5f01b2fSopenharmony_ci            std::vector<uint8_t> vT0 = {'[', '$', 'i', '#', '[', 'i'};
2856c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vT0), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2857c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vT0, true, false).is_discarded());
2858c5f01b2fSopenharmony_ci
2859c5f01b2fSopenharmony_ci            std::vector<uint8_t> vu = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'u', 1, 0};
2860c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vu), "[json.exception.parse_error.110] parse error at byte 12: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2861c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vu, true, false).is_discarded());
2862c5f01b2fSopenharmony_ci
2863c5f01b2fSopenharmony_ci            std::vector<uint8_t> vm = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'm', 1, 0, 0, 0};
2864c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vm), "[json.exception.parse_error.110] parse error at byte 14: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2865c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vm, true, false).is_discarded());
2866c5f01b2fSopenharmony_ci
2867c5f01b2fSopenharmony_ci            std::vector<uint8_t> vM = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'M', 1, 0, 0, 0, 0, 0, 0, 0};
2868c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.parse_error.110] parse error at byte 18: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2869c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vM, true, false).is_discarded());
2870c5f01b2fSopenharmony_ci
2871c5f01b2fSopenharmony_ci            std::vector<uint8_t> vU = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 1, 2, 3, 4, 5};
2872c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vU), "[json.exception.parse_error.110] parse error at byte 18: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2873c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vU, true, false).is_discarded());
2874c5f01b2fSopenharmony_ci
2875c5f01b2fSopenharmony_ci            std::vector<uint8_t> vT1 = {'[', '$', 'T', '#', '[', '$', 'i', '#', 'i', 2, 2, 3};
2876c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vT1, true, false).is_discarded());
2877c5f01b2fSopenharmony_ci
2878c5f01b2fSopenharmony_ci            std::vector<uint8_t> vh = {'[', '$', 'h', '#', '[', '$', 'i', '#', 'i', 2, 2, 3};
2879c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vh, true, false).is_discarded());
2880c5f01b2fSopenharmony_ci
2881c5f01b2fSopenharmony_ci            std::vector<uint8_t> vR = {'[', '$', 'i', '#', '[', 'i', 1, '[', ']', ']', 1};
2882c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR), "[json.exception.parse_error.113] parse error at byte 8: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&);
2883c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vR, true, false).is_discarded());
2884c5f01b2fSopenharmony_ci
2885c5f01b2fSopenharmony_ci            std::vector<uint8_t> vRo = {'[', '$', 'i', '#', '[', 'i', 0, '{', '}', ']', 1};
2886c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vRo), "[json.exception.parse_error.113] parse error at byte 8: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x7B", json::parse_error&);
2887c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vRo, true, false).is_discarded());
2888c5f01b2fSopenharmony_ci
2889c5f01b2fSopenharmony_ci            std::vector<uint8_t> vR1 = {'[', '$', 'i', '#', '[', '[', 'i', 1, ']', ']', 1};
2890c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR1), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&);
2891c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vR1, true, false).is_discarded());
2892c5f01b2fSopenharmony_ci
2893c5f01b2fSopenharmony_ci            std::vector<uint8_t> vR2 = {'[', '$', 'i', '#', '[', '#', '[', 'i', 1, ']', ']', 1};
2894c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR2), "[json.exception.parse_error.113] parse error at byte 11: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x5D", json::parse_error&);
2895c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vR2, true, false).is_discarded());
2896c5f01b2fSopenharmony_ci
2897c5f01b2fSopenharmony_ci            std::vector<uint8_t> vR3 = {'[', '#', '[', 'i', '2', 'i', 2, ']'};
2898c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR3), "[json.exception.parse_error.112] parse error at byte 8: syntax error while parsing BJData size: ndarray requires both type and size", json::parse_error&);
2899c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vR3, true, false).is_discarded());
2900c5f01b2fSopenharmony_ci
2901c5f01b2fSopenharmony_ci            std::vector<uint8_t> vR4 = {'[', '$', 'i', '#', '[', '$', 'i', '#', '[', 'i', 1, ']', 1};
2902c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR4), "[json.exception.parse_error.110] parse error at byte 14: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2903c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vR4, true, false).is_discarded());
2904c5f01b2fSopenharmony_ci
2905c5f01b2fSopenharmony_ci            std::vector<uint8_t> vR5 = {'[', '$', 'i', '#', '[', '[', '[', ']', ']', ']'};
2906c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR5), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&);
2907c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vR5, true, false).is_discarded());
2908c5f01b2fSopenharmony_ci
2909c5f01b2fSopenharmony_ci            std::vector<uint8_t> vR6 = {'[', '$', 'i', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'};
2910c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR6), "[json.exception.parse_error.112] parse error at byte 14: syntax error while parsing BJData size: ndarray can not be recursive", json::parse_error&);
2911c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vR6, true, false).is_discarded());
2912c5f01b2fSopenharmony_ci
2913c5f01b2fSopenharmony_ci            std::vector<uint8_t> vH = {'[', 'H', '[', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'};
2914c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vH), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&);
2915c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vH, true, false).is_discarded());
2916c5f01b2fSopenharmony_ci        }
2917c5f01b2fSopenharmony_ci
2918c5f01b2fSopenharmony_ci        SECTION("objects")
2919c5f01b2fSopenharmony_ci        {
2920c5f01b2fSopenharmony_ci            std::vector<uint8_t> vST = {'{', '$', 'i', '#', 'i', 2, 'i', 1, 'a', 1};
2921c5f01b2fSopenharmony_ci            json _;
2922c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vST), "[json.exception.parse_error.110] parse error at byte 11: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2923c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vST, true, false).is_discarded());
2924c5f01b2fSopenharmony_ci
2925c5f01b2fSopenharmony_ci            std::vector<uint8_t> vT = {'{', '$', 'i', 'i', 1, 'a', 1};
2926c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH(_ = json::from_bjdata(vT), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing BJData size: expected '#' after type information; last byte: 0x69");
2927c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vT, true, false).is_discarded());
2928c5f01b2fSopenharmony_ci
2929c5f01b2fSopenharmony_ci            std::vector<uint8_t> vS = {'{', '#', 'i', 2, 'i', 1, 'a', 'i', 1};
2930c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vS), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2931c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vS, true, false).is_discarded());
2932c5f01b2fSopenharmony_ci
2933c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'{', 'i', 1, 'a', 'i', 1};
2934c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2935c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v, true, false).is_discarded());
2936c5f01b2fSopenharmony_ci
2937c5f01b2fSopenharmony_ci            std::vector<uint8_t> v2 = {'{', 'i', 1, 'a', 'i', 1, 'i'};
2938c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2939c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v2, true, false).is_discarded());
2940c5f01b2fSopenharmony_ci
2941c5f01b2fSopenharmony_ci            std::vector<uint8_t> v3 = {'{', 'i', 1, 'a'};
2942c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v3), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2943c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v3, true, false).is_discarded());
2944c5f01b2fSopenharmony_ci
2945c5f01b2fSopenharmony_ci            std::vector<uint8_t> vST1 = {'{', '$', 'd', '#', 'i', 2, 'i', 1, 'a'};
2946c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vST1), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing BJData number: unexpected end of input", json::parse_error&);
2947c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vST1, true, false).is_discarded());
2948c5f01b2fSopenharmony_ci
2949c5f01b2fSopenharmony_ci            std::vector<uint8_t> vST2 = {'{', '#', 'i', 2, 'i', 1, 'a'};
2950c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vST2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing BJData value: unexpected end of input", json::parse_error&);
2951c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vST2, true, false).is_discarded());
2952c5f01b2fSopenharmony_ci
2953c5f01b2fSopenharmony_ci            std::vector<uint8_t> vO = {'{', '#', '[', 'i', 2, 'i', 1, ']', 'i', 1, 'a', 'i', 1, 'i', 1, 'b', 'i', 2};
2954c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vO), "[json.exception.parse_error.112] parse error at byte 8: syntax error while parsing BJData size: ndarray requires both type and size", json::parse_error&);
2955c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vO, true, false).is_discarded());
2956c5f01b2fSopenharmony_ci
2957c5f01b2fSopenharmony_ci            std::vector<uint8_t> vO2 = {'{', '$', 'i', '#', '[', 'i', 2, 'i', 1, ']', 'i', 1, 'a', 1, 'i', 1, 'b', 2};
2958c5f01b2fSopenharmony_ci            CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vO2), "[json.exception.parse_error.112] parse error at byte 10: syntax error while parsing BJData object: BJData object does not support ND-array size in optimized format", json::parse_error&);
2959c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(vO2, true, false).is_discarded());
2960c5f01b2fSopenharmony_ci        }
2961c5f01b2fSopenharmony_ci    }
2962c5f01b2fSopenharmony_ci
2963c5f01b2fSopenharmony_ci    SECTION("writing optimized values")
2964c5f01b2fSopenharmony_ci    {
2965c5f01b2fSopenharmony_ci        SECTION("integer")
2966c5f01b2fSopenharmony_ci        {
2967c5f01b2fSopenharmony_ci            SECTION("array of i")
2968c5f01b2fSopenharmony_ci            {
2969c5f01b2fSopenharmony_ci                json j = {1, -1};
2970c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'i', '#', 'i', 2, 1, 0xff};
2971c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
2972c5f01b2fSopenharmony_ci            }
2973c5f01b2fSopenharmony_ci
2974c5f01b2fSopenharmony_ci            SECTION("array of U")
2975c5f01b2fSopenharmony_ci            {
2976c5f01b2fSopenharmony_ci                json j = {200, 201};
2977c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'U', '#', 'i', 2, 0xC8, 0xC9};
2978c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
2979c5f01b2fSopenharmony_ci            }
2980c5f01b2fSopenharmony_ci
2981c5f01b2fSopenharmony_ci            SECTION("array of I")
2982c5f01b2fSopenharmony_ci            {
2983c5f01b2fSopenharmony_ci                json j = {30000, -30000};
2984c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'I', '#', 'i', 2, 0x30, 0x75, 0xd0, 0x8a};
2985c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
2986c5f01b2fSopenharmony_ci            }
2987c5f01b2fSopenharmony_ci
2988c5f01b2fSopenharmony_ci            SECTION("array of u")
2989c5f01b2fSopenharmony_ci            {
2990c5f01b2fSopenharmony_ci                json j = {50000, 50001};
2991c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'u', '#', 'i', 2, 0x50, 0xC3, 0x51, 0xC3};
2992c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
2993c5f01b2fSopenharmony_ci            }
2994c5f01b2fSopenharmony_ci
2995c5f01b2fSopenharmony_ci            SECTION("array of l")
2996c5f01b2fSopenharmony_ci            {
2997c5f01b2fSopenharmony_ci                json j = {70000, -70000};
2998c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'l', '#', 'i', 2, 0x70, 0x11, 0x01, 0x00, 0x90, 0xEE, 0xFE, 0xFF};
2999c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
3000c5f01b2fSopenharmony_ci            }
3001c5f01b2fSopenharmony_ci
3002c5f01b2fSopenharmony_ci            SECTION("array of m")
3003c5f01b2fSopenharmony_ci            {
3004c5f01b2fSopenharmony_ci                json j = {3147483647, 3147483648};
3005c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0x00, 0xCA, 0x9A, 0xBB};
3006c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
3007c5f01b2fSopenharmony_ci            }
3008c5f01b2fSopenharmony_ci
3009c5f01b2fSopenharmony_ci            SECTION("array of L")
3010c5f01b2fSopenharmony_ci            {
3011c5f01b2fSopenharmony_ci                json j = {5000000000, -5000000000};
3012c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'L', '#', 'i', 2, 0x00, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xFA, 0xD5, 0xFE, 0xFF, 0xFF, 0xFF};
3013c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
3014c5f01b2fSopenharmony_ci            }
3015c5f01b2fSopenharmony_ci        }
3016c5f01b2fSopenharmony_ci
3017c5f01b2fSopenharmony_ci        SECTION("unsigned integer")
3018c5f01b2fSopenharmony_ci        {
3019c5f01b2fSopenharmony_ci            SECTION("array of i")
3020c5f01b2fSopenharmony_ci            {
3021c5f01b2fSopenharmony_ci                json j = {1u, 2u};
3022c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'i', '#', 'i', 2, 1, 2};
3023c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected_size = {'[', '#', 'i', 2, 'i', 1, 'i', 2};
3024c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
3025c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true) == expected_size);
3026c5f01b2fSopenharmony_ci            }
3027c5f01b2fSopenharmony_ci
3028c5f01b2fSopenharmony_ci            SECTION("array of U")
3029c5f01b2fSopenharmony_ci            {
3030c5f01b2fSopenharmony_ci                json j = {200u, 201u};
3031c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'U', '#', 'i', 2, 0xC8, 0xC9};
3032c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected_size = {'[', '#', 'i', 2, 'U', 0xC8, 'U', 0xC9};
3033c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
3034c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true) == expected_size);
3035c5f01b2fSopenharmony_ci            }
3036c5f01b2fSopenharmony_ci
3037c5f01b2fSopenharmony_ci            SECTION("array of I")
3038c5f01b2fSopenharmony_ci            {
3039c5f01b2fSopenharmony_ci                json j = {30000u, 30001u};
3040c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'I', '#', 'i', 2, 0x30, 0x75, 0x31, 0x75};
3041c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected_size = {'[', '#', 'i', 2, 'I', 0x30, 0x75, 'I', 0x31, 0x75};
3042c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
3043c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true) == expected_size);
3044c5f01b2fSopenharmony_ci            }
3045c5f01b2fSopenharmony_ci
3046c5f01b2fSopenharmony_ci            SECTION("array of u")
3047c5f01b2fSopenharmony_ci            {
3048c5f01b2fSopenharmony_ci                json j = {50000u, 50001u};
3049c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'u', '#', 'i', 2, 0x50, 0xC3, 0x51, 0xC3};
3050c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected_size = {'[', '#', 'i', 2, 'u', 0x50, 0xC3, 'u', 0x51, 0xC3};
3051c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
3052c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true) == expected_size);
3053c5f01b2fSopenharmony_ci            }
3054c5f01b2fSopenharmony_ci
3055c5f01b2fSopenharmony_ci            SECTION("array of l")
3056c5f01b2fSopenharmony_ci            {
3057c5f01b2fSopenharmony_ci                json j = {70000u, 70001u};
3058c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'l', '#', 'i', 2, 0x70, 0x11, 0x01, 0x00, 0x71, 0x11, 0x01, 0x00};
3059c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected_size = {'[', '#', 'i', 2, 'l', 0x70, 0x11, 0x01, 0x00, 'l', 0x71, 0x11, 0x01, 0x00};
3060c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
3061c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true) == expected_size);
3062c5f01b2fSopenharmony_ci            }
3063c5f01b2fSopenharmony_ci
3064c5f01b2fSopenharmony_ci            SECTION("array of m")
3065c5f01b2fSopenharmony_ci            {
3066c5f01b2fSopenharmony_ci                json j = {3147483647u, 3147483648u};
3067c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0x00, 0xCA, 0x9A, 0xBB};
3068c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected_size = {'[', '#', 'i', 2, 'm', 0xFF, 0xC9, 0x9A, 0xBB, 'm', 0x00, 0xCA, 0x9A, 0xBB};
3069c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
3070c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true) == expected_size);
3071c5f01b2fSopenharmony_ci            }
3072c5f01b2fSopenharmony_ci
3073c5f01b2fSopenharmony_ci            SECTION("array of L")
3074c5f01b2fSopenharmony_ci            {
3075c5f01b2fSopenharmony_ci                json j = {5000000000u, 5000000001u};
3076c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'L', '#', 'i', 2, 0x00, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00, 0x01, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00};
3077c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected_size = {'[', '#', 'i', 2, 'L', 0x00, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00, 'L', 0x01, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00};
3078c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
3079c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true) == expected_size);
3080c5f01b2fSopenharmony_ci            }
3081c5f01b2fSopenharmony_ci
3082c5f01b2fSopenharmony_ci            SECTION("array of M")
3083c5f01b2fSopenharmony_ci            {
3084c5f01b2fSopenharmony_ci                json j = {10223372036854775807ull, 10223372036854775808ull};
3085c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected = {'[', '$', 'M', '#', 'i', 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0x00, 0x00, 0x64, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D};
3086c5f01b2fSopenharmony_ci                std::vector<uint8_t> expected_size = {'[', '#', 'i', 2, 'M', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 'M', 0x00, 0x00, 0x64, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D};
3087c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == expected);
3088c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true) == expected_size);
3089c5f01b2fSopenharmony_ci            }
3090c5f01b2fSopenharmony_ci        }
3091c5f01b2fSopenharmony_ci    }
3092c5f01b2fSopenharmony_ci}
3093c5f01b2fSopenharmony_ci
3094c5f01b2fSopenharmony_ciTEST_CASE("Universal Binary JSON Specification Examples 1")
3095c5f01b2fSopenharmony_ci{
3096c5f01b2fSopenharmony_ci    SECTION("Null Value")
3097c5f01b2fSopenharmony_ci    {
3098c5f01b2fSopenharmony_ci        json j = {{"passcode", nullptr}};
3099c5f01b2fSopenharmony_ci        std::vector<uint8_t> v = {'{', 'i', 8, 'p', 'a', 's', 's', 'c', 'o', 'd', 'e', 'Z', '}'};
3100c5f01b2fSopenharmony_ci        CHECK(json::to_bjdata(j) == v);
3101c5f01b2fSopenharmony_ci        CHECK(json::from_bjdata(v) == j);
3102c5f01b2fSopenharmony_ci    }
3103c5f01b2fSopenharmony_ci
3104c5f01b2fSopenharmony_ci    SECTION("No-Op Value")
3105c5f01b2fSopenharmony_ci    {
3106c5f01b2fSopenharmony_ci        json j = {"foo", "bar", "baz"};
3107c5f01b2fSopenharmony_ci        std::vector<uint8_t> v = {'[', 'S', 'i', 3, 'f', 'o', 'o',
3108c5f01b2fSopenharmony_ci                                  'S', 'i', 3, 'b', 'a', 'r',
3109c5f01b2fSopenharmony_ci                                  'S', 'i', 3, 'b', 'a', 'z', ']'
3110c5f01b2fSopenharmony_ci                                 };
3111c5f01b2fSopenharmony_ci        std::vector<uint8_t> v2 = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'N',
3112c5f01b2fSopenharmony_ci                                   'S', 'i', 3, 'b', 'a', 'r', 'N', 'N', 'N',
3113c5f01b2fSopenharmony_ci                                   'S', 'i', 3, 'b', 'a', 'z', 'N', 'N', ']'
3114c5f01b2fSopenharmony_ci                                  };
3115c5f01b2fSopenharmony_ci        CHECK(json::to_bjdata(j) == v);
3116c5f01b2fSopenharmony_ci        CHECK(json::from_bjdata(v) == j);
3117c5f01b2fSopenharmony_ci        CHECK(json::from_bjdata(v2) == j);
3118c5f01b2fSopenharmony_ci    }
3119c5f01b2fSopenharmony_ci
3120c5f01b2fSopenharmony_ci    SECTION("Boolean Types")
3121c5f01b2fSopenharmony_ci    {
3122c5f01b2fSopenharmony_ci        json j = {{"authorized", true}, {"verified", false}};
3123c5f01b2fSopenharmony_ci        std::vector<uint8_t> v = {'{', 'i', 10, 'a', 'u', 't', 'h', 'o', 'r', 'i', 'z', 'e', 'd', 'T',
3124c5f01b2fSopenharmony_ci                                  'i', 8, 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'F', '}'
3125c5f01b2fSopenharmony_ci                                 };
3126c5f01b2fSopenharmony_ci        CHECK(json::to_bjdata(j) == v);
3127c5f01b2fSopenharmony_ci        CHECK(json::from_bjdata(v) == j);
3128c5f01b2fSopenharmony_ci    }
3129c5f01b2fSopenharmony_ci
3130c5f01b2fSopenharmony_ci    SECTION("Numeric Types")
3131c5f01b2fSopenharmony_ci    {
3132c5f01b2fSopenharmony_ci        json j =
3133c5f01b2fSopenharmony_ci        {
3134c5f01b2fSopenharmony_ci            {"int8", 16},
3135c5f01b2fSopenharmony_ci            {"uint8", 255},
3136c5f01b2fSopenharmony_ci            {"int16", 32767},
3137c5f01b2fSopenharmony_ci            {"uint16", 42767},
3138c5f01b2fSopenharmony_ci            {"int32", 2147483647},
3139c5f01b2fSopenharmony_ci            {"uint32", 3147483647},
3140c5f01b2fSopenharmony_ci            {"int64", 9223372036854775807},
3141c5f01b2fSopenharmony_ci            {"uint64", 10223372036854775807ull},
3142c5f01b2fSopenharmony_ci            {"float64", 113243.7863123}
3143c5f01b2fSopenharmony_ci        };
3144c5f01b2fSopenharmony_ci        std::vector<uint8_t> v = {'{',
3145c5f01b2fSopenharmony_ci                                  'i', 7, 'f', 'l', 'o', 'a', 't', '6', '4', 'D', 0xcf, 0x34, 0xbc, 0x94, 0xbc, 0xa5, 0xfb, 0x40,
3146c5f01b2fSopenharmony_ci                                  'i', 5, 'i', 'n', 't', '1', '6', 'I', 0xff, 0x7f,
3147c5f01b2fSopenharmony_ci                                  'i', 5, 'i', 'n', 't', '3', '2', 'l', 0xff, 0xff, 0xff, 0x7f,
3148c5f01b2fSopenharmony_ci                                  'i', 5, 'i', 'n', 't', '6', '4', 'L', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f,
3149c5f01b2fSopenharmony_ci                                  'i', 4, 'i', 'n', 't', '8', 'i', 16,
3150c5f01b2fSopenharmony_ci                                  'i', 6, 'u', 'i', 'n', 't', '1', '6', 'u', 0x0F, 0xA7,
3151c5f01b2fSopenharmony_ci                                  'i', 6, 'u', 'i', 'n', 't', '3', '2', 'm', 0xFF, 0xC9, 0x9A, 0xBB,
3152c5f01b2fSopenharmony_ci                                  'i', 6, 'u', 'i', 'n', 't', '6', '4', 'M', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D,
3153c5f01b2fSopenharmony_ci                                  'i', 5, 'u', 'i', 'n', 't', '8', 'U', 0xff,
3154c5f01b2fSopenharmony_ci                                  '}'
3155c5f01b2fSopenharmony_ci                                 };
3156c5f01b2fSopenharmony_ci        CHECK(json::to_bjdata(j) == v);
3157c5f01b2fSopenharmony_ci        CHECK(json::from_bjdata(v) == j);
3158c5f01b2fSopenharmony_ci    }
3159c5f01b2fSopenharmony_ci
3160c5f01b2fSopenharmony_ci    SECTION("Char Type")
3161c5f01b2fSopenharmony_ci    {
3162c5f01b2fSopenharmony_ci        json j = {{"rolecode", "a"}, {"delim", ";"}};
3163c5f01b2fSopenharmony_ci        std::vector<uint8_t> v = {'{', 'i', 5, 'd', 'e', 'l', 'i', 'm', 'C', ';', 'i', 8, 'r', 'o', 'l', 'e', 'c', 'o', 'd', 'e', 'C', 'a', '}'};
3164c5f01b2fSopenharmony_ci        //CHECK(json::to_bjdata(j) == v);
3165c5f01b2fSopenharmony_ci        CHECK(json::from_bjdata(v) == j);
3166c5f01b2fSopenharmony_ci    }
3167c5f01b2fSopenharmony_ci
3168c5f01b2fSopenharmony_ci    SECTION("String Type")
3169c5f01b2fSopenharmony_ci    {
3170c5f01b2fSopenharmony_ci        SECTION("English")
3171c5f01b2fSopenharmony_ci        {
3172c5f01b2fSopenharmony_ci            json j = "hello";
3173c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'S', 'i', 5, 'h', 'e', 'l', 'l', 'o'};
3174c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(j) == v);
3175c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v) == j);
3176c5f01b2fSopenharmony_ci        }
3177c5f01b2fSopenharmony_ci
3178c5f01b2fSopenharmony_ci        SECTION("Russian")
3179c5f01b2fSopenharmony_ci        {
3180c5f01b2fSopenharmony_ci            json j = "привет";
3181c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'S', 'i', 12, 0xD0, 0xBF, 0xD1, 0x80, 0xD0, 0xB8, 0xD0, 0xB2, 0xD0, 0xB5, 0xD1, 0x82};
3182c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(j) == v);
3183c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v) == j);
3184c5f01b2fSopenharmony_ci        }
3185c5f01b2fSopenharmony_ci
3186c5f01b2fSopenharmony_ci        SECTION("Russian")
3187c5f01b2fSopenharmony_ci        {
3188c5f01b2fSopenharmony_ci            json j = "مرحبا";
3189c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'S', 'i', 10, 0xD9, 0x85, 0xD8, 0xB1, 0xD8, 0xAD, 0xD8, 0xA8, 0xD8, 0xA7};
3190c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(j) == v);
3191c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v) == j);
3192c5f01b2fSopenharmony_ci        }
3193c5f01b2fSopenharmony_ci    }
3194c5f01b2fSopenharmony_ci
3195c5f01b2fSopenharmony_ci    SECTION("Array Type")
3196c5f01b2fSopenharmony_ci    {
3197c5f01b2fSopenharmony_ci        SECTION("size=false type=false")
3198c5f01b2fSopenharmony_ci        {
3199c5f01b2fSopenharmony_ci            // note the float has been replaced by a double
3200c5f01b2fSopenharmony_ci            json j = {nullptr, true, false, 4782345193, 153.132, "ham"};
3201c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', 'Z', 'T', 'F', 'L', 0xE9, 0xCB, 0x0C, 0x1D, 0x01, 0x00, 0x00, 0x00, 'D', 0x4e, 0x62, 0x10, 0x58, 0x39, 0x24, 0x63, 0x40, 'S', 'i', 3, 'h', 'a', 'm', ']'};
3202c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(j) == v);
3203c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v) == j);
3204c5f01b2fSopenharmony_ci        }
3205c5f01b2fSopenharmony_ci
3206c5f01b2fSopenharmony_ci        SECTION("size=true type=false")
3207c5f01b2fSopenharmony_ci        {
3208c5f01b2fSopenharmony_ci            // note the float has been replaced by a double
3209c5f01b2fSopenharmony_ci            json j = {nullptr, true, false, 4782345193, 153.132, "ham"};
3210c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '#', 'i', 6, 'Z', 'T', 'F', 'L', 0xE9, 0xCB, 0x0C, 0x1D, 0x01, 0x00, 0x00, 0x00, 'D', 0x4e, 0x62, 0x10, 0x58, 0x39, 0x24, 0x63, 0x40, 'S', 'i', 3, 'h', 'a', 'm'};
3211c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(j, true) == v);
3212c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v) == j);
3213c5f01b2fSopenharmony_ci        }
3214c5f01b2fSopenharmony_ci
3215c5f01b2fSopenharmony_ci        SECTION("size=true type=true")
3216c5f01b2fSopenharmony_ci        {
3217c5f01b2fSopenharmony_ci            // note the float has been replaced by a double
3218c5f01b2fSopenharmony_ci            json j = {nullptr, true, false, 4782345193, 153.132, "ham"};
3219c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'[', '#', 'i', 6, 'Z', 'T', 'F', 'L', 0xE9, 0xCB, 0x0C, 0x1D, 0x01, 0x00, 0x00, 0x00, 'D', 0x4e, 0x62, 0x10, 0x58, 0x39, 0x24, 0x63, 0x40, 'S', 'i', 3, 'h', 'a', 'm'};
3220c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(j, true, true) == v);
3221c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v) == j);
3222c5f01b2fSopenharmony_ci        }
3223c5f01b2fSopenharmony_ci    }
3224c5f01b2fSopenharmony_ci
3225c5f01b2fSopenharmony_ci    SECTION("Object Type")
3226c5f01b2fSopenharmony_ci    {
3227c5f01b2fSopenharmony_ci        SECTION("size=false type=false")
3228c5f01b2fSopenharmony_ci        {
3229c5f01b2fSopenharmony_ci            json j =
3230c5f01b2fSopenharmony_ci            {
3231c5f01b2fSopenharmony_ci                {
3232c5f01b2fSopenharmony_ci                    "post", {
3233c5f01b2fSopenharmony_ci                        {"id", 1137},
3234c5f01b2fSopenharmony_ci                        {"author", "rkalla"},
3235c5f01b2fSopenharmony_ci                        {"timestamp", 1364482090592},
3236c5f01b2fSopenharmony_ci                        {"body", "I totally agree!"}
3237c5f01b2fSopenharmony_ci                    }
3238c5f01b2fSopenharmony_ci                }
3239c5f01b2fSopenharmony_ci            };
3240c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'{', 'i', 4, 'p', 'o', 's', 't', '{',
3241c5f01b2fSopenharmony_ci                                      'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a',
3242c5f01b2fSopenharmony_ci                                      'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!',
3243c5f01b2fSopenharmony_ci                                      'i', 2, 'i', 'd', 'I', 0x71, 0x04,
3244c5f01b2fSopenharmony_ci                                      'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x60, 0x66, 0x78, 0xB1, 0x3D, 0x01, 0x00, 0x00,
3245c5f01b2fSopenharmony_ci                                      '}', '}'
3246c5f01b2fSopenharmony_ci                                     };
3247c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(j) == v);
3248c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v) == j);
3249c5f01b2fSopenharmony_ci        }
3250c5f01b2fSopenharmony_ci
3251c5f01b2fSopenharmony_ci        SECTION("size=true type=false")
3252c5f01b2fSopenharmony_ci        {
3253c5f01b2fSopenharmony_ci            json j =
3254c5f01b2fSopenharmony_ci            {
3255c5f01b2fSopenharmony_ci                {
3256c5f01b2fSopenharmony_ci                    "post", {
3257c5f01b2fSopenharmony_ci                        {"id", 1137},
3258c5f01b2fSopenharmony_ci                        {"author", "rkalla"},
3259c5f01b2fSopenharmony_ci                        {"timestamp", 1364482090592},
3260c5f01b2fSopenharmony_ci                        {"body", "I totally agree!"}
3261c5f01b2fSopenharmony_ci                    }
3262c5f01b2fSopenharmony_ci                }
3263c5f01b2fSopenharmony_ci            };
3264c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '{', '#', 'i', 4,
3265c5f01b2fSopenharmony_ci                                      'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a',
3266c5f01b2fSopenharmony_ci                                      'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!',
3267c5f01b2fSopenharmony_ci                                      'i', 2, 'i', 'd', 'I', 0x71, 0x04,
3268c5f01b2fSopenharmony_ci                                      'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x60, 0x66, 0x78, 0xB1, 0x3D, 0x01, 0x00, 0x00,
3269c5f01b2fSopenharmony_ci                                     };
3270c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(j, true) == v);
3271c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v) == j);
3272c5f01b2fSopenharmony_ci        }
3273c5f01b2fSopenharmony_ci
3274c5f01b2fSopenharmony_ci        SECTION("size=true type=true")
3275c5f01b2fSopenharmony_ci        {
3276c5f01b2fSopenharmony_ci            json j =
3277c5f01b2fSopenharmony_ci            {
3278c5f01b2fSopenharmony_ci                {
3279c5f01b2fSopenharmony_ci                    "post", {
3280c5f01b2fSopenharmony_ci                        {"id", 1137},
3281c5f01b2fSopenharmony_ci                        {"author", "rkalla"},
3282c5f01b2fSopenharmony_ci                        {"timestamp", 1364482090592},
3283c5f01b2fSopenharmony_ci                        {"body", "I totally agree!"}
3284c5f01b2fSopenharmony_ci                    }
3285c5f01b2fSopenharmony_ci                }
3286c5f01b2fSopenharmony_ci            };
3287c5f01b2fSopenharmony_ci            std::vector<uint8_t> v = {'{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '{', '#', 'i', 4,
3288c5f01b2fSopenharmony_ci                                      'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a',
3289c5f01b2fSopenharmony_ci                                      'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!',
3290c5f01b2fSopenharmony_ci                                      'i', 2, 'i', 'd', 'I', 0x71, 0x04,
3291c5f01b2fSopenharmony_ci                                      'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x60, 0x66, 0x78, 0xB1, 0x3D, 0x01, 0x00, 0x00,
3292c5f01b2fSopenharmony_ci                                     };
3293c5f01b2fSopenharmony_ci            CHECK(json::to_bjdata(j, true, true) == v);
3294c5f01b2fSopenharmony_ci            CHECK(json::from_bjdata(v) == j);
3295c5f01b2fSopenharmony_ci        }
3296c5f01b2fSopenharmony_ci    }
3297c5f01b2fSopenharmony_ci
3298c5f01b2fSopenharmony_ci    SECTION("Optimized Format")
3299c5f01b2fSopenharmony_ci    {
3300c5f01b2fSopenharmony_ci        SECTION("Array Example")
3301c5f01b2fSopenharmony_ci        {
3302c5f01b2fSopenharmony_ci            SECTION("No Optimization")
3303c5f01b2fSopenharmony_ci            {
3304c5f01b2fSopenharmony_ci                // note the floats have been replaced by doubles
3305c5f01b2fSopenharmony_ci                json j = {29.97, 31.13, 67.0, 2.113, 23.888};
3306c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'[',
3307c5f01b2fSopenharmony_ci                                          'D', 0xb8, 0x1e, 0x85, 0xeb, 0x51, 0xf8, 0x3d, 0x40,
3308c5f01b2fSopenharmony_ci                                          'D', 0xe1, 0x7a, 0x14, 0xae, 0x47, 0x21, 0x3f, 0x40,
3309c5f01b2fSopenharmony_ci                                          'D', 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40,
3310c5f01b2fSopenharmony_ci                                          'D', 0x81, 0x95, 0x43, 0x8b, 0x6c, 0xe7, 0x00, 0x40,
3311c5f01b2fSopenharmony_ci                                          'D', 0x17, 0xd9, 0xce, 0xf7, 0x53, 0xe3, 0x37, 0x40,
3312c5f01b2fSopenharmony_ci                                          ']'
3313c5f01b2fSopenharmony_ci                                         };
3314c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j) == v);
3315c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v) == j);
3316c5f01b2fSopenharmony_ci            }
3317c5f01b2fSopenharmony_ci
3318c5f01b2fSopenharmony_ci            SECTION("Optimized with count")
3319c5f01b2fSopenharmony_ci            {
3320c5f01b2fSopenharmony_ci                // note the floats have been replaced by doubles
3321c5f01b2fSopenharmony_ci                json j = {29.97, 31.13, 67.0, 2.113, 23.888};
3322c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'[', '#', 'i', 5,
3323c5f01b2fSopenharmony_ci                                          'D', 0xb8, 0x1e, 0x85, 0xeb, 0x51, 0xf8, 0x3d, 0x40,
3324c5f01b2fSopenharmony_ci                                          'D', 0xe1, 0x7a, 0x14, 0xae, 0x47, 0x21, 0x3f, 0x40,
3325c5f01b2fSopenharmony_ci                                          'D', 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40,
3326c5f01b2fSopenharmony_ci                                          'D', 0x81, 0x95, 0x43, 0x8b, 0x6c, 0xe7, 0x00, 0x40,
3327c5f01b2fSopenharmony_ci                                          'D', 0x17, 0xd9, 0xce, 0xf7, 0x53, 0xe3, 0x37, 0x40,
3328c5f01b2fSopenharmony_ci                                         };
3329c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true) == v);
3330c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v) == j);
3331c5f01b2fSopenharmony_ci            }
3332c5f01b2fSopenharmony_ci
3333c5f01b2fSopenharmony_ci            SECTION("Optimized with type & count")
3334c5f01b2fSopenharmony_ci            {
3335c5f01b2fSopenharmony_ci                // note the floats have been replaced by doubles
3336c5f01b2fSopenharmony_ci                json j = {29.97, 31.13, 67.0, 2.113, 23.888};
3337c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'[', '$', 'D', '#', 'i', 5,
3338c5f01b2fSopenharmony_ci                                          0xb8, 0x1e, 0x85, 0xeb, 0x51, 0xf8, 0x3d, 0x40,
3339c5f01b2fSopenharmony_ci                                          0xe1, 0x7a, 0x14, 0xae, 0x47, 0x21, 0x3f, 0x40,
3340c5f01b2fSopenharmony_ci                                          0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40,
3341c5f01b2fSopenharmony_ci                                          0x81, 0x95, 0x43, 0x8b, 0x6c, 0xe7, 0x00, 0x40,
3342c5f01b2fSopenharmony_ci                                          0x17, 0xd9, 0xce, 0xf7, 0x53, 0xe3, 0x37, 0x40,
3343c5f01b2fSopenharmony_ci                                         };
3344c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == v);
3345c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v) == j);
3346c5f01b2fSopenharmony_ci            }
3347c5f01b2fSopenharmony_ci        }
3348c5f01b2fSopenharmony_ci
3349c5f01b2fSopenharmony_ci        SECTION("Object Example")
3350c5f01b2fSopenharmony_ci        {
3351c5f01b2fSopenharmony_ci            SECTION("No Optimization")
3352c5f01b2fSopenharmony_ci            {
3353c5f01b2fSopenharmony_ci                // note the floats have been replaced by doubles
3354c5f01b2fSopenharmony_ci                json j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} };
3355c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'{',
3356c5f01b2fSopenharmony_ci                                          'i', 3, 'a', 'l', 't', 'D',      0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40,
3357c5f01b2fSopenharmony_ci                                          'i', 3, 'l', 'a', 't', 'D',      0x60, 0xe5, 0xd0, 0x22, 0xdb, 0xf9, 0x3d, 0x40,
3358c5f01b2fSopenharmony_ci                                          'i', 4, 'l', 'o', 'n', 'g', 'D', 0xa8, 0xc6, 0x4b, 0x37, 0x89, 0x21, 0x3f, 0x40,
3359c5f01b2fSopenharmony_ci                                          '}'
3360c5f01b2fSopenharmony_ci                                         };
3361c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j) == v);
3362c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v) == j);
3363c5f01b2fSopenharmony_ci            }
3364c5f01b2fSopenharmony_ci
3365c5f01b2fSopenharmony_ci            SECTION("Optimized with count")
3366c5f01b2fSopenharmony_ci            {
3367c5f01b2fSopenharmony_ci                // note the floats have been replaced by doubles
3368c5f01b2fSopenharmony_ci                json j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} };
3369c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'{', '#', 'i', 3,
3370c5f01b2fSopenharmony_ci                                          'i', 3, 'a', 'l', 't', 'D',      0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40,
3371c5f01b2fSopenharmony_ci                                          'i', 3, 'l', 'a', 't', 'D',      0x60, 0xe5, 0xd0, 0x22, 0xdb, 0xf9, 0x3d, 0x40,
3372c5f01b2fSopenharmony_ci                                          'i', 4, 'l', 'o', 'n', 'g', 'D', 0xa8, 0xc6, 0x4b, 0x37, 0x89, 0x21, 0x3f, 0x40,
3373c5f01b2fSopenharmony_ci                                         };
3374c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true) == v);
3375c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v) == j);
3376c5f01b2fSopenharmony_ci            }
3377c5f01b2fSopenharmony_ci
3378c5f01b2fSopenharmony_ci            SECTION("Optimized with type & count")
3379c5f01b2fSopenharmony_ci            {
3380c5f01b2fSopenharmony_ci                // note the floats have been replaced by doubles
3381c5f01b2fSopenharmony_ci                json j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} };
3382c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'{', '$', 'D', '#', 'i', 3,
3383c5f01b2fSopenharmony_ci                                          'i', 3, 'a', 'l', 't',      0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40,
3384c5f01b2fSopenharmony_ci                                          'i', 3, 'l', 'a', 't',      0x60, 0xe5, 0xd0, 0x22, 0xdb, 0xf9, 0x3d, 0x40,
3385c5f01b2fSopenharmony_ci                                          'i', 4, 'l', 'o', 'n', 'g', 0xa8, 0xc6, 0x4b, 0x37, 0x89, 0x21, 0x3f, 0x40,
3386c5f01b2fSopenharmony_ci                                         };
3387c5f01b2fSopenharmony_ci                CHECK(json::to_bjdata(j, true, true) == v);
3388c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v) == j);
3389c5f01b2fSopenharmony_ci            }
3390c5f01b2fSopenharmony_ci        }
3391c5f01b2fSopenharmony_ci
3392c5f01b2fSopenharmony_ci        SECTION("Special Cases (Null, No-Op and Boolean)")
3393c5f01b2fSopenharmony_ci        {
3394c5f01b2fSopenharmony_ci            SECTION("Array")
3395c5f01b2fSopenharmony_ci            {
3396c5f01b2fSopenharmony_ci                json _;
3397c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'[', '$', 'N', '#', 'I', 0x00, 0x02};
3398c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x4E is not a permitted optimized array type", json::parse_error&);
3399c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v, true, false).is_discarded());
3400c5f01b2fSopenharmony_ci            }
3401c5f01b2fSopenharmony_ci
3402c5f01b2fSopenharmony_ci            SECTION("Object")
3403c5f01b2fSopenharmony_ci            {
3404c5f01b2fSopenharmony_ci                json _;
3405c5f01b2fSopenharmony_ci                std::vector<uint8_t> v = {'{', '$', 'Z', '#', 'i', 3, 'i', 4, 'n', 'a', 'm', 'e', 'i', 8, 'p', 'a', 's', 's', 'w', 'o', 'r', 'd', 'i', 5, 'e', 'm', 'a', 'i', 'l'};
3406c5f01b2fSopenharmony_ci                CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x5A is not a permitted optimized array type", json::parse_error&);
3407c5f01b2fSopenharmony_ci                CHECK(json::from_bjdata(v, true, false).is_discarded());
3408c5f01b2fSopenharmony_ci            }
3409c5f01b2fSopenharmony_ci        }
3410c5f01b2fSopenharmony_ci    }
3411c5f01b2fSopenharmony_ci}
3412c5f01b2fSopenharmony_ci
3413c5f01b2fSopenharmony_ci#if !defined(JSON_NOEXCEPTION)
3414c5f01b2fSopenharmony_ciTEST_CASE("all BJData first bytes")
3415c5f01b2fSopenharmony_ci{
3416c5f01b2fSopenharmony_ci    // these bytes will fail immediately with exception parse_error.112
3417c5f01b2fSopenharmony_ci    std::set<uint8_t> supported =
3418c5f01b2fSopenharmony_ci    {
3419c5f01b2fSopenharmony_ci        'T', 'F', 'Z', 'U', 'i', 'I', 'l', 'L', 'd', 'D', 'C', 'S', '[', '{', 'N', 'H', 'u', 'm', 'M', 'h'
3420c5f01b2fSopenharmony_ci    };
3421c5f01b2fSopenharmony_ci
3422c5f01b2fSopenharmony_ci    for (auto i = 0; i < 256; ++i)
3423c5f01b2fSopenharmony_ci    {
3424c5f01b2fSopenharmony_ci        const auto byte = static_cast<uint8_t>(i);
3425c5f01b2fSopenharmony_ci        CAPTURE(byte)
3426c5f01b2fSopenharmony_ci
3427c5f01b2fSopenharmony_ci        try
3428c5f01b2fSopenharmony_ci        {
3429c5f01b2fSopenharmony_ci            auto res = json::from_bjdata(std::vector<uint8_t>(1, byte));
3430c5f01b2fSopenharmony_ci        }
3431c5f01b2fSopenharmony_ci        catch (const json::parse_error& e)
3432c5f01b2fSopenharmony_ci        {
3433c5f01b2fSopenharmony_ci            // check that parse_error.112 is only thrown if the
3434c5f01b2fSopenharmony_ci            // first byte is not in the supported set
3435c5f01b2fSopenharmony_ci            INFO_WITH_TEMP(e.what());
3436c5f01b2fSopenharmony_ci            if (supported.find(byte) == supported.end())
3437c5f01b2fSopenharmony_ci            {
3438c5f01b2fSopenharmony_ci                CHECK(e.id == 112);
3439c5f01b2fSopenharmony_ci            }
3440c5f01b2fSopenharmony_ci            else
3441c5f01b2fSopenharmony_ci            {
3442c5f01b2fSopenharmony_ci                CHECK(e.id != 112);
3443c5f01b2fSopenharmony_ci            }
3444c5f01b2fSopenharmony_ci        }
3445c5f01b2fSopenharmony_ci    }
3446c5f01b2fSopenharmony_ci}
3447c5f01b2fSopenharmony_ci#endif
3448c5f01b2fSopenharmony_ci
3449c5f01b2fSopenharmony_ciTEST_CASE("BJData roundtrips" * doctest::skip())
3450c5f01b2fSopenharmony_ci{
3451c5f01b2fSopenharmony_ci    SECTION("input from self-generated BJData files")
3452c5f01b2fSopenharmony_ci    {
3453c5f01b2fSopenharmony_ci        for (std::string filename :
3454c5f01b2fSopenharmony_ci                {
3455c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json",
3456c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json.org/1.json",
3457c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json.org/2.json",
3458c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json.org/3.json",
3459c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json.org/4.json",
3460c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json.org/5.json",
3461c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json",
3462c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json",
3463c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json",
3464c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json",
3465c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json",
3466c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json",
3467c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json",
3468c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json",
3469c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json",
3470c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json",
3471c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json",
3472c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json",
3473c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json",
3474c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json",
3475c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json",
3476c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json",
3477c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json",
3478c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json",
3479c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json",
3480c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json",
3481c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json",
3482c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json",
3483c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json",
3484c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json",
3485c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json",
3486c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json",
3487c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json",
3488c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json",
3489c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json",
3490c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json",
3491c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json",
3492c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json",
3493c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_testsuite/sample.json",
3494c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_tests/pass1.json",
3495c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_tests/pass2.json",
3496c5f01b2fSopenharmony_ci                    TEST_DATA_DIRECTORY "/json_tests/pass3.json"
3497c5f01b2fSopenharmony_ci                })
3498c5f01b2fSopenharmony_ci        {
3499c5f01b2fSopenharmony_ci            CAPTURE(filename)
3500c5f01b2fSopenharmony_ci
3501c5f01b2fSopenharmony_ci            {
3502c5f01b2fSopenharmony_ci                INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
3503c5f01b2fSopenharmony_ci                // parse JSON file
3504c5f01b2fSopenharmony_ci                std::ifstream f_json(filename);
3505c5f01b2fSopenharmony_ci                json j1 = json::parse(f_json);
3506c5f01b2fSopenharmony_ci
3507c5f01b2fSopenharmony_ci                // parse BJData file
3508c5f01b2fSopenharmony_ci                auto packed = utils::read_binary_file(filename + ".bjdata");
3509c5f01b2fSopenharmony_ci                json j2;
3510c5f01b2fSopenharmony_ci                CHECK_NOTHROW(j2 = json::from_bjdata(packed));
3511c5f01b2fSopenharmony_ci
3512c5f01b2fSopenharmony_ci                // compare parsed JSON values
3513c5f01b2fSopenharmony_ci                CHECK(j1 == j2);
3514c5f01b2fSopenharmony_ci            }
3515c5f01b2fSopenharmony_ci
3516c5f01b2fSopenharmony_ci            {
3517c5f01b2fSopenharmony_ci                INFO_WITH_TEMP(filename + ": std::ifstream");
3518c5f01b2fSopenharmony_ci                // parse JSON file
3519c5f01b2fSopenharmony_ci                std::ifstream f_json(filename);
3520c5f01b2fSopenharmony_ci                json j1 = json::parse(f_json);
3521c5f01b2fSopenharmony_ci
3522c5f01b2fSopenharmony_ci                // parse BJData file
3523c5f01b2fSopenharmony_ci                std::ifstream f_bjdata(filename + ".bjdata", std::ios::binary);
3524c5f01b2fSopenharmony_ci                json j2;
3525c5f01b2fSopenharmony_ci                CHECK_NOTHROW(j2 = json::from_bjdata(f_bjdata));
3526c5f01b2fSopenharmony_ci
3527c5f01b2fSopenharmony_ci                // compare parsed JSON values
3528c5f01b2fSopenharmony_ci                CHECK(j1 == j2);
3529c5f01b2fSopenharmony_ci            }
3530c5f01b2fSopenharmony_ci
3531c5f01b2fSopenharmony_ci            {
3532c5f01b2fSopenharmony_ci                INFO_WITH_TEMP(filename + ": output to output adapters");
3533c5f01b2fSopenharmony_ci                // parse JSON file
3534c5f01b2fSopenharmony_ci                std::ifstream f_json(filename);
3535c5f01b2fSopenharmony_ci                json j1 = json::parse(f_json);
3536c5f01b2fSopenharmony_ci
3537c5f01b2fSopenharmony_ci                // parse BJData file
3538c5f01b2fSopenharmony_ci                auto packed = utils::read_binary_file(filename + ".bjdata");
3539c5f01b2fSopenharmony_ci
3540c5f01b2fSopenharmony_ci                {
3541c5f01b2fSopenharmony_ci                    INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
3542c5f01b2fSopenharmony_ci                    std::vector<uint8_t> vec;
3543c5f01b2fSopenharmony_ci                    json::to_bjdata(j1, vec);
3544c5f01b2fSopenharmony_ci                    CHECK(vec == packed);
3545c5f01b2fSopenharmony_ci                }
3546c5f01b2fSopenharmony_ci            }
3547c5f01b2fSopenharmony_ci        }
3548c5f01b2fSopenharmony_ci    }
3549c5f01b2fSopenharmony_ci}
3550