1 #include "handler_unittest.hpp" 2 3 #include <blobs-ipmid/blobs.hpp> 4 5 #include <cstdint> 6 #include <vector> 7 8 #include <gtest/gtest.h> 9 10 namespace blobs 11 { 12 13 class SmbiosBlobHandlerStatCloseTest : public SmbiosBlobHandlerTest 14 { 15 protected: 16 blobs::BlobMeta meta; 17 18 // Initialize expected_meta_ with empty members 19 blobs::BlobMeta expected_meta_session = {}; 20 blobs::BlobMeta expected_meta_path = {}; 21 }; 22 23 TEST_F(SmbiosBlobHandlerStatCloseTest, InvalidSessionStatIsRejected) 24 { 25 EXPECT_FALSE(handler.stat(session, &meta)); 26 } 27 28 TEST_F(SmbiosBlobHandlerStatCloseTest, SessionStatAlwaysInitialReadAndWrite) 29 { 30 // Verify the session stat returns the information for a session. 31 32 EXPECT_TRUE(handler.open(session, blobs::OpenFlags::write, expectedBlobId)); 33 34 EXPECT_TRUE(handler.stat(session, &meta)); 35 expected_meta_session.blobState = blobs::StateFlags::open_write; 36 EXPECT_EQ(meta, expected_meta_session); 37 38 EXPECT_TRUE(handler.stat(expectedBlobId, &meta)); 39 expected_meta_path.blobState = blobs::StateFlags::open_write; 40 EXPECT_EQ(meta, expected_meta_path); 41 } 42 43 TEST_F(SmbiosBlobHandlerStatCloseTest, AfterWriteMetadataLengthMatches) 44 { 45 // Verify that after writes, the length returned matches. 46 47 std::vector<uint8_t> data = {0x01}; 48 EXPECT_TRUE(handler.open(session, blobs::OpenFlags::write, expectedBlobId)); 49 EXPECT_TRUE(handler.write(session, handlerMaxBufferSize - 1, data)); 50 51 // We wrote one byte to the last index, making the length the buffer size. 52 EXPECT_TRUE(handler.stat(session, &meta)); 53 expected_meta_session.size = handlerMaxBufferSize; 54 expected_meta_session.blobState = blobs::StateFlags::open_write; 55 EXPECT_EQ(meta, expected_meta_session); 56 57 EXPECT_TRUE(handler.stat(expectedBlobId, &meta)); 58 expected_meta_path.size = handlerMaxBufferSize; 59 expected_meta_path.blobState = blobs::StateFlags::open_write; 60 EXPECT_EQ(meta, expected_meta_path); 61 } 62 63 TEST_F(SmbiosBlobHandlerStatCloseTest, CloseWithInvalidSessionFails) 64 { 65 // Verify you cannot close an invalid session. 66 67 EXPECT_FALSE(handler.close(session)); 68 } 69 70 TEST_F(SmbiosBlobHandlerStatCloseTest, CloseWithValidSessionSuccess) 71 { 72 // Verify you can close a valid session. 73 74 EXPECT_TRUE(handler.open(session, 0, expectedBlobId)); 75 76 EXPECT_TRUE(handler.close(session)); 77 } 78 } // namespace blobs 79