1 #include "data_mock.hpp" 2 #include "firmware_handler.hpp" 3 #include "firmware_unittest.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 <gmock/gmock.h> 12 #include <gtest/gtest.h> 13 14 namespace ipmi_flash 15 { 16 namespace 17 { 18 19 using ::testing::Return; 20 using ::testing::StrEq; 21 22 class FirmwareHandlerCloseTest : public FakeLpcFirmwareTest 23 {}; 24 25 TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithDataHandler) 26 { 27 /* Boring test where you open a blob_id, then verify that when it's closed 28 * everything looks right. 29 */ 30 EXPECT_CALL(*dataMock, open()).WillOnce(Return(true)); 31 EXPECT_CALL(*hashImageMock, open(StrEq(hashBlobId), std::ios::out)) 32 .WillOnce(Return(true)); 33 34 EXPECT_TRUE( 35 handler->open(0, 36 static_cast<std::uint16_t>(blobs::OpenFlags::write) | 37 FirmwareFlags::UpdateFlags::lpc, 38 hashBlobId)); 39 40 /* The active hash blob_id was added. */ 41 auto currentBlobs = handler->getBlobIds(); 42 EXPECT_EQ(3, currentBlobs.size()); 43 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), 44 activeHashBlobId)); 45 46 /* Set up close() expectations. */ 47 EXPECT_CALL(*dataMock, close()); 48 EXPECT_CALL(*hashImageMock, close()); 49 EXPECT_TRUE(handler->close(0)); 50 51 /* Close does not delete the active blob id. This indicates that there is 52 * data queued. 53 */ 54 } 55 56 TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithoutDataHandler) 57 { 58 /* Boring test where you open a blob_id using ipmi, so there's no data 59 * handler, and it's closed and everything looks right. 60 */ 61 EXPECT_CALL(*hashImageMock, open(StrEq(hashBlobId), std::ios::out)) 62 .WillOnce(Return(true)); 63 64 EXPECT_TRUE( 65 handler->open(0, 66 static_cast<std::uint16_t>(blobs::OpenFlags::write) | 67 FirmwareFlags::UpdateFlags::ipmi, 68 hashBlobId)); 69 70 /* The active hash blob_id was added. */ 71 auto currentBlobs = handler->getBlobIds(); 72 EXPECT_EQ(3, currentBlobs.size()); 73 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), 74 activeHashBlobId)); 75 76 /* Set up close() expectations. */ 77 EXPECT_CALL(*hashImageMock, close()); 78 EXPECT_TRUE(handler->close(0)); 79 } 80 81 } // namespace 82 } // namespace ipmi_flash 83