diff options
Diffstat (limited to '3rdparty/asio/src/tests/unit/buffer.cpp')
-rw-r--r-- | 3rdparty/asio/src/tests/unit/buffer.cpp | 133 |
1 files changed, 108 insertions, 25 deletions
diff --git a/3rdparty/asio/src/tests/unit/buffer.cpp b/3rdparty/asio/src/tests/unit/buffer.cpp index f66a8f0122e..9fa1db6e67f 100644 --- a/3rdparty/asio/src/tests/unit/buffer.cpp +++ b/3rdparty/asio/src/tests/unit/buffer.cpp @@ -2,7 +2,7 @@ // buffer.cpp // ~~~~~~~~~~ // -// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot 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) @@ -16,16 +16,14 @@ // Test that header file is self-contained. #include "asio/buffer.hpp" +#include <array> +#include <cstring> #include "unit_test.hpp" #if defined(ASIO_HAS_BOOST_ARRAY) # include <boost/array.hpp> #endif // defined(ASIO_HAS_BOOST_ARRAY) -#if defined(ASIO_HAS_STD_ARRAY) -# include <array> -#endif // defined(ASIO_HAS_STD_ARRAY) - //------------------------------------------------------------------------------ // buffer_compile test @@ -37,6 +35,42 @@ namespace buffer_compile { using namespace asio; +template <typename T> +class mutable_contiguous_container +{ +public: + typedef T value_type; + typedef T* iterator; + typedef const T* const_iterator; + typedef T& reference; + typedef const T& const_reference; + + mutable_contiguous_container() {} + std::size_t size() const { return 0; } + iterator begin() { return 0; } + const_iterator begin() const { return 0; } + iterator end() { return 0; } + const_iterator end() const { return 0; } +}; + +template <typename T> +class const_contiguous_container +{ +public: + typedef const T value_type; + typedef const T* iterator; + typedef const T* const_iterator; + typedef const T& reference; + typedef const T& const_reference; + + const_contiguous_container() {} + std::size_t size() const { return 0; } + iterator begin() { return 0; } + const_iterator begin() const { return 0; } + iterator end() { return 0; } + const_iterator end() const { return 0; } +}; + void test() { try @@ -50,11 +84,9 @@ void test() const boost::array<char, 1024>& const_array_data_1 = array_data; boost::array<const char, 1024> const_array_data_2 = { { 0 } }; #endif // defined(ASIO_HAS_BOOST_ARRAY) -#if defined(ASIO_HAS_STD_ARRAY) std::array<char, 1024> std_array_data; const std::array<char, 1024>& const_std_array_data_1 = std_array_data; std::array<const char, 1024> const_std_array_data_2 = { { 0 } }; -#endif // defined(ASIO_HAS_STD_ARRAY) std::vector<char> vector_data(1024); const std::vector<char>& const_vector_data = vector_data; std::string string_data(1024, ' '); @@ -66,6 +98,10 @@ void test() #elif defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) std::experimental::string_view string_view_data(string_data); #endif // defined(ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) + mutable_contiguous_container<char> mutable_contiguous_data; + const mutable_contiguous_container<char> const_mutable_contiguous_data; + const_contiguous_container<char> const_contiguous_data; + const const_contiguous_container<char> const_const_contiguous_data; // mutable_buffer constructors. @@ -189,14 +225,12 @@ void test() cb1 = buffer(const_array_data_2); cb1 = buffer(const_array_data_2, 1024); #endif // defined(ASIO_HAS_BOOST_ARRAY) -#if defined(ASIO_HAS_STD_ARRAY) mb1 = buffer(std_array_data); mb1 = buffer(std_array_data, 1024); cb1 = buffer(const_std_array_data_1); cb1 = buffer(const_std_array_data_1, 1024); cb1 = buffer(const_std_array_data_2); cb1 = buffer(const_std_array_data_2, 1024); -#endif // defined(ASIO_HAS_STD_ARRAY) mb1 = buffer(vector_data); mb1 = buffer(vector_data, 1024); cb1 = buffer(const_vector_data); @@ -209,6 +243,14 @@ void test() cb1 = buffer(string_view_data); cb1 = buffer(string_view_data, 1024); #endif // defined(ASIO_HAS_STRING_VIEW) + mb1 = buffer(mutable_contiguous_data); + mb1 = buffer(mutable_contiguous_data, 1024); + cb1 = buffer(const_mutable_contiguous_data); + cb1 = buffer(const_mutable_contiguous_data, 1024); + cb1 = buffer(const_contiguous_data); + cb1 = buffer(const_contiguous_data, 1024); + cb1 = buffer(const_const_contiguous_data); + cb1 = buffer(const_const_contiguous_data, 1024); // buffer_copy function overloads. @@ -600,13 +642,11 @@ struct valid_const_a const_buffer* end() const { return 0; } }; -#if defined(ASIO_HAS_DECLTYPE) struct valid_const_b { const_buffer* begin() const { return 0; } const_buffer* end() const { return 0; } }; -#endif // defined(ASIO_HAS_DECLTYPE) struct valid_mutable_a { @@ -616,13 +656,11 @@ struct valid_mutable_a mutable_buffer* end() const { return 0; } }; -#if defined(ASIO_HAS_DECLTYPE) struct valid_mutable_b { mutable_buffer* begin() const { return 0; } mutable_buffer* end() const { return 0; } }; -#endif // defined(ASIO_HAS_DECLTYPE) struct invalid_const_a { @@ -643,7 +681,6 @@ struct invalid_const_c const_buffer* end() const { return 0; } }; -#if defined(ASIO_HAS_DECLTYPE) struct invalid_const_d { int* begin() const { return 0; } @@ -659,7 +696,6 @@ struct invalid_const_f { const_buffer* end() const { return 0; } }; -#endif // defined(ASIO_HAS_DECLTYPE) struct invalid_mutable_a { @@ -680,7 +716,6 @@ struct invalid_mutable_c mutable_buffer* end() const { return 0; } }; -#if defined(ASIO_HAS_DECLTYPE) struct invalid_mutable_d { int* begin() const { return 0; } @@ -696,7 +731,6 @@ struct invalid_mutable_f { mutable_buffer* end() const { return 0; } }; -#endif // defined(ASIO_HAS_DECLTYPE) void test() { @@ -751,14 +785,12 @@ void test() ASIO_CHECK(buffer_sequence_begin(b7) == b7.begin()); ASIO_CHECK(buffer_sequence_end(b7) == b7.end()); -#if defined(ASIO_HAS_DECLTYPE) ASIO_CHECK(is_const_buffer_sequence<valid_const_b>::value); ASIO_CHECK(!is_mutable_buffer_sequence<valid_const_b>::value); valid_const_b b8; ASIO_CHECK(buffer_sequence_begin(b8) == b8.begin()); ASIO_CHECK(buffer_sequence_end(b8) == b8.end()); -#endif // defined(ASIO_HAS_DECLTYPE) ASIO_CHECK(is_const_buffer_sequence<valid_mutable_a>::value); ASIO_CHECK(is_mutable_buffer_sequence<valid_mutable_a>::value); @@ -767,14 +799,12 @@ void test() ASIO_CHECK(buffer_sequence_begin(b9) == b9.begin()); ASIO_CHECK(buffer_sequence_end(b9) == b9.end()); -#if defined(ASIO_HAS_DECLTYPE) ASIO_CHECK(is_const_buffer_sequence<valid_mutable_b>::value); ASIO_CHECK(is_mutable_buffer_sequence<valid_mutable_b>::value); valid_mutable_b b10; ASIO_CHECK(buffer_sequence_begin(b10) == b10.begin()); ASIO_CHECK(buffer_sequence_end(b10) == b10.end()); -#endif // defined(ASIO_HAS_DECLTYPE) ASIO_CHECK(!is_const_buffer_sequence<invalid_const_a>::value); ASIO_CHECK(!is_mutable_buffer_sequence<invalid_const_a>::value); @@ -785,7 +815,6 @@ void test() ASIO_CHECK(!is_const_buffer_sequence<invalid_const_c>::value); ASIO_CHECK(!is_mutable_buffer_sequence<invalid_const_c>::value); -#if defined(ASIO_HAS_DECLTYPE) ASIO_CHECK(!is_const_buffer_sequence<invalid_const_d>::value); ASIO_CHECK(!is_mutable_buffer_sequence<invalid_const_d>::value); @@ -794,7 +823,6 @@ void test() ASIO_CHECK(!is_const_buffer_sequence<invalid_const_f>::value); ASIO_CHECK(!is_mutable_buffer_sequence<invalid_const_f>::value); -#endif // defined(ASIO_HAS_DECLTYPE) ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_a>::value); ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_a>::value); @@ -805,7 +833,6 @@ void test() ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_c>::value); ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_c>::value); -#if defined(ASIO_HAS_DECLTYPE) ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_d>::value); ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_d>::value); @@ -814,11 +841,66 @@ void test() ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_f>::value); ASIO_CHECK(!is_mutable_buffer_sequence<invalid_mutable_f>::value); -#endif // defined(ASIO_HAS_DECLTYPE) } } // namespace buffer_sequence +namespace buffer_literals { + +void test() +{ +#if defined(ASIO_HAS_USER_DEFINED_LITERALS) + using namespace asio::buffer_literals; + using namespace std; // For memcmp. + + asio::const_buffer b1 = ""_buf; + ASIO_CHECK(b1.size() == 0); + + asio::const_buffer b2 = "hello"_buf; + ASIO_CHECK(b2.size() == 5); + ASIO_CHECK(memcmp(b2.data(), "hello", 5) == 0); + + asio::const_buffer b3 = 0x00_buf; + ASIO_CHECK(b3.size() == 1); + ASIO_CHECK(memcmp(b3.data(), "\x00", 1) == 0); + + asio::const_buffer b4 = 0X01_buf; + ASIO_CHECK(b4.size() == 1); + ASIO_CHECK(memcmp(b4.data(), "\x01", 1) == 0); + + asio::const_buffer b5 = 0xaB_buf; + ASIO_CHECK(b5.size() == 1); + ASIO_CHECK(memcmp(b5.data(), "\xab", 1) == 0); + + asio::const_buffer b6 = 0xABcd_buf; + ASIO_CHECK(b6.size() == 2); + ASIO_CHECK(memcmp(b6.data(), "\xab\xcd", 2) == 0); + + asio::const_buffer b7 = 0x01ab01cd01ef01ba01dc01fe_buf; + ASIO_CHECK(b7.size() == 12); + ASIO_CHECK(memcmp(b7.data(), + "\x01\xab\x01\xcd\x01\xef\x01\xba\x01\xdc\x01\xfe", 12) == 0); + + asio::const_buffer b8 = 0b00000000_buf; + ASIO_CHECK(b8.size() == 1); + ASIO_CHECK(memcmp(b8.data(), "\x00", 1) == 0); + + asio::const_buffer b9 = 0B00000001_buf; + ASIO_CHECK(b9.size() == 1); + ASIO_CHECK(memcmp(b9.data(), "\x01", 1) == 0); + + asio::const_buffer b10 = 0B11111111_buf; + ASIO_CHECK(b10.size() == 1); + ASIO_CHECK(memcmp(b10.data(), "\xFF", 1) == 0); + + asio::const_buffer b11 = 0b1111000000001111_buf; + ASIO_CHECK(b11.size() == 2); + ASIO_CHECK(memcmp(b11.data(), "\xF0\x0F", 2) == 0); +#endif // (defined(ASIO_HAS_USER_DEFINED_LITERALS) +} + +} // namespace buffer_literals + //------------------------------------------------------------------------------ ASIO_TEST_SUITE @@ -827,4 +909,5 @@ ASIO_TEST_SUITE ASIO_COMPILE_TEST_CASE(buffer_compile::test) ASIO_TEST_CASE(buffer_copy_runtime::test) ASIO_TEST_CASE(buffer_sequence::test) + ASIO_TEST_CASE(buffer_literals::test) ) |