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
44e50bf6
"README.md" did not exist on "14bac4ba622a1dd2e59ee2c06988d1c4fe08eb8c"
Commit
44e50bf6
authored
2 years ago
by
Leon Dietrich
Committed by
Benny Baumann
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
add: unix socket test case
parent
9a99da53
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/address_tests.cpp
+5
-0
5 additions, 0 deletions
test/address_tests.cpp
test/socket_test.cpp
+49
-0
49 additions, 0 deletions
test/socket_test.cpp
with
54 additions
and
0 deletions
test/address_tests.cpp
+
5
−
0
View file @
44e50bf6
...
@@ -62,3 +62,8 @@ BOOST_AUTO_TEST_CASE(Socketaddr_comparison) {
...
@@ -62,3 +62,8 @@ BOOST_AUTO_TEST_CASE(Socketaddr_comparison) {
BOOST_CHECK_NE
(
get_first_general_socketaddr
(
"[::1]"
,
"443"
),
get_first_general_socketaddr
(
"::1"
,
"80"
));
BOOST_CHECK_NE
(
get_first_general_socketaddr
(
"[::1]"
,
"443"
),
get_first_general_socketaddr
(
"::1"
,
"80"
));
BOOST_CHECK_EQUAL
(
get_first_general_socketaddr
(
"[::1]"
,
"443"
),
get_first_general_socketaddr
(
"::1"
,
"443"
));
BOOST_CHECK_EQUAL
(
get_first_general_socketaddr
(
"[::1]"
,
"443"
),
get_first_general_socketaddr
(
"::1"
,
"443"
));
}
}
BOOST_AUTO_TEST_CASE
(
Unix_socket_construction_test
)
{
const
auto
sa
=
get_first_general_socketaddr
(
"/tmp/9Lq7BNBnBycd6nxy.socket"
,
""
,
socket_t
::
UNIX
);
BOOST_CHECK_EQUAL
(
sa
.
str
(),
"FileSocket /tmp/9Lq7BNBnBycd6nxy.socket"
);
}
This diff is collapsed.
Click to expand it.
test/socket_test.cpp
+
49
−
0
View file @
44e50bf6
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#include
"net/socketaddress.hpp"
#include
"net/socketaddress.hpp"
#include
"net/sock_address_factory.hpp"
#include
"net/sock_address_factory.hpp"
#include
"net/tcp_server_socket.hpp"
#include
"net/tcp_server_socket.hpp"
#include
"net/unix_socket_server.hpp"
#include
"lib/ev/ev.hpp"
#include
"lib/ev/ev.hpp"
#include
"mumta/evloop.hpp"
#include
"mumta/evloop.hpp"
...
@@ -27,6 +28,7 @@ const std::string udp_test_string = "TEST UDP PACKET";
...
@@ -27,6 +28,7 @@ const std::string udp_test_string = "TEST UDP PACKET";
volatile
bool
tcp_called
=
false
;
volatile
bool
tcp_called
=
false
;
volatile
bool
udp_called
=
false
;
volatile
bool
udp_called
=
false
;
volatile
bool
unix_called
=
false
;
int
udp_source_family
;
int
udp_source_family
;
...
@@ -118,6 +120,38 @@ void run_tcp_test(const socketaddr& interface_addr) {
...
@@ -118,6 +120,38 @@ void run_tcp_test(const socketaddr& interface_addr) {
server
.
reset
();
server
.
reset
();
}
}
void
run_unix_test
()
{
using
namespace
std
::
chrono_literals
;
const
socketaddr
socket_name
=
get_first_general_socketaddr
(
"/tmp/9Lq7BNBnBycd6nxy.socket"
,
""
,
socket_t
::
UNIX
);
auto
server
=
std
::
make_shared
<
unix_socket_server
>
(
socket_name
,
[](
std
::
shared_ptr
<
async_server_socket
>
s
,
std
::
shared_ptr
<
connection_client
>
c
)
{
BOOST_REQUIRE
(
s
);
BOOST_REQUIRE
(
c
);
c
->
set_incomming_data_callback
(
[
c
](
const
iorecord
&
data
)
{
c
->
write_data
(
data
);
});
});
auto
client
=
connect
(
socket_name
);
client
->
set_incomming_data_callback
(
[](
const
iorecord
&
data
)
{
BOOST_CHECK_EQUAL
(
data
.
str
(),
"Moin, von UNIX"
);
unix_called
=
true
;
});
const
std
::
string
moin_string
(
"Moin, von UNIX"
);
client
->
write_data
(
iorecord
(
moin_string
.
c_str
(),
moin_string
.
length
()));
std
::
this_thread
::
yield
();
std
::
this_thread
::
sleep_for
(
100ms
);
client
.
reset
();
server
.
reset
();
}
BOOST_AUTO_TEST_CASE
(
Netio_Socket_TCP
)
{
BOOST_AUTO_TEST_CASE
(
Netio_Socket_TCP
)
{
using
namespace
std
::
chrono_literals
;
using
namespace
std
::
chrono_literals
;
...
@@ -149,3 +183,18 @@ BOOST_AUTO_TEST_CASE(Netio_Socket_UDP) {
...
@@ -149,3 +183,18 @@ BOOST_AUTO_TEST_CASE(Netio_Socket_UDP) {
BOOST_CHECK
(
udp_called
);
BOOST_CHECK
(
udp_called
);
}
}
BOOST_AUTO_TEST_CASE
(
Netio_Socket_UNIX
)
{
using
namespace
std
::
chrono_literals
;
std
::
thread
ev_thread
(
ev_thread_callable
);
BOOST_CHECK_NO_THROW
(
run_unix_test
());
// TODO put in own test while keeping same ev loop setup
// Sleep one second without using ev timer
std
::
this_thread
::
sleep_for
(
500ms
);
ev_thread
.
join
();
BOOST_CHECK
(
unix_called
);
}
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