|
22 | 22 | #include <gtest/gtest.h> |
23 | 23 | using namespace Exiv2; |
24 | 24 |
|
| 25 | +TEST(MemIo_Default, readEReturns0) |
| 26 | +{ |
| 27 | + std::vector<byte> buf(10); |
| 28 | + MemIo io; |
| 29 | + ASSERT_EQ(0, io.read(buf.data(), (long)buf.size())); |
| 30 | +} |
| 31 | + |
| 32 | +TEST(MemIo_Default, isNotAtEof) |
| 33 | +{ |
| 34 | + MemIo io; |
| 35 | + ASSERT_FALSE(io.eof()); |
| 36 | +} |
| 37 | + |
| 38 | +TEST(MemIo_Default, seekBeyondBufferSizeReturns1AndSetsEofToTrue) |
| 39 | +{ |
| 40 | + MemIo io; |
| 41 | + ASSERT_EQ(1, io.seek(1, BasicIo::beg)); |
| 42 | + ASSERT_TRUE(io.eof()); |
| 43 | +} |
| 44 | + |
| 45 | +TEST(MemIo_Default, seekBefore0Returns1ButItDoesNotSetEofToTrue) |
| 46 | +{ |
| 47 | + MemIo io; |
| 48 | + ASSERT_EQ(1, io.seek(-1, BasicIo::beg)); |
| 49 | + ASSERT_FALSE(io.eof()); |
| 50 | +} |
| 51 | + |
| 52 | +TEST(MemIo_Default, seekToEndPosition_doesNotTriggerEof) |
| 53 | +{ |
| 54 | + MemIo io; |
| 55 | + ASSERT_EQ(0, io.tell()); |
| 56 | + ASSERT_EQ(0, io.seek(0, BasicIo::end)); |
| 57 | + ASSERT_EQ(0, io.tell()); |
| 58 | + ASSERT_FALSE(io.eof()); |
| 59 | +} |
| 60 | + |
| 61 | +TEST(MemIo_Default, seekToEndPositionAndReadTriggersEof) |
| 62 | +{ |
| 63 | + MemIo io; |
| 64 | + ASSERT_EQ(0, io.seek(0, BasicIo::end)); |
| 65 | + ASSERT_EQ(0, io.tell()); |
| 66 | + |
| 67 | + std::vector<byte> buf2(64, 0); |
| 68 | + ASSERT_EQ(0, io.read(buf2.data(), 1)); // Note that we cannot even read 1 byte being at the end |
| 69 | + ASSERT_TRUE(io.eof()); |
| 70 | +} |
| 71 | + |
| 72 | +// ------------------------- |
| 73 | + |
25 | 74 | TEST(MemIo, seek_out_of_bounds_00) |
26 | 75 | { |
27 | 76 | byte buf[1024]; |
|
0 commit comments