blob: 26dc4fcbfd9b23338a502c5ba610347962f6b55b [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:
Patrick Williams39e7b322024-07-16 02:33:27 -050018 MockLampTest(sdbusplus::bus_t& bus, const std::string& objPath,
George Liub49b7d82021-02-08 14:10:17 +080019 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{
Patrick Williams39e7b322024-07-16 02:33:27 -050032 sdbusplus::bus_t bus = sdbusplus::bus::new_default();
George Liub49b7d82021-02-08 14:10:17 +080033 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}