extend file_handler to support reads
Problem: the upcomming version handler will need to read from files.
Currently file hander (image handler) does not support reads.
Solution: Add read support by providing an optional mode parameter.
Tests added:
FileHanderTest added to
- Test out open for reads
- Test out reading out bytes and verifying size and content
- Test out trying to read beyond EOF
- Test out offset reads that go beyond EOF
Tested:
Existing unit tests pass
New unit tests for reading all pass
Signed-off-by: Jason Ling <jasonling@google.com>
Change-Id: Ie416a6b4b452d8d04fa158bd55989d07a891896f
diff --git a/bmc/firmware-handler/test/firmware_commit_unittest.cpp b/bmc/firmware-handler/test/firmware_commit_unittest.cpp
index cb50b8e..d564de6 100644
--- a/bmc/firmware-handler/test/firmware_commit_unittest.cpp
+++ b/bmc/firmware-handler/test/firmware_commit_unittest.cpp
@@ -48,7 +48,8 @@
auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
std::move(blobs), std::move(data), CreateActionMap("asdf"));
- EXPECT_CALL(*imageMock2, open("asdf")).WillOnce(Return(true));
+ EXPECT_CALL(*imageMock2, open("asdf", std::ios::out))
+ .WillOnce(Return(true));
EXPECT_TRUE(handler->open(
0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf"));
@@ -64,7 +65,8 @@
auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
std::move(blobs), std::move(data), CreateActionMap("asdf"));
- EXPECT_CALL(*imageMock1, open(StrEq(hashBlobId))).WillOnce(Return(true));
+ EXPECT_CALL(*imageMock1, open(StrEq(hashBlobId), std::ios::out))
+ .WillOnce(Return(true));
EXPECT_TRUE(handler->open(
0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi,