@@ -25,17 +25,17 @@ namespace nebula::drivers::connections
25
25
26
26
using std::chrono_literals::operator " " ms;
27
27
28
- static const char localhost_ip[] = " 127.0.0.1" ;
29
- static const char broadcast_ip[] = " 255.255.255.255" ;
30
- static const char any_ip[] = " 0.0.0.0" ;
31
- static const char multicast_group[] = " 230.1.2.3" ;
32
- static const char multicast_group2[] = " 230.4.5.6" ;
28
+ static const char * const g_localhost_ip = " 127.0.0.1" ;
29
+ static const char * const g_broadcast_ip = " 255.255.255.255" ;
30
+ static const char * const g_any_ip = " 0.0.0.0" ;
31
+ static const char * const g_multicast_group = " 230.1.2.3" ;
32
+ static const char * const g_multicast_group2 = " 230.4.5.6" ;
33
33
34
- static const char sender_ip[] = " 192.168.201" ;
35
- static const uint16_t sender_port = 7373 ;
36
- static const uint16_t host_port = 6262 ;
34
+ static const char * const g_sender_ip = " 192.168.201.100 " ;
35
+ static const uint16_t g_sender_port = 7373 ;
36
+ static const uint16_t g_host_port = 6262 ;
37
37
38
- static const std::chrono::duration send_receive_timeout = 100ms;
38
+ static const std::chrono::duration g_send_receive_timeout = 100ms;
39
39
40
40
UdpSocket::callback_t empty_cb ()
41
41
{
@@ -57,19 +57,19 @@ util::expected<uint64_t, std::string> read_sys_param(const std::string & param_f
57
57
TEST (TestUdp, TestBasicLifecycle)
58
58
{
59
59
ASSERT_NO_THROW (
60
- UdpSocket::Builder (localhost_ip, host_port ).bind ().subscribe (empty_cb ()).unsubscribe ());
60
+ UdpSocket::Builder (g_localhost_ip, g_host_port ).bind ().subscribe (empty_cb ()).unsubscribe ());
61
61
}
62
62
63
63
TEST (TestUdp, TestSpecialAddressesBind)
64
64
{
65
- ASSERT_THROW (UdpSocket::Builder (broadcast_ip, host_port ), UsageError);
66
- ASSERT_NO_THROW (UdpSocket::Builder (any_ip, host_port ).bind ());
65
+ ASSERT_THROW (UdpSocket::Builder (g_broadcast_ip, g_host_port ), UsageError);
66
+ ASSERT_NO_THROW (UdpSocket::Builder (g_any_ip, g_host_port ).bind ());
67
67
}
68
68
69
69
TEST (TestUdp, TestJoiningInvalidMulticastGroup)
70
70
{
71
71
ASSERT_THROW (
72
- UdpSocket::Builder (localhost_ip, host_port ).join_multicast_group (broadcast_ip ).bind (),
72
+ UdpSocket::Builder (g_localhost_ip, g_host_port ).join_multicast_group (g_broadcast_ip ).bind (),
73
73
SocketError);
74
74
}
75
75
@@ -81,11 +81,11 @@ TEST(TestUdp, TestBufferResize)
81
81
82
82
// Setting buffer sizes up to and including rmem_max shall succeed
83
83
ASSERT_NO_THROW (
84
- UdpSocket::Builder (localhost_ip, host_port ).set_socket_buffer_size (rmem_max).bind ());
84
+ UdpSocket::Builder (g_localhost_ip, g_host_port ).set_socket_buffer_size (rmem_max).bind ());
85
85
86
86
// Linux only supports sizes up to INT32_MAX
87
87
ASSERT_THROW (
88
- UdpSocket::Builder (localhost_ip, host_port )
88
+ UdpSocket::Builder (g_localhost_ip, g_host_port )
89
89
.set_socket_buffer_size (static_cast <size_t >(INT32_MAX) + 1 )
90
90
.bind (),
91
91
UsageError);
@@ -94,49 +94,51 @@ TEST(TestUdp, TestBufferResize)
94
94
TEST (TestUdp, TestCorrectUsageIsEnforced)
95
95
{
96
96
// The following functions can be called in any order, any number of times
97
- ASSERT_NO_THROW (UdpSocket::Builder (localhost_ip, host_port )
97
+ ASSERT_NO_THROW (UdpSocket::Builder (g_localhost_ip, g_host_port )
98
98
.set_polling_interval (20 )
99
99
.set_socket_buffer_size (3000 )
100
100
.set_mtu (1600 )
101
- .limit_to_sender (sender_ip, sender_port )
101
+ .limit_to_sender (g_sender_ip, g_sender_port )
102
102
.set_polling_interval (20 )
103
103
.set_socket_buffer_size (3000 )
104
104
.set_mtu (1600 )
105
- .set_send_destination (sender_ip, sender_port )
106
- .limit_to_sender (sender_ip, sender_port )
105
+ .set_send_destination (g_sender_ip, g_sender_port )
106
+ .limit_to_sender (g_sender_ip, g_sender_port )
107
107
.bind ());
108
108
109
109
// Only one multicast group can be joined
110
110
ASSERT_THROW (
111
- UdpSocket::Builder (localhost_ip, host_port )
112
- .join_multicast_group (multicast_group )
113
- .join_multicast_group (multicast_group2 ),
111
+ UdpSocket::Builder (g_localhost_ip, g_host_port )
112
+ .join_multicast_group (g_multicast_group )
113
+ .join_multicast_group (g_multicast_group2 ),
114
114
UsageError);
115
115
116
116
// Pre-existing subscriptions shall be gracefully unsubscribed when a new subscription is created
117
- ASSERT_NO_THROW (
118
- UdpSocket::Builder (localhost_ip, host_port).bind ().subscribe (empty_cb ()).subscribe (empty_cb ()));
117
+ ASSERT_NO_THROW (UdpSocket::Builder (g_localhost_ip, g_host_port)
118
+ .bind ()
119
+ .subscribe (empty_cb ())
120
+ .subscribe (empty_cb ()));
119
121
120
122
// Explicitly unsubscribing shall be supported
121
- ASSERT_NO_THROW (UdpSocket::Builder (localhost_ip, host_port )
123
+ ASSERT_NO_THROW (UdpSocket::Builder (g_localhost_ip, g_host_port )
122
124
.bind ()
123
125
.subscribe (empty_cb ())
124
126
.unsubscribe ()
125
127
.subscribe (empty_cb ()));
126
128
127
129
// Unsubscribing on a non-subscribed socket shall also be supported
128
- ASSERT_NO_THROW (UdpSocket::Builder (localhost_ip, host_port ).bind ().unsubscribe ());
130
+ ASSERT_NO_THROW (UdpSocket::Builder (g_localhost_ip, g_host_port ).bind ().unsubscribe ());
129
131
}
130
132
131
133
TEST (TestUdp, TestReceiving)
132
134
{
133
135
const std::vector<uint8_t > payload{1 , 2 , 3 };
134
- auto sock = UdpSocket::Builder (localhost_ip, host_port ).bind ();
136
+ auto sock = UdpSocket::Builder (g_localhost_ip, g_host_port ).bind ();
135
137
136
- auto err_no_opt = udp_send (localhost_ip, host_port , payload);
138
+ auto err_no_opt = udp_send (g_localhost_ip, g_host_port , payload);
137
139
if (err_no_opt.has_value ()) GTEST_SKIP () << strerror (err_no_opt.value ());
138
140
139
- auto result_opt = receive_once (sock, send_receive_timeout );
141
+ auto result_opt = receive_once (sock, g_send_receive_timeout );
140
142
141
143
ASSERT_TRUE (result_opt.has_value ());
142
144
auto const & [recv_payload, metadata] = result_opt.value ();
@@ -152,12 +154,12 @@ TEST(TestUdp, TestReceivingOversized)
152
154
const size_t mtu = 1500 ;
153
155
std::vector<uint8_t > payload;
154
156
payload.resize (mtu + 1 , 0x42 );
155
- auto sock = UdpSocket::Builder (localhost_ip, host_port ).set_mtu (mtu).bind ();
157
+ auto sock = UdpSocket::Builder (g_localhost_ip, g_host_port ).set_mtu (mtu).bind ();
156
158
157
- auto err_no_opt = udp_send (localhost_ip, host_port , payload);
159
+ auto err_no_opt = udp_send (g_localhost_ip, g_host_port , payload);
158
160
if (err_no_opt.has_value ()) GTEST_SKIP () << strerror (err_no_opt.value ());
159
161
160
- auto result_opt = receive_once (sock, send_receive_timeout );
162
+ auto result_opt = receive_once (sock, g_send_receive_timeout );
161
163
162
164
ASSERT_TRUE (result_opt.has_value ());
163
165
auto const & [recv_payload, metadata] = result_opt.value ();
@@ -170,13 +172,14 @@ TEST(TestUdp, TestReceivingOversized)
170
172
TEST (TestUdp, TestFilteringSender)
171
173
{
172
174
std::vector<uint8_t > payload{1 , 2 , 3 };
173
- auto sock =
174
- UdpSocket::Builder (localhost_ip, host_port).limit_to_sender (sender_ip, sender_port).bind ();
175
+ auto sock = UdpSocket::Builder (g_localhost_ip, g_host_port)
176
+ .limit_to_sender (g_sender_ip, g_sender_port)
177
+ .bind ();
175
178
176
- auto err_no_opt = udp_send (localhost_ip, host_port , payload);
179
+ auto err_no_opt = udp_send (g_localhost_ip, g_host_port , payload);
177
180
if (err_no_opt.has_value ()) GTEST_SKIP () << strerror (err_no_opt.value ());
178
181
179
- auto result_opt = receive_once (sock, send_receive_timeout );
182
+ auto result_opt = receive_once (sock, g_send_receive_timeout );
180
183
ASSERT_FALSE (result_opt.has_value ());
181
184
}
182
185
@@ -186,17 +189,17 @@ TEST(TestUdp, TestMoveable)
186
189
187
190
size_t n_received = 0 ;
188
191
189
- auto sock = UdpSocket::Builder (localhost_ip, host_port ).bind ();
192
+ auto sock = UdpSocket::Builder (g_localhost_ip, g_host_port ).bind ();
190
193
sock.subscribe ([&n_received](const auto &, const auto &) { n_received++; });
191
194
192
- auto err_no_opt = udp_send (localhost_ip, host_port , payload);
195
+ auto err_no_opt = udp_send (g_localhost_ip, g_host_port , payload);
193
196
if (err_no_opt.has_value ()) GTEST_SKIP () << strerror (err_no_opt.value ());
194
197
195
198
// The subscription moves to the new socket object
196
199
UdpSocket sock2{std::move (sock)};
197
200
ASSERT_TRUE (sock2.is_subscribed ());
198
201
199
- err_no_opt = udp_send (localhost_ip, host_port , payload);
202
+ err_no_opt = udp_send (g_localhost_ip, g_host_port , payload);
200
203
if (err_no_opt.has_value ()) GTEST_SKIP () << strerror (err_no_opt.value ());
201
204
202
205
std::this_thread::sleep_for (100ms);
@@ -208,17 +211,17 @@ TEST(TestUdp, TestSending)
208
211
const std::vector<uint8_t > payload{1 , 2 , 3 };
209
212
210
213
// A socket without a send destination shall not be able to send
211
- auto sock = UdpSocket::Builder (localhost_ip, host_port ).bind ();
214
+ auto sock = UdpSocket::Builder (g_localhost_ip, g_host_port ).bind ();
212
215
ASSERT_THROW (sock.send (payload), UsageError);
213
216
214
217
// A socket with a send destination shall be able to send
215
- auto sock2 = UdpSocket::Builder (localhost_ip, host_port )
216
- .set_send_destination (localhost_ip, host_port )
218
+ auto sock2 = UdpSocket::Builder (g_localhost_ip, g_host_port )
219
+ .set_send_destination (g_localhost_ip, g_host_port )
217
220
.bind ();
218
221
ASSERT_NO_THROW (sock2.send (payload));
219
222
220
223
// The sent payload shall be received by the destination
221
- auto result3 = receive_once (sock2, send_receive_timeout );
224
+ auto result3 = receive_once (sock2, g_send_receive_timeout );
222
225
ASSERT_TRUE (result3.has_value ());
223
226
auto const & [recv_payload, metadata] = result3.value ();
224
227
ASSERT_EQ (recv_payload, payload);
0 commit comments