test/net/TestLocalSocketAddress: add unit tests for GetLocalRaw()

This commit is contained in:
Max Kellermann 2024-05-03 13:32:06 +02:00 committed by Max Kellermann
parent 73509fc189
commit 3813433e02
1 changed files with 7 additions and 0 deletions

View File

@ -9,6 +9,8 @@
#include <sys/un.h> #include <sys/un.h>
using std::string_view_literals::operator""sv;
TEST(LocalSocketAddress, Path1) TEST(LocalSocketAddress, Path1)
{ {
const char *path = "/run/foo/bar.socket"; const char *path = "/run/foo/bar.socket";
@ -17,6 +19,7 @@ TEST(LocalSocketAddress, Path1)
EXPECT_TRUE(a.IsDefined()); EXPECT_TRUE(a.IsDefined());
EXPECT_EQ(a.GetFamily(), AF_LOCAL); EXPECT_EQ(a.GetFamily(), AF_LOCAL);
EXPECT_EQ(ToString(a), path); EXPECT_EQ(ToString(a), path);
EXPECT_EQ(a.GetLocalRaw(), "/run/foo/bar.socket\0"sv);
EXPECT_STREQ(a.GetLocalPath(), path); EXPECT_STREQ(a.GetLocalPath(), path);
const struct sockaddr *const sa = a; const struct sockaddr *const sa = a;
@ -32,6 +35,7 @@ TEST(LocalSocketAddress, Path2)
EXPECT_TRUE(a.IsDefined()); EXPECT_TRUE(a.IsDefined());
EXPECT_EQ(a.GetFamily(), AF_LOCAL); EXPECT_EQ(a.GetFamily(), AF_LOCAL);
EXPECT_EQ(ToString(a), path); EXPECT_EQ(ToString(a), path);
EXPECT_EQ(a.GetLocalRaw(), "/run/foo/bar.socket\0"sv);
EXPECT_STREQ(a.GetLocalPath(), path); EXPECT_STREQ(a.GetLocalPath(), path);
const struct sockaddr *const sa = a; const struct sockaddr *const sa = a;
@ -49,6 +53,7 @@ TEST(LocalSocketAddress, Path)
EXPECT_TRUE(a.IsDefined()); EXPECT_TRUE(a.IsDefined());
EXPECT_EQ(a.GetFamily(), AF_LOCAL); EXPECT_EQ(a.GetFamily(), AF_LOCAL);
EXPECT_EQ(ToString(a), path); EXPECT_EQ(ToString(a), path);
EXPECT_EQ(a.GetLocalRaw(), "/run/foo/bar.socket\0"sv);
EXPECT_STREQ(a.GetLocalPath(), path); EXPECT_STREQ(a.GetLocalPath(), path);
const auto &sun = *(const struct sockaddr_un *)a.GetAddress(); const auto &sun = *(const struct sockaddr_un *)a.GetAddress();
@ -66,6 +71,7 @@ TEST(LocalSocketAddress, Abstract1)
EXPECT_TRUE(a.IsDefined()); EXPECT_TRUE(a.IsDefined());
EXPECT_EQ(a.GetFamily(), AF_LOCAL); EXPECT_EQ(a.GetFamily(), AF_LOCAL);
EXPECT_EQ(ToString(a), path); EXPECT_EQ(ToString(a), path);
EXPECT_EQ(a.GetLocalRaw(), "\0foo.bar"sv);
EXPECT_EQ(a.GetLocalPath(), nullptr); EXPECT_EQ(a.GetLocalPath(), nullptr);
const struct sockaddr *const sa = a; const struct sockaddr *const sa = a;
@ -88,6 +94,7 @@ TEST(LocalSocketAddress, Abstract)
EXPECT_TRUE(a.IsDefined()); EXPECT_TRUE(a.IsDefined());
EXPECT_EQ(a.GetFamily(), AF_LOCAL); EXPECT_EQ(a.GetFamily(), AF_LOCAL);
EXPECT_EQ(ToString(a), path); EXPECT_EQ(ToString(a), path);
EXPECT_EQ(a.GetLocalRaw(), "\0foo.bar"sv);
EXPECT_EQ(a.GetLocalPath(), nullptr); EXPECT_EQ(a.GetLocalPath(), nullptr);
const auto &sun = *(const struct sockaddr_un *)a.GetAddress(); const auto &sun = *(const struct sockaddr_un *)a.GetAddress();