2016-02-11 12:53:42 +01:00
|
|
|
#include <cpp-utils/data/DataFixture.h>
|
2014-11-27 16:40:22 +01:00
|
|
|
#include "testutils/FuseWriteTest.h"
|
2015-04-25 16:43:37 +02:00
|
|
|
#include "../../testutils/InMemoryFile.h"
|
2014-11-27 16:40:22 +01:00
|
|
|
|
2016-02-11 12:53:42 +01:00
|
|
|
#include "fspp/fuse/FuseErrnoException.h"
|
2014-11-27 16:40:22 +01:00
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::Invoke;
|
|
|
|
using ::testing::Action;
|
|
|
|
|
2015-04-25 16:43:37 +02:00
|
|
|
using cpputils::DataFixture;
|
|
|
|
using cpputils::Data;
|
2014-11-27 16:40:22 +01:00
|
|
|
|
2014-11-28 14:46:45 +01:00
|
|
|
using namespace fspp::fuse;
|
2014-11-27 16:40:22 +01:00
|
|
|
|
|
|
|
class FuseWriteOverflowTest: public FuseWriteTest {
|
|
|
|
public:
|
|
|
|
size_t FILESIZE;
|
|
|
|
size_t WRITESIZE;
|
|
|
|
size_t OFFSET;
|
|
|
|
|
2015-04-25 16:43:37 +02:00
|
|
|
WriteableInMemoryFile testFile;
|
|
|
|
Data writeData;
|
2014-11-27 16:40:22 +01:00
|
|
|
|
|
|
|
FuseWriteOverflowTest(size_t filesize, size_t writesize, size_t offset)
|
2015-04-25 16:43:37 +02:00
|
|
|
: FILESIZE(filesize), WRITESIZE(writesize), OFFSET(offset), testFile(DataFixture::generate(FILESIZE)), writeData(DataFixture::generate(WRITESIZE)) {
|
2014-11-27 16:40:22 +01:00
|
|
|
ReturnIsFileOnLstatWithSize(FILENAME, FILESIZE);
|
|
|
|
OnOpenReturnFileDescriptor(FILENAME, 0);
|
|
|
|
EXPECT_CALL(fsimpl, write(0, _, _, _)).WillRepeatedly(WriteToFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This write() mock implementation writes to the stored virtual file.
|
|
|
|
Action<void(int, const void*, size_t, off_t)> WriteToFile =
|
|
|
|
Invoke([this](int, const void *buf, size_t count, off_t offset) {
|
|
|
|
testFile.write(buf, count, offset);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
class FuseWriteOverflowTestWithNonemptyFile: public FuseWriteOverflowTest {
|
|
|
|
public:
|
|
|
|
FuseWriteOverflowTestWithNonemptyFile(): FuseWriteOverflowTest(1000, 2000, 500) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(FuseWriteOverflowTestWithNonemptyFile, WriteMoreThanFileSizeFromBeginning) {
|
|
|
|
WriteFile(FILENAME, writeData.data(), WRITESIZE, 0);
|
|
|
|
|
|
|
|
EXPECT_EQ(WRITESIZE, testFile.size());
|
2015-04-25 16:43:37 +02:00
|
|
|
EXPECT_TRUE(testFile.fileContentEquals(writeData, 0));
|
2014-11-27 16:40:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FuseWriteOverflowTestWithNonemptyFile, WriteMoreThanFileSizeFromMiddle) {
|
|
|
|
WriteFile(FILENAME, writeData.data(), WRITESIZE, OFFSET);
|
|
|
|
|
|
|
|
EXPECT_EQ(OFFSET + WRITESIZE, testFile.size());
|
|
|
|
EXPECT_TRUE(testFile.regionUnchanged(0, OFFSET));
|
2015-04-25 16:43:37 +02:00
|
|
|
EXPECT_TRUE(testFile.fileContentEquals(writeData, OFFSET));
|
2014-11-27 16:40:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FuseWriteOverflowTestWithNonemptyFile, WriteAfterFileEnd) {
|
|
|
|
WriteFile(FILENAME, writeData.data(), WRITESIZE, FILESIZE + OFFSET);
|
|
|
|
|
|
|
|
EXPECT_EQ(FILESIZE + OFFSET + WRITESIZE, testFile.size());
|
|
|
|
EXPECT_TRUE(testFile.regionUnchanged(0, FILESIZE));
|
2015-04-25 16:43:37 +02:00
|
|
|
EXPECT_TRUE(testFile.fileContentEquals(writeData, FILESIZE + OFFSET));
|
2014-11-27 16:40:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class FuseWriteOverflowTestWithEmptyFile: public FuseWriteOverflowTest {
|
|
|
|
public:
|
|
|
|
FuseWriteOverflowTestWithEmptyFile(): FuseWriteOverflowTest(0, 2000, 500) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(FuseWriteOverflowTestWithEmptyFile, WriteToBeginOfEmptyFile) {
|
|
|
|
WriteFile(FILENAME, writeData.data(), WRITESIZE, 0);
|
|
|
|
|
|
|
|
EXPECT_EQ(WRITESIZE, testFile.size());
|
2015-04-25 16:43:37 +02:00
|
|
|
EXPECT_TRUE(testFile.fileContentEquals(writeData, 0));
|
2014-11-27 16:40:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FuseWriteOverflowTestWithEmptyFile, WriteAfterFileEnd) {
|
|
|
|
WriteFile(FILENAME, writeData.data(), WRITESIZE, OFFSET);
|
|
|
|
|
|
|
|
EXPECT_EQ(OFFSET + WRITESIZE, testFile.size());
|
2015-04-25 16:43:37 +02:00
|
|
|
EXPECT_TRUE(testFile.fileContentEquals(writeData, OFFSET));
|
2014-11-27 16:40:22 +01:00
|
|
|
}
|