Mercurial > irccd
annotate tests/src/libcommon/io/main.cpp @ 746:fe3d80412701
Irccd: load config in irccd-test
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 03 Aug 2018 12:15:00 +0200 |
parents | e8c4ba5ed1c6 |
children | 35c1517d705d |
rev | line source |
---|---|
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
1 /* |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
2 * main.cpp -- test io classes |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
3 * |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
4 * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr> |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
5 * |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
6 * Permission to use, copy, modify, and/or distribute this software for any |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
7 * purpose with or without fee is hereby granted, provided that the above |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
8 * copyright notice and this permission notice appear in all copies. |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
9 * |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
17 */ |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
18 |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
19 #define BOOST_TEST_MODULE "io" |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
20 #include <boost/test/unit_test.hpp> |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
21 #include <boost/mpl/list.hpp> |
700
91bc29e87399
Irccd: use Boost.Predef, closes #805 @1h
David Demelier <markand@malikania.fr>
parents:
670
diff
changeset
|
22 #include <boost/predef/os.h> |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
23 |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
24 #include <irccd/sysconfig.hpp> |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
25 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
26 #include <irccd/socket_acceptor.hpp> |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
27 #include <irccd/socket_connector.hpp> |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
28 #include <irccd/socket_stream.hpp> |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
29 |
701
2007a37d7e1a
CMake: prefix options with IRCCD_, #closes 800 @2h
David Demelier <markand@malikania.fr>
parents:
700
diff
changeset
|
30 #if defined(IRCCD_HAVE_SSL) |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
31 # include <irccd/tls_acceptor.hpp> |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
32 # include <irccd/tls_connector.hpp> |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
33 # include <irccd/tls_stream.hpp> |
701
2007a37d7e1a
CMake: prefix options with IRCCD_, #closes 800 @2h
David Demelier <markand@malikania.fr>
parents:
700
diff
changeset
|
34 #endif // !IRCCD_HAVE_SSL |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
35 |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
36 using boost::asio::io_service; |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
37 using boost::asio::ip::tcp; |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
38 |
701
2007a37d7e1a
CMake: prefix options with IRCCD_, #closes 800 @2h
David Demelier <markand@malikania.fr>
parents:
700
diff
changeset
|
39 #if defined(IRCCD_HAVE_SSL) |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
40 using boost::asio::ssl::context; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
41 #endif |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
42 |
700
91bc29e87399
Irccd: use Boost.Predef, closes #805 @1h
David Demelier <markand@malikania.fr>
parents:
670
diff
changeset
|
43 #if !BOOST_OS_WINDOWS |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
44 using boost::asio::local::stream_protocol; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
45 #endif |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
46 |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
47 namespace irccd { |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
48 |
723
e8c4ba5ed1c6
Tests: put code in anonymous namespaces, closes #889 @10m
David Demelier <markand@malikania.fr>
parents:
701
diff
changeset
|
49 namespace { |
e8c4ba5ed1c6
Tests: put code in anonymous namespaces, closes #889 @10m
David Demelier <markand@malikania.fr>
parents:
701
diff
changeset
|
50 |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
51 class io_test { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
52 public: |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
53 io_service service_; |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
54 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
55 std::unique_ptr<io::acceptor> acceptor_; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
56 std::unique_ptr<io::connector> connector_; |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
57 |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
58 std::shared_ptr<io::stream> stream1_; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
59 std::shared_ptr<io::stream> stream2_; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
60 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
61 virtual std::unique_ptr<io::acceptor> create_acceptor() = 0; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
62 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
63 virtual std::unique_ptr<io::connector> create_connector() = 0; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
64 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
65 void init() |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
66 { |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
67 acceptor_ = create_acceptor(); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
68 connector_ = create_connector(); |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
69 |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
70 acceptor_->accept([this] (auto code, auto stream) { |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
71 if (code) |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
72 throw std::system_error(code); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
73 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
74 stream1_ = std::move(stream); |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
75 }); |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
76 connector_->connect([this] (auto code, auto stream) { |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
77 if (code) |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
78 throw std::system_error(code); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
79 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
80 stream2_ = std::move(stream); |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
81 }); |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
82 |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
83 service_.run(); |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
84 service_.reset(); |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
85 } |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
86 }; |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
87 |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
88 class ip_io_test : public io_test { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
89 private: |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
90 tcp::endpoint endpoint_; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
91 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
92 protected: |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
93 /** |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
94 * \copydoc io_test::create_acceptor |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
95 */ |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
96 std::unique_ptr<io::acceptor> create_acceptor() override |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
97 { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
98 tcp::endpoint endpoint(tcp::v4(), 0U); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
99 tcp::acceptor acceptor(service_, std::move(endpoint)); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
100 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
101 endpoint_ = acceptor.local_endpoint(); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
102 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
103 return std::make_unique<io::ip_acceptor>(std::move(acceptor)); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
104 } |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
105 |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
106 /** |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
107 * \copydoc io_test::create_connector |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
108 */ |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
109 std::unique_ptr<io::connector> create_connector() override |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
110 { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
111 return std::make_unique<io::ip_connector>(service_, endpoint_); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
112 } |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
113 }; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
114 |
701
2007a37d7e1a
CMake: prefix options with IRCCD_, #closes 800 @2h
David Demelier <markand@malikania.fr>
parents:
700
diff
changeset
|
115 #if defined(IRCCD_HAVE_SSL) |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
116 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
117 class ssl_io_test : public io_test { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
118 private: |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
119 tcp::endpoint endpoint_; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
120 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
121 protected: |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
122 /** |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
123 * \copydoc io_test::create_acceptor |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
124 */ |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
125 std::unique_ptr<io::acceptor> create_acceptor() override |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
126 { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
127 context context(context::sslv23); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
128 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
129 context.use_certificate_file(TESTS_SOURCE_DIR "/data/test.crt", context::pem); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
130 context.use_private_key_file(TESTS_SOURCE_DIR "/data/test.key", context::pem); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
131 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
132 tcp::endpoint endpoint(tcp::v4(), 0U); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
133 tcp::acceptor acceptor(service_, std::move(endpoint)); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
134 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
135 endpoint_ = acceptor.local_endpoint(); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
136 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
137 return std::make_unique<io::tls_acceptor<>>(std::move(context), std::move(acceptor)); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
138 } |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
139 |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
140 /** |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
141 * \copydoc io_test::create_connector |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
142 */ |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
143 std::unique_ptr<io::connector> create_connector() override |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
144 { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
145 return std::make_unique<io::tls_connector<>>(context(context::sslv23), service_, endpoint_); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
146 } |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
147 }; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
148 |
701
2007a37d7e1a
CMake: prefix options with IRCCD_, #closes 800 @2h
David Demelier <markand@malikania.fr>
parents:
700
diff
changeset
|
149 #endif // !IRCCD_HAVE_SSL |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
150 |
700
91bc29e87399
Irccd: use Boost.Predef, closes #805 @1h
David Demelier <markand@malikania.fr>
parents:
670
diff
changeset
|
151 #if !BOOST_OS_WINDOWS |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
152 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
153 class local_io_test : public io_test { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
154 public: |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
155 /** |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
156 * \copydoc io_test::create_acceptor |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
157 */ |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
158 std::unique_ptr<io::acceptor> create_acceptor() override |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
159 { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
160 std::remove(CMAKE_BINARY_DIR "/tmp/io-test.sock"); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
161 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
162 stream_protocol::acceptor acceptor(service_, CMAKE_BINARY_DIR "/tmp/io-test.sock"); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
163 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
164 return std::make_unique<io::local_acceptor>(std::move(acceptor)); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
165 } |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
166 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
167 /** |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
168 * \copydoc io_test::create_connector |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
169 */ |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
170 std::unique_ptr<io::connector> create_connector() override |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
171 { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
172 return std::make_unique<io::local_connector>(service_, CMAKE_BINARY_DIR "/tmp/io-test.sock"); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
173 } |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
174 }; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
175 |
700
91bc29e87399
Irccd: use Boost.Predef, closes #805 @1h
David Demelier <markand@malikania.fr>
parents:
670
diff
changeset
|
176 #endif // !BOOST_OS_WINDOWS |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
177 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
178 /** |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
179 * List of fixtures to tests. |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
180 */ |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
181 using list = boost::mpl::list< |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
182 ip_io_test |
701
2007a37d7e1a
CMake: prefix options with IRCCD_, #closes 800 @2h
David Demelier <markand@malikania.fr>
parents:
700
diff
changeset
|
183 #if defined(IRCCD_HAVE_SSL) |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
184 , ssl_io_test |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
185 #endif |
700
91bc29e87399
Irccd: use Boost.Predef, closes #805 @1h
David Demelier <markand@malikania.fr>
parents:
670
diff
changeset
|
186 #if !BOOST_OS_WINDOWS |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
187 , local_io_test |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
188 #endif |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
189 >; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
190 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
191 BOOST_AUTO_TEST_CASE_TEMPLATE(invalid_argument, Test, list) |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
192 { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
193 Test fixture; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
194 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
195 const nlohmann::json message{ |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
196 { "abc", 123 }, |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
197 { "def", 456 } |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
198 }; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
199 |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
200 fixture.init(); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
201 fixture.stream1_->read([] (auto code, auto message) { |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
202 BOOST_TEST(!code); |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
203 BOOST_TEST(message.is_object()); |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
204 BOOST_TEST(message["abc"].template get<int>() == 123); |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
205 BOOST_TEST(message["def"].template get<int>() == 456); |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
206 }); |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
207 fixture.stream2_->write(message, [] (auto code) { |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
208 BOOST_TEST(!code); |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
209 }); |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
210 fixture.service_.run(); |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
211 } |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
212 |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
213 BOOST_AUTO_TEST_CASE_TEMPLATE(network_down, Test, list) |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
214 { |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
215 Test fixture; |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
216 |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
217 fixture.init(); |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
218 fixture.stream1_->read([] (auto code, auto message) { |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
219 BOOST_TEST(code.value() == static_cast<int>(std::errc::not_connected)); |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
220 BOOST_TEST(message.is_null()); |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
221 }); |
670
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
222 fixture.stream2_ = nullptr; |
95ac3ace1610
Common: introduce new io code
David Demelier <markand@malikania.fr>
parents:
668
diff
changeset
|
223 fixture.service_.run(); |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
224 } |
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
225 |
723
e8c4ba5ed1c6
Tests: put code in anonymous namespaces, closes #889 @10m
David Demelier <markand@malikania.fr>
parents:
701
diff
changeset
|
226 } // !namespace |
e8c4ba5ed1c6
Tests: put code in anonymous namespaces, closes #889 @10m
David Demelier <markand@malikania.fr>
parents:
701
diff
changeset
|
227 |
668
8a79b5c0ddc7
Tests: add network_stream test, closes #788 @1h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
228 } // !irccd |