Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 1 | #include "data_mock.hpp" |
Patrick Venture | df848ee | 2018-11-06 15:44:00 -0800 | [diff] [blame] | 2 | #include "firmware_handler.hpp" |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 3 | #include "image_mock.hpp" |
Patrick Venture | df848ee | 2018-11-06 15:44:00 -0800 | [diff] [blame] | 4 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 5 | #include <sdbusplus/test/sdbus_mock.hpp> |
Patrick Venture | df848ee | 2018-11-06 15:44:00 -0800 | [diff] [blame] | 6 | #include <vector> |
| 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | namespace blobs |
| 11 | { |
| 12 | TEST(FirmwareHandlerCanHandleTest, VerifyItemsInListAreOk) |
| 13 | { |
Patrick Venture | df848ee | 2018-11-06 15:44:00 -0800 | [diff] [blame] | 14 | struct ListItem |
| 15 | { |
| 16 | std::string name; |
| 17 | bool expected; |
| 18 | }; |
| 19 | |
| 20 | std::vector<ListItem> items = { |
| 21 | {"asdf", true}, {"nope", false}, {"123123", false}, {"bcdf", true}}; |
| 22 | |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 23 | ImageHandlerMock imageMock; |
| 24 | |
| 25 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 26 | {FirmwareBlobHandler::hashBlobID, &imageMock}, |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 27 | {"asdf", &imageMock}, |
| 28 | {"bcdf", &imageMock}, |
| 29 | }; |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 30 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 31 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 32 | }; |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 33 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 34 | sdbusplus::SdBusMock sdbus_mock; |
| 35 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 36 | |
| 37 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
| 38 | std::move(bus_mock), blobs, data); |
Patrick Venture | df848ee | 2018-11-06 15:44:00 -0800 | [diff] [blame] | 39 | |
| 40 | for (const auto& item : items) |
| 41 | { |
| 42 | EXPECT_EQ(item.expected, handler->canHandleBlob(item.name)); |
| 43 | } |
| 44 | } |
| 45 | } // namespace blobs |