Skip to content

Commit

Permalink
[posix] Add posix Cli Daemon module: unit test update
Browse files Browse the repository at this point in the history
  • Loading branch information
yangsong-cnyn committed Feb 20, 2025
1 parent bffbb89 commit b9057c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/host/posix/cli_daemon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ namespace otbr {
class CliDaemon
{
public:
CliDaemon();
CliDaemon(void);

void Init(const std::string &aNetIfName);

std::string GetSocketFilename(const char *aSuffix) const;

private:
void CreateListenSocketOrDie(void);

std::string GetSocketFilename(const char *aSuffix) const;

int mListenSocket;
int mDaemonLock;

Expand Down
21 changes: 11 additions & 10 deletions tests/gtest/test_cli_daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,31 @@

TEST(CliDaemon, InitSocketCreationWithFullNetIfName)
{
const char *netif_name = "tun0";
const char *netIfName = "tun0";
const char *socketFile = "openthread-tun0.sock";
const char *lockFile = "openthread-tun0.lock";

otbr::CliDaemon cliDaemon;
cliDaemon.Init(netif_name);
cliDaemon.Init(netIfName);

struct stat st;
std::string socketFile = cliDaemon.GetSocketFilename(".sock");
std::string lockFile = cliDaemon.GetSocketFilename(".lock");

EXPECT_EQ(stat(socketFile.c_str(), &st), 0);
EXPECT_EQ(stat(lockFile.c_str(), &st), 0);
EXPECT_EQ(stat(socketFile, &st), 0);
EXPECT_EQ(stat(lockFile, &st), 0);
}

TEST(CliDaemon, InitSocketCreationWithEmptyNetIfName)
{
const char *socketFile = "openthread-wpan0.sock";
const char *lockFile = "openthread-wpan0.lock";

otbr::CliDaemon cliDaemon;
cliDaemon.Init("");

struct stat st;
std::string socketFile = cliDaemon.GetSocketFilename(".sock");
std::string lockFile = cliDaemon.GetSocketFilename(".lock");

EXPECT_EQ(stat(socketFile.c_str(), &st), 0);
EXPECT_EQ(stat(lockFile.c_str(), &st), 0);
EXPECT_EQ(stat(socketFile, &st), 0);
EXPECT_EQ(stat(lockFile, &st), 0);
}

#endif // __linux__

0 comments on commit b9057c5

Please sign in to comment.