repo_name
stringclasses
10 values
file_path
stringlengths
29
222
content
stringlengths
24
926k
extention
stringclasses
5 values
asio
data/projects/asio/test/ts/net.cpp
// // net.cpp // ~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Prevent link dependency on the Boost.System library. #if !defined(BOOST_SYSTEM_NO_DEPRECATED) #define BOOST_SYSTEM_NO_DEPRECATED #endif // !defined(BOOST_SYSTEM_NO_DEPRECATED) // Test that header file is self-contained. #include <boost/asio/ts/net.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "ts/net", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/ts/io_context.cpp
// // io_context.cpp // ~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Prevent link dependency on the Boost.System library. #if !defined(BOOST_SYSTEM_NO_DEPRECATED) #define BOOST_SYSTEM_NO_DEPRECATED #endif // !defined(BOOST_SYSTEM_NO_DEPRECATED) // Test that header file is self-contained. #include <boost/asio/ts/io_context.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "ts/io_context", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/ip/udp.cpp
// // udp.cpp // ~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/udp.hpp> #include <cstring> #include <functional> #include <boost/asio/io_context.hpp> #include "../unit_test.hpp" #include "../archetypes/async_result.hpp" #include "../archetypes/gettable_socket_option.hpp" #include "../archetypes/io_control_command.hpp" #include "../archetypes/settable_socket_option.hpp" //------------------------------------------------------------------------------ // ip_udp_socket_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::udp::socket compile and link correctly. Runtime failures are ignored. namespace ip_udp_socket_compile { struct connect_handler { connect_handler() {} void operator()(const boost::system::error_code&) {} connect_handler(connect_handler&&) {} private: connect_handler(const connect_handler&); }; struct wait_handler { wait_handler() {} void operator()(const boost::system::error_code&) {} wait_handler(wait_handler&&) {} private: wait_handler(const wait_handler&); }; struct send_handler { send_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} send_handler(send_handler&&) {} private: send_handler(const send_handler&); }; struct receive_handler { receive_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} receive_handler(receive_handler&&) {} private: receive_handler(const receive_handler&); }; void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); char mutable_char_buffer[128] = ""; const char const_char_buffer[128] = ""; socket_base::message_flags in_flags = 0; archetypes::settable_socket_option<void> settable_socket_option1; archetypes::settable_socket_option<int> settable_socket_option2; archetypes::settable_socket_option<double> settable_socket_option3; archetypes::gettable_socket_option<void> gettable_socket_option1; archetypes::gettable_socket_option<int> gettable_socket_option2; archetypes::gettable_socket_option<double> gettable_socket_option3; archetypes::io_control_command io_control_command; archetypes::immediate_handler immediate; archetypes::lazy_handler lazy; boost::system::error_code ec; // basic_datagram_socket constructors. ip::udp::socket socket1(ioc); ip::udp::socket socket2(ioc, ip::udp::v4()); ip::udp::socket socket3(ioc, ip::udp::v6()); ip::udp::socket socket4(ioc, ip::udp::endpoint(ip::udp::v4(), 0)); ip::udp::socket socket5(ioc, ip::udp::endpoint(ip::udp::v6(), 0)); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::udp::socket::native_handle_type native_socket1 = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); ip::udp::socket socket6(ioc, ip::udp::v4(), native_socket1); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::udp::socket socket7(ioc_ex); ip::udp::socket socket8(ioc_ex, ip::udp::v4()); ip::udp::socket socket9(ioc_ex, ip::udp::v6()); ip::udp::socket socket10(ioc_ex, ip::udp::endpoint(ip::udp::v4(), 0)); ip::udp::socket socket11(ioc_ex, ip::udp::endpoint(ip::udp::v6(), 0)); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::udp::socket::native_handle_type native_socket2 = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); ip::udp::socket socket12(ioc_ex, ip::udp::v4(), native_socket2); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::udp::socket socket13(std::move(socket6)); // basic_datagram_socket operators. socket1 = ip::udp::socket(ioc); socket1 = std::move(socket2); // basic_io_object functions. ip::udp::socket::executor_type ex = socket1.get_executor(); (void)ex; // basic_socket functions. ip::udp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer(); (void)lowest_layer; const ip::udp::socket& socket14 = socket1; const ip::udp::socket::lowest_layer_type& lowest_layer2 = socket14.lowest_layer(); (void)lowest_layer2; socket1.open(ip::udp::v4()); socket1.open(ip::udp::v6()); socket1.open(ip::udp::v4(), ec); socket1.open(ip::udp::v6(), ec); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::udp::socket::native_handle_type native_socket3 = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); socket1.assign(ip::udp::v4(), native_socket3); ip::udp::socket::native_handle_type native_socket4 = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); socket1.assign(ip::udp::v4(), native_socket4, ec); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) bool is_open = socket1.is_open(); (void)is_open; socket1.close(); socket1.close(ec); socket1.release(); socket1.release(ec); ip::udp::socket::native_handle_type native_socket5 = socket1.native_handle(); (void)native_socket5; socket1.cancel(); socket1.cancel(ec); bool at_mark1 = socket1.at_mark(); (void)at_mark1; bool at_mark2 = socket1.at_mark(ec); (void)at_mark2; std::size_t available1 = socket1.available(); (void)available1; std::size_t available2 = socket1.available(ec); (void)available2; socket1.bind(ip::udp::endpoint(ip::udp::v4(), 0)); socket1.bind(ip::udp::endpoint(ip::udp::v6(), 0)); socket1.bind(ip::udp::endpoint(ip::udp::v4(), 0), ec); socket1.bind(ip::udp::endpoint(ip::udp::v6(), 0), ec); socket1.connect(ip::udp::endpoint(ip::udp::v4(), 0)); socket1.connect(ip::udp::endpoint(ip::udp::v6(), 0)); socket1.connect(ip::udp::endpoint(ip::udp::v4(), 0), ec); socket1.connect(ip::udp::endpoint(ip::udp::v6(), 0), ec); socket1.async_connect(ip::udp::endpoint(ip::udp::v4(), 0), connect_handler()); socket1.async_connect(ip::udp::endpoint(ip::udp::v6(), 0), connect_handler()); socket1.async_connect(ip::udp::endpoint(ip::udp::v4(), 0), immediate); socket1.async_connect(ip::udp::endpoint(ip::udp::v6(), 0), immediate); int i1 = socket1.async_connect(ip::udp::endpoint(ip::udp::v4(), 0), lazy); (void)i1; int i2 = socket1.async_connect(ip::udp::endpoint(ip::udp::v6(), 0), lazy); (void)i2; socket1.set_option(settable_socket_option1); socket1.set_option(settable_socket_option1, ec); socket1.set_option(settable_socket_option2); socket1.set_option(settable_socket_option2, ec); socket1.set_option(settable_socket_option3); socket1.set_option(settable_socket_option3, ec); socket1.get_option(gettable_socket_option1); socket1.get_option(gettable_socket_option1, ec); socket1.get_option(gettable_socket_option2); socket1.get_option(gettable_socket_option2, ec); socket1.get_option(gettable_socket_option3); socket1.get_option(gettable_socket_option3, ec); socket1.io_control(io_control_command); socket1.io_control(io_control_command, ec); bool non_blocking1 = socket1.non_blocking(); (void)non_blocking1; socket1.non_blocking(true); socket1.non_blocking(false, ec); bool non_blocking2 = socket1.native_non_blocking(); (void)non_blocking2; socket1.native_non_blocking(true); socket1.native_non_blocking(false, ec); ip::udp::endpoint endpoint1 = socket1.local_endpoint(); (void)endpoint1; ip::udp::endpoint endpoint2 = socket1.local_endpoint(ec); (void)endpoint2; ip::udp::endpoint endpoint3 = socket1.remote_endpoint(); (void)endpoint3; ip::udp::endpoint endpoint4 = socket1.remote_endpoint(ec); (void)endpoint4; socket1.shutdown(socket_base::shutdown_both); socket1.shutdown(socket_base::shutdown_both, ec); socket1.wait(socket_base::wait_read); socket1.wait(socket_base::wait_write, ec); socket1.async_wait(socket_base::wait_read, wait_handler()); socket1.async_wait(socket_base::wait_read, immediate); int i3 = socket1.async_wait(socket_base::wait_write, lazy); (void)i3; // basic_datagram_socket functions. socket1.send(buffer(mutable_char_buffer)); socket1.send(buffer(const_char_buffer)); socket1.send(null_buffers()); socket1.send(buffer(mutable_char_buffer), in_flags); socket1.send(buffer(const_char_buffer), in_flags); socket1.send(null_buffers(), in_flags); socket1.send(buffer(mutable_char_buffer), in_flags, ec); socket1.send(buffer(const_char_buffer), in_flags, ec); socket1.send(null_buffers(), in_flags, ec); socket1.async_send(buffer(mutable_char_buffer), send_handler()); socket1.async_send(buffer(const_char_buffer), send_handler()); socket1.async_send(null_buffers(), send_handler()); socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler()); socket1.async_send(buffer(const_char_buffer), in_flags, send_handler()); socket1.async_send(null_buffers(), in_flags, send_handler()); socket1.async_send(buffer(mutable_char_buffer), immediate); socket1.async_send(buffer(const_char_buffer), immediate); socket1.async_send(null_buffers(), immediate); socket1.async_send(buffer(mutable_char_buffer), in_flags, immediate); socket1.async_send(buffer(const_char_buffer), in_flags, immediate); socket1.async_send(null_buffers(), in_flags, immediate); int i4 = socket1.async_send(buffer(mutable_char_buffer), lazy); (void)i4; int i5 = socket1.async_send(buffer(const_char_buffer), lazy); (void)i5; int i6 = socket1.async_send(null_buffers(), lazy); (void)i6; int i7 = socket1.async_send(buffer(mutable_char_buffer), in_flags, lazy); (void)i7; int i8 = socket1.async_send(buffer(const_char_buffer), in_flags, lazy); (void)i8; int i9 = socket1.async_send(null_buffers(), in_flags, lazy); (void)i9; socket1.send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0)); socket1.send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0)); socket1.send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0)); socket1.send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0)); socket1.send_to(null_buffers(), ip::udp::endpoint(ip::udp::v4(), 0)); socket1.send_to(null_buffers(), ip::udp::endpoint(ip::udp::v6(), 0)); socket1.send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), in_flags); socket1.send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), in_flags); socket1.send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), in_flags); socket1.send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), in_flags); socket1.send_to(null_buffers(), ip::udp::endpoint(ip::udp::v4(), 0), in_flags); socket1.send_to(null_buffers(), ip::udp::endpoint(ip::udp::v6(), 0), in_flags); socket1.send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, ec); socket1.send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, ec); socket1.send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, ec); socket1.send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, ec); socket1.send_to(null_buffers(), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, ec); socket1.send_to(null_buffers(), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, ec); socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), send_handler()); socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), send_handler()); socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), send_handler()); socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v4(), 0), send_handler()); socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v6(), 0), send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, send_handler()); socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), immediate); socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), immediate); socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), immediate); socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), immediate); socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v4(), 0), immediate); socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v6(), 0), immediate); socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, immediate); socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, immediate); socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, immediate); socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, immediate); socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, immediate); socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, immediate); int i10 = socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), lazy); (void)i10; int i11 = socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), lazy); (void)i11; int i12 = socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), lazy); (void)i12; int i13 = socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), lazy); (void)i13; int i14 = socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v4(), 0), lazy); (void)i14; int i15 = socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v6(), 0), lazy); (void)i15; int i16 = socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, lazy); (void)i16; int i17 = socket1.async_send_to(buffer(mutable_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, lazy); (void)i17; int i18 = socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, lazy); (void)i18; int i19 = socket1.async_send_to(buffer(const_char_buffer), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, lazy); (void)i19; int i20 = socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v4(), 0), in_flags, lazy); (void)i20; int i21 = socket1.async_send_to(null_buffers(), ip::udp::endpoint(ip::udp::v6(), 0), in_flags, lazy); (void)i21; socket1.receive(buffer(mutable_char_buffer)); socket1.receive(null_buffers()); socket1.receive(buffer(mutable_char_buffer), in_flags); socket1.receive(null_buffers(), in_flags); socket1.receive(buffer(mutable_char_buffer), in_flags, ec); socket1.receive(null_buffers(), in_flags, ec); socket1.async_receive(buffer(mutable_char_buffer), receive_handler()); socket1.async_receive(null_buffers(), receive_handler()); socket1.async_receive(buffer(mutable_char_buffer), in_flags, receive_handler()); socket1.async_receive(null_buffers(), in_flags, receive_handler()); socket1.async_receive(buffer(mutable_char_buffer), immediate); socket1.async_receive(null_buffers(), immediate); socket1.async_receive(buffer(mutable_char_buffer), in_flags, immediate); socket1.async_receive(null_buffers(), in_flags, immediate); int i22 = socket1.async_receive(buffer(mutable_char_buffer), lazy); (void)i22; int i23 = socket1.async_receive(null_buffers(), lazy); (void)i23; int i24 = socket1.async_receive(buffer(mutable_char_buffer), in_flags, lazy); (void)i24; int i25 = socket1.async_receive(null_buffers(), in_flags, lazy); (void)i25; ip::udp::endpoint endpoint; socket1.receive_from(buffer(mutable_char_buffer), endpoint); socket1.receive_from(null_buffers(), endpoint); socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags); socket1.receive_from(null_buffers(), endpoint, in_flags); socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags, ec); socket1.receive_from(null_buffers(), endpoint, in_flags, ec); socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, receive_handler()); socket1.async_receive_from(null_buffers(), endpoint, receive_handler()); socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, in_flags, receive_handler()); socket1.async_receive_from(null_buffers(), endpoint, in_flags, receive_handler()); socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, immediate); socket1.async_receive_from(null_buffers(), endpoint, immediate); socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, in_flags, immediate); socket1.async_receive_from(null_buffers(), endpoint, in_flags, immediate); int i26 = socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, lazy); (void)i26; int i27 = socket1.async_receive_from(null_buffers(), endpoint, lazy); (void)i27; int i28 = socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, in_flags, lazy); (void)i28; int i29 = socket1.async_receive_from(null_buffers(), endpoint, in_flags, lazy); (void)i29; } catch (std::exception&) { } } } // namespace ip_udp_socket_compile //------------------------------------------------------------------------------ // ip_udp_socket_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks the runtime operation of the ip::udp::socket class. namespace ip_udp_socket_runtime { void handle_send(size_t expected_bytes_sent, const boost::system::error_code& err, size_t bytes_sent) { BOOST_ASIO_CHECK(!err); BOOST_ASIO_CHECK(expected_bytes_sent == bytes_sent); } void handle_recv(size_t expected_bytes_recvd, const boost::system::error_code& err, size_t bytes_recvd) { BOOST_ASIO_CHECK(!err); BOOST_ASIO_CHECK(expected_bytes_recvd == bytes_recvd); } void test() { using namespace std; // For memcmp and memset. using namespace boost::asio; namespace ip = boost::asio::ip; namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; io_context ioc; ip::udp::socket s1(ioc, ip::udp::endpoint(ip::udp::v4(), 0)); ip::udp::endpoint target_endpoint = s1.local_endpoint(); target_endpoint.address(ip::address_v4::loopback()); ip::udp::socket s2(ioc); s2.open(ip::udp::v4()); s2.bind(ip::udp::endpoint(ip::udp::v4(), 0)); char send_msg[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; s2.send_to(buffer(send_msg, sizeof(send_msg)), target_endpoint); char recv_msg[sizeof(send_msg)]; ip::udp::endpoint sender_endpoint; size_t bytes_recvd = s1.receive_from(buffer(recv_msg, sizeof(recv_msg)), sender_endpoint); BOOST_ASIO_CHECK(bytes_recvd == sizeof(send_msg)); BOOST_ASIO_CHECK(memcmp(send_msg, recv_msg, sizeof(send_msg)) == 0); memset(recv_msg, 0, sizeof(recv_msg)); target_endpoint = sender_endpoint; s1.async_send_to(buffer(send_msg, sizeof(send_msg)), target_endpoint, bindns::bind(handle_send, sizeof(send_msg), _1, _2)); s2.async_receive_from(buffer(recv_msg, sizeof(recv_msg)), sender_endpoint, bindns::bind(handle_recv, sizeof(recv_msg), _1, _2)); ioc.run(); BOOST_ASIO_CHECK(memcmp(send_msg, recv_msg, sizeof(send_msg)) == 0); } } // namespace ip_udp_socket_runtime //------------------------------------------------------------------------------ // ip_udp_resolver_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::udp::resolver compile and link correctly. Runtime failures are ignored. namespace ip_udp_resolver_compile { struct resolve_handler { resolve_handler() {} void operator()(const boost::system::error_code&, boost::asio::ip::udp::resolver::results_type) {} resolve_handler(resolve_handler&&) {} private: resolve_handler(const resolve_handler&); }; void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); archetypes::lazy_handler lazy; boost::system::error_code ec; #if !defined(BOOST_ASIO_NO_DEPRECATED) ip::udp::resolver::query q(ip::udp::v4(), "localhost", "0"); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) ip::udp::endpoint e(ip::address_v4::loopback(), 0); // basic_resolver constructors. ip::udp::resolver resolver(ioc); ip::udp::resolver resolver2(ioc_ex); ip::udp::resolver resolver3(std::move(resolver)); // basic_resolver operators. resolver = ip::udp::resolver(ioc); resolver = std::move(resolver3); // basic_io_object functions. ip::udp::resolver::executor_type ex = resolver.get_executor(); (void)ex; // basic_resolver functions. resolver.cancel(); #if !defined(BOOST_ASIO_NO_DEPRECATED) ip::udp::resolver::results_type results1 = resolver.resolve(q); (void)results1; ip::udp::resolver::results_type results2 = resolver.resolve(q, ec); (void)results2; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) ip::udp::resolver::results_type results3 = resolver.resolve("", ""); (void)results3; ip::udp::resolver::results_type results4 = resolver.resolve("", "", ec); (void)results4; ip::udp::resolver::results_type results5 = resolver.resolve("", "", ip::udp::resolver::flags()); (void)results5; ip::udp::resolver::results_type results6 = resolver.resolve("", "", ip::udp::resolver::flags(), ec); (void)results6; ip::udp::resolver::results_type results7 = resolver.resolve(ip::udp::v4(), "", ""); (void)results7; ip::udp::resolver::results_type results8 = resolver.resolve(ip::udp::v4(), "", "", ec); (void)results8; ip::udp::resolver::results_type results9 = resolver.resolve(ip::udp::v4(), "", "", ip::udp::resolver::flags()); (void)results9; ip::udp::resolver::results_type results10 = resolver.resolve(ip::udp::v4(), "", "", ip::udp::resolver::flags(), ec); (void)results10; ip::udp::resolver::results_type results11 = resolver.resolve(e); (void)results11; ip::udp::resolver::results_type results12 = resolver.resolve(e, ec); (void)results12; #if !defined(BOOST_ASIO_NO_DEPRECATED) resolver.async_resolve(q, resolve_handler()); int i1 = resolver.async_resolve(q, lazy); (void)i1; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) resolver.async_resolve("", "", resolve_handler()); int i2 = resolver.async_resolve("", "", lazy); (void)i2; resolver.async_resolve("", "", ip::udp::resolver::flags(), resolve_handler()); int i3 = resolver.async_resolve("", "", ip::udp::resolver::flags(), lazy); (void)i3; resolver.async_resolve(ip::udp::v4(), "", "", resolve_handler()); int i4 = resolver.async_resolve(ip::udp::v4(), "", "", lazy); (void)i4; resolver.async_resolve(ip::udp::v4(), "", "", ip::udp::resolver::flags(), resolve_handler()); int i5 = resolver.async_resolve(ip::udp::v4(), "", "", ip::udp::resolver::flags(), lazy); (void)i5; resolver.async_resolve(e, resolve_handler()); int i6 = resolver.async_resolve(e, lazy); (void)i6; } catch (std::exception&) { } } } // namespace ip_udp_resolver_compile //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/udp", BOOST_ASIO_COMPILE_TEST_CASE(ip_udp_socket_compile::test) BOOST_ASIO_TEST_CASE(ip_udp_socket_runtime::test) BOOST_ASIO_COMPILE_TEST_CASE(ip_udp_resolver_compile::test) )
cpp
asio
data/projects/asio/test/ip/address_v4.cpp
// // address_v4.cpp // ~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/address_v4.hpp> #include "../unit_test.hpp" #include <sstream> //------------------------------------------------------------------------------ // ip_address_v4_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::address_v4 compile and link correctly. Runtime failures are ignored. namespace ip_address_v4_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { boost::system::error_code ec; // address_v4 constructors. ip::address_v4 addr1; const ip::address_v4::bytes_type const_bytes_value = { { 127, 0, 0, 1 } }; ip::address_v4 addr2(const_bytes_value); const unsigned long const_ulong_value = 0x7F000001; ip::address_v4 addr3(const_ulong_value); // address_v4 functions. bool b = addr1.is_loopback(); (void)b; b = addr1.is_unspecified(); (void)b; #if !defined(BOOST_ASIO_NO_DEPRECATED) b = addr1.is_class_a(); (void)b; b = addr1.is_class_b(); (void)b; b = addr1.is_class_c(); (void)b; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) b = addr1.is_multicast(); (void)b; ip::address_v4::bytes_type bytes_value = addr1.to_bytes(); (void)bytes_value; ip::address_v4::uint_type uint_value = addr1.to_uint(); (void)uint_value; #if !defined(BOOST_ASIO_NO_DEPRECATED) unsigned long ulong_value = addr1.to_ulong(); (void)ulong_value; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) std::string string_value = addr1.to_string(); #if !defined(BOOST_ASIO_NO_DEPRECATED) string_value = addr1.to_string(ec); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) // address_v4 static functions. #if !defined(BOOST_ASIO_NO_DEPRECATED) addr1 = ip::address_v4::from_string("127.0.0.1"); addr1 = ip::address_v4::from_string("127.0.0.1", ec); addr1 = ip::address_v4::from_string(string_value); addr1 = ip::address_v4::from_string(string_value, ec); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) addr1 = ip::address_v4::any(); addr1 = ip::address_v4::loopback(); addr1 = ip::address_v4::broadcast(); #if !defined(BOOST_ASIO_NO_DEPRECATED) addr1 = ip::address_v4::broadcast(addr2, addr3); addr1 = ip::address_v4::netmask(addr2); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) // address_v4 comparisons. b = (addr1 == addr2); (void)b; b = (addr1 != addr2); (void)b; b = (addr1 < addr2); (void)b; b = (addr1 > addr2); (void)b; b = (addr1 <= addr2); (void)b; b = (addr1 >= addr2); (void)b; // address_v4 creation functions. addr1 = ip::make_address_v4(const_bytes_value); addr1 = ip::make_address_v4(const_ulong_value); addr1 = ip::make_address_v4("127.0.0.1"); addr1 = ip::make_address_v4("127.0.0.1", ec); addr1 = ip::make_address_v4(string_value); addr1 = ip::make_address_v4(string_value, ec); #if defined(BOOST_ASIO_HAS_STRING_VIEW) # if defined(BOOST_ASIO_HAS_STD_STRING_VIEW) std::string_view string_view_value("127.0.0.1"); # elif defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) std::experimental::string_view string_view_value("127.0.0.1"); # endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) addr1 = ip::make_address_v4(string_view_value); addr1 = ip::make_address_v4(string_view_value, ec); #endif // defined(BOOST_ASIO_HAS_STRING_VIEW) // address_v4 I/O. std::ostringstream os; os << addr1; #if !defined(BOOST_NO_STD_WSTREAMBUF) std::wostringstream wos; wos << addr1; #endif // !defined(BOOST_NO_STD_WSTREAMBUF) #if defined(BOOST_ASIO_HAS_STD_HASH) std::size_t hash1 = std::hash<ip::address_v4>()(addr1); (void)hash1; #endif // defined(BOOST_ASIO_HAS_STD_HASH) } catch (std::exception&) { } } } // namespace ip_address_v4_compile //------------------------------------------------------------------------------ // ip_address_v4_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that the various public member functions meet the // necessary postconditions. namespace ip_address_v4_runtime { void test() { using boost::asio::ip::address_v4; address_v4 a1; BOOST_ASIO_CHECK(a1.to_bytes()[0] == 0); BOOST_ASIO_CHECK(a1.to_bytes()[1] == 0); BOOST_ASIO_CHECK(a1.to_bytes()[2] == 0); BOOST_ASIO_CHECK(a1.to_bytes()[3] == 0); BOOST_ASIO_CHECK(a1.to_uint() == 0); #if !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(a1.to_ulong() == 0); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) address_v4::bytes_type b1 = {{ 1, 2, 3, 4 }}; address_v4 a2(b1); BOOST_ASIO_CHECK(a2.to_bytes()[0] == 1); BOOST_ASIO_CHECK(a2.to_bytes()[1] == 2); BOOST_ASIO_CHECK(a2.to_bytes()[2] == 3); BOOST_ASIO_CHECK(a2.to_bytes()[3] == 4); BOOST_ASIO_CHECK(((a2.to_uint() >> 24) & 0xFF) == b1[0]); BOOST_ASIO_CHECK(((a2.to_uint() >> 16) & 0xFF) == b1[1]); BOOST_ASIO_CHECK(((a2.to_uint() >> 8) & 0xFF) == b1[2]); BOOST_ASIO_CHECK((a2.to_uint() & 0xFF) == b1[3]); #if !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(((a2.to_ulong() >> 24) & 0xFF) == b1[0]); BOOST_ASIO_CHECK(((a2.to_ulong() >> 16) & 0xFF) == b1[1]); BOOST_ASIO_CHECK(((a2.to_ulong() >> 8) & 0xFF) == b1[2]); BOOST_ASIO_CHECK((a2.to_ulong() & 0xFF) == b1[3]); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) address_v4 a3(0x01020304); BOOST_ASIO_CHECK(a3.to_bytes()[0] == 1); BOOST_ASIO_CHECK(a3.to_bytes()[1] == 2); BOOST_ASIO_CHECK(a3.to_bytes()[2] == 3); BOOST_ASIO_CHECK(a3.to_bytes()[3] == 4); BOOST_ASIO_CHECK(a3.to_uint() == 0x01020304); #if !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(a3.to_ulong() == 0x01020304); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(address_v4(0x7F000001).is_loopback()); BOOST_ASIO_CHECK(address_v4(0x7F000002).is_loopback()); BOOST_ASIO_CHECK(!address_v4(0x00000000).is_loopback()); BOOST_ASIO_CHECK(!address_v4(0x01020304).is_loopback()); BOOST_ASIO_CHECK(address_v4(0x00000000).is_unspecified()); BOOST_ASIO_CHECK(!address_v4(0x7F000001).is_unspecified()); BOOST_ASIO_CHECK(!address_v4(0x01020304).is_unspecified()); #if !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(address_v4(0x01000000).is_class_a()); BOOST_ASIO_CHECK(address_v4(0x7F000000).is_class_a()); BOOST_ASIO_CHECK(!address_v4(0x80000000).is_class_a()); BOOST_ASIO_CHECK(!address_v4(0xBFFF0000).is_class_a()); BOOST_ASIO_CHECK(!address_v4(0xC0000000).is_class_a()); BOOST_ASIO_CHECK(!address_v4(0xDFFFFF00).is_class_a()); BOOST_ASIO_CHECK(!address_v4(0xE0000000).is_class_a()); BOOST_ASIO_CHECK(!address_v4(0xEFFFFFFF).is_class_a()); BOOST_ASIO_CHECK(!address_v4(0xF0000000).is_class_a()); BOOST_ASIO_CHECK(!address_v4(0xFFFFFFFF).is_class_a()); BOOST_ASIO_CHECK(!address_v4(0x01000000).is_class_b()); BOOST_ASIO_CHECK(!address_v4(0x7F000000).is_class_b()); BOOST_ASIO_CHECK(address_v4(0x80000000).is_class_b()); BOOST_ASIO_CHECK(address_v4(0xBFFF0000).is_class_b()); BOOST_ASIO_CHECK(!address_v4(0xC0000000).is_class_b()); BOOST_ASIO_CHECK(!address_v4(0xDFFFFF00).is_class_b()); BOOST_ASIO_CHECK(!address_v4(0xE0000000).is_class_b()); BOOST_ASIO_CHECK(!address_v4(0xEFFFFFFF).is_class_b()); BOOST_ASIO_CHECK(!address_v4(0xF0000000).is_class_b()); BOOST_ASIO_CHECK(!address_v4(0xFFFFFFFF).is_class_b()); BOOST_ASIO_CHECK(!address_v4(0x01000000).is_class_c()); BOOST_ASIO_CHECK(!address_v4(0x7F000000).is_class_c()); BOOST_ASIO_CHECK(!address_v4(0x80000000).is_class_c()); BOOST_ASIO_CHECK(!address_v4(0xBFFF0000).is_class_c()); BOOST_ASIO_CHECK(address_v4(0xC0000000).is_class_c()); BOOST_ASIO_CHECK(address_v4(0xDFFFFF00).is_class_c()); BOOST_ASIO_CHECK(!address_v4(0xE0000000).is_class_c()); BOOST_ASIO_CHECK(!address_v4(0xEFFFFFFF).is_class_c()); BOOST_ASIO_CHECK(!address_v4(0xF0000000).is_class_c()); BOOST_ASIO_CHECK(!address_v4(0xFFFFFFFF).is_class_c()); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(!address_v4(0x01000000).is_multicast()); BOOST_ASIO_CHECK(!address_v4(0x7F000000).is_multicast()); BOOST_ASIO_CHECK(!address_v4(0x80000000).is_multicast()); BOOST_ASIO_CHECK(!address_v4(0xBFFF0000).is_multicast()); BOOST_ASIO_CHECK(!address_v4(0xC0000000).is_multicast()); BOOST_ASIO_CHECK(!address_v4(0xDFFFFF00).is_multicast()); BOOST_ASIO_CHECK(address_v4(0xE0000000).is_multicast()); BOOST_ASIO_CHECK(address_v4(0xEFFFFFFF).is_multicast()); BOOST_ASIO_CHECK(!address_v4(0xF0000000).is_multicast()); BOOST_ASIO_CHECK(!address_v4(0xFFFFFFFF).is_multicast()); address_v4 a4 = address_v4::any(); BOOST_ASIO_CHECK(a4.to_bytes()[0] == 0); BOOST_ASIO_CHECK(a4.to_bytes()[1] == 0); BOOST_ASIO_CHECK(a4.to_bytes()[2] == 0); BOOST_ASIO_CHECK(a4.to_bytes()[3] == 0); BOOST_ASIO_CHECK(a4.to_uint() == 0); #if !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(a4.to_ulong() == 0); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) address_v4 a5 = address_v4::loopback(); BOOST_ASIO_CHECK(a5.to_bytes()[0] == 0x7F); BOOST_ASIO_CHECK(a5.to_bytes()[1] == 0); BOOST_ASIO_CHECK(a5.to_bytes()[2] == 0); BOOST_ASIO_CHECK(a5.to_bytes()[3] == 0x01); BOOST_ASIO_CHECK(a5.to_uint() == 0x7F000001); #if !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(a5.to_ulong() == 0x7F000001); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) address_v4 a6 = address_v4::broadcast(); BOOST_ASIO_CHECK(a6.to_bytes()[0] == 0xFF); BOOST_ASIO_CHECK(a6.to_bytes()[1] == 0xFF); BOOST_ASIO_CHECK(a6.to_bytes()[2] == 0xFF); BOOST_ASIO_CHECK(a6.to_bytes()[3] == 0xFF); BOOST_ASIO_CHECK(a6.to_uint() == 0xFFFFFFFF); #if !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(a6.to_ulong() == 0xFFFFFFFF); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) #if !defined(BOOST_ASIO_NO_DEPRECATED) address_v4 class_a_net(0xFF000000); address_v4 class_b_net(0xFFFF0000); address_v4 class_c_net(0xFFFFFF00); address_v4 other_net(0xFFFFFFFF); BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0x01000000)) == class_a_net); BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0x7F000000)) == class_a_net); BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0x80000000)) == class_b_net); BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0xBFFF0000)) == class_b_net); BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0xC0000000)) == class_c_net); BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0xDFFFFF00)) == class_c_net); BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0xE0000000)) == other_net); BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0xEFFFFFFF)) == other_net); BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0xF0000000)) == other_net); BOOST_ASIO_CHECK(address_v4::netmask(address_v4(0xFFFFFFFF)) == other_net); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) } } // namespace ip_address_v4_runtime //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/address_v4", BOOST_ASIO_COMPILE_TEST_CASE(ip_address_v4_compile::test) BOOST_ASIO_TEST_CASE(ip_address_v4_runtime::test) )
cpp
asio
data/projects/asio/test/ip/basic_resolver_iterator.cpp
// // basic_resolver_iterator.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/basic_resolver_iterator.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "ip/basic_resolver_iterator", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/ip/basic_resolver_query.cpp
// // basic_resolver_query.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/basic_resolver_query.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "ip/basic_resolver_query", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/ip/host_name.cpp
// // host_name.cpp // ~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/host_name.hpp> #include "../unit_test.hpp" //------------------------------------------------------------------------------ // ip_host_name_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all host_name functions compile and link // correctly. Runtime failures are ignored. namespace ip_host_name_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { boost::system::error_code ec; std::string host_name = ip::host_name(); std::string host_name2 = ip::host_name(ec); } catch (std::exception&) { } } } // namespace ip_host_name_compile //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/host_name", BOOST_ASIO_COMPILE_TEST_CASE(ip_host_name_compile::test) )
cpp
asio
data/projects/asio/test/ip/unicast.cpp
// // unicast.cpp // ~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/unicast.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/udp.hpp> #include "../unit_test.hpp" //------------------------------------------------------------------------------ // ip_unicast_compile test // ~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all nested classes, enums and constants in // ip::unicast compile and link correctly. Runtime failures are ignored. namespace ip_unicast_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; ip::udp::socket sock(ioc); // hops class. ip::unicast::hops hops1(1024); sock.set_option(hops1); ip::unicast::hops hops2; sock.get_option(hops2); hops1 = 1; (void)static_cast<int>(hops1.value()); } catch (std::exception&) { } } } // namespace ip_unicast_compile //------------------------------------------------------------------------------ // ip_unicast_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks the runtime operation of the socket options defined // in the ip::unicast namespace. namespace ip_unicast_runtime { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; io_context ioc; boost::system::error_code ec; ip::udp::endpoint ep_v4(ip::address_v4::loopback(), 0); ip::udp::socket sock_v4(ioc); sock_v4.open(ep_v4.protocol(), ec); sock_v4.bind(ep_v4, ec); bool have_v4 = !ec; ip::udp::endpoint ep_v6(ip::address_v6::loopback(), 0); ip::udp::socket sock_v6(ioc); sock_v6.open(ep_v6.protocol(), ec); sock_v6.bind(ep_v6, ec); bool have_v6 = !ec; BOOST_ASIO_CHECK(have_v4 || have_v6); // hops class. if (have_v4) { ip::unicast::hops hops1(1); BOOST_ASIO_CHECK(hops1.value() == 1); sock_v4.set_option(hops1, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK(!ec); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) ip::unicast::hops hops2; sock_v4.get_option(hops2, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK(!ec); BOOST_ASIO_CHECK(hops2.value() == 1); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) ip::unicast::hops hops3(255); BOOST_ASIO_CHECK(hops3.value() == 255); sock_v4.set_option(hops3, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK(!ec); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) ip::unicast::hops hops4; sock_v4.get_option(hops4, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK(!ec); BOOST_ASIO_CHECK(hops4.value() == 255); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) } if (have_v6) { ip::unicast::hops hops1(1); BOOST_ASIO_CHECK(hops1.value() == 1); sock_v6.set_option(hops1, ec); BOOST_ASIO_CHECK(!ec); ip::unicast::hops hops2; sock_v6.get_option(hops2, ec); BOOST_ASIO_CHECK(!ec); BOOST_ASIO_CHECK(hops2.value() == 1); ip::unicast::hops hops3(255); BOOST_ASIO_CHECK(hops3.value() == 255); sock_v6.set_option(hops3, ec); BOOST_ASIO_CHECK(!ec); ip::unicast::hops hops4; sock_v6.get_option(hops4, ec); BOOST_ASIO_CHECK(!ec); BOOST_ASIO_CHECK(hops4.value() == 255); } } } // namespace ip_unicast_runtime //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/unicast", BOOST_ASIO_COMPILE_TEST_CASE(ip_unicast_compile::test) BOOST_ASIO_TEST_CASE(ip_unicast_runtime::test) )
cpp
asio
data/projects/asio/test/ip/v6_only.cpp
// // v6_only.cpp // ~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/v6_only.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/ip/udp.hpp> #include "../unit_test.hpp" //------------------------------------------------------------------------------ // ip_v6_only_compile test // ~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that the ip::v6_only socket option compiles and // link correctly. Runtime failures are ignored. namespace ip_v6_only_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; ip::udp::socket sock(ioc); // v6_only class. ip::v6_only v6_only1(true); sock.set_option(v6_only1); ip::v6_only v6_only2; sock.get_option(v6_only2); v6_only1 = true; (void)static_cast<bool>(v6_only1); (void)static_cast<bool>(!v6_only1); (void)static_cast<bool>(v6_only1.value()); } catch (std::exception&) { } } } // namespace ip_v6_only_compile //------------------------------------------------------------------------------ // ip_v6_only_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks the runtime operation of the ip::v6_only socket // option. namespace ip_v6_only_runtime { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; io_context ioc; boost::system::error_code ec; ip::tcp::endpoint ep_v6(ip::address_v6::loopback(), 0); ip::tcp::acceptor acceptor_v6(ioc); acceptor_v6.open(ep_v6.protocol(), ec); acceptor_v6.bind(ep_v6, ec); bool have_v6 = !ec; acceptor_v6.close(ec); acceptor_v6.open(ep_v6.protocol(), ec); if (have_v6) { ip::v6_only v6_only1; acceptor_v6.get_option(v6_only1, ec); BOOST_ASIO_CHECK(!ec); bool have_dual_stack = !v6_only1.value(); if (have_dual_stack) { ip::v6_only v6_only2(false); BOOST_ASIO_CHECK(!v6_only2.value()); BOOST_ASIO_CHECK(!static_cast<bool>(v6_only2)); BOOST_ASIO_CHECK(!v6_only2); acceptor_v6.set_option(v6_only2, ec); BOOST_ASIO_CHECK(!ec); ip::v6_only v6_only3; acceptor_v6.get_option(v6_only3, ec); BOOST_ASIO_CHECK(!ec); BOOST_ASIO_CHECK(!v6_only3.value()); BOOST_ASIO_CHECK(!static_cast<bool>(v6_only3)); BOOST_ASIO_CHECK(!v6_only3); ip::v6_only v6_only4(true); BOOST_ASIO_CHECK(v6_only4.value()); BOOST_ASIO_CHECK(static_cast<bool>(v6_only4)); BOOST_ASIO_CHECK(!!v6_only4); acceptor_v6.set_option(v6_only4, ec); BOOST_ASIO_CHECK(!ec); ip::v6_only v6_only5; acceptor_v6.get_option(v6_only5, ec); BOOST_ASIO_CHECK(!ec); BOOST_ASIO_CHECK(v6_only5.value()); BOOST_ASIO_CHECK(static_cast<bool>(v6_only5)); BOOST_ASIO_CHECK(!!v6_only5); } } } } // namespace ip_v6_only_runtime //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/v6_only", BOOST_ASIO_COMPILE_TEST_CASE(ip_v6_only_compile::test) BOOST_ASIO_TEST_CASE(ip_v6_only_runtime::test) )
cpp
asio
data/projects/asio/test/ip/multicast.cpp
// // multicast.cpp // ~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/multicast.hpp> #include <boost/asio/io_context.hpp> #include <boost/asio/ip/udp.hpp> #include "../unit_test.hpp" //------------------------------------------------------------------------------ // ip_multicast_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all nested classes, enums and constants in // ip::multicast compile and link correctly. Runtime failures are ignored. namespace ip_multicast_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; ip::udp::socket sock(ioc); const ip::address address; const ip::address_v4 address_v4; const ip::address_v6 address_v6; // join_group class. ip::multicast::join_group join_group1; ip::multicast::join_group join_group2(address); ip::multicast::join_group join_group3(address_v4); ip::multicast::join_group join_group4(address_v4, address_v4); ip::multicast::join_group join_group5(address_v6); ip::multicast::join_group join_group6(address_v6, 1); sock.set_option(join_group6); // leave_group class. ip::multicast::leave_group leave_group1; ip::multicast::leave_group leave_group2(address); ip::multicast::leave_group leave_group3(address_v4); ip::multicast::leave_group leave_group4(address_v4, address_v4); ip::multicast::leave_group leave_group5(address_v6); ip::multicast::leave_group leave_group6(address_v6, 1); sock.set_option(leave_group6); // outbound_interface class. ip::multicast::outbound_interface outbound_interface1; ip::multicast::outbound_interface outbound_interface2(address_v4); ip::multicast::outbound_interface outbound_interface3(1); sock.set_option(outbound_interface3); // hops class. ip::multicast::hops hops1(1024); sock.set_option(hops1); ip::multicast::hops hops2; sock.get_option(hops2); hops1 = 1; (void)static_cast<int>(hops1.value()); // enable_loopback class. ip::multicast::enable_loopback enable_loopback1(true); sock.set_option(enable_loopback1); ip::multicast::enable_loopback enable_loopback2; sock.get_option(enable_loopback2); enable_loopback1 = true; (void)static_cast<bool>(enable_loopback1); (void)static_cast<bool>(!enable_loopback1); (void)static_cast<bool>(enable_loopback1.value()); } catch (std::exception&) { } } } // namespace ip_multicast_compile //------------------------------------------------------------------------------ // ip_multicast_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks the runtime operation of the socket options defined // in the ip::multicast namespace. namespace ip_multicast_runtime { #if defined(__hpux) // HP-UX doesn't declare this function extern "C", so it is declared again here // to avoid a linker error about an undefined symbol. extern "C" unsigned int if_nametoindex(const char*); #endif // defined(__hpux) void test() { using namespace boost::asio; namespace ip = boost::asio::ip; io_context ioc; boost::system::error_code ec; ip::udp::endpoint ep_v4(ip::address_v4::loopback(), 0); ip::udp::socket sock_v4(ioc); sock_v4.open(ep_v4.protocol(), ec); sock_v4.bind(ep_v4, ec); bool have_v4 = !ec; ip::udp::endpoint ep_v6(ip::address_v6::loopback(), 0); ip::udp::socket sock_v6(ioc); sock_v6.open(ep_v6.protocol(), ec); sock_v6.bind(ep_v6, ec); bool have_v6 = !ec; BOOST_ASIO_CHECK(have_v4 || have_v6); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Windows CE seems to have problems with some multicast group addresses. // The following address works on CE, but as it is not a private multicast // address it will not be used on other platforms. const ip::address multicast_address_v4 = ip::make_address("239.0.0.4", ec); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) const ip::address multicast_address_v4 = ip::make_address("239.255.0.1", ec); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK(!have_v4 || !ec); #if (defined(__MACH__) && defined(__APPLE__)) \ || defined(__FreeBSD__) \ || defined(__NetBSD__) \ || defined(__OpenBSD__) const ip::address multicast_address_v6 = ip::make_address("ff02::1%lo0", ec); #else // (defined(__MACH__) && defined(__APPLE__)) // || defined(__FreeBSD__) // || defined(__NetBSD__) // || defined(__OpenBSD__) const ip::address multicast_address_v6 = ip::make_address("ff01::1", ec); #endif // (defined(__MACH__) && defined(__APPLE__)) // || defined(__FreeBSD__) // || defined(__NetBSD__) // || defined(__OpenBSD__) BOOST_ASIO_CHECK(!have_v6 || !ec); // join_group class. if (have_v4) { ip::multicast::join_group join_group(multicast_address_v4); sock_v4.set_option(join_group, ec); BOOST_ASIO_CHECK_MESSAGE(!ec || ec == error::no_such_device, ec.value() << ", " << ec.message()); if (!ec) { // leave_group class. ip::multicast::leave_group leave_group(multicast_address_v4); sock_v4.set_option(leave_group, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); } } if (have_v6) { ip::multicast::join_group join_group(multicast_address_v6); sock_v6.set_option(join_group, ec); BOOST_ASIO_CHECK_MESSAGE(!ec || ec == error::no_such_device, ec.value() << ", " << ec.message()); if (!ec) { // leave_group class. ip::multicast::leave_group leave_group(multicast_address_v6); sock_v6.set_option(leave_group, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); } } // outbound_interface class. if (have_v4) { ip::multicast::outbound_interface outbound_interface( ip::address_v4::loopback()); sock_v4.set_option(outbound_interface, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); } if (have_v6) { #if defined(__hpux) ip::multicast::outbound_interface outbound_interface(if_nametoindex("lo0")); #else ip::multicast::outbound_interface outbound_interface(1); #endif sock_v6.set_option(outbound_interface, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); } // hops class. if (have_v4) { ip::multicast::hops hops1(1); BOOST_ASIO_CHECK(hops1.value() == 1); sock_v4.set_option(hops1, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); ip::multicast::hops hops2; sock_v4.get_option(hops2, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(hops2.value() == 1); ip::multicast::hops hops3(0); BOOST_ASIO_CHECK(hops3.value() == 0); sock_v4.set_option(hops3, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); ip::multicast::hops hops4; sock_v4.get_option(hops4, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(hops4.value() == 0); } if (have_v6) { ip::multicast::hops hops1(1); BOOST_ASIO_CHECK(hops1.value() == 1); sock_v6.set_option(hops1, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); ip::multicast::hops hops2; sock_v6.get_option(hops2, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(hops2.value() == 1); ip::multicast::hops hops3(0); BOOST_ASIO_CHECK(hops3.value() == 0); sock_v6.set_option(hops3, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); ip::multicast::hops hops4; sock_v6.get_option(hops4, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(hops4.value() == 0); } // enable_loopback class. if (have_v4) { ip::multicast::enable_loopback enable_loopback1(true); BOOST_ASIO_CHECK(enable_loopback1.value()); BOOST_ASIO_CHECK(static_cast<bool>(enable_loopback1)); BOOST_ASIO_CHECK(!!enable_loopback1); sock_v4.set_option(enable_loopback1, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) ip::multicast::enable_loopback enable_loopback2; sock_v4.get_option(enable_loopback2, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Not supported under Windows CE but can get value. BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(enable_loopback2.value()); BOOST_ASIO_CHECK(static_cast<bool>(enable_loopback2)); BOOST_ASIO_CHECK(!!enable_loopback2); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) ip::multicast::enable_loopback enable_loopback3(false); BOOST_ASIO_CHECK(!enable_loopback3.value()); BOOST_ASIO_CHECK(!static_cast<bool>(enable_loopback3)); BOOST_ASIO_CHECK(!enable_loopback3); sock_v4.set_option(enable_loopback3, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Option is not supported under Windows CE. BOOST_ASIO_CHECK_MESSAGE(ec == boost::asio::error::no_protocol_option, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) ip::multicast::enable_loopback enable_loopback4; sock_v4.get_option(enable_loopback4, ec); #if defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) // Not supported under Windows CE but can get value. BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); #else // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(!enable_loopback4.value()); BOOST_ASIO_CHECK(!static_cast<bool>(enable_loopback4)); BOOST_ASIO_CHECK(!enable_loopback4); #endif // defined(BOOST_ASIO_WINDOWS) && defined(UNDER_CE) } if (have_v6) { ip::multicast::enable_loopback enable_loopback1(true); BOOST_ASIO_CHECK(enable_loopback1.value()); BOOST_ASIO_CHECK(static_cast<bool>(enable_loopback1)); BOOST_ASIO_CHECK(!!enable_loopback1); sock_v6.set_option(enable_loopback1, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); ip::multicast::enable_loopback enable_loopback2; sock_v6.get_option(enable_loopback2, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(enable_loopback2.value()); BOOST_ASIO_CHECK(static_cast<bool>(enable_loopback2)); BOOST_ASIO_CHECK(!!enable_loopback2); ip::multicast::enable_loopback enable_loopback3(false); BOOST_ASIO_CHECK(!enable_loopback3.value()); BOOST_ASIO_CHECK(!static_cast<bool>(enable_loopback3)); BOOST_ASIO_CHECK(!enable_loopback3); sock_v6.set_option(enable_loopback3, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); ip::multicast::enable_loopback enable_loopback4; sock_v6.get_option(enable_loopback4, ec); BOOST_ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message()); BOOST_ASIO_CHECK(!enable_loopback4.value()); BOOST_ASIO_CHECK(!static_cast<bool>(enable_loopback4)); BOOST_ASIO_CHECK(!enable_loopback4); } } } // namespace ip_multicast_runtime //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/multicast", BOOST_ASIO_COMPILE_TEST_CASE(ip_multicast_compile::test) BOOST_ASIO_TEST_CASE(ip_multicast_runtime::test) )
cpp
asio
data/projects/asio/test/ip/icmp.cpp
// // icmp.cpp // ~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/icmp.hpp> #include <cstring> #include <boost/asio/io_context.hpp> #include <boost/asio/placeholders.hpp> #include "../unit_test.hpp" #include "../archetypes/async_result.hpp" #include "../archetypes/gettable_socket_option.hpp" #include "../archetypes/io_control_command.hpp" #include "../archetypes/settable_socket_option.hpp" //------------------------------------------------------------------------------ // ip_icmp_socket_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::icmp::socket compile and link correctly. Runtime failures are ignored. namespace ip_icmp_socket_compile { struct connect_handler { connect_handler() {} void operator()(const boost::system::error_code&) {} connect_handler(connect_handler&&) {} private: connect_handler(const connect_handler&); }; struct send_handler { send_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} send_handler(send_handler&&) {} private: send_handler(const send_handler&); }; struct receive_handler { receive_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} receive_handler(receive_handler&&) {} private: receive_handler(const receive_handler&); }; void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); char mutable_char_buffer[128] = ""; const char const_char_buffer[128] = ""; socket_base::message_flags in_flags = 0; archetypes::settable_socket_option<void> settable_socket_option1; archetypes::settable_socket_option<int> settable_socket_option2; archetypes::settable_socket_option<double> settable_socket_option3; archetypes::gettable_socket_option<void> gettable_socket_option1; archetypes::gettable_socket_option<int> gettable_socket_option2; archetypes::gettable_socket_option<double> gettable_socket_option3; archetypes::io_control_command io_control_command; archetypes::immediate_handler immediate; archetypes::lazy_handler lazy; boost::system::error_code ec; // basic_datagram_socket constructors. ip::icmp::socket socket1(ioc); ip::icmp::socket socket2(ioc, ip::icmp::v4()); ip::icmp::socket socket3(ioc, ip::icmp::v6()); ip::icmp::socket socket4(ioc, ip::icmp::endpoint(ip::icmp::v4(), 0)); ip::icmp::socket socket5(ioc, ip::icmp::endpoint(ip::icmp::v6(), 0)); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::icmp::socket::native_handle_type native_socket1 = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); ip::icmp::socket socket6(ioc, ip::icmp::v4(), native_socket1); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::icmp::socket socket7(ioc_ex); ip::icmp::socket socket8(ioc_ex, ip::icmp::v4()); ip::icmp::socket socket9(ioc_ex, ip::icmp::v6()); ip::icmp::socket socket10(ioc_ex, ip::icmp::endpoint(ip::icmp::v4(), 0)); ip::icmp::socket socket11(ioc_ex, ip::icmp::endpoint(ip::icmp::v6(), 0)); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::icmp::socket::native_handle_type native_socket2 = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); ip::icmp::socket socket12(ioc_ex, ip::icmp::v4(), native_socket2); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::icmp::socket socket13(std::move(socket6)); // basic_datagram_socket operators. socket1 = ip::icmp::socket(ioc); socket1 = std::move(socket2); // basic_io_object functions. ip::icmp::socket::executor_type ex = socket1.get_executor(); (void)ex; // basic_socket functions. ip::icmp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer(); (void)lowest_layer; const ip::icmp::socket& socket14 = socket1; const ip::icmp::socket::lowest_layer_type& lowest_layer2 = socket14.lowest_layer(); (void)lowest_layer2; socket1.open(ip::icmp::v4()); socket1.open(ip::icmp::v6()); socket1.open(ip::icmp::v4(), ec); socket1.open(ip::icmp::v6(), ec); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::icmp::socket::native_handle_type native_socket3 = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); socket1.assign(ip::icmp::v4(), native_socket3); ip::icmp::socket::native_handle_type native_socket4 = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); socket1.assign(ip::icmp::v4(), native_socket4, ec); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) bool is_open = socket1.is_open(); (void)is_open; socket1.close(); socket1.close(ec); socket1.release(); socket1.release(ec); ip::icmp::socket::native_handle_type native_socket5 = socket1.native_handle(); (void)native_socket5; socket1.cancel(); socket1.cancel(ec); bool at_mark1 = socket1.at_mark(); (void)at_mark1; bool at_mark2 = socket1.at_mark(ec); (void)at_mark2; std::size_t available1 = socket1.available(); (void)available1; std::size_t available2 = socket1.available(ec); (void)available2; socket1.bind(ip::icmp::endpoint(ip::icmp::v4(), 0)); socket1.bind(ip::icmp::endpoint(ip::icmp::v6(), 0)); socket1.bind(ip::icmp::endpoint(ip::icmp::v4(), 0), ec); socket1.bind(ip::icmp::endpoint(ip::icmp::v6(), 0), ec); socket1.connect(ip::icmp::endpoint(ip::icmp::v4(), 0)); socket1.connect(ip::icmp::endpoint(ip::icmp::v6(), 0)); socket1.connect(ip::icmp::endpoint(ip::icmp::v4(), 0), ec); socket1.connect(ip::icmp::endpoint(ip::icmp::v6(), 0), ec); socket1.async_connect(ip::icmp::endpoint(ip::icmp::v4(), 0), connect_handler()); socket1.async_connect(ip::icmp::endpoint(ip::icmp::v6(), 0), connect_handler()); socket1.async_connect(ip::icmp::endpoint(ip::icmp::v4(), 0), immediate); socket1.async_connect(ip::icmp::endpoint(ip::icmp::v6(), 0), immediate); int i1 = socket1.async_connect(ip::icmp::endpoint(ip::icmp::v4(), 0), lazy); (void)i1; int i2 = socket1.async_connect(ip::icmp::endpoint(ip::icmp::v6(), 0), lazy); (void)i2; socket1.set_option(settable_socket_option1); socket1.set_option(settable_socket_option1, ec); socket1.set_option(settable_socket_option2); socket1.set_option(settable_socket_option2, ec); socket1.set_option(settable_socket_option3); socket1.set_option(settable_socket_option3, ec); socket1.get_option(gettable_socket_option1); socket1.get_option(gettable_socket_option1, ec); socket1.get_option(gettable_socket_option2); socket1.get_option(gettable_socket_option2, ec); socket1.get_option(gettable_socket_option3); socket1.get_option(gettable_socket_option3, ec); socket1.io_control(io_control_command); socket1.io_control(io_control_command, ec); bool non_blocking1 = socket1.non_blocking(); (void)non_blocking1; socket1.non_blocking(true); socket1.non_blocking(false, ec); bool non_blocking2 = socket1.native_non_blocking(); (void)non_blocking2; socket1.native_non_blocking(true); socket1.native_non_blocking(false, ec); ip::icmp::endpoint endpoint1 = socket1.local_endpoint(); (void)endpoint1; ip::icmp::endpoint endpoint2 = socket1.local_endpoint(ec); (void)endpoint2; ip::icmp::endpoint endpoint3 = socket1.remote_endpoint(); (void)endpoint3; ip::icmp::endpoint endpoint4 = socket1.remote_endpoint(ec); (void)endpoint4; socket1.shutdown(socket_base::shutdown_both); socket1.shutdown(socket_base::shutdown_both, ec); // basic_datagram_socket functions. socket1.send(buffer(mutable_char_buffer)); socket1.send(buffer(const_char_buffer)); socket1.send(null_buffers()); socket1.send(buffer(mutable_char_buffer), in_flags); socket1.send(buffer(const_char_buffer), in_flags); socket1.send(null_buffers(), in_flags); socket1.send(buffer(mutable_char_buffer), in_flags, ec); socket1.send(buffer(const_char_buffer), in_flags, ec); socket1.send(null_buffers(), in_flags, ec); socket1.async_send(buffer(mutable_char_buffer), send_handler()); socket1.async_send(buffer(const_char_buffer), send_handler()); socket1.async_send(null_buffers(), send_handler()); socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler()); socket1.async_send(buffer(const_char_buffer), in_flags, send_handler()); socket1.async_send(null_buffers(), in_flags, send_handler()); socket1.async_send(buffer(mutable_char_buffer), immediate); socket1.async_send(buffer(const_char_buffer), immediate); socket1.async_send(null_buffers(), immediate); socket1.async_send(buffer(mutable_char_buffer), in_flags, immediate); socket1.async_send(buffer(const_char_buffer), in_flags, immediate); socket1.async_send(null_buffers(), in_flags, immediate); int i3 = socket1.async_send(buffer(mutable_char_buffer), lazy); (void)i3; int i4 = socket1.async_send(buffer(const_char_buffer), lazy); (void)i4; int i5 = socket1.async_send(null_buffers(), lazy); (void)i5; int i6 = socket1.async_send(buffer(mutable_char_buffer), in_flags, lazy); (void)i6; int i7 = socket1.async_send(buffer(const_char_buffer), in_flags, lazy); (void)i7; int i8 = socket1.async_send(null_buffers(), in_flags, lazy); (void)i8; socket1.send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0)); socket1.send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0)); socket1.send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0)); socket1.send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0)); socket1.send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v4(), 0)); socket1.send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v6(), 0)); socket1.send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags); socket1.send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags); socket1.send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags); socket1.send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags); socket1.send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags); socket1.send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags); socket1.send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, ec); socket1.send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, ec); socket1.send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, ec); socket1.send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, ec); socket1.send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, ec); socket1.send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, ec); socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), send_handler()); socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), send_handler()); socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), send_handler()); socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v4(), 0), send_handler()); socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v6(), 0), send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, send_handler()); socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, send_handler()); socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, send_handler()); socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), immediate); socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), immediate); socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), immediate); socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), immediate); socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v4(), 0), immediate); socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v6(), 0), immediate); socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, immediate); socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, immediate); socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, immediate); socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, immediate); socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, immediate); socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, immediate); int i9 = socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), lazy); (void)i9; int i10 = socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), lazy); (void)i10; int i11 = socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), lazy); (void)i11; int i12 = socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), lazy); (void)i12; int i13 = socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v4(), 0), lazy); (void)i13; int i14 = socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v6(), 0), lazy); (void)i14; int i15 = socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, lazy); (void)i15; int i16 = socket1.async_send_to(buffer(mutable_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, lazy); (void)i16; int i17 = socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, lazy); (void)i17; int i18 = socket1.async_send_to(buffer(const_char_buffer), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, lazy); (void)i18; int i19 = socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v4(), 0), in_flags, lazy); (void)i19; int i20 = socket1.async_send_to(null_buffers(), ip::icmp::endpoint(ip::icmp::v6(), 0), in_flags, lazy); (void)i20; socket1.receive(buffer(mutable_char_buffer)); socket1.receive(null_buffers()); socket1.receive(buffer(mutable_char_buffer), in_flags); socket1.receive(null_buffers(), in_flags); socket1.receive(buffer(mutable_char_buffer), in_flags, ec); socket1.receive(null_buffers(), in_flags, ec); socket1.async_receive(buffer(mutable_char_buffer), receive_handler()); socket1.async_receive(null_buffers(), receive_handler()); socket1.async_receive(buffer(mutable_char_buffer), in_flags, receive_handler()); socket1.async_receive(null_buffers(), in_flags, receive_handler()); socket1.async_receive(buffer(mutable_char_buffer), immediate); socket1.async_receive(null_buffers(), immediate); socket1.async_receive(buffer(mutable_char_buffer), in_flags, immediate); socket1.async_receive(null_buffers(), in_flags, immediate); int i21 = socket1.async_receive(buffer(mutable_char_buffer), lazy); (void)i21; int i22 = socket1.async_receive(null_buffers(), lazy); (void)i22; int i23 = socket1.async_receive(buffer(mutable_char_buffer), in_flags, lazy); (void)i23; int i24 = socket1.async_receive(null_buffers(), in_flags, lazy); (void)i24; ip::icmp::endpoint endpoint; socket1.receive_from(buffer(mutable_char_buffer), endpoint); socket1.receive_from(null_buffers(), endpoint); socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags); socket1.receive_from(null_buffers(), endpoint, in_flags); socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags, ec); socket1.receive_from(null_buffers(), endpoint, in_flags, ec); socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, receive_handler()); socket1.async_receive_from(null_buffers(), endpoint, receive_handler()); socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, in_flags, receive_handler()); socket1.async_receive_from(null_buffers(), endpoint, in_flags, receive_handler()); socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, immediate); socket1.async_receive_from(null_buffers(), endpoint, immediate); socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, in_flags, immediate); socket1.async_receive_from(null_buffers(), endpoint, in_flags, immediate); int i25 = socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, lazy); (void)i25; int i26 = socket1.async_receive_from(null_buffers(), endpoint, lazy); (void)i26; int i27 = socket1.async_receive_from(buffer(mutable_char_buffer), endpoint, in_flags, lazy); (void)i27; int i28 = socket1.async_receive_from(null_buffers(), endpoint, in_flags, lazy); (void)i28; } catch (std::exception&) { } } } // namespace ip_icmp_socket_compile //------------------------------------------------------------------------------ // ip_icmp_resolver_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::icmp::resolver compile and link correctly. Runtime failures are ignored. namespace ip_icmp_resolver_compile { struct resolve_handler { resolve_handler() {} void operator()(const boost::system::error_code&, boost::asio::ip::icmp::resolver::results_type) {} resolve_handler(resolve_handler&&) {} private: resolve_handler(const resolve_handler&); }; void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); archetypes::lazy_handler lazy; boost::system::error_code ec; #if !defined(BOOST_ASIO_NO_DEPRECATED) ip::icmp::resolver::query q(ip::icmp::v4(), "localhost", "0"); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) ip::icmp::endpoint e(ip::address_v4::loopback(), 0); // basic_resolver constructors. ip::icmp::resolver resolver(ioc); ip::icmp::resolver resolver2(ioc_ex); ip::icmp::resolver resolver3(std::move(resolver)); // basic_resolver operators. resolver = ip::icmp::resolver(ioc); resolver = std::move(resolver3); // basic_io_object functions. ip::icmp::resolver::executor_type ex = resolver.get_executor(); (void)ex; // basic_resolver functions. resolver.cancel(); #if !defined(BOOST_ASIO_NO_DEPRECATED) ip::icmp::resolver::results_type results1 = resolver.resolve(q); (void)results1; ip::icmp::resolver::results_type results2 = resolver.resolve(q, ec); (void)results2; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) ip::icmp::resolver::results_type results3 = resolver.resolve("", ""); (void)results3; ip::icmp::resolver::results_type results4 = resolver.resolve("", "", ec); (void)results4; ip::icmp::resolver::results_type results5 = resolver.resolve("", "", ip::icmp::resolver::flags()); (void)results5; ip::icmp::resolver::results_type results6 = resolver.resolve("", "", ip::icmp::resolver::flags(), ec); (void)results6; ip::icmp::resolver::results_type results7 = resolver.resolve(ip::icmp::v4(), "", ""); (void)results7; ip::icmp::resolver::results_type results8 = resolver.resolve(ip::icmp::v4(), "", "", ec); (void)results8; ip::icmp::resolver::results_type results9 = resolver.resolve(ip::icmp::v4(), "", "", ip::icmp::resolver::flags()); (void)results9; ip::icmp::resolver::results_type results10 = resolver.resolve(ip::icmp::v4(), "", "", ip::icmp::resolver::flags(), ec); (void)results10; ip::icmp::resolver::results_type results11 = resolver.resolve(e); (void)results11; ip::icmp::resolver::results_type results12 = resolver.resolve(e, ec); (void)results12; #if !defined(BOOST_ASIO_NO_DEPRECATED) resolver.async_resolve(q, resolve_handler()); int i1 = resolver.async_resolve(q, lazy); (void)i1; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) resolver.async_resolve("", "", resolve_handler()); int i2 = resolver.async_resolve("", "", lazy); (void)i2; resolver.async_resolve("", "", ip::icmp::resolver::flags(), resolve_handler()); int i3 = resolver.async_resolve("", "", ip::icmp::resolver::flags(), lazy); (void)i3; resolver.async_resolve(ip::icmp::v4(), "", "", resolve_handler()); int i4 = resolver.async_resolve(ip::icmp::v4(), "", "", lazy); (void)i4; resolver.async_resolve(ip::icmp::v4(), "", "", ip::icmp::resolver::flags(), resolve_handler()); int i5 = resolver.async_resolve(ip::icmp::v4(), "", "", ip::icmp::resolver::flags(), lazy); (void)i5; resolver.async_resolve(e, resolve_handler()); int i6 = resolver.async_resolve(e, lazy); (void)i6; } catch (std::exception&) { } } } // namespace ip_icmp_resolver_compile //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/icmp", BOOST_ASIO_COMPILE_TEST_CASE(ip_icmp_socket_compile::test) BOOST_ASIO_COMPILE_TEST_CASE(ip_icmp_resolver_compile::test) )
cpp
asio
data/projects/asio/test/ip/address_v6_iterator.cpp
// // address_v6_iterator.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/address_v6_iterator.hpp> #include "../unit_test.hpp" //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/address_v6_iterator", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/ip/address_v6_range.cpp
// // address_v6_range.cpp // ~~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/address_v6_range.hpp> #include "../unit_test.hpp" //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/address_v6_range", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/ip/network_v4.cpp
// // network_v4.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/network_v4.hpp> #include "../unit_test.hpp" #include <sstream> //------------------------------------------------------------------------------ // ip_network_v4_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::network_v4 compile and link correctly. Runtime failures are ignored. namespace ip_network_v4_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { boost::system::error_code ec; // network_v4 constructors. ip::network_v4 net1(ip::make_address_v4("192.168.1.0"), 32); ip::network_v4 net2(ip::make_address_v4("192.168.1.0"), ip::make_address_v4("255.255.255.0")); // network_v4 functions. ip::address_v4 addr1 = net1.address(); (void)addr1; unsigned short prefix_len = net1.prefix_length(); (void)prefix_len; ip::address_v4 addr2 = net1.netmask(); (void)addr2; ip::address_v4 addr3 = net1.network(); (void)addr3; ip::address_v4 addr4 = net1.broadcast(); (void)addr4; ip::address_v4_range hosts = net1.hosts(); (void)hosts; ip::network_v4 net3 = net1.canonical(); (void)net3; bool b1 = net1.is_host(); (void)b1; bool b2 = net1.is_subnet_of(net2); (void)b2; std::string s1 = net1.to_string(); (void)s1; std::string s2 = net1.to_string(ec); (void)s2; // network_v4 comparisons. bool b3 = (net1 == net2); (void)b3; bool b4 = (net1 != net2); (void)b4; // network_v4 creation functions. net1 = ip::make_network_v4(ip::address_v4(), 24); net1 = ip::make_network_v4(ip::address_v4(), ip::address_v4()); net1 = ip::make_network_v4("10.0.0.0/8"); net1 = ip::make_network_v4("10.0.0.0/8", ec); net1 = ip::make_network_v4(s1); net1 = ip::make_network_v4(s1, ec); #if defined(BOOST_ASIO_HAS_STRING_VIEW) # if defined(BOOST_ASIO_HAS_STD_STRING_VIEW) std::string_view string_view_value("10.0.0.0/8"); # elif defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) std::experimental::string_view string_view_value("10.0.0.0/8"); # endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) net1 = ip::make_network_v4(string_view_value); net1 = ip::make_network_v4(string_view_value, ec); #endif // defined(BOOST_ASIO_HAS_STRING_VIEW) // network_v4 I/O. std::ostringstream os; os << net1; #if !defined(BOOST_NO_STD_WSTREAMBUF) std::wostringstream wos; wos << net1; #endif // !defined(BOOST_NO_STD_WSTREAMBUF) } catch (std::exception&) { } } } // namespace ip_network_v4_compile //------------------------------------------------------------------------------ // ip_network_v4_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that the various public member functions meet the // necessary postconditions. namespace ip_network_v4_runtime { void test() { using boost::asio::ip::address_v4; using boost::asio::ip::make_address_v4; using boost::asio::ip::network_v4; using boost::asio::ip::make_network_v4; address_v4 addr = make_address_v4("1.2.3.4"); // calculate prefix length network_v4 net1(addr, make_address_v4("255.255.255.0")); BOOST_ASIO_CHECK(net1.prefix_length() == 24); network_v4 net2(addr, make_address_v4("255.255.255.192")); BOOST_ASIO_CHECK(net2.prefix_length() == 26); network_v4 net3(addr, make_address_v4("128.0.0.0")); BOOST_ASIO_CHECK(net3.prefix_length() == 1); std::string msg; try { make_network_v4(addr, make_address_v4("255.255.255.1")); } catch(std::exception& ex) { msg = ex.what(); } BOOST_ASIO_CHECK(msg == std::string("non-contiguous netmask")); msg.clear(); try { make_network_v4(addr, make_address_v4("0.255.255.0")); } catch(std::exception& ex) { msg = ex.what(); } BOOST_ASIO_CHECK(msg == std::string("non-contiguous netmask")); // calculate netmask network_v4 net4(addr, 23); BOOST_ASIO_CHECK(net4.netmask() == make_address_v4("255.255.254.0")); network_v4 net5(addr, 12); BOOST_ASIO_CHECK(net5.netmask() == make_address_v4("255.240.0.0")); network_v4 net6(addr, 24); BOOST_ASIO_CHECK(net6.netmask() == make_address_v4("255.255.255.0")); network_v4 net7(addr, 16); BOOST_ASIO_CHECK(net7.netmask() == make_address_v4("255.255.0.0")); network_v4 net8(addr, 8); BOOST_ASIO_CHECK(net8.netmask() == make_address_v4("255.0.0.0")); network_v4 net9(addr, 32); BOOST_ASIO_CHECK(net9.netmask() == make_address_v4("255.255.255.255")); network_v4 net10(addr, 1); BOOST_ASIO_CHECK(net10.netmask() == make_address_v4("128.0.0.0")); network_v4 net11(addr, 0); BOOST_ASIO_CHECK(net11.netmask() == make_address_v4("0.0.0.0")); msg.clear(); try { make_network_v4(addr, 33); } catch(std::out_of_range& ex) { msg = ex.what(); } BOOST_ASIO_CHECK(msg == std::string("prefix length too large")); // construct address range from address and prefix length BOOST_ASIO_CHECK(network_v4(make_address_v4("192.168.77.100"), 32).network() == make_address_v4("192.168.77.100")); BOOST_ASIO_CHECK(network_v4(make_address_v4("192.168.77.100"), 24).network() == make_address_v4("192.168.77.0")); BOOST_ASIO_CHECK(network_v4(make_address_v4("192.168.77.128"), 25).network() == make_address_v4("192.168.77.128")); // construct address range from string in CIDR notation BOOST_ASIO_CHECK(make_network_v4("192.168.77.100/32").network() == make_address_v4("192.168.77.100")); BOOST_ASIO_CHECK(make_network_v4("192.168.77.100/24").network() == make_address_v4("192.168.77.0")); BOOST_ASIO_CHECK(make_network_v4("192.168.77.128/25").network() == make_address_v4("192.168.77.128")); // construct network from invalid string boost::system::error_code ec; make_network_v4("10.0.0.256/24", ec); BOOST_ASIO_CHECK(!!ec); make_network_v4("10.0.0.0/33", ec); BOOST_ASIO_CHECK(!!ec); make_network_v4("10.0.0.0/-1", ec); BOOST_ASIO_CHECK(!!ec); make_network_v4("10.0.0.0/", ec); BOOST_ASIO_CHECK(!!ec); make_network_v4("10.0.0.0", ec); BOOST_ASIO_CHECK(!!ec); // prefix length BOOST_ASIO_CHECK(make_network_v4("193.99.144.80/24").prefix_length() == 24); BOOST_ASIO_CHECK(network_v4(make_address_v4("193.99.144.80"), 24).prefix_length() == 24); BOOST_ASIO_CHECK(network_v4(make_address_v4("192.168.77.0"), make_address_v4("255.255.255.0")).prefix_length() == 24); // to string std::string a("192.168.77.0/32"); BOOST_ASIO_CHECK(make_network_v4(a.c_str()).to_string() == a); BOOST_ASIO_CHECK(network_v4(make_address_v4("192.168.77.10"), 24).to_string() == std::string("192.168.77.10/24")); // return host part BOOST_ASIO_CHECK(make_network_v4("192.168.77.11/24").address() == make_address_v4("192.168.77.11")); // return host in CIDR notation BOOST_ASIO_CHECK(make_network_v4("192.168.78.30/20").address().to_string() == "192.168.78.30"); // return network in CIDR notation BOOST_ASIO_CHECK(make_network_v4("192.168.78.30/20").canonical().to_string() == "192.168.64.0/20"); // is host BOOST_ASIO_CHECK(make_network_v4("192.168.77.0/32").is_host()); BOOST_ASIO_CHECK(!make_network_v4("192.168.77.0/31").is_host()); // is real subnet of BOOST_ASIO_CHECK(make_network_v4("192.168.0.192/24").is_subnet_of(make_network_v4("192.168.0.0/16"))); BOOST_ASIO_CHECK(make_network_v4("192.168.0.0/24").is_subnet_of(make_network_v4("192.168.192.168/16"))); BOOST_ASIO_CHECK(make_network_v4("192.168.0.192/24").is_subnet_of(make_network_v4("192.168.192.168/16"))); BOOST_ASIO_CHECK(make_network_v4("192.168.0.0/24").is_subnet_of(make_network_v4("192.168.0.0/16"))); BOOST_ASIO_CHECK(make_network_v4("192.168.0.0/24").is_subnet_of(make_network_v4("192.168.0.0/23"))); BOOST_ASIO_CHECK(make_network_v4("192.168.0.0/24").is_subnet_of(make_network_v4("192.168.0.0/0"))); BOOST_ASIO_CHECK(make_network_v4("192.168.0.0/32").is_subnet_of(make_network_v4("192.168.0.0/24"))); BOOST_ASIO_CHECK(!make_network_v4("192.168.0.0/32").is_subnet_of(make_network_v4("192.168.0.0/32"))); BOOST_ASIO_CHECK(!make_network_v4("192.168.0.0/24").is_subnet_of(make_network_v4("192.168.1.0/24"))); BOOST_ASIO_CHECK(!make_network_v4("192.168.0.0/16").is_subnet_of(make_network_v4("192.168.1.0/24"))); network_v4 r(make_network_v4("192.168.0.0/24")); BOOST_ASIO_CHECK(!r.is_subnet_of(r)); network_v4 net12(make_network_v4("192.168.0.2/24")); network_v4 net13(make_network_v4("192.168.1.1/28")); network_v4 net14(make_network_v4("192.168.1.21/28")); // network BOOST_ASIO_CHECK(net12.network() == make_address_v4("192.168.0.0")); BOOST_ASIO_CHECK(net13.network() == make_address_v4("192.168.1.0")); BOOST_ASIO_CHECK(net14.network() == make_address_v4("192.168.1.16")); // netmask BOOST_ASIO_CHECK(net12.netmask() == make_address_v4("255.255.255.0")); BOOST_ASIO_CHECK(net13.netmask() == make_address_v4("255.255.255.240")); BOOST_ASIO_CHECK(net14.netmask() == make_address_v4("255.255.255.240")); // broadcast BOOST_ASIO_CHECK(net12.broadcast() == make_address_v4("192.168.0.255")); BOOST_ASIO_CHECK(net13.broadcast() == make_address_v4("192.168.1.15")); BOOST_ASIO_CHECK(net14.broadcast() == make_address_v4("192.168.1.31")); // iterator BOOST_ASIO_CHECK(std::distance(net12.hosts().begin(),net12.hosts().end()) == 254); BOOST_ASIO_CHECK(*net12.hosts().begin() == make_address_v4("192.168.0.1")); BOOST_ASIO_CHECK(net12.hosts().end() != net12.hosts().find(make_address_v4("192.168.0.10"))); BOOST_ASIO_CHECK(net12.hosts().end() == net12.hosts().find(make_address_v4("192.168.1.10"))); BOOST_ASIO_CHECK(std::distance(net13.hosts().begin(),net13.hosts().end()) == 14); BOOST_ASIO_CHECK(*net13.hosts().begin() == make_address_v4("192.168.1.1")); BOOST_ASIO_CHECK(net13.hosts().end() != net13.hosts().find(make_address_v4("192.168.1.14"))); BOOST_ASIO_CHECK(net13.hosts().end() == net13.hosts().find(make_address_v4("192.168.1.15"))); BOOST_ASIO_CHECK(std::distance(net14.hosts().begin(),net14.hosts().end()) == 14); BOOST_ASIO_CHECK(*net14.hosts().begin() == make_address_v4("192.168.1.17")); BOOST_ASIO_CHECK(net14.hosts().end() != net14.hosts().find(make_address_v4("192.168.1.30"))); BOOST_ASIO_CHECK(net14.hosts().end() == net14.hosts().find(make_address_v4("192.168.1.31"))); } } // namespace ip_network_v4_runtime //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/network_v4", BOOST_ASIO_COMPILE_TEST_CASE(ip_network_v4_compile::test) BOOST_ASIO_TEST_CASE(ip_network_v4_runtime::test) )
cpp
asio
data/projects/asio/test/ip/address.cpp
// // address.cpp // ~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/address.hpp> #include "../unit_test.hpp" #include <sstream> //------------------------------------------------------------------------------ // ip_address_compile test // ~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::address compile and link correctly. Runtime failures are ignored. namespace ip_address_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { boost::system::error_code ec; // address constructors. ip::address addr1; const ip::address_v4 const_addr_v4; ip::address addr2(const_addr_v4); const ip::address_v6 const_addr_v6; ip::address addr3(const_addr_v6); // address functions. bool b = addr1.is_v4(); (void)b; b = addr1.is_v6(); (void)b; b = addr1.is_loopback(); (void)b; b = addr1.is_unspecified(); (void)b; b = addr1.is_multicast(); (void)b; ip::address_v4 addr_v4_value = addr1.to_v4(); (void)addr_v4_value; ip::address_v6 addr_v6_value = addr1.to_v6(); (void)addr_v6_value; std::string string_value = addr1.to_string(); #if !defined(BOOST_ASIO_NO_DEPRECATED) string_value = addr1.to_string(ec); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) // address static functions. #if !defined(BOOST_ASIO_NO_DEPRECATED) addr1 = ip::address::from_string("127.0.0.1"); addr1 = ip::address::from_string("127.0.0.1", ec); addr1 = ip::address::from_string(string_value); addr1 = ip::address::from_string(string_value, ec); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) // address comparisons. b = (addr1 == addr2); (void)b; b = (addr1 != addr2); (void)b; b = (addr1 < addr2); (void)b; b = (addr1 > addr2); (void)b; b = (addr1 <= addr2); (void)b; b = (addr1 >= addr2); (void)b; // address creation functions. addr1 = ip::make_address("127.0.0.1"); addr1 = ip::make_address("127.0.0.1", ec); addr1 = ip::make_address(string_value); addr1 = ip::make_address(string_value, ec); #if defined(BOOST_ASIO_HAS_STRING_VIEW) # if defined(BOOST_ASIO_HAS_STD_STRING_VIEW) std::string_view string_view_value("127.0.0.1"); # elif defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) std::experimental::string_view string_view_value("127.0.0.1"); # endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) addr1 = ip::make_address(string_view_value); addr1 = ip::make_address(string_view_value, ec); #endif // defined(BOOST_ASIO_HAS_STRING_VIEW) // address I/O. std::ostringstream os; os << addr1; #if !defined(BOOST_NO_STD_WSTREAMBUF) std::wostringstream wos; wos << addr1; #endif // !defined(BOOST_NO_STD_WSTREAMBUF) std::size_t hash1 = std::hash<ip::address>()(addr1); (void)hash1; } catch (std::exception&) { } } } // namespace ip_address_compile //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/address", BOOST_ASIO_COMPILE_TEST_CASE(ip_address_compile::test) )
cpp
asio
data/projects/asio/test/ip/basic_endpoint.cpp
// // basic_endpoint.cpp // ~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/basic_endpoint.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "ip/basic_endpoint", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/ip/basic_resolver_entry.cpp
// // basic_resolver_entry.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/basic_resolver_entry.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "ip/basic_resolver_entry", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/ip/address_v4_range.cpp
// // address_v4_range.cpp // ~~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/address_v4_range.hpp> #include "../unit_test.hpp" //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/address_v4_range", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/ip/network_v6.cpp
// // network_v6.cpp // ~~~~~~~~~~~~~~ // // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/network_v6.hpp> #include "../unit_test.hpp" #include <sstream> //------------------------------------------------------------------------------ // ip_network_v6_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::network_v6 compile and link correctly. Runtime failures are ignored. namespace ip_network_v6_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { boost::system::error_code ec; // network_v6 constructors. ip::network_v6 net1(ip::make_address_v6("2001:370::10:7344"), 64); ip::network_v6 net2(ip::make_address_v6("2001:370::10:7345"), 96); // network_v6 functions. ip::address_v6 addr1 = net1.address(); (void)addr1; unsigned short prefix_len = net1.prefix_length(); (void)prefix_len; ip::address_v6 addr3 = net1.network(); (void)addr3; ip::address_v6_range hosts = net1.hosts(); (void)hosts; ip::network_v6 net3 = net1.canonical(); (void)net3; bool b1 = net1.is_host(); (void)b1; bool b2 = net1.is_subnet_of(net2); (void)b2; std::string s1 = net1.to_string(); (void)s1; std::string s2 = net1.to_string(ec); (void)s2; // network_v6 comparisons. bool b3 = (net1 == net2); (void)b3; bool b4 = (net1 != net2); (void)b4; // network_v6 creation functions. net1 = ip::make_network_v6(ip::address_v6(), 24); net1 = ip::make_network_v6("10.0.0.0/8"); net1 = ip::make_network_v6("10.0.0.0/8", ec); net1 = ip::make_network_v6(s1); net1 = ip::make_network_v6(s1, ec); #if defined(BOOST_ASIO_HAS_STRING_VIEW) # if defined(BOOST_ASIO_HAS_STD_STRING_VIEW) std::string_view string_view_value("0::0/8"); # elif defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) std::experimental::string_view string_view_value("0::0/8"); # endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) net1 = ip::make_network_v6(string_view_value); net1 = ip::make_network_v6(string_view_value, ec); #endif // defined(BOOST_ASIO_STD_STRING_VIEW) // network_v6 I/O. std::ostringstream os; os << net1; #if !defined(BOOST_NO_STD_WSTREAMBUF) std::wostringstream wos; wos << net1; #endif // !defined(BOOST_NO_STD_WSTREAMBUF) } catch (std::exception&) { } } } // namespace ip_network_v6_compile //------------------------------------------------------------------------------ // ip_network_v6_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that the various public member functions meet the // necessary postconditions. namespace ip_network_v6_runtime { void test() { using boost::asio::ip::address_v6; using boost::asio::ip::make_address_v6; using boost::asio::ip::network_v6; using boost::asio::ip::make_network_v6; address_v6 addr = make_address_v6("2001:370::10:7344"); std::string msg; try { make_network_v6(addr, 129); } catch(std::out_of_range& ex) { msg = ex.what(); } BOOST_ASIO_CHECK(msg == std::string("prefix length too large")); // construct address range from address and prefix length BOOST_ASIO_CHECK(network_v6(make_address_v6("2001:370::10:7344"), 128).network() == make_address_v6("2001:370::10:7344")); BOOST_ASIO_CHECK(network_v6(make_address_v6("2001:370::10:7344"), 64).network() == make_address_v6("2001:370::")); BOOST_ASIO_CHECK(network_v6(make_address_v6("2001:370::10:7344"), 27).network() == make_address_v6("2001:360::")); // construct address range from string in CIDR notation BOOST_ASIO_CHECK(make_network_v6("2001:370::10:7344/128").network() == make_address_v6("2001:370::10:7344")); BOOST_ASIO_CHECK(make_network_v6("2001:370::10:7344/64").network() == make_address_v6("2001:370::")); BOOST_ASIO_CHECK(make_network_v6("2001:370::10:7344/27").network() == make_address_v6("2001:360::")); // construct network from invalid string boost::system::error_code ec; make_network_v6("a:b/24", ec); BOOST_ASIO_CHECK(!!ec); make_network_v6("2001:370::10:7344/129", ec); BOOST_ASIO_CHECK(!!ec); make_network_v6("2001:370::10:7344/-1", ec); BOOST_ASIO_CHECK(!!ec); make_network_v6("2001:370::10:7344/", ec); BOOST_ASIO_CHECK(!!ec); make_network_v6("2001:370::10:7344", ec); BOOST_ASIO_CHECK(!!ec); // prefix length BOOST_ASIO_CHECK(make_network_v6("2001:370::10:7344/128").prefix_length() == 128); BOOST_ASIO_CHECK(network_v6(make_address_v6("2001:370::10:7344"), 27).prefix_length() == 27); // to string std::string a("2001:370::10:7344/64"); BOOST_ASIO_CHECK(make_network_v6(a.c_str()).to_string() == a); BOOST_ASIO_CHECK(network_v6(make_address_v6("2001:370::10:7344"), 27).to_string() == std::string("2001:370::10:7344/27")); // return host part BOOST_ASIO_CHECK(make_network_v6("2001:370::10:7344/64").address() == make_address_v6("2001:370::10:7344")); BOOST_ASIO_CHECK(make_network_v6("2001:370::10:7344/27").address().to_string() == "2001:370::10:7344"); // return network in CIDR notation BOOST_ASIO_CHECK(make_network_v6("2001:370::10:7344/27").canonical().to_string() == "2001:360::/27"); // is host BOOST_ASIO_CHECK(make_network_v6("2001:370::10:7344/128").is_host()); BOOST_ASIO_CHECK(!make_network_v6("2001:370::10:7344/127").is_host()); // is real subnet of BOOST_ASIO_CHECK(make_network_v6("2001:370::10:3744/64").is_subnet_of(make_network_v6("2001:370::/16"))); BOOST_ASIO_CHECK(make_network_v6("2001:370::/64").is_subnet_of(make_network_v6("2001:370::/16"))); BOOST_ASIO_CHECK(make_network_v6("2001:0db8:85a3::/64").is_subnet_of(make_network_v6("2001:0d00::/24"))); BOOST_ASIO_CHECK(!make_network_v6("2001:370::10:3744/128").is_subnet_of(make_network_v6("2001:370::10:3744/128"))); BOOST_ASIO_CHECK(make_network_v6("2001:0db8:85a3::/64").is_subnet_of(make_network_v6("2001:0dc0::/24"))); network_v6 r(make_network_v6("2001:370::/64")); BOOST_ASIO_CHECK(!r.is_subnet_of(r)); network_v6 net12(make_network_v6("2001:370::10:7344/64")); network_v6 net13(make_network_v6("2001:0db8::/127")); network_v6 net14(make_network_v6("2001:0db8::/125")); network_v6 net15(make_network_v6("2001:0db8::/119")); // network BOOST_ASIO_CHECK(net12.network() == make_address_v6("2001:370::")); BOOST_ASIO_CHECK(net13.network() == make_address_v6("2001:0db8::")); BOOST_ASIO_CHECK(net14.network() == make_address_v6("2001:0db8::")); BOOST_ASIO_CHECK(net15.network() == make_address_v6("2001:0db8::")); // iterator //BOOST_ASIO_CHECK(std::distance(net12.hosts().begin(),net12.hosts().end()) == 18446744073709552000); BOOST_ASIO_CHECK(std::distance(net13.hosts().begin(),net13.hosts().end()) == 2); BOOST_ASIO_CHECK(std::distance(net14.hosts().begin(),net14.hosts().end()) == 8); BOOST_ASIO_CHECK(std::distance(net15.hosts().begin(),net15.hosts().end()) == 512); BOOST_ASIO_CHECK(*net12.hosts().begin() == make_address_v6("2001:0370::")); BOOST_ASIO_CHECK(net12.hosts().end() != net12.hosts().find(make_address_v6("2001:0370::ffff:ffff:ffff:ffff"))); BOOST_ASIO_CHECK(*net13.hosts().begin() == make_address_v6("2001:0db8::")); BOOST_ASIO_CHECK(net13.hosts().end() != net13.hosts().find(make_address_v6("2001:0db8::1"))); BOOST_ASIO_CHECK(net13.hosts().end() == net13.hosts().find(make_address_v6("2001:0db8::2"))); BOOST_ASIO_CHECK(*net14.hosts().begin() == make_address_v6("2001:0db8::")); BOOST_ASIO_CHECK(net14.hosts().end() != net14.hosts().find(make_address_v6("2001:0db8::7"))); BOOST_ASIO_CHECK(net14.hosts().end() == net14.hosts().find(make_address_v6("2001:0db8::8"))); BOOST_ASIO_CHECK(*net15.hosts().begin() == make_address_v6("2001:0db8::")); BOOST_ASIO_CHECK(net15.hosts().end() != net15.hosts().find(make_address_v6("2001:0db8::01ff"))); BOOST_ASIO_CHECK(net15.hosts().end() == net15.hosts().find(make_address_v6("2001:0db8::0200"))); } } // namespace ip_network_v6_runtime //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/network_v6", BOOST_ASIO_COMPILE_TEST_CASE(ip_network_v6_compile::test) BOOST_ASIO_TEST_CASE(ip_network_v6_runtime::test) )
cpp
asio
data/projects/asio/test/ip/tcp.cpp
// // tcp.cpp // ~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Enable cancel() support on Windows. #define BOOST_ASIO_ENABLE_CANCELIO 1 // Test that header file is self-contained. #include <boost/asio/ip/tcp.hpp> #include <cstring> #include <functional> #include <boost/asio/io_context.hpp> #include <boost/asio/read.hpp> #include <boost/asio/write.hpp> #include "../unit_test.hpp" #include "../archetypes/async_result.hpp" #include "../archetypes/gettable_socket_option.hpp" #include "../archetypes/io_control_command.hpp" #include "../archetypes/settable_socket_option.hpp" #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) # include <boost/array.hpp> #else // defined(BOOST_ASIO_HAS_BOOST_ARRAY) # include <array> #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) //------------------------------------------------------------------------------ // ip_tcp_compile test // ~~~~~~~~~~~~~~~~~~~ // The following test checks that all nested classes, enums and constants in // ip::tcp compile and link correctly. Runtime failures are ignored. namespace ip_tcp_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; ip::tcp::socket sock(ioc); // no_delay class. ip::tcp::no_delay no_delay1(true); sock.set_option(no_delay1); ip::tcp::no_delay no_delay2; sock.get_option(no_delay2); no_delay1 = true; (void)static_cast<bool>(no_delay1); (void)static_cast<bool>(!no_delay1); (void)static_cast<bool>(no_delay1.value()); ip::tcp::endpoint ep; (void)static_cast<std::size_t>(std::hash<ip::tcp::endpoint>()(ep)); } catch (std::exception&) { } } } // namespace ip_tcp_compile //------------------------------------------------------------------------------ // ip_tcp_runtime test // ~~~~~~~~~~~~~~~~~~~ // The following test checks the runtime operation of the ip::tcp class. namespace ip_tcp_runtime { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; io_context ioc; ip::tcp::socket sock(ioc, ip::tcp::v4()); boost::system::error_code ec; // no_delay class. ip::tcp::no_delay no_delay1(true); BOOST_ASIO_CHECK(no_delay1.value()); BOOST_ASIO_CHECK(static_cast<bool>(no_delay1)); BOOST_ASIO_CHECK(!!no_delay1); sock.set_option(no_delay1, ec); BOOST_ASIO_CHECK(!ec); ip::tcp::no_delay no_delay2; sock.get_option(no_delay2, ec); BOOST_ASIO_CHECK(!ec); BOOST_ASIO_CHECK(no_delay2.value()); BOOST_ASIO_CHECK(static_cast<bool>(no_delay2)); BOOST_ASIO_CHECK(!!no_delay2); ip::tcp::no_delay no_delay3(false); BOOST_ASIO_CHECK(!no_delay3.value()); BOOST_ASIO_CHECK(!static_cast<bool>(no_delay3)); BOOST_ASIO_CHECK(!no_delay3); sock.set_option(no_delay3, ec); BOOST_ASIO_CHECK(!ec); ip::tcp::no_delay no_delay4; sock.get_option(no_delay4, ec); BOOST_ASIO_CHECK(!ec); BOOST_ASIO_CHECK(!no_delay4.value()); BOOST_ASIO_CHECK(!static_cast<bool>(no_delay4)); BOOST_ASIO_CHECK(!no_delay4); } } // namespace ip_tcp_runtime //------------------------------------------------------------------------------ // ip_tcp_socket_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::tcp::socket compile and link correctly. Runtime failures are ignored. namespace ip_tcp_socket_compile { struct connect_handler { connect_handler() {} void operator()(const boost::system::error_code&) {} connect_handler(connect_handler&&) {} private: connect_handler(const connect_handler&); }; struct wait_handler { wait_handler() {} void operator()(const boost::system::error_code&) {} wait_handler(wait_handler&&) {} private: wait_handler(const wait_handler&); }; struct send_handler { send_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} send_handler(send_handler&&) {} private: send_handler(const send_handler&); }; struct receive_handler { receive_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} receive_handler(receive_handler&&) {} private: receive_handler(const receive_handler&); }; struct write_some_handler { write_some_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} write_some_handler(write_some_handler&&) {} private: write_some_handler(const write_some_handler&); }; struct read_some_handler { read_some_handler() {} void operator()(const boost::system::error_code&, std::size_t) {} read_some_handler(read_some_handler&&) {} private: read_some_handler(const read_some_handler&); }; void test() { #if defined(BOOST_ASIO_HAS_BOOST_ARRAY) using boost::array; #else // defined(BOOST_ASIO_HAS_BOOST_ARRAY) using std::array; #endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY) using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); char mutable_char_buffer[128] = ""; const char const_char_buffer[128] = ""; array<boost::asio::mutable_buffer, 2> mutable_buffers = {{ boost::asio::buffer(mutable_char_buffer, 10), boost::asio::buffer(mutable_char_buffer + 10, 10) }}; array<boost::asio::const_buffer, 2> const_buffers = {{ boost::asio::buffer(const_char_buffer, 10), boost::asio::buffer(const_char_buffer + 10, 10) }}; socket_base::message_flags in_flags = 0; archetypes::settable_socket_option<void> settable_socket_option1; archetypes::settable_socket_option<int> settable_socket_option2; archetypes::settable_socket_option<double> settable_socket_option3; archetypes::gettable_socket_option<void> gettable_socket_option1; archetypes::gettable_socket_option<int> gettable_socket_option2; archetypes::gettable_socket_option<double> gettable_socket_option3; archetypes::io_control_command io_control_command; archetypes::immediate_handler immediate; archetypes::lazy_handler lazy; boost::system::error_code ec; // basic_stream_socket constructors. ip::tcp::socket socket1(ioc); ip::tcp::socket socket2(ioc, ip::tcp::v4()); ip::tcp::socket socket3(ioc, ip::tcp::v6()); ip::tcp::socket socket4(ioc, ip::tcp::endpoint(ip::tcp::v4(), 0)); ip::tcp::socket socket5(ioc, ip::tcp::endpoint(ip::tcp::v6(), 0)); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::tcp::socket::native_handle_type native_socket1 = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); ip::tcp::socket socket6(ioc, ip::tcp::v4(), native_socket1); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::tcp::socket socket7(ioc_ex); ip::tcp::socket socket8(ioc_ex, ip::tcp::v4()); ip::tcp::socket socket9(ioc_ex, ip::tcp::v6()); ip::tcp::socket socket10(ioc_ex, ip::tcp::endpoint(ip::tcp::v4(), 0)); ip::tcp::socket socket11(ioc_ex, ip::tcp::endpoint(ip::tcp::v6(), 0)); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::tcp::socket::native_handle_type native_socket2 = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); ip::tcp::socket socket12(ioc_ex, ip::tcp::v4(), native_socket2); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::tcp::socket socket13(std::move(socket5)); // basic_stream_socket operators. socket1 = ip::tcp::socket(ioc); socket1 = std::move(socket2); // basic_io_object functions. ip::tcp::socket::executor_type ex = socket1.get_executor(); (void)ex; // basic_socket functions. ip::tcp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer(); (void)lowest_layer; const ip::tcp::socket& socket14 = socket1; const ip::tcp::socket::lowest_layer_type& lowest_layer2 = socket14.lowest_layer(); (void)lowest_layer2; socket1.open(ip::tcp::v4()); socket1.open(ip::tcp::v6()); socket1.open(ip::tcp::v4(), ec); socket1.open(ip::tcp::v6(), ec); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::tcp::socket::native_handle_type native_socket3 = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); socket1.assign(ip::tcp::v4(), native_socket3); ip::tcp::socket::native_handle_type native_socket4 = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); socket1.assign(ip::tcp::v4(), native_socket4, ec); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) bool is_open = socket1.is_open(); (void)is_open; socket1.close(); socket1.close(ec); socket1.release(); socket1.release(ec); ip::tcp::socket::native_handle_type native_socket5 = socket1.native_handle(); (void)native_socket5; socket1.cancel(); socket1.cancel(ec); bool at_mark1 = socket1.at_mark(); (void)at_mark1; bool at_mark2 = socket1.at_mark(ec); (void)at_mark2; std::size_t available1 = socket1.available(); (void)available1; std::size_t available2 = socket1.available(ec); (void)available2; socket1.bind(ip::tcp::endpoint(ip::tcp::v4(), 0)); socket1.bind(ip::tcp::endpoint(ip::tcp::v6(), 0)); socket1.bind(ip::tcp::endpoint(ip::tcp::v4(), 0), ec); socket1.bind(ip::tcp::endpoint(ip::tcp::v6(), 0), ec); socket1.connect(ip::tcp::endpoint(ip::tcp::v4(), 0)); socket1.connect(ip::tcp::endpoint(ip::tcp::v6(), 0)); socket1.connect(ip::tcp::endpoint(ip::tcp::v4(), 0), ec); socket1.connect(ip::tcp::endpoint(ip::tcp::v6(), 0), ec); socket1.async_connect(ip::tcp::endpoint(ip::tcp::v4(), 0), connect_handler()); socket1.async_connect(ip::tcp::endpoint(ip::tcp::v6(), 0), connect_handler()); socket1.async_connect(ip::tcp::endpoint(ip::tcp::v4(), 0), immediate); socket1.async_connect(ip::tcp::endpoint(ip::tcp::v6(), 0), immediate); int i1 = socket1.async_connect(ip::tcp::endpoint(ip::tcp::v4(), 0), lazy); (void)i1; int i2 = socket1.async_connect(ip::tcp::endpoint(ip::tcp::v6(), 0), lazy); (void)i2; socket1.set_option(settable_socket_option1); socket1.set_option(settable_socket_option1, ec); socket1.set_option(settable_socket_option2); socket1.set_option(settable_socket_option2, ec); socket1.set_option(settable_socket_option3); socket1.set_option(settable_socket_option3, ec); socket1.get_option(gettable_socket_option1); socket1.get_option(gettable_socket_option1, ec); socket1.get_option(gettable_socket_option2); socket1.get_option(gettable_socket_option2, ec); socket1.get_option(gettable_socket_option3); socket1.get_option(gettable_socket_option3, ec); socket1.io_control(io_control_command); socket1.io_control(io_control_command, ec); bool non_blocking1 = socket1.non_blocking(); (void)non_blocking1; socket1.non_blocking(true); socket1.non_blocking(false, ec); bool non_blocking2 = socket1.native_non_blocking(); (void)non_blocking2; socket1.native_non_blocking(true); socket1.native_non_blocking(false, ec); ip::tcp::endpoint endpoint1 = socket1.local_endpoint(); (void)endpoint1; ip::tcp::endpoint endpoint2 = socket1.local_endpoint(ec); (void)endpoint2; ip::tcp::endpoint endpoint3 = socket1.remote_endpoint(); (void)endpoint3; ip::tcp::endpoint endpoint4 = socket1.remote_endpoint(ec); (void)endpoint4; socket1.shutdown(socket_base::shutdown_both); socket1.shutdown(socket_base::shutdown_both, ec); socket1.wait(socket_base::wait_read); socket1.wait(socket_base::wait_write, ec); socket1.async_wait(socket_base::wait_read, wait_handler()); socket1.async_wait(socket_base::wait_read, immediate); int i3 = socket1.async_wait(socket_base::wait_write, lazy); (void)i3; // basic_stream_socket functions. socket1.send(buffer(mutable_char_buffer)); socket1.send(buffer(const_char_buffer)); socket1.send(mutable_buffers); socket1.send(const_buffers); socket1.send(null_buffers()); socket1.send(buffer(mutable_char_buffer), in_flags); socket1.send(buffer(const_char_buffer), in_flags); socket1.send(mutable_buffers, in_flags); socket1.send(const_buffers, in_flags); socket1.send(null_buffers(), in_flags); socket1.send(buffer(mutable_char_buffer), in_flags, ec); socket1.send(buffer(const_char_buffer), in_flags, ec); socket1.send(mutable_buffers, in_flags, ec); socket1.send(const_buffers, in_flags, ec); socket1.send(null_buffers(), in_flags, ec); socket1.async_send(buffer(mutable_char_buffer), send_handler()); socket1.async_send(buffer(const_char_buffer), send_handler()); socket1.async_send(mutable_buffers, send_handler()); socket1.async_send(const_buffers, send_handler()); socket1.async_send(null_buffers(), send_handler()); socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler()); socket1.async_send(buffer(const_char_buffer), in_flags, send_handler()); socket1.async_send(mutable_buffers, in_flags, send_handler()); socket1.async_send(const_buffers, in_flags, send_handler()); socket1.async_send(null_buffers(), in_flags, send_handler()); socket1.async_send(buffer(mutable_char_buffer), immediate); socket1.async_send(buffer(const_char_buffer), immediate); socket1.async_send(mutable_buffers, immediate); socket1.async_send(const_buffers, immediate); socket1.async_send(null_buffers(), immediate); socket1.async_send(buffer(mutable_char_buffer), in_flags, immediate); socket1.async_send(buffer(const_char_buffer), in_flags, immediate); socket1.async_send(mutable_buffers, in_flags, immediate); socket1.async_send(const_buffers, in_flags, immediate); socket1.async_send(null_buffers(), in_flags, immediate); int i4 = socket1.async_send(buffer(mutable_char_buffer), lazy); (void)i4; int i5 = socket1.async_send(buffer(const_char_buffer), lazy); (void)i5; int i6 = socket1.async_send(mutable_buffers, lazy); (void)i6; int i7 = socket1.async_send(const_buffers, lazy); (void)i7; int i8 = socket1.async_send(null_buffers(), lazy); (void)i8; int i9 = socket1.async_send(buffer(mutable_char_buffer), in_flags, lazy); (void)i9; int i10 = socket1.async_send(buffer(const_char_buffer), in_flags, lazy); (void)i10; int i11 = socket1.async_send(mutable_buffers, in_flags, lazy); (void)i11; int i12 = socket1.async_send(const_buffers, in_flags, lazy); (void)i12; int i13 = socket1.async_send(null_buffers(), in_flags, lazy); (void)i13; socket1.receive(buffer(mutable_char_buffer)); socket1.receive(mutable_buffers); socket1.receive(null_buffers()); socket1.receive(buffer(mutable_char_buffer), in_flags); socket1.receive(mutable_buffers, in_flags); socket1.receive(null_buffers(), in_flags); socket1.receive(buffer(mutable_char_buffer), in_flags, ec); socket1.receive(mutable_buffers, in_flags, ec); socket1.receive(null_buffers(), in_flags, ec); socket1.async_receive(buffer(mutable_char_buffer), receive_handler()); socket1.async_receive(mutable_buffers, receive_handler()); socket1.async_receive(null_buffers(), receive_handler()); socket1.async_receive(buffer(mutable_char_buffer), in_flags, receive_handler()); socket1.async_receive(mutable_buffers, in_flags, receive_handler()); socket1.async_receive(null_buffers(), in_flags, receive_handler()); socket1.async_receive(buffer(mutable_char_buffer), immediate); socket1.async_receive(mutable_buffers, immediate); socket1.async_receive(null_buffers(), immediate); socket1.async_receive(buffer(mutable_char_buffer), in_flags, immediate); socket1.async_receive(mutable_buffers, in_flags, immediate); socket1.async_receive(null_buffers(), in_flags, immediate); int i14 = socket1.async_receive(buffer(mutable_char_buffer), lazy); (void)i14; int i15 = socket1.async_receive(mutable_buffers, lazy); (void)i15; int i16 = socket1.async_receive(null_buffers(), lazy); (void)i16; int i17 = socket1.async_receive(buffer(mutable_char_buffer), in_flags, lazy); (void)i17; int i18 = socket1.async_receive(mutable_buffers, in_flags, lazy); (void)i18; int i19 = socket1.async_receive(null_buffers(), in_flags, lazy); (void)i19; socket1.write_some(buffer(mutable_char_buffer)); socket1.write_some(buffer(const_char_buffer)); socket1.write_some(mutable_buffers); socket1.write_some(const_buffers); socket1.write_some(null_buffers()); socket1.write_some(buffer(mutable_char_buffer), ec); socket1.write_some(buffer(const_char_buffer), ec); socket1.write_some(mutable_buffers, ec); socket1.write_some(const_buffers, ec); socket1.write_some(null_buffers(), ec); socket1.async_write_some(buffer(mutable_char_buffer), write_some_handler()); socket1.async_write_some(buffer(const_char_buffer), write_some_handler()); socket1.async_write_some(mutable_buffers, write_some_handler()); socket1.async_write_some(const_buffers, write_some_handler()); socket1.async_write_some(null_buffers(), write_some_handler()); socket1.async_write_some(buffer(mutable_char_buffer), immediate); socket1.async_write_some(buffer(const_char_buffer), immediate); socket1.async_write_some(mutable_buffers, immediate); socket1.async_write_some(const_buffers, immediate); socket1.async_write_some(null_buffers(), immediate); int i20 = socket1.async_write_some(buffer(mutable_char_buffer), lazy); (void)i20; int i21 = socket1.async_write_some(buffer(const_char_buffer), lazy); (void)i21; int i22 = socket1.async_write_some(mutable_buffers, lazy); (void)i22; int i23 = socket1.async_write_some(const_buffers, lazy); (void)i23; int i24 = socket1.async_write_some(null_buffers(), lazy); (void)i24; socket1.read_some(buffer(mutable_char_buffer)); socket1.read_some(mutable_buffers); socket1.read_some(null_buffers()); socket1.read_some(buffer(mutable_char_buffer), ec); socket1.read_some(mutable_buffers, ec); socket1.read_some(null_buffers(), ec); socket1.async_read_some(buffer(mutable_char_buffer), read_some_handler()); socket1.async_read_some(mutable_buffers, read_some_handler()); socket1.async_read_some(null_buffers(), read_some_handler()); socket1.async_read_some(buffer(mutable_char_buffer), immediate); socket1.async_read_some(mutable_buffers, immediate); socket1.async_read_some(null_buffers(), immediate); int i25 = socket1.async_read_some(buffer(mutable_char_buffer), lazy); (void)i25; int i26 = socket1.async_read_some(mutable_buffers, lazy); (void)i26; int i27 = socket1.async_read_some(null_buffers(), lazy); (void)i27; } catch (std::exception&) { } } } // namespace ip_tcp_socket_compile //------------------------------------------------------------------------------ // ip_tcp_socket_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks the runtime operation of the ip::tcp::socket class. namespace ip_tcp_socket_runtime { static const char write_data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; void handle_read_noop(const boost::system::error_code& err, size_t bytes_transferred, bool* called) { *called = true; BOOST_ASIO_CHECK(!err); BOOST_ASIO_CHECK(bytes_transferred == 0); } void handle_write_noop(const boost::system::error_code& err, size_t bytes_transferred, bool* called) { *called = true; BOOST_ASIO_CHECK(!err); BOOST_ASIO_CHECK(bytes_transferred == 0); } void handle_read(const boost::system::error_code& err, size_t bytes_transferred, bool* called) { *called = true; BOOST_ASIO_CHECK(!err); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); } void handle_write(const boost::system::error_code& err, size_t bytes_transferred, bool* called) { *called = true; BOOST_ASIO_CHECK(!err); BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data)); } void handle_read_cancel(const boost::system::error_code& err, size_t bytes_transferred, bool* called) { *called = true; BOOST_ASIO_CHECK(err == boost::asio::error::operation_aborted); BOOST_ASIO_CHECK(bytes_transferred == 0); } void handle_read_eof(const boost::system::error_code& err, size_t bytes_transferred, bool* called) { *called = true; BOOST_ASIO_CHECK(err == boost::asio::error::eof); BOOST_ASIO_CHECK(bytes_transferred == 0); } void test() { using namespace std; // For memcmp. using namespace boost::asio; namespace ip = boost::asio::ip; namespace bindns = std; using bindns::placeholders::_1; using bindns::placeholders::_2; io_context ioc; ip::tcp::acceptor acceptor(ioc, ip::tcp::endpoint(ip::tcp::v4(), 0)); ip::tcp::endpoint server_endpoint = acceptor.local_endpoint(); server_endpoint.address(ip::address_v4::loopback()); ip::tcp::socket client_side_socket(ioc); ip::tcp::socket server_side_socket(ioc); client_side_socket.connect(server_endpoint); acceptor.accept(server_side_socket); // No-op read. bool read_noop_completed = false; client_side_socket.async_read_some( boost::asio::mutable_buffer(0, 0), bindns::bind(handle_read_noop, _1, _2, &read_noop_completed)); ioc.run(); BOOST_ASIO_CHECK(read_noop_completed); // No-op write. bool write_noop_completed = false; client_side_socket.async_write_some( boost::asio::const_buffer(0, 0), bindns::bind(handle_write_noop, _1, _2, &write_noop_completed)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(write_noop_completed); // Read and write to transfer data. char read_buffer[sizeof(write_data)]; bool read_completed = false; boost::asio::async_read(client_side_socket, boost::asio::buffer(read_buffer), bindns::bind(handle_read, _1, _2, &read_completed)); bool write_completed = false; boost::asio::async_write(server_side_socket, boost::asio::buffer(write_data), bindns::bind(handle_write, _1, _2, &write_completed)); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(read_completed); BOOST_ASIO_CHECK(write_completed); BOOST_ASIO_CHECK(memcmp(read_buffer, write_data, sizeof(write_data)) == 0); // Cancelled read. bool read_cancel_completed = false; boost::asio::async_read(server_side_socket, boost::asio::buffer(read_buffer), bindns::bind(handle_read_cancel, _1, _2, &read_cancel_completed)); ioc.restart(); ioc.poll(); BOOST_ASIO_CHECK(!read_cancel_completed); server_side_socket.cancel(); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(read_cancel_completed); // A read when the peer closes socket should fail with eof. bool read_eof_completed = false; boost::asio::async_read(client_side_socket, boost::asio::buffer(read_buffer), bindns::bind(handle_read_eof, _1, _2, &read_eof_completed)); server_side_socket.close(); ioc.restart(); ioc.run(); BOOST_ASIO_CHECK(read_eof_completed); } } // namespace ip_tcp_socket_runtime //------------------------------------------------------------------------------ // ip_tcp_acceptor_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::tcp::acceptor compile and link correctly. Runtime failures are ignored. namespace ip_tcp_acceptor_compile { struct wait_handler { wait_handler() {} void operator()(const boost::system::error_code&) {} wait_handler(wait_handler&&) {} private: wait_handler(const wait_handler&); }; struct accept_handler { accept_handler() {} void operator()(const boost::system::error_code&) {} accept_handler(accept_handler&&) {} private: accept_handler(const accept_handler&); }; struct move_accept_handler { move_accept_handler() {} void operator()( const boost::system::error_code&, boost::asio::ip::tcp::socket) {} move_accept_handler(move_accept_handler&&) {} private: move_accept_handler(const move_accept_handler&) {} }; struct move_accept_ioc_handler { move_accept_ioc_handler() {} void operator()(const boost::system::error_code&, boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::io_context::executor_type>) {} move_accept_ioc_handler(move_accept_handler&&) {} private: move_accept_ioc_handler(const move_accept_handler&) {} }; void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); ip::tcp::socket peer_socket1(ioc); boost::asio::basic_stream_socket<ip::tcp, io_context::executor_type> peer_socket2(ioc); ip::tcp::endpoint peer_endpoint; archetypes::settable_socket_option<void> settable_socket_option1; archetypes::settable_socket_option<int> settable_socket_option2; archetypes::settable_socket_option<double> settable_socket_option3; archetypes::gettable_socket_option<void> gettable_socket_option1; archetypes::gettable_socket_option<int> gettable_socket_option2; archetypes::gettable_socket_option<double> gettable_socket_option3; archetypes::io_control_command io_control_command; archetypes::immediate_handler immediate; archetypes::lazy_handler lazy; boost::system::error_code ec; // basic_socket_acceptor constructors. ip::tcp::acceptor acceptor1(ioc); ip::tcp::acceptor acceptor2(ioc, ip::tcp::v4()); ip::tcp::acceptor acceptor3(ioc, ip::tcp::v6()); ip::tcp::acceptor acceptor4(ioc, ip::tcp::endpoint(ip::tcp::v4(), 0)); ip::tcp::acceptor acceptor5(ioc, ip::tcp::endpoint(ip::tcp::v6(), 0)); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::tcp::acceptor::native_handle_type native_acceptor1 = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); ip::tcp::acceptor acceptor6(ioc, ip::tcp::v4(), native_acceptor1); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::tcp::acceptor acceptor7(ioc_ex); ip::tcp::acceptor acceptor8(ioc_ex, ip::tcp::v4()); ip::tcp::acceptor acceptor9(ioc_ex, ip::tcp::v6()); ip::tcp::acceptor acceptor10(ioc_ex, ip::tcp::endpoint(ip::tcp::v4(), 0)); ip::tcp::acceptor acceptor11(ioc_ex, ip::tcp::endpoint(ip::tcp::v6(), 0)); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::tcp::acceptor::native_handle_type native_acceptor2 = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); ip::tcp::acceptor acceptor12(ioc_ex, ip::tcp::v4(), native_acceptor2); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::tcp::acceptor acceptor13(std::move(acceptor5)); // basic_socket_acceptor operators. acceptor1 = ip::tcp::acceptor(ioc); acceptor1 = std::move(acceptor2); // basic_io_object functions. ip::tcp::acceptor::executor_type ex = acceptor1.get_executor(); (void)ex; // basic_socket_acceptor functions. acceptor1.open(ip::tcp::v4()); acceptor1.open(ip::tcp::v6()); acceptor1.open(ip::tcp::v4(), ec); acceptor1.open(ip::tcp::v6(), ec); #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) ip::tcp::acceptor::native_handle_type native_acceptor3 = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); acceptor1.assign(ip::tcp::v4(), native_acceptor3); ip::tcp::acceptor::native_handle_type native_acceptor4 = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); acceptor1.assign(ip::tcp::v4(), native_acceptor4, ec); #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) bool is_open = acceptor1.is_open(); (void)is_open; acceptor1.close(); acceptor1.close(ec); acceptor1.release(); acceptor1.release(ec); ip::tcp::acceptor::native_handle_type native_acceptor5 = acceptor1.native_handle(); (void)native_acceptor5; acceptor1.cancel(); acceptor1.cancel(ec); acceptor1.bind(ip::tcp::endpoint(ip::tcp::v4(), 0)); acceptor1.bind(ip::tcp::endpoint(ip::tcp::v6(), 0)); acceptor1.bind(ip::tcp::endpoint(ip::tcp::v4(), 0), ec); acceptor1.bind(ip::tcp::endpoint(ip::tcp::v6(), 0), ec); acceptor1.set_option(settable_socket_option1); acceptor1.set_option(settable_socket_option1, ec); acceptor1.set_option(settable_socket_option2); acceptor1.set_option(settable_socket_option2, ec); acceptor1.set_option(settable_socket_option3); acceptor1.set_option(settable_socket_option3, ec); acceptor1.get_option(gettable_socket_option1); acceptor1.get_option(gettable_socket_option1, ec); acceptor1.get_option(gettable_socket_option2); acceptor1.get_option(gettable_socket_option2, ec); acceptor1.get_option(gettable_socket_option3); acceptor1.get_option(gettable_socket_option3, ec); acceptor1.io_control(io_control_command); acceptor1.io_control(io_control_command, ec); bool non_blocking1 = acceptor1.non_blocking(); (void)non_blocking1; acceptor1.non_blocking(true); acceptor1.non_blocking(false, ec); bool non_blocking2 = acceptor1.native_non_blocking(); (void)non_blocking2; acceptor1.native_non_blocking(true); acceptor1.native_non_blocking(false, ec); ip::tcp::endpoint endpoint1 = acceptor1.local_endpoint(); (void)endpoint1; ip::tcp::endpoint endpoint2 = acceptor1.local_endpoint(ec); (void)endpoint2; acceptor1.wait(socket_base::wait_read); acceptor1.wait(socket_base::wait_write, ec); acceptor1.async_wait(socket_base::wait_read, wait_handler()); acceptor1.async_wait(socket_base::wait_read, immediate); int i1 = acceptor1.async_wait(socket_base::wait_write, lazy); (void)i1; acceptor1.accept(peer_socket1); acceptor1.accept(peer_socket1, ec); acceptor1.accept(peer_socket1, peer_endpoint); acceptor1.accept(peer_socket1, peer_endpoint, ec); acceptor1.accept(peer_socket2); acceptor1.accept(peer_socket2, ec); acceptor1.accept(peer_socket2, peer_endpoint); acceptor1.accept(peer_socket2, peer_endpoint, ec); peer_socket1 = acceptor1.accept(); peer_socket1 = acceptor1.accept(ioc); peer_socket1 = acceptor1.accept(ioc_ex); peer_socket1 = acceptor1.accept(peer_endpoint); peer_socket1 = acceptor1.accept(ioc, peer_endpoint); peer_socket1 = acceptor1.accept(ioc_ex, peer_endpoint); (void)peer_socket1; peer_socket2 = acceptor1.accept(ioc); peer_socket2 = acceptor1.accept(ioc_ex); peer_socket2 = acceptor1.accept(ioc, peer_endpoint); peer_socket2 = acceptor1.accept(ioc_ex, peer_endpoint); (void)peer_socket2; acceptor1.async_accept(peer_socket1, accept_handler()); acceptor1.async_accept(peer_socket1, peer_endpoint, accept_handler()); acceptor1.async_accept(peer_socket1, immediate); acceptor1.async_accept(peer_socket1, peer_endpoint, immediate); int i2 = acceptor1.async_accept(peer_socket1, lazy); (void)i2; int i3 = acceptor1.async_accept(peer_socket1, peer_endpoint, lazy); (void)i3; acceptor1.async_accept(peer_socket2, accept_handler()); acceptor1.async_accept(peer_socket2, peer_endpoint, accept_handler()); acceptor1.async_accept(peer_socket2, immediate); acceptor1.async_accept(peer_socket2, peer_endpoint, immediate); int i4 = acceptor1.async_accept(peer_socket2, lazy); (void)i4; int i5 = acceptor1.async_accept(peer_socket2, peer_endpoint, lazy); (void)i5; acceptor1.async_accept(move_accept_handler()); acceptor1.async_accept(ioc, move_accept_handler()); acceptor1.async_accept(ioc_ex, move_accept_handler()); acceptor1.async_accept(ioc_ex, move_accept_ioc_handler()); acceptor1.async_accept(peer_endpoint, move_accept_handler()); acceptor1.async_accept(ioc, peer_endpoint, move_accept_handler()); acceptor1.async_accept(ioc_ex, peer_endpoint, move_accept_handler()); acceptor1.async_accept(ioc_ex, peer_endpoint, move_accept_ioc_handler()); acceptor1.async_accept(immediate); acceptor1.async_accept(ioc, immediate); acceptor1.async_accept(ioc_ex, immediate); acceptor1.async_accept(peer_endpoint, immediate); acceptor1.async_accept(ioc, peer_endpoint, immediate); acceptor1.async_accept(ioc_ex, peer_endpoint, immediate); } catch (std::exception&) { } } } // namespace ip_tcp_acceptor_compile //------------------------------------------------------------------------------ // ip_tcp_acceptor_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks the runtime operation of the ip::tcp::acceptor // class. namespace ip_tcp_acceptor_runtime { void handle_accept(const boost::system::error_code& err) { BOOST_ASIO_CHECK(!err); } void handle_connect(const boost::system::error_code& err) { BOOST_ASIO_CHECK(!err); } void test() { using namespace boost::asio; namespace ip = boost::asio::ip; io_context ioc; ip::tcp::acceptor acceptor(ioc, ip::tcp::endpoint(ip::tcp::v4(), 0)); ip::tcp::endpoint server_endpoint = acceptor.local_endpoint(); server_endpoint.address(ip::address_v4::loopback()); ip::tcp::socket client_side_socket(ioc); ip::tcp::socket server_side_socket(ioc); client_side_socket.connect(server_endpoint); acceptor.accept(server_side_socket); client_side_socket.close(); server_side_socket.close(); client_side_socket.connect(server_endpoint); ip::tcp::endpoint client_endpoint; acceptor.accept(server_side_socket, client_endpoint); ip::tcp::endpoint client_side_local_endpoint = client_side_socket.local_endpoint(); BOOST_ASIO_CHECK(client_side_local_endpoint.port() == client_endpoint.port()); ip::tcp::endpoint server_side_remote_endpoint = server_side_socket.remote_endpoint(); BOOST_ASIO_CHECK(server_side_remote_endpoint.port() == client_endpoint.port()); client_side_socket.close(); server_side_socket.close(); acceptor.async_accept(server_side_socket, &handle_accept); client_side_socket.async_connect(server_endpoint, &handle_connect); ioc.run(); client_side_socket.close(); server_side_socket.close(); acceptor.async_accept(server_side_socket, client_endpoint, &handle_accept); client_side_socket.async_connect(server_endpoint, &handle_connect); ioc.restart(); ioc.run(); client_side_local_endpoint = client_side_socket.local_endpoint(); BOOST_ASIO_CHECK(client_side_local_endpoint.port() == client_endpoint.port()); server_side_remote_endpoint = server_side_socket.remote_endpoint(); BOOST_ASIO_CHECK(server_side_remote_endpoint.port() == client_endpoint.port()); } } // namespace ip_tcp_acceptor_runtime //------------------------------------------------------------------------------ // ip_tcp_resolver_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::tcp::resolver compile and link correctly. Runtime failures are ignored. namespace ip_tcp_resolver_compile { struct resolve_handler { resolve_handler() {} void operator()(const boost::system::error_code&, boost::asio::ip::tcp::resolver::results_type) {} resolve_handler(resolve_handler&&) {} private: resolve_handler(const resolve_handler&); }; #if !defined(BOOST_ASIO_NO_DEPRECATED) struct legacy_resolve_handler { legacy_resolve_handler() {} void operator()(const boost::system::error_code&, boost::asio::ip::tcp::resolver::iterator) {} legacy_resolve_handler(legacy_resolve_handler&&) {} private: legacy_resolve_handler(const legacy_resolve_handler&); }; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); archetypes::lazy_handler lazy; boost::system::error_code ec; #if !defined(BOOST_ASIO_NO_DEPRECATED) ip::tcp::resolver::query q(ip::tcp::v4(), "localhost", "0"); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) ip::tcp::endpoint e(ip::address_v4::loopback(), 0); // basic_resolver constructors. ip::tcp::resolver resolver(ioc); ip::tcp::resolver resolver2(ioc_ex); ip::tcp::resolver resolver3(std::move(resolver)); // basic_resolver operators. resolver = ip::tcp::resolver(ioc); resolver = std::move(resolver3); // basic_io_object functions. ip::tcp::resolver::executor_type ex = resolver.get_executor(); (void)ex; // basic_resolver functions. resolver.cancel(); #if !defined(BOOST_ASIO_NO_DEPRECATED) ip::tcp::resolver::results_type results1 = resolver.resolve(q); (void)results1; ip::tcp::resolver::results_type results2 = resolver.resolve(q, ec); (void)results2; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) ip::tcp::resolver::results_type results3 = resolver.resolve("", ""); (void)results3; ip::tcp::resolver::results_type results4 = resolver.resolve("", "", ec); (void)results4; ip::tcp::resolver::results_type results5 = resolver.resolve("", "", ip::tcp::resolver::flags()); (void)results5; ip::tcp::resolver::results_type results6 = resolver.resolve("", "", ip::tcp::resolver::flags(), ec); (void)results6; ip::tcp::resolver::results_type results7 = resolver.resolve(ip::tcp::v4(), "", ""); (void)results7; ip::tcp::resolver::results_type results8 = resolver.resolve(ip::tcp::v4(), "", "", ec); (void)results8; ip::tcp::resolver::results_type results9 = resolver.resolve(ip::tcp::v4(), "", "", ip::tcp::resolver::flags()); (void)results9; ip::tcp::resolver::results_type results10 = resolver.resolve(ip::tcp::v4(), "", "", ip::tcp::resolver::flags(), ec); (void)results10; ip::tcp::resolver::results_type results11 = resolver.resolve(e); (void)results11; ip::tcp::resolver::results_type results12 = resolver.resolve(e, ec); (void)results12; #if !defined(BOOST_ASIO_NO_DEPRECATED) resolver.async_resolve(q, resolve_handler()); resolver.async_resolve(q, legacy_resolve_handler()); int i1 = resolver.async_resolve(q, lazy); (void)i1; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) resolver.async_resolve("", "", resolve_handler()); #if !defined(BOOST_ASIO_NO_DEPRECATED) resolver.async_resolve("", "", legacy_resolve_handler()); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) int i2 = resolver.async_resolve("", "", lazy); (void)i2; resolver.async_resolve("", "", ip::tcp::resolver::flags(), resolve_handler()); #if !defined(BOOST_ASIO_NO_DEPRECATED) resolver.async_resolve("", "", ip::tcp::resolver::flags(), legacy_resolve_handler()); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) int i3 = resolver.async_resolve("", "", ip::tcp::resolver::flags(), lazy); (void)i3; resolver.async_resolve(ip::tcp::v4(), "", "", resolve_handler()); #if !defined(BOOST_ASIO_NO_DEPRECATED) resolver.async_resolve(ip::tcp::v4(), "", "", legacy_resolve_handler()); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) int i4 = resolver.async_resolve(ip::tcp::v4(), "", "", lazy); (void)i4; resolver.async_resolve(ip::tcp::v4(), "", "", ip::tcp::resolver::flags(), resolve_handler()); #if !defined(BOOST_ASIO_NO_DEPRECATED) resolver.async_resolve(ip::tcp::v4(), "", "", ip::tcp::resolver::flags(), legacy_resolve_handler()); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) int i5 = resolver.async_resolve(ip::tcp::v4(), "", "", ip::tcp::resolver::flags(), lazy); (void)i5; resolver.async_resolve(e, resolve_handler()); #if !defined(BOOST_ASIO_NO_DEPRECATED) resolver.async_resolve(e, legacy_resolve_handler()); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) int i6 = resolver.async_resolve(e, lazy); (void)i6; } catch (std::exception&) { } } } // namespace ip_tcp_resolver_compile //------------------------------------------------------------------------------ // ip_tcp_resolver_entry_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::tcp::resolver::entry compile and link correctly. Runtime failures are // ignored. namespace ip_tcp_resolver_entry_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; const ip::tcp::endpoint endpoint; const std::string host_name; const std::string service_name; const std::allocator<char> alloc; try { // basic_resolver_entry constructors. const ip::basic_resolver_entry<ip::tcp> entry1; ip::basic_resolver_entry<ip::tcp> entry2(endpoint, host_name, service_name); ip::basic_resolver_entry<ip::tcp> entry3(entry1); ip::basic_resolver_entry<ip::tcp> entry4(std::move(entry2)); // basic_resolver_entry functions. ip::tcp::endpoint e1 = entry1.endpoint(); (void)e1; ip::tcp::endpoint e2 = entry1; (void)e2; std::string s1 = entry1.host_name(); (void)s1; std::string s2 = entry1.host_name(alloc); (void)s2; std::string s3 = entry1.service_name(); (void)s3; std::string s4 = entry1.service_name(alloc); (void)s4; } catch (std::exception&) { } } } // namespace ip_tcp_resolver_entry_compile //------------------------------------------------------------------------------ // ip_tcp_iostream_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public types and member functions on the // class ip::tcp::iostream compile and link correctly. Runtime failures are // ignored. namespace ip_tcp_iostream_compile { void test() { #if !defined(BOOST_ASIO_NO_IOSTREAM) using namespace boost::asio; namespace ip = boost::asio::ip; boost::asio::io_context ioc; boost::asio::ip::tcp::socket sock(ioc); // basic_socket_iostream typedefs. (void)static_cast<ip::tcp::iostream::protocol_type*>(0); (void)static_cast<ip::tcp::iostream::endpoint_type*>(0); (void)static_cast<ip::tcp::iostream::clock_type*>(0); (void)static_cast<ip::tcp::iostream::time_point*>(0); (void)static_cast<ip::tcp::iostream::duration*>(0); (void)static_cast<ip::tcp::iostream::traits_type*>(0); // basic_socket_iostream constructors. ip::tcp::iostream ios1; ip::tcp::iostream ios2(std::move(sock)); ip::tcp::iostream ios3("hostname", "service"); // basic_socket_iostream operators. ios1 = ip::tcp::iostream(); ios2 = std::move(ios1); // basic_socket_iostream members. ios1.connect("hostname", "service"); ios1.close(); (void)static_cast<std::streambuf*>(ios1.rdbuf()); basic_socket<ip::tcp>& sref = ios1.socket(); (void)sref; boost::system::error_code ec = ios1.error(); (void)ec; ip::tcp::iostream::time_point tp = ios1.expiry(); (void)tp; ios1.expires_at(tp); ip::tcp::iostream::duration d = ip::tcp::iostream::duration(); ios1.expires_after(d); // iostream operators. int i = 0; ios1 >> i; ios1 << i; #endif // !defined(BOOST_ASIO_NO_IOSTREAM) } } // namespace ip_tcp_iostream_compile //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/tcp", BOOST_ASIO_COMPILE_TEST_CASE(ip_tcp_compile::test) BOOST_ASIO_TEST_CASE(ip_tcp_runtime::test) BOOST_ASIO_COMPILE_TEST_CASE(ip_tcp_socket_compile::test) BOOST_ASIO_TEST_CASE(ip_tcp_socket_runtime::test) BOOST_ASIO_COMPILE_TEST_CASE(ip_tcp_acceptor_compile::test) BOOST_ASIO_TEST_CASE(ip_tcp_acceptor_runtime::test) BOOST_ASIO_COMPILE_TEST_CASE(ip_tcp_resolver_compile::test) BOOST_ASIO_COMPILE_TEST_CASE(ip_tcp_resolver_entry_compile::test) BOOST_ASIO_COMPILE_TEST_CASE(ip_tcp_resolver_entry_compile::test) BOOST_ASIO_COMPILE_TEST_CASE(ip_tcp_iostream_compile::test) )
cpp
asio
data/projects/asio/test/ip/address_v4_iterator.cpp
// // address_v4_iterator.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/address_v4_iterator.hpp> #include "../unit_test.hpp" //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/address_v4_iterator", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/ip/address_v6.cpp
// // address_v6.cpp // ~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/address_v6.hpp> #include "../unit_test.hpp" #include <sstream> //------------------------------------------------------------------------------ // ip_address_v6_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // ip::address_v6 compile and link correctly. Runtime failures are ignored. namespace ip_address_v6_compile { void test() { using namespace boost::asio; namespace ip = boost::asio::ip; try { boost::system::error_code ec; // address_v6 constructors. ip::address_v6 addr1; const ip::address_v6::bytes_type const_bytes_value = { { 0 } }; ip::address_v6 addr2(const_bytes_value); // address_v6 functions. unsigned long scope_id = addr1.scope_id(); addr1.scope_id(scope_id); bool b = addr1.is_unspecified(); (void)b; b = addr1.is_loopback(); (void)b; b = addr1.is_multicast(); (void)b; b = addr1.is_link_local(); (void)b; b = addr1.is_site_local(); (void)b; b = addr1.is_v4_mapped(); (void)b; #if !defined(BOOST_ASIO_NO_DEPRECATED) b = addr1.is_v4_compatible(); (void)b; #endif // !defined(BOOST_ASIO_NO_DEPRECATED) b = addr1.is_multicast_node_local(); (void)b; b = addr1.is_multicast_link_local(); (void)b; b = addr1.is_multicast_site_local(); (void)b; b = addr1.is_multicast_org_local(); (void)b; b = addr1.is_multicast_global(); (void)b; ip::address_v6::bytes_type bytes_value = addr1.to_bytes(); (void)bytes_value; std::string string_value = addr1.to_string(); #if !defined(BOOST_ASIO_NO_DEPRECATED) string_value = addr1.to_string(ec); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) #if !defined(BOOST_ASIO_NO_DEPRECATED) ip::address_v4 addr3 = addr1.to_v4(); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) // address_v6 static functions. #if !defined(BOOST_ASIO_NO_DEPRECATED) addr1 = ip::address_v6::from_string("0::0"); addr1 = ip::address_v6::from_string("0::0", ec); addr1 = ip::address_v6::from_string(string_value); addr1 = ip::address_v6::from_string(string_value, ec); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) addr1 = ip::address_v6::any(); addr1 = ip::address_v6::loopback(); #if !defined(BOOST_ASIO_NO_DEPRECATED) addr1 = ip::address_v6::v4_mapped(addr3); addr1 = ip::address_v6::v4_compatible(addr3); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) // address_v6 comparisons. b = (addr1 == addr2); (void)b; b = (addr1 != addr2); (void)b; b = (addr1 < addr2); (void)b; b = (addr1 > addr2); (void)b; b = (addr1 <= addr2); (void)b; b = (addr1 >= addr2); (void)b; // address_v6 creation functions. addr1 = ip::make_address_v6(const_bytes_value, scope_id); addr1 = ip::make_address_v6("0::0"); addr1 = ip::make_address_v6("0::0", ec); addr1 = ip::make_address_v6(string_value); addr1 = ip::make_address_v6(string_value, ec); #if defined(BOOST_ASIO_HAS_STRING_VIEW) # if defined(BOOST_ASIO_HAS_STD_STRING_VIEW) std::string_view string_view_value("0::0"); # else // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) std::experimental::string_view string_view_value("0::0"); # endif // defined(BOOST_ASIO_HAS_STD_EXPERIMENTAL_STRING_VIEW) addr1 = ip::make_address_v6(string_view_value); addr1 = ip::make_address_v6(string_view_value, ec); #endif // defined(BOOST_ASIO_HAS_STRING_VIEW) // address_v6 IPv4-mapped conversion. #if defined(BOOST_ASIO_NO_DEPRECATED) ip::address_v4 addr3; #endif // defined(BOOST_ASIO_NO_DEPRECATED) addr1 = ip::make_address_v6(ip::v4_mapped, addr3); addr3 = ip::make_address_v4(ip::v4_mapped, addr1); // address_v6 I/O. std::ostringstream os; os << addr1; #if !defined(BOOST_NO_STD_WSTREAMBUF) std::wostringstream wos; wos << addr1; #endif // !defined(BOOST_NO_STD_WSTREAMBUF) #if defined(BOOST_ASIO_HAS_STD_HASH) std::size_t hash1 = std::hash<ip::address_v6>()(addr1); (void)hash1; #endif // defined(BOOST_ASIO_HAS_STD_HASH) } catch (std::exception&) { } } } // namespace ip_address_v6_compile //------------------------------------------------------------------------------ // ip_address_v6_runtime test // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that the various public member functions meet the // necessary postconditions. namespace ip_address_v6_runtime { void test() { using boost::asio::ip::address_v6; address_v6 a1; BOOST_ASIO_CHECK(a1.is_unspecified()); BOOST_ASIO_CHECK(a1.scope_id() == 0); address_v6::bytes_type b1 = {{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }}; address_v6 a2(b1, 12345); BOOST_ASIO_CHECK(a2.to_bytes()[0] == 1); BOOST_ASIO_CHECK(a2.to_bytes()[1] == 2); BOOST_ASIO_CHECK(a2.to_bytes()[2] == 3); BOOST_ASIO_CHECK(a2.to_bytes()[3] == 4); BOOST_ASIO_CHECK(a2.to_bytes()[4] == 5); BOOST_ASIO_CHECK(a2.to_bytes()[5] == 6); BOOST_ASIO_CHECK(a2.to_bytes()[6] == 7); BOOST_ASIO_CHECK(a2.to_bytes()[7] == 8); BOOST_ASIO_CHECK(a2.to_bytes()[8] == 9); BOOST_ASIO_CHECK(a2.to_bytes()[9] == 10); BOOST_ASIO_CHECK(a2.to_bytes()[10] == 11); BOOST_ASIO_CHECK(a2.to_bytes()[11] == 12); BOOST_ASIO_CHECK(a2.to_bytes()[12] == 13); BOOST_ASIO_CHECK(a2.to_bytes()[13] == 14); BOOST_ASIO_CHECK(a2.to_bytes()[14] == 15); BOOST_ASIO_CHECK(a2.to_bytes()[15] == 16); BOOST_ASIO_CHECK(a2.scope_id() == 12345); address_v6 a3; a3.scope_id(12345); BOOST_ASIO_CHECK(a3.scope_id() == 12345); address_v6 unspecified_address; address_v6::bytes_type loopback_bytes = {{ 0 }}; loopback_bytes[15] = 1; address_v6 loopback_address(loopback_bytes); address_v6::bytes_type link_local_bytes = {{ 0xFE, 0x80, 1 }}; address_v6 link_local_address(link_local_bytes); address_v6::bytes_type site_local_bytes = {{ 0xFE, 0xC0, 1 }}; address_v6 site_local_address(site_local_bytes); address_v6::bytes_type v4_mapped_bytes = {{ 0 }}; v4_mapped_bytes[10] = 0xFF, v4_mapped_bytes[11] = 0xFF; v4_mapped_bytes[12] = 1, v4_mapped_bytes[13] = 2; v4_mapped_bytes[14] = 3, v4_mapped_bytes[15] = 4; address_v6 v4_mapped_address(v4_mapped_bytes); address_v6::bytes_type v4_compat_bytes = {{ 0 }}; v4_compat_bytes[12] = 1, v4_compat_bytes[13] = 2; v4_compat_bytes[14] = 3, v4_compat_bytes[15] = 4; address_v6 v4_compat_address(v4_compat_bytes); address_v6::bytes_type mcast_global_bytes = {{ 0xFF, 0x0E, 1 }}; address_v6 mcast_global_address(mcast_global_bytes); address_v6::bytes_type mcast_link_local_bytes = {{ 0xFF, 0x02, 1 }}; address_v6 mcast_link_local_address(mcast_link_local_bytes); address_v6::bytes_type mcast_node_local_bytes = {{ 0xFF, 0x01, 1 }}; address_v6 mcast_node_local_address(mcast_node_local_bytes); address_v6::bytes_type mcast_org_local_bytes = {{ 0xFF, 0x08, 1 }}; address_v6 mcast_org_local_address(mcast_org_local_bytes); address_v6::bytes_type mcast_site_local_bytes = {{ 0xFF, 0x05, 1 }}; address_v6 mcast_site_local_address(mcast_site_local_bytes); BOOST_ASIO_CHECK(!unspecified_address.is_loopback()); BOOST_ASIO_CHECK(loopback_address.is_loopback()); BOOST_ASIO_CHECK(!link_local_address.is_loopback()); BOOST_ASIO_CHECK(!site_local_address.is_loopback()); BOOST_ASIO_CHECK(!v4_mapped_address.is_loopback()); BOOST_ASIO_CHECK(!v4_compat_address.is_loopback()); BOOST_ASIO_CHECK(!mcast_global_address.is_loopback()); BOOST_ASIO_CHECK(!mcast_link_local_address.is_loopback()); BOOST_ASIO_CHECK(!mcast_node_local_address.is_loopback()); BOOST_ASIO_CHECK(!mcast_org_local_address.is_loopback()); BOOST_ASIO_CHECK(!mcast_site_local_address.is_loopback()); BOOST_ASIO_CHECK(unspecified_address.is_unspecified()); BOOST_ASIO_CHECK(!loopback_address.is_unspecified()); BOOST_ASIO_CHECK(!link_local_address.is_unspecified()); BOOST_ASIO_CHECK(!site_local_address.is_unspecified()); BOOST_ASIO_CHECK(!v4_mapped_address.is_unspecified()); BOOST_ASIO_CHECK(!v4_compat_address.is_unspecified()); BOOST_ASIO_CHECK(!mcast_global_address.is_unspecified()); BOOST_ASIO_CHECK(!mcast_link_local_address.is_unspecified()); BOOST_ASIO_CHECK(!mcast_node_local_address.is_unspecified()); BOOST_ASIO_CHECK(!mcast_org_local_address.is_unspecified()); BOOST_ASIO_CHECK(!mcast_site_local_address.is_unspecified()); BOOST_ASIO_CHECK(!unspecified_address.is_link_local()); BOOST_ASIO_CHECK(!loopback_address.is_link_local()); BOOST_ASIO_CHECK(link_local_address.is_link_local()); BOOST_ASIO_CHECK(!site_local_address.is_link_local()); BOOST_ASIO_CHECK(!v4_mapped_address.is_link_local()); BOOST_ASIO_CHECK(!v4_compat_address.is_link_local()); BOOST_ASIO_CHECK(!mcast_global_address.is_link_local()); BOOST_ASIO_CHECK(!mcast_link_local_address.is_link_local()); BOOST_ASIO_CHECK(!mcast_node_local_address.is_link_local()); BOOST_ASIO_CHECK(!mcast_org_local_address.is_link_local()); BOOST_ASIO_CHECK(!mcast_site_local_address.is_link_local()); BOOST_ASIO_CHECK(!unspecified_address.is_site_local()); BOOST_ASIO_CHECK(!loopback_address.is_site_local()); BOOST_ASIO_CHECK(!link_local_address.is_site_local()); BOOST_ASIO_CHECK(site_local_address.is_site_local()); BOOST_ASIO_CHECK(!v4_mapped_address.is_site_local()); BOOST_ASIO_CHECK(!v4_compat_address.is_site_local()); BOOST_ASIO_CHECK(!mcast_global_address.is_site_local()); BOOST_ASIO_CHECK(!mcast_link_local_address.is_site_local()); BOOST_ASIO_CHECK(!mcast_node_local_address.is_site_local()); BOOST_ASIO_CHECK(!mcast_org_local_address.is_site_local()); BOOST_ASIO_CHECK(!mcast_site_local_address.is_site_local()); BOOST_ASIO_CHECK(!unspecified_address.is_v4_mapped()); BOOST_ASIO_CHECK(!loopback_address.is_v4_mapped()); BOOST_ASIO_CHECK(!link_local_address.is_v4_mapped()); BOOST_ASIO_CHECK(!site_local_address.is_v4_mapped()); BOOST_ASIO_CHECK(v4_mapped_address.is_v4_mapped()); BOOST_ASIO_CHECK(!v4_compat_address.is_v4_mapped()); BOOST_ASIO_CHECK(!mcast_global_address.is_v4_mapped()); BOOST_ASIO_CHECK(!mcast_link_local_address.is_v4_mapped()); BOOST_ASIO_CHECK(!mcast_node_local_address.is_v4_mapped()); BOOST_ASIO_CHECK(!mcast_org_local_address.is_v4_mapped()); BOOST_ASIO_CHECK(!mcast_site_local_address.is_v4_mapped()); #if !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(!unspecified_address.is_v4_compatible()); BOOST_ASIO_CHECK(!loopback_address.is_v4_compatible()); BOOST_ASIO_CHECK(!link_local_address.is_v4_compatible()); BOOST_ASIO_CHECK(!site_local_address.is_v4_compatible()); BOOST_ASIO_CHECK(!v4_mapped_address.is_v4_compatible()); BOOST_ASIO_CHECK(v4_compat_address.is_v4_compatible()); BOOST_ASIO_CHECK(!mcast_global_address.is_v4_compatible()); BOOST_ASIO_CHECK(!mcast_link_local_address.is_v4_compatible()); BOOST_ASIO_CHECK(!mcast_node_local_address.is_v4_compatible()); BOOST_ASIO_CHECK(!mcast_org_local_address.is_v4_compatible()); BOOST_ASIO_CHECK(!mcast_site_local_address.is_v4_compatible()); #endif // !defined(BOOST_ASIO_NO_DEPRECATED) BOOST_ASIO_CHECK(!unspecified_address.is_multicast()); BOOST_ASIO_CHECK(!loopback_address.is_multicast()); BOOST_ASIO_CHECK(!link_local_address.is_multicast()); BOOST_ASIO_CHECK(!site_local_address.is_multicast()); BOOST_ASIO_CHECK(!v4_mapped_address.is_multicast()); BOOST_ASIO_CHECK(!v4_compat_address.is_multicast()); BOOST_ASIO_CHECK(mcast_global_address.is_multicast()); BOOST_ASIO_CHECK(mcast_link_local_address.is_multicast()); BOOST_ASIO_CHECK(mcast_node_local_address.is_multicast()); BOOST_ASIO_CHECK(mcast_org_local_address.is_multicast()); BOOST_ASIO_CHECK(mcast_site_local_address.is_multicast()); BOOST_ASIO_CHECK(!unspecified_address.is_multicast_global()); BOOST_ASIO_CHECK(!loopback_address.is_multicast_global()); BOOST_ASIO_CHECK(!link_local_address.is_multicast_global()); BOOST_ASIO_CHECK(!site_local_address.is_multicast_global()); BOOST_ASIO_CHECK(!v4_mapped_address.is_multicast_global()); BOOST_ASIO_CHECK(!v4_compat_address.is_multicast_global()); BOOST_ASIO_CHECK(mcast_global_address.is_multicast_global()); BOOST_ASIO_CHECK(!mcast_link_local_address.is_multicast_global()); BOOST_ASIO_CHECK(!mcast_node_local_address.is_multicast_global()); BOOST_ASIO_CHECK(!mcast_org_local_address.is_multicast_global()); BOOST_ASIO_CHECK(!mcast_site_local_address.is_multicast_global()); BOOST_ASIO_CHECK(!unspecified_address.is_multicast_link_local()); BOOST_ASIO_CHECK(!loopback_address.is_multicast_link_local()); BOOST_ASIO_CHECK(!link_local_address.is_multicast_link_local()); BOOST_ASIO_CHECK(!site_local_address.is_multicast_link_local()); BOOST_ASIO_CHECK(!v4_mapped_address.is_multicast_link_local()); BOOST_ASIO_CHECK(!v4_compat_address.is_multicast_link_local()); BOOST_ASIO_CHECK(!mcast_global_address.is_multicast_link_local()); BOOST_ASIO_CHECK(mcast_link_local_address.is_multicast_link_local()); BOOST_ASIO_CHECK(!mcast_node_local_address.is_multicast_link_local()); BOOST_ASIO_CHECK(!mcast_org_local_address.is_multicast_link_local()); BOOST_ASIO_CHECK(!mcast_site_local_address.is_multicast_link_local()); BOOST_ASIO_CHECK(!unspecified_address.is_multicast_node_local()); BOOST_ASIO_CHECK(!loopback_address.is_multicast_node_local()); BOOST_ASIO_CHECK(!link_local_address.is_multicast_node_local()); BOOST_ASIO_CHECK(!site_local_address.is_multicast_node_local()); BOOST_ASIO_CHECK(!v4_mapped_address.is_multicast_node_local()); BOOST_ASIO_CHECK(!v4_compat_address.is_multicast_node_local()); BOOST_ASIO_CHECK(!mcast_global_address.is_multicast_node_local()); BOOST_ASIO_CHECK(!mcast_link_local_address.is_multicast_node_local()); BOOST_ASIO_CHECK(mcast_node_local_address.is_multicast_node_local()); BOOST_ASIO_CHECK(!mcast_org_local_address.is_multicast_node_local()); BOOST_ASIO_CHECK(!mcast_site_local_address.is_multicast_node_local()); BOOST_ASIO_CHECK(!unspecified_address.is_multicast_org_local()); BOOST_ASIO_CHECK(!loopback_address.is_multicast_org_local()); BOOST_ASIO_CHECK(!link_local_address.is_multicast_org_local()); BOOST_ASIO_CHECK(!site_local_address.is_multicast_org_local()); BOOST_ASIO_CHECK(!v4_mapped_address.is_multicast_org_local()); BOOST_ASIO_CHECK(!v4_compat_address.is_multicast_org_local()); BOOST_ASIO_CHECK(!mcast_global_address.is_multicast_org_local()); BOOST_ASIO_CHECK(!mcast_link_local_address.is_multicast_org_local()); BOOST_ASIO_CHECK(!mcast_node_local_address.is_multicast_org_local()); BOOST_ASIO_CHECK(mcast_org_local_address.is_multicast_org_local()); BOOST_ASIO_CHECK(!mcast_site_local_address.is_multicast_org_local()); BOOST_ASIO_CHECK(!unspecified_address.is_multicast_site_local()); BOOST_ASIO_CHECK(!loopback_address.is_multicast_site_local()); BOOST_ASIO_CHECK(!link_local_address.is_multicast_site_local()); BOOST_ASIO_CHECK(!site_local_address.is_multicast_site_local()); BOOST_ASIO_CHECK(!v4_mapped_address.is_multicast_site_local()); BOOST_ASIO_CHECK(!v4_compat_address.is_multicast_site_local()); BOOST_ASIO_CHECK(!mcast_global_address.is_multicast_site_local()); BOOST_ASIO_CHECK(!mcast_link_local_address.is_multicast_site_local()); BOOST_ASIO_CHECK(!mcast_node_local_address.is_multicast_site_local()); BOOST_ASIO_CHECK(!mcast_org_local_address.is_multicast_site_local()); BOOST_ASIO_CHECK(mcast_site_local_address.is_multicast_site_local()); BOOST_ASIO_CHECK(address_v6::loopback().is_loopback()); } } // namespace ip_address_v6_runtime //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "ip/address_v6", BOOST_ASIO_COMPILE_TEST_CASE(ip_address_v6_compile::test) BOOST_ASIO_TEST_CASE(ip_address_v6_runtime::test) )
cpp
asio
data/projects/asio/test/ip/basic_resolver.cpp
// // basic_resolver.cpp // ~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/basic_resolver.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "ip/basic_resolver", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/ip/resolver_query_base.cpp
// // resolver_query_base.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/ip/resolver_query_base.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "ip/resolver_query_base", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/posix/descriptor_base.cpp
// // descriptor_base.cpp // ~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/posix/descriptor_base.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "posix/descriptor_base", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/posix/basic_stream_descriptor.cpp
// // basic_stream_descriptor.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/posix/basic_stream_descriptor.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "posix/basic_stream_descriptor", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/posix/stream_descriptor.cpp
// // stream_descriptor.cpp // ~~~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/posix/stream_descriptor.hpp> #include <boost/asio/io_context.hpp> #include "../archetypes/async_result.hpp" #include "../unit_test.hpp" //------------------------------------------------------------------------------ // posix_stream_descriptor_compile test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The following test checks that all public member functions on the class // posix::stream_descriptor compile and link correctly. Runtime failures are // ignored. namespace posix_stream_descriptor_compile { void wait_handler(const boost::system::error_code&) { } void write_some_handler(const boost::system::error_code&, std::size_t) { } void read_some_handler(const boost::system::error_code&, std::size_t) { } void test() { #if defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR) using namespace boost::asio; namespace posix = boost::asio::posix; try { io_context ioc; const io_context::executor_type ioc_ex = ioc.get_executor(); char mutable_char_buffer[128] = ""; const char const_char_buffer[128] = ""; posix::descriptor_base::bytes_readable io_control_command; archetypes::immediate_handler immediate; archetypes::lazy_handler lazy; boost::system::error_code ec; // basic_stream_descriptor constructors. posix::stream_descriptor descriptor1(ioc); posix::stream_descriptor descriptor2(ioc_ex); int native_descriptor1 = -1; posix::stream_descriptor descriptor3(ioc, native_descriptor1); posix::stream_descriptor descriptor4(ioc_ex, native_descriptor1); posix::stream_descriptor descriptor5(std::move(descriptor2)); posix::basic_stream_descriptor<io_context::executor_type> descriptor6(ioc); posix::stream_descriptor descriptor7(std::move(descriptor6)); // basic_stream_descriptor operators. descriptor1 = posix::stream_descriptor(ioc); descriptor1 = std::move(descriptor2); descriptor1 = std::move(descriptor6); // basic_io_object functions. posix::stream_descriptor::executor_type ex = descriptor1.get_executor(); (void)ex; // basic_descriptor functions. posix::stream_descriptor::lowest_layer_type& lowest_layer = descriptor1.lowest_layer(); (void)lowest_layer; const posix::stream_descriptor& descriptor8 = descriptor1; const posix::stream_descriptor::lowest_layer_type& lowest_layer2 = descriptor8.lowest_layer(); (void)lowest_layer2; int native_descriptor2 = -1; descriptor1.assign(native_descriptor2); bool is_open = descriptor1.is_open(); (void)is_open; descriptor1.close(); descriptor1.close(ec); posix::stream_descriptor::native_handle_type native_descriptor3 = descriptor1.native_handle(); (void)native_descriptor3; posix::stream_descriptor::native_handle_type native_descriptor4 = descriptor1.release(); (void)native_descriptor4; descriptor1.cancel(); descriptor1.cancel(ec); descriptor1.io_control(io_control_command); descriptor1.io_control(io_control_command, ec); bool non_blocking1 = descriptor1.non_blocking(); (void)non_blocking1; descriptor1.non_blocking(true); descriptor1.non_blocking(false, ec); bool non_blocking2 = descriptor1.native_non_blocking(); (void)non_blocking2; descriptor1.native_non_blocking(true); descriptor1.native_non_blocking(false, ec); descriptor1.wait(posix::descriptor_base::wait_read); descriptor1.wait(posix::descriptor_base::wait_write, ec); descriptor1.async_wait(posix::descriptor_base::wait_read, &wait_handler); descriptor1.async_wait(posix::descriptor_base::wait_read, immediate); int i1 = descriptor1.async_wait(posix::descriptor_base::wait_write, lazy); (void)i1; // basic_stream_descriptor functions. descriptor1.write_some(buffer(mutable_char_buffer)); descriptor1.write_some(buffer(const_char_buffer)); descriptor1.write_some(null_buffers()); descriptor1.write_some(buffer(mutable_char_buffer), ec); descriptor1.write_some(buffer(const_char_buffer), ec); descriptor1.write_some(null_buffers(), ec); descriptor1.async_write_some(buffer(mutable_char_buffer), write_some_handler); descriptor1.async_write_some(buffer(const_char_buffer), write_some_handler); descriptor1.async_write_some(null_buffers(), write_some_handler); descriptor1.async_write_some(buffer(mutable_char_buffer), immediate); descriptor1.async_write_some(buffer(const_char_buffer), immediate); descriptor1.async_write_some(null_buffers(), immediate); int i2 = descriptor1.async_write_some(buffer(mutable_char_buffer), lazy); (void)i2; int i3 = descriptor1.async_write_some(buffer(const_char_buffer), lazy); (void)i3; int i4 = descriptor1.async_write_some(null_buffers(), lazy); (void)i4; descriptor1.read_some(buffer(mutable_char_buffer)); descriptor1.read_some(buffer(mutable_char_buffer), ec); descriptor1.read_some(null_buffers(), ec); descriptor1.async_read_some(buffer(mutable_char_buffer), read_some_handler); descriptor1.async_read_some(null_buffers(), read_some_handler); descriptor1.async_read_some(buffer(mutable_char_buffer), immediate); descriptor1.async_read_some(null_buffers(), immediate); int i5 = descriptor1.async_read_some(buffer(mutable_char_buffer), lazy); (void)i5; int i6 = descriptor1.async_read_some(null_buffers(), lazy); (void)i6; } catch (std::exception&) { } #endif // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR) } } // namespace posix_stream_descriptor_compile //------------------------------------------------------------------------------ BOOST_ASIO_TEST_SUITE ( "posix/stream_descriptor", BOOST_ASIO_COMPILE_TEST_CASE(posix_stream_descriptor_compile::test) )
cpp
asio
data/projects/asio/test/posix/descriptor.cpp
// // descriptor.cpp // ~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/posix/descriptor.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "posix/descriptor", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/posix/basic_descriptor.cpp
// // basic_descriptor.cpp // ~~~~~~~~~~~~~~~~~~~~ // // 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) // // Disable autolinking for unit tests. #if !defined(BOOST_ALL_NO_LIB) #define BOOST_ALL_NO_LIB 1 #endif // !defined(BOOST_ALL_NO_LIB) // Test that header file is self-contained. #include <boost/asio/posix/basic_descriptor.hpp> #include "../unit_test.hpp" BOOST_ASIO_TEST_SUITE ( "posix/basic_descriptor", BOOST_ASIO_TEST_CASE(null_test) )
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_preferable_member_require.cpp
// // cpp14/can_prefer_not_preferable_member_require.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = false; }; template <int> struct object { template <int N> constexpr object<N> require(prop<N>) const { return object<N>(); } }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_concept_free.cpp
// // cpp14/can_require_concept_free.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable_concept = true; }; template <int> struct object { template <int N> friend constexpr object<N> require_concept(const object&, prop<N>) { return object<N>(); } }; int main() { static_assert(boost::asio::can_require_concept_v<object<1>, prop<2>>, ""); static_assert(boost::asio::can_require_concept_v<const object<1>, prop<2>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/require_member.cpp
// // cpp14/require_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable = true; }; template <int> struct object { template <int N> constexpr object<N> require(prop<N>) const { return object<N>(); } }; int main() { object<1> o1 = {}; object<2> o2 = boost::asio::require(o1, prop<2>()); object<3> o3 = boost::asio::require(o1, prop<2>(), prop<3>()); object<4> o4 = boost::asio::require(o1, prop<2>(), prop<3>(), prop<4>()); (void)o2; (void)o3; (void)o4; const object<1> o5 = {}; object<2> o6 = boost::asio::require(o5, prop<2>()); object<3> o7 = boost::asio::require(o5, prop<2>(), prop<3>()); object<4> o8 = boost::asio::require(o5, prop<2>(), prop<3>(), prop<4>()); (void)o6; (void)o7; (void)o8; constexpr object<2> o9 = boost::asio::require(object<1>(), prop<2>()); constexpr object<3> o10 = boost::asio::require(object<1>(), prop<2>(), prop<3>()); constexpr object<4> o11 = boost::asio::require(object<1>(), prop<2>(), prop<3>(), prop<4>()); (void)o9; (void)o10; (void)o11; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_query_not_applicable_unsupported.cpp
// // cpp14/can_query_not_applicable_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { }; struct object { }; int main() { static_assert(!boost::asio::can_query_v<object, prop>, ""); static_assert(!boost::asio::can_query_v<const object, prop>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/prefer_free_require.cpp
// // cpp14/prefer_free_require.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> friend constexpr object<N> require(const object&, prop<N>) { return object<N>(); } }; int main() { object<1> o1 = {}; object<2> o2 = boost::asio::prefer(o1, prop<2>()); object<3> o3 = boost::asio::prefer(o1, prop<2>(), prop<3>()); object<4> o4 = boost::asio::prefer(o1, prop<2>(), prop<3>(), prop<4>()); (void)o2; (void)o3; (void)o4; const object<1> o5 = {}; object<2> o6 = boost::asio::prefer(o5, prop<2>()); object<3> o7 = boost::asio::prefer(o5, prop<2>(), prop<3>()); object<4> o8 = boost::asio::prefer(o5, prop<2>(), prop<3>(), prop<4>()); (void)o6; (void)o7; (void)o8; constexpr object<2> o9 = boost::asio::prefer(object<1>(), prop<2>()); constexpr object<3> o10 = boost::asio::prefer(object<1>(), prop<2>(), prop<3>()); constexpr object<4> o11 = boost::asio::prefer(object<1>(), prop<2>(), prop<3>(), prop<4>()); (void)o9; (void)o10; (void)o11; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_not_applicable_member.cpp
// // cpp14/can_require_not_applicable_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { static constexpr bool is_requirable = true; }; template <int> struct object { template <int N> constexpr object<N> require(prop<N>) const { return object<N>(); } }; int main() { static_assert(!boost::asio::can_require_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_require_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/require_concept_member.cpp
// // cpp14/require_concept_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable_concept = true; }; template <int> struct object { template <int N> constexpr object<N> require_concept(prop<N>) const { return object<N>(); } }; int main() { object<1> o1 = {}; object<2> o2 = boost::asio::require_concept(o1, prop<2>()); (void)o2; const object<1> o3 = {}; object<2> o4 = boost::asio::require_concept(o3, prop<2>()); (void)o4; constexpr object<2> o5 = boost::asio::require_concept(object<1>(), prop<2>()); (void)o5; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_unsupported.cpp
// // cpp14/can_prefer_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { }; template <int> struct object { }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static constexpr bool value = true; }; } // namespace asio } // namespace boost int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_member_prefer.cpp
// // cpp14/can_prefer_member_prefer.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> constexpr object<N> prefer(prop<N>) const { return object<N>(); } }; int main() { static_assert(boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_concept_not_applicable_static.cpp
// // cpp14/can_require_concept_not_applicable_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { static constexpr bool is_requirable_concept = true; template <typename> static constexpr bool static_query_v = true; static constexpr bool value() { return true; } }; template <int> struct object { }; int main() { static_assert(!boost::asio::can_require_concept_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_concept_v<const object<1>, prop<2>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/query_member.cpp
// // cpp14/query_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; }; struct object { constexpr int query(prop) const { return 123; } }; int main() { object o1 = {}; int result1 = boost::asio::query(o1, prop()); assert(result1 == 123); (void)result1; const object o2 = {}; int result2 = boost::asio::query(o2, prop()); assert(result2 == 123); (void)result2; constexpr object o3 = {}; constexpr int result3 = boost::asio::query(o3, prop()); assert(result3 == 123); (void)result3; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_query_not_applicable_member.cpp
// // cpp14/can_query_not_applicable_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { }; struct object { constexpr int query(prop) const { return 123; } }; int main() { static_assert(!boost::asio::can_query_v<object, prop>, ""); static_assert(!boost::asio::can_query_v<const object, prop>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_free_prefer.cpp
// // cpp14/can_prefer_free_prefer.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> friend constexpr object<N> prefer(const object&, prop<N>) { return object<N>(); } }; int main() { static_assert(boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_concept_unsupported.cpp
// // cpp14/can_require_concept_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { }; template <int> struct object { }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static constexpr bool value = true; }; } // namespace asio } // namespace boost int main() { static_assert(!boost::asio::can_require_concept<object<1>, prop<2>>::value, ""); static_assert(!boost::asio::can_require_concept<const object<1>, prop<2>>::value, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_concept_member.cpp
// // cpp14/can_require_concept_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable_concept = true; }; template <int> struct object { template <int N> constexpr object<N> require_concept(prop<N>) const { return object<N>(); } }; int main() { static_assert(boost::asio::can_require_concept_v<object<1>, prop<2>>, ""); static_assert(boost::asio::can_require_concept_v<const object<1>, prop<2>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_static.cpp
// // cpp14/can_prefer_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = true; template <typename> static constexpr bool static_query_v = true; static constexpr bool value() { return true; } }; template <int> struct object { }; int main() { static_assert(boost::asio::can_prefer_v<object<1>, prop<1>>, ""); static_assert(boost::asio::can_prefer_v<object<1>, prop<1>, prop<1>>, ""); static_assert(boost::asio::can_prefer_v<object<1>, prop<1>, prop<1>, prop<1>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<1>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<1>, prop<1>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<1>, prop<1>, prop<1>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_query_unsupported.cpp
// // cpp14/can_query_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; }; struct object { }; int main() { static_assert(!boost::asio::can_query_v<object, prop>, ""); static_assert(!boost::asio::can_query_v<const object, prop>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_preferable_unsupported.cpp
// // cpp14/can_prefer_not_preferable_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = false; }; template <int> struct object { }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_applicable_free_require.cpp
// // cpp14/can_prefer_not_applicable_free_require.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> friend constexpr object<N> require(const object&, prop<N>) { return object<N>(); } }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/prefer_member_prefer.cpp
// // cpp14/prefer_member_prefer.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> constexpr object<N> prefer(prop<N>) const { return object<N>(); } }; int main() { object<1> o1 = {}; object<2> o2 = boost::asio::prefer(o1, prop<2>()); object<3> o3 = boost::asio::prefer(o1, prop<2>(), prop<3>()); object<4> o4 = boost::asio::prefer(o1, prop<2>(), prop<3>(), prop<4>()); (void)o2; (void)o3; (void)o4; const object<1> o5 = {}; object<2> o6 = boost::asio::prefer(o5, prop<2>()); object<3> o7 = boost::asio::prefer(o5, prop<2>(), prop<3>()); object<4> o8 = boost::asio::prefer(o5, prop<2>(), prop<3>(), prop<4>()); (void)o6; (void)o7; (void)o8; constexpr object<2> o9 = boost::asio::prefer(object<1>(), prop<2>()); constexpr object<3> o10 = boost::asio::prefer(object<1>(), prop<2>(), prop<3>()); constexpr object<4> o11 = boost::asio::prefer(object<1>(), prop<2>(), prop<3>(), prop<4>()); (void)o9; (void)o10; (void)o11; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_applicable_static.cpp
// // cpp14/can_prefer_not_applicable_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { static constexpr bool is_preferable = true; template <typename> static constexpr bool static_query_v = true; static constexpr bool value() { return true; } }; template <int> struct object { }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<1>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<1>, prop<1>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<1>, prop<1>, prop<1>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<1>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<1>, prop<1>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<1>, prop<1>, prop<1>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_applicable_member_prefer.cpp
// // cpp14/can_prefer_not_applicable_member_prefer.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> constexpr object<N> prefer(prop<N>) const { return object<N>(); } }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_preferable_member_prefer.cpp
// // cpp14/can_prefer_not_preferable_member_prefer.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = false; }; template <int> struct object { template <int N> constexpr object<N> prefer(prop<N>) const { return object<N>(); } }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_free_require.cpp
// // cpp14/can_prefer_free_require.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> friend constexpr object<N> require(const object&, prop<N>) { return object<N>(); } }; int main() { static_assert(boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_not_applicable_static.cpp
// // cpp14/can_require_not_applicable_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { static constexpr bool is_requirable = true; template <typename> static constexpr bool static_query_v = true; static constexpr bool value() { return true; } }; template <int> struct object { }; int main() { static_assert(!boost::asio::can_require_v<object<1>, prop<1>>, ""); static_assert(!boost::asio::can_require_v<object<1>, prop<1>, prop<1>>, ""); static_assert(!boost::asio::can_require_v<object<1>, prop<1>, prop<1>, prop<1>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<1>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<1>, prop<1>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<1>, prop<1>, prop<1>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_static.cpp
// // cpp14/can_require_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable = true; template <typename> static constexpr bool static_query_v = true; static constexpr bool value() { return true; } }; template <int> struct object { }; int main() { static_assert(boost::asio::can_require_v<object<1>, prop<1>>, ""); static_assert(boost::asio::can_require_v<object<1>, prop<1>, prop<1>>, ""); static_assert(boost::asio::can_require_v<object<1>, prop<1>, prop<1>, prop<1>>, ""); static_assert(boost::asio::can_require_v<const object<1>, prop<1>>, ""); static_assert(boost::asio::can_require_v<const object<1>, prop<1>, prop<1>>, ""); static_assert(boost::asio::can_require_v<const object<1>, prop<1>, prop<1>, prop<1>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_applicable_member_require.cpp
// // cpp14/can_prefer_not_applicable_member_require.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> constexpr object<N> require(prop<N>) const { return object<N>(); } }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_preferable_free_prefer.cpp
// // cpp14/can_prefer_not_preferable_free_prefer.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = false; }; template <int> struct object { template <int N> friend constexpr object<N> prefer(const object&, prop<N>) { return object<N>(); } }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/query_static.cpp
// // cpp14/query_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; template <typename> static constexpr int static_query_v = 123; }; struct object { }; int main() { object o1 = {}; int result1 = boost::asio::query(o1, prop()); assert(result1 == 123); (void)result1; const object o2 = {}; int result2 = boost::asio::query(o2, prop()); assert(result2 == 123); (void)result2; constexpr object o3 = {}; constexpr int result3 = boost::asio::query(o3, prop()); assert(result3 == 123); (void)result3; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_member_require.cpp
// // cpp14/can_prefer_member_require.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> constexpr object<N> require(prop<N>) const { return object<N>(); } }; int main() { static_assert(boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_concept_not_applicable_member.cpp
// // cpp14/can_require_concept_not_applicable_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { static constexpr bool is_requirable_concept = true; }; template <int> struct object { template <int N> constexpr object<N> require_concept(prop<N>) const { return object<N>(); } }; int main() { static_assert(!boost::asio::can_require_concept_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_concept_v<const object<1>, prop<2>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/require_concept_static.cpp
// // cpp14/require_concept_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable_concept = true; template <typename> static constexpr bool static_query_v = true; static constexpr bool value() { return true; } }; template <int> struct object { }; int main() { object<1> o1 = {}; const object<1>& o2 = boost::asio::require_concept(o1, prop<1>()); assert(&o1 == &o2); (void)o2; const object<1> o3 = {}; const object<1>& o4 = boost::asio::require_concept(o3, prop<1>()); assert(&o3 == &o4); (void)o4; constexpr object<1> o5 = boost::asio::require_concept(object<1>(), prop<1>()); (void)o5; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_applicable_unsupported.cpp
// // cpp14/can_prefer_not_applicable_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { }; template <int> struct object { }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_query_member.cpp
// // cpp14/can_query_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; }; struct object { constexpr int query(prop) const { return 123; } }; int main() { static_assert(boost::asio::can_query_v<object, prop>, ""); static_assert(boost::asio::can_query_v<const object, prop>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_member.cpp
// // cpp14/can_require_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable = true; }; template <int> struct object { template <int N> constexpr object<N> require(prop<N>) const { return object<N>(); } }; int main() { static_assert(boost::asio::can_require_v<object<1>, prop<2>>, ""); static_assert(boost::asio::can_require_v<object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_require_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(boost::asio::can_require_v<const object<1>, prop<2>>, ""); static_assert(boost::asio::can_require_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_require_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_free.cpp
// // cpp14/can_require_free.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable = true; }; template <int> struct object { template <int N> friend constexpr object<N> require(const object&, prop<N>) { return object<N>(); } }; int main() { static_assert(boost::asio::can_require_v<object<1>, prop<2>>, ""); static_assert(boost::asio::can_require_v<object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_require_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(boost::asio::can_require_v<const object<1>, prop<2>>, ""); static_assert(boost::asio::can_require_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(boost::asio::can_require_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_not_applicable_unsupported.cpp
// // cpp14/can_require_not_applicable_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { }; template <int> struct object { }; int main() { static_assert(!boost::asio::can_require_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_require_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/query_free.cpp
// // cpp14/query_free.cpp // ~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; }; struct object { friend constexpr int query(const object&, prop) { return 123; } }; int main() { object o1 = {}; int result1 = boost::asio::query(o1, prop()); assert(result1 == 123); (void)result1; const object o2 = {}; int result2 = boost::asio::query(o2, prop()); assert(result2 == 123); (void)result2; constexpr object o3 = {}; constexpr int result3 = boost::asio::query(o3, prop()); assert(result3 == 123); (void)result3; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_concept_not_applicable_free.cpp
// // cpp14/can_require_concept_not_applicable_free.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { static constexpr bool is_requirable_concept = true; }; template <int> struct object { template <int N> friend constexpr object<N> require_concept(const object&, prop<N>) { return object<N>(); } }; int main() { static_assert(!boost::asio::can_require_concept_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_concept_v<const object<1>, prop<2>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_concept_static.cpp
// // cpp14/can_require_concept_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable_concept = true; template <typename> static constexpr bool static_query_v = true; static constexpr bool value() { return true; } }; template <int> struct object { }; int main() { static_assert(boost::asio::can_require_concept_v<object<1>, prop<1>>, ""); static_assert(boost::asio::can_require_concept_v<const object<1>, prop<1>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/require_concept_free.cpp
// // cpp14/require_concept_free.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable_concept = true; }; template <int> struct object { template <int N> friend constexpr object<N> require_concept(const object&, prop<N>) { return object<N>(); } }; int main() { object<1> o1 = {}; object<2> o2 = boost::asio::require_concept(o1, prop<2>()); (void)o2; const object<1> o3 = {}; object<2> o4 = boost::asio::require_concept(o3, prop<2>()); (void)o4; constexpr object<2> o5 = boost::asio::require_concept(object<1>(), prop<2>()); (void)o5; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_query_static.cpp
// // cpp14/can_query_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; template <typename> static constexpr int static_query_v = 123; }; struct object { }; int main() { static_assert(boost::asio::can_query_v<object, prop>, ""); static_assert(boost::asio::can_query_v<const object, prop>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_not_applicable_free.cpp
// // cpp14/can_require_not_applicable_free.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { static constexpr bool is_requirable = true; }; template <int> struct object { template <int N> friend constexpr object<N> require(const object&, prop<N>) { return object<N>(); } }; int main() { static_assert(!boost::asio::can_require_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_require_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_applicable_free_prefer.cpp
// // cpp14/can_prefer_not_applicable_free_prefer.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> friend constexpr object<N> prefer(const object&, prop<N>) { return object<N>(); } }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_query_free.cpp
// // cpp14/can_query_free.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; }; struct object { friend constexpr int query(const object&, prop) { return 123; } }; int main() { static_assert(boost::asio::can_query_v<object, prop>, ""); static_assert(boost::asio::can_query_v<const object, prop>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_query_not_applicable_static.cpp
// // cpp14/can_query_not_applicable_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { template <typename> static constexpr int static_query_v = 123; }; struct object { }; int main() { static_assert(!boost::asio::can_query_v<object, prop>, ""); static_assert(!boost::asio::can_query_v<const object, prop>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/require_static.cpp
// // cpp14/require_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable = true; template <typename> static constexpr bool static_query_v = true; static constexpr bool value() { return true; } }; template <int> struct object { }; int main() { object<1> o1 = {}; object<1> o2 = boost::asio::require(o1, prop<1>()); object<1> o3 = boost::asio::require(o1, prop<1>(), prop<1>()); object<1> o4 = boost::asio::require(o1, prop<1>(), prop<1>(), prop<1>()); (void)o2; (void)o3; (void)o4; const object<1> o5 = {}; object<1> o6 = boost::asio::require(o5, prop<1>()); object<1> o7 = boost::asio::require(o5, prop<1>(), prop<1>()); object<1> o8 = boost::asio::require(o5, prop<1>(), prop<1>(), prop<1>()); (void)o6; (void)o7; (void)o8; constexpr object<1> o9 = boost::asio::require(object<1>(), prop<1>()); constexpr object<1> o10 = boost::asio::require(object<1>(), prop<1>(), prop<1>()); constexpr object<1> o11 = boost::asio::require(object<1>(), prop<1>(), prop<1>(), prop<1>()); (void)o9; (void)o10; (void)o11; }
cpp
asio
data/projects/asio/test/properties/cpp14/require_free.cpp
// // cpp14/require_free.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_requirable = true; }; template <int> struct object { template <int N> friend constexpr object<N> require(const object&, prop<N>) { return object<N>(); } }; int main() { object<1> o1 = {}; object<2> o2 = boost::asio::require(o1, prop<2>()); object<3> o3 = boost::asio::require(o1, prop<2>(), prop<3>()); object<4> o4 = boost::asio::require(o1, prop<2>(), prop<3>(), prop<4>()); (void)o2; (void)o3; (void)o4; const object<1> o5 = {}; object<2> o6 = boost::asio::require(o5, prop<2>()); object<3> o7 = boost::asio::require(o5, prop<2>(), prop<3>()); object<4> o8 = boost::asio::require(o5, prop<2>(), prop<3>(), prop<4>()); (void)o6; (void)o7; (void)o8; constexpr object<2> o9 = boost::asio::require(object<1>(), prop<2>()); constexpr object<3> o10 = boost::asio::require(object<1>(), prop<2>(), prop<3>()); constexpr object<4> o11 = boost::asio::require(object<1>(), prop<2>(), prop<3>(), prop<4>()); (void)o9; (void)o10; (void)o11; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_concept_not_applicable_unsupported.cpp
// // cpp14/can_require_concept_not_applicable_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { }; template <int> struct object { }; int main() { static_assert(!boost::asio::can_require_concept_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_concept_v<const object<1>, prop<2>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/prefer_static.cpp
// // cpp14/prefer_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = true; template <typename> static constexpr bool static_query_v = true; static constexpr bool value() { return true; } }; template <int> struct object { }; int main() { object<1> o1 = {}; object<1> o2 = boost::asio::prefer(o1, prop<1>()); object<1> o3 = boost::asio::prefer(o1, prop<1>(), prop<1>()); object<1> o4 = boost::asio::prefer(o1, prop<1>(), prop<1>(), prop<1>()); (void)o2; (void)o3; (void)o4; const object<1> o5 = {}; object<1> o6 = boost::asio::prefer(o5, prop<1>()); object<1> o7 = boost::asio::prefer(o5, prop<1>(), prop<1>()); object<1> o8 = boost::asio::prefer(o5, prop<1>(), prop<1>(), prop<1>()); (void)o6; (void)o7; (void)o8; constexpr object<1> o9 = boost::asio::prefer(object<1>(), prop<1>()); constexpr object<1> o10 = boost::asio::prefer(object<1>(), prop<1>(), prop<1>()); constexpr object<1> o11 = boost::asio::prefer(object<1>(), prop<1>(), prop<1>(), prop<1>()); (void)o9; (void)o10; (void)o11; }
cpp
asio
data/projects/asio/test/properties/cpp14/prefer_unsupported.cpp
// // cpp14/prefer_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = true; }; template <int> struct object { }; int main() { object<1> o1 = {}; object<1> o2 = boost::asio::prefer(o1, prop<2>()); object<1> o3 = boost::asio::prefer(o1, prop<2>(), prop<3>()); object<1> o4 = boost::asio::prefer(o1, prop<2>(), prop<3>(), prop<4>()); (void)o2; (void)o3; (void)o4; const object<1> o5 = {}; object<1> o6 = boost::asio::prefer(o5, prop<2>()); object<1> o7 = boost::asio::prefer(o5, prop<2>(), prop<3>()); object<1> o8 = boost::asio::prefer(o5, prop<2>(), prop<3>(), prop<4>()); (void)o6; (void)o7; (void)o8; constexpr object<1> o9 = boost::asio::prefer(object<1>(), prop<2>()); constexpr object<1> o10 = boost::asio::prefer(object<1>(), prop<2>(), prop<3>()); constexpr object<1> o11 = boost::asio::prefer(object<1>(), prop<2>(), prop<3>(), prop<4>()); (void)o9; (void)o10; (void)o11; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_preferable_static.cpp
// // cpp14/can_prefer_not_preferable_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = false; }; template <int> struct object { }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<1>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<1>, prop<1>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<1>, prop<1>, prop<1>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<1>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<1>, prop<1>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<1>, prop<1>, prop<1>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/prefer_member_require.cpp
// // cpp14/prefer_member_require.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> constexpr object<N> require(prop<N>) const { return object<N>(); } }; int main() { object<1> o1 = {}; object<2> o2 = boost::asio::prefer(o1, prop<2>()); object<3> o3 = boost::asio::prefer(o1, prop<2>(), prop<3>()); object<4> o4 = boost::asio::prefer(o1, prop<2>(), prop<3>(), prop<4>()); (void)o2; (void)o3; (void)o4; const object<1> o5 = {}; object<2> o6 = boost::asio::prefer(o5, prop<2>()); object<3> o7 = boost::asio::prefer(o5, prop<2>(), prop<3>()); object<4> o8 = boost::asio::prefer(o5, prop<2>(), prop<3>(), prop<4>()); (void)o6; (void)o7; (void)o8; constexpr object<2> o9 = boost::asio::prefer(object<1>(), prop<2>()); constexpr object<3> o10 = boost::asio::prefer(object<1>(), prop<2>(), prop<3>()); constexpr object<4> o11 = boost::asio::prefer(object<1>(), prop<2>(), prop<3>(), prop<4>()); (void)o9; (void)o10; (void)o11; }
cpp
asio
data/projects/asio/test/properties/cpp14/prefer_free_prefer.cpp
// // cpp14/prefer_free_prefer.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = true; }; template <int> struct object { template <int N> friend constexpr object<N> prefer(const object&, prop<N>) { return object<N>(); } }; int main() { object<1> o1 = {}; object<2> o2 = boost::asio::prefer(o1, prop<2>()); object<3> o3 = boost::asio::prefer(o1, prop<2>(), prop<3>()); object<4> o4 = boost::asio::prefer(o1, prop<2>(), prop<3>(), prop<4>()); (void)o2; (void)o3; (void)o4; const object<1> o5 = {}; object<2> o6 = boost::asio::prefer(o5, prop<2>()); object<3> o7 = boost::asio::prefer(o5, prop<2>(), prop<3>()); object<4> o8 = boost::asio::prefer(o5, prop<2>(), prop<3>(), prop<4>()); (void)o6; (void)o7; (void)o8; constexpr object<2> o9 = boost::asio::prefer(object<1>(), prop<2>()); constexpr object<3> o10 = boost::asio::prefer(object<1>(), prop<2>(), prop<3>()); constexpr object<4> o11 = boost::asio::prefer(object<1>(), prop<2>(), prop<3>(), prop<4>()); (void)o9; (void)o10; (void)o11; }
cpp
asio
data/projects/asio/test/properties/cpp14/can_query_not_applicable_free.cpp
// // cpp14/can_query_not_applicable_free.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { }; struct object { friend constexpr int query(const object&, prop) { return 123; } }; int main() { static_assert(!boost::asio::can_query_v<object, prop>, ""); static_assert(!boost::asio::can_query_v<const object, prop>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_require_unsupported.cpp
// // cpp14/can_require_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { }; template <int> struct object { }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static constexpr bool value = true; }; } // namespace asio } // namespace boost int main() { static_assert(!boost::asio::can_require_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_require_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_require_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp14/can_prefer_not_preferable_free_require.cpp
// // cpp14/can_prefer_not_preferable_free_require.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { template <typename> static constexpr bool is_applicable_property_v = true; static constexpr bool is_preferable = false; }; template <int> struct object { template <int N> friend constexpr object<N> require(const object&, prop<N>) { return object<N>(); } }; int main() { static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<object<1>, prop<2>, prop<3>, prop<4>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>>, ""); static_assert(!boost::asio::can_prefer_v<const object<1>, prop<2>, prop<3>, prop<4>>, ""); }
cpp
asio
data/projects/asio/test/properties/cpp03/can_prefer_not_preferable_member_require.cpp
// // cpp03/can_prefer_not_preferable_member_require.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { static const bool is_preferable = false; }; template <int> struct object { template <int N> object<N> require(prop<N>) const { return object<N>(); } }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static const bool value = true; }; namespace traits { template<int N, int M> struct require_member<object<N>, prop<M> > { static const bool is_valid = true; static const bool is_noexcept = true; typedef object<M> result_type; }; } // namespace traits } // namespace asio } // namespace boost int main() { assert((!boost::asio::can_prefer<object<1>, prop<2> >::value)); assert((!boost::asio::can_prefer<object<1>, prop<2>, prop<3> >::value)); assert((!boost::asio::can_prefer<object<1>, prop<2>, prop<3>, prop<4> >::value)); assert((!boost::asio::can_prefer<const object<1>, prop<2> >::value)); assert((!boost::asio::can_prefer<const object<1>, prop<2>, prop<3> >::value)); assert((!boost::asio::can_prefer<const object<1>, prop<2>, prop<3>, prop<4> >::value)); }
cpp
asio
data/projects/asio/test/properties/cpp03/can_require_concept_free.cpp
// // cpp03/can_require_concept_free.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { static const bool is_requirable_concept = true; }; template <int> struct object { template <int N> friend object<N> require_concept(const object&, prop<N>) { return object<N>(); } }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static const bool value = true; }; namespace traits { template<int N, int M> struct require_concept_free<object<N>, prop<M> > { static const bool is_valid = true; static const bool is_noexcept = true; typedef object<M> result_type; }; } // namespace traits } // namespace asio } // namespace boost int main() { assert((boost::asio::can_require_concept<object<1>, prop<2> >::value)); assert((boost::asio::can_require_concept<const object<1>, prop<2> >::value)); }
cpp
asio
data/projects/asio/test/properties/cpp03/require_member.cpp
// // cpp03/require_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { static const bool is_requirable = true; }; template <int> struct object { template <int N> object<N> require(prop<N>) const { return object<N>(); } }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static const bool value = true; }; namespace traits { template<int N, int M> struct require_member<object<N>, prop<M> > { static const bool is_valid = true; static const bool is_noexcept = true; typedef object<M> result_type; }; } // namespace traits } // namespace asio } // namespace boost int main() { object<1> o1 = {}; object<2> o2 = boost::asio::require(o1, prop<2>()); object<3> o3 = boost::asio::require(o1, prop<2>(), prop<3>()); object<4> o4 = boost::asio::require(o1, prop<2>(), prop<3>(), prop<4>()); (void)o2; (void)o3; (void)o4; const object<1> o5 = {}; object<2> o6 = boost::asio::require(o5, prop<2>()); object<3> o7 = boost::asio::require(o5, prop<2>(), prop<3>()); object<4> o8 = boost::asio::require(o5, prop<2>(), prop<3>(), prop<4>()); (void)o6; (void)o7; (void)o8; }
cpp
asio
data/projects/asio/test/properties/cpp03/can_query_not_applicable_unsupported.cpp
// // cpp03/can_query_not_applicable_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { }; struct object { }; int main() { assert((!boost::asio::can_query<object, prop>::value)); assert((!boost::asio::can_query<const object, prop>::value)); }
cpp
asio
data/projects/asio/test/properties/cpp03/prefer_free_require.cpp
// // cpp03/prefer_free_require.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { static const bool is_preferable = true; }; template <int> struct object { template <int N> friend object<N> require(const object&, prop<N>) { return object<N>(); } }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static const bool value = true; }; namespace traits { template<int N, int M> struct require_free<object<N>, prop<M> > { static const bool is_valid = true; static const bool is_noexcept = true; typedef object<M> result_type; }; } // namespace traits } // namespace asio } // namespace boost int main() { object<1> o1 = {}; object<2> o2 = boost::asio::prefer(o1, prop<2>()); object<3> o3 = boost::asio::prefer(o1, prop<2>(), prop<3>()); object<4> o4 = boost::asio::prefer(o1, prop<2>(), prop<3>(), prop<4>()); (void)o2; (void)o3; (void)o4; const object<1> o5 = {}; object<2> o6 = boost::asio::prefer(o5, prop<2>()); object<3> o7 = boost::asio::prefer(o5, prop<2>(), prop<3>()); object<4> o8 = boost::asio::prefer(o5, prop<2>(), prop<3>(), prop<4>()); (void)o6; (void)o7; (void)o8; }
cpp
asio
data/projects/asio/test/properties/cpp03/can_require_not_applicable_member.cpp
// // cpp03/can_require_not_applicable_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require.hpp> #include <cassert> template <int> struct prop { static const bool is_requirable = true; }; template <int> struct object { template <int N> object<N> require(prop<N>) const { return object<N>(); } }; namespace boost { namespace asio { namespace traits { template<int N, int M> struct require_member<object<N>, prop<M> > { static const bool is_valid = true; static const bool is_noexcept = true; typedef object<M> result_type; }; } // namespace traits } // namespace asio } // namespace boost int main() { assert((!boost::asio::can_require<object<1>, prop<2> >::value)); assert((!boost::asio::can_require<object<1>, prop<2>, prop<3> >::value)); assert((!boost::asio::can_require<object<1>, prop<2>, prop<3>, prop<4> >::value)); assert((!boost::asio::can_require<const object<1>, prop<2> >::value)); assert((!boost::asio::can_require<const object<1>, prop<2>, prop<3> >::value)); assert((!boost::asio::can_require<const object<1>, prop<2>, prop<3>, prop<4> >::value)); }
cpp
asio
data/projects/asio/test/properties/cpp03/require_concept_member.cpp
// // cpp03/require_concept_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { static const bool is_requirable_concept = true; }; template <int> struct object { template <int N> object<N> require_concept(prop<N>) const { return object<N>(); } }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static const bool value = true; }; namespace traits { template<int N, int M> struct require_concept_member<object<N>, prop<M> > { static const bool is_valid = true; static const bool is_noexcept = true; typedef object<M> result_type; }; } // namespace traits } // namespace asio } // namespace boost int main() { object<1> o1 = {}; object<2> o2 = boost::asio::require_concept(o1, prop<2>()); (void)o2; const object<1> o3 = {}; object<2> o4 = boost::asio::require_concept(o3, prop<2>()); (void)o4; }
cpp
asio
data/projects/asio/test/properties/cpp03/can_prefer_unsupported.cpp
// // cpp03/can_prefer_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { static const bool is_preferable = true; }; template <int> struct object { }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static const bool value = true; }; } // namespace asio } // namespace boost int main() { assert((boost::asio::can_prefer<object<1>, prop<2> >::value)); assert((boost::asio::can_prefer<object<1>, prop<2>, prop<3> >::value)); assert((boost::asio::can_prefer<object<1>, prop<2>, prop<3>, prop<4> >::value)); assert((boost::asio::can_prefer<const object<1>, prop<2> >::value)); assert((boost::asio::can_prefer<const object<1>, prop<2>, prop<3> >::value)); assert((boost::asio::can_prefer<const object<1>, prop<2>, prop<3>, prop<4> >::value)); }
cpp
asio
data/projects/asio/test/properties/cpp03/can_prefer_member_prefer.cpp
// // cpp03/can_prefer_member_prefer.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { static const bool is_preferable = true; }; template <int> struct object { template <int N> object<N> prefer(prop<N>) const { return object<N>(); } }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static const bool value = true; }; namespace traits { template<int N, int M> struct prefer_member<object<N>, prop<M> > { static const bool is_valid = true; static const bool is_noexcept = true; typedef object<M> result_type; }; } // namespace traits } // namespace asio } // namespace boost int main() { assert((boost::asio::can_prefer<object<1>, prop<2> >::value)); assert((boost::asio::can_prefer<object<1>, prop<2>, prop<3> >::value)); assert((boost::asio::can_prefer<object<1>, prop<2>, prop<3>, prop<4> >::value)); assert((boost::asio::can_prefer<const object<1>, prop<2> >::value)); assert((boost::asio::can_prefer<const object<1>, prop<2>, prop<3> >::value)); assert((boost::asio::can_prefer<const object<1>, prop<2>, prop<3>, prop<4> >::value)); }
cpp
asio
data/projects/asio/test/properties/cpp03/can_require_concept_not_applicable_static.cpp
// // cpp03/can_require_concept_not_applicable_static.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { static const bool is_requirable_concept = true; }; template <int> struct object { }; namespace boost { namespace asio { namespace traits { template<int N> struct static_require_concept<object<N>, prop<N> > { static const bool is_valid = true; }; } // namespace traits } // namespace asio } // namespace boost int main() { assert((!boost::asio::can_require_concept<object<1>, prop<2> >::value)); assert((!boost::asio::can_require_concept<const object<1>, prop<2> >::value)); }
cpp
asio
data/projects/asio/test/properties/cpp03/query_member.cpp
// // cpp03/query_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { }; struct object { int query(prop) const { return 123; } }; namespace boost { namespace asio { template<> struct is_applicable_property<object, prop> { static const bool value = true; }; namespace traits { template<> struct query_member<object, prop> { static const bool is_valid = true; static const bool is_noexcept = true; typedef int result_type; }; } // namespace traits } // namespace asio } // namespace boost int main() { object o1 = {}; int result1 = boost::asio::query(o1, prop()); assert(result1 == 123); (void)result1; const object o2 = {}; int result2 = boost::asio::query(o2, prop()); assert(result2 == 123); (void)result2; }
cpp
asio
data/projects/asio/test/properties/cpp03/can_query_not_applicable_member.cpp
// // cpp03/can_query_not_applicable_member.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/query.hpp> #include <cassert> struct prop { }; struct object { int query(prop) const { return 123; } }; namespace boost { namespace asio { namespace traits { template<> struct query_member<object, prop> { static const bool is_valid = true; static const bool is_noexcept = true; typedef int result_type; }; } // namespace traits } // namespace asio } // namespace boost int main() { assert((!boost::asio::can_query<object, prop>::value)); assert((!boost::asio::can_query<const object, prop>::value)); }
cpp
asio
data/projects/asio/test/properties/cpp03/can_prefer_free_prefer.cpp
// // cpp03/can_prefer_free_prefer.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/prefer.hpp> #include <cassert> template <int> struct prop { static const bool is_preferable = true; }; template <int> struct object { template <int N> friend object<N> prefer(const object&, prop<N>) { return object<N>(); } }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static const bool value = true; }; namespace traits { template<int N, int M> struct prefer_free<object<N>, prop<M> > { static const bool is_valid = true; static const bool is_noexcept = true; typedef object<M> result_type; }; } // namespace traits } // namespace asio } // namespace boost int main() { assert((boost::asio::can_prefer<object<1>, prop<2> >::value)); assert((boost::asio::can_prefer<object<1>, prop<2>, prop<3> >::value)); assert((boost::asio::can_prefer<object<1>, prop<2>, prop<3>, prop<4> >::value)); assert((boost::asio::can_prefer<const object<1>, prop<2> >::value)); assert((boost::asio::can_prefer<const object<1>, prop<2>, prop<3> >::value)); assert((boost::asio::can_prefer<const object<1>, prop<2>, prop<3>, prop<4> >::value)); }
cpp
asio
data/projects/asio/test/properties/cpp03/can_require_concept_unsupported.cpp
// // cpp03/can_require_concept_unsupported.cpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // 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) // #include <boost/asio/require_concept.hpp> #include <cassert> template <int> struct prop { }; template <int> struct object { }; namespace boost { namespace asio { template<int N, int M> struct is_applicable_property<object<N>, prop<M> > { static const bool value = true; }; } // namespace asio } // namespace boost int main() { assert((!boost::asio::can_require_concept<object<1>, prop<2> >::value)); assert((!boost::asio::can_require_concept<const object<1>, prop<2> >::value)); }
cpp