- Allow callback when fuse filesystem is mounted

- Use that callback to initialize the file system instead of initializing it up front
This commit is contained in:
Sebastian Messmer 2018-12-03 01:57:21 -05:00
parent 175d7b4f26
commit 449133e3da
64 changed files with 301 additions and 172 deletions

View File

@ -67,8 +67,8 @@ using gitversion::VersionCompare;
namespace cryfs {
Cli::Cli(RandomGenerator &keyGenerator, const SCryptSettings& scryptSettings, shared_ptr<Console> console):
_keyGenerator(keyGenerator), _scryptSettings(scryptSettings), _console(), _noninteractive(false) {
Cli::Cli(RandomGenerator &keyGenerator, const SCryptSettings &scryptSettings, shared_ptr<Console> console):
_keyGenerator(keyGenerator), _scryptSettings(scryptSettings), _console(), _noninteractive(false), _idleUnmounter(none), _device(none) {
_noninteractive = Environment::isNoninteractive();
if (_noninteractive) {
_console = make_shared<NoninteractiveConsole>(console);
@ -221,23 +221,29 @@ namespace cryfs {
void Cli::_runFilesystem(const ProgramOptions &options) {
try {
LocalStateDir localStateDir(Environment::localStateDir());
auto blockStore = make_unique_ref<OnDiskBlockStore2>(options.baseDir());
auto config = _loadOrCreateConfig(options, localStateDir);
CryDevice device(std::move(config.configFile), std::move(blockStore), std::move(localStateDir), config.myClientId,
options.allowIntegrityViolations(), config.configFile.config()->missingBlockIsIntegrityViolation());
_sanityCheckFilesystem(&device);
fspp::FilesystemImpl fsimpl(&device);
fspp::fuse::Fuse fuse(&fsimpl, "cryfs", "cryfs@" + options.baseDir().string());
LocalStateDir localStateDir(Environment::localStateDir());
auto blockStore = make_unique_ref<OnDiskBlockStore2>(options.baseDir());
auto config = _loadOrCreateConfig(options, localStateDir);
const bool missingBlockIsIntegrityViolation = config.configFile.config()->missingBlockIsIntegrityViolation();
_device = optional<unique_ref<CryDevice>>(make_unique_ref<CryDevice>(std::move(config.configFile), std::move(blockStore), std::move(localStateDir), config.myClientId,
options.allowIntegrityViolations(), missingBlockIsIntegrityViolation));
_sanityCheckFilesystem(_device->get());
_initLogfile(options);
auto initFilesystem = [this, &options] (fspp::fuse::Fuse *fuse){
ASSERT(_device != none, "File system not ready to be initialized. Was it already initialized before?");
//TODO Test auto unmounting after idle timeout
//TODO This can fail due to a race condition if the filesystem isn't started yet (e.g. passing --unmount-idle 0").
auto idleUnmounter = _createIdleCallback(options.unmountAfterIdleMinutes(), [&fuse] { fuse.stop(); });
if (idleUnmounter != none) {
device.onFsAction(std::bind(&CallAfterTimeout::resetTimer, idleUnmounter->get()));
}
//TODO Test auto unmounting after idle timeout
_idleUnmounter = _createIdleCallback(options.unmountAfterIdleMinutes(), [fuse] {fuse->stop();});
if (_idleUnmounter != none) {
(*_device)->onFsAction(std::bind(&CallAfterTimeout::resetTimer, _idleUnmounter->get()));
}
return make_shared<fspp::FilesystemImpl>(std::move(*_device));
};
auto fuse = make_unique_ref<fspp::fuse::Fuse>(initFilesystem, "cryfs", "cryfs@" + options.baseDir().string());
_initLogfile(options);
#ifdef __APPLE__
std::cout << "\nMounting filesystem. To unmount, call:\n$ umount " << options.mountDir() << "\n" << std::endl;
@ -245,7 +251,7 @@ namespace cryfs {
std::cout << "\nMounting filesystem. To unmount, call:\n$ fusermount -u " << options.mountDir() << "\n"
<< std::endl;
#endif
fuse.run(options.mountDir(), options.fuseOptions());
fuse->run(options.mountDir(), options.fuseOptions());
} catch (const CryfsException &e) {
throw; // CryfsException is only thrown if setup goes wrong. Throw it through so that we get the correct process exit code.
} catch (const std::exception &e) {

View File

@ -48,6 +48,8 @@ namespace cryfs {
cpputils::SCryptSettings _scryptSettings;
std::shared_ptr<cpputils::Console> _console;
bool _noninteractive;
boost::optional<cpputils::unique_ref<CallAfterTimeout>> _idleUnmounter;
boost::optional<cpputils::unique_ref<CryDevice>> _device;
DISALLOW_COPY_AND_ASSIGN(Cli);
};

View File

@ -8,12 +8,15 @@
#include <cpp-utils/assert/assert.h>
#include <cpp-utils/logging/logging.h>
#include <csignal>
#include "InvalidFilesystem.h"
using std::vector;
using std::string;
namespace bf = boost::filesystem;
using namespace cpputils::logging;
using std::make_shared;
using std::shared_ptr;
using namespace fspp::fuse;
namespace {
@ -226,8 +229,8 @@ Fuse::~Fuse() {
_argv.clear();
}
Fuse::Fuse(Filesystem *fs, std::string fstype, boost::optional<std::string> fsname)
:_fs(fs), _mountdir(), _running(false), _fstype(std::move(fstype)), _fsname(std::move(fsname)) {
Fuse::Fuse(std::function<shared_ptr<Filesystem> (Fuse *fuse)> init, std::string fstype, boost::optional<std::string> fsname)
:_init(std::move(init)), _fs(make_shared<InvalidFilesystem>()), _mountdir(), _running(false), _fstype(std::move(fstype)), _fsname(std::move(fsname)) {
}
void Fuse::_logException(const std::exception &e) {
@ -717,7 +720,6 @@ int Fuse::write(const bf::path &path, const char *buf, size_t size, int64_t offs
}
}
//TODO
int Fuse::statfs(const bf::path &path, struct ::statvfs *fsstat) {
#ifdef FSPP_LOG
LOG(DEBUG, "statfs({}, _)", path);
@ -859,6 +861,8 @@ int Fuse::fsyncdir(const bf::path &path, int datasync, fuse_file_info *fileinfo)
void Fuse::init(fuse_conn_info *conn) {
UNUSED(conn);
_fs = _init(this);
LOG(INFO, "Filesystem started.");
_running = true;
@ -869,8 +873,10 @@ void Fuse::init(fuse_conn_info *conn) {
}
void Fuse::destroy() {
_fs = make_shared<InvalidFilesystem>();
LOG(INFO, "Filesystem stopped.");
_running = false;
cpputils::logging::logger()->flush();
}
int Fuse::access(const bf::path &path, int mask) {

View File

@ -21,7 +21,7 @@ class Filesystem;
class Fuse final {
public:
explicit Fuse(Filesystem *fs, std::string fstype, boost::optional<std::string> fsname);
explicit Fuse(std::function<std::shared_ptr<Filesystem> (Fuse *fuse)> init, std::string fstype, boost::optional<std::string> fsname);
~Fuse();
void run(const boost::filesystem::path &mountdir, const std::vector<std::string> &fuseOptions);
@ -68,7 +68,8 @@ private:
std::vector<char *> _build_argv(const boost::filesystem::path &mountdir, const std::vector<std::string> &fuseOptions);
void _add_fuse_option_if_not_exists(std::vector<char *> *argv, const std::string &key, const std::string &value);
Filesystem *_fs;
std::function<std::shared_ptr<Filesystem> (Fuse *fuse)> _init;
std::shared_ptr<Filesystem> _fs;
boost::filesystem::path _mountdir;
std::vector<char*> _argv;
std::atomic<bool> _running;

View File

@ -0,0 +1,110 @@
#pragma once
#ifndef MESSMER_FSPP_FUSE_INVALIDFILESYSTEM_H_
#define MESSMER_FSPP_FUSE_INVALIDFILESYSTEM_H_
#include "Filesystem.h"
namespace fspp {
namespace fuse {
class InvalidFilesystem final : public Filesystem {
int createAndOpenFile(const boost::filesystem::path &, ::mode_t , ::uid_t , ::gid_t ) override {
throw std::logic_error("Filesystem not initialized yet");
}
int openFile(const boost::filesystem::path &, int ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void flush(int ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void closeFile(int ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void lstat(const boost::filesystem::path &, fspp::fuse::STAT *) override {
throw std::logic_error("Filesystem not initialized yet");
}
void fstat(int , fspp::fuse::STAT *) override {
throw std::logic_error("Filesystem not initialized yet");
}
void chmod(const boost::filesystem::path &, ::mode_t ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void chown(const boost::filesystem::path &, ::uid_t , ::gid_t ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void truncate(const boost::filesystem::path &, fspp::num_bytes_t ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void ftruncate(int , fspp::num_bytes_t ) override {
throw std::logic_error("Filesystem not initialized yet");
}
fspp::num_bytes_t read(int , void *, fspp::num_bytes_t , fspp::num_bytes_t ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void write(int , const void *, fspp::num_bytes_t , fspp::num_bytes_t ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void fsync(int ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void fdatasync(int ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void access(const boost::filesystem::path &, int ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void mkdir(const boost::filesystem::path &, ::mode_t , ::uid_t , ::gid_t ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void rmdir(const boost::filesystem::path &) override {
throw std::logic_error("Filesystem not initialized yet");
}
void unlink(const boost::filesystem::path &) override {
throw std::logic_error("Filesystem not initialized yet");
}
void rename(const boost::filesystem::path &, const boost::filesystem::path &) override {
throw std::logic_error("Filesystem not initialized yet");
}
void utimens(const boost::filesystem::path &, timespec , timespec ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void statfs(struct ::statvfs *) override {
throw std::logic_error("Filesystem not initialized yet");
}
cpputils::unique_ref<std::vector<Dir::Entry>> readDir(const boost::filesystem::path &) override {
throw std::logic_error("Filesystem not initialized yet");
}
void createSymlink(const boost::filesystem::path &, const boost::filesystem::path &, ::uid_t , ::gid_t ) override {
throw std::logic_error("Filesystem not initialized yet");
}
void readSymlink(const boost::filesystem::path &, char *, fspp::num_bytes_t ) override {
throw std::logic_error("Filesystem not initialized yet");
}
};
}
}
#endif

View File

@ -32,7 +32,7 @@ using namespace cpputils::logging;
#define PROFILE(name)
#endif
FilesystemImpl::FilesystemImpl(Device *device)
FilesystemImpl::FilesystemImpl(cpputils::unique_ref<Device> device)
:
#ifdef FSPP_PROFILE
_loadFileNanosec(0), _loadDirNanosec(0), _loadSymlinkNanosec(0), _openFileNanosec(0), _flushNanosec(0),
@ -44,7 +44,7 @@ FilesystemImpl::FilesystemImpl(Device *device)
_utimensNanosec(0), _statfsNanosec(0), _createSymlinkNanosec(0), _createSymlinkNanosec_withoutLoading(0),
_readSymlinkNanosec(0), _readSymlinkNanosec_withoutLoading(0),
#endif
_device(device), _open_files()
_device(std::move(device)), _open_files()
{
}

View File

@ -21,7 +21,7 @@ class OpenFile;
class FilesystemImpl final: public fuse::Filesystem {
public:
explicit FilesystemImpl(Device *device);
explicit FilesystemImpl(cpputils::unique_ref<Device> device);
virtual ~FilesystemImpl();
int openFile(const boost::filesystem::path &path, int flags) override;
@ -93,7 +93,7 @@ private:
std::atomic<uint64_t> _readSymlinkNanosec_withoutLoading;
#endif
Device *_device;
cpputils::unique_ref<Device> _device;
FuseOpenFileList _open_files;
DISALLOW_COPY_AND_ASSIGN(FilesystemImpl);

View File

@ -17,7 +17,7 @@ INSTANTIATE_TEST_CASE_P(FuseAccessErrorTest, FuseAccessErrorTest, Values(EACCES,
TEST_P(FuseAccessErrorTest, ReturnedErrorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, access(StrEq(FILENAME), _))
EXPECT_CALL(*fsimpl, access(StrEq(FILENAME), _))
.Times(AtLeast(1)).WillRepeatedly(Throw(FuseErrnoException(GetParam())));
int error = AccessFileReturnError(FILENAME, 0);

View File

@ -9,7 +9,7 @@ class FuseAccessFilenameTest: public FuseAccessTest {
TEST_F(FuseAccessFilenameTest, AccessFile) {
ReturnIsFileOnLstat("/myfile");
EXPECT_CALL(fsimpl, access(StrEq("/myfile"), _))
EXPECT_CALL(*fsimpl, access(StrEq("/myfile"), _))
.Times(1).WillOnce(Return());
AccessFile("/myfile", 0);
@ -18,7 +18,7 @@ TEST_F(FuseAccessFilenameTest, AccessFile) {
TEST_F(FuseAccessFilenameTest, AccessFileNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsFileOnLstat("/mydir/myfile");
EXPECT_CALL(fsimpl, access(StrEq("/mydir/myfile"), _))
EXPECT_CALL(*fsimpl, access(StrEq("/mydir/myfile"), _))
.Times(1).WillOnce(Return());
AccessFile("/mydir/myfile", 0);
@ -28,7 +28,7 @@ TEST_F(FuseAccessFilenameTest, AccessFileNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsFileOnLstat("/mydir/mydir2/myfile");
EXPECT_CALL(fsimpl, access(StrEq("/mydir/mydir2/myfile"), _))
EXPECT_CALL(*fsimpl, access(StrEq("/mydir/mydir2/myfile"), _))
.Times(1).WillOnce(Return());
AccessFile("/mydir/mydir2/myfile", 0);

View File

@ -12,7 +12,7 @@ INSTANTIATE_TEST_CASE_P(FuseAccessModeTest, FuseAccessModeTest, Values(0, F_OK,
TEST_P(FuseAccessModeTest, AccessFile) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, access(StrEq(FILENAME), GetParam()))
EXPECT_CALL(*fsimpl, access(StrEq(FILENAME), GetParam()))
.Times(1).WillOnce(Return());
AccessFile(FILENAME, GetParam());

View File

@ -79,11 +79,11 @@ INSTANTIATE_TEST_CASE_P(FuseCloseTest, FuseCloseTest, Values(0, 1, 2, 100, 1024*
Barrier barrier;
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _)).WillOnce(Return(GetParam()));
EXPECT_CALL(*fsimpl, openFile(StrEq(FILENAME), _)).WillOnce(Return(GetParam()));
{
//InSequence fileCloseSequence;
EXPECT_CALL(fsimpl, flush(Eq(GetParam()))).Times(1);
EXPECT_CALL(fsimpl, closeFile(Eq(GetParam()))).Times(1).WillOnce(Invoke([&barrier] (int) {
EXPECT_CALL(*fsimpl, flush(Eq(GetParam()))).Times(1);
EXPECT_CALL(*fsimpl, closeFile(Eq(GetParam()))).Times(1).WillOnce(Invoke([&barrier] (int) {
// Release the waiting lock at the end of this test case, because the fuse release() came in now.
barrier.Release();
}));

View File

@ -17,7 +17,7 @@ INSTANTIATE_TEST_CASE_P(FuseCreateAndOpenErrorTest, FuseCreateAndOpenErrorTest,
TEST_F(FuseCreateAndOpenErrorTest, ReturnNoError) {
ReturnDoesntExistOnLstat(FILENAME);
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _)).Times(1).WillOnce(Return(1));
EXPECT_CALL(*fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _)).Times(1).WillOnce(Return(1));
//For the syscall to succeed, we also need to give an fstat implementation.
ReturnIsFileOnFstat(1);
@ -27,7 +27,7 @@ TEST_F(FuseCreateAndOpenErrorTest, ReturnNoError) {
TEST_P(FuseCreateAndOpenErrorTest, ReturnError) {
ReturnDoesntExistOnLstat(FILENAME);
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
EXPECT_CALL(*fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = CreateAndOpenFileReturnError(FILENAME, O_RDONLY);
EXPECT_EQ(GetParam(), error);

View File

@ -34,9 +34,9 @@ INSTANTIATE_TEST_CASE_P(FuseCreateAndOpenFileDescriptorTest, FuseCreateAndOpenFi
TEST_P(FuseCreateAndOpenFileDescriptorTest, TestReturnedFileDescriptor) {
ReturnDoesntExistOnLstat(FILENAME);
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _))
EXPECT_CALL(*fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _))
.Times(1).WillOnce(Return(GetParam()));
EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(fspp::num_bytes_t(1)));
EXPECT_CALL(*fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(fspp::num_bytes_t(1)));
//For the syscall to succeed, we also need to give an fstat implementation.
ReturnIsFileOnFstatWithSize(GetParam(), fspp::num_bytes_t(1));

View File

@ -10,7 +10,7 @@ public:
TEST_F(FuseCreateAndOpenFilenameTest, CreateAndOpenFile) {
ReturnDoesntExistOnLstat("/myfile");
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq("/myfile"), _, _, _))
EXPECT_CALL(*fsimpl, createAndOpenFile(StrEq("/myfile"), _, _, _))
.Times(1).WillOnce(Return(0));
//For the syscall to succeed, we also need to give an fstat implementation.
ReturnIsFileOnFstat(0);
@ -21,7 +21,7 @@ TEST_F(FuseCreateAndOpenFilenameTest, CreateAndOpenFile) {
TEST_F(FuseCreateAndOpenFilenameTest, CreateAndOpenFileNested) {
ReturnIsDirOnLstat("/mydir");
ReturnDoesntExistOnLstat("/mydir/myfile");
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq("/mydir/myfile"), _, _, _))
EXPECT_CALL(*fsimpl, createAndOpenFile(StrEq("/mydir/myfile"), _, _, _))
.Times(1).WillOnce(Return(0));
//For the syscall to succeed, we also need to give an fstat implementation.
ReturnIsFileOnFstat(0);
@ -33,7 +33,7 @@ TEST_F(FuseCreateAndOpenFilenameTest, CreateAndOpenFileNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnDoesntExistOnLstat("/mydir/mydir2/myfile");
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq("/mydir/mydir2/myfile"), _, _, _))
EXPECT_CALL(*fsimpl, createAndOpenFile(StrEq("/mydir/mydir2/myfile"), _, _, _))
.Times(1).WillOnce(Return(0));
//For the syscall to succeed, we also need to give an fstat implementation.
ReturnIsFileOnFstat(0);

View File

@ -10,7 +10,7 @@ INSTANTIATE_TEST_CASE_P(FuseCreateAndOpenFlagsTest, FuseCreateAndOpenFlagsTest,
//TODO Disabled because it doesn't seem to work. Fuse doesn't seem to pass flags to create(). Why?
/*TEST_P(FuseCreateAndOpenFlagsTest, testFlags) {
ReturnDoesntExistOnLstat(FILENAME);
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), OpenFlagsEq(GetParam()), _, _))
EXPECT_CALL(*fsimpl, createAndOpenFile(StrEq(FILENAME), OpenFlagsEq(GetParam()), _, _))
.Times(1).WillOnce(Return(0));
//For the syscall to succeed, we also need to give an fstat implementation.
ReturnIsFileOnFstat(0);

View File

@ -15,7 +15,7 @@ INSTANTIATE_TEST_CASE_P(FuseFdatasyncErrorTest, FuseFdatasyncErrorTest, Values(E
TEST_P(FuseFdatasyncErrorTest, ReturnedErrorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, fdatasync(0))
EXPECT_CALL(*fsimpl, fdatasync(0))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = FdatasyncFileReturnError(FILENAME);

View File

@ -17,7 +17,7 @@ INSTANTIATE_TEST_CASE_P(FuseFdatasyncFileDescriptorTest, FuseFdatasyncFileDescri
TEST_P(FuseFdatasyncFileDescriptorTest, FileDescriptorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
OnOpenReturnFileDescriptor(FILENAME, GetParam());
EXPECT_CALL(fsimpl, fdatasync(Eq(GetParam())))
EXPECT_CALL(*fsimpl, fdatasync(Eq(GetParam())))
.Times(1).WillOnce(Return());
FdatasyncFile(FILENAME);

View File

@ -19,8 +19,8 @@ INSTANTIATE_TEST_CASE_P(FuseFlushErrorTest, FuseFlushErrorTest, Values(EBADF, EI
TEST_P(FuseFlushErrorTest, ReturnErrorFromFlush) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _)).WillOnce(Return(GetParam()));
EXPECT_CALL(fsimpl, flush(Eq(GetParam()))).Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
EXPECT_CALL(*fsimpl, openFile(StrEq(FILENAME), _)).WillOnce(Return(GetParam()));
EXPECT_CALL(*fsimpl, flush(Eq(GetParam()))).Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
auto fs = TestFS();
auto fd = OpenFile(fs.get(), FILENAME);

View File

@ -27,8 +27,8 @@ INSTANTIATE_TEST_CASE_P(FuseFlushFileDescriptorTest, FuseFlushFileDescriptorTest
TEST_P(FuseFlushFileDescriptorTest, FlushOnCloseFile) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _)).WillOnce(Return(GetParam()));
EXPECT_CALL(fsimpl, flush(Eq(GetParam()))).Times(1);
EXPECT_CALL(*fsimpl, openFile(StrEq(FILENAME), _)).WillOnce(Return(GetParam()));
EXPECT_CALL(*fsimpl, flush(Eq(GetParam()))).Times(1);
OpenAndCloseFile(FILENAME);
}

View File

@ -29,7 +29,7 @@ TEST_P(FuseFstatErrorTest, ReturnedErrorCodeIsCorrect) {
ReturnDoesntExistOnLstat(FILENAME);
OnCreateAndOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, fstat(Eq(0), _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
EXPECT_CALL(*fsimpl, fstat(Eq(0), _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
auto fs = TestFS();

View File

@ -28,7 +28,7 @@ TEST_P(FuseFstatParameterTest, FileDescriptorIsCorrect) {
ReturnDoesntExistOnLstat(FILENAME);
OnCreateAndOpenReturnFileDescriptor(FILENAME, GetParam());
EXPECT_CALL(fsimpl, fstat(Eq(GetParam()), _)).Times(1).WillOnce(ReturnIsFileFstat);
EXPECT_CALL(*fsimpl, fstat(Eq(GetParam()), _)).Times(1).WillOnce(ReturnIsFileFstat);
CallFstat(FILENAME);
}

View File

@ -25,5 +25,5 @@ unique_ref<OpenFileHandle> FuseFstatTest::CreateFileAllowErrors(const TempTestFS
}
void FuseFstatTest::OnCreateAndOpenReturnFileDescriptor(const char *filename, int descriptor) {
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(filename), _, _, _)).Times(1).WillOnce(Return(descriptor));
EXPECT_CALL(*fsimpl, createAndOpenFile(StrEq(filename), _, _, _)).Times(1).WillOnce(Return(descriptor));
}

View File

@ -15,7 +15,7 @@ INSTANTIATE_TEST_CASE_P(FuseFsyncErrorTest, FuseFsyncErrorTest, Values(EBADF, EI
TEST_P(FuseFsyncErrorTest, ReturnedErrorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, fsync(0))
EXPECT_CALL(*fsimpl, fsync(0))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = FsyncFileReturnError(FILENAME);

View File

@ -17,7 +17,7 @@ INSTANTIATE_TEST_CASE_P(FuseFsyncFileDescriptorTest, FuseFsyncFileDescriptorTest
TEST_P(FuseFsyncFileDescriptorTest, FileDescriptorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
OnOpenReturnFileDescriptor(FILENAME, GetParam());
EXPECT_CALL(fsimpl, fsync(Eq(GetParam())))
EXPECT_CALL(*fsimpl, fsync(Eq(GetParam())))
.Times(1).WillOnce(Return());
FsyncFile(FILENAME);

View File

@ -16,7 +16,7 @@ INSTANTIATE_TEST_CASE_P(FuseFTruncateErrorTest, FuseFTruncateErrorTest, Values(E
TEST_P(FuseFTruncateErrorTest, ReturnedErrorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, ftruncate(0, _))
EXPECT_CALL(*fsimpl, ftruncate(0, _))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
//Needed to make ::ftruncate system call return successfully
ReturnIsFileOnFstat(0);

View File

@ -18,7 +18,7 @@ INSTANTIATE_TEST_CASE_P(FuseFTruncateFileDescriptorTest, FuseFTruncateFileDescri
TEST_P(FuseFTruncateFileDescriptorTest, FileDescriptorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
OnOpenReturnFileDescriptor(FILENAME, GetParam());
EXPECT_CALL(fsimpl, ftruncate(Eq(GetParam()), _))
EXPECT_CALL(*fsimpl, ftruncate(Eq(GetParam()), _))
.Times(1).WillOnce(Return());
//Needed to make ::ftruncate system call return successfully
ReturnIsFileOnFstat(GetParam());

View File

@ -18,7 +18,7 @@ INSTANTIATE_TEST_CASE_P(FuseFTruncateSizeTest, FuseFTruncateSizeTest, Values(
TEST_P(FuseFTruncateSizeTest, FTruncateFile) {
ReturnIsFileOnLstat(FILENAME);
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, ftruncate(Eq(0), GetParam()))
EXPECT_CALL(*fsimpl, ftruncate(Eq(0), GetParam()))
.Times(1).WillOnce(Return());
//Needed to make ::ftruncate system call return successfully
ReturnIsFileOnFstat(0);

View File

@ -17,14 +17,14 @@ public:
INSTANTIATE_TEST_CASE_P(LstatErrorCodes, FuseLstatErrorTest, Values(EACCES, EBADF, EFAULT, ELOOP, ENAMETOOLONG, ENOENT, ENOMEM, ENOTDIR, EOVERFLOW, EINVAL, ENOTDIR));
TEST_F(FuseLstatErrorTest, ReturnNoError) {
EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsFile);
EXPECT_CALL(*fsimpl, lstat(StrEq(FILENAME), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsFile);
errno = 0;
int error = LstatPathReturnError(FILENAME);
EXPECT_EQ(0, error);
}
TEST_P(FuseLstatErrorTest, ReturnError) {
EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).Times(AtLeast(1)).WillRepeatedly(Throw(FuseErrnoException(GetParam())));
EXPECT_CALL(*fsimpl, lstat(StrEq(FILENAME), _)).Times(AtLeast(1)).WillRepeatedly(Throw(FuseErrnoException(GetParam())));
int error = LstatPathReturnError(FILENAME);
EXPECT_EQ(GetParam(), error);
}

View File

@ -8,30 +8,30 @@ class FuseLstatPathParameterTest: public FuseLstatTest {
};
TEST_F(FuseLstatPathParameterTest, PathParameterIsCorrectRoot) {
EXPECT_CALL(fsimpl, lstat(StrEq("/"), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsDir);
EXPECT_CALL(*fsimpl, lstat(StrEq("/"), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsDir);
LstatPath("/");
}
TEST_F(FuseLstatPathParameterTest, PathParameterIsCorrectSimpleFile) {
EXPECT_CALL(fsimpl, lstat(StrEq("/myfile"), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsFile);
EXPECT_CALL(*fsimpl, lstat(StrEq("/myfile"), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsFile);
LstatPath("/myfile");
}
TEST_F(FuseLstatPathParameterTest, PathParameterIsCorrectSimpleDir) {
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir"), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsDir);
EXPECT_CALL(*fsimpl, lstat(StrEq("/mydir"), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsDir);
LstatPath("/mydir/");
}
TEST_F(FuseLstatPathParameterTest, PathParameterIsCorrectNestedFile) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir/mydir2/myfile"), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsFile);
EXPECT_CALL(*fsimpl, lstat(StrEq("/mydir/mydir2/myfile"), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsFile);
LstatPath("/mydir/mydir2/myfile");
}
TEST_F(FuseLstatPathParameterTest, PathParameterIsCorrectNestedDir) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir/mydir2/mydir3"), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsDir);
EXPECT_CALL(*fsimpl, lstat(StrEq("/mydir/mydir2/mydir3"), _)).Times(AtLeast(1)).WillRepeatedly(ReturnIsDir);
LstatPath("/mydir/mydir2/mydir3/");
}

View File

@ -41,7 +41,7 @@ fspp::fuse::STAT FuseLstatTest::CallDirLstatWithImpl(function<void(fspp::fuse::S
}
fspp::fuse::STAT FuseLstatTest::CallLstatWithImpl(function<void(fspp::fuse::STAT*)> implementation) {
EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).WillRepeatedly(Invoke([implementation](const char*, fspp::fuse::STAT *stat) {
EXPECT_CALL(*fsimpl, lstat(StrEq(FILENAME), _)).WillRepeatedly(Invoke([implementation](const char*, fspp::fuse::STAT *stat) {
implementation(stat);
}));

View File

@ -8,7 +8,7 @@ class FuseMkdirDirnameTest: public FuseMkdirTest {
TEST_F(FuseMkdirDirnameTest, Mkdir) {
ReturnDoesntExistOnLstat("/mydir");
EXPECT_CALL(fsimpl, mkdir(StrEq("/mydir"), _, _, _))
EXPECT_CALL(*fsimpl, mkdir(StrEq("/mydir"), _, _, _))
// After mkdir was called, lstat should return that it is a dir.
// This is needed to make the ::mkdir() syscall pass.
.Times(1).WillOnce(FromNowOnReturnIsDirOnLstat());
@ -19,7 +19,7 @@ TEST_F(FuseMkdirDirnameTest, Mkdir) {
TEST_F(FuseMkdirDirnameTest, MkdirNested) {
ReturnIsDirOnLstat("/mydir");
ReturnDoesntExistOnLstat("/mydir/mysubdir");
EXPECT_CALL(fsimpl, mkdir(StrEq("/mydir/mysubdir"), _, _, _))
EXPECT_CALL(*fsimpl, mkdir(StrEq("/mydir/mysubdir"), _, _, _))
// After mkdir was called, lstat should return that it is a dir.
// This is needed to make the ::mkdir() syscall pass.
.Times(1).WillOnce(FromNowOnReturnIsDirOnLstat());
@ -31,7 +31,7 @@ TEST_F(FuseMkdirDirnameTest, MkdirNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnDoesntExistOnLstat("/mydir/mydir2/mydir3");
EXPECT_CALL(fsimpl, mkdir(StrEq("/mydir/mydir2/mydir3"), _, _, _))
EXPECT_CALL(*fsimpl, mkdir(StrEq("/mydir/mydir2/mydir3"), _, _, _))
// After mkdir was called, lstat should return that it is a dir.
// This is needed to make the ::mkdir() syscall pass.
.Times(1).WillOnce(FromNowOnReturnIsDirOnLstat());

View File

@ -16,7 +16,7 @@ INSTANTIATE_TEST_CASE_P(FuseMkdirErrorTest, FuseMkdirErrorTest, Values(EACCES, E
TEST_F(FuseMkdirErrorTest, NoError) {
ReturnDoesntExistOnLstat(DIRNAME);
EXPECT_CALL(fsimpl, mkdir(StrEq(DIRNAME), _, _, _))
EXPECT_CALL(*fsimpl, mkdir(StrEq(DIRNAME), _, _, _))
.Times(1).WillOnce(FromNowOnReturnIsDirOnLstat());
int error = MkdirReturnError(DIRNAME, 0);
@ -25,7 +25,7 @@ TEST_F(FuseMkdirErrorTest, NoError) {
TEST_P(FuseMkdirErrorTest, ReturnedErrorIsCorrect) {
ReturnDoesntExistOnLstat(DIRNAME);
EXPECT_CALL(fsimpl, mkdir(StrEq(DIRNAME), _, _, _))
EXPECT_CALL(*fsimpl, mkdir(StrEq(DIRNAME), _, _, _))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = MkdirReturnError(DIRNAME, 0);

View File

@ -12,7 +12,7 @@ INSTANTIATE_TEST_CASE_P(FuseMkdirModeTest, FuseMkdirModeTest, Values(0, S_IRUSR,
TEST_P(FuseMkdirModeTest, Mkdir) {
ReturnDoesntExistOnLstat(DIRNAME);
EXPECT_CALL(fsimpl, mkdir(StrEq(DIRNAME), GetParam(), _, _))
EXPECT_CALL(*fsimpl, mkdir(StrEq(DIRNAME), GetParam(), _, _))
.Times(1).WillOnce(FromNowOnReturnIsDirOnLstat());
Mkdir(DIRNAME, GetParam());

View File

@ -17,7 +17,7 @@ INSTANTIATE_TEST_CASE_P(FuseOpenErrorTest, FuseOpenErrorTest, Values(EACCES, EDQ
TEST_F(FuseOpenErrorTest, ReturnNoError) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _)).Times(1).WillOnce(Return(1));
EXPECT_CALL(*fsimpl, openFile(StrEq(FILENAME), _)).Times(1).WillOnce(Return(1));
errno = 0;
int error = OpenFileReturnError(FILENAME, O_RDONLY);
EXPECT_EQ(0, error);
@ -25,7 +25,7 @@ TEST_F(FuseOpenErrorTest, ReturnNoError) {
TEST_P(FuseOpenErrorTest, ReturnError) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
EXPECT_CALL(*fsimpl, openFile(StrEq(FILENAME), _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = OpenFileReturnError(FILENAME, O_RDONLY);
EXPECT_EQ(GetParam(), error);
}

View File

@ -34,9 +34,9 @@ INSTANTIATE_TEST_CASE_P(FuseOpenFileDescriptorTest, FuseOpenFileDescriptorTest,
TEST_P(FuseOpenFileDescriptorTest, TestReturnedFileDescriptor) {
ReturnIsFileOnLstatWithSize(FILENAME, fspp::num_bytes_t(1));
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _))
EXPECT_CALL(*fsimpl, openFile(StrEq(FILENAME), _))
.Times(1).WillOnce(Return(GetParam()));
EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(fspp::num_bytes_t(1)));
EXPECT_CALL(*fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(fspp::num_bytes_t(1)));
OpenAndReadFile(FILENAME);
}

View File

@ -10,7 +10,7 @@ public:
TEST_F(FuseOpenFilenameTest, OpenFile) {
ReturnIsFileOnLstat("/myfile");
EXPECT_CALL(fsimpl, openFile(StrEq("/myfile"), _))
EXPECT_CALL(*fsimpl, openFile(StrEq("/myfile"), _))
.Times(1).WillOnce(Return(0));
OpenFile("/myfile", O_RDONLY);
@ -19,7 +19,7 @@ TEST_F(FuseOpenFilenameTest, OpenFile) {
TEST_F(FuseOpenFilenameTest, OpenFileNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsFileOnLstat("/mydir/myfile");
EXPECT_CALL(fsimpl, openFile(StrEq("/mydir/myfile"), _))
EXPECT_CALL(*fsimpl, openFile(StrEq("/mydir/myfile"), _))
.Times(1).WillOnce(Return(0));
OpenFile("/mydir/myfile", O_RDONLY);
@ -29,7 +29,7 @@ TEST_F(FuseOpenFilenameTest, OpenFileNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsFileOnLstat("/mydir/mydir2/myfile");
EXPECT_CALL(fsimpl, openFile(StrEq("/mydir/mydir2/myfile"), _))
EXPECT_CALL(*fsimpl, openFile(StrEq("/mydir/mydir2/myfile"), _))
.Times(1).WillOnce(Return(0));
OpenFile("/mydir/mydir2/myfile", O_RDONLY);

View File

@ -11,7 +11,7 @@ INSTANTIATE_TEST_CASE_P(FuseOpenFlagsTest, FuseOpenFlagsTest, Values(O_RDWR, O_R
TEST_P(FuseOpenFlagsTest, testFlags) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), OpenFlagsEq(GetParam())))
EXPECT_CALL(*fsimpl, openFile(StrEq(FILENAME), OpenFlagsEq(GetParam())))
.Times(1).WillOnce(Return(0));
OpenFile(FILENAME, GetParam());

View File

@ -27,7 +27,7 @@ INSTANTIATE_TEST_CASE_P(FuseReadErrorTest, FuseReadErrorTest, Values(EAGAIN, EBA
TEST_P(FuseReadErrorTest, ReturnErrorOnFirstReadCall) {
EXPECT_CALL(fsimpl, read(0, _, _, _))
EXPECT_CALL(*fsimpl, read(0, _, _, _))
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
char *buf = new char[READCOUNT.value()];
@ -41,14 +41,14 @@ TEST_P(FuseReadErrorTest, ReturnErrorOnSecondReadCall) {
// We store the number of bytes the first call could successfully read and check later that our
// read syscall returns exactly this number of bytes
fspp::num_bytes_t successfullyReadBytes = fspp::num_bytes_t(-1);
EXPECT_CALL(fsimpl, read(0, _, _, Eq(fspp::num_bytes_t(0))))
EXPECT_CALL(*fsimpl, read(0, _, _, Eq(fspp::num_bytes_t(0))))
.Times(1)
.WillOnce(Invoke([&successfullyReadBytes](int, void*, fspp::num_bytes_t count, fspp::num_bytes_t) {
// Store the number of successfully read bytes
successfullyReadBytes = count;
return count;
}));
EXPECT_CALL(fsimpl, read(0, _, _, Ne(fspp::num_bytes_t(0))))
EXPECT_CALL(*fsimpl, read(0, _, _, Ne(fspp::num_bytes_t(0))))
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
char *buf = new char[READCOUNT.value()];

View File

@ -17,7 +17,7 @@ INSTANTIATE_TEST_CASE_P(FuseReadFileDescriptorTest, FuseReadFileDescriptorTest,
TEST_P(FuseReadFileDescriptorTest, FileDescriptorIsCorrect) {
ReturnIsFileOnLstatWithSize(FILENAME, fspp::num_bytes_t(1));
OnOpenReturnFileDescriptor(FILENAME, GetParam());
EXPECT_CALL(fsimpl, read(Eq(GetParam()), _, _, _))
EXPECT_CALL(*fsimpl, read(Eq(GetParam()), _, _, _))
.Times(1).WillOnce(ReturnSuccessfulRead);
char buf[1];

View File

@ -16,7 +16,7 @@ public:
void SetUp() override {
ReturnIsFileOnLstatWithSize(FILENAME, FILESIZE);
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, read(0, _, _, _)).WillRepeatedly(ReturnSuccessfulReadRegardingSize(FILESIZE));
EXPECT_CALL(*fsimpl, read(0, _, _, _)).WillRepeatedly(ReturnSuccessfulReadRegardingSize(FILESIZE));
}
};

View File

@ -52,7 +52,7 @@ public:
testFile = std::make_unique<InMemoryFile>(DataFixture::generate(testData.fileSize().value()));
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, read(0, _, _, _))
EXPECT_CALL(*fsimpl, read(0, _, _, _))
.WillRepeatedly(ReadFromFile);
}

View File

@ -9,7 +9,7 @@ public:
};
TEST_F(FuseReadDirDirnameTest, ReadRootDir) {
EXPECT_CALL(fsimpl, readDir(StrEq("/")))
EXPECT_CALL(*fsimpl, readDir(StrEq("/")))
.Times(1).WillOnce(ReturnDirEntries({}));
ReadDir("/");
@ -17,7 +17,7 @@ TEST_F(FuseReadDirDirnameTest, ReadRootDir) {
TEST_F(FuseReadDirDirnameTest, ReadDir) {
ReturnIsDirOnLstat("/mydir");
EXPECT_CALL(fsimpl, readDir(StrEq("/mydir")))
EXPECT_CALL(*fsimpl, readDir(StrEq("/mydir")))
.Times(1).WillOnce(ReturnDirEntries({}));
ReadDir("/mydir");
@ -26,7 +26,7 @@ TEST_F(FuseReadDirDirnameTest, ReadDir) {
TEST_F(FuseReadDirDirnameTest, ReadDirNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
EXPECT_CALL(fsimpl, readDir(StrEq("/mydir/mydir2")))
EXPECT_CALL(*fsimpl, readDir(StrEq("/mydir/mydir2")))
.Times(1).WillOnce(ReturnDirEntries({}));
ReadDir("/mydir/mydir2");
@ -36,7 +36,7 @@ TEST_F(FuseReadDirDirnameTest, ReadDirNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsDirOnLstat("/mydir/mydir2/mydir3");
EXPECT_CALL(fsimpl, readDir(StrEq("/mydir/mydir2/mydir3")))
EXPECT_CALL(*fsimpl, readDir(StrEq("/mydir/mydir2/mydir3")))
.Times(1).WillOnce(ReturnDirEntries({}));
ReadDir("/mydir/mydir2/mydir3");

View File

@ -19,7 +19,7 @@ INSTANTIATE_TEST_CASE_P(FuseReadDirErrorTest, FuseReadDirErrorTest, Values(EACCE
TEST_F(FuseReadDirErrorTest, NoError) {
ReturnIsDirOnLstat(DIRNAME);
EXPECT_CALL(fsimpl, readDir(StrEq(DIRNAME)))
EXPECT_CALL(*fsimpl, readDir(StrEq(DIRNAME)))
.Times(1).WillOnce(ReturnDirEntries({}));
int error = ReadDirReturnError(DIRNAME);
@ -28,7 +28,7 @@ TEST_F(FuseReadDirErrorTest, NoError) {
TEST_P(FuseReadDirErrorTest, ReturnedErrorCodeIsCorrect) {
ReturnIsDirOnLstat(DIRNAME);
EXPECT_CALL(fsimpl, readDir(StrEq(DIRNAME)))
EXPECT_CALL(*fsimpl, readDir(StrEq(DIRNAME)))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = ReadDirReturnError(DIRNAME);

View File

@ -26,7 +26,7 @@ class FuseReadDirReturnTest: public FuseReadDirTest, public WithParamInterface<v
public:
void testDirEntriesAreCorrect(const vector<string> &direntries) {
ReturnIsDirOnLstat(DIRNAME);
EXPECT_CALL(fsimpl, readDir(StrEq(DIRNAME)))
EXPECT_CALL(*fsimpl, readDir(StrEq(DIRNAME)))
.Times(1).WillOnce(ReturnDirEntries(direntries));
auto returned_dir_entries = ReadDir(DIRNAME);

View File

@ -15,7 +15,7 @@ INSTANTIATE_TEST_CASE_P(FuseRenameErrorTest, FuseRenameErrorTest, Values(EACCES,
TEST_P(FuseRenameErrorTest, ReturnedErrorIsCorrect) {
ReturnIsFileOnLstat(FILENAME1);
ReturnDoesntExistOnLstat(FILENAME2);
EXPECT_CALL(fsimpl, rename(StrEq(FILENAME1), StrEq(FILENAME2)))
EXPECT_CALL(*fsimpl, rename(StrEq(FILENAME1), StrEq(FILENAME2)))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = RenameReturnError(FILENAME1, FILENAME2);

View File

@ -9,7 +9,7 @@ class FuseRenameFilenameTest: public FuseRenameTest {
TEST_F(FuseRenameFilenameTest, RenameFileRootToRoot) {
ReturnIsFileOnLstat("/myfile");
ReturnDoesntExistOnLstat("/myrenamedfile");
EXPECT_CALL(fsimpl, rename(StrEq("/myfile"), StrEq("/myrenamedfile")))
EXPECT_CALL(*fsimpl, rename(StrEq("/myfile"), StrEq("/myrenamedfile")))
.Times(1).WillOnce(Return());
Rename("/myfile", "/myrenamedfile");
@ -19,7 +19,7 @@ TEST_F(FuseRenameFilenameTest, RenameFileRootToNested) {
ReturnIsFileOnLstat("/myfile");
ReturnIsDirOnLstat("/mydir");
ReturnDoesntExistOnLstat("/mydir/myrenamedfile");
EXPECT_CALL(fsimpl, rename(StrEq("/myfile"), StrEq("/mydir/myrenamedfile")))
EXPECT_CALL(*fsimpl, rename(StrEq("/myfile"), StrEq("/mydir/myrenamedfile")))
.Times(1).WillOnce(Return());
Rename("/myfile", "/mydir/myrenamedfile");
@ -29,7 +29,7 @@ TEST_F(FuseRenameFilenameTest, RenameFileNestedToRoot) {
ReturnDoesntExistOnLstat("/myrenamedfile");
ReturnIsDirOnLstat("/mydir");
ReturnIsFileOnLstat("/mydir/myfile");
EXPECT_CALL(fsimpl, rename(StrEq("/mydir/myfile"), StrEq("/myrenamedfile")))
EXPECT_CALL(*fsimpl, rename(StrEq("/mydir/myfile"), StrEq("/myrenamedfile")))
.Times(1).WillOnce(Return());
Rename("/mydir/myfile", "/myrenamedfile");
@ -39,7 +39,7 @@ TEST_F(FuseRenameFilenameTest, RenameFileNestedToNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsFileOnLstat("/mydir/myfile");
ReturnDoesntExistOnLstat("/mydir/myrenamedfile");
EXPECT_CALL(fsimpl, rename(StrEq("/mydir/myfile"), StrEq("/mydir/myrenamedfile")))
EXPECT_CALL(*fsimpl, rename(StrEq("/mydir/myfile"), StrEq("/mydir/myrenamedfile")))
.Times(1).WillOnce(Return());
Rename("/mydir/myfile", "/mydir/myrenamedfile");
@ -50,7 +50,7 @@ TEST_F(FuseRenameFilenameTest, RenameFileNestedToNested2) {
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsFileOnLstat("/mydir/mydir2/myfile");
ReturnDoesntExistOnLstat("/mydir/mydir2/myrenamedfile");
EXPECT_CALL(fsimpl, rename(StrEq("/mydir/mydir2/myfile"), StrEq("/mydir/mydir2/myrenamedfile")))
EXPECT_CALL(*fsimpl, rename(StrEq("/mydir/mydir2/myfile"), StrEq("/mydir/mydir2/myrenamedfile")))
.Times(1).WillOnce(Return());
Rename("/mydir/mydir2/myfile", "/mydir/mydir2/myrenamedfile");
@ -61,7 +61,7 @@ TEST_F(FuseRenameFilenameTest, RenameFileNestedToNested_DifferentFolder) {
ReturnIsDirOnLstat("/mydir2");
ReturnIsFileOnLstat("/mydir/myfile");
ReturnDoesntExistOnLstat("/mydir2/myrenamedfile");
EXPECT_CALL(fsimpl, rename(StrEq("/mydir/myfile"), StrEq("/mydir2/myrenamedfile")))
EXPECT_CALL(*fsimpl, rename(StrEq("/mydir/myfile"), StrEq("/mydir2/myrenamedfile")))
.Times(1).WillOnce(Return());
Rename("/mydir/myfile", "/mydir2/myrenamedfile");
@ -70,7 +70,7 @@ TEST_F(FuseRenameFilenameTest, RenameFileNestedToNested_DifferentFolder) {
TEST_F(FuseRenameFilenameTest, RenameDirRootToRoot) {
ReturnIsDirOnLstat("/mydir");
ReturnDoesntExistOnLstat("/myrenameddir");
EXPECT_CALL(fsimpl, rename(StrEq("/mydir"), StrEq("/myrenameddir")))
EXPECT_CALL(*fsimpl, rename(StrEq("/mydir"), StrEq("/myrenameddir")))
.Times(1).WillOnce(Return());
Rename("/mydir", "/myrenameddir");
@ -80,7 +80,7 @@ TEST_F(FuseRenameFilenameTest, RenameDirRootToNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/myrootdir");
ReturnDoesntExistOnLstat("/myrootdir/myrenameddir");
EXPECT_CALL(fsimpl, rename(StrEq("/mydir"), StrEq("/myrootdir/myrenameddir")))
EXPECT_CALL(*fsimpl, rename(StrEq("/mydir"), StrEq("/myrootdir/myrenameddir")))
.Times(1).WillOnce(Return());
Rename("/mydir", "/myrootdir/myrenameddir");
@ -90,7 +90,7 @@ TEST_F(FuseRenameFilenameTest, RenameDirNestedToRoot) {
ReturnDoesntExistOnLstat("/myrenameddir");
ReturnIsDirOnLstat("/myrootdir");
ReturnIsDirOnLstat("/myrootdir/mydir");
EXPECT_CALL(fsimpl, rename(StrEq("/myrootdir/mydir"), StrEq("/myrenameddir")))
EXPECT_CALL(*fsimpl, rename(StrEq("/myrootdir/mydir"), StrEq("/myrenameddir")))
.Times(1).WillOnce(Return());
Rename("/myrootdir/mydir", "/myrenameddir");
@ -100,7 +100,7 @@ TEST_F(FuseRenameFilenameTest, RenameDirNestedToNested) {
ReturnIsDirOnLstat("/myrootdir");
ReturnIsDirOnLstat("/myrootdir/mydir");
ReturnDoesntExistOnLstat("/myrootdir/myrenameddir");
EXPECT_CALL(fsimpl, rename(StrEq("/myrootdir/mydir"), StrEq("/myrootdir/myrenameddir")))
EXPECT_CALL(*fsimpl, rename(StrEq("/myrootdir/mydir"), StrEq("/myrootdir/myrenameddir")))
.Times(1).WillOnce(Return());
Rename("/myrootdir/mydir", "/myrootdir/myrenameddir");
@ -111,7 +111,7 @@ TEST_F(FuseRenameFilenameTest, RenameDirNestedToNested2) {
ReturnIsDirOnLstat("/myrootdir/myrootdir2");
ReturnIsDirOnLstat("/myrootdir/myrootdir2/mydir");
ReturnDoesntExistOnLstat("/myrootdir/myrootdir2/myrenameddir");
EXPECT_CALL(fsimpl, rename(StrEq("/myrootdir/myrootdir2/mydir"), StrEq("/myrootdir/myrootdir2/myrenameddir")))
EXPECT_CALL(*fsimpl, rename(StrEq("/myrootdir/myrootdir2/mydir"), StrEq("/myrootdir/myrootdir2/myrenameddir")))
.Times(1).WillOnce(Return());
Rename("/myrootdir/myrootdir2/mydir", "/myrootdir/myrootdir2/myrenameddir");
@ -122,7 +122,7 @@ TEST_F(FuseRenameFilenameTest, RenameDirNestedToNested_DifferentFolder) {
ReturnIsDirOnLstat("/myrootdir2");
ReturnIsDirOnLstat("/myrootdir/mydir");
ReturnDoesntExistOnLstat("/myrootdir2/myrenameddir");
EXPECT_CALL(fsimpl, rename(StrEq("/myrootdir/mydir"), StrEq("/myrootdir2/myrenameddir")))
EXPECT_CALL(*fsimpl, rename(StrEq("/myrootdir/mydir"), StrEq("/myrootdir2/myrenameddir")))
.Times(1).WillOnce(Return());
Rename("/myrootdir/mydir", "/myrootdir2/myrenameddir");

View File

@ -7,7 +7,7 @@ class FuseRmdirDirnameTest: public FuseRmdirTest {
TEST_F(FuseRmdirDirnameTest, Rmdir) {
ReturnIsDirOnLstat("/mydir");
EXPECT_CALL(fsimpl, rmdir(StrEq("/mydir")))
EXPECT_CALL(*fsimpl, rmdir(StrEq("/mydir")))
// After rmdir was called, lstat should return that it doesn't exist anymore
// This is needed to make the ::rmdir() syscall pass.
.Times(1).WillOnce(FromNowOnReturnDoesntExistOnLstat());
@ -18,7 +18,7 @@ TEST_F(FuseRmdirDirnameTest, Rmdir) {
TEST_F(FuseRmdirDirnameTest, RmdirNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mysubdir");
EXPECT_CALL(fsimpl, rmdir(StrEq("/mydir/mysubdir")))
EXPECT_CALL(*fsimpl, rmdir(StrEq("/mydir/mysubdir")))
// After rmdir was called, lstat should return that it doesn't exist anymore
// This is needed to make the ::rmdir() syscall pass.
.Times(1).WillOnce(FromNowOnReturnDoesntExistOnLstat());
@ -30,7 +30,7 @@ TEST_F(FuseRmdirDirnameTest, RmdirNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsDirOnLstat("/mydir/mydir2/mydir3");
EXPECT_CALL(fsimpl, rmdir(StrEq("/mydir/mydir2/mydir3")))
EXPECT_CALL(*fsimpl, rmdir(StrEq("/mydir/mydir2/mydir3")))
// After rmdir was called, lstat should return that it doesn't exist anymore
// This is needed to make the ::rmdir() syscall pass.
.Times(1).WillOnce(FromNowOnReturnDoesntExistOnLstat());

View File

@ -14,7 +14,7 @@ INSTANTIATE_TEST_CASE_P(FuseRmdirErrorTest, FuseRmdirErrorTest, Values(EACCES, E
TEST_P(FuseRmdirErrorTest, ReturnedErrorIsCorrect) {
ReturnIsDirOnLstat(DIRNAME);
EXPECT_CALL(fsimpl, rmdir(StrEq(DIRNAME)))
EXPECT_CALL(*fsimpl, rmdir(StrEq(DIRNAME)))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = RmdirReturnError(DIRNAME);

View File

@ -17,14 +17,14 @@ INSTANTIATE_TEST_CASE_P(FuseStatfsErrorTest, FuseStatfsErrorTest, Values(EACCES,
TEST_F(FuseStatfsErrorTest, ReturnNoError) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, statfs(_)).Times(1).WillOnce(Return());
EXPECT_CALL(*fsimpl, statfs(_)).Times(1).WillOnce(Return());
int error = StatfsReturnError(FILENAME);
EXPECT_EQ(0, error);
}
TEST_P(FuseStatfsErrorTest, ReturnError) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, statfs( _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
EXPECT_CALL(*fsimpl, statfs( _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = StatfsReturnError(FILENAME);
EXPECT_EQ(GetParam(), error);
}

View File

@ -33,7 +33,7 @@ int FuseStatfsTest::StatfsReturnError(const std::string &path, struct ::statvfs
struct ::statvfs FuseStatfsTest::CallStatfsWithImpl(function<void(struct ::statvfs*)> implementation) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, statfs(_)).WillRepeatedly(Invoke([implementation](struct ::statvfs *stat) {
EXPECT_CALL(*fsimpl, statfs(_)).WillRepeatedly(Invoke([implementation](struct ::statvfs *stat) {
implementation(stat);
}));

View File

@ -15,7 +15,7 @@ INSTANTIATE_TEST_CASE_P(FuseTruncateErrorTest, FuseTruncateErrorTest, Values(EAC
TEST_P(FuseTruncateErrorTest, ReturnedErrorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), _))
EXPECT_CALL(*fsimpl, truncate(StrEq(FILENAME), _))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = TruncateFileReturnError(FILENAME, fspp::num_bytes_t(0));

View File

@ -9,7 +9,7 @@ class FuseTruncateFilenameTest: public FuseTruncateTest {
TEST_F(FuseTruncateFilenameTest, TruncateFile) {
ReturnIsFileOnLstat("/myfile");
EXPECT_CALL(fsimpl, truncate(StrEq("/myfile"), _))
EXPECT_CALL(*fsimpl, truncate(StrEq("/myfile"), _))
.Times(1).WillOnce(Return());
TruncateFile("/myfile", fspp::num_bytes_t(0));
@ -18,7 +18,7 @@ TEST_F(FuseTruncateFilenameTest, TruncateFile) {
TEST_F(FuseTruncateFilenameTest, TruncateFileNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsFileOnLstat("/mydir/myfile");
EXPECT_CALL(fsimpl, truncate(StrEq("/mydir/myfile"), _))
EXPECT_CALL(*fsimpl, truncate(StrEq("/mydir/myfile"), _))
.Times(1).WillOnce(Return());
TruncateFile("/mydir/myfile", fspp::num_bytes_t(0));
@ -28,7 +28,7 @@ TEST_F(FuseTruncateFilenameTest, TruncateFileNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsFileOnLstat("/mydir/mydir2/myfile");
EXPECT_CALL(fsimpl, truncate(StrEq("/mydir/mydir2/myfile"), _))
EXPECT_CALL(*fsimpl, truncate(StrEq("/mydir/mydir2/myfile"), _))
.Times(1).WillOnce(Return());
TruncateFile("/mydir/mydir2/myfile", fspp::num_bytes_t(0));

View File

@ -18,7 +18,7 @@ INSTANTIATE_TEST_CASE_P(FuseTruncateSizeTest, FuseTruncateSizeTest, Values(
TEST_P(FuseTruncateSizeTest, TruncateFile) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), Eq(GetParam())))
EXPECT_CALL(*fsimpl, truncate(StrEq(FILENAME), Eq(GetParam())))
.Times(1).WillOnce(Return());
TruncateFile(FILENAME, GetParam());

View File

@ -14,7 +14,7 @@ INSTANTIATE_TEST_CASE_P(FuseUnlinkErrorTest, FuseUnlinkErrorTest, Values(EACCES,
TEST_P(FuseUnlinkErrorTest, ReturnedErrorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, unlink(StrEq(FILENAME)))
EXPECT_CALL(*fsimpl, unlink(StrEq(FILENAME)))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = UnlinkReturnError(FILENAME);

View File

@ -7,7 +7,7 @@ class FuseUnlinkFilenameTest: public FuseUnlinkTest {
TEST_F(FuseUnlinkFilenameTest, Unlink) {
ReturnIsFileOnLstat("/mydir");
EXPECT_CALL(fsimpl, unlink(StrEq("/mydir")))
EXPECT_CALL(*fsimpl, unlink(StrEq("/mydir")))
// After rmdir was called, lstat should return that it doesn't exist anymore
// This is needed to make the ::rmdir() syscall pass.
.Times(1).WillOnce(FromNowOnReturnDoesntExistOnLstat());
@ -18,7 +18,7 @@ TEST_F(FuseUnlinkFilenameTest, Unlink) {
TEST_F(FuseUnlinkFilenameTest, UnlinkNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsFileOnLstat("/mydir/mysubdir");
EXPECT_CALL(fsimpl, unlink(StrEq("/mydir/mysubdir")))
EXPECT_CALL(*fsimpl, unlink(StrEq("/mydir/mysubdir")))
// After rmdir was called, lstat should return that it doesn't exist anymore
// This is needed to make the ::rmdir() syscall pass.
.Times(1).WillOnce(FromNowOnReturnDoesntExistOnLstat());
@ -30,7 +30,7 @@ TEST_F(FuseUnlinkFilenameTest, UnlinkNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsFileOnLstat("/mydir/mydir2/mydir3");
EXPECT_CALL(fsimpl, unlink(StrEq("/mydir/mydir2/mydir3")))
EXPECT_CALL(*fsimpl, unlink(StrEq("/mydir/mydir2/mydir3")))
// After rmdir was called, lstat should return that it doesn't exist anymore
// This is needed to make the ::rmdir() syscall pass.
.Times(1).WillOnce(FromNowOnReturnDoesntExistOnLstat());

View File

@ -15,7 +15,7 @@ INSTANTIATE_TEST_CASE_P(FuseUtimensErrorTest, FuseUtimensErrorTest, Values(EACCE
TEST_P(FuseUtimensErrorTest, ReturnedErrorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, utimens(StrEq(FILENAME), _, _))
EXPECT_CALL(*fsimpl, utimens(StrEq(FILENAME), _, _))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = UtimensReturnError(FILENAME, TIMEVALUE, TIMEVALUE);

View File

@ -9,7 +9,7 @@ class FuseUtimensFilenameTest: public FuseUtimensTest {
TEST_F(FuseUtimensFilenameTest, UtimensFile) {
ReturnIsFileOnLstat("/myfile");
EXPECT_CALL(fsimpl, utimens(StrEq("/myfile"), _, _))
EXPECT_CALL(*fsimpl, utimens(StrEq("/myfile"), _, _))
.Times(1).WillOnce(Return());
Utimens("/myfile", TIMEVALUE, TIMEVALUE);
@ -18,7 +18,7 @@ TEST_F(FuseUtimensFilenameTest, UtimensFile) {
TEST_F(FuseUtimensFilenameTest, UtimensFileNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsFileOnLstat("/mydir/myfile");
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/myfile"), _, _))
EXPECT_CALL(*fsimpl, utimens(StrEq("/mydir/myfile"), _, _))
.Times(1).WillOnce(Return());
Utimens("/mydir/myfile", TIMEVALUE, TIMEVALUE);
@ -28,7 +28,7 @@ TEST_F(FuseUtimensFilenameTest, UtimensFileNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsFileOnLstat("/mydir/mydir2/myfile");
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/mydir2/myfile"), _, _))
EXPECT_CALL(*fsimpl, utimens(StrEq("/mydir/mydir2/myfile"), _, _))
.Times(1).WillOnce(Return());
Utimens("/mydir/mydir2/myfile", TIMEVALUE, TIMEVALUE);
@ -36,7 +36,7 @@ TEST_F(FuseUtimensFilenameTest, UtimensFileNested2) {
TEST_F(FuseUtimensFilenameTest, UtimensDir) {
ReturnIsDirOnLstat("/mydir");
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir"), _, _))
EXPECT_CALL(*fsimpl, utimens(StrEq("/mydir"), _, _))
.Times(1).WillOnce(Return());
Utimens("/mydir", TIMEVALUE, TIMEVALUE);
@ -45,7 +45,7 @@ TEST_F(FuseUtimensFilenameTest, UtimensDir) {
TEST_F(FuseUtimensFilenameTest, UtimensDirNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/mydir2"), _, _))
EXPECT_CALL(*fsimpl, utimens(StrEq("/mydir/mydir2"), _, _))
.Times(1).WillOnce(Return());
Utimens("/mydir/mydir2", TIMEVALUE, TIMEVALUE);
@ -55,7 +55,7 @@ TEST_F(FuseUtimensFilenameTest, UtimensDirNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsDirOnLstat("/mydir/mydir2/mydir3");
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/mydir2/mydir3"), _, _))
EXPECT_CALL(*fsimpl, utimens(StrEq("/mydir/mydir2/mydir3"), _, _))
.Times(1).WillOnce(Return());
Utimens("/mydir/mydir2/mydir3", TIMEVALUE, TIMEVALUE);

View File

@ -23,7 +23,7 @@ INSTANTIATE_TEST_CASE_P(FuseUtimensTimeParameterTest, FuseUtimensTimeParameterTe
TEST_P(FuseUtimensTimeParameterTest, Utimens) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, utimens(StrEq(FILENAME), TimeSpecEq(GetParam()[0]), TimeSpecEq(GetParam()[1])))
EXPECT_CALL(*fsimpl, utimens(StrEq(FILENAME), TimeSpecEq(GetParam()[0]), TimeSpecEq(GetParam()[1])))
.Times(1).WillOnce(Return());
Utimens(FILENAME, GetParam()[0], GetParam()[1]);

View File

@ -49,7 +49,7 @@ public:
testFile = std::make_unique<WriteableInMemoryFile>(DataFixture::generate(testData.fileSize().value(), 1));
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, write(0, _, _, _))
EXPECT_CALL(*fsimpl, write(0, _, _, _))
.WillRepeatedly(WriteToFile);
}

View File

@ -27,7 +27,7 @@ INSTANTIATE_TEST_CASE_P(FuseWriteErrorTest, FuseWriteErrorTest, Values(EAGAIN, E
TEST_P(FuseWriteErrorTest, ReturnErrorOnFirstWriteCall) {
EXPECT_CALL(fsimpl, write(0, _, _, _))
EXPECT_CALL(*fsimpl, write(0, _, _, _))
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
char *buf = new char[WRITECOUNT.value()];
@ -41,13 +41,13 @@ TEST_P(FuseWriteErrorTest, ReturnErrorOnSecondWriteCall) {
// We store the number of bytes the first call could successfully write and check later that our
// write syscall returns exactly this number of bytes
fspp::num_bytes_t successfullyWrittenBytes = fspp::num_bytes_t(-1);
EXPECT_CALL(fsimpl, write(0, _, _, Eq(fspp::num_bytes_t(0))))
EXPECT_CALL(*fsimpl, write(0, _, _, Eq(fspp::num_bytes_t(0))))
.Times(1)
.WillOnce(Invoke([&successfullyWrittenBytes](int, const void*, fspp::num_bytes_t count, fspp::num_bytes_t) {
// Store the number of successfully written bytes
successfullyWrittenBytes = count;
}));
EXPECT_CALL(fsimpl, write(0, _, _, Ne(fspp::num_bytes_t(0))))
EXPECT_CALL(*fsimpl, write(0, _, _, Ne(fspp::num_bytes_t(0))))
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
char *buf = new char[WRITECOUNT.value()];

View File

@ -18,7 +18,7 @@ INSTANTIATE_TEST_CASE_P(FuseWriteFileDescriptorTest, FuseWriteFileDescriptorTest
TEST_P(FuseWriteFileDescriptorTest, FileDescriptorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
OnOpenReturnFileDescriptor(FILENAME, GetParam());
EXPECT_CALL(fsimpl, write(Eq(GetParam()), _, _, _))
EXPECT_CALL(*fsimpl, write(Eq(GetParam()), _, _, _))
.Times(1).WillOnce(Return());
char buf[1];

View File

@ -26,7 +26,7 @@ public:
: FILESIZE(filesize), WRITESIZE(writesize), OFFSET(offset), testFile(DataFixture::generate(FILESIZE.value())), writeData(DataFixture::generate(WRITESIZE.value())) {
ReturnIsFileOnLstatWithSize(FILENAME, FILESIZE);
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, write(0, _, _, _)).WillRepeatedly(WriteToFile);
EXPECT_CALL(*fsimpl, write(0, _, _, _)).WillRepeatedly(WriteToFile);
}
// This write() mock implementation writes to the stored virtual file.

View File

@ -6,6 +6,8 @@ using ::testing::Return;
using ::testing::Throw;
using ::testing::Action;
using ::testing::Invoke;
using std::make_shared;
using std::shared_ptr;
using cpputils::unique_ref;
using cpputils::make_unique_ref;
@ -17,43 +19,46 @@ using namespace fspp::fuse;
MockFilesystem::MockFilesystem() {}
MockFilesystem::~MockFilesystem() {}
FuseTest::FuseTest(): fsimpl() {
FuseTest::FuseTest(): fsimpl(make_shared<MockFilesystem>()) {
auto defaultAction = Throw(FuseErrnoException(EIO));
ON_CALL(fsimpl, openFile(_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, closeFile(_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, lstat(_,_)).WillByDefault(Throw(FuseErrnoException(ENOENT)));
ON_CALL(fsimpl, fstat(_,_)).WillByDefault(Throw(FuseErrnoException(ENOENT)));
ON_CALL(fsimpl, truncate(_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, ftruncate(_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, read(_,_,_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, write(_,_,_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, fsync(_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, fdatasync(_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, access(_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, createAndOpenFile(_,_,_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, mkdir(_,_,_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, rmdir(_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, unlink(_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, rename(_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, readDir(_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, utimens(_,_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, statfs(_)).WillByDefault(Invoke([](struct statvfs *result) {
ON_CALL(*fsimpl, openFile(_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, closeFile(_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, lstat(_,_)).WillByDefault(Throw(FuseErrnoException(ENOENT)));
ON_CALL(*fsimpl, fstat(_,_)).WillByDefault(Throw(FuseErrnoException(ENOENT)));
ON_CALL(*fsimpl, truncate(_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, ftruncate(_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, read(_,_,_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, write(_,_,_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, fsync(_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, fdatasync(_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, access(_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, createAndOpenFile(_,_,_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, mkdir(_,_,_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, rmdir(_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, unlink(_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, rename(_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, readDir(_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, utimens(_,_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, statfs(_)).WillByDefault(Invoke([](struct statvfs *result) {
::statvfs("/", result); // As dummy value take the values from the root filesystem
}));
ON_CALL(fsimpl, chmod(_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, chown(_,_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, createSymlink(_,_,_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, readSymlink(_,_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, chmod(_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, chown(_,_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, createSymlink(_,_,_,_)).WillByDefault(defaultAction);
ON_CALL(*fsimpl, readSymlink(_,_,_)).WillByDefault(defaultAction);
EXPECT_CALL(fsimpl, access(_,_)).WillRepeatedly(Return());
EXPECT_CALL(*fsimpl, access(_,_)).WillRepeatedly(Return());
ReturnIsDirOnLstat("/");
}
unique_ref<FuseTest::TempTestFS> FuseTest::TestFS() {
return make_unique_ref<TempTestFS>(&fsimpl);
return make_unique_ref<TempTestFS>(fsimpl);
}
FuseTest::TempTestFS::TempTestFS(MockFilesystem *fsimpl): _mountDir(), _fuse(fsimpl, "fusetest", boost::none), _fuse_thread(&_fuse) {
FuseTest::TempTestFS::TempTestFS(shared_ptr<MockFilesystem> fsimpl)
:_mountDir(),
_fuse([fsimpl] (Fuse*) {return fsimpl;}, "fusetest", boost::none), _fuse_thread(&_fuse) {
_fuse_thread.start(_mountDir.path(), {"-f"});
}
@ -87,7 +92,6 @@ Action<void(int, fspp::fuse::STAT*)> FuseTest::ReturnIsFileFstatWithSize(fspp::n
result->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
result->st_nlink = 1;
result->st_size = size.value();
std::cout << "Return size: " << size.value() <<std::endl;
});
}
@ -100,29 +104,29 @@ Action<void(const char*, fspp::fuse::STAT*)> FuseTest::ReturnIsDir =
Action<void(const char*, fspp::fuse::STAT*)> FuseTest::ReturnDoesntExist = Throw(fspp::fuse::FuseErrnoException(ENOENT));
void FuseTest::OnOpenReturnFileDescriptor(const char *filename, int descriptor) {
EXPECT_CALL(fsimpl, openFile(StrEq(filename), _)).Times(1).WillOnce(Return(descriptor));
EXPECT_CALL(*fsimpl, openFile(StrEq(filename), _)).Times(1).WillOnce(Return(descriptor));
}
void FuseTest::ReturnIsFileOnLstat(const bf::path &path) {
EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnIsFile);
EXPECT_CALL(*fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnIsFile);
}
void FuseTest::ReturnIsFileOnLstatWithSize(const bf::path &path, const fspp::num_bytes_t size) {
EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnIsFileWithSize(size));
EXPECT_CALL(*fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnIsFileWithSize(size));
}
void FuseTest::ReturnIsDirOnLstat(const bf::path &path) {
EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnIsDir);
EXPECT_CALL(*fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnIsDir);
}
void FuseTest::ReturnDoesntExistOnLstat(const bf::path &path) {
EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnDoesntExist);
EXPECT_CALL(*fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnDoesntExist);
}
void FuseTest::ReturnIsFileOnFstat(int descriptor) {
EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstat);
EXPECT_CALL(*fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstat);
}
void FuseTest::ReturnIsFileOnFstatWithSize(int descriptor, fspp::num_bytes_t size) {
EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstatWithSize(size));
EXPECT_CALL(*fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstatWithSize(size));
}

View File

@ -90,7 +90,7 @@ public:
class TempTestFS {
public:
TempTestFS(MockFilesystem *fsimpl);
TempTestFS(std::shared_ptr<MockFilesystem> fsimpl);
virtual ~TempTestFS();
public:
const boost::filesystem::path &mountDir() const;
@ -102,7 +102,7 @@ public:
cpputils::unique_ref<TempTestFS> TestFS();
MockFilesystem fsimpl;
std::shared_ptr<MockFilesystem> fsimpl;
//TODO Combine ReturnIsFile and ReturnIsFileFstat. This should be possible in gmock by either (a) using ::testing::Undefined as parameter type or (b) using action macros