mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibCore: Fix relative seeking in IODevice
The recently introduced read buffer in IODevice broke relative seeking. The amount of data in the buffer wouldn't get taken into account.
This commit is contained in:
parent
b818d4c7e3
commit
cdaa179eeb
4 changed files with 35 additions and 1 deletions
|
@ -44,3 +44,35 @@ TEST_CASE(file_readline)
|
|||
EXPECT_EQ(inputData[i], outputData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(file_get_read_position)
|
||||
{
|
||||
const String path = "10kb.txt";
|
||||
auto file = Core::File::open(path, Core::OpenMode::ReadOnly).release_value();
|
||||
|
||||
const size_t step_size = 98;
|
||||
for (size_t i = 0; i < 10240 - step_size; i += step_size) {
|
||||
auto read_buffer = file->read(step_size);
|
||||
EXPECT_EQ(read_buffer.size(), step_size);
|
||||
|
||||
for (size_t j = 0; j < read_buffer.size(); j++) {
|
||||
EXPECT_EQ(static_cast<u32>(read_buffer[j] - '0'), (i + j) % 10);
|
||||
}
|
||||
|
||||
off_t offset = 0;
|
||||
VERIFY(file->seek(0, Core::SeekMode::FromCurrentPosition, &offset));
|
||||
EXPECT_EQ(offset, static_cast<off_t>(i + step_size));
|
||||
}
|
||||
|
||||
{
|
||||
off_t offset = 0;
|
||||
VERIFY(file->seek(0, Core::SeekMode::FromEndPosition, &offset));
|
||||
EXPECT_EQ(offset, 10240);
|
||||
}
|
||||
|
||||
{
|
||||
off_t offset = 0;
|
||||
VERIFY(file->seek(0, Core::SeekMode::SetPosition, &offset));
|
||||
EXPECT_EQ(offset, 0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue