2014-11-20 21:23:35 +01:00
|
|
|
#include "testutils/FuseOpenTest.h"
|
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::StrEq;
|
|
|
|
using ::testing::WithParamInterface;
|
|
|
|
using ::testing::Values;
|
|
|
|
using ::testing::Return;
|
|
|
|
|
|
|
|
class FuseOpenFileDescriptorTest: public FuseOpenTest, public WithParamInterface<int> {
|
|
|
|
public:
|
|
|
|
void OpenAndReadFile(const char *filename) {
|
|
|
|
auto fs = TestFS();
|
|
|
|
|
|
|
|
int fd = OpenFile(fs.get(), filename);
|
|
|
|
ReadFile(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int OpenFile(const TempTestFS *fs, const char *filename) {
|
|
|
|
auto realpath = fs->mountDir() / filename;
|
|
|
|
int fd = ::open(realpath.c_str(), O_RDONLY);
|
|
|
|
EXPECT_GE(fd, 0) << "Opening file failed";
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
void ReadFile(int fd) {
|
2015-11-27 17:43:21 +01:00
|
|
|
uint8_t buf;
|
|
|
|
int retval = ::read(fd, &buf, 1);
|
|
|
|
EXPECT_EQ(1, retval) << "Reading file failed";
|
2014-11-20 21:23:35 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
INSTANTIATE_TEST_CASE_P(FuseOpenFileDescriptorTest, FuseOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024));
|
|
|
|
|
|
|
|
TEST_P(FuseOpenFileDescriptorTest, TestReturnedFileDescriptor) {
|
2015-11-27 17:43:21 +01:00
|
|
|
ReturnIsFileOnLstatWithSize(FILENAME, 1);
|
2014-11-20 21:23:35 +01:00
|
|
|
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _))
|
|
|
|
.Times(1).WillOnce(Return(GetParam()));
|
2015-11-27 17:43:21 +01:00
|
|
|
EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(1));
|
2014-11-20 21:23:35 +01:00
|
|
|
|
|
|
|
OpenAndReadFile(FILENAME);
|
|
|
|
}
|
2015-11-27 17:43:21 +01:00
|
|
|
|