static handler: transition to generic file handler
The static layout image handler simply writes the bytes into an expected
location and the verification mechanism is responsible for doing things
with the file there. Therefore, use a file handler.
Change-Id: I97128fb04df640fe682c77ef7ee278c61293748f
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/file_handler_unittest.cpp b/test/file_handler_unittest.cpp
new file mode 100644
index 0000000..26a490d
--- /dev/null
+++ b/test/file_handler_unittest.cpp
@@ -0,0 +1,58 @@
+#include "file_handler.hpp"
+
+#include <cstdint>
+#include <cstdio>
+#include <fstream>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+namespace blobs
+{
+
+static constexpr auto TESTPATH = "test.output";
+
+class FileHandlerOpenTest : public ::testing::Test
+{
+ protected:
+ void TearDown() override
+ {
+ (void)std::remove(TESTPATH);
+ }
+};
+
+TEST_F(FileHandlerOpenTest, VerifyItIsHappy)
+{
+ /* Opening a fail may create it? */
+
+ FileHandler handler(TESTPATH);
+ EXPECT_TRUE(handler.open(""));
+
+ /* Calling open twice fails the second time. */
+ EXPECT_FALSE(handler.open(""));
+}
+
+TEST_F(FileHandlerOpenTest, VerifyWriteDataWrites)
+{
+ /* Verify writing bytes writes them... flushing data can be an issue here,
+ * so we close first.
+ */
+ FileHandler handler(TESTPATH);
+ EXPECT_TRUE(handler.open(""));
+
+ std::vector<std::uint8_t> bytes = {0x01, 0x02};
+ std::uint32_t offset = 0;
+
+ EXPECT_TRUE(handler.write(offset, bytes));
+ handler.close();
+
+ std::ifstream data;
+ data.open(TESTPATH, std::ios::binary);
+ char expectedBytes[2];
+ data.read(&expectedBytes[0], sizeof(expectedBytes));
+ EXPECT_EQ(expectedBytes[0], bytes[0]);
+ EXPECT_EQ(expectedBytes[1], bytes[1]);
+ /* annoyingly the memcmp was failing... but it's the same data. */
+}
+
+} // namespace blobs