2014-11-20 21:23:35 +01:00
|
|
|
#include "testutils/FuseOpenTest.h"
|
|
|
|
|
|
|
|
using ::testing::_;
|
2019-10-13 17:49:57 +02:00
|
|
|
using ::testing::Eq;
|
2014-11-20 21:23:35 +01:00
|
|
|
using ::testing::WithParamInterface;
|
|
|
|
using ::testing::Values;
|
|
|
|
using ::testing::Return;
|
2017-08-25 01:14:16 +02:00
|
|
|
using cpputils::unique_ref;
|
|
|
|
using cpputils::make_unique_ref;
|
2014-11-20 21:23:35 +01:00
|
|
|
|
|
|
|
class FuseOpenFileDescriptorTest: public FuseOpenTest, public WithParamInterface<int> {
|
|
|
|
public:
|
|
|
|
void OpenAndReadFile(const char *filename) {
|
|
|
|
auto fs = TestFS();
|
|
|
|
|
2017-08-25 01:14:16 +02:00
|
|
|
auto fd = OpenFile(fs.get(), filename);
|
|
|
|
ReadFile(fd->fd());
|
2014-11-20 21:23:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-08-25 01:14:16 +02:00
|
|
|
unique_ref<OpenFileHandle> OpenFile(const TempTestFS *fs, const char *filename) {
|
2014-11-20 21:23:35 +01:00
|
|
|
auto realpath = fs->mountDir() / filename;
|
2018-05-21 01:20:38 +02:00
|
|
|
auto fd = make_unique_ref<OpenFileHandle>(realpath.string().c_str(), O_RDONLY);
|
2017-08-25 01:14:16 +02:00
|
|
|
EXPECT_GE(fd->fd(), 0) << "Opening file failed";
|
2014-11-20 21:23:35 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
};
|
2019-10-13 14:16:06 +02:00
|
|
|
INSTANTIATE_TEST_SUITE_P(FuseOpenFileDescriptorTest, FuseOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024));
|
2014-11-20 21:23:35 +01:00
|
|
|
|
|
|
|
TEST_P(FuseOpenFileDescriptorTest, TestReturnedFileDescriptor) {
|
2018-09-15 23:32:58 +02:00
|
|
|
ReturnIsFileOnLstatWithSize(FILENAME, fspp::num_bytes_t(1));
|
2019-10-13 17:49:57 +02:00
|
|
|
EXPECT_CALL(*fsimpl, openFile(Eq(FILENAME), _))
|
2014-11-20 21:23:35 +01:00
|
|
|
.Times(1).WillOnce(Return(GetParam()));
|
2018-12-03 07:57:21 +01:00
|
|
|
EXPECT_CALL(*fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(fspp::num_bytes_t(1)));
|
2014-11-20 21:23:35 +01:00
|
|
|
|
|
|
|
OpenAndReadFile(FILENAME);
|
|
|
|
}
|
2015-11-27 17:43:21 +01:00
|
|
|
|