2014-11-25 16:47:36 +01:00
|
|
|
#include "testutils/FuseCreateAndOpenTest.h"
|
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::StrEq;
|
|
|
|
using ::testing::WithParamInterface;
|
|
|
|
using ::testing::Values;
|
|
|
|
using ::testing::Return;
|
|
|
|
|
|
|
|
class FuseCreateAndOpenFileDescriptorTest: public FuseCreateAndOpenTest, public WithParamInterface<int> {
|
|
|
|
public:
|
|
|
|
void CreateAndOpenAndReadFile(const char *filename) {
|
|
|
|
auto fs = TestFS();
|
|
|
|
|
|
|
|
int fd = CreateAndOpenFile(fs.get(), filename);
|
|
|
|
ReadFile(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int CreateAndOpenFile(const TempTestFS *fs, const char *filename) {
|
|
|
|
auto realpath = fs->mountDir() / filename;
|
2015-11-24 14:33:17 +01:00
|
|
|
#if __GNUC__ == 4 && __GNUC_MINOR__ == 8
|
|
|
|
int fd = ::open(realpath.c_str(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
|
|
|
#else
|
2014-11-25 16:47:36 +01:00
|
|
|
int fd = ::open(realpath.c_str(), O_RDONLY | O_CREAT);
|
2015-11-24 14:33:17 +01:00
|
|
|
#endif
|
2014-11-25 16:47:36 +01:00
|
|
|
EXPECT_GE(fd, 0) << "Creating file failed";
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
void ReadFile(int fd) {
|
|
|
|
int retval = ::read(fd, nullptr, 0);
|
|
|
|
EXPECT_EQ(0, retval) << "Reading file failed";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
INSTANTIATE_TEST_CASE_P(FuseCreateAndOpenFileDescriptorTest, FuseCreateAndOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024));
|
|
|
|
|
|
|
|
TEST_P(FuseCreateAndOpenFileDescriptorTest, TestReturnedFileDescriptor) {
|
|
|
|
ReturnDoesntExistOnLstat(FILENAME);
|
2015-04-25 03:26:59 +02:00
|
|
|
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _))
|
2014-11-25 16:47:36 +01:00
|
|
|
.Times(1).WillOnce(Return(GetParam()));
|
|
|
|
EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(0));
|
|
|
|
//For the syscall to succeed, we also need to give an fstat implementation.
|
|
|
|
ReturnIsFileOnFstat(GetParam());
|
|
|
|
|
|
|
|
CreateAndOpenAndReadFile(FILENAME);
|
|
|
|
}
|