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

39 lines
1.2 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 ::testing::_;
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));
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()];
auto retval = ReadFileReturnError(FILENAME, buf, READSIZE, OFFSET);
EXPECT_EQ(FILESIZE-OFFSET, retval.read_bytes);
2014-11-27 03:48:38 +01:00
}