tests: Add a test for #19755 to the SocketTests.

This commit is contained in:
Augustin Cavalier
2025-09-17 17:05:49 -04:00
parent 17ec872f61
commit 6b4d2c8127
2 changed files with 26 additions and 2 deletions
@@ -14,7 +14,8 @@
// This test reproduces a KDL from issue #13927 where a socket is created
// and an attempt is made to connect to an address, which fails. The socket
// is closed and then reused to connect to a *different* address.
void SocketTests::ClientSocketReuseTest()
void
SocketTests::ClientSocketReuseTest()
{
// TODO: Try to find unused ports instead of using these hard-coded ones.
const uint16_t kFirstPort = 14025;
@@ -49,12 +50,34 @@ void SocketTests::ClientSocketReuseTest()
}
void SocketTests::AddTests(BTestSuite &parent) {
// This test reproduces a KDL from issue #19755.
void
SocketTests::TcpRecvmsgTest()
{
// create a client socket
int fd = socket(AF_INET, SOCK_STREAM, 0);
CPPUNIT_ASSERT(fd >= 0);
struct msghdr msg;
memset(&msg, 0, sizeof(msg));
ssize_t r = recvmsg(fd, &msg, 0);
CPPUNIT_ASSERT(r == -1);
close(fd);
}
void
SocketTests::AddTests(BTestSuite &parent)
{
CppUnit::TestSuite &suite = *new CppUnit::TestSuite("SocketTests");
suite.addTest(new CppUnit::TestCaller<SocketTests>(
"SocketTests::ClientSocketReuseTest",
&SocketTests::ClientSocketReuseTest));
suite.addTest(new CppUnit::TestCaller<SocketTests>(
"SocketTests::TcpRecvmsgTest",
&SocketTests::TcpRecvmsgTest));
parent.addTest("SocketTests", &suite);
}
@@ -7,6 +7,7 @@
class SocketTests : public BTestCase {
public:
void ClientSocketReuseTest();
void TcpRecvmsgTest();
static void AddTests(BTestSuite& suite);
};