1 | // |
2 | // stream_descriptor.cpp |
3 | // ~~~~~~~~~~~~~~~~~~~~~ |
4 | // |
5 | // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
6 | // |
7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
9 | // |
10 | |
11 | // Disable autolinking for unit tests. |
12 | #if !defined(BOOST_ALL_NO_LIB) |
13 | #define BOOST_ALL_NO_LIB 1 |
14 | #endif // !defined(BOOST_ALL_NO_LIB) |
15 | |
16 | // Test that header file is self-contained. |
17 | #include <boost/asio/posix/stream_descriptor.hpp> |
18 | |
19 | #include <boost/asio/io_service.hpp> |
20 | #include "../archetypes/async_result.hpp" |
21 | #include "../unit_test.hpp" |
22 | |
23 | //------------------------------------------------------------------------------ |
24 | |
25 | // posix_stream_descriptor_compile test |
26 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
27 | // The following test checks that all public member functions on the class |
28 | // posix::stream_descriptor compile and link correctly. Runtime failures are |
29 | // ignored. |
30 | |
31 | namespace posix_stream_descriptor_compile { |
32 | |
33 | void write_some_handler(const boost::system::error_code&, std::size_t) |
34 | { |
35 | } |
36 | |
37 | void read_some_handler(const boost::system::error_code&, std::size_t) |
38 | { |
39 | } |
40 | |
41 | void test() |
42 | { |
43 | #if defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR) |
44 | using namespace boost::asio; |
45 | namespace posix = boost::asio::posix; |
46 | |
47 | try |
48 | { |
49 | io_service ios; |
50 | char mutable_char_buffer[128] = "" ; |
51 | const char const_char_buffer[128] = "" ; |
52 | posix::descriptor_base::bytes_readable io_control_command; |
53 | archetypes::lazy_handler lazy; |
54 | boost::system::error_code ec; |
55 | |
56 | // basic_stream_descriptor constructors. |
57 | |
58 | posix::stream_descriptor descriptor1(ios); |
59 | int native_descriptor1 = -1; |
60 | posix::stream_descriptor descriptor2(ios, native_descriptor1); |
61 | |
62 | #if defined(BOOST_ASIO_HAS_MOVE) |
63 | posix::stream_descriptor descriptor3(std::move(descriptor3)); |
64 | #endif // defined(BOOST_ASIO_HAS_MOVE) |
65 | |
66 | // basic_stream_descriptor operators. |
67 | |
68 | #if defined(BOOST_ASIO_HAS_MOVE) |
69 | descriptor1 = posix::stream_descriptor(ios); |
70 | descriptor1 = std::move(descriptor2); |
71 | #endif // defined(BOOST_ASIO_HAS_MOVE) |
72 | |
73 | // basic_io_object functions. |
74 | |
75 | io_service& ios_ref = descriptor1.get_io_service(); |
76 | (void)ios_ref; |
77 | |
78 | // basic_descriptor functions. |
79 | |
80 | posix::stream_descriptor::lowest_layer_type& lowest_layer |
81 | = descriptor1.lowest_layer(); |
82 | (void)lowest_layer; |
83 | |
84 | const posix::stream_descriptor& descriptor4 = descriptor1; |
85 | const posix::stream_descriptor::lowest_layer_type& lowest_layer2 |
86 | = descriptor4.lowest_layer(); |
87 | (void)lowest_layer2; |
88 | |
89 | int native_descriptor2 = -1; |
90 | descriptor1.assign(native_descriptor: native_descriptor2); |
91 | |
92 | bool is_open = descriptor1.is_open(); |
93 | (void)is_open; |
94 | |
95 | descriptor1.close(); |
96 | descriptor1.close(ec); |
97 | |
98 | posix::stream_descriptor::native_type native_descriptor3 |
99 | = descriptor1.native(); |
100 | (void)native_descriptor3; |
101 | |
102 | posix::stream_descriptor::native_handle_type native_descriptor4 |
103 | = descriptor1.native_handle(); |
104 | (void)native_descriptor4; |
105 | |
106 | posix::stream_descriptor::native_handle_type native_descriptor5 |
107 | = descriptor1.release(); |
108 | (void)native_descriptor5; |
109 | |
110 | descriptor1.cancel(); |
111 | descriptor1.cancel(ec); |
112 | |
113 | descriptor1.io_control(command&: io_control_command); |
114 | descriptor1.io_control(command&: io_control_command, ec); |
115 | |
116 | bool non_blocking1 = descriptor1.non_blocking(); |
117 | (void)non_blocking1; |
118 | descriptor1.non_blocking(mode: true); |
119 | descriptor1.non_blocking(mode: false, ec); |
120 | |
121 | bool non_blocking2 = descriptor1.native_non_blocking(); |
122 | (void)non_blocking2; |
123 | descriptor1.native_non_blocking(mode: true); |
124 | descriptor1.native_non_blocking(mode: false, ec); |
125 | |
126 | // basic_stream_descriptor functions. |
127 | |
128 | descriptor1.write_some(buffers: buffer(data&: mutable_char_buffer)); |
129 | descriptor1.write_some(buffers: buffer(data: const_char_buffer)); |
130 | descriptor1.write_some(buffers: null_buffers()); |
131 | descriptor1.write_some(buffers: buffer(data&: mutable_char_buffer), ec); |
132 | descriptor1.write_some(buffers: buffer(data: const_char_buffer), ec); |
133 | descriptor1.write_some(buffers: null_buffers(), ec); |
134 | |
135 | descriptor1.async_write_some(buffers: buffer(data&: mutable_char_buffer), |
136 | handler&: write_some_handler); |
137 | descriptor1.async_write_some(buffers: buffer(data: const_char_buffer), |
138 | handler&: write_some_handler); |
139 | descriptor1.async_write_some(buffers: null_buffers(), |
140 | handler&: write_some_handler); |
141 | int i1 = descriptor1.async_write_some(buffers: buffer(data&: mutable_char_buffer), handler&: lazy); |
142 | (void)i1; |
143 | int i2 = descriptor1.async_write_some(buffers: buffer(data: const_char_buffer), handler&: lazy); |
144 | (void)i2; |
145 | int i3 = descriptor1.async_write_some(buffers: null_buffers(), handler&: lazy); |
146 | (void)i3; |
147 | |
148 | descriptor1.read_some(buffers: buffer(data&: mutable_char_buffer)); |
149 | descriptor1.read_some(buffers: buffer(data&: mutable_char_buffer), ec); |
150 | descriptor1.read_some(buffers: null_buffers(), ec); |
151 | |
152 | descriptor1.async_read_some(buffers: buffer(data&: mutable_char_buffer), handler&: read_some_handler); |
153 | descriptor1.async_read_some(buffers: null_buffers(), handler&: read_some_handler); |
154 | int i4 = descriptor1.async_read_some(buffers: buffer(data&: mutable_char_buffer), handler&: lazy); |
155 | (void)i4; |
156 | int i5 = descriptor1.async_read_some(buffers: null_buffers(), handler&: lazy); |
157 | (void)i5; |
158 | } |
159 | catch (std::exception&) |
160 | { |
161 | } |
162 | #endif // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR) |
163 | } |
164 | |
165 | } // namespace posix_stream_descriptor_compile |
166 | |
167 | //------------------------------------------------------------------------------ |
168 | |
169 | BOOST_ASIO_TEST_SUITE |
170 | ( |
171 | "posix/stream_descriptor" , |
172 | BOOST_ASIO_TEST_CASE(posix_stream_descriptor_compile::test) |
173 | ) |
174 | |