blob: ab12125af1eeccb8e0d91c108f76d7b4514fac35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include "file_handler.hpp"
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <vector>
#include <gtest/gtest.h>
namespace ipmi_flash
{
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 ipmi_flash
|