| // Copyright 2024 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #pragma once |
| |
| #include "ec_util_mock.hpp" |
| #include "firmware_mtd_updater.hpp" |
| #include "host_command_mock.hpp" |
| #include "mtd_mock.hpp" |
| #include "payload_update_mock.hpp" |
| #include "sys_mock.hpp" |
| |
| #include <hoth.hpp> |
| #include <sdbusplus/bus.hpp> |
| #include <sdbusplus/test/sdbus_mock.hpp> |
| |
| #include <memory> |
| |
| #include <gtest/gtest.h> |
| |
| class HothTest : public ::testing::Test |
| { |
| protected: |
| auto static constexpr TEST_PATH = "/test/path"; |
| auto static constexpr HOTH_INTERFACE = "xyz.openbmc_project.Control.Hoth"; |
| |
| HothTest() : |
| bus(sdbusplus::get_mocked_new(&sdbus_mock)), |
| firmwareUpdater( |
| std::make_unique<google::hoth::internal::FirmwareMtdUpdater>(&mtd, &sys)), |
| // Need to set up the expectations before constructing the Hoth object |
| hoth(std::make_unique<google::hoth::Hoth>(bus, TEST_PATH, &hostCmd, &payloadUpdate, |
| &ecUtil, firmwareUpdater.get())) |
| { |
| using ::testing::_; |
| using ::testing::IsNull; |
| using ::testing::Return; |
| using ::testing::StrEq; |
| EXPECT_CALL(sdbus_mock, |
| sd_bus_emit_object_added(IsNull(), StrEq(TEST_PATH))) |
| .WillRepeatedly(Return(0)); |
| EXPECT_CALL(sdbus_mock, |
| sd_bus_emit_object_removed(IsNull(), StrEq(TEST_PATH))) |
| .WillRepeatedly(Return(0)); |
| EXPECT_CALL(sdbus_mock, |
| sd_bus_add_object_vtable(IsNull(), _, StrEq(TEST_PATH), |
| StrEq(HOTH_INTERFACE), _, _)) |
| .WillRepeatedly(Return(0)); |
| |
| EXPECT_CALL(sdbus_mock, sd_bus_slot_unref(_)) |
| .WillRepeatedly(Return(nullptr)); |
| } |
| |
| // sdbus mock object |
| sdbusplus::SdBusMock sdbus_mock; |
| // sdbusplus handle |
| sdbusplus::bus::bus bus; |
| |
| // Host Command interface handle |
| google::hoth::internal::HostCommandMock hostCmd; |
| |
| // Host Command interface handle |
| google::hoth::internal::PayloadUpdateMock payloadUpdate; |
| |
| // EC Utility interface handle |
| google::hoth::internal::EcUtilMock ecUtil; |
| |
| // Mtd mock object |
| google::hoth::internal::MtdMock mtd; |
| |
| // Sys mock object |
| google::hoth::internal::SysMock sys; |
| |
| // FirmwareUpdater interface handle |
| std::unique_ptr<google::hoth::internal::FirmwareUpdater> firmwareUpdater = nullptr; |
| |
| // Hoth object |
| std::unique_ptr<google::hoth::Hoth> hoth = nullptr; |
| }; |