Skip to content

Commit

Permalink
iox-#1036 unit tests for cxx::perms streaming operator
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Eltzschig <me@elchris.org>
  • Loading branch information
elfenpiff committed Jan 28, 2022
1 parent 614d2ad commit 265ef57
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
1 change: 0 additions & 1 deletion iceoryx_hoofs/source/cxx/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,3 @@ template std::ostream& operator<<(std::ostream&, perms) noexcept;
template log::LogStream& operator<<(log::LogStream&, perms) noexcept;
} // namespace cxx
} // namespace iox

42 changes: 42 additions & 0 deletions iceoryx_hoofs/test/moduletests/test_cxx_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/cxx/filesystem.hpp"
#include "iceoryx_hoofs/testing/mocks/logger_mock.hpp"
#include "test.hpp"

namespace
Expand Down Expand Up @@ -104,4 +105,45 @@ TEST(filesystem_test, permsSatisfiesBinaryExclusiveOrAssignmentOperationCorrectl

EXPECT_THAT(static_cast<permsBaseType_t>(sut ^= TEST_VALUE_RHS), Eq(sutBaseValue ^= BASE_VALUE_RHS));
}

TEST(filesystem_test, permsWhenEverythingIsSetTheOutputPrintsEverything)
{
Logger_Mock loggerMock;
{
auto logStream = iox::log::LogStream(loggerMock);
logStream << perms::mask;
}

ASSERT_THAT(loggerMock.m_logs.size(), Eq(1U));
EXPECT_THAT(loggerMock.m_logs[0].message,
Eq("owner: {read, write, execute}, group: {read, write, execute}, others: {read, write, execute}, "
"special bits: {set_uid, set_git, sticky_bit}"));
}

TEST(filesystem_test, permsWhenNothingIsSetEveryEntryIsNone)
{
Logger_Mock loggerMock;
{
auto logStream = iox::log::LogStream(loggerMock);
logStream << perms::none;
}

ASSERT_THAT(loggerMock.m_logs.size(), Eq(1U));
EXPECT_THAT(loggerMock.m_logs[0].message,
Eq("owner: {none}, group: {none}, others: {none}, special bits: {none}"));
}

TEST(filesystem_test, permsWhenSomeOrSetTheOutputIsCorrect)
{
Logger_Mock loggerMock;
{
auto logStream = iox::log::LogStream(loggerMock);
logStream << (perms::owner_write | perms::owner_exec | perms::group_read | perms::group_exec | perms::others_all
| perms::sticky_bit);
}
ASSERT_THAT(loggerMock.m_logs.size(), Eq(1U));
EXPECT_THAT(loggerMock.m_logs[0].message,
Eq("owner: {write, execute}, group: {read, execute}, others: {read, write, execute}, special bits: "
"{sticky_bit}"));
}
} // namespace

0 comments on commit 265ef57

Please sign in to comment.