mirror of
https://github.com/boostorg/json.git
synced 2025-05-12 06:01:41 +00:00
Add standalone test_suite
This commit is contained in:
parent
3844c0eb09
commit
07246e2909
@ -146,6 +146,7 @@ endif()
|
|||||||
file (GLOB_RECURSE PROJECT_FILES
|
file (GLOB_RECURSE PROJECT_FILES
|
||||||
${PROJECT_SOURCE_DIR}/include/boost/json/*.hpp
|
${PROJECT_SOURCE_DIR}/include/boost/json/*.hpp
|
||||||
${PROJECT_SOURCE_DIR}/include/boost/json/*.ipp
|
${PROJECT_SOURCE_DIR}/include/boost/json/*.ipp
|
||||||
|
${PROJECT_SOURCE_DIR}/include/boost/json/*.natvis
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory (bench)
|
add_subdirectory (bench)
|
||||||
|
@ -16,6 +16,8 @@ GroupSources(bench "/")
|
|||||||
# Disable auto-linking
|
# Disable auto-linking
|
||||||
add_definitions(-DBOOST_ALL_NO_LIB=1)
|
add_definitions(-DBOOST_ALL_NO_LIB=1)
|
||||||
|
|
||||||
|
include_directories(../test)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
if (CMAKE_BUILD_TYPE EQUAL "Debug")
|
if (CMAKE_BUILD_TYPE EQUAL "Debug")
|
||||||
else()
|
else()
|
||||||
|
@ -24,6 +24,8 @@ else
|
|||||||
|
|
||||||
exe bench :
|
exe bench :
|
||||||
bench.cpp
|
bench.cpp
|
||||||
: :
|
:
|
||||||
|
<include>../test
|
||||||
|
:
|
||||||
$(LIB)
|
$(LIB)
|
||||||
;
|
;
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
#include "lib/rapidjson/include/rapidjson/stringbuffer.h"
|
#include "lib/rapidjson/include/rapidjson/stringbuffer.h"
|
||||||
|
|
||||||
#include <boost/json.hpp>
|
#include <boost/json.hpp>
|
||||||
#include <boost/beast/_experimental/unit_test/dstream.hpp>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -27,6 +26,8 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
References
|
References
|
||||||
@ -37,14 +38,12 @@ http://seriot.ch/parsing_json.php
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace beast = boost::beast;
|
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
using clock_type = std::chrono::steady_clock;
|
using clock_type = std::chrono::steady_clock;
|
||||||
|
|
||||||
beast::unit_test::dstream dout(std::cerr);
|
::test_suite::debug_stream dout(std::cerr);
|
||||||
std::stringstream strout;
|
std::stringstream strout;
|
||||||
|
|
||||||
#if defined(BOOST_MSVC)
|
#if defined(BOOST_MSVC)
|
||||||
|
@ -33,7 +33,7 @@ array_impl(
|
|||||||
sizeof(table) + 1)
|
sizeof(table) + 1)
|
||||||
/ sizeof(table)
|
/ sizeof(table)
|
||||||
* sizeof(table),
|
* sizeof(table),
|
||||||
std::max(
|
(std::max)(
|
||||||
alignof(table),
|
alignof(table),
|
||||||
alignof(value)))) table;
|
alignof(value)))) table;
|
||||||
tab_->capacity = static_cast<
|
tab_->capacity = static_cast<
|
||||||
@ -88,7 +88,7 @@ destroy_impl(
|
|||||||
sizeof(table) + 1)
|
sizeof(table) + 1)
|
||||||
/ sizeof(table)
|
/ sizeof(table)
|
||||||
* sizeof(table),
|
* sizeof(table),
|
||||||
std::max(
|
(std::max)(
|
||||||
alignof(table),
|
alignof(table),
|
||||||
alignof(value)));
|
alignof(value)));
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,16 @@
|
|||||||
# Official repository: https://github.com/vinniefalco/json
|
# Official repository: https://github.com/vinniefalco/json
|
||||||
#
|
#
|
||||||
|
|
||||||
source_group (json FILES ${PROJECT_SOURCE_DIR}/include/boost/json.hpp)
|
source_group (boost FILES ${PROJECT_SOURCE_DIR}/include/boost/json.hpp)
|
||||||
source_group (json FILES ${PROJECT_SOURCE_DIR}/include/boost/pilfer.hpp)
|
source_group (boost FILES ${PROJECT_SOURCE_DIR}/include/boost/pilfer.hpp)
|
||||||
source_group (TREE ${PROJECT_SOURCE_DIR}/include/boost/json PREFIX json FILES ${PROJECT_FILES})
|
source_group (TREE ${PROJECT_SOURCE_DIR}/include/boost/json PREFIX json FILES ${PROJECT_FILES})
|
||||||
|
|
||||||
GroupSources(test "/")
|
GroupSources(test "/")
|
||||||
|
|
||||||
add_definitions(-DBOOST_JSON_HEADER_ONLY=1)
|
add_definitions(-DBOOST_JSON_HEADER_ONLY=1)
|
||||||
|
|
||||||
|
include_directories(.)
|
||||||
|
|
||||||
add_executable (json-tests
|
add_executable (json-tests
|
||||||
${BEAST_FILES}
|
${BEAST_FILES}
|
||||||
${PROJECT_FILES}
|
${PROJECT_FILES}
|
||||||
@ -24,6 +26,7 @@ add_executable (json-tests
|
|||||||
${PROJECT_SOURCE_DIR}/src/src.cpp
|
${PROJECT_SOURCE_DIR}/src/src.cpp
|
||||||
Jamfile
|
Jamfile
|
||||||
test.hpp
|
test.hpp
|
||||||
|
test_suite.hpp
|
||||||
parse-vectors.hpp
|
parse-vectors.hpp
|
||||||
main.cpp
|
main.cpp
|
||||||
_detail_number.cpp
|
_detail_number.cpp
|
||||||
|
@ -58,6 +58,7 @@ for local f in $(SOURCES)
|
|||||||
RUN_TESTS += [
|
RUN_TESTS += [
|
||||||
run $(f) main.cpp : : :
|
run $(f) main.cpp : : :
|
||||||
$(LIB)
|
$(LIB)
|
||||||
|
<include>.
|
||||||
] ;
|
] ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ for local f in $(LIMIT_SOURCES)
|
|||||||
RUN_TESTS += [
|
RUN_TESTS += [
|
||||||
run $(f) main.cpp : : :
|
run $(f) main.cpp : : :
|
||||||
<source>../src/src.cpp
|
<source>../src/src.cpp
|
||||||
|
<include>.
|
||||||
<define>BOOST_JSON_MAX_STRING_SIZE=1000
|
<define>BOOST_JSON_MAX_STRING_SIZE=1000
|
||||||
<define>BOOST_JSON_MAX_OBJECT_SIZE=30
|
<define>BOOST_JSON_MAX_OBJECT_SIZE=30
|
||||||
<define>BOOST_JSON_MAX_ARRAY_SIZE=100
|
<define>BOOST_JSON_MAX_ARRAY_SIZE=100
|
||||||
|
@ -10,14 +10,15 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/json/detail/number.hpp>
|
#include <boost/json/detail/number.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
class number_parser_test : public beast::unit_test::suite
|
class number_parser_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<class F>
|
template<class F>
|
||||||
@ -30,9 +31,9 @@ public:
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
number_parser p;
|
number_parser p;
|
||||||
p.write(s.data(), s.size(), ec);
|
p.write(s.data(), s.size(), ec);
|
||||||
if(BEAST_EXPECTS(! ec, ec.message()))
|
if(BOOST_TEST(! ec))
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(p.is_done());
|
BOOST_TEST(p.is_done());
|
||||||
f(p.get());
|
f(p.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,18 +42,17 @@ public:
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
number_parser p;
|
number_parser p;
|
||||||
p.write_some(s.data(), s.size(), ec);
|
p.write_some(s.data(), s.size(), ec);
|
||||||
if(! BEAST_EXPECTS(
|
if(! BOOST_TEST(! ec))
|
||||||
! ec, ec.message()))
|
|
||||||
break;
|
break;
|
||||||
auto n = p.write_some("x", 1, ec);
|
auto n = p.write_some("x", 1, ec);
|
||||||
if(! BEAST_EXPECT(
|
if(! BOOST_TEST(
|
||||||
p.is_done()))
|
p.is_done()))
|
||||||
break;
|
break;
|
||||||
if(! BEAST_EXPECT(n == 0))
|
if(! BOOST_TEST(n == 0))
|
||||||
break;
|
break;
|
||||||
f(p.get());
|
f(p.get());
|
||||||
p.finish(ec);
|
p.finish(ec);
|
||||||
BEAST_EXPECTS(! ec, ec.message());
|
BOOST_TEST(! ec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for(size_t i = 1; i < s.size(); ++i)
|
for(size_t i = 1; i < s.size(); ++i)
|
||||||
@ -60,13 +60,13 @@ public:
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
number_parser p;
|
number_parser p;
|
||||||
p.write_some(s.data(), i, ec);
|
p.write_some(s.data(), i, ec);
|
||||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
if(! BOOST_TEST(! ec))
|
||||||
continue;
|
continue;
|
||||||
p.write(
|
p.write(
|
||||||
s.data() + i, s.size() - i, ec);
|
s.data() + i, s.size() - i, ec);
|
||||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
if(! BOOST_TEST(! ec))
|
||||||
continue;
|
continue;
|
||||||
BEAST_EXPECT(p.is_done());
|
BOOST_TEST(p.is_done());
|
||||||
f(p.get());
|
f(p.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ public:
|
|||||||
{
|
{
|
||||||
number_parser p;
|
number_parser p;
|
||||||
p.write(s.data(), s.size(), xec);
|
p.write(s.data(), s.size(), xec);
|
||||||
BEAST_EXPECT(xec);
|
BOOST_TEST(xec);
|
||||||
}
|
}
|
||||||
for(size_t i = 1; i < s.size(); ++i)
|
for(size_t i = 1; i < s.size(); ++i)
|
||||||
{
|
{
|
||||||
@ -87,14 +87,14 @@ public:
|
|||||||
p.write_some(s.data(), i, ec);
|
p.write_some(s.data(), i, ec);
|
||||||
if(ec == xec)
|
if(ec == xec)
|
||||||
{
|
{
|
||||||
BEAST_PASS();
|
BOOST_TEST_PASS();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
if(! BOOST_TEST(! ec))
|
||||||
continue;
|
continue;
|
||||||
p.write(
|
p.write(
|
||||||
s.data() + i, s.size() - i, ec);
|
s.data() + i, s.size() - i, ec);
|
||||||
BEAST_EXPECT(ec == xec);
|
BOOST_TEST(ec == xec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,9 +106,9 @@ public:
|
|||||||
grind(s,
|
grind(s,
|
||||||
[&](detail::number num)
|
[&](detail::number num)
|
||||||
{
|
{
|
||||||
if( BEAST_EXPECT(
|
if( BOOST_TEST(
|
||||||
num.kind == kind::int64))
|
num.kind == kind::int64))
|
||||||
BEAST_EXPECT(num.i == i);
|
BOOST_TEST(num.i == i);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,9 +120,9 @@ public:
|
|||||||
grind(s,
|
grind(s,
|
||||||
[&](detail::number num)
|
[&](detail::number num)
|
||||||
{
|
{
|
||||||
if( BEAST_EXPECT(
|
if( BOOST_TEST(
|
||||||
num.kind == kind::uint64))
|
num.kind == kind::uint64))
|
||||||
BEAST_EXPECT(num.u == u);
|
BOOST_TEST(num.u == u);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,9 +134,9 @@ public:
|
|||||||
grind(s,
|
grind(s,
|
||||||
[&](detail::number num)
|
[&](detail::number num)
|
||||||
{
|
{
|
||||||
if( BEAST_EXPECT(
|
if( BOOST_TEST(
|
||||||
num.kind == kind::double_))
|
num.kind == kind::double_))
|
||||||
BEAST_EXPECT(num.d == d);
|
BOOST_TEST(num.d == d);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,24 +293,24 @@ public:
|
|||||||
// maybe_init
|
// maybe_init
|
||||||
{
|
{
|
||||||
number_parser p;
|
number_parser p;
|
||||||
BEAST_EXPECT(! p.maybe_init(0));
|
BOOST_TEST(! p.maybe_init(0));
|
||||||
BEAST_EXPECT(! p.maybe_init('A'));
|
BOOST_TEST(! p.maybe_init('A'));
|
||||||
BEAST_EXPECT(! p.maybe_init('a'));
|
BOOST_TEST(! p.maybe_init('a'));
|
||||||
BEAST_EXPECT(! p.maybe_init('.'));
|
BOOST_TEST(! p.maybe_init('.'));
|
||||||
BEAST_EXPECT(! p.maybe_init('!'));
|
BOOST_TEST(! p.maybe_init('!'));
|
||||||
BEAST_EXPECT(! p.maybe_init(' '));
|
BOOST_TEST(! p.maybe_init(' '));
|
||||||
BEAST_EXPECT(p.maybe_init('0')); p.reset();
|
BOOST_TEST(p.maybe_init('0')); p.reset();
|
||||||
BEAST_EXPECT(p.maybe_init('1')); p.reset();
|
BOOST_TEST(p.maybe_init('1')); p.reset();
|
||||||
BEAST_EXPECT(p.maybe_init('2')); p.reset();
|
BOOST_TEST(p.maybe_init('2')); p.reset();
|
||||||
BEAST_EXPECT(p.maybe_init('3')); p.reset();
|
BOOST_TEST(p.maybe_init('3')); p.reset();
|
||||||
BEAST_EXPECT(p.maybe_init('4')); p.reset();
|
BOOST_TEST(p.maybe_init('4')); p.reset();
|
||||||
BEAST_EXPECT(p.maybe_init('5')); p.reset();
|
BOOST_TEST(p.maybe_init('5')); p.reset();
|
||||||
BEAST_EXPECT(p.maybe_init('6')); p.reset();
|
BOOST_TEST(p.maybe_init('6')); p.reset();
|
||||||
BEAST_EXPECT(p.maybe_init('7')); p.reset();
|
BOOST_TEST(p.maybe_init('7')); p.reset();
|
||||||
BEAST_EXPECT(p.maybe_init('8')); p.reset();
|
BOOST_TEST(p.maybe_init('8')); p.reset();
|
||||||
BEAST_EXPECT(p.maybe_init('9')); p.reset();
|
BOOST_TEST(p.maybe_init('9')); p.reset();
|
||||||
BEAST_EXPECT(p.maybe_init('0')); p.reset();
|
BOOST_TEST(p.maybe_init('0')); p.reset();
|
||||||
BEAST_EXPECT(p.maybe_init('-')); p.reset();
|
BOOST_TEST(p.maybe_init('-')); p.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish
|
// finish
|
||||||
@ -318,25 +318,23 @@ public:
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
number_parser p;
|
number_parser p;
|
||||||
p.write_some("0x", 2, ec);
|
p.write_some("0x", 2, ec);
|
||||||
if(BEAST_EXPECTS(! ec,
|
if(BOOST_TEST(! ec))
|
||||||
ec.message()))
|
|
||||||
{
|
{
|
||||||
p.finish(ec);
|
p.finish(ec);
|
||||||
BEAST_EXPECTS(! ec,
|
BOOST_TEST(! ec);
|
||||||
ec.message());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
testParse();
|
testParse();
|
||||||
testMembers();
|
testMembers();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,number_parser);
|
TEST_SUITE(number_parser_test, "boost.json.detail.number_parser");
|
||||||
|
|
||||||
} // detail
|
} // detail
|
||||||
} // json
|
} // json
|
||||||
|
355
test/array.cpp
355
test/array.cpp
@ -10,14 +10,13 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/json/array.hpp>
|
#include <boost/json/array.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
|
|
||||||
#include "test.hpp"
|
#include "test.hpp"
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
class array_test : public beast::unit_test::suite
|
class array_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using init_list =
|
using init_list =
|
||||||
@ -44,10 +43,10 @@ public:
|
|||||||
void
|
void
|
||||||
check(array const& a)
|
check(array const& a)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(a.size() == 3);
|
BOOST_TEST(a.size() == 3);
|
||||||
BEAST_EXPECT(a[0].is_number());
|
BOOST_TEST(a[0].is_number());
|
||||||
BEAST_EXPECT(a[1].is_bool());
|
BOOST_TEST(a[1].is_bool());
|
||||||
BEAST_EXPECT(a[2].is_string());
|
BOOST_TEST(a[2].is_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -70,8 +69,8 @@ public:
|
|||||||
// array()
|
// array()
|
||||||
{
|
{
|
||||||
array a;
|
array a;
|
||||||
BEAST_EXPECT(a.empty());
|
BOOST_TEST(a.empty());
|
||||||
BEAST_EXPECT(a.size() == 0);
|
BOOST_TEST(a.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// array(storage_ptr)
|
// array(storage_ptr)
|
||||||
@ -85,9 +84,9 @@ public:
|
|||||||
// default storage
|
// default storage
|
||||||
{
|
{
|
||||||
array a(3, true);
|
array a(3, true);
|
||||||
BEAST_EXPECT(a.size() == 3);
|
BOOST_TEST(a.size() == 3);
|
||||||
for(auto const& v : a)
|
for(auto const& v : a)
|
||||||
BEAST_EXPECT(v.is_bool());
|
BOOST_TEST(v.is_bool());
|
||||||
check_storage(a, storage_ptr{});
|
check_storage(a, storage_ptr{});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +99,7 @@ public:
|
|||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
{
|
{
|
||||||
array a(3, true, sp);
|
array a(3, true, sp);
|
||||||
BEAST_EXPECT(a.size() == 3);
|
BOOST_TEST(a.size() == 3);
|
||||||
check_storage(a, sp);
|
check_storage(a, sp);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -110,18 +109,18 @@ public:
|
|||||||
// default storage
|
// default storage
|
||||||
{
|
{
|
||||||
array a(3);
|
array a(3);
|
||||||
BEAST_EXPECT(a.size() == 3);
|
BOOST_TEST(a.size() == 3);
|
||||||
for(auto const& v : a)
|
for(auto const& v : a)
|
||||||
BEAST_EXPECT(v.is_null());
|
BOOST_TEST(v.is_null());
|
||||||
check_storage(a, storage_ptr{});
|
check_storage(a, storage_ptr{});
|
||||||
}
|
}
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
{
|
{
|
||||||
array a(3, sp);
|
array a(3, sp);
|
||||||
BEAST_EXPECT(a.size() == 3);
|
BOOST_TEST(a.size() == 3);
|
||||||
for(auto const& v : a)
|
for(auto const& v : a)
|
||||||
BEAST_EXPECT(v.is_null());
|
BOOST_TEST(v.is_null());
|
||||||
check_storage(a, sp);
|
check_storage(a, sp);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -133,11 +132,11 @@ public:
|
|||||||
init_list init{ 0, 1, str_, 3, 4 };
|
init_list init{ 0, 1, str_, 3, 4 };
|
||||||
array a(init.begin(), init.end());
|
array a(init.begin(), init.end());
|
||||||
check_storage(a, storage_ptr{});
|
check_storage(a, storage_ptr{});
|
||||||
BEAST_EXPECT(a[0].as_int64() == 0);
|
BOOST_TEST(a[0].as_int64() == 0);
|
||||||
BEAST_EXPECT(a[1].as_int64() == 1);
|
BOOST_TEST(a[1].as_int64() == 1);
|
||||||
BEAST_EXPECT(a[2].as_string() == str_);
|
BOOST_TEST(a[2].as_string() == str_);
|
||||||
BEAST_EXPECT(a[3].as_int64() == 3);
|
BOOST_TEST(a[3].as_int64() == 3);
|
||||||
BEAST_EXPECT(a[4].as_int64() == 4);
|
BOOST_TEST(a[4].as_int64() == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// random iterator
|
// random iterator
|
||||||
@ -198,7 +197,7 @@ public:
|
|||||||
init_list init{ 1, true, str_ };
|
init_list init{ 1, true, str_ };
|
||||||
array a1(init.begin(), init.end());
|
array a1(init.begin(), init.end());
|
||||||
array a2(pilfer(a1));
|
array a2(pilfer(a1));
|
||||||
BEAST_EXPECT(a1.empty());
|
BOOST_TEST(a1.empty());
|
||||||
check(a2);
|
check(a2);
|
||||||
check_storage(a2, storage_ptr{});
|
check_storage(a2, storage_ptr{});
|
||||||
}
|
}
|
||||||
@ -208,7 +207,7 @@ public:
|
|||||||
init_list init{ 1, true, str_ };
|
init_list init{ 1, true, str_ };
|
||||||
array a1(init.begin(), init.end());
|
array a1(init.begin(), init.end());
|
||||||
array a2 = std::move(a1);
|
array a2 = std::move(a1);
|
||||||
BEAST_EXPECT(a1.empty());
|
BOOST_TEST(a1.empty());
|
||||||
check(a2);
|
check(a2);
|
||||||
check_storage(a2, storage_ptr{});
|
check_storage(a2, storage_ptr{});
|
||||||
}
|
}
|
||||||
@ -220,7 +219,7 @@ public:
|
|||||||
array a1(init.begin(), init.end());
|
array a1(init.begin(), init.end());
|
||||||
array a2(
|
array a2(
|
||||||
std::move(a1), storage_ptr{});
|
std::move(a1), storage_ptr{});
|
||||||
BEAST_EXPECT(a1.empty());
|
BOOST_TEST(a1.empty());
|
||||||
check(a2);
|
check(a2);
|
||||||
check_storage(a1, storage_ptr{});
|
check_storage(a1, storage_ptr{});
|
||||||
check_storage(a2, storage_ptr{});
|
check_storage(a2, storage_ptr{});
|
||||||
@ -231,7 +230,7 @@ public:
|
|||||||
init_list init{ 1, true, str_ };
|
init_list init{ 1, true, str_ };
|
||||||
array a1(init.begin(), init.end());
|
array a1(init.begin(), init.end());
|
||||||
array a2(std::move(a1), sp);
|
array a2(std::move(a1), sp);
|
||||||
BEAST_EXPECT(! a1.empty());
|
BOOST_TEST(! a1.empty());
|
||||||
check(a2);
|
check(a2);
|
||||||
check_storage(a1, storage_ptr{});
|
check_storage(a1, storage_ptr{});
|
||||||
check_storage(a2, sp);
|
check_storage(a2, sp);
|
||||||
@ -298,7 +297,7 @@ public:
|
|||||||
array a1({1, true, str_});
|
array a1({1, true, str_});
|
||||||
array a2({nullptr, object{}, 1.f});
|
array a2({nullptr, object{}, 1.f});
|
||||||
a2 = std::move(a1);
|
a2 = std::move(a1);
|
||||||
BEAST_EXPECT(a1.empty());
|
BOOST_TEST(a1.empty());
|
||||||
check(a2);
|
check(a2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,8 +306,8 @@ public:
|
|||||||
array a1;
|
array a1;
|
||||||
array a2;
|
array a2;
|
||||||
a2 = std::move(a1);
|
a2 = std::move(a1);
|
||||||
BEAST_EXPECT(a1.empty());
|
BOOST_TEST(a1.empty());
|
||||||
BEAST_EXPECT(a2.empty());
|
BOOST_TEST(a2.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
@ -369,85 +368,85 @@ public:
|
|||||||
// at(pos)
|
// at(pos)
|
||||||
{
|
{
|
||||||
array a({1, true, str_});
|
array a({1, true, str_});
|
||||||
BEAST_EXPECT(a.at(0).is_number());
|
BOOST_TEST(a.at(0).is_number());
|
||||||
BEAST_EXPECT(a.at(1).is_bool());
|
BOOST_TEST(a.at(1).is_bool());
|
||||||
BEAST_EXPECT(a.at(2).is_string());
|
BOOST_TEST(a.at(2).is_string());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
a.at(3);
|
a.at(3);
|
||||||
BEAST_FAIL();
|
BOOST_TEST_FAIL();
|
||||||
}
|
}
|
||||||
catch(std::out_of_range const&)
|
catch(std::out_of_range const&)
|
||||||
{
|
{
|
||||||
BEAST_PASS();
|
BOOST_TEST_PASS();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// at(pos) const
|
// at(pos) const
|
||||||
{
|
{
|
||||||
array const a({1, true, str_});
|
array const a({1, true, str_});
|
||||||
BEAST_EXPECT(a.at(0).is_number());
|
BOOST_TEST(a.at(0).is_number());
|
||||||
BEAST_EXPECT(a.at(1).is_bool());
|
BOOST_TEST(a.at(1).is_bool());
|
||||||
BEAST_EXPECT(a.at(2).is_string());
|
BOOST_TEST(a.at(2).is_string());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
a.at(3);
|
a.at(3);
|
||||||
BEAST_FAIL();
|
BOOST_TEST_FAIL();
|
||||||
}
|
}
|
||||||
catch(std::out_of_range const&)
|
catch(std::out_of_range const&)
|
||||||
{
|
{
|
||||||
BEAST_PASS();
|
BOOST_TEST_PASS();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator[&](size_type)
|
// operator[&](size_type)
|
||||||
{
|
{
|
||||||
array a({1, true, str_});
|
array a({1, true, str_});
|
||||||
BEAST_EXPECT(a[0].is_number());
|
BOOST_TEST(a[0].is_number());
|
||||||
BEAST_EXPECT(a[1].is_bool());
|
BOOST_TEST(a[1].is_bool());
|
||||||
BEAST_EXPECT(a[2].is_string());
|
BOOST_TEST(a[2].is_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator[&](size_type) const
|
// operator[&](size_type) const
|
||||||
{
|
{
|
||||||
array const a({1, true, str_});
|
array const a({1, true, str_});
|
||||||
BEAST_EXPECT(a[0].is_number());
|
BOOST_TEST(a[0].is_number());
|
||||||
BEAST_EXPECT(a[1].is_bool());
|
BOOST_TEST(a[1].is_bool());
|
||||||
BEAST_EXPECT(a[2].is_string());
|
BOOST_TEST(a[2].is_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// front()
|
// front()
|
||||||
{
|
{
|
||||||
array a({1, true, str_});
|
array a({1, true, str_});
|
||||||
BEAST_EXPECT(a.front().is_number());
|
BOOST_TEST(a.front().is_number());
|
||||||
}
|
}
|
||||||
|
|
||||||
// front() const
|
// front() const
|
||||||
{
|
{
|
||||||
array const a({1, true, str_});
|
array const a({1, true, str_});
|
||||||
BEAST_EXPECT(a.front().is_number());
|
BOOST_TEST(a.front().is_number());
|
||||||
}
|
}
|
||||||
|
|
||||||
// back()
|
// back()
|
||||||
{
|
{
|
||||||
array a({1, true, str_});
|
array a({1, true, str_});
|
||||||
BEAST_EXPECT(a.back().is_string());
|
BOOST_TEST(a.back().is_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// back() const
|
// back() const
|
||||||
{
|
{
|
||||||
array const a({1, true, str_});
|
array const a({1, true, str_});
|
||||||
BEAST_EXPECT(a.back().is_string());
|
BOOST_TEST(a.back().is_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// data()
|
// data()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
array a({1, true, str_});
|
array a({1, true, str_});
|
||||||
BEAST_EXPECT(a.data() == &a[0]);
|
BOOST_TEST(a.data() == &a[0]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(array{}.data() == nullptr);
|
BOOST_TEST(array{}.data() == nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,11 +454,11 @@ public:
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
array const a({1, true, str_});
|
array const a({1, true, str_});
|
||||||
BEAST_EXPECT(a.data() == &a[0]);
|
BOOST_TEST(a.data() == &a[0]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
array const a{};
|
array const a{};
|
||||||
BEAST_EXPECT(a.data() == nullptr);
|
BOOST_TEST(a.data() == nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -472,104 +471,104 @@ public:
|
|||||||
|
|
||||||
{
|
{
|
||||||
auto it = a.begin();
|
auto it = a.begin();
|
||||||
BEAST_EXPECT(it->is_number()); ++it;
|
BOOST_TEST(it->is_number()); ++it;
|
||||||
BEAST_EXPECT(it->is_bool()); it++;
|
BOOST_TEST(it->is_bool()); it++;
|
||||||
BEAST_EXPECT(it->is_string()); ++it;
|
BOOST_TEST(it->is_string()); ++it;
|
||||||
BEAST_EXPECT(it == a.end());
|
BOOST_TEST(it == a.end());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = a.cbegin();
|
auto it = a.cbegin();
|
||||||
BEAST_EXPECT(it->is_number()); ++it;
|
BOOST_TEST(it->is_number()); ++it;
|
||||||
BEAST_EXPECT(it->is_bool()); it++;
|
BOOST_TEST(it->is_bool()); it++;
|
||||||
BEAST_EXPECT(it->is_string()); ++it;
|
BOOST_TEST(it->is_string()); ++it;
|
||||||
BEAST_EXPECT(it == a.cend());
|
BOOST_TEST(it == a.cend());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = ac.begin();
|
auto it = ac.begin();
|
||||||
BEAST_EXPECT(it->is_number()); ++it;
|
BOOST_TEST(it->is_number()); ++it;
|
||||||
BEAST_EXPECT(it->is_bool()); it++;
|
BOOST_TEST(it->is_bool()); it++;
|
||||||
BEAST_EXPECT(it->is_string()); ++it;
|
BOOST_TEST(it->is_string()); ++it;
|
||||||
BEAST_EXPECT(it == ac.end());
|
BOOST_TEST(it == ac.end());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = a.end();
|
auto it = a.end();
|
||||||
--it; BEAST_EXPECT(it->is_string());
|
--it; BOOST_TEST(it->is_string());
|
||||||
it--; BEAST_EXPECT(it->is_bool());
|
it--; BOOST_TEST(it->is_bool());
|
||||||
--it; BEAST_EXPECT(it->is_number());
|
--it; BOOST_TEST(it->is_number());
|
||||||
BEAST_EXPECT(it == a.begin());
|
BOOST_TEST(it == a.begin());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = a.cend();
|
auto it = a.cend();
|
||||||
--it; BEAST_EXPECT(it->is_string());
|
--it; BOOST_TEST(it->is_string());
|
||||||
it--; BEAST_EXPECT(it->is_bool());
|
it--; BOOST_TEST(it->is_bool());
|
||||||
--it; BEAST_EXPECT(it->is_number());
|
--it; BOOST_TEST(it->is_number());
|
||||||
BEAST_EXPECT(it == a.cbegin());
|
BOOST_TEST(it == a.cbegin());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = ac.end();
|
auto it = ac.end();
|
||||||
--it; BEAST_EXPECT(it->is_string());
|
--it; BOOST_TEST(it->is_string());
|
||||||
it--; BEAST_EXPECT(it->is_bool());
|
it--; BOOST_TEST(it->is_bool());
|
||||||
--it; BEAST_EXPECT(it->is_number());
|
--it; BOOST_TEST(it->is_number());
|
||||||
BEAST_EXPECT(it == ac.begin());
|
BOOST_TEST(it == ac.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto it = a.rbegin();
|
auto it = a.rbegin();
|
||||||
BEAST_EXPECT(it->is_string()); ++it;
|
BOOST_TEST(it->is_string()); ++it;
|
||||||
BEAST_EXPECT(it->is_bool()); it++;
|
BOOST_TEST(it->is_bool()); it++;
|
||||||
BEAST_EXPECT(it->is_number()); ++it;
|
BOOST_TEST(it->is_number()); ++it;
|
||||||
BEAST_EXPECT(it == a.rend());
|
BOOST_TEST(it == a.rend());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = a.crbegin();
|
auto it = a.crbegin();
|
||||||
BEAST_EXPECT(it->is_string()); ++it;
|
BOOST_TEST(it->is_string()); ++it;
|
||||||
BEAST_EXPECT(it->is_bool()); it++;
|
BOOST_TEST(it->is_bool()); it++;
|
||||||
BEAST_EXPECT(it->is_number()); ++it;
|
BOOST_TEST(it->is_number()); ++it;
|
||||||
BEAST_EXPECT(it == a.crend());
|
BOOST_TEST(it == a.crend());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = ac.rbegin();
|
auto it = ac.rbegin();
|
||||||
BEAST_EXPECT(it->is_string()); ++it;
|
BOOST_TEST(it->is_string()); ++it;
|
||||||
BEAST_EXPECT(it->is_bool()); it++;
|
BOOST_TEST(it->is_bool()); it++;
|
||||||
BEAST_EXPECT(it->is_number()); ++it;
|
BOOST_TEST(it->is_number()); ++it;
|
||||||
BEAST_EXPECT(it == ac.rend());
|
BOOST_TEST(it == ac.rend());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = a.rend();
|
auto it = a.rend();
|
||||||
--it; BEAST_EXPECT(it->is_number());
|
--it; BOOST_TEST(it->is_number());
|
||||||
it--; BEAST_EXPECT(it->is_bool());
|
it--; BOOST_TEST(it->is_bool());
|
||||||
--it; BEAST_EXPECT(it->is_string());
|
--it; BOOST_TEST(it->is_string());
|
||||||
BEAST_EXPECT(it == a.rbegin());
|
BOOST_TEST(it == a.rbegin());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = a.crend();
|
auto it = a.crend();
|
||||||
--it; BEAST_EXPECT(it->is_number());
|
--it; BOOST_TEST(it->is_number());
|
||||||
it--; BEAST_EXPECT(it->is_bool());
|
it--; BOOST_TEST(it->is_bool());
|
||||||
--it; BEAST_EXPECT(it->is_string());
|
--it; BOOST_TEST(it->is_string());
|
||||||
BEAST_EXPECT(it == a.crbegin());
|
BOOST_TEST(it == a.crbegin());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = ac.rend();
|
auto it = ac.rend();
|
||||||
--it; BEAST_EXPECT(it->is_number());
|
--it; BOOST_TEST(it->is_number());
|
||||||
it--; BEAST_EXPECT(it->is_bool());
|
it--; BOOST_TEST(it->is_bool());
|
||||||
--it; BEAST_EXPECT(it->is_string());
|
--it; BOOST_TEST(it->is_string());
|
||||||
BEAST_EXPECT(it == ac.rbegin());
|
BOOST_TEST(it == ac.rbegin());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
array a2;
|
array a2;
|
||||||
array const& ca2(a2);
|
array const& ca2(a2);
|
||||||
BEAST_EXPECT(std::distance(
|
BOOST_TEST(std::distance(
|
||||||
a2.begin(), a2.end()) == 0);
|
a2.begin(), a2.end()) == 0);
|
||||||
BEAST_EXPECT(std::distance(
|
BOOST_TEST(std::distance(
|
||||||
ca2.begin(), ca2.end()) == 0);
|
ca2.begin(), ca2.end()) == 0);
|
||||||
BEAST_EXPECT(std::distance(
|
BOOST_TEST(std::distance(
|
||||||
ca2.cbegin(), ca2.cend()) == 0);
|
ca2.cbegin(), ca2.cend()) == 0);
|
||||||
BEAST_EXPECT(std::distance(
|
BOOST_TEST(std::distance(
|
||||||
a2.rbegin(), a2.rend()) == 0);
|
a2.rbegin(), a2.rend()) == 0);
|
||||||
BEAST_EXPECT(std::distance(
|
BOOST_TEST(std::distance(
|
||||||
ca2.rbegin(), ca2.rend()) == 0);
|
ca2.rbegin(), ca2.rend()) == 0);
|
||||||
BEAST_EXPECT(std::distance(
|
BOOST_TEST(std::distance(
|
||||||
ca2.crbegin(), ca2.crend()) == 0);
|
ca2.crbegin(), ca2.crend()) == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -581,32 +580,32 @@ public:
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
array a;
|
array a;
|
||||||
BEAST_EXPECT(a.empty());
|
BOOST_TEST(a.empty());
|
||||||
a.emplace_back(1);
|
a.emplace_back(1);
|
||||||
BEAST_EXPECT(! a.empty());
|
BOOST_TEST(! a.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
array a({1, 2});
|
array a({1, 2});
|
||||||
BEAST_EXPECT(! a.empty());
|
BOOST_TEST(! a.empty());
|
||||||
a.clear();
|
a.clear();
|
||||||
BEAST_EXPECT(a.empty());
|
BOOST_TEST(a.empty());
|
||||||
BEAST_EXPECT(a.capacity() > 0);
|
BOOST_TEST(a.capacity() > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// size()
|
// size()
|
||||||
{
|
{
|
||||||
array a;
|
array a;
|
||||||
BEAST_EXPECT(a.size() == 0);
|
BOOST_TEST(a.size() == 0);
|
||||||
a.emplace_back(1);
|
a.emplace_back(1);
|
||||||
BEAST_EXPECT(a.size() == 1);
|
BOOST_TEST(a.size() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// max_size()
|
// max_size()
|
||||||
{
|
{
|
||||||
array a;
|
array a;
|
||||||
BEAST_EXPECT(a.max_size() > 0);
|
BOOST_TEST(a.max_size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reserve()
|
// reserve()
|
||||||
@ -629,7 +628,7 @@ public:
|
|||||||
{
|
{
|
||||||
array a;
|
array a;
|
||||||
a.reserve(50);
|
a.reserve(50);
|
||||||
BEAST_EXPECT(a.capacity() >= 50);
|
BOOST_TEST(a.capacity() >= 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
@ -637,16 +636,16 @@ public:
|
|||||||
array a(min_capacity_, 'c', sp);
|
array a(min_capacity_, 'c', sp);
|
||||||
a.reserve(a.capacity() + 1);
|
a.reserve(a.capacity() + 1);
|
||||||
auto const new_cap = a.capacity();
|
auto const new_cap = a.capacity();
|
||||||
BEAST_EXPECT(new_cap > min_capacity_);
|
BOOST_TEST(new_cap > min_capacity_);
|
||||||
a.reserve((min_capacity_ + new_cap) / 2);
|
a.reserve((min_capacity_ + new_cap) / 2);
|
||||||
BEAST_EXPECT(a.capacity() == new_cap);
|
BOOST_TEST(a.capacity() == new_cap);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// capacity()
|
// capacity()
|
||||||
{
|
{
|
||||||
array a;
|
array a;
|
||||||
BEAST_EXPECT(a.capacity() == 0);
|
BOOST_TEST(a.capacity() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// shrink_to_fit()
|
// shrink_to_fit()
|
||||||
@ -654,16 +653,16 @@ public:
|
|||||||
{
|
{
|
||||||
array a(1);
|
array a(1);
|
||||||
a.shrink_to_fit();
|
a.shrink_to_fit();
|
||||||
BEAST_EXPECT(a.size() == 1);
|
BOOST_TEST(a.size() == 1);
|
||||||
BEAST_EXPECT(a.capacity() >= 1);
|
BOOST_TEST(a.capacity() >= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
array a(min_capacity_, 'c');
|
array a(min_capacity_, 'c');
|
||||||
BEAST_EXPECT(a.capacity() >= min_capacity_);
|
BOOST_TEST(a.capacity() >= min_capacity_);
|
||||||
a.erase(a.begin(), a.begin() + 2);
|
a.erase(a.begin(), a.begin() + 2);
|
||||||
a.shrink_to_fit();
|
a.shrink_to_fit();
|
||||||
BEAST_EXPECT(a.capacity() == min_capacity_);
|
BOOST_TEST(a.capacity() == min_capacity_);
|
||||||
}
|
}
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
@ -671,23 +670,23 @@ public:
|
|||||||
array a(1, sp);
|
array a(1, sp);
|
||||||
a.resize(a.capacity());
|
a.resize(a.capacity());
|
||||||
a.shrink_to_fit();
|
a.shrink_to_fit();
|
||||||
BEAST_EXPECT(a.size() == a.capacity());
|
BOOST_TEST(a.size() == a.capacity());
|
||||||
});
|
});
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
{
|
{
|
||||||
array a(sp);
|
array a(sp);
|
||||||
a.reserve(10);
|
a.reserve(10);
|
||||||
BEAST_EXPECT(a.capacity() >= 10);
|
BOOST_TEST(a.capacity() >= 10);
|
||||||
a.shrink_to_fit();
|
a.shrink_to_fit();
|
||||||
BEAST_EXPECT(a.capacity() == 0);
|
BOOST_TEST(a.capacity() == 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
{
|
{
|
||||||
array a(min_capacity_, sp);
|
array a(min_capacity_, sp);
|
||||||
a.reserve(min_capacity_ * 2);
|
a.reserve(min_capacity_ * 2);
|
||||||
BEAST_EXPECT(a.capacity() >=
|
BOOST_TEST(a.capacity() >=
|
||||||
min_capacity_ * 2);
|
min_capacity_ * 2);
|
||||||
a.shrink_to_fit();
|
a.shrink_to_fit();
|
||||||
if(a.capacity() > min_capacity_)
|
if(a.capacity() > min_capacity_)
|
||||||
@ -703,17 +702,17 @@ public:
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
array a;
|
array a;
|
||||||
BEAST_EXPECT(a.size() == 0);
|
BOOST_TEST(a.size() == 0);
|
||||||
BEAST_EXPECT(a.capacity() == 0);
|
BOOST_TEST(a.capacity() == 0);
|
||||||
a.clear();
|
a.clear();
|
||||||
BEAST_EXPECT(a.size() == 0);
|
BOOST_TEST(a.size() == 0);
|
||||||
BEAST_EXPECT(a.capacity() == 0);
|
BOOST_TEST(a.capacity() == 0);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
array a({1, true, str_});
|
array a({1, true, str_});
|
||||||
a.clear();
|
a.clear();
|
||||||
BEAST_EXPECT(a.size() == 0);
|
BOOST_TEST(a.size() == 0);
|
||||||
BEAST_EXPECT(a.capacity() > 0);
|
BOOST_TEST(a.capacity() > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -744,11 +743,11 @@ public:
|
|||||||
value v({1,2,3});
|
value v({1,2,3});
|
||||||
array a({1, str_}, sp);
|
array a({1, str_}, sp);
|
||||||
a.insert(a.begin() + 1, 3, v);
|
a.insert(a.begin() + 1, 3, v);
|
||||||
BEAST_EXPECT(a[0].is_number());
|
BOOST_TEST(a[0].is_number());
|
||||||
BEAST_EXPECT(a[1].as_array().size() == 3);
|
BOOST_TEST(a[1].as_array().size() == 3);
|
||||||
BEAST_EXPECT(a[2].as_array().size() == 3);
|
BOOST_TEST(a[2].as_array().size() == 3);
|
||||||
BEAST_EXPECT(a[3].as_array().size() == 3);
|
BOOST_TEST(a[3].as_array().size() == 3);
|
||||||
BEAST_EXPECT(a[4].is_string());
|
BOOST_TEST(a[4].is_string());
|
||||||
});
|
});
|
||||||
|
|
||||||
// insert(const_iterator, InputIt, InputIt)
|
// insert(const_iterator, InputIt, InputIt)
|
||||||
@ -772,7 +771,7 @@ public:
|
|||||||
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
|
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
|
||||||
27, 28, 29, 30 };
|
27, 28, 29, 30 };
|
||||||
BEAST_EXPECT(init.size() > min_capacity_);
|
BOOST_TEST(init.size() > min_capacity_);
|
||||||
array a(sp);
|
array a(sp);
|
||||||
a.insert(a.begin(),
|
a.insert(a.begin(),
|
||||||
init.begin(), init.end());
|
init.begin(), init.end());
|
||||||
@ -785,7 +784,7 @@ public:
|
|||||||
a.insert(a.begin(),
|
a.insert(a.begin(),
|
||||||
make_input_iterator(init.begin()),
|
make_input_iterator(init.begin()),
|
||||||
make_input_iterator(init.end()));
|
make_input_iterator(init.end()));
|
||||||
BEAST_EXPECT(a.empty());
|
BOOST_TEST(a.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
// input iterator
|
// input iterator
|
||||||
@ -809,7 +808,7 @@ public:
|
|||||||
a.insert(a.begin(),
|
a.insert(a.begin(),
|
||||||
make_input_iterator(init.begin()),
|
make_input_iterator(init.begin()),
|
||||||
make_input_iterator(init.end()));
|
make_input_iterator(init.end()));
|
||||||
BEAST_EXPECT(a.size() == init.size() + 1);
|
BOOST_TEST(a.size() == init.size() + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// backward relocate
|
// backward relocate
|
||||||
@ -829,12 +828,12 @@ public:
|
|||||||
array a({0, 3, 4}, sp);
|
array a({0, 3, 4}, sp);
|
||||||
auto it = a.insert(
|
auto it = a.insert(
|
||||||
a.begin() + 1, {1, str_});
|
a.begin() + 1, {1, str_});
|
||||||
BEAST_EXPECT(it == a.begin() + 1);
|
BOOST_TEST(it == a.begin() + 1);
|
||||||
BEAST_EXPECT(a[0].as_int64() == 0);
|
BOOST_TEST(a[0].as_int64() == 0);
|
||||||
BEAST_EXPECT(a[1].as_int64() == 1);
|
BOOST_TEST(a[1].as_int64() == 1);
|
||||||
BEAST_EXPECT(a[2].as_string() == str_);
|
BOOST_TEST(a[2].as_string() == str_);
|
||||||
BEAST_EXPECT(a[3].as_int64() == 3);
|
BOOST_TEST(a[3].as_int64() == 3);
|
||||||
BEAST_EXPECT(a[4].as_int64() == 4);
|
BOOST_TEST(a[4].as_int64() == 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
// emplace(const_iterator, arg)
|
// emplace(const_iterator, arg)
|
||||||
@ -843,12 +842,12 @@ public:
|
|||||||
array a({0, 2, 3, 4}, sp);
|
array a({0, 2, 3, 4}, sp);
|
||||||
auto it = a.emplace(
|
auto it = a.emplace(
|
||||||
a.begin() + 1, str_);
|
a.begin() + 1, str_);
|
||||||
BEAST_EXPECT(it == a.begin() + 1);
|
BOOST_TEST(it == a.begin() + 1);
|
||||||
BEAST_EXPECT(a[0].as_int64() == 0);
|
BOOST_TEST(a[0].as_int64() == 0);
|
||||||
BEAST_EXPECT(a[1].as_string() == str_);
|
BOOST_TEST(a[1].as_string() == str_);
|
||||||
BEAST_EXPECT(a[2].as_int64() == 2);
|
BOOST_TEST(a[2].as_int64() == 2);
|
||||||
BEAST_EXPECT(a[3].as_int64() == 3);
|
BOOST_TEST(a[3].as_int64() == 3);
|
||||||
BEAST_EXPECT(a[4].as_int64() == 4);
|
BOOST_TEST(a[4].as_int64() == 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
// erase(pos)
|
// erase(pos)
|
||||||
@ -873,7 +872,7 @@ public:
|
|||||||
array a({1, true}, sp);
|
array a({1, true}, sp);
|
||||||
value v(str_);
|
value v(str_);
|
||||||
a.push_back(v);
|
a.push_back(v);
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
v.as_string() == str_);
|
v.as_string() == str_);
|
||||||
check(a);
|
check(a);
|
||||||
check_storage(a, sp);
|
check_storage(a, sp);
|
||||||
@ -920,7 +919,7 @@ public:
|
|||||||
{
|
{
|
||||||
array a(5, sp);
|
array a(5, sp);
|
||||||
a.resize(3);
|
a.resize(3);
|
||||||
BEAST_EXPECT(a.size() == 3);
|
BOOST_TEST(a.size() == 3);
|
||||||
check_storage(a, sp);
|
check_storage(a, sp);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -928,7 +927,7 @@ public:
|
|||||||
{
|
{
|
||||||
array a(sp);
|
array a(sp);
|
||||||
a.resize(3);
|
a.resize(3);
|
||||||
BEAST_EXPECT(a.size() == 3);
|
BOOST_TEST(a.size() == 3);
|
||||||
check_storage(a, sp);
|
check_storage(a, sp);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -944,7 +943,7 @@ public:
|
|||||||
{
|
{
|
||||||
array a(5, v, sp);
|
array a(5, v, sp);
|
||||||
a.resize(3, v);
|
a.resize(3, v);
|
||||||
BEAST_EXPECT(a.size() == 3);
|
BOOST_TEST(a.size() == 3);
|
||||||
check_storage(a, sp);
|
check_storage(a, sp);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -952,7 +951,7 @@ public:
|
|||||||
{
|
{
|
||||||
array a(3, v, sp);
|
array a(3, v, sp);
|
||||||
a.resize(5, v);
|
a.resize(5, v);
|
||||||
BEAST_EXPECT(a.size() == 5);
|
BOOST_TEST(a.size() == 5);
|
||||||
check_storage(a, sp);
|
check_storage(a, sp);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -965,9 +964,9 @@ public:
|
|||||||
array a2 = {1.};
|
array a2 = {1.};
|
||||||
a1.swap(a2);
|
a1.swap(a2);
|
||||||
check(a2);
|
check(a2);
|
||||||
BEAST_EXPECT(a1.size() == 1);
|
BOOST_TEST(a1.size() == 1);
|
||||||
BEAST_EXPECT(a1.front().is_number());
|
BOOST_TEST(a1.front().is_number());
|
||||||
BEAST_EXPECT(a1.front().as_double() == 1.);
|
BOOST_TEST(a1.front().as_double() == 1.);
|
||||||
}
|
}
|
||||||
|
|
||||||
// different storage
|
// different storage
|
||||||
@ -977,7 +976,7 @@ public:
|
|||||||
array a2 = {1.};
|
array a2 = {1.};
|
||||||
a1.swap(a2);
|
a1.swap(a2);
|
||||||
check(a2);
|
check(a2);
|
||||||
BEAST_EXPECT(a1.size() == 1);
|
BOOST_TEST(a1.size() == 1);
|
||||||
});
|
});
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
{
|
{
|
||||||
@ -985,7 +984,7 @@ public:
|
|||||||
array a2({1, true, str_}, sp);
|
array a2({1, true, str_}, sp);
|
||||||
a1.swap(a2);
|
a1.swap(a2);
|
||||||
check(a1);
|
check(a1);
|
||||||
BEAST_EXPECT(a2.size() == 1);
|
BOOST_TEST(a2.size() == 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1025,12 +1024,12 @@ public:
|
|||||||
a.insert(a.begin() + 1,
|
a.insert(a.begin() + 1,
|
||||||
3, nullptr);
|
3, nullptr);
|
||||||
a1 = a;
|
a1 = a;
|
||||||
BEAST_EXPECT(a1.size() == 5);
|
BOOST_TEST(a1.size() == 5);
|
||||||
BEAST_EXPECT(a1[0].is_number());
|
BOOST_TEST(a1[0].is_number());
|
||||||
BEAST_EXPECT(a1[1].is_null());
|
BOOST_TEST(a1[1].is_null());
|
||||||
BEAST_EXPECT(a1[2].is_null());
|
BOOST_TEST(a1[2].is_null());
|
||||||
BEAST_EXPECT(a1[3].is_null());
|
BOOST_TEST(a1[3].is_null());
|
||||||
BEAST_EXPECT(a1[4].is_bool());
|
BOOST_TEST(a1[4].is_bool());
|
||||||
});
|
});
|
||||||
|
|
||||||
// insert(const_iterator, InputIt, InputIt)
|
// insert(const_iterator, InputIt, InputIt)
|
||||||
@ -1052,10 +1051,10 @@ public:
|
|||||||
array a({1, nullptr}, sp);
|
array a({1, nullptr}, sp);
|
||||||
a.emplace(a.begin() + 1, true);
|
a.emplace(a.begin() + 1, true);
|
||||||
a1 = a;
|
a1 = a;
|
||||||
BEAST_EXPECT(a1.size() == 3);
|
BOOST_TEST(a1.size() == 3);
|
||||||
BEAST_EXPECT(a1[0].is_number());
|
BOOST_TEST(a1[0].is_number());
|
||||||
BEAST_EXPECT(a1[1].is_bool());
|
BOOST_TEST(a1[1].is_bool());
|
||||||
BEAST_EXPECT(a1[2].is_null());
|
BOOST_TEST(a1[2].is_null());
|
||||||
});
|
});
|
||||||
|
|
||||||
// emplace(const_iterator, arg)
|
// emplace(const_iterator, arg)
|
||||||
@ -1066,15 +1065,15 @@ public:
|
|||||||
a.emplace(a.begin() + 1, true);
|
a.emplace(a.begin() + 1, true);
|
||||||
a1 = a;
|
a1 = a;
|
||||||
check(a1);
|
check(a1);
|
||||||
BEAST_EXPECT(a1.size() == 3);
|
BOOST_TEST(a1.size() == 3);
|
||||||
BEAST_EXPECT(a1[0].is_number());
|
BOOST_TEST(a1[0].is_number());
|
||||||
BEAST_EXPECT(a1[1].is_bool());
|
BOOST_TEST(a1[1].is_bool());
|
||||||
BEAST_EXPECT(a1[2].is_string());
|
BOOST_TEST(a1[2].is_string());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
testCtors();
|
testCtors();
|
||||||
testAssignment();
|
testAssignment();
|
||||||
@ -1087,7 +1086,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,array);
|
TEST_SUITE(array_test, "boost.json.array");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -10,13 +10,13 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/json/basic_parser.hpp>
|
#include <boost/json/basic_parser.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "test.hpp"
|
|
||||||
#include "parse-vectors.hpp"
|
#include "parse-vectors.hpp"
|
||||||
|
#include "test.hpp"
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
@ -140,9 +140,11 @@ validate( string_view s )
|
|||||||
|
|
||||||
} // (anon)
|
} // (anon)
|
||||||
|
|
||||||
class basic_parser_test : public beast::unit_test::suite
|
class basic_parser_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
::test_suite::log_type log;
|
||||||
|
|
||||||
void
|
void
|
||||||
split_grind(
|
split_grind(
|
||||||
string_view s,
|
string_view s,
|
||||||
@ -153,7 +155,7 @@ public:
|
|||||||
for(std::size_t i = 1;
|
for(std::size_t i = 1;
|
||||||
i < s.size(); ++i)
|
i < s.size(); ++i)
|
||||||
{
|
{
|
||||||
if(! BEAST_EXPECT(i < 100000))
|
if(! BOOST_TEST(i < 100000))
|
||||||
break;
|
break;
|
||||||
error_code ec;
|
error_code ec;
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
@ -161,8 +163,7 @@ public:
|
|||||||
p.write_some(s.data(), i, ec);
|
p.write_some(s.data(), i, ec);
|
||||||
if(ec)
|
if(ec)
|
||||||
{
|
{
|
||||||
BEAST_EXPECTS(ec == ex,
|
BOOST_TEST(ec == ex);
|
||||||
ec.message());
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
p.write(
|
p.write(
|
||||||
@ -170,8 +171,7 @@ public:
|
|||||||
s.size() - n, ec);
|
s.size() - n, ec);
|
||||||
if(! ec)
|
if(! ec)
|
||||||
p.finish(ec);
|
p.finish(ec);
|
||||||
if(! BEAST_EXPECTS(ec == ex,
|
if(! BOOST_TEST(ec == ex))
|
||||||
ec.message()))
|
|
||||||
log << "should be " << ex.message() << std::endl;
|
log << "should be " << ex.message() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ public:
|
|||||||
// exercise all error paths
|
// exercise all error paths
|
||||||
for(std::size_t j = 1;;++j)
|
for(std::size_t j = 1;;++j)
|
||||||
{
|
{
|
||||||
if(! BEAST_EXPECT(j < 100000))
|
if(! BOOST_TEST(j < 100000))
|
||||||
break;
|
break;
|
||||||
error_code ec;
|
error_code ec;
|
||||||
fail_parser p(j);
|
fail_parser p(j);
|
||||||
@ -194,8 +194,7 @@ public:
|
|||||||
p.finish(ec);
|
p.finish(ec);
|
||||||
if(ec == error::test_failure)
|
if(ec == error::test_failure)
|
||||||
continue;
|
continue;
|
||||||
BEAST_EXPECTS(ec == ex,
|
BOOST_TEST(ec == ex);
|
||||||
ec.message());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,7 +207,7 @@ public:
|
|||||||
// exercise all exception paths
|
// exercise all exception paths
|
||||||
for(std::size_t j = 1;;++j)
|
for(std::size_t j = 1;;++j)
|
||||||
{
|
{
|
||||||
if(! BEAST_EXPECT(j < 100000))
|
if(! BOOST_TEST(j < 100000))
|
||||||
break;
|
break;
|
||||||
error_code ec;
|
error_code ec;
|
||||||
throw_parser p(j);
|
throw_parser p(j);
|
||||||
@ -218,8 +217,7 @@ public:
|
|||||||
s.data(), s.size(), ec);
|
s.data(), s.size(), ec);
|
||||||
if(! ec)
|
if(! ec)
|
||||||
p.finish(ec);
|
p.finish(ec);
|
||||||
BEAST_EXPECTS(ec == ex,
|
BOOST_TEST(ec == ex);
|
||||||
ec.message());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch(test_exception const&)
|
catch(test_exception const&)
|
||||||
@ -228,7 +226,7 @@ public:
|
|||||||
}
|
}
|
||||||
catch(std::exception const& e)
|
catch(std::exception const& e)
|
||||||
{
|
{
|
||||||
BEAST_FAIL();
|
BOOST_TEST_FAIL();
|
||||||
log << " " <<
|
log << " " <<
|
||||||
e.what() << std::endl;
|
e.what() << std::endl;
|
||||||
}
|
}
|
||||||
@ -249,13 +247,12 @@ public:
|
|||||||
p.finish(ex);
|
p.finish(ex);
|
||||||
if(good)
|
if(good)
|
||||||
{
|
{
|
||||||
if(! BEAST_EXPECTS(
|
if(! BOOST_TEST(! ex))
|
||||||
! ex, ex.message()))
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(! BEAST_EXPECT(ex))
|
if(! BOOST_TEST(ex))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -483,10 +480,9 @@ public:
|
|||||||
p.write_some(
|
p.write_some(
|
||||||
s.data(), s.size(),
|
s.data(), s.size(),
|
||||||
ec);
|
ec);
|
||||||
if(! BEAST_EXPECTS(! ec,
|
if(! BOOST_TEST(! ec))
|
||||||
ec.message()))
|
|
||||||
return;
|
return;
|
||||||
BEAST_EXPECT(is_done ==
|
BOOST_TEST(is_done ==
|
||||||
p.is_done());
|
p.is_done());
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -537,43 +533,40 @@ public:
|
|||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
p.depth() == 0);
|
p.depth() == 0);
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
p.max_depth() > 0);
|
p.max_depth() > 0);
|
||||||
p.max_depth(1);
|
p.max_depth(1);
|
||||||
p.write("[{}]", 4, ec);
|
p.write("[{}]", 4, ec);
|
||||||
BEAST_EXPECTS(
|
BOOST_TEST(
|
||||||
ec == error::too_deep,
|
ec == error::too_deep);
|
||||||
ec.message());
|
BOOST_TEST(! p.is_done());
|
||||||
BEAST_EXPECT(! p.is_done());
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
p.max_depth() > 0);
|
p.max_depth() > 0);
|
||||||
p.max_depth(1);
|
p.max_depth(1);
|
||||||
p.write_some("[", 1, ec);
|
p.write_some("[", 1, ec);
|
||||||
BEAST_EXPECT(p.depth() == 1);
|
BOOST_TEST(p.depth() == 1);
|
||||||
if(BEAST_EXPECTS(! ec,
|
if(BOOST_TEST(! ec))
|
||||||
ec.message()))
|
|
||||||
{
|
{
|
||||||
p.write_some("{", 1, ec);
|
p.write_some("{", 1, ec);
|
||||||
BEAST_EXPECTS(
|
BOOST_TEST(
|
||||||
ec == error::too_deep,
|
ec == error::too_deep);
|
||||||
ec.message());
|
|
||||||
}
|
}
|
||||||
BEAST_EXPECT(! p.is_done());
|
BOOST_TEST(! p.is_done());
|
||||||
ec = {};
|
ec = {};
|
||||||
p.write_some("{}", 2, ec);
|
p.write_some("{}", 2, ec);
|
||||||
BEAST_EXPECT(ec);
|
BOOST_TEST(ec);
|
||||||
p.reset();
|
p.reset();
|
||||||
p.write("{}", 2, ec);
|
p.write("{}", 2, ec);
|
||||||
if(! ec)
|
if(! ec)
|
||||||
p.finish(ec);
|
p.finish(ec);
|
||||||
BEAST_EXPECTS(! ec, ec.message());
|
BOOST_TEST(! ec);
|
||||||
BEAST_EXPECT(p.is_done());
|
BOOST_TEST(p.is_done());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,7 +605,7 @@ public:
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
p.finish(ec);
|
p.finish(ec);
|
||||||
BEAST_EXPECT(ec);
|
BOOST_TEST(ec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,7 +618,7 @@ public:
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
p.write_some("0", 1, ec);
|
p.write_some("0", 1, ec);
|
||||||
BEAST_EXPECTS(! ec, ec.message());
|
BOOST_TEST(! ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// partial write
|
// partial write
|
||||||
@ -634,15 +627,15 @@ public:
|
|||||||
fail_parser p;
|
fail_parser p;
|
||||||
auto const n =
|
auto const n =
|
||||||
p.write_some("null x", 6, ec);
|
p.write_some("null x", 6, ec);
|
||||||
BEAST_EXPECTS(! ec, ec.message());
|
BOOST_TEST(! ec);
|
||||||
BEAST_EXPECT(n < 6);
|
BOOST_TEST(n < 6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// write_some(char const*, size_t)
|
// write_some(char const*, size_t)
|
||||||
{
|
{
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
p.write_some("x", 1),
|
p.write_some("x", 1),
|
||||||
system_error);
|
system_error);
|
||||||
}
|
}
|
||||||
@ -652,9 +645,8 @@ public:
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
p.write("0x", 2, ec);
|
p.write("0x", 2, ec);
|
||||||
BEAST_EXPECTS(
|
BOOST_TEST(
|
||||||
ec == error::extra_data,
|
ec == error::extra_data);
|
||||||
ec.message());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// write(char const*, size_t)
|
// write(char const*, size_t)
|
||||||
@ -666,7 +658,7 @@ public:
|
|||||||
|
|
||||||
{
|
{
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
p.write("0x", 2),
|
p.write("0x", 2),
|
||||||
system_error);
|
system_error);
|
||||||
}
|
}
|
||||||
@ -677,9 +669,8 @@ public:
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
p.finish("{", 1, ec);
|
p.finish("{", 1, ec);
|
||||||
BEAST_EXPECTS(
|
BOOST_TEST(
|
||||||
ec == error::incomplete,
|
ec == error::incomplete);
|
||||||
ec.message());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish(char const*, size_t)
|
// finish(char const*, size_t)
|
||||||
@ -691,7 +682,7 @@ public:
|
|||||||
|
|
||||||
{
|
{
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
p.finish("{", 1),
|
p.finish("{", 1),
|
||||||
system_error);
|
system_error);
|
||||||
}
|
}
|
||||||
@ -702,16 +693,16 @@ public:
|
|||||||
{
|
{
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
p.write("{}", 2);
|
p.write("{}", 2);
|
||||||
BEAST_EXPECT(! p.is_done());
|
BOOST_TEST(! p.is_done());
|
||||||
p.finish();
|
p.finish();
|
||||||
BEAST_EXPECT(p.is_done());
|
BOOST_TEST(p.is_done());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
fail_parser p;
|
fail_parser p;
|
||||||
p.write("{", 1);
|
p.write("{", 1);
|
||||||
BEAST_EXPECT(! p.is_done());
|
BOOST_TEST(! p.is_done());
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
p.finish(),
|
p.finish(),
|
||||||
system_error);
|
system_error);
|
||||||
}
|
}
|
||||||
@ -797,11 +788,11 @@ public:
|
|||||||
base64::decode(
|
base64::decode(
|
||||||
p.get(), s.data(), s.size());
|
p.get(), s.data(), s.size());
|
||||||
string_view const js(p.get(), len);
|
string_view const js(p.get(), len);
|
||||||
BEAST_EXPECT(! validate(js));
|
BOOST_TEST(! validate(js));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
testObject();
|
testObject();
|
||||||
testArray();
|
testArray();
|
||||||
@ -818,7 +809,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,basic_parser);
|
TEST_SUITE(basic_parser_test, "boost.json.basic_parser");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -10,21 +10,22 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/json/error.hpp>
|
#include <boost/json/error.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
class error_test : public beast::unit_test::suite
|
class error_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void check(error e)
|
void check(error e)
|
||||||
{
|
{
|
||||||
auto const ec = make_error_code(e);
|
auto const ec = make_error_code(e);
|
||||||
BEAST_EXPECT(ec.category().name() != nullptr);
|
BOOST_TEST(ec.category().name() != nullptr);
|
||||||
BEAST_EXPECT(! ec.message().empty());
|
BOOST_TEST(! ec.message().empty());
|
||||||
BEAST_EXPECT(ec.category().default_error_condition(
|
BOOST_TEST(ec.category().default_error_condition(
|
||||||
static_cast<int>(e)).category() == ec.category());
|
static_cast<int>(e)).category() == ec.category());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,20 +33,20 @@ public:
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
auto const ec = make_error_code(e);
|
auto const ec = make_error_code(e);
|
||||||
BEAST_EXPECT(ec.category().name() != nullptr);
|
BOOST_TEST(ec.category().name() != nullptr);
|
||||||
BEAST_EXPECT(! ec.message().empty());
|
BOOST_TEST(! ec.message().empty());
|
||||||
BEAST_EXPECT(ec == c);
|
BOOST_TEST(ec == c);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto ec = make_error_condition(c);
|
auto ec = make_error_condition(c);
|
||||||
BEAST_EXPECT(ec.category().name() != nullptr);
|
BOOST_TEST(ec.category().name() != nullptr);
|
||||||
BEAST_EXPECT(! ec.message().empty());
|
BOOST_TEST(! ec.message().empty());
|
||||||
BEAST_EXPECT(ec == c);
|
BOOST_TEST(ec == c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
check(condition::parse_error, error::syntax);
|
check(condition::parse_error, error::syntax);
|
||||||
check(condition::parse_error, error::extra_data);
|
check(condition::parse_error, error::extra_data);
|
||||||
@ -88,7 +89,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,error);
|
TEST_SUITE(error_test, "boost.json.error");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -10,16 +10,18 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/json.hpp>
|
#include <boost/json.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
|
||||||
|
|
||||||
struct zjson_test : public beast::unit_test::suite
|
struct json_test
|
||||||
{
|
{
|
||||||
|
::test_suite::log_type log;
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
|
using namespace json;
|
||||||
log <<
|
log <<
|
||||||
"sizeof(alignof)\n"
|
"sizeof(alignof)\n"
|
||||||
" object == " << sizeof(object) << " (" << alignof(object) << ")\n"
|
" object == " << sizeof(object) << " (" << alignof(object) << ")\n"
|
||||||
@ -28,16 +30,14 @@ struct zjson_test : public beast::unit_test::suite
|
|||||||
" string == " << sizeof(string) << " (" << alignof(string) << ")\n"
|
" string == " << sizeof(string) << " (" << alignof(string) << ")\n"
|
||||||
" value == " << sizeof(value) << " (" << alignof(value) << ")\n"
|
" value == " << sizeof(value) << " (" << alignof(value) << ")\n"
|
||||||
" serializer == " << sizeof(serializer) << "\n"
|
" serializer == " << sizeof(serializer) << "\n"
|
||||||
" number_parser == " << sizeof(detail::number_parser) << "\n"
|
" number_parser == " << sizeof(json::detail::number_parser) << "\n"
|
||||||
" basic_parser == " << sizeof(basic_parser) << "\n"
|
" basic_parser == " << sizeof(basic_parser) << "\n"
|
||||||
" parser == " << sizeof(parser) << "\n"
|
" parser == " << sizeof(parser)
|
||||||
<< std::endl;
|
|
||||||
;
|
;
|
||||||
pass();
|
BOOST_TEST_PASS();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,zjson);
|
TEST_SUITE(json_test, "boost.json.zsizes");
|
||||||
|
|
||||||
} // json
|
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -10,13 +10,14 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/json/kind.hpp>
|
#include <boost/json/kind.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
class kind_test : public beast::unit_test::suite
|
class kind_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BOOST_STATIC_ASSERT(
|
BOOST_STATIC_ASSERT(
|
||||||
@ -25,16 +26,16 @@ public:
|
|||||||
void
|
void
|
||||||
testEnum()
|
testEnum()
|
||||||
{
|
{
|
||||||
pass();
|
BOOST_TEST_PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() override
|
void run()
|
||||||
{
|
{
|
||||||
testEnum();
|
testEnum();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,kind);
|
TEST_SUITE(kind_test, "boost.json.kind");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -13,10 +13,11 @@
|
|||||||
#include <boost/json/value.hpp>
|
#include <boost/json/value.hpp>
|
||||||
#include <boost/json/parser.hpp>
|
#include <boost/json/parser.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
#include "test.hpp"
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
#include "test.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ namespace json {
|
|||||||
length.
|
length.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class limits_test : public beast::unit_test::suite
|
class limits_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void
|
void
|
||||||
@ -43,8 +44,8 @@ public:
|
|||||||
{"21",21},{"22",22},{"23",23},{"24",24},{"25",25},
|
{"21",21},{"22",22},{"23",23},{"24",24},{"25",25},
|
||||||
{"26",26},{"27",27},{"28",28},{"29",29},{"30",30},
|
{"26",26},{"27",27},{"28",28},{"29",29},{"30",30},
|
||||||
{"31",31}};
|
{"31",31}};
|
||||||
BEAST_EXPECT(init.size() > object::max_size());
|
BOOST_TEST(init.size() > object::max_size());
|
||||||
BEAST_THROWS(value{init}, std::length_error);
|
BOOST_TEST_THROWS(value{init}, std::length_error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ public:
|
|||||||
{
|
{
|
||||||
// max size
|
// max size
|
||||||
{
|
{
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
object(object::max_size()+1),
|
object(object::max_size()+1),
|
||||||
std::length_error);
|
std::length_error);
|
||||||
}
|
}
|
||||||
@ -69,11 +70,11 @@ public:
|
|||||||
{"21",21},{"22",22},{"23",23},{"24",24},{"25",25},
|
{"21",21},{"22",22},{"23",23},{"24",24},{"25",25},
|
||||||
{"26",26},{"27",27},{"28",28},{"29",29},{"30",30},
|
{"26",26},{"27",27},{"28",28},{"29",29},{"30",30},
|
||||||
{"31",31}};
|
{"31",31}};
|
||||||
BEAST_EXPECT(init.size() > object::max_size());
|
BOOST_TEST(init.size() > object::max_size());
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
object(init.begin(), init.end()),
|
object(init.begin(), init.end()),
|
||||||
std::length_error);
|
std::length_error);
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
object(
|
object(
|
||||||
make_input_iterator(init.begin()),
|
make_input_iterator(init.begin()),
|
||||||
make_input_iterator(init.end())),
|
make_input_iterator(init.end())),
|
||||||
@ -84,7 +85,7 @@ public:
|
|||||||
{
|
{
|
||||||
std::string const big(
|
std::string const big(
|
||||||
string::max_size() + 1, '*');
|
string::max_size() + 1, '*');
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
object({ {big, nullptr} }),
|
object({ {big, nullptr} }),
|
||||||
std::length_error);
|
std::length_error);
|
||||||
}
|
}
|
||||||
@ -94,7 +95,7 @@ public:
|
|||||||
testArray()
|
testArray()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
array(
|
array(
|
||||||
array::max_size()+1,
|
array::max_size()+1,
|
||||||
value(nullptr)),
|
value(nullptr)),
|
||||||
@ -104,7 +105,7 @@ public:
|
|||||||
{
|
{
|
||||||
std::vector<int> v(
|
std::vector<int> v(
|
||||||
array::max_size()+1, 42);
|
array::max_size()+1, 42);
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
array(v.begin(), v.end()),
|
array(v.begin(), v.end()),
|
||||||
std::length_error);
|
std::length_error);
|
||||||
}
|
}
|
||||||
@ -112,7 +113,7 @@ public:
|
|||||||
{
|
{
|
||||||
std::vector<int> v(
|
std::vector<int> v(
|
||||||
array::max_size()+1, 42);
|
array::max_size()+1, 42);
|
||||||
BEAST_THROWS(array(
|
BOOST_TEST_THROWS(array(
|
||||||
make_input_iterator(v.begin()),
|
make_input_iterator(v.begin()),
|
||||||
make_input_iterator(v.end())),
|
make_input_iterator(v.end())),
|
||||||
std::length_error);
|
std::length_error);
|
||||||
@ -120,7 +121,7 @@ public:
|
|||||||
|
|
||||||
{
|
{
|
||||||
array a;
|
array a;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
a.insert(a.begin(),
|
a.insert(a.begin(),
|
||||||
array::max_size() + 1,
|
array::max_size() + 1,
|
||||||
nullptr),
|
nullptr),
|
||||||
@ -135,7 +136,7 @@ public:
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
string s;
|
string s;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
(s.resize(s.max_size() + 1)),
|
(s.resize(s.max_size() + 1)),
|
||||||
std::length_error);
|
std::length_error);
|
||||||
}
|
}
|
||||||
@ -143,7 +144,7 @@ public:
|
|||||||
{
|
{
|
||||||
string s;
|
string s;
|
||||||
s.resize(100);
|
s.resize(100);
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
(s.append(s.max_size() - 1, '*')),
|
(s.append(s.max_size() - 1, '*')),
|
||||||
std::length_error);
|
std::length_error);
|
||||||
}
|
}
|
||||||
@ -171,7 +172,7 @@ public:
|
|||||||
auto const js =
|
auto const js =
|
||||||
"\"" + big + "\":null";
|
"\"" + big + "\":null";
|
||||||
value jv;
|
value jv;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
jv = parse(js),
|
jv = parse(js),
|
||||||
std::length_error);
|
std::length_error);
|
||||||
}
|
}
|
||||||
@ -184,7 +185,7 @@ public:
|
|||||||
auto const js =
|
auto const js =
|
||||||
"{\"" + big + "\":null}";
|
"{\"" + big + "\":null}";
|
||||||
value jv;
|
value jv;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
jv = parse(js),
|
jv = parse(js),
|
||||||
std::length_error);
|
std::length_error);
|
||||||
}
|
}
|
||||||
@ -197,7 +198,7 @@ public:
|
|||||||
{
|
{
|
||||||
std::string big;
|
std::string big;
|
||||||
value jv;
|
value jv;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
jv = parse(
|
jv = parse(
|
||||||
"[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,"
|
"[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,"
|
||||||
"1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,"
|
"1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,"
|
||||||
@ -231,7 +232,7 @@ public:
|
|||||||
auto const js =
|
auto const js =
|
||||||
"\"" + big + "\"";
|
"\"" + big + "\"";
|
||||||
value jv;
|
value jv;
|
||||||
BEAST_THROWS(jv = parse(js),
|
BOOST_TEST_THROWS(jv = parse(js),
|
||||||
decltype(detail::string_too_large_exception()));
|
decltype(detail::string_too_large_exception()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,13 +245,13 @@ public:
|
|||||||
auto const js =
|
auto const js =
|
||||||
"\"" + big + "\"";
|
"\"" + big + "\"";
|
||||||
value jv;
|
value jv;
|
||||||
BEAST_THROWS(jv = parse(js),
|
BOOST_TEST_THROWS(jv = parse(js),
|
||||||
decltype(detail::string_too_large_exception()));
|
decltype(detail::string_too_large_exception()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
#if ! defined(BOOST_JSON_NO_MAX_OBJECT_SIZE) && \
|
#if ! defined(BOOST_JSON_NO_MAX_OBJECT_SIZE) && \
|
||||||
! defined(BOOST_JSON_NO_MAX_ARRAY_SIZE) && \
|
! defined(BOOST_JSON_NO_MAX_ARRAY_SIZE) && \
|
||||||
@ -266,12 +267,12 @@ public:
|
|||||||
testParser();
|
testParser();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
pass();
|
BOOST_TEST_PASS();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,limits);
|
TEST_SUITE(limits_test, "boost.json.limits");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -7,4 +7,25 @@
|
|||||||
// Official repository: https://github.com/vinniefalco/json
|
// Official repository: https://github.com/vinniefalco/json
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/main.ipp>
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <crtdbg.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Simple main used to produce stand
|
||||||
|
// alone executables that run unit tests.
|
||||||
|
int main(int argc, char const* const* argv)
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
{
|
||||||
|
int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||||||
|
flags |= _CRTDBG_LEAK_CHECK_DF;
|
||||||
|
_CrtSetDbgFlag(flags);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
::test_suite::debug_stream log(std::cerr);
|
||||||
|
return ::test_suite::run(log, argc, argv);
|
||||||
|
}
|
||||||
|
@ -10,10 +10,11 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/json/number_cast.hpp>
|
#include <boost/json/number_cast.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
@ -35,22 +36,22 @@ T min_of()
|
|||||||
|
|
||||||
} // (anon)
|
} // (anon)
|
||||||
|
|
||||||
class number_cast_test : public beast::unit_test::suite
|
class number_cast_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void
|
void
|
||||||
testNumberCast()
|
testNumberCast()
|
||||||
{
|
{
|
||||||
#define EQAL(T) BEAST_EXPECT(number_cast<T>(jv) == V)
|
#define EQAL(T) BOOST_TEST(number_cast<T>(jv) == V)
|
||||||
#define EQUS(T) BEAST_EXPECT((V >= 0) && number_cast<T>(jv) == static_cast<std::uint64_t>(V))
|
#define EQUS(T) BOOST_TEST((V >= 0) && number_cast<T>(jv) == static_cast<std::uint64_t>(V))
|
||||||
#define EQUF(T) BEAST_EXPECT(static_cast<float>(V) == static_cast<float>(number_cast<T>(jv)))
|
#define EQUF(T) BOOST_TEST(static_cast<float>(V) == static_cast<float>(number_cast<T>(jv)))
|
||||||
#define THRO(T) BEAST_THROWS(number_cast<T>(jv), system_error)
|
#define THRO(T) BOOST_TEST_THROWS(number_cast<T>(jv), system_error)
|
||||||
|
|
||||||
BEAST_THROWS(number_cast<int>(value(object_kind)), system_error);
|
BOOST_TEST_THROWS(number_cast<int>(value(object_kind)), system_error);
|
||||||
BEAST_THROWS(number_cast<int>(value(array_kind)), system_error);
|
BOOST_TEST_THROWS(number_cast<int>(value(array_kind)), system_error);
|
||||||
BEAST_THROWS(number_cast<int>(value(string_kind)), system_error);
|
BOOST_TEST_THROWS(number_cast<int>(value(string_kind)), system_error);
|
||||||
BEAST_THROWS(number_cast<int>(value(false)), system_error);
|
BOOST_TEST_THROWS(number_cast<int>(value(false)), system_error);
|
||||||
BEAST_THROWS(number_cast<int>(value(nullptr)), system_error);
|
BOOST_TEST_THROWS(number_cast<int>(value(nullptr)), system_error);
|
||||||
|
|
||||||
{
|
{
|
||||||
unsigned char V = 0;
|
unsigned char V = 0;
|
||||||
@ -298,13 +299,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
testNumberCast();
|
testNumberCast();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,number_cast);
|
TEST_SUITE(number_cast_test, "boost.json.number_cast");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
290
test/object.cpp
290
test/object.cpp
@ -12,16 +12,16 @@
|
|||||||
|
|
||||||
#include <boost/json/pool.hpp>
|
#include <boost/json/pool.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "test.hpp"
|
#include "test.hpp"
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
class object_test : public beast::unit_test::suite
|
class object_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
string_view const str_;
|
string_view const str_;
|
||||||
@ -108,13 +108,13 @@ public:
|
|||||||
object const& o,
|
object const& o,
|
||||||
std::size_t capacity)
|
std::size_t capacity)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(! o.empty());
|
BOOST_TEST(! o.empty());
|
||||||
BEAST_EXPECT(o.size() == 3);
|
BOOST_TEST(o.size() == 3);
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
o.capacity() == capacity);
|
o.capacity() == capacity);
|
||||||
BEAST_EXPECT(o.at("a").as_int64() == 1);
|
BOOST_TEST(o.at("a").as_int64() == 1);
|
||||||
BEAST_EXPECT(o.at("b").as_bool());
|
BOOST_TEST(o.at("b").as_bool());
|
||||||
BEAST_EXPECT(o.at("c").as_string() == "hello");
|
BOOST_TEST(o.at("c").as_string() == "hello");
|
||||||
check_storage(o, o.storage());
|
check_storage(o, o.storage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,9 +129,9 @@ public:
|
|||||||
// object()
|
// object()
|
||||||
{
|
{
|
||||||
object o;
|
object o;
|
||||||
BEAST_EXPECT(o.empty());
|
BOOST_TEST(o.empty());
|
||||||
BEAST_EXPECT(o.size() == 0);
|
BOOST_TEST(o.size() == 0);
|
||||||
BEAST_EXPECT(o.capacity() == 0);
|
BOOST_TEST(o.capacity() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// object(storage_ptr)
|
// object(storage_ptr)
|
||||||
@ -139,27 +139,27 @@ public:
|
|||||||
{
|
{
|
||||||
object o(sp);
|
object o(sp);
|
||||||
check_storage(o, sp);
|
check_storage(o, sp);
|
||||||
BEAST_EXPECT(o.empty());
|
BOOST_TEST(o.empty());
|
||||||
BEAST_EXPECT(o.size() == 0);
|
BOOST_TEST(o.size() == 0);
|
||||||
BEAST_EXPECT(o.capacity() == 0);
|
BOOST_TEST(o.capacity() == 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
// object(std::size_t, storage_ptr)
|
// object(std::size_t, storage_ptr)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
object o(10);
|
object o(10);
|
||||||
BEAST_EXPECT(o.empty());
|
BOOST_TEST(o.empty());
|
||||||
BEAST_EXPECT(o.size() == 0);
|
BOOST_TEST(o.size() == 0);
|
||||||
BEAST_EXPECT(o.capacity() >= 10);
|
BOOST_TEST(o.capacity() >= 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
{
|
{
|
||||||
object o(10, sp);
|
object o(10, sp);
|
||||||
check_storage(o, sp);
|
check_storage(o, sp);
|
||||||
BEAST_EXPECT(o.empty());
|
BOOST_TEST(o.empty());
|
||||||
BEAST_EXPECT(o.size() == 0);
|
BOOST_TEST(o.size() == 0);
|
||||||
BEAST_EXPECT(o.capacity() >= 10);
|
BOOST_TEST(o.capacity() >= 10);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,9 +193,9 @@ public:
|
|||||||
{"b", true},
|
{"b", true},
|
||||||
{"c", "hello"}};
|
{"c", "hello"}};
|
||||||
object o(init.begin(), init.end(), 5, sp);
|
object o(init.begin(), init.end(), 5, sp);
|
||||||
BEAST_EXPECT(! o.empty());
|
BOOST_TEST(! o.empty());
|
||||||
BEAST_EXPECT(o.size() == 3);
|
BOOST_TEST(o.size() == 3);
|
||||||
BEAST_EXPECT(o.capacity() == 7);
|
BOOST_TEST(o.capacity() == 7);
|
||||||
check(o, 7);
|
check(o, 7);
|
||||||
check_storage(o, sp);
|
check_storage(o, sp);
|
||||||
});
|
});
|
||||||
@ -211,9 +211,9 @@ public:
|
|||||||
make_input_iterator(init.begin()),
|
make_input_iterator(init.begin()),
|
||||||
make_input_iterator(init.end()),
|
make_input_iterator(init.end()),
|
||||||
5, sp);
|
5, sp);
|
||||||
BEAST_EXPECT(! o.empty());
|
BOOST_TEST(! o.empty());
|
||||||
BEAST_EXPECT(o.size() == 3);
|
BOOST_TEST(o.size() == 3);
|
||||||
BEAST_EXPECT(o.capacity() == 7);
|
BOOST_TEST(o.capacity() == 7);
|
||||||
check(o, 7);
|
check(o, 7);
|
||||||
check_storage(o, sp);
|
check_storage(o, sp);
|
||||||
});
|
});
|
||||||
@ -230,8 +230,8 @@ public:
|
|||||||
auto const sp =
|
auto const sp =
|
||||||
storage_ptr{};
|
storage_ptr{};
|
||||||
object o2(std::move(o1));
|
object o2(std::move(o1));
|
||||||
BEAST_EXPECT(o1.empty());
|
BOOST_TEST(o1.empty());
|
||||||
BEAST_EXPECT(o1.size() == 0);
|
BOOST_TEST(o1.size() == 0);
|
||||||
check(o2, 3);
|
check(o2, 3);
|
||||||
check_storage(o1, sp);
|
check_storage(o1, sp);
|
||||||
check_storage(o2, sp);
|
check_storage(o2, sp);
|
||||||
@ -246,7 +246,7 @@ public:
|
|||||||
{"c", "hello"}
|
{"c", "hello"}
|
||||||
});
|
});
|
||||||
object o2(std::move(o1), sp);
|
object o2(std::move(o1), sp);
|
||||||
BEAST_EXPECT(! o1.empty());
|
BOOST_TEST(! o1.empty());
|
||||||
check(o2, 3);
|
check(o2, 3);
|
||||||
check_storage(o1,
|
check_storage(o1,
|
||||||
storage_ptr{});
|
storage_ptr{});
|
||||||
@ -263,11 +263,11 @@ public:
|
|||||||
{"c", "hello"}
|
{"c", "hello"}
|
||||||
}, sp);
|
}, sp);
|
||||||
object o2(pilfer(o1));
|
object o2(pilfer(o1));
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
o1.storage() == nullptr);
|
o1.storage() == nullptr);
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
*o2.storage() == *sp);
|
*o2.storage() == *sp);
|
||||||
BEAST_EXPECT(o1.empty());
|
BOOST_TEST(o1.empty());
|
||||||
check(o2, 3);
|
check(o2, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +282,7 @@ public:
|
|||||||
{"c", "hello"}
|
{"c", "hello"}
|
||||||
});
|
});
|
||||||
object o2(o1);
|
object o2(o1);
|
||||||
BEAST_EXPECT(! o1.empty());
|
BOOST_TEST(! o1.empty());
|
||||||
check(o2, 3);
|
check(o2, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +295,7 @@ public:
|
|||||||
{"c", "hello"}
|
{"c", "hello"}
|
||||||
});
|
});
|
||||||
object o2(o1, sp);
|
object o2(o1, sp);
|
||||||
BEAST_EXPECT(! o1.empty());
|
BOOST_TEST(! o1.empty());
|
||||||
check(o2, 3);
|
check(o2, 3);
|
||||||
check_storage(o2, sp);
|
check_storage(o2, sp);
|
||||||
});
|
});
|
||||||
@ -341,7 +341,7 @@ public:
|
|||||||
{"c", "hello"}
|
{"c", "hello"}
|
||||||
},
|
},
|
||||||
5, sp);
|
5, sp);
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
*o.storage() == *sp);
|
*o.storage() == *sp);
|
||||||
check(o, 7);
|
check(o, 7);
|
||||||
});
|
});
|
||||||
@ -357,7 +357,7 @@ public:
|
|||||||
object o2;
|
object o2;
|
||||||
o2 = std::move(o1);
|
o2 = std::move(o1);
|
||||||
check(o2, 3);
|
check(o2, 3);
|
||||||
BEAST_EXPECT(o1.empty());
|
BOOST_TEST(o1.empty());
|
||||||
check_storage(o1,
|
check_storage(o1,
|
||||||
storage_ptr{});
|
storage_ptr{});
|
||||||
check_storage(o2,
|
check_storage(o2,
|
||||||
@ -444,7 +444,7 @@ public:
|
|||||||
{"a", 1},
|
{"a", 1},
|
||||||
{"b", true},
|
{"b", true},
|
||||||
{"c", "hello"} },
|
{"c", "hello"} },
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
*o.storage() == *sp);
|
*o.storage() == *sp);
|
||||||
check(o, 3);
|
check(o, 3);
|
||||||
check_storage(o, sp);
|
check_storage(o, sp);
|
||||||
@ -465,117 +465,117 @@ public:
|
|||||||
|
|
||||||
// empty container
|
// empty container
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(no.begin() == no.end());
|
BOOST_TEST(no.begin() == no.end());
|
||||||
BEAST_EXPECT(cno.begin() == cno.end());
|
BOOST_TEST(cno.begin() == cno.end());
|
||||||
BEAST_EXPECT(no.cbegin() == no.cend());
|
BOOST_TEST(no.cbegin() == no.cend());
|
||||||
}
|
}
|
||||||
|
|
||||||
// begin()
|
// begin()
|
||||||
{
|
{
|
||||||
auto it = o.begin();
|
auto it = o.begin();
|
||||||
BEAST_EXPECT(it->key() == "a"); ++it;
|
BOOST_TEST(it->key() == "a"); ++it;
|
||||||
BEAST_EXPECT(it->key() == "b"); it++;
|
BOOST_TEST(it->key() == "b"); it++;
|
||||||
BEAST_EXPECT(it->key() == "c"); ++it;
|
BOOST_TEST(it->key() == "c"); ++it;
|
||||||
BEAST_EXPECT(it == o.end());
|
BOOST_TEST(it == o.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// begin() const
|
// begin() const
|
||||||
{
|
{
|
||||||
auto it = co.begin();
|
auto it = co.begin();
|
||||||
BEAST_EXPECT(it->key() == "a"); ++it;
|
BOOST_TEST(it->key() == "a"); ++it;
|
||||||
BEAST_EXPECT(it->key() == "b"); it++;
|
BOOST_TEST(it->key() == "b"); it++;
|
||||||
BEAST_EXPECT(it->key() == "c"); ++it;
|
BOOST_TEST(it->key() == "c"); ++it;
|
||||||
BEAST_EXPECT(it == co.end());
|
BOOST_TEST(it == co.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// cbegin()
|
// cbegin()
|
||||||
{
|
{
|
||||||
auto it = o.cbegin();
|
auto it = o.cbegin();
|
||||||
BEAST_EXPECT(it->key() == "a"); ++it;
|
BOOST_TEST(it->key() == "a"); ++it;
|
||||||
BEAST_EXPECT(it->key() == "b"); it++;
|
BOOST_TEST(it->key() == "b"); it++;
|
||||||
BEAST_EXPECT(it->key() == "c"); ++it;
|
BOOST_TEST(it->key() == "c"); ++it;
|
||||||
BEAST_EXPECT(it == o.cend());
|
BOOST_TEST(it == o.cend());
|
||||||
}
|
}
|
||||||
|
|
||||||
// end()
|
// end()
|
||||||
{
|
{
|
||||||
auto it = o.end();
|
auto it = o.end();
|
||||||
--it; BEAST_EXPECT(it->key() == "c");
|
--it; BOOST_TEST(it->key() == "c");
|
||||||
it--; BEAST_EXPECT(it->key() == "b");
|
it--; BOOST_TEST(it->key() == "b");
|
||||||
--it; BEAST_EXPECT(it->key() == "a");
|
--it; BOOST_TEST(it->key() == "a");
|
||||||
BEAST_EXPECT(it == o.begin());
|
BOOST_TEST(it == o.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
// end() const
|
// end() const
|
||||||
{
|
{
|
||||||
auto it = co.end();
|
auto it = co.end();
|
||||||
--it; BEAST_EXPECT(it->key() == "c");
|
--it; BOOST_TEST(it->key() == "c");
|
||||||
it--; BEAST_EXPECT(it->key() == "b");
|
it--; BOOST_TEST(it->key() == "b");
|
||||||
--it; BEAST_EXPECT(it->key() == "a");
|
--it; BOOST_TEST(it->key() == "a");
|
||||||
BEAST_EXPECT(it == co.begin());
|
BOOST_TEST(it == co.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
// cend()
|
// cend()
|
||||||
{
|
{
|
||||||
auto it = o.cend();
|
auto it = o.cend();
|
||||||
--it; BEAST_EXPECT(it->key() == "c");
|
--it; BOOST_TEST(it->key() == "c");
|
||||||
it--; BEAST_EXPECT(it->key() == "b");
|
it--; BOOST_TEST(it->key() == "b");
|
||||||
--it; BEAST_EXPECT(it->key() == "a");
|
--it; BOOST_TEST(it->key() == "a");
|
||||||
BEAST_EXPECT(it == o.cbegin());
|
BOOST_TEST(it == o.cbegin());
|
||||||
}
|
}
|
||||||
|
|
||||||
// rbegin()
|
// rbegin()
|
||||||
{
|
{
|
||||||
auto it = o.rbegin();
|
auto it = o.rbegin();
|
||||||
BEAST_EXPECT(it->key() == "c"); ++it;
|
BOOST_TEST(it->key() == "c"); ++it;
|
||||||
BEAST_EXPECT(it->key() == "b"); it++;
|
BOOST_TEST(it->key() == "b"); it++;
|
||||||
BEAST_EXPECT(it->key() == "a"); ++it;
|
BOOST_TEST(it->key() == "a"); ++it;
|
||||||
BEAST_EXPECT(it == o.rend());
|
BOOST_TEST(it == o.rend());
|
||||||
}
|
}
|
||||||
|
|
||||||
// rbegin() const
|
// rbegin() const
|
||||||
{
|
{
|
||||||
auto it = co.rbegin();
|
auto it = co.rbegin();
|
||||||
BEAST_EXPECT(it->key() == "c"); ++it;
|
BOOST_TEST(it->key() == "c"); ++it;
|
||||||
BEAST_EXPECT(it->key() == "b"); it++;
|
BOOST_TEST(it->key() == "b"); it++;
|
||||||
BEAST_EXPECT(it->key() == "a"); ++it;
|
BOOST_TEST(it->key() == "a"); ++it;
|
||||||
BEAST_EXPECT(it == co.rend());
|
BOOST_TEST(it == co.rend());
|
||||||
}
|
}
|
||||||
|
|
||||||
// crbegin()
|
// crbegin()
|
||||||
{
|
{
|
||||||
auto it = o.crbegin();
|
auto it = o.crbegin();
|
||||||
BEAST_EXPECT(it->key() == "c"); ++it;
|
BOOST_TEST(it->key() == "c"); ++it;
|
||||||
BEAST_EXPECT(it->key() == "b"); it++;
|
BOOST_TEST(it->key() == "b"); it++;
|
||||||
BEAST_EXPECT(it->key() == "a"); ++it;
|
BOOST_TEST(it->key() == "a"); ++it;
|
||||||
BEAST_EXPECT(it == o.crend());
|
BOOST_TEST(it == o.crend());
|
||||||
}
|
}
|
||||||
|
|
||||||
// rend()
|
// rend()
|
||||||
{
|
{
|
||||||
auto it = o.rend();
|
auto it = o.rend();
|
||||||
--it; BEAST_EXPECT(it->key() == "a");
|
--it; BOOST_TEST(it->key() == "a");
|
||||||
it--; BEAST_EXPECT(it->key() == "b");
|
it--; BOOST_TEST(it->key() == "b");
|
||||||
--it; BEAST_EXPECT(it->key() == "c");
|
--it; BOOST_TEST(it->key() == "c");
|
||||||
BEAST_EXPECT(it == o.rbegin());
|
BOOST_TEST(it == o.rbegin());
|
||||||
}
|
}
|
||||||
|
|
||||||
// rend() const
|
// rend() const
|
||||||
{
|
{
|
||||||
auto it = co.rend();
|
auto it = co.rend();
|
||||||
--it; BEAST_EXPECT(it->key() == "a");
|
--it; BOOST_TEST(it->key() == "a");
|
||||||
it--; BEAST_EXPECT(it->key() == "b");
|
it--; BOOST_TEST(it->key() == "b");
|
||||||
--it; BEAST_EXPECT(it->key() == "c");
|
--it; BOOST_TEST(it->key() == "c");
|
||||||
BEAST_EXPECT(it == co.rbegin());
|
BOOST_TEST(it == co.rbegin());
|
||||||
}
|
}
|
||||||
|
|
||||||
// crend()
|
// crend()
|
||||||
{
|
{
|
||||||
auto it = o.crend();
|
auto it = o.crend();
|
||||||
--it; BEAST_EXPECT(it->key() == "a");
|
--it; BOOST_TEST(it->key() == "a");
|
||||||
it--; BEAST_EXPECT(it->key() == "b");
|
it--; BOOST_TEST(it->key() == "b");
|
||||||
--it; BEAST_EXPECT(it->key() == "c");
|
--it; BOOST_TEST(it->key() == "c");
|
||||||
BEAST_EXPECT(it == o.crbegin());
|
BOOST_TEST(it == o.crbegin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,7 +584,7 @@ public:
|
|||||||
void
|
void
|
||||||
testCapacity()
|
testCapacity()
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
object{}.size() < object{}.max_size());
|
object{}.size() < object{}.max_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -598,15 +598,15 @@ public:
|
|||||||
{
|
{
|
||||||
object o;
|
object o;
|
||||||
o.clear();
|
o.clear();
|
||||||
BEAST_EXPECT(o.empty());
|
BOOST_TEST(o.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
object o;
|
object o;
|
||||||
o.emplace("x", 1);
|
o.emplace("x", 1);
|
||||||
BEAST_EXPECT(! o.empty());
|
BOOST_TEST(! o.empty());
|
||||||
o.clear();
|
o.clear();
|
||||||
BEAST_EXPECT(o.empty());
|
BOOST_TEST(o.empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,9 +617,9 @@ public:
|
|||||||
object o(sp);
|
object o(sp);
|
||||||
auto result = o.insert(
|
auto result = o.insert(
|
||||||
std::make_pair("x", 1));
|
std::make_pair("x", 1));
|
||||||
BEAST_EXPECT(result.second);
|
BOOST_TEST(result.second);
|
||||||
BEAST_EXPECT(result.first->key() == "x");
|
BOOST_TEST(result.first->key() == "x");
|
||||||
BEAST_EXPECT(result.first->value().as_int64() == 1);
|
BOOST_TEST(result.first->value().as_int64() == 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
@ -627,9 +627,9 @@ public:
|
|||||||
object o(sp);
|
object o(sp);
|
||||||
auto const p = std::make_pair("x", 1);
|
auto const p = std::make_pair("x", 1);
|
||||||
auto result = o.insert(p);
|
auto result = o.insert(p);
|
||||||
BEAST_EXPECT(result.second);
|
BOOST_TEST(result.second);
|
||||||
BEAST_EXPECT(result.first->key() == "x");
|
BOOST_TEST(result.first->key() == "x");
|
||||||
BEAST_EXPECT(result.first->value().as_int64() == 1);
|
BOOST_TEST(result.first->value().as_int64() == 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
@ -640,9 +640,9 @@ public:
|
|||||||
{"c", 3}}, sp);
|
{"c", 3}}, sp);
|
||||||
auto const result = o.insert(
|
auto const result = o.insert(
|
||||||
std::make_pair("b", 4));
|
std::make_pair("b", 4));
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
result.first->value().as_int64() == 2);
|
result.first->value().as_int64() == 2);
|
||||||
BEAST_EXPECT(! result.second);
|
BOOST_TEST(! result.second);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,7 +702,7 @@ public:
|
|||||||
{
|
{
|
||||||
object o({{"a", 1}}, sp);
|
object o({{"a", 1}}, sp);
|
||||||
o.insert_or_assign("a", str_);
|
o.insert_or_assign("a", str_);
|
||||||
BEAST_EXPECT(o["a"].is_string());
|
BOOST_TEST(o["a"].is_string());
|
||||||
});
|
});
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
@ -712,8 +712,8 @@ public:
|
|||||||
{"b", 2},
|
{"b", 2},
|
||||||
{"c", 3}}, sp);
|
{"c", 3}}, sp);
|
||||||
o.insert_or_assign("d", str_);
|
o.insert_or_assign("d", str_);
|
||||||
BEAST_EXPECT(o["d"].is_string());
|
BOOST_TEST(o["d"].is_string());
|
||||||
BEAST_EXPECT(o.size() == 4);
|
BOOST_TEST(o.size() == 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
@ -727,9 +727,9 @@ public:
|
|||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
{
|
{
|
||||||
object o({{"a", 1}}, sp);
|
object o({{"a", 1}}, sp);
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
! o.insert_or_assign("a", 2).second);
|
! o.insert_or_assign("a", 2).second);
|
||||||
BEAST_EXPECT(o["a"].as_int64() == 2);
|
BOOST_TEST(o["a"].as_int64() == 2);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,8 +753,8 @@ public:
|
|||||||
{"b", true},
|
{"b", true},
|
||||||
{"c", "hello"}}, sp);
|
{"c", "hello"}}, sp);
|
||||||
auto it = o.erase(o.begin());
|
auto it = o.erase(o.begin());
|
||||||
BEAST_EXPECT(it->key() == "c");
|
BOOST_TEST(it->key() == "c");
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
it->value().as_string() == "hello");
|
it->value().as_string() == "hello");
|
||||||
check(o, 7);
|
check(o, 7);
|
||||||
});
|
});
|
||||||
@ -767,7 +767,7 @@ public:
|
|||||||
{"a", 1},
|
{"a", 1},
|
||||||
{"b", true},
|
{"b", true},
|
||||||
{"c", "hello"}});
|
{"c", "hello"}});
|
||||||
BEAST_EXPECT(o.erase("b2") == 0);
|
BOOST_TEST(o.erase("b2") == 0);
|
||||||
check(o, 3);
|
check(o, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -777,7 +777,7 @@ public:
|
|||||||
{"b", true},
|
{"b", true},
|
||||||
{"b2", 2},
|
{"b2", 2},
|
||||||
{"c", "hello"}});
|
{"c", "hello"}});
|
||||||
BEAST_EXPECT(o.erase("b2") == 1);
|
BOOST_TEST(o.erase("b2") == 1);
|
||||||
check(o, 7);
|
check(o, 7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -788,9 +788,9 @@ public:
|
|||||||
object o1 = {{"a",1}, {"b",true}, {"c", "hello"}};
|
object o1 = {{"a",1}, {"b",true}, {"c", "hello"}};
|
||||||
object o2 = {{"d",{1,2,3}}};
|
object o2 = {{"d",{1,2,3}}};
|
||||||
swap(o1, o2);
|
swap(o1, o2);
|
||||||
BEAST_EXPECT(o1.size() == 1);
|
BOOST_TEST(o1.size() == 1);
|
||||||
BEAST_EXPECT(o2.size() == 3);
|
BOOST_TEST(o2.size() == 3);
|
||||||
BEAST_EXPECT(o1.count("d") == 1);
|
BOOST_TEST(o1.count("d") == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
@ -798,9 +798,9 @@ public:
|
|||||||
object o1 = {{"a",1}, {"b",true}, {"c", "hello"}};
|
object o1 = {{"a",1}, {"b",true}, {"c", "hello"}};
|
||||||
object o2({{"d",{1,2,3}}}, sp);
|
object o2({{"d",{1,2,3}}}, sp);
|
||||||
swap(o1, o2);
|
swap(o1, o2);
|
||||||
BEAST_EXPECT(o1.size() == 1);
|
BOOST_TEST(o1.size() == 1);
|
||||||
BEAST_EXPECT(o2.size() == 3);
|
BOOST_TEST(o2.size() == 3);
|
||||||
BEAST_EXPECT(o1.count("d") == 1);
|
BOOST_TEST(o1.count("d") == 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
fail_loop([&](storage_ptr const& sp)
|
fail_loop([&](storage_ptr const& sp)
|
||||||
@ -808,9 +808,9 @@ public:
|
|||||||
object o1({{"d",{1,2,3}}}, sp);
|
object o1({{"d",{1,2,3}}}, sp);
|
||||||
object o2 = {{"a",1}, {"b",true}, {"c", "hello"}};
|
object o2 = {{"a",1}, {"b",true}, {"c", "hello"}};
|
||||||
swap(o1, o2);
|
swap(o1, o2);
|
||||||
BEAST_EXPECT(o1.size() == 3);
|
BOOST_TEST(o1.size() == 3);
|
||||||
BEAST_EXPECT(o2.size() == 1);
|
BOOST_TEST(o2.size() == 1);
|
||||||
BEAST_EXPECT(o2.count("d") == 1);
|
BOOST_TEST(o2.count("d") == 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -828,17 +828,17 @@ public:
|
|||||||
|
|
||||||
// at(key)
|
// at(key)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
o1.at("a").is_number());
|
o1.at("a").is_number());
|
||||||
BEAST_THROWS((o1.at("d")),
|
BOOST_TEST_THROWS((o1.at("d")),
|
||||||
std::out_of_range);
|
std::out_of_range);
|
||||||
}
|
}
|
||||||
|
|
||||||
// at(key) const
|
// at(key) const
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
co1.at("a").is_number());
|
co1.at("a").is_number());
|
||||||
BEAST_THROWS((co1.at("d")),
|
BOOST_TEST_THROWS((co1.at("d")),
|
||||||
std::out_of_range);
|
std::out_of_range);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -848,31 +848,31 @@ public:
|
|||||||
{"a", 1},
|
{"a", 1},
|
||||||
{"b", true},
|
{"b", true},
|
||||||
{"c", "hello"}});
|
{"c", "hello"}});
|
||||||
BEAST_EXPECT(o.count("d") == 0);;
|
BOOST_TEST(o.count("d") == 0);;
|
||||||
BEAST_EXPECT(o["a"].is_number());
|
BOOST_TEST(o["a"].is_number());
|
||||||
BEAST_EXPECT(o["d"].is_null());
|
BOOST_TEST(o["d"].is_null());
|
||||||
BEAST_EXPECT(o.count("d") == 1);
|
BOOST_TEST(o.count("d") == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// count(key)
|
// count(key)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(o1.count("a") == 1);
|
BOOST_TEST(o1.count("a") == 1);
|
||||||
BEAST_EXPECT(o1.count("d") == 0);
|
BOOST_TEST(o1.count("d") == 0);
|
||||||
BEAST_EXPECT(o1.count("e") == 0);
|
BOOST_TEST(o1.count("e") == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// find(key)
|
// find(key)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
o1.find("a")->key() == "a");
|
o1.find("a")->key() == "a");
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
o1.find("e") == o1.end());
|
o1.find("e") == o1.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// contains(key)
|
// contains(key)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(o1.contains("a"));
|
BOOST_TEST(o1.contains("a"));
|
||||||
BEAST_EXPECT(! o1.contains("e"));
|
BOOST_TEST(! o1.contains("e"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,17 +886,17 @@ public:
|
|||||||
for(std::size_t i = 0; i < 10; ++i)
|
for(std::size_t i = 0; i < 10; ++i)
|
||||||
o.emplace(std::to_string(i), i);
|
o.emplace(std::to_string(i), i);
|
||||||
o.reserve(15);
|
o.reserve(15);
|
||||||
BEAST_EXPECT(o.capacity() >= 15);
|
BOOST_TEST(o.capacity() >= 15);
|
||||||
o.reserve(20);
|
o.reserve(20);
|
||||||
BEAST_EXPECT(o.capacity() >= 20);
|
BOOST_TEST(o.capacity() >= 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
object o;
|
object o;
|
||||||
o.reserve(3);
|
o.reserve(3);
|
||||||
BEAST_EXPECT(o.capacity() == 3);
|
BOOST_TEST(o.capacity() == 3);
|
||||||
o.reserve(7);
|
o.reserve(7);
|
||||||
BEAST_EXPECT(o.capacity() == 7);
|
BOOST_TEST(o.capacity() == 7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -913,18 +913,18 @@ public:
|
|||||||
{"b", true},
|
{"b", true},
|
||||||
{"b", {1,2,3}},
|
{"b", {1,2,3}},
|
||||||
{"c", "hello"}});
|
{"c", "hello"}});
|
||||||
BEAST_EXPECT(o.at("a").as_int64() == 1);
|
BOOST_TEST(o.at("a").as_int64() == 1);
|
||||||
BEAST_EXPECT(o.at("b").as_bool());
|
BOOST_TEST(o.at("b").as_bool());
|
||||||
BEAST_EXPECT(o.at("c").as_string() == "hello");
|
BOOST_TEST(o.at("c").as_string() == "hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
// find in missing or empty tables
|
// find in missing or empty tables
|
||||||
{
|
{
|
||||||
object o;
|
object o;
|
||||||
BEAST_EXPECT(o.find("a") == o.end());
|
BOOST_TEST(o.find("a") == o.end());
|
||||||
o.reserve(3);
|
o.reserve(3);
|
||||||
BEAST_EXPECT(o.capacity() > 0);
|
BOOST_TEST(o.capacity() > 0);
|
||||||
BEAST_EXPECT(o.find("a") == o.end());
|
BOOST_TEST(o.find("a") == o.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// destroy key_value_pair array with need_free=false
|
// destroy key_value_pair array with need_free=false
|
||||||
@ -939,7 +939,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
testSpecial();
|
testSpecial();
|
||||||
testIterators();
|
testIterators();
|
||||||
@ -951,7 +951,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,object);
|
TEST_SUITE(object_test, "boost.json.object");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -10,20 +10,23 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/json/parser.hpp>
|
#include <boost/json/parser.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
#include <boost/json/pool.hpp>
|
#include <boost/json/pool.hpp>
|
||||||
#include <boost/json/serializer.hpp>
|
#include <boost/json/serializer.hpp>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "parse-vectors.hpp"
|
#include "parse-vectors.hpp"
|
||||||
#include "test.hpp"
|
#include "test.hpp"
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
class parser_test : public beast::unit_test::suite
|
class parser_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
::test_suite::log_type log;
|
||||||
|
|
||||||
value
|
value
|
||||||
from_string_test(
|
from_string_test(
|
||||||
string_view s,
|
string_view s,
|
||||||
@ -38,8 +41,7 @@ public:
|
|||||||
ec);
|
ec);
|
||||||
if(! ec)
|
if(! ec)
|
||||||
p.finish(ec);
|
p.finish(ec);
|
||||||
BEAST_EXPECTS(! ec,
|
BOOST_TEST(! ec);
|
||||||
ec.message());
|
|
||||||
//log << " " << to_string_test(p.get()) << std::endl;
|
//log << " " << to_string_test(p.get()) << std::endl;
|
||||||
return p.release();
|
return p.release();
|
||||||
}
|
}
|
||||||
@ -54,7 +56,7 @@ public:
|
|||||||
to_string(jv1);
|
to_string(jv1);
|
||||||
auto jv2 =
|
auto jv2 =
|
||||||
from_string_test(s2);
|
from_string_test(s2);
|
||||||
if(! BEAST_EXPECT(equal(jv1, jv2)))
|
if(! BOOST_TEST(equal(jv1, jv2)))
|
||||||
log <<
|
log <<
|
||||||
" " << s1 << "\n" <<
|
" " << s1 << "\n" <<
|
||||||
" " << s2 << std::endl;
|
" " << s2 << std::endl;
|
||||||
@ -186,13 +188,11 @@ public:
|
|||||||
parser p;
|
parser p;
|
||||||
p.start();
|
p.start();
|
||||||
p.write(js.data(), N, ec);
|
p.write(js.data(), N, ec);
|
||||||
if(BEAST_EXPECTS(! ec,
|
if(BOOST_TEST(! ec))
|
||||||
ec.message()))
|
|
||||||
{
|
{
|
||||||
p.finish(js.data() + N,
|
p.finish(js.data() + N,
|
||||||
js.size() - N, ec);
|
js.size() - N, ec);
|
||||||
if(BEAST_EXPECTS(! ec,
|
if(BOOST_TEST(! ec))
|
||||||
ec.message()))
|
|
||||||
check_round_trip(
|
check_round_trip(
|
||||||
p.release(), js);
|
p.release(), js);
|
||||||
}
|
}
|
||||||
@ -246,9 +246,8 @@ public:
|
|||||||
parser p;
|
parser p;
|
||||||
error_code ec;
|
error_code ec;
|
||||||
p.write("", 0, ec);
|
p.write("", 0, ec);
|
||||||
BEAST_EXPECTS(
|
BOOST_TEST(
|
||||||
ec == error::need_start,
|
ec == error::need_start);
|
||||||
ec.message());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// destroy after start
|
// destroy after start
|
||||||
@ -260,7 +259,7 @@ public:
|
|||||||
// release before done
|
// release before done
|
||||||
{
|
{
|
||||||
parser p;
|
parser p;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
p.release(),
|
p.release(),
|
||||||
std::logic_error);
|
std::logic_error);
|
||||||
}
|
}
|
||||||
@ -287,14 +286,14 @@ public:
|
|||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
auto jv = parse(js, ec);
|
auto jv = parse(js, ec);
|
||||||
BEAST_EXPECTS(! ec, ec.message());
|
BOOST_TEST(! ec);
|
||||||
check_round_trip(jv, js);
|
check_round_trip(jv, js);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
auto jv = parse("xxx", ec);
|
auto jv = parse("xxx", ec);
|
||||||
BEAST_EXPECT(ec);
|
BOOST_TEST(ec);
|
||||||
BEAST_EXPECT(jv.is_null());
|
BOOST_TEST(jv.is_null());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +303,7 @@ public:
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
scoped_storage<pool> sp;
|
scoped_storage<pool> sp;
|
||||||
auto jv = parse(js, ec, sp);
|
auto jv = parse(js, ec, sp);
|
||||||
BEAST_EXPECTS(! ec, ec.message());
|
BOOST_TEST(! ec);
|
||||||
check_round_trip(jv, js);
|
check_round_trip(jv, js);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,8 +311,8 @@ public:
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
scoped_storage<pool> sp;
|
scoped_storage<pool> sp;
|
||||||
auto jv = parse("xxx", ec, sp);
|
auto jv = parse("xxx", ec, sp);
|
||||||
BEAST_EXPECT(ec);
|
BOOST_TEST(ec);
|
||||||
BEAST_EXPECT(jv.is_null());
|
BOOST_TEST(jv.is_null());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,7 +326,7 @@ public:
|
|||||||
|
|
||||||
{
|
{
|
||||||
value jv;
|
value jv;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
jv = parse("{,"),
|
jv = parse("{,"),
|
||||||
system_error);
|
system_error);
|
||||||
}
|
}
|
||||||
@ -343,7 +342,7 @@ public:
|
|||||||
{
|
{
|
||||||
scoped_storage<pool> sp;
|
scoped_storage<pool> sp;
|
||||||
value jv;
|
value jv;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
jv = parse("xxx", sp),
|
jv = parse("xxx", sp),
|
||||||
system_error);
|
system_error);
|
||||||
}
|
}
|
||||||
@ -381,9 +380,9 @@ R"xx({
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
p.start();
|
p.start();
|
||||||
p.finish(in.data(), in.size(), ec);
|
p.finish(in.data(), in.size(), ec);
|
||||||
if(BEAST_EXPECTS(! ec, ec.message()))
|
if(BOOST_TEST(! ec))
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(to_string(p.release()) ==
|
BOOST_TEST(to_string(p.release()) ==
|
||||||
"{\"glossary\":{\"title\":\"example glossary\",\"GlossDiv\":"
|
"{\"glossary\":{\"title\":\"example glossary\",\"GlossDiv\":"
|
||||||
"{\"title\":\"S\",\"GlossList\":{\"GlossEntry\":{\"ID\":\"SGML\","
|
"{\"title\":\"S\",\"GlossList\":{\"GlossEntry\":{\"ID\":\"SGML\","
|
||||||
"\"SortAs\":\"SGML\",\"GlossTerm\":\"Standard Generalized Markup "
|
"\"SortAs\":\"SGML\",\"GlossTerm\":\"Standard Generalized Markup "
|
||||||
@ -399,7 +398,7 @@ R"xx({
|
|||||||
void
|
void
|
||||||
testIssue15()
|
testIssue15()
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(
|
BOOST_TEST(
|
||||||
json::parse("{\"port\": 12345}")
|
json::parse("{\"port\": 12345}")
|
||||||
.as_object()
|
.as_object()
|
||||||
.at("port")
|
.at("port")
|
||||||
@ -422,7 +421,7 @@ R"xx({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,parser);
|
TEST_SUITE(parser_test, "boost.json.parser");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
#include <boost/json/pool.hpp>
|
#include <boost/json/pool.hpp>
|
||||||
|
|
||||||
#include <boost/json/parser.hpp>
|
#include <boost/json/parser.hpp>
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
class pool_test : public beast::unit_test::suite
|
class pool_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void
|
void
|
||||||
@ -46,17 +47,17 @@ R"xx({
|
|||||||
}
|
}
|
||||||
})xx"
|
})xx"
|
||||||
, make_storage<pool>());
|
, make_storage<pool>());
|
||||||
pass();
|
BOOST_TEST_PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
testStorage();
|
testStorage();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,pool);
|
TEST_SUITE(pool_test, "boost.json.pool");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -10,18 +10,24 @@
|
|||||||
#ifndef GTEST_HPP
|
#ifndef GTEST_HPP
|
||||||
#define GTEST_HPP
|
#define GTEST_HPP
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
#include <boost/utility/string_view.hpp>
|
#include <boost/utility/string_view.hpp>
|
||||||
|
|
||||||
#define TEST(s1,s2) \
|
#include "test_suite.hpp"
|
||||||
struct s2 ## s1 ## _test; \
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,Ryu,s2##s1); \
|
|
||||||
struct s2 ## s1 ## _test : ::boost::beast::unit_test::suite { \
|
|
||||||
void run() override; }; void s2##s1##_test::run()
|
|
||||||
|
|
||||||
#define EXPECT_STREQ(s1, s2) BEAST_EXPECT(::boost::string_view(s1) == ::boost::string_view(s2))
|
#define TEST(s1,s2) \
|
||||||
#define ASSERT_STREQ(s1, s2) { auto const s1_ = (s1); auto const s2_ = (s2); \
|
struct s1 ## _ ## s2 ## _test; \
|
||||||
|
TEST_SUITE(s1 ## _ ## s2 ## _test, "boost.Ryu." #s1 "." #s2); \
|
||||||
|
struct s1 ## _ ## s2 ## _test { \
|
||||||
|
void run(); }; void s1 ## _ ## s2 ## _test::run()
|
||||||
|
|
||||||
|
#define EXPECT_STREQ(s1, s2) \
|
||||||
|
BOOST_TEST(::boost::json::string_view(s1) == \
|
||||||
|
::boost::json::string_view(s2))
|
||||||
|
|
||||||
|
#define ASSERT_STREQ(s1, s2) \
|
||||||
|
{ auto const s1_ = (s1); auto const s2_ = (s2); \
|
||||||
EXPECT_STREQ(s1_, s2_); }
|
EXPECT_STREQ(s1_, s2_); }
|
||||||
#define ASSERT_EQ(e1, e2) BEAST_EXPECT((e1)==(e2))
|
|
||||||
|
#define ASSERT_EQ(e1, e2) BOOST_TEST((e1)==(e2))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,17 +11,20 @@
|
|||||||
#include <boost/json/serializer.hpp>
|
#include <boost/json/serializer.hpp>
|
||||||
|
|
||||||
#include <boost/json/parser.hpp>
|
#include <boost/json/parser.hpp>
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
#include <iostream>
|
||||||
|
|
||||||
#include "parse-vectors.hpp"
|
#include "parse-vectors.hpp"
|
||||||
#include "test.hpp"
|
#include "test.hpp"
|
||||||
#include <iostream>
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
class serializer_test : public beast::unit_test::suite
|
class serializer_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
::test_suite::log_type log;
|
||||||
|
|
||||||
void
|
void
|
||||||
grind_one(
|
grind_one(
|
||||||
string_view s,
|
string_view s,
|
||||||
@ -32,7 +35,7 @@ public:
|
|||||||
error_code ec;
|
error_code ec;
|
||||||
auto const s1 = to_string(jv);
|
auto const s1 = to_string(jv);
|
||||||
auto const jv2 = parse(s1, ec);
|
auto const jv2 = parse(s1, ec);
|
||||||
if(! BEAST_EXPECT(equal(jv, jv2)))
|
if(! BOOST_TEST(equal(jv, jv2)))
|
||||||
{
|
{
|
||||||
if(name.empty())
|
if(name.empty())
|
||||||
log <<
|
log <<
|
||||||
@ -58,7 +61,7 @@ public:
|
|||||||
|
|
||||||
auto const s1 = to_string(jv);
|
auto const s1 = to_string(jv);
|
||||||
auto const jv2 = parse(s1, ec);
|
auto const jv2 = parse(s1, ec);
|
||||||
BEAST_EXPECT(equal(jv, jv2));
|
BOOST_TEST(equal(jv, jv2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +97,7 @@ public:
|
|||||||
" " << s1 << "\n"
|
" " << s1 << "\n"
|
||||||
" " << s2 << std::endl;
|
" " << s2 << std::endl;
|
||||||
};
|
};
|
||||||
if(! BEAST_EXPECT(
|
if(! BOOST_TEST(
|
||||||
s2.size() == i))
|
s2.size() == i))
|
||||||
{
|
{
|
||||||
dump();
|
dump();
|
||||||
@ -103,13 +106,13 @@ public:
|
|||||||
s2.grow(sr.read(
|
s2.grow(sr.read(
|
||||||
s2.data() + i,
|
s2.data() + i,
|
||||||
s1.size() - i));
|
s1.size() - i));
|
||||||
if(! BEAST_EXPECT(
|
if(! BOOST_TEST(
|
||||||
s2.size() == s1.size()))
|
s2.size() == s1.size()))
|
||||||
{
|
{
|
||||||
dump();
|
dump();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(! BEAST_EXPECT(s2 == s1))
|
if(! BOOST_TEST(s2 == s1))
|
||||||
{
|
{
|
||||||
dump();
|
dump();
|
||||||
break;
|
break;
|
||||||
@ -135,7 +138,7 @@ public:
|
|||||||
// is_done()
|
// is_done()
|
||||||
{
|
{
|
||||||
serializer sr(jv);
|
serializer sr(jv);
|
||||||
BEAST_EXPECT(! sr.is_done());
|
BOOST_TEST(! sr.is_done());
|
||||||
}
|
}
|
||||||
|
|
||||||
// read()
|
// read()
|
||||||
@ -145,15 +148,15 @@ public:
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
auto n = sr.read(
|
auto n = sr.read(
|
||||||
buf, sizeof(buf));
|
buf, sizeof(buf));
|
||||||
BEAST_EXPECT(sr.is_done());
|
BOOST_TEST(sr.is_done());
|
||||||
BEAST_EXPECT(string_view(
|
BOOST_TEST(string_view(
|
||||||
buf, n) == "null");
|
buf, n) == "null");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
serializer sr;
|
serializer sr;
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
sr.read(buf, sizeof(buf)),
|
sr.read(buf, sizeof(buf)),
|
||||||
std::logic_error);
|
std::logic_error);
|
||||||
}
|
}
|
||||||
@ -443,15 +446,13 @@ public:
|
|||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
auto const jv1 = parse(js, ec);
|
auto const jv1 = parse(js, ec);
|
||||||
if(! BEAST_EXPECTS(! ec,
|
if(! BOOST_TEST(! ec))
|
||||||
ec.message()))
|
|
||||||
return;
|
return;
|
||||||
auto const jv2 =
|
auto const jv2 =
|
||||||
parse(to_ostream(jv1), ec);
|
parse(to_ostream(jv1), ec);
|
||||||
if(! BEAST_EXPECTS(! ec,
|
if(! BOOST_TEST(! ec))
|
||||||
ec.message()))
|
|
||||||
return;
|
return;
|
||||||
if(! BEAST_EXPECT(equal(jv1, jv2)))
|
if(! BOOST_TEST(equal(jv1, jv2)))
|
||||||
log <<
|
log <<
|
||||||
" " << js << "\n"
|
" " << js << "\n"
|
||||||
" " << jv1 << "\n"
|
" " << jv1 << "\n"
|
||||||
@ -474,7 +475,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,serializer);
|
TEST_SUITE(serializer_test, "boost.json.serializer");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -9,10 +9,11 @@
|
|||||||
|
|
||||||
#include <boost/json.hpp>
|
#include <boost/json.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
#include <complex>
|
#include <complex>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
@ -477,11 +478,11 @@ usingExchange2()
|
|||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
|
|
||||||
class snippets_test : public beast::unit_test::suite
|
class snippets_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
(void)&usingStrings;
|
(void)&usingStrings;
|
||||||
(void)&usingArrays;
|
(void)&usingArrays;
|
||||||
@ -494,11 +495,11 @@ public:
|
|||||||
(void)&usingSerializing;
|
(void)&usingSerializing;
|
||||||
(void)&usingExchange1;
|
(void)&usingExchange1;
|
||||||
(void)&usingExchange2;
|
(void)&usingExchange2;
|
||||||
pass();
|
BOOST_TEST_PASS();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,snippets);
|
TEST_SUITE(snippets_test, "boost.json.snippets");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -10,14 +10,13 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <boost/json/storage_ptr.hpp>
|
#include <boost/json/storage_ptr.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
|
|
||||||
#include "test.hpp"
|
#include "test.hpp"
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
class storage_ptr_test : public beast::unit_test::suite
|
class storage_ptr_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct not_storage
|
struct not_storage
|
||||||
@ -91,22 +90,22 @@ public:
|
|||||||
// storage_ptr()
|
// storage_ptr()
|
||||||
{
|
{
|
||||||
storage_ptr sp;
|
storage_ptr sp;
|
||||||
BEAST_EXPECT(sp.get());
|
BOOST_TEST(sp.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// storage_ptr(storage_ptr&&)
|
// storage_ptr(storage_ptr&&)
|
||||||
{
|
{
|
||||||
storage_ptr sp1 = dsp;
|
storage_ptr sp1 = dsp;
|
||||||
storage_ptr sp2(std::move(sp1));
|
storage_ptr sp2(std::move(sp1));
|
||||||
BEAST_EXPECT(sp1.get());
|
BOOST_TEST(sp1.get());
|
||||||
BEAST_EXPECT(*sp2 == *dsp);
|
BOOST_TEST(*sp2 == *dsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// storage_ptr(storage_ptr const&)
|
// storage_ptr(storage_ptr const&)
|
||||||
{
|
{
|
||||||
storage_ptr sp1 = dsp;
|
storage_ptr sp1 = dsp;
|
||||||
storage_ptr sp2(sp1);
|
storage_ptr sp2(sp1);
|
||||||
BEAST_EXPECT(sp1 == sp2);
|
BOOST_TEST(sp1 == sp2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator=(storage_ptr&&)
|
// operator=(storage_ptr&&)
|
||||||
@ -114,7 +113,7 @@ public:
|
|||||||
storage_ptr sp1(dsp);
|
storage_ptr sp1(dsp);
|
||||||
storage_ptr sp2(usp);
|
storage_ptr sp2(usp);
|
||||||
sp2 = std::move(sp1);
|
sp2 = std::move(sp1);
|
||||||
BEAST_EXPECT(*sp2 == *dsp);
|
BOOST_TEST(*sp2 == *dsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator=(storage_ptr const&)
|
// operator=(storage_ptr const&)
|
||||||
@ -122,43 +121,43 @@ public:
|
|||||||
storage_ptr sp1(dsp);
|
storage_ptr sp1(dsp);
|
||||||
storage_ptr sp2(usp);
|
storage_ptr sp2(usp);
|
||||||
sp2 = sp1;
|
sp2 = sp1;
|
||||||
BEAST_EXPECT(*sp1 == *sp2);
|
BOOST_TEST(*sp1 == *sp2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get()
|
// get()
|
||||||
{
|
{
|
||||||
storage_ptr sp(dsp);
|
storage_ptr sp(dsp);
|
||||||
BEAST_EXPECT(sp.get() == dsp.get());
|
BOOST_TEST(sp.get() == dsp.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator->()
|
// operator->()
|
||||||
{
|
{
|
||||||
storage_ptr sp(dsp);
|
storage_ptr sp(dsp);
|
||||||
BEAST_EXPECT(sp.operator->() == dsp.get());
|
BOOST_TEST(sp.operator->() == dsp.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator*()
|
// operator*()
|
||||||
{
|
{
|
||||||
storage_ptr sp(dsp);
|
storage_ptr sp(dsp);
|
||||||
BEAST_EXPECT(&sp.operator*() == dsp.get());
|
BOOST_TEST(&sp.operator*() == dsp.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// exception in make_storage
|
// exception in make_storage
|
||||||
{
|
{
|
||||||
BEAST_THROWS(
|
BOOST_TEST_THROWS(
|
||||||
make_storage<throwing>(),
|
make_storage<throwing>(),
|
||||||
std::exception);
|
std::exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
testMembers();
|
testMembers();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,storage_ptr);
|
TEST_SUITE(storage_ptr_test, "boost.json.storage_ptr");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
1056
test/string.cpp
1056
test/string.cpp
File diff suppressed because it is too large
Load Diff
@ -15,12 +15,14 @@
|
|||||||
#include <boost/json/serializer.hpp>
|
#include <boost/json/serializer.hpp>
|
||||||
#include <boost/json/storage_ptr.hpp>
|
#include <boost/json/storage_ptr.hpp>
|
||||||
#include <boost/json/detail/format.hpp>
|
#include <boost/json/detail/format.hpp>
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
@ -54,7 +56,7 @@ struct fail_storage
|
|||||||
|
|
||||||
~fail_storage()
|
~fail_storage()
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(nalloc == 0);
|
BOOST_TEST(nalloc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
@ -79,7 +81,7 @@ struct fail_storage
|
|||||||
std::size_t,
|
std::size_t,
|
||||||
std::size_t) noexcept
|
std::size_t) noexcept
|
||||||
{
|
{
|
||||||
if(BEAST_EXPECT(nalloc > 0))
|
if(BOOST_TEST(nalloc > 0))
|
||||||
--nalloc;
|
--nalloc;
|
||||||
::operator delete(p);
|
::operator delete(p);
|
||||||
}
|
}
|
||||||
@ -103,7 +105,7 @@ fail_loop(F&& f)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
BEAST_EXPECT(ss->fail < 200);
|
BOOST_TEST(ss->fail < 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
@ -577,7 +579,7 @@ check_storage(
|
|||||||
object const& o,
|
object const& o,
|
||||||
storage_ptr const& sp)
|
storage_ptr const& sp)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(equal_storage(o, sp));
|
BOOST_TEST(equal_storage(o, sp));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -586,7 +588,7 @@ check_storage(
|
|||||||
array const& a,
|
array const& a,
|
||||||
storage_ptr const& sp)
|
storage_ptr const& sp)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(equal_storage(a, sp));
|
BOOST_TEST(equal_storage(a, sp));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -595,7 +597,7 @@ check_storage(
|
|||||||
value const& v,
|
value const& v,
|
||||||
storage_ptr const& sp)
|
storage_ptr const& sp)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(equal_storage(v, sp));
|
BOOST_TEST(equal_storage(v, sp));
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
|
641
test/test_suite.hpp
Normal file
641
test/test_suite.hpp
Normal file
@ -0,0 +1,641 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
// Official repository: https://github.com/vinniefalco/json
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef TEST_SUITE_HPP
|
||||||
|
#define TEST_SUITE_HPP
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <ios>
|
||||||
|
#include <memory>
|
||||||
|
#include <ostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <streambuf>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#include <debugapi.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// This is a derivative work
|
||||||
|
// Copyright 2002-2018 Peter Dimov
|
||||||
|
// Copyright (c) 2002, 2009, 2014 Peter Dimov
|
||||||
|
// Copyright (2) Beman Dawes 2010, 2011
|
||||||
|
// Copyright (3) Ion Gaztanaga 2013
|
||||||
|
//
|
||||||
|
// Copyright 2018 Glen Joseph Fernandes
|
||||||
|
// (glenjofe@gmail.com)
|
||||||
|
|
||||||
|
namespace test_suite {
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<
|
||||||
|
class CharT, class Traits, class Allocator>
|
||||||
|
class debug_streambuf
|
||||||
|
: public std::basic_stringbuf<
|
||||||
|
CharT, Traits, Allocator>
|
||||||
|
{
|
||||||
|
using ostream =
|
||||||
|
std::basic_ostream<CharT, Traits>;
|
||||||
|
|
||||||
|
ostream& os_;
|
||||||
|
bool dbg_;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void write(T const*) = delete;
|
||||||
|
|
||||||
|
void write(char const* s)
|
||||||
|
{
|
||||||
|
if(dbg_)
|
||||||
|
::OutputDebugStringA(s);
|
||||||
|
os_ << s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void write(wchar_t const* s)
|
||||||
|
{
|
||||||
|
if(dbg_)
|
||||||
|
::OutputDebugStringW(s);
|
||||||
|
os_ << s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit
|
||||||
|
debug_streambuf(ostream& os)
|
||||||
|
: os_(os)
|
||||||
|
, dbg_(::IsDebuggerPresent() != 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~debug_streambuf()
|
||||||
|
{
|
||||||
|
sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sync() override
|
||||||
|
{
|
||||||
|
write(this->str().c_str());
|
||||||
|
this->str("");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** std::ostream with Visual Studio IDE redirection.
|
||||||
|
|
||||||
|
Instances of this stream wrap a specified `std::ostream`
|
||||||
|
(such as `std::cout` or `std::cerr`). If the IDE debugger
|
||||||
|
is attached when the stream is created, output will be
|
||||||
|
additionally copied to the Visual Studio Output window.
|
||||||
|
*/
|
||||||
|
template<
|
||||||
|
class CharT,
|
||||||
|
class Traits = std::char_traits<CharT>,
|
||||||
|
class Allocator = std::allocator<CharT>
|
||||||
|
>
|
||||||
|
class basic_debug_stream
|
||||||
|
: public std::basic_ostream<CharT, Traits>
|
||||||
|
{
|
||||||
|
detail::debug_streambuf<
|
||||||
|
CharT, Traits, Allocator> buf_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** Construct a stream.
|
||||||
|
|
||||||
|
@param os The output stream to wrap.
|
||||||
|
*/
|
||||||
|
explicit
|
||||||
|
basic_debug_stream(std::ostream& os)
|
||||||
|
: std::basic_ostream<CharT, Traits>(&buf_)
|
||||||
|
, buf_(os)
|
||||||
|
{
|
||||||
|
if(os.flags() & std::ios::unitbuf)
|
||||||
|
std::unitbuf(*this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
using debug_stream = detail::basic_debug_stream<char>;
|
||||||
|
using debug_wstream = detail::basic_debug_stream<wchar_t>;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
using debug_stream = std::ostream&;
|
||||||
|
using debug_wstream = std::wostream&;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
struct suite_info
|
||||||
|
{
|
||||||
|
char const* name;
|
||||||
|
void (*run)();
|
||||||
|
};
|
||||||
|
|
||||||
|
class runner;
|
||||||
|
|
||||||
|
inline
|
||||||
|
runner*&
|
||||||
|
current() noexcept;
|
||||||
|
|
||||||
|
class runner
|
||||||
|
{
|
||||||
|
runner* saved_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
runner() noexcept
|
||||||
|
: saved_(current())
|
||||||
|
{
|
||||||
|
current() = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual
|
||||||
|
~runner()
|
||||||
|
{
|
||||||
|
current() = saved_;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void on_begin(char const* name) = 0;
|
||||||
|
virtual void on_end() = 0;
|
||||||
|
|
||||||
|
virtual void note(char const* msg) = 0;
|
||||||
|
virtual void pass(char const* expr, char const* file, int line, char const* func) = 0;
|
||||||
|
virtual void fail(char const* expr, char const* file, int line, char const* func) = 0;
|
||||||
|
|
||||||
|
template<class Bool
|
||||||
|
#if 0
|
||||||
|
,class = typename std::enable_if<
|
||||||
|
std::is_convertible<bool, Bool>::Value>::type
|
||||||
|
#endif
|
||||||
|
>
|
||||||
|
bool
|
||||||
|
maybe_fail(
|
||||||
|
Bool cond,
|
||||||
|
char const* expr,
|
||||||
|
char const* file,
|
||||||
|
int line,
|
||||||
|
char const* func)
|
||||||
|
{
|
||||||
|
if(static_cast<bool>(cond))
|
||||||
|
{
|
||||||
|
pass(expr, file, line, func);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
fail(expr, file, line, func);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
run(suite_info const& si)
|
||||||
|
{
|
||||||
|
on_begin(si.name);
|
||||||
|
si.run();
|
||||||
|
on_end();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
runner*&
|
||||||
|
current() noexcept
|
||||||
|
{
|
||||||
|
static runner* p = nullptr;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
|
||||||
|
using clock_type =
|
||||||
|
std::chrono::steady_clock;
|
||||||
|
|
||||||
|
struct elapsed
|
||||||
|
{
|
||||||
|
clock_type::duration d;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline
|
||||||
|
std::ostream&
|
||||||
|
operator<<(
|
||||||
|
std::ostream& os,
|
||||||
|
elapsed const& e)
|
||||||
|
{
|
||||||
|
using namespace std::chrono;
|
||||||
|
auto const ms = duration_cast<
|
||||||
|
milliseconds>(e.d);
|
||||||
|
if(ms < seconds{1})
|
||||||
|
{
|
||||||
|
os << ms.count() << "ms";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::streamsize width{
|
||||||
|
os.width()};
|
||||||
|
std::streamsize precision{
|
||||||
|
os.precision()};
|
||||||
|
os << std::fixed <<
|
||||||
|
std::setprecision(1) <<
|
||||||
|
(ms.count() / 1000.0) << "s";
|
||||||
|
os.precision(precision);
|
||||||
|
os.width(width);
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
class simple_runner : public runner
|
||||||
|
{
|
||||||
|
struct summary
|
||||||
|
{
|
||||||
|
char const* name;
|
||||||
|
clock_type::time_point start;
|
||||||
|
clock_type::duration elapsed;
|
||||||
|
std::atomic<std::size_t> failed;
|
||||||
|
std::atomic<std::size_t> total;
|
||||||
|
|
||||||
|
summary(summary const& other) noexcept
|
||||||
|
: name(other.name)
|
||||||
|
, start(other.start)
|
||||||
|
, elapsed(other.elapsed)
|
||||||
|
, failed(other.failed.load())
|
||||||
|
, total(other.total.load())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit
|
||||||
|
summary(char const* name_) noexcept
|
||||||
|
: name(name_)
|
||||||
|
, start(clock_type::now())
|
||||||
|
, failed(0)
|
||||||
|
, total(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
summary all_;
|
||||||
|
std::ostream& log_;
|
||||||
|
std::vector<summary> v_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit
|
||||||
|
simple_runner(
|
||||||
|
std::ostream& log)
|
||||||
|
: all_("(all)")
|
||||||
|
, log_(log)
|
||||||
|
{
|
||||||
|
std::unitbuf(log_);
|
||||||
|
v_.reserve(256);
|
||||||
|
}
|
||||||
|
|
||||||
|
~simple_runner()
|
||||||
|
{
|
||||||
|
log_ <<
|
||||||
|
elapsed{clock_type::now() -
|
||||||
|
all_.start } << ", " <<
|
||||||
|
v_.size() << " suites, " <<
|
||||||
|
all_.failed.load() << " failures, " <<
|
||||||
|
all_.total.load() << " total." <<
|
||||||
|
std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// true if no failures
|
||||||
|
bool
|
||||||
|
success() const noexcept
|
||||||
|
{
|
||||||
|
return all_.failed.load() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
on_begin(char const* name) override
|
||||||
|
{
|
||||||
|
v_.emplace_back(name);
|
||||||
|
log_ << name << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
on_end() override
|
||||||
|
{
|
||||||
|
v_.back().elapsed =
|
||||||
|
clock_type::now() -
|
||||||
|
v_.back().start;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
note(char const* msg) override
|
||||||
|
{
|
||||||
|
log_ << msg << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
pass(char const*, char const*, int, char const*) override
|
||||||
|
{
|
||||||
|
++all_.total;
|
||||||
|
++v_.back().total;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
fail(char const* expr, char const* file, int line, char const* func) override
|
||||||
|
{
|
||||||
|
++all_.failed;
|
||||||
|
++v_.back().total;
|
||||||
|
++v_.back().failed;
|
||||||
|
auto const id = ++all_.total;
|
||||||
|
log_ <<
|
||||||
|
"#" << id <<
|
||||||
|
" failed: " << expr <<
|
||||||
|
", file: " << file <<
|
||||||
|
"(" << line << ") " <<
|
||||||
|
func << "\n";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
|
||||||
|
template<
|
||||||
|
class CharT,
|
||||||
|
class Traits = std::char_traits<CharT>,
|
||||||
|
class Allocator = std::allocator<CharT>
|
||||||
|
>
|
||||||
|
class log_ostream
|
||||||
|
: public std::basic_ostream<CharT, Traits>
|
||||||
|
{
|
||||||
|
struct buffer_type :
|
||||||
|
std::basic_stringbuf<
|
||||||
|
CharT, Traits, Allocator>
|
||||||
|
{
|
||||||
|
~buffer_type()
|
||||||
|
{
|
||||||
|
sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sync() override
|
||||||
|
{
|
||||||
|
auto const& s = this->str();
|
||||||
|
if(s.size() > 0)
|
||||||
|
current()->note(s.c_str());
|
||||||
|
this->str("");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
buffer_type buf_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
log_ostream()
|
||||||
|
: std::basic_ostream<
|
||||||
|
CharT, Traits>(&buf_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
|
||||||
|
class suite_list
|
||||||
|
{
|
||||||
|
static std::size_t const max_size_ = 256;
|
||||||
|
std::size_t count_ = 0;
|
||||||
|
suite_info data_[max_size_];
|
||||||
|
|
||||||
|
public:
|
||||||
|
void
|
||||||
|
insert(suite_info inf)
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
if(count_ == max_size_)
|
||||||
|
throw std::length_error(
|
||||||
|
"too many test suites");
|
||||||
|
#endif
|
||||||
|
data_[count_++] = inf;
|
||||||
|
}
|
||||||
|
|
||||||
|
suite_info const*
|
||||||
|
begin() const noexcept
|
||||||
|
{
|
||||||
|
return data_;
|
||||||
|
}
|
||||||
|
|
||||||
|
suite_info const*
|
||||||
|
end() const noexcept
|
||||||
|
{
|
||||||
|
return begin() + count_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sort()
|
||||||
|
{
|
||||||
|
std::sort(
|
||||||
|
data_,
|
||||||
|
data_ + count_,
|
||||||
|
[]( detail::suite_info const& lhs,
|
||||||
|
detail::suite_info const& rhs)
|
||||||
|
{
|
||||||
|
return std::lexicographical_compare(
|
||||||
|
lhs.name, lhs.name + std::strlen(lhs.name),
|
||||||
|
rhs.name, rhs.name + std::strlen(rhs.name));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline
|
||||||
|
suite_list&
|
||||||
|
suites()
|
||||||
|
{
|
||||||
|
static suite_list list;
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct instance
|
||||||
|
{
|
||||||
|
explicit
|
||||||
|
instance(
|
||||||
|
char const* name) noexcept
|
||||||
|
{
|
||||||
|
suites().insert(suite_info{
|
||||||
|
name, &instance::run });
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
run()
|
||||||
|
{
|
||||||
|
auto const saved =
|
||||||
|
current();
|
||||||
|
//current()->os_
|
||||||
|
T().run();
|
||||||
|
current() = saved;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
current_function_helper()
|
||||||
|
{
|
||||||
|
#if defined(__GNUC__) || \
|
||||||
|
(defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || \
|
||||||
|
(defined(__ICC) && (__ICC >= 600)) || \
|
||||||
|
defined(__ghs__) || \
|
||||||
|
defined(__clang__)
|
||||||
|
# define TEST_SUITE_FUNCTION __PRETTY_FUNCTION__
|
||||||
|
|
||||||
|
#elif defined(__DMC__) && (__DMC__ >= 0x810)
|
||||||
|
# define TEST_SUITE_FUNCTION __PRETTY_FUNCTION__
|
||||||
|
|
||||||
|
#elif defined(__FUNCSIG__)
|
||||||
|
# define TEST_SUITE_FUNCTION __FUNCSIG__
|
||||||
|
|
||||||
|
#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || \
|
||||||
|
(defined(__IBMCPP__) && (__IBMCPP__ >= 500))
|
||||||
|
# define TEST_SUITE_FUNCTION __FUNCTION__
|
||||||
|
|
||||||
|
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
|
||||||
|
# define TEST_SUITE_FUNCTION __FUNC__
|
||||||
|
|
||||||
|
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
|
||||||
|
# define TEST_SUITE_FUNCTION __func__
|
||||||
|
|
||||||
|
#elif defined(__cplusplus) && (__cplusplus >= 201103)
|
||||||
|
# define TEST_SUITE_FUNCTION __func__
|
||||||
|
|
||||||
|
#else
|
||||||
|
# define TEST_SUITE_FUNCTION "(unknown)"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
|
||||||
|
/** The type of log for output to the currently running suite.
|
||||||
|
*/
|
||||||
|
using log_type = detail::log_ostream<char>;
|
||||||
|
|
||||||
|
#define BOOST_TEST(expr) \
|
||||||
|
::test_suite::detail::current()->maybe_fail( \
|
||||||
|
(expr), #expr, __FILE__, __LINE__, TEST_SUITE_FUNCTION)
|
||||||
|
|
||||||
|
#define BOOST_ERROR(msg) \
|
||||||
|
::test_suite::detail::current()->fail( \
|
||||||
|
msg, __FILE__, __LINE__, TEST_SUITE_FUNCTION)
|
||||||
|
|
||||||
|
#define BOOST_TEST_PASS() \
|
||||||
|
::test_suite::detail::current()->pass( \
|
||||||
|
"", __FILE__, __LINE__, TEST_SUITE_FUNCTION)
|
||||||
|
|
||||||
|
#define BOOST_TEST_FAIL() \
|
||||||
|
::test_suite::detail::current()->fail( \
|
||||||
|
"", __FILE__, __LINE__, TEST_SUITE_FUNCTION)
|
||||||
|
|
||||||
|
#define BOOST_TEST_NOT(expr) BOOST_TEST(!(expr))
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_EXCEPTIONS
|
||||||
|
# define BOOST_TEST_THROWS( expr, except ) \
|
||||||
|
try { \
|
||||||
|
expr; \
|
||||||
|
::test_suite::detail::current()->fail ( \
|
||||||
|
#except, __FILE__, __LINE__, \
|
||||||
|
TEST_SUITE_FUNCTION); \
|
||||||
|
} \
|
||||||
|
catch(except const&) { \
|
||||||
|
::test_suite::detail::current()->pass( \
|
||||||
|
#except, __FILE__, __LINE__, \
|
||||||
|
TEST_SUITE_FUNCTION); \
|
||||||
|
} \
|
||||||
|
catch(...) { \
|
||||||
|
::test_suite::detail::current()->fail( \
|
||||||
|
#except, __FILE__, __LINE__, \
|
||||||
|
TEST_SUITE_FUNCTION); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define BOOST_TEST_THROWS( expr, except )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TEST_SUITE(type, name) \
|
||||||
|
namespace { static ::test_suite::detail::instance<type> type##_(name); }
|
||||||
|
|
||||||
|
inline
|
||||||
|
int
|
||||||
|
run(std::ostream& log,
|
||||||
|
int argc, char const* const* argv)
|
||||||
|
{
|
||||||
|
if(argc == 2)
|
||||||
|
{
|
||||||
|
std::string arg(argv[1]);
|
||||||
|
if(arg == "-h" || arg == "--help")
|
||||||
|
{
|
||||||
|
log <<
|
||||||
|
"Usage:\n"
|
||||||
|
" " << argv[0] << ": { <suite-name>... }" <<
|
||||||
|
std::endl;
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace ::test_suite;
|
||||||
|
|
||||||
|
detail::simple_runner runner(log);
|
||||||
|
detail::suites().sort();
|
||||||
|
if(argc == 1)
|
||||||
|
{
|
||||||
|
for(auto const& e : detail::suites())
|
||||||
|
runner.run(e);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::vector<std::string> args;
|
||||||
|
args.reserve(argc - 1);
|
||||||
|
for(int i = 0; i < argc - 1; ++i)
|
||||||
|
args.push_back(argv[i + 1]);
|
||||||
|
for(auto const& e : detail::suites())
|
||||||
|
{
|
||||||
|
std::string s(e.name);
|
||||||
|
if(std::find_if(
|
||||||
|
args.begin(), args.end(),
|
||||||
|
[&](std::string const& arg)
|
||||||
|
{
|
||||||
|
if(arg.size() > s.size())
|
||||||
|
return false;
|
||||||
|
return s.compare(
|
||||||
|
s.size() - arg.size(),
|
||||||
|
arg.size(),
|
||||||
|
arg.data(),
|
||||||
|
arg.size()) == 0;
|
||||||
|
}) != args.end())
|
||||||
|
{
|
||||||
|
runner.run(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return runner.success() ?
|
||||||
|
EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // test_suite
|
||||||
|
|
||||||
|
#endif
|
1036
test/value.cpp
1036
test/value.cpp
File diff suppressed because it is too large
Load Diff
@ -13,14 +13,12 @@
|
|||||||
#include <boost/json/value.hpp>
|
#include <boost/json/value.hpp>
|
||||||
#include <boost/json/serializer.hpp>
|
#include <boost/json/serializer.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
#include "test_suite.hpp"
|
||||||
|
|
||||||
#include "test.hpp"
|
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
class value_ref_test : public beast::unit_test::suite
|
class value_ref_test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using init_list =
|
using init_list =
|
||||||
@ -177,7 +175,7 @@ public:
|
|||||||
auto const jv =
|
auto const jv =
|
||||||
value_ref(init).make_value({});
|
value_ref(init).make_value({});
|
||||||
auto const js = to_string(jv);
|
auto const js = to_string(jv);
|
||||||
BEAST_EXPECT(js == s);
|
BOOST_TEST(js == s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -276,7 +274,7 @@ public:
|
|||||||
{
|
{
|
||||||
auto const jv = value(object(init));
|
auto const jv = value(object(init));
|
||||||
auto const js = to_string(jv);
|
auto const js = to_string(jv);
|
||||||
BEAST_EXPECT(js == s);
|
BOOST_TEST(js == s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -297,7 +295,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run() override
|
run()
|
||||||
{
|
{
|
||||||
testCtors();
|
testCtors();
|
||||||
testInitList();
|
testInitList();
|
||||||
@ -306,7 +304,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(boost,json,value_ref);
|
TEST_SUITE(value_ref_test, "boost.json.value_ref");
|
||||||
|
|
||||||
} // json
|
} // json
|
||||||
} // boost
|
} // boost
|
||||||
|
Loading…
x
Reference in New Issue
Block a user