1 #include "scheduled_host_transition.hpp" 2 3 #include <gmock/gmock.h> 4 #include <gtest/gtest.h> 5 #include <sdbusplus/bus.hpp> 6 #include <sdbusplus/test/sdbus_mock.hpp> 7 #include <xyz/openbmc_project/ScheduledTime/error.hpp> 8 9 namespace phosphor 10 { 11 namespace state 12 { 13 namespace manager 14 { 15 16 using namespace std::chrono; 17 using InvalidTimeError = 18 sdbusplus::xyz::openbmc_project::ScheduledTime::Error::InvalidTime; 19 20 class TestScheduledHostTransition : public testing::Test 21 { 22 public: 23 sdbusplus::SdBusMock sdbusMock; 24 sdbusplus::bus::bus mockedBus = sdbusplus::get_mocked_new(&sdbusMock); 25 ScheduledHostTransition scheduledHostTransition; 26 27 TestScheduledHostTransition() : scheduledHostTransition(mockedBus, "") 28 { 29 // Empty 30 } 31 32 seconds getCurrentTime() 33 { 34 return scheduledHostTransition.getTime(); 35 } 36 }; 37 38 TEST_F(TestScheduledHostTransition, disableHostTransition) 39 { 40 EXPECT_EQ(scheduledHostTransition.scheduledTime(0), 0); 41 } 42 43 TEST_F(TestScheduledHostTransition, invalidScheduledTime) 44 { 45 // scheduled time is 1 min earlier than current time 46 uint64_t schTime = 47 static_cast<uint64_t>((getCurrentTime() - seconds(60)).count()); 48 EXPECT_THROW(scheduledHostTransition.scheduledTime(schTime), 49 InvalidTimeError); 50 } 51 52 } // namespace manager 53 } // namespace state 54 } // namespace phosphor 55