William A. Kennington III | 9c97d2c | 2018-11-02 17:25:36 -0700 | [diff] [blame^] | 1 | #include <cstring> |
| 2 | #include <gtest/gtest.h> |
| 3 | #include <signal.h> |
| 4 | #include <stdplus/signal.hpp> |
| 5 | |
| 6 | namespace stdplus |
| 7 | { |
| 8 | namespace signal |
| 9 | { |
| 10 | namespace |
| 11 | { |
| 12 | |
| 13 | TEST(SignalTest, BlockSignal) |
| 14 | { |
| 15 | constexpr int s = SIGINT; |
| 16 | constexpr int otherS = SIGTERM; |
| 17 | constexpr int notBlocked = SIGPROF; |
| 18 | |
| 19 | sigset_t expectedSet; |
| 20 | EXPECT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &expectedSet)); |
| 21 | EXPECT_EQ(0, sigaddset(&expectedSet, otherS)); |
| 22 | EXPECT_EQ(0, sigprocmask(SIG_BLOCK, &expectedSet, nullptr)); |
| 23 | EXPECT_EQ(0, sigismember(&expectedSet, notBlocked)); |
| 24 | EXPECT_EQ(0, sigismember(&expectedSet, s)); |
| 25 | EXPECT_EQ(0, sigaddset(&expectedSet, s)); |
| 26 | |
| 27 | block(s); |
| 28 | |
| 29 | sigset_t newSet; |
| 30 | EXPECT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &newSet)); |
| 31 | EXPECT_EQ(sigismember(&expectedSet, s), sigismember(&newSet, s)); |
| 32 | EXPECT_EQ(sigismember(&expectedSet, otherS), sigismember(&newSet, otherS)); |
| 33 | EXPECT_EQ(sigismember(&expectedSet, notBlocked), |
| 34 | sigismember(&newSet, notBlocked)); |
| 35 | } |
| 36 | |
| 37 | TEST(SignalTest, KeepBlockSignal) |
| 38 | { |
| 39 | constexpr int s = SIGINT; |
| 40 | constexpr int otherS = SIGTERM; |
| 41 | constexpr int notBlocked = SIGPROF; |
| 42 | |
| 43 | sigset_t expectedSet; |
| 44 | EXPECT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &expectedSet)); |
| 45 | EXPECT_EQ(0, sigaddset(&expectedSet, s)); |
| 46 | EXPECT_EQ(0, sigaddset(&expectedSet, otherS)); |
| 47 | EXPECT_EQ(0, sigismember(&expectedSet, notBlocked)); |
| 48 | EXPECT_EQ(0, sigprocmask(SIG_BLOCK, &expectedSet, nullptr)); |
| 49 | |
| 50 | block(s); |
| 51 | |
| 52 | sigset_t newSet; |
| 53 | EXPECT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &newSet)); |
| 54 | EXPECT_EQ(sigismember(&expectedSet, s), sigismember(&newSet, s)); |
| 55 | EXPECT_EQ(sigismember(&expectedSet, otherS), sigismember(&newSet, otherS)); |
| 56 | EXPECT_EQ(sigismember(&expectedSet, notBlocked), |
| 57 | sigismember(&newSet, notBlocked)); |
| 58 | } |
| 59 | |
| 60 | } // namespace |
| 61 | } // namespace signal |
| 62 | } // namespace stdplus |