Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Endpoint.ut.cpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#include "Endpoint.hpp"
18
20
21#include <boost/test/unit_test.hpp>
22
23using namespace std;
24using namespace toolbox;
25
27
29{
30 const auto uri = "192.168.1.3:443"s;
31 const auto ep = parse_dgram_endpoint(uri);
32 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_INET);
33 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_DGRAM);
34 BOOST_CHECK_EQUAL(ep.protocol().protocol(), IPPROTO_UDP);
35 BOOST_CHECK_EQUAL(to_string(ep), "udp4://"s + uri);
36}
37
39{
40 const auto uri = "[fe80::c8bf:7d86:cbdc:bda9]:443"s;
41 const auto ep = parse_dgram_endpoint(uri);
42 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_INET6);
43 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_DGRAM);
44 BOOST_CHECK_EQUAL(ep.protocol().protocol(), IPPROTO_UDP);
45 BOOST_CHECK_EQUAL(to_string(ep), "udp6://"s + uri);
46}
47
49{
50 const auto uri = "udp4://192.168.1.3:443"s;
51 const auto ep = parse_dgram_endpoint(uri);
52 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_INET);
53 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_DGRAM);
54 BOOST_CHECK_EQUAL(ep.protocol().protocol(), IPPROTO_UDP);
56}
57
59{
60 const auto uri = "udp6://[fe80::c8bf:7d86:cbdc:bda9]:443"s;
61 const auto ep = parse_dgram_endpoint(uri);
62 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_INET6);
63 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_DGRAM);
64 BOOST_CHECK_EQUAL(ep.protocol().protocol(), IPPROTO_UDP);
66}
67
69{
70 const auto uri = "unix:///tmp/foo.sock"s;
71 const auto ep = parse_dgram_endpoint(uri);
72 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_UNIX);
73 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_DGRAM);
74 BOOST_CHECK_EQUAL(ep.protocol().protocol(), 0);
76}
77
79{
80 const auto uri = "unix://|12345"s;
81 const auto ep = parse_dgram_endpoint(uri);
82 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_UNIX);
83 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_DGRAM);
84 BOOST_CHECK_EQUAL(ep.protocol().protocol(), 0);
86}
87
89{
90 const auto uri = "192.168.1.3:443"s;
91 const auto ep = parse_stream_endpoint(uri);
92 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_INET);
93 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_STREAM);
94 BOOST_CHECK_EQUAL(ep.protocol().protocol(), IPPROTO_TCP);
95 BOOST_CHECK_EQUAL(to_string(ep), "tcp4://"s + uri);
96}
97
99{
100 const auto uri = "[fe80::c8bf:7d86:cbdc:bda9]:443"s;
101 const auto ep = parse_stream_endpoint(uri);
102 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_INET6);
103 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_STREAM);
104 BOOST_CHECK_EQUAL(ep.protocol().protocol(), IPPROTO_TCP);
105 BOOST_CHECK_EQUAL(to_string(ep), "tcp6://"s + uri);
106}
107
109{
110 const auto uri = "tcp4://192.168.1.3:443"s;
111 const auto ep = parse_stream_endpoint(uri);
112 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_INET);
113 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_STREAM);
114 BOOST_CHECK_EQUAL(ep.protocol().protocol(), IPPROTO_TCP);
116}
117
119{
120 const auto uri = "tcp6://[fe80::c8bf:7d86:cbdc:bda9]:443"s;
121 const auto ep = parse_stream_endpoint(uri);
122 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_INET6);
123 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_STREAM);
124 BOOST_CHECK_EQUAL(ep.protocol().protocol(), IPPROTO_TCP);
126}
127
129{
130 const auto uri = "unix:///tmp/foo.sock"s;
131 const auto ep = parse_stream_endpoint(uri);
132 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_UNIX);
133 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_STREAM);
134 BOOST_CHECK_EQUAL(ep.protocol().protocol(), 0);
136}
137
139{
140 const auto uri = "unix://|12345"s;
141 const auto ep = parse_stream_endpoint(uri);
142 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_UNIX);
143 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_STREAM);
144 BOOST_CHECK_EQUAL(ep.protocol().protocol(), 0);
146}
147
149{
150 const auto ep = parse_stream_endpoint("tcp4://:80");
151 BOOST_CHECK_EQUAL(ep.protocol().family(), AF_INET);
152 BOOST_CHECK_EQUAL(ep.protocol().type(), SOCK_STREAM);
153 BOOST_CHECK_EQUAL(ep.protocol().protocol(), IPPROTO_TCP);
154 BOOST_CHECK_EQUAL(to_string(ep), "tcp4://0.0.0.0:80");
155}
156
BOOST_AUTO_TEST_CASE(ParseDgramUnspec4Case)
BOOST_CHECK_EQUAL(v.size(), 10U)
STL namespace.
DgramEndpoint parse_dgram_endpoint(std::string_view uri)
Definition Endpoint.hpp:51
StreamEndpoint parse_stream_endpoint(std::string_view uri)
Definition Endpoint.hpp:57
std::string to_string(ValueT &&val)
Definition String.hpp:54
constexpr auto bind() noexcept
Definition Slot.hpp:92