William A. Kennington III | 0a816c5 | 2018-07-17 14:40:14 -0700 | [diff] [blame] | 1 | #include <gmock/gmock.h> |
| 2 | #include <gtest/gtest.h> |
| 3 | #include <sdeventplus/internal/sdevent.hpp> |
| 4 | #include <sdeventplus/source/base.hpp> |
| 5 | #include <sdeventplus/test/sdevent.hpp> |
| 6 | #include <type_traits> |
| 7 | |
| 8 | namespace sdeventplus |
| 9 | { |
| 10 | namespace source |
| 11 | { |
| 12 | namespace |
| 13 | { |
| 14 | |
| 15 | using testing::Return; |
| 16 | |
| 17 | class BaseImpl : public Base |
| 18 | { |
| 19 | public: |
| 20 | BaseImpl(sd_event_source* source, internal::SdEvent* sdevent) : |
| 21 | Base(source, sdevent) |
| 22 | { |
| 23 | } |
| 24 | BaseImpl(sd_event_source* source, std::false_type, |
| 25 | internal::SdEvent* sdevent) : |
| 26 | Base(source, std::false_type(), sdevent) |
| 27 | { |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | class BaseTest : public testing::Test |
| 32 | { |
| 33 | protected: |
| 34 | testing::StrictMock<test::SdEventMock> mock; |
| 35 | sd_event_source* const expected_source = |
| 36 | reinterpret_cast<sd_event_source*>(1234); |
| 37 | }; |
| 38 | |
| 39 | TEST_F(BaseTest, NewBaseRef) |
| 40 | { |
| 41 | EXPECT_CALL(mock, sd_event_source_ref(expected_source)) |
| 42 | .WillOnce(Return(expected_source)); |
| 43 | BaseImpl source(expected_source, &mock); |
| 44 | |
| 45 | EXPECT_CALL(mock, sd_event_source_unref(expected_source)) |
| 46 | .WillOnce(Return(nullptr)); |
| 47 | } |
| 48 | |
| 49 | TEST_F(BaseTest, NewBaseNoRef) |
| 50 | { |
| 51 | BaseImpl source(expected_source, std::false_type(), &mock); |
| 52 | |
| 53 | EXPECT_CALL(mock, sd_event_source_unref(expected_source)) |
| 54 | .WillOnce(Return(nullptr)); |
| 55 | } |
| 56 | |
| 57 | } // namespace |
| 58 | } // namespace source |
| 59 | } // namespace sdeventplus |