Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 27ac582 | 2019-05-20 17:39:31 -0700 | [diff] [blame] | 3 | #include "bmc_update_mock.hpp" |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 4 | #include "data_mock.hpp" |
| 5 | #include "firmware_handler.hpp" |
| 6 | #include "image_mock.hpp" |
| 7 | #include "verification_mock.hpp" |
| 8 | |
| 9 | #include <memory> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include <gmock/gmock.h> |
| 13 | #include <gtest/gtest.h> |
| 14 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 15 | namespace ipmi_flash |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 16 | { |
| 17 | |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 18 | class IpmiOnlyFirmwareStaticTest : public ::testing::Test |
| 19 | { |
| 20 | protected: |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 21 | void SetUp() override |
| 22 | { |
| 23 | blobs = { |
| 24 | {hashBlobId, &imageMock}, |
| 25 | {staticLayoutBlobId, &imageMock}, |
| 26 | }; |
Patrick Venture | 19044e1 | 2019-05-23 19:30:28 -0700 | [diff] [blame] | 27 | |
| 28 | std::unique_ptr<VerificationInterface> verifyMock = |
| 29 | std::make_unique<VerificationMock>(); |
| 30 | verifyMockPtr = reinterpret_cast<VerificationMock*>(verifyMock.get()); |
| 31 | |
Patrick Venture | 1a406fe | 2019-05-31 07:29:56 -0700 | [diff] [blame^] | 32 | std::unique_ptr<UpdateInterface> updateMock = |
| 33 | std::make_unique<UpdateMock>(); |
| 34 | updateMockPtr = reinterpret_cast<UpdateMock*>(updateMock.get()); |
| 35 | |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 36 | handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 1a406fe | 2019-05-31 07:29:56 -0700 | [diff] [blame^] | 37 | blobs, data, std::move(verifyMock), std::move(updateMock)); |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 38 | } |
Patrick Venture | 19044e1 | 2019-05-23 19:30:28 -0700 | [diff] [blame] | 39 | |
Patrick Venture | 6fdd02e | 2019-05-28 13:02:04 -0700 | [diff] [blame] | 40 | void expectedState(FirmwareBlobHandler::UpdateState state) |
| 41 | { |
| 42 | auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get()); |
| 43 | EXPECT_EQ(state, realHandler->getCurrentState()); |
| 44 | } |
| 45 | |
Patrick Venture | 19044e1 | 2019-05-23 19:30:28 -0700 | [diff] [blame] | 46 | ImageHandlerMock imageMock; |
| 47 | std::vector<HandlerPack> blobs; |
| 48 | std::vector<DataHandlerPack> data = { |
| 49 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}}; |
| 50 | std::unique_ptr<blobs::GenericBlobInterface> handler; |
| 51 | VerificationMock* verifyMockPtr; |
Patrick Venture | 1a406fe | 2019-05-31 07:29:56 -0700 | [diff] [blame^] | 52 | UpdateMock* updateMockPtr; |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 55 | class IpmiOnlyFirmwareTest : public ::testing::Test |
| 56 | { |
| 57 | protected: |
| 58 | ImageHandlerMock imageMock; |
| 59 | std::vector<HandlerPack> blobs; |
| 60 | std::vector<DataHandlerPack> data = { |
| 61 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}}; |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 62 | std::unique_ptr<blobs::GenericBlobInterface> handler; |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 63 | |
| 64 | void SetUp() override |
| 65 | { |
| 66 | blobs = { |
| 67 | {hashBlobId, &imageMock}, |
| 68 | {"asdf", &imageMock}, |
| 69 | }; |
| 70 | handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 27ac582 | 2019-05-20 17:39:31 -0700 | [diff] [blame] | 71 | blobs, data, CreateVerifyMock(), CreateUpdateMock()); |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 72 | } |
| 73 | }; |
| 74 | |
| 75 | class FakeLpcFirmwareTest : public ::testing::Test |
| 76 | { |
| 77 | protected: |
| 78 | DataHandlerMock dataMock; |
| 79 | ImageHandlerMock imageMock; |
| 80 | std::vector<HandlerPack> blobs; |
| 81 | std::vector<DataHandlerPack> data; |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 82 | std::unique_ptr<blobs::GenericBlobInterface> handler; |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 83 | |
| 84 | void SetUp() override |
| 85 | { |
| 86 | blobs = { |
| 87 | {hashBlobId, &imageMock}, |
| 88 | {"asdf", &imageMock}, |
| 89 | }; |
| 90 | data = { |
| 91 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
| 92 | {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock}, |
| 93 | }; |
| 94 | handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 27ac582 | 2019-05-20 17:39:31 -0700 | [diff] [blame] | 95 | blobs, data, CreateVerifyMock(), CreateUpdateMock()); |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 96 | } |
| 97 | }; |
| 98 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 99 | } // namespace ipmi_flash |