2014-11-25 16:47:36 +01:00
|
|
|
#include "testutils/FuseCreateAndOpenTest.h"
|
|
|
|
|
|
|
|
using ::testing::_;
|
2019-10-13 17:49:57 +02:00
|
|
|
using ::testing::Eq;
|
2014-11-25 16:47:36 +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-25 16:47:36 +01:00
|
|
|
|
|
|
|
class FuseCreateAndOpenFileDescriptorTest: public FuseCreateAndOpenTest, public WithParamInterface<int> {
|
|
|
|
public:
|
|
|
|
void CreateAndOpenAndReadFile(const char *filename) {
|
|
|
|
auto fs = TestFS();
|
|
|
|
|
2017-08-25 01:14:16 +02:00
|
|
|
auto fd = CreateAndOpenFile(fs.get(), filename);
|
|
|
|
ReadFile(fd->fd());
|
2014-11-25 16:47:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-08-25 01:14:16 +02:00
|
|
|
unique_ref<OpenFileHandle> CreateAndOpenFile(const TempTestFS *fs, const char *filename) {
|
2014-11-25 16:47:36 +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 | O_CREAT, S_IRUSR | S_IRGRP | S_IROTH);
|
2017-08-25 01:14:16 +02:00
|
|
|
EXPECT_GE(fd->fd(), 0) << "Creating file failed";
|
2014-11-25 16:47:36 +01:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
void ReadFile(int fd) {
|
2020-08-01 03:08:19 +02:00
|
|
|
uint8_t buf = 0;
|
2015-11-27 17:43:21 +01:00
|
|
|
int retval = ::read(fd, &buf, 1);
|
|
|
|
EXPECT_EQ(1, retval) << "Reading file failed";
|
2014-11-25 16:47:36 +01:00
|
|
|
}
|
|
|
|
};
|
2019-10-13 14:16:06 +02:00
|
|
|
INSTANTIATE_TEST_SUITE_P(FuseCreateAndOpenFileDescriptorTest, FuseCreateAndOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024));
|
2014-11-25 16:47:36 +01:00
|
|
|
|
|
|
|
TEST_P(FuseCreateAndOpenFileDescriptorTest, TestReturnedFileDescriptor) {
|
|
|
|
ReturnDoesntExistOnLstat(FILENAME);
|
2019-10-13 17:49:57 +02:00
|
|
|
EXPECT_CALL(*fsimpl, createAndOpenFile(Eq(FILENAME), _, _, _))
|
2014-11-25 16:47:36 +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-25 16:47:36 +01:00
|
|
|
//For the syscall to succeed, we also need to give an fstat implementation.
|
2018-09-15 23:32:58 +02:00
|
|
|
ReturnIsFileOnFstatWithSize(GetParam(), fspp::num_bytes_t(1));
|
2014-11-25 16:47:36 +01:00
|
|
|
|
|
|
|
CreateAndOpenAndReadFile(FILENAME);
|
|
|
|
}
|