diff options
Diffstat (limited to '3rdparty/asio/src/tests/unit/read_until.cpp')
-rw-r--r-- | 3rdparty/asio/src/tests/unit/read_until.cpp | 820 |
1 files changed, 781 insertions, 39 deletions
diff --git a/3rdparty/asio/src/tests/unit/read_until.cpp b/3rdparty/asio/src/tests/unit/read_until.cpp index 782ac2f4b6b..139fcf6f0a9 100644 --- a/3rdparty/asio/src/tests/unit/read_until.cpp +++ b/3rdparty/asio/src/tests/unit/read_until.cpp @@ -2,7 +2,7 @@ // read_until.cpp // ~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2016 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) @@ -17,18 +17,13 @@ #include "asio/read_until.hpp" #include <cstring> +#include <functional> #include "archetypes/async_result.hpp" #include "asio/io_context.hpp" #include "asio/post.hpp" #include "asio/streambuf.hpp" #include "unit_test.hpp" -#if defined(ASIO_HAS_BOOST_BIND) -# include <boost/bind.hpp> -#else // defined(ASIO_HAS_BOOST_BIND) -# include <functional> -#endif // defined(ASIO_HAS_BOOST_BIND) - class test_stream { public: @@ -42,7 +37,7 @@ public: { } - executor_type get_executor() ASIO_NOEXCEPT + executor_type get_executor() noexcept { return io_context_.get_executor(); } @@ -88,7 +83,7 @@ public: size_t bytes_transferred = read_some(buffers); asio::post(get_executor(), asio::detail::bind_handler( - ASIO_MOVE_CAST(Handler)(handler), + static_cast<Handler&&>(handler), asio::error_code(), bytes_transferred)); } @@ -104,8 +99,98 @@ private: static const char read_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -void test_char_read_until() +void test_dynamic_string_read_until_char() +{ + asio::io_context ioc; + test_stream s(ioc); + std::string data1, data2; + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb1 = asio::dynamic_buffer(data1); + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb2 = asio::dynamic_buffer(data2, 25); + asio::error_code ec; + + s.reset(read_data, sizeof(read_data)); + sb1.consume(sb1.size()); + std::size_t length = asio::read_until(s, sb1, 'Z'); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, 'Z'); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, 'Z'); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, 'Z', ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, 'Z', ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, 'Z', ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, 'Z', ec); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, 'Z', ec); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, 'Z', ec); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, 'Y', ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, 'Y', ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, 'Y', ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); +} + +void test_streambuf_read_until_char() { +#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1) asio::io_context ioc; test_stream s(ioc); asio::streambuf sb1; @@ -188,12 +273,103 @@ void test_char_read_until() length = asio::read_until(s, sb2, 'Y', ec); ASIO_CHECK(!ec); ASIO_CHECK(length == 25); +#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1) } -void test_string_read_until() +void test_dynamic_string_read_until_string() { asio::io_context ioc; test_stream s(ioc); + std::string data1, data2; + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb1 = asio::dynamic_buffer(data1); + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb2 = asio::dynamic_buffer(data2, 25); + asio::error_code ec; + + s.reset(read_data, sizeof(read_data)); + sb1.consume(sb1.size()); + std::size_t length = asio::read_until(s, sb1, "XYZ"); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, "XYZ"); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, "XYZ"); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, "XYZ", ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, "XYZ", ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, "XYZ", ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, "XYZ", ec); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, "XYZ", ec); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, "XYZ", ec); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, "WXY", ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, "WXY", ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, "WXY", ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); +} + +void test_streambuf_read_until_string() +{ +#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1) + asio::io_context ioc; + test_stream s(ioc); asio::streambuf sb1; asio::streambuf sb2(25); asio::error_code ec; @@ -274,6 +450,7 @@ void test_string_read_until() length = asio::read_until(s, sb2, "WXY", ec); ASIO_CHECK(!ec); ASIO_CHECK(length == 25); +#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1) } class match_char @@ -303,8 +480,98 @@ namespace asio { }; } // namespace asio -void test_match_condition_read_until() +void test_dynamic_string_read_until_match_condition() +{ + asio::io_context ioc; + test_stream s(ioc); + std::string data1, data2; + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb1 = asio::dynamic_buffer(data1); + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb2 = asio::dynamic_buffer(data2, 25); + asio::error_code ec; + + s.reset(read_data, sizeof(read_data)); + sb1.consume(sb1.size()); + std::size_t length = asio::read_until(s, sb1, match_char('Z')); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, match_char('Z')); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, match_char('Z')); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, match_char('Z'), ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, match_char('Z'), ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb1.consume(sb1.size()); + length = asio::read_until(s, sb1, match_char('Z'), ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, match_char('Z'), ec); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, match_char('Z'), ec); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, match_char('Z'), ec); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, match_char('Y'), ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, match_char('Y'), ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + sb2.consume(sb2.size()); + length = asio::read_until(s, sb2, match_char('Y'), ec); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); +} + +void test_streambuf_read_until_match_condition() { +#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1) asio::io_context ioc; test_stream s(ioc); asio::streambuf sb1; @@ -387,6 +654,7 @@ void test_match_condition_read_until() length = asio::read_until(s, sb2, match_char('Y'), ec); ASIO_CHECK(!ec); ASIO_CHECK(length == 25); +#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1) } void async_read_handler( @@ -398,15 +666,170 @@ void async_read_handler( *called = true; } -void test_char_async_read_until() +void test_dynamic_string_async_read_until_char() +{ + namespace bindns = std; + using bindns::placeholders::_1; + using bindns::placeholders::_2; + + asio::io_context ioc; + test_stream s(ioc); + std::string data1, data2; + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb1 = asio::dynamic_buffer(data1); + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb2 = asio::dynamic_buffer(data2, 25); + asio::error_code ec; + std::size_t length; + bool called; + + s.reset(read_data, sizeof(read_data)); + ec = asio::error_code(); + length = 0; + called = false; + sb1.consume(sb1.size()); + asio::async_read_until(s, sb1, 'Z', + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + ec = asio::error_code(); + length = 0; + called = false; + sb1.consume(sb1.size()); + asio::async_read_until(s, sb1, 'Z', + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + ec = asio::error_code(); + length = 0; + called = false; + sb1.consume(sb1.size()); + asio::async_read_until(s, sb1, 'Z', + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, 'Z', + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, 'Z', + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, 'Z', + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, 'Y', + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, 'Y', + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, 'Y', + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + sb2.consume(sb2.size()); + int i = asio::async_read_until(s, sb2, 'Y', + archetypes::lazy_handler()); + ASIO_CHECK(i == 42); + ioc.restart(); + ioc.run(); +} + +void test_streambuf_async_read_until_char() { -#if defined(ASIO_HAS_BOOST_BIND) - namespace bindns = boost; -#else // defined(ASIO_HAS_BOOST_BIND) +#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1) namespace bindns = std; - using std::placeholders::_1; - using std::placeholders::_2; -#endif // defined(ASIO_HAS_BOOST_BIND) + using bindns::placeholders::_1; + using bindns::placeholders::_2; asio::io_context ioc; test_stream s(ioc); @@ -555,17 +978,173 @@ void test_char_async_read_until() ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); +#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1) +} + +void test_dynamic_string_async_read_until_string() +{ + namespace bindns = std; + using bindns::placeholders::_1; + using bindns::placeholders::_2; + + asio::io_context ioc; + test_stream s(ioc); + std::string data1, data2; + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb1 = asio::dynamic_buffer(data1); + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb2 = asio::dynamic_buffer(data2, 25); + asio::error_code ec; + std::size_t length; + bool called; + + s.reset(read_data, sizeof(read_data)); + ec = asio::error_code(); + length = 0; + called = false; + sb1.consume(sb1.size()); + asio::async_read_until(s, sb1, "XYZ", + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + ec = asio::error_code(); + length = 0; + called = false; + sb1.consume(sb1.size()); + asio::async_read_until(s, sb1, "XYZ", + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + ec = asio::error_code(); + length = 0; + called = false; + sb1.consume(sb1.size()); + asio::async_read_until(s, sb1, "XYZ", + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, "XYZ", + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, "XYZ", + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, "XYZ", + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, "WXY", + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, "WXY", + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, "WXY", + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + sb2.consume(sb2.size()); + int i = asio::async_read_until(s, sb2, "WXY", + archetypes::lazy_handler()); + ASIO_CHECK(i == 42); + ioc.restart(); + ioc.run(); } -void test_string_async_read_until() +void test_streambuf_async_read_until_string() { -#if defined(ASIO_HAS_BOOST_BIND) - namespace bindns = boost; -#else // defined(ASIO_HAS_BOOST_BIND) +#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1) namespace bindns = std; - using std::placeholders::_1; - using std::placeholders::_2; -#endif // defined(ASIO_HAS_BOOST_BIND) + using bindns::placeholders::_1; + using bindns::placeholders::_2; asio::io_context ioc; test_stream s(ioc); @@ -714,17 +1293,173 @@ void test_string_async_read_until() ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); +#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1) +} + +void test_dynamic_string_async_read_until_match_condition() +{ + namespace bindns = std; + using bindns::placeholders::_1; + using bindns::placeholders::_2; + + asio::io_context ioc; + test_stream s(ioc); + std::string data1, data2; + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb1 = asio::dynamic_buffer(data1); + asio::dynamic_string_buffer<char, std::string::traits_type, + std::string::allocator_type> sb2 = asio::dynamic_buffer(data2, 25); + asio::error_code ec; + std::size_t length; + bool called; + + s.reset(read_data, sizeof(read_data)); + ec = asio::error_code(); + length = 0; + called = false; + sb1.consume(sb1.size()); + asio::async_read_until(s, sb1, match_char('Z'), + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + ec = asio::error_code(); + length = 0; + called = false; + sb1.consume(sb1.size()); + asio::async_read_until(s, sb1, match_char('Z'), + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + ec = asio::error_code(); + length = 0; + called = false; + sb1.consume(sb1.size()); + asio::async_read_until(s, sb1, match_char('Z'), + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 26); + + s.reset(read_data, sizeof(read_data)); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, match_char('Z'), + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, match_char('Z'), + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, match_char('Z'), + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(ec == asio::error::not_found); + ASIO_CHECK(length == 0); + + s.reset(read_data, sizeof(read_data)); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, match_char('Y'), + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(1); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, match_char('Y'), + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + s.next_read_length(10); + ec = asio::error_code(); + length = 0; + called = false; + sb2.consume(sb2.size()); + asio::async_read_until(s, sb2, match_char('Y'), + bindns::bind(async_read_handler, _1, &ec, + _2, &length, &called)); + ioc.restart(); + ioc.run(); + ASIO_CHECK(called); + ASIO_CHECK(!ec); + ASIO_CHECK(length == 25); + + s.reset(read_data, sizeof(read_data)); + sb2.consume(sb2.size()); + int i = asio::async_read_until(s, sb2, match_char('Y'), + archetypes::lazy_handler()); + ASIO_CHECK(i == 42); + ioc.restart(); + ioc.run(); } -void test_match_condition_async_read_until() +void test_streambuf_async_read_until_match_condition() { -#if defined(ASIO_HAS_BOOST_BIND) - namespace bindns = boost; -#else // defined(ASIO_HAS_BOOST_BIND) +#if !defined(ASIO_NO_DYNAMIC_BUFFER_V1) namespace bindns = std; - using std::placeholders::_1; - using std::placeholders::_2; -#endif // defined(ASIO_HAS_BOOST_BIND) + using bindns::placeholders::_1; + using bindns::placeholders::_2; asio::io_context ioc; test_stream s(ioc); @@ -873,15 +1608,22 @@ void test_match_condition_async_read_until() ASIO_CHECK(i == 42); ioc.restart(); ioc.run(); +#endif // !defined(ASIO_NO_DYNAMIC_BUFFER_V1) } ASIO_TEST_SUITE ( "read_until", - ASIO_TEST_CASE(test_char_read_until) - ASIO_TEST_CASE(test_string_read_until) - ASIO_TEST_CASE(test_match_condition_read_until) - ASIO_TEST_CASE(test_char_async_read_until) - ASIO_TEST_CASE(test_string_async_read_until) - ASIO_TEST_CASE(test_match_condition_async_read_until) + ASIO_TEST_CASE(test_dynamic_string_read_until_char) + ASIO_TEST_CASE(test_streambuf_read_until_char) + ASIO_TEST_CASE(test_dynamic_string_read_until_string) + ASIO_TEST_CASE(test_streambuf_read_until_string) + ASIO_TEST_CASE(test_dynamic_string_read_until_match_condition) + ASIO_TEST_CASE(test_streambuf_read_until_match_condition) + ASIO_TEST_CASE(test_dynamic_string_async_read_until_char) + ASIO_TEST_CASE(test_streambuf_async_read_until_char) + ASIO_TEST_CASE(test_dynamic_string_async_read_until_string) + ASIO_TEST_CASE(test_streambuf_async_read_until_string) + ASIO_TEST_CASE(test_dynamic_string_async_read_until_match_condition) + ASIO_TEST_CASE(test_streambuf_async_read_until_match_condition) ) |