libcryfs/test/fspp/fuse/lstat/testutils/FuseLstatTest.cpp

60 lines
1.8 KiB
C++
Raw Normal View History

#include "FuseLstatTest.h"
using std::function;
using ::testing::StrEq;
using ::testing::_;
using ::testing::Invoke;
void FuseLstatTest::LstatPath(const std::string &path) {
2018-09-16 03:02:03 +02:00
fspp::fuse::STAT dummy{};
LstatPath(path, &dummy);
}
int FuseLstatTest::LstatPathReturnError(const std::string &path) {
2018-09-16 03:02:03 +02:00
fspp::fuse::STAT dummy{};
return LstatPathReturnError(path, &dummy);
}
2018-09-16 03:02:03 +02:00
void FuseLstatTest::LstatPath(const std::string &path, fspp::fuse::STAT *result) {
int error = LstatPathReturnError(path, result);
EXPECT_EQ(0, error) << "lstat syscall failed. errno: " << error;
}
2018-09-16 03:02:03 +02:00
int FuseLstatTest::LstatPathReturnError(const std::string &path, fspp::fuse::STAT *result) {
auto fs = TestFS();
auto realpath = fs->mountDir() / path;
int retval = ::lstat(realpath.string().c_str(), result);
if (retval == 0) {
return 0;
} else {
return errno;
}
}
2018-09-16 03:02:03 +02:00
fspp::fuse::STAT FuseLstatTest::CallFileLstatWithImpl(function<void(fspp::fuse::STAT*)> implementation) {
return CallLstatWithModeAndImpl(S_IFREG, implementation);
}
2018-09-16 03:02:03 +02:00
fspp::fuse::STAT FuseLstatTest::CallDirLstatWithImpl(function<void(fspp::fuse::STAT*)> implementation) {
return CallLstatWithModeAndImpl(S_IFDIR, implementation);
}
2018-09-16 03:02:03 +02:00
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) {
implementation(stat);
}));
2018-09-16 03:02:03 +02:00
fspp::fuse::STAT result{};
LstatPath(FILENAME, &result);
return result;
}
2018-09-16 03:02:03 +02:00
fspp::fuse::STAT FuseLstatTest::CallLstatWithModeAndImpl(mode_t mode, function<void(fspp::fuse::STAT*)> implementation) {
return CallLstatWithImpl([mode, implementation] (fspp::fuse::STAT *stat) {
stat->st_mode = mode;
implementation(stat);
});
}