Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 1 | #include "firmware_handler.hpp" |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 2 | #include "image_mock.hpp" |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 3 | |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 4 | #include <algorithm> |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 5 | #include <vector> |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 6 | |
| 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | namespace blobs |
| 10 | { |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 11 | |
| 12 | TEST(FirmwareHandlerTest, CreateEmptyListVerifyFails) |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 13 | { |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 14 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 15 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler({}, data); |
| 19 | EXPECT_EQ(handler, nullptr); |
| 20 | } |
| 21 | TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails) |
| 22 | { |
| 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 | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 27 | {"asdf", &imageMock}, |
| 28 | }; |
| 29 | |
| 30 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, {}); |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 31 | EXPECT_EQ(handler, nullptr); |
| 32 | } |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 33 | TEST(FirmwareHandlerTest, VerifyHashRequiredForHappiness) |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 34 | { |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 35 | /* This works fine only if you also pass in the hash handler. */ |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 36 | ImageHandlerMock imageMock; |
| 37 | |
| 38 | std::vector<HandlerPack> blobs = { |
| 39 | {"asdf", &imageMock}, |
| 40 | }; |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 41 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 42 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 43 | }; |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 44 | |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 45 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data); |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 46 | EXPECT_EQ(handler, nullptr); |
| 47 | |
| 48 | blobs.push_back({FirmwareBlobHandler::hashBlobID, &imageMock}); |
| 49 | |
| 50 | handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data); |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 51 | auto result = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame^] | 52 | EXPECT_EQ(3, result.size()); |
| 53 | EXPECT_EQ(3, std::count(result.begin(), result.end(), "asdf") + |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 54 | std::count(result.begin(), result.end(), |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame^] | 55 | FirmwareBlobHandler::hashBlobID) + |
| 56 | std::count(result.begin(), result.end(), |
| 57 | FirmwareBlobHandler::verifyBlobID)); |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 58 | } |
| 59 | } // namespace blobs |