mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
add unit test
This commit is contained in:
parent
10b8684003
commit
ae1fc94fb5
@ -234,6 +234,7 @@ void ReadBufferFromFileDescriptor::rewind()
|
||||
working_buffer.resize(0);
|
||||
pos = working_buffer.begin();
|
||||
file_offset_of_buffer_end = 0;
|
||||
buffer_is_dirty = true;
|
||||
}
|
||||
|
||||
|
||||
|
36
src/IO/tests/gtest_seek_backwards.cpp
Normal file
36
src/IO/tests/gtest_seek_backwards.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <Common/filesystemHelpers.h>
|
||||
#include <IO/WriteBufferFromFile.h>
|
||||
#include <IO/ReadBufferFromFile.h>
|
||||
#include <IO/WriteHelpers.h>
|
||||
#include <IO/ReadHelpers.h>
|
||||
|
||||
using namespace DB;
|
||||
|
||||
TEST(ReadBufferFromFile, seekBackwards)
|
||||
{
|
||||
static constexpr size_t N = 256;
|
||||
static constexpr size_t BUF_SIZE = 64;
|
||||
|
||||
auto tmp_file = createTemporaryFile("/tmp/");
|
||||
|
||||
{
|
||||
WriteBufferFromFile out(tmp_file->path());
|
||||
for (size_t i = 0; i < N; ++i)
|
||||
writeIntBinary(i, out);
|
||||
}
|
||||
|
||||
ReadBufferFromFile in(tmp_file->path(), BUF_SIZE);
|
||||
size_t x;
|
||||
|
||||
/// Read something to initialize the buffer.
|
||||
in.seek(BUF_SIZE * 10, SEEK_SET);
|
||||
readIntBinary(x, in);
|
||||
|
||||
/// Check 2 consecutive seek calls without reading.
|
||||
in.seek(BUF_SIZE * 2, SEEK_SET);
|
||||
in.seek(BUF_SIZE, SEEK_SET);
|
||||
|
||||
readIntBinary(x, in);
|
||||
ASSERT_EQ(x, 8);
|
||||
}
|
Loading…
Reference in New Issue
Block a user