blob: 21dc6a00efc9e55ab53a0ee9ab71f0046dae6e2a [file] [log] [blame]
Patrick Venture1cde5f92018-11-07 08:26:47 -08001#include "data_mock.hpp"
Patrick Venturedf848ee2018-11-06 15:44:00 -08002#include "firmware_handler.hpp"
Patrick Venturea78e39f2018-11-06 18:37:06 -08003#include "image_mock.hpp"
Patrick Venturedf848ee2018-11-06 15:44:00 -08004
Patrick Venture4eb55952018-11-16 15:36:24 -08005#include <sdbusplus/test/sdbus_mock.hpp>
Patrick Venturedf848ee2018-11-06 15:44:00 -08006#include <vector>
7
8#include <gtest/gtest.h>
9
10namespace blobs
11{
12TEST(FirmwareHandlerCanHandleTest, VerifyItemsInListAreOk)
13{
Patrick Venturedf848ee2018-11-06 15:44:00 -080014 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 Venturea78e39f2018-11-06 18:37:06 -080023 ImageHandlerMock imageMock;
24
25 std::vector<HandlerPack> blobs = {
Patrick Venture18235e62018-11-08 10:21:09 -080026 {FirmwareBlobHandler::hashBlobID, &imageMock},
Patrick Venturea78e39f2018-11-06 18:37:06 -080027 {"asdf", &imageMock},
28 {"bcdf", &imageMock},
29 };
Patrick Venture1cde5f92018-11-07 08:26:47 -080030 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080031 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080032 };
Patrick Venturea78e39f2018-11-06 18:37:06 -080033
Patrick Venture4eb55952018-11-16 15:36:24 -080034 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 Venturedf848ee2018-11-06 15:44:00 -080039
40 for (const auto& item : items)
41 {
42 EXPECT_EQ(item.expected, handler->canHandleBlob(item.name));
43 }
44}
45} // namespace blobs