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