blob: 7d756496a98a4279c42a712b8b5bbd3b63839baa [file] [log] [blame]
George Liub49b7d82021-02-08 14:10:17 +08001#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 <string.h>
6
7#include <gmock/gmock.h>
8#include <gtest/gtest.h>
9
10using namespace pldm::led;
11using ::testing::DoAll;
12using ::testing::Return;
13using ::testing::SetArgPointee;
14
15class MockLampTest : public HostLampTest
16{
17 public:
18 MockLampTest(sdbusplus::bus::bus& 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
30TEST(TestLamp, Asserted)
31{
32 sdbusplus::bus::bus 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}