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))).WillOnce(Return(true)); 32 33 EXPECT_TRUE(handler->open( 34 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc, 35 hashBlobId)); 36 37 /* The active hash blob_id was added. */ 38 auto currentBlobs = handler->getBlobIds(); 39 EXPECT_EQ(3, currentBlobs.size()); 40 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), 41 activeHashBlobId)); 42 43 /* Set up close() expectations. */ 44 EXPECT_CALL(*dataMock, close()); 45 EXPECT_CALL(*hashImageMock, close()); 46 EXPECT_TRUE(handler->close(0)); 47 48 /* Close does not delete the active blob id. This indicates that there is 49 * data queued. 50 */ 51 } 52 53 TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithoutDataHandler) 54 { 55 /* Boring test where you open a blob_id using ipmi, so there's no data 56 * handler, and it's closed and everything looks right. 57 */ 58 EXPECT_CALL(*hashImageMock, open(StrEq(hashBlobId))).WillOnce(Return(true)); 59 60 EXPECT_TRUE(handler->open( 61 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, 62 hashBlobId)); 63 64 /* The active hash blob_id was added. */ 65 auto currentBlobs = handler->getBlobIds(); 66 EXPECT_EQ(3, currentBlobs.size()); 67 EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), 68 activeHashBlobId)); 69 70 /* Set up close() expectations. */ 71 EXPECT_CALL(*hashImageMock, close()); 72 EXPECT_TRUE(handler->close(0)); 73 } 74 75 } // namespace 76 } // namespace ipmi_flash 77