handler: Implement read/write/close/delete
Implement read/write/close/delete as pass-through functions.
Signed-off-by: Kun Yi <kunyi@google.com>
Change-Id: I56b935b03b8048a70a168d00061c043795b90f5e
diff --git a/test/handler_open_unittest.cpp b/test/handler_open_unittest.cpp
index 1d69f24..83053ad 100644
--- a/test/handler_open_unittest.cpp
+++ b/test/handler_open_unittest.cpp
@@ -50,4 +50,68 @@
EXPECT_TRUE(handler.open(sessionId, flags, testBlobId));
}
+TEST_F(BinaryStoreBlobHandlerOpenTest, CloseFailForInvalidSession)
+{
+ uint16_t invalidSessionId = 1;
+ EXPECT_FALSE(handler.close(invalidSessionId));
+}
+
+TEST_F(BinaryStoreBlobHandlerOpenTest, CloseFailWhenStoreCloseFails)
+{
+ auto testBaseId = "/test/"s;
+ auto testBlobId = "/test/blob0"s;
+ uint16_t flags = OpenFlags::read, sessionId = 0;
+ auto bstore = std::make_unique<MockBinaryStore>();
+
+ EXPECT_CALL(*bstore, getBaseBlobId()).WillRepeatedly(Return(testBaseId));
+ EXPECT_CALL(*bstore, canHandleBlob(StartsWith(testBaseId)))
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(*bstore, openOrCreateBlob(_, flags)).WillOnce(Return(true));
+ EXPECT_CALL(*bstore, close()).WillOnce(Return(false));
+
+ handler.addNewBinaryStore(std::move(bstore));
+
+ EXPECT_TRUE(handler.open(sessionId, flags, testBlobId));
+ EXPECT_FALSE(handler.close(sessionId));
+}
+
+TEST_F(BinaryStoreBlobHandlerOpenTest, CloseSucceedWhenStoreCloseSucceeds)
+{
+ auto testBaseId = "/test/"s;
+ auto testBlobId = "/test/blob0"s;
+ uint16_t flags = OpenFlags::read, sessionId = 0;
+ auto bstore = std::make_unique<MockBinaryStore>();
+
+ EXPECT_CALL(*bstore, getBaseBlobId()).WillRepeatedly(Return(testBaseId));
+ EXPECT_CALL(*bstore, canHandleBlob(StartsWith(testBaseId)))
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(*bstore, openOrCreateBlob(_, flags)).WillOnce(Return(true));
+ EXPECT_CALL(*bstore, close()).WillOnce(Return(true));
+
+ handler.addNewBinaryStore(std::move(bstore));
+
+ EXPECT_TRUE(handler.open(sessionId, flags, testBlobId));
+ EXPECT_TRUE(handler.close(sessionId));
+}
+
+TEST_F(BinaryStoreBlobHandlerOpenTest, ClosedSessionCannotBeReclosed)
+{
+ auto testBaseId = "/test/"s;
+ auto testBlobId = "/test/blob0"s;
+ uint16_t flags = OpenFlags::read, sessionId = 0;
+ auto bstore = std::make_unique<MockBinaryStore>();
+
+ EXPECT_CALL(*bstore, getBaseBlobId()).WillRepeatedly(Return(testBaseId));
+ EXPECT_CALL(*bstore, canHandleBlob(StartsWith(testBaseId)))
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(*bstore, openOrCreateBlob(_, flags)).WillOnce(Return(true));
+ EXPECT_CALL(*bstore, close()).WillRepeatedly(Return(true));
+
+ handler.addNewBinaryStore(std::move(bstore));
+
+ EXPECT_TRUE(handler.open(sessionId, flags, testBlobId));
+ EXPECT_TRUE(handler.close(sessionId));
+ EXPECT_FALSE(handler.close(sessionId));
+}
+
} // namespace blobs