2014-11-27 03:48:38 +01:00
|
|
|
#include "testutils/FuseReadTest.h"
|
|
|
|
|
2018-05-21 08:18:34 +02:00
|
|
|
#include "fspp/fs_interface/FuseErrnoException.h"
|
2014-11-27 03:48:38 +01:00
|
|
|
|
2014-11-28 14:46:45 +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) {
|
2019-06-08 22:06:17 +02:00
|
|
|
std::array<char, READSIZE.value()> buf{};
|
|
|
|
auto retval = ReadFileReturnError(FILENAME, buf.data(), READSIZE, fspp::num_bytes_t(0));
|
2014-12-06 15:33:01 +01:00
|
|
|
EXPECT_EQ(FILESIZE, retval.read_bytes);
|
2014-11-27 03:48:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FuseReadOverflowTest, ReadMoreThanFileSizeFromMiddle) {
|
2019-06-08 22:06:17 +02:00
|
|
|
std::array<char, READSIZE.value()> buf{};
|
|
|
|
auto retval = ReadFileReturnError(FILENAME, buf.data(), READSIZE, OFFSET);
|
2014-12-06 15:33:01 +01:00
|
|
|
EXPECT_EQ(FILESIZE-OFFSET, retval.read_bytes);
|
2014-11-27 03:48:38 +01:00
|
|
|
}
|