Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
code
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ReadMailReallyFast
code
Commits
8c3cfe18
Commit
8c3cfe18
authored
1 year ago
by
Benny Baumann
Browse files
Options
Downloads
Patches
Plain Diff
fix: Fix UDP socket test
Also cleans up the overall socket test code
parent
571b6343
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#10729
canceled
1 year ago
Stage: prebuild
Stage: build
Stage: testing
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/socket_test.cpp
+14
-12
14 additions, 12 deletions
test/socket_test.cpp
with
14 additions
and
12 deletions
test/socket_test.cpp
+
14
−
12
View file @
8c3cfe18
...
...
@@ -22,7 +22,9 @@
using
namespace
rmrf
::
net
;
const
std
::
string
udp_test_string
=
"TEST UDP PACKET"
;
const
std
::
string
test_string_tcp
=
"Moin from TCP"
;
const
std
::
string
test_string_udp
=
"Moin from UDP"
;
const
std
::
string
test_string_unix
=
"Moin from UNIX"
;
volatile
bool
tcp_called
=
false
;
volatile
bool
udp_called
=
false
;
...
...
@@ -60,7 +62,7 @@ void ev_thread_callable() {
}
void
udp_test_cb
(
const
iorecord
&
data
)
{
BOOST_CHECK_EQUAL
(
(
char
*
)
data
.
p
tr
(),
udp_
test_string
.
c_str
()
);
BOOST_CHECK_EQUAL
(
data
.
s
tr
(),
test_string
_udp
);
std
::
stringstream
msg_ss
;
msg_ss
<<
"Received UDP packet from: "
<<
data
.
get_address
().
str
();
BOOST_TEST_MESSAGE
(
msg_ss
.
str
());
...
...
@@ -74,12 +76,13 @@ void run_udp_test() {
const
socketaddr
source_address
=
get_first_general_socketaddr
(
"127.0.0.1"
,
9862
,
socket_t
::
UDP
);
const
socketaddr
destination_address
=
get_first_general_socketaddr
(
"127.0.0.1"
,
9863
,
socket_t
::
UDP
);
auto
sender
=
client_factory_construct_udp_client
(
source_address
,
udp_test_cb
);
auto
receiver
=
connect
(
destination_address
,
socket_t
::
UDP
);
udp_source_family
=
destination_address
.
family
();
auto
sender
=
client_factory_construct_udp_client
(
source_address
,
nullptr
);
auto
receiver
=
client_factory_construct_udp_client
(
destination_address
,
udp_test_cb
);
udp_packet
<
1024
>
data
;
data
<<
udp_
test_string
;
data
<<
test_string
_udp
;
sender
->
send_packet
(
destination_address
,
data
);
std
::
this_thread
::
yield
();
...
...
@@ -105,11 +108,11 @@ void run_tcp_test(const socketaddr& interface_addr) {
auto
client
=
connect
(
"127.0.0.1"
,
"9861"
);
client
->
set_incomming_data_callback
(
[](
const
iorecord
&
data
)
{
BOOST_CHECK_EQUAL
(
data
.
str
(),
"Moin"
);
BOOST_CHECK_EQUAL
(
data
.
str
(),
test_string_tcp
);
tcp_called
=
true
;
});
const
std
::
string
moin_string
(
"Moin"
);
client
->
write_data
(
iorecord
(
moin
_string
.
c_str
(),
moin
_string
.
length
()));
client
->
write_data
(
iorecord
(
test
_string
_tcp
.
c_str
(),
test
_string
_tcp
.
length
()));
std
::
this_thread
::
yield
();
std
::
this_thread
::
sleep_for
(
100ms
);
...
...
@@ -136,12 +139,11 @@ void run_unix_test() {
auto
client
=
connect
(
socket_name
);
client
->
set_incomming_data_callback
(
[](
const
iorecord
&
data
)
{
BOOST_CHECK_EQUAL
(
data
.
str
(),
"Moin, von UNIX"
);
BOOST_CHECK_EQUAL
(
data
.
str
(),
test_string_unix
);
unix_called
=
true
;
});
const
std
::
string
moin_string
(
"Moin, von UNIX"
);
client
->
write_data
(
iorecord
(
moin_string
.
c_str
(),
moin_string
.
length
()));
client
->
write_data
(
iorecord
(
test_string_unix
.
c_str
(),
test_string_unix
.
length
()));
std
::
this_thread
::
yield
();
std
::
this_thread
::
sleep_for
(
100ms
);
...
...
@@ -155,7 +157,7 @@ BOOST_AUTO_TEST_CASE(Netio_Socket_TCP) {
std
::
thread
ev_thread
(
ev_thread_callable
);
const
auto
interface_addr
=
get_first_general_socketaddr
(
"127.0.0.1"
,
9861
);
(
void
)
interface_addr
;
//
(void)interface_addr;
BOOST_CHECK_NO_THROW
(
run_tcp_test
(
interface_addr
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment