William A. Kennington III | feef68f | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 1 | #include <gtest/gtest.h> |
| 2 | #include <sdeventplus/internal/utils.hpp> |
| 3 | #include <stdexcept> |
| 4 | #include <system_error> |
| 5 | |
| 6 | namespace sdeventplus |
| 7 | { |
| 8 | namespace internal |
| 9 | { |
| 10 | namespace |
| 11 | { |
| 12 | |
| 13 | TEST(UtilsTest, PerformCallbackSuccess) |
| 14 | { |
William A. Kennington III | 4e9e604 | 2018-07-17 16:54:36 -0700 | [diff] [blame] | 15 | EXPECT_EQ(0, performCallback(nullptr, []() {})); |
William A. Kennington III | feef68f | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | TEST(UtilsTest, SetPrepareSystemError) |
| 19 | { |
William A. Kennington III | 4e9e604 | 2018-07-17 16:54:36 -0700 | [diff] [blame] | 20 | EXPECT_EQ(-EBUSY, performCallback("system_error", []() { |
William A. Kennington III | feef68f | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 21 | throw std::system_error(EBUSY, std::generic_category()); |
| 22 | })); |
| 23 | } |
| 24 | |
| 25 | TEST(UtilsTest, SetPrepareException) |
| 26 | { |
William A. Kennington III | 4e9e604 | 2018-07-17 16:54:36 -0700 | [diff] [blame] | 27 | EXPECT_EQ(-ENOSYS, performCallback("runtime_error", []() { |
| 28 | throw std::runtime_error("Exception"); |
| 29 | })); |
William A. Kennington III | feef68f | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | TEST(UtilsTest, SetPrepareUnknownException) |
| 33 | { |
William A. Kennington III | 4e9e604 | 2018-07-17 16:54:36 -0700 | [diff] [blame] | 34 | EXPECT_EQ(-ENOSYS, |
| 35 | performCallback("unknown", []() { throw static_cast<int>(1); })); |
William A. Kennington III | feef68f | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | } // namespace |
| 39 | } // namespace internal |
| 40 | } // namespace sdeventplus |