Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame^] | 1 | #include "data_mock.hpp" |
| 2 | #include "firmware_handler.hpp" |
| 3 | #include "image_mock.hpp" |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | namespace blobs |
| 8 | { |
| 9 | using ::testing::Eq; |
| 10 | using ::testing::Return; |
| 11 | |
| 12 | TEST(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI) |
| 13 | { |
| 14 | ImageHandlerMock imageMock1, imageMock2; |
| 15 | std::vector<HandlerPack> blobs = { |
| 16 | {FirmwareBlobHandler::hashBlobID, &imageMock1}, |
| 17 | {"asdf", &imageMock2}, |
| 18 | }; |
| 19 | |
| 20 | DataHandlerMock dataMock; |
| 21 | |
| 22 | std::vector<DataHandlerPack> data = { |
| 23 | {FirmwareBlobHandler::FirmwareUpdateFlags::ipmi, nullptr}, |
| 24 | {FirmwareBlobHandler::FirmwareUpdateFlags::lpc, &dataMock}, |
| 25 | }; |
| 26 | |
| 27 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data); |
| 28 | |
| 29 | EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true)); |
| 30 | |
| 31 | EXPECT_TRUE(handler->open( |
| 32 | 0, OpenFlags::write | FirmwareBlobHandler::FirmwareUpdateFlags::ipmi, |
| 33 | "asdf")); |
| 34 | |
| 35 | std::vector<std::uint8_t> bytes = {0xaa, 0x55}; |
| 36 | |
| 37 | EXPECT_FALSE(handler->writeMeta(0, 0, bytes)); |
| 38 | } |
| 39 | |
| 40 | TEST(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough) |
| 41 | { |
| 42 | ImageHandlerMock imageMock1, imageMock2; |
| 43 | std::vector<HandlerPack> blobs = { |
| 44 | {FirmwareBlobHandler::hashBlobID, &imageMock1}, |
| 45 | {"asdf", &imageMock2}, |
| 46 | }; |
| 47 | |
| 48 | DataHandlerMock dataMock; |
| 49 | |
| 50 | std::vector<DataHandlerPack> data = { |
| 51 | {FirmwareBlobHandler::FirmwareUpdateFlags::ipmi, nullptr}, |
| 52 | {FirmwareBlobHandler::FirmwareUpdateFlags::lpc, &dataMock}, |
| 53 | }; |
| 54 | |
| 55 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data); |
| 56 | |
| 57 | EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true)); |
| 58 | |
| 59 | EXPECT_TRUE(handler->open( |
| 60 | 0, OpenFlags::write | FirmwareBlobHandler::FirmwareUpdateFlags::lpc, |
| 61 | "asdf")); |
| 62 | |
| 63 | std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04}; |
| 64 | |
| 65 | EXPECT_CALL(dataMock, write(Eq(bytes))).WillOnce(Return(true)); |
| 66 | EXPECT_TRUE(handler->writeMeta(0, 0, bytes)); |
| 67 | } |
| 68 | |
| 69 | } // namespace blobs |