2014-11-20 15:35:52 +01:00
|
|
|
#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{};
|
2014-11-20 15:35:52 +01:00
|
|
|
LstatPath(path, &dummy);
|
|
|
|
}
|
|
|
|
|
2014-12-06 15:33:01 +01:00
|
|
|
int FuseLstatTest::LstatPathReturnError(const std::string &path) {
|
2018-09-16 03:02:03 +02:00
|
|
|
fspp::fuse::STAT dummy{};
|
2014-12-06 15:33:01 +01:00
|
|
|
return LstatPathReturnError(path, &dummy);
|
2014-11-20 16:48:58 +01:00
|
|
|
}
|
|
|
|
|
2018-09-16 03:02:03 +02:00
|
|
|
void FuseLstatTest::LstatPath(const std::string &path, fspp::fuse::STAT *result) {
|
2014-12-06 15:33:01 +01:00
|
|
|
int error = LstatPathReturnError(path, result);
|
|
|
|
EXPECT_EQ(0, error) << "lstat syscall failed. errno: " << error;
|
2014-11-20 16:48:58 +01:00
|
|
|
}
|
|
|
|
|
2018-09-16 03:02:03 +02:00
|
|
|
int FuseLstatTest::LstatPathReturnError(const std::string &path, fspp::fuse::STAT *result) {
|
2014-11-20 15:35:52 +01:00
|
|
|
auto fs = TestFS();
|
|
|
|
|
|
|
|
auto realpath = fs->mountDir() / path;
|
2018-05-21 01:20:38 +02:00
|
|
|
int retval = ::lstat(realpath.string().c_str(), result);
|
2014-12-06 15:33:01 +01:00
|
|
|
if (retval == 0) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return errno;
|
|
|
|
}
|
2014-11-20 15:35:52 +01:00
|
|
|
}
|
|
|
|
|
2018-09-16 03:02:03 +02:00
|
|
|
fspp::fuse::STAT FuseLstatTest::CallFileLstatWithImpl(function<void(fspp::fuse::STAT*)> implementation) {
|
2014-11-20 15:35:52 +01:00
|
|
|
return CallLstatWithModeAndImpl(S_IFREG, implementation);
|
|
|
|
}
|
|
|
|
|
2018-09-16 03:02:03 +02:00
|
|
|
fspp::fuse::STAT FuseLstatTest::CallDirLstatWithImpl(function<void(fspp::fuse::STAT*)> implementation) {
|
2014-11-20 15:35:52 +01:00
|
|
|
return CallLstatWithModeAndImpl(S_IFDIR, implementation);
|
|
|
|
}
|
|
|
|
|
2018-09-16 03:02:03 +02:00
|
|
|
fspp::fuse::STAT FuseLstatTest::CallLstatWithImpl(function<void(fspp::fuse::STAT*)> implementation) {
|
2018-12-03 07:57:21 +01:00
|
|
|
EXPECT_CALL(*fsimpl, lstat(StrEq(FILENAME), _)).WillRepeatedly(Invoke([implementation](const char*, fspp::fuse::STAT *stat) {
|
2014-11-20 15:35:52 +01:00
|
|
|
implementation(stat);
|
|
|
|
}));
|
|
|
|
|
2018-09-16 03:02:03 +02:00
|
|
|
fspp::fuse::STAT result{};
|
2014-11-20 15:35:52 +01:00
|
|
|
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) {
|
2014-11-20 15:35:52 +01:00
|
|
|
stat->st_mode = mode;
|
|
|
|
implementation(stat);
|
|
|
|
});
|
|
|
|
}
|