From 45986c8ee2b129ff8a8df89ed8f0886a6af809e4 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Fri, 9 Apr 2021 19:53:31 +0200 Subject: [PATCH] tests/comms: Add some tests for SockAddrInet/Unix --- tests/zm_comms.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/zm_comms.cpp b/tests/zm_comms.cpp index bb05e7097..7869c424a 100644 --- a/tests/zm_comms.cpp +++ b/tests/zm_comms.cpp @@ -91,3 +91,35 @@ TEST_CASE("ZM::Pipe read/write") { REQUIRE(pipe.read(rcv.data(), rcv.size()) == -1); } } + +TEST_CASE("ZM::SockAddrInet") { + ZM::SockAddrInet addr; + REQUIRE(addr.getAddrSize() == sizeof(sockaddr_in)); + + SECTION("resolve") { + addr.resolve(80, ""); + REQUIRE(addr.getDomain() == AF_INET); + + SECTION("newSockAddr from resolved addr") { + ZM::SockAddr *addr2 = ZM::SockAddr::newSockAddr(&addr); + REQUIRE(addr2->getDomain() == AF_INET); + REQUIRE(addr2->getAddrSize() == sizeof(sockaddr_in)); + } + } +} + +TEST_CASE("ZM::SockAddrUnix") { + ZM::SockAddrUnix addr; + REQUIRE(addr.getAddrSize() == sizeof(sockaddr_un)); + + SECTION("resovle") { + addr.resolve("/", ""); + REQUIRE(addr.getDomain() == AF_UNIX); + + SECTION("newSockAddr from resolved addr") { + ZM::SockAddr *addr2 = ZM::SockAddr::newSockAddr(&addr); + REQUIRE(addr2->getDomain() == AF_UNIX); + REQUIRE(addr2->getAddrSize() == sizeof(sockaddr_un)); + } + } +}