1 #include "oem/ibm/host-bmc/host_lamp_test.hpp"
2 #include "pldmd/dbus_impl_requester.hpp"
3 #include "test/test_instance_id.hpp"
4 
5 #include <cstring>
6 
7 #include <gmock/gmock.h>
8 #include <gtest/gtest.h>
9 
10 using namespace pldm::led;
11 using ::testing::DoAll;
12 using ::testing::Return;
13 using ::testing::SetArgPointee;
14 
15 class MockLampTest : public HostLampTest
16 {
17   public:
MockLampTest(sdbusplus::bus_t & bus,const std::string & objPath,uint8_t mctp_eid,pldm::InstanceIdDb & instanceIdDb,pldm_pdr * repo,pldm::requester::Handler<pldm::requester::Request> * handler)18     MockLampTest(sdbusplus::bus_t& bus, const std::string& objPath,
19                  uint8_t mctp_eid, pldm::InstanceIdDb& instanceIdDb,
20                  pldm_pdr* repo,
21                  pldm::requester::Handler<pldm::requester::Request>* handler) :
22         HostLampTest(bus, objPath, mctp_eid, instanceIdDb, repo, handler)
23     {}
24 
25     MOCK_METHOD(uint16_t, getEffecterID, (), (override));
26     MOCK_METHOD(uint8_t, setHostStateEffecter, (uint16_t effecterId),
27                 (override));
28 };
29 
TEST(TestLamp,Asserted)30 TEST(TestLamp, Asserted)
31 {
32     sdbusplus::bus_t bus = sdbusplus::bus::new_default();
33     TestInstanceIdDb instanceIdDb;
34 
35     MockLampTest lampTest(bus, "/xyz/openbmc_project/led/groups/host_lamp_test",
36                           0, instanceIdDb, nullptr, nullptr);
37 
38     lampTest.asserted(false);
39     EXPECT_EQ(lampTest.asserted(), false);
40 
41     EXPECT_CALL(lampTest, getEffecterID())
42         .Times(2)
43         .WillOnce(Return(0))
44         .WillOnce(Return(1));
45     EXPECT_CALL(lampTest, setHostStateEffecter(1)).Times(1).WillOnce(Return(0));
46 
47     ASSERT_THROW(lampTest.asserted(true), sdbusplus::exception::SdBusError);
48 
49     lampTest.asserted(true);
50     EXPECT_EQ(lampTest.asserted(), true);
51 }
52