diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2022-01-18 13:25:51 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-20 10:40:51 +0100 |
commit | c63feb4f09c3ac195b46bc734450904f9d75e899 (patch) | |
tree | eb24c693186b890f1bd5161ae46e73cd0df0582f /Tests | |
parent | ab36fb7a238d48f520772e3d28962bb994b2e668 (diff) | |
download | serenity-c63feb4f09c3ac195b46bc734450904f9d75e899.zip |
Tests: Add should_error_when_connection_fails test to TestLibCoreStream
This test makes sure that Socket classes such as TCPSocket properly
return an error when connection fails rather than crashing or creating
an invalid object.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/LibCore/TestLibCoreStream.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Tests/LibCore/TestLibCoreStream.cpp b/Tests/LibCore/TestLibCoreStream.cpp index f0926e2da3..ec9b35fa10 100644 --- a/Tests/LibCore/TestLibCoreStream.cpp +++ b/Tests/LibCore/TestLibCoreStream.cpp @@ -140,6 +140,18 @@ TEST_CASE(file_adopt_invalid_fd) // TCPSocket tests +TEST_CASE(should_error_when_connection_fails) +{ + // NOTE: This is required here because Core::TCPSocket requires + // Core::EventLoop through Core::Notifier. + Core::EventLoop event_loop; + + auto maybe_tcp_socket = Core::Stream::TCPSocket::connect({ { 127, 0, 0, 1 }, 1234 }); + EXPECT(maybe_tcp_socket.is_error()); + EXPECT(maybe_tcp_socket.error().is_syscall()); + EXPECT(maybe_tcp_socket.error().code() == ECONNREFUSED); +} + constexpr auto sent_data = "Mr. Watson, come here. I want to see you."sv; TEST_CASE(tcp_socket_read) |