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
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
EXPECT_CALL(fsimpl, read(0, _, _, _)).WillRepeatedly(ReturnSuccessfulReadRegardingSize(FILESIZE));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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) {
|
2018-09-15 23:32:58 +02:00
|
|
|
char buf[READSIZE.value()];
|
|
|
|
auto retval = ReadFileReturnError(FILENAME, buf, 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) {
|
2018-09-15 23:32:58 +02:00
|
|
|
char buf[READSIZE.value()];
|
2014-12-06 15:33:01 +01:00
|
|
|
auto retval = ReadFileReturnError(FILENAME, buf, READSIZE, OFFSET);
|
|
|
|
EXPECT_EQ(FILESIZE-OFFSET, retval.read_bytes);
|
2014-11-27 03:48:38 +01:00
|
|
|
}
|