blob: 3ca2695f86da61896ae78522701c86a0c4fe9c7c [file] [log] [blame]
#include <signal.h>
#include <stdplus/signal.hpp>
#include <cstring>
#include <gtest/gtest.h>
namespace stdplus
{
namespace signal
{
namespace
{
TEST(Signal, Block)
{
constexpr int s = SIGINT;
constexpr int otherS = SIGTERM;
constexpr int notBlocked = SIGPROF;
sigset_t expectedSet;
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &expectedSet));
ASSERT_EQ(0, sigaddset(&expectedSet, otherS));
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &expectedSet, nullptr));
ASSERT_EQ(0, sigismember(&expectedSet, notBlocked));
ASSERT_EQ(0, sigismember(&expectedSet, s));
ASSERT_EQ(0, sigaddset(&expectedSet, s));
block(s);
sigset_t newSet;
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &newSet));
EXPECT_EQ(sigismember(&expectedSet, s), sigismember(&newSet, s));
EXPECT_EQ(sigismember(&expectedSet, otherS), sigismember(&newSet, otherS));
EXPECT_EQ(sigismember(&expectedSet, notBlocked),
sigismember(&newSet, notBlocked));
}
TEST(Signal, StayBlocked)
{
constexpr int s = SIGINT;
constexpr int otherS = SIGTERM;
constexpr int notBlocked = SIGPROF;
sigset_t expectedSet;
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &expectedSet));
ASSERT_EQ(0, sigaddset(&expectedSet, s));
ASSERT_EQ(0, sigaddset(&expectedSet, otherS));
ASSERT_EQ(0, sigismember(&expectedSet, notBlocked));
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &expectedSet, nullptr));
block(s);
sigset_t newSet;
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &newSet));
EXPECT_EQ(sigismember(&expectedSet, s), sigismember(&newSet, s));
EXPECT_EQ(sigismember(&expectedSet, otherS), sigismember(&newSet, otherS));
EXPECT_EQ(sigismember(&expectedSet, notBlocked),
sigismember(&newSet, notBlocked));
}
} // namespace
} // namespace signal
} // namespace stdplus