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.
This commit is contained in:
sin-ack 2022-01-18 13:25:51 +00:00 committed by Andreas Kling
parent ab36fb7a23
commit c63feb4f09

View file

@ -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)