1 #include "data_mock.hpp" 2 #include "firmware_handler.hpp" 3 #include "flags.hpp" 4 #include "image_mock.hpp" 5 #include "triggerable_mock.hpp" 6 #include "util.hpp" 7 8 #include <memory> 9 #include <vector> 10 11 #include <gtest/gtest.h> 12 13 namespace ipmi_flash 14 { 15 namespace 16 { 17 18 using ::testing::Return; 19 using ::testing::StrEq; 20 21 class FirmwareHandlerCommitTest : public ::testing::Test 22 { 23 protected: 24 ImageHandlerMock *imageMock1, *imageMock2; 25 std::vector<HandlerPack> blobs; 26 std::vector<DataHandlerPack> data; 27 28 void SetUp() override 29 { 30 std::unique_ptr<ImageHandlerInterface> image = 31 std::make_unique<ImageHandlerMock>(); 32 imageMock1 = reinterpret_cast<ImageHandlerMock*>(image.get()); 33 blobs.emplace_back(hashBlobId, std::move(image)); 34 35 image = std::make_unique<ImageHandlerMock>(); 36 imageMock2 = reinterpret_cast<ImageHandlerMock*>(image.get()); 37 blobs.emplace_back("asdf", std::move(image)); 38 39 data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr); 40 } 41 }; 42 43 TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage) 44 { 45 /* Verify the flash image returns failure on this command. It's a fairly 46 * artificial test. 47 */ 48 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( 49 std::move(blobs), std::move(data), CreateActionMap("asdf")); 50 51 EXPECT_CALL(*imageMock2, open("asdf", std::ios::out)) 52 .WillOnce(Return(true)); 53 54 EXPECT_TRUE(handler->open( 55 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf")); 56 57 EXPECT_FALSE(handler->commit(0, {})); 58 } 59 60 TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile) 61 { 62 /* Verify the hash file returns failure on this command. It's a fairly 63 * artificial test. 64 */ 65 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( 66 std::move(blobs), std::move(data), CreateActionMap("asdf")); 67 68 EXPECT_CALL(*imageMock1, open(StrEq(hashBlobId), std::ios::out)) 69 .WillOnce(Return(true)); 70 71 EXPECT_TRUE(handler->open( 72 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, 73 hashBlobId)); 74 75 EXPECT_FALSE(handler->commit(0, {})); 76 } 77 78 } // namespace 79 } // namespace ipmi_flash 80