libcryfs/test/fspp/fuse/read/FuseReadOverflowTest.cpp

36 lines
1.3 KiB
C++
Raw Normal View History

2014-11-27 03:48:38 +01:00
#include "testutils/FuseReadTest.h"
#include "fspp/fs_interface/FuseErrnoException.h"
2014-11-27 03:48:38 +01:00
using namespace fspp::fuse;
2014-11-27 03:48:38 +01:00
class FuseReadOverflowTest: public FuseReadTest {
public:
2018-09-15 23:32:58 +02:00
static constexpr fspp::num_bytes_t FILESIZE = fspp::num_bytes_t(1000);
static constexpr fspp::num_bytes_t READSIZE = fspp::num_bytes_t(2000);
static constexpr fspp::num_bytes_t OFFSET = fspp::num_bytes_t(500);
2014-11-27 03:48:38 +01:00
void SetUp() override {
ReturnIsFileOnLstatWithSize(FILENAME, FILESIZE);
OnOpenReturnFileDescriptor(FILENAME, 0);
2021-04-21 08:09:00 +02:00
EXPECT_CALL(*fsimpl, read(0, testing::_, testing::_, testing::_)).WillRepeatedly(ReturnSuccessfulReadRegardingSize(FILESIZE));
2014-11-27 03:48:38 +01:00
}
};
2018-09-15 23:32:58 +02:00
constexpr fspp::num_bytes_t FuseReadOverflowTest::FILESIZE;
constexpr fspp::num_bytes_t FuseReadOverflowTest::READSIZE;
constexpr fspp::num_bytes_t FuseReadOverflowTest::OFFSET;
2018-09-03 17:58:03 +02:00
2014-11-27 03:48:38 +01:00
TEST_F(FuseReadOverflowTest, ReadMoreThanFileSizeFromBeginning) {
std::array<char, READSIZE.value()> buf{};
auto retval = ReadFileReturnError(FILENAME, buf.data(), READSIZE, fspp::num_bytes_t(0));
EXPECT_EQ(FILESIZE, retval.read_bytes);
2014-11-27 03:48:38 +01:00
}
TEST_F(FuseReadOverflowTest, ReadMoreThanFileSizeFromMiddle) {
std::array<char, READSIZE.value()> buf{};
auto retval = ReadFileReturnError(FILENAME, buf.data(), READSIZE, OFFSET);
EXPECT_EQ(FILESIZE-OFFSET, retval.read_bytes);
2014-11-27 03:48:38 +01:00
}