2014-11-28 22:11:26 +01:00
|
|
|
#include "FuseStatfsTest.h"
|
|
|
|
|
|
|
|
using std::function;
|
|
|
|
using ::testing::StrEq;
|
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::Invoke;
|
|
|
|
|
|
|
|
void FuseStatfsTest::Statfs(const std::string &path) {
|
2017-12-01 16:01:49 +01:00
|
|
|
struct ::statvfs dummy{};
|
2014-11-28 22:11:26 +01:00
|
|
|
Statfs(path, &dummy);
|
|
|
|
}
|
|
|
|
|
2014-12-06 15:33:01 +01:00
|
|
|
int FuseStatfsTest::StatfsReturnError(const std::string &path) {
|
2017-12-01 16:01:49 +01:00
|
|
|
struct ::statvfs dummy{};
|
2014-12-06 15:33:01 +01:00
|
|
|
return StatfsReturnError(path, &dummy);
|
2014-11-28 22:11:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FuseStatfsTest::Statfs(const std::string &path, struct ::statvfs *result) {
|
2014-12-06 15:33:01 +01:00
|
|
|
int error = StatfsReturnError(path, result);
|
|
|
|
EXPECT_EQ(0, error) << "lstat syscall failed. errno: " << errno;
|
2014-11-28 22:11:26 +01:00
|
|
|
}
|
|
|
|
|
2014-12-06 15:33:01 +01:00
|
|
|
int FuseStatfsTest::StatfsReturnError(const std::string &path, struct ::statvfs *result) {
|
2014-11-28 22:11:26 +01:00
|
|
|
auto fs = TestFS();
|
|
|
|
|
|
|
|
auto realpath = fs->mountDir() / path;
|
2018-05-21 01:20:38 +02:00
|
|
|
int retval = ::statvfs(realpath.string().c_str(), result);
|
2014-12-06 15:33:01 +01:00
|
|
|
if (retval == 0) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return errno;
|
|
|
|
}
|
2014-11-28 22:11:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ::statvfs FuseStatfsTest::CallStatfsWithImpl(function<void(struct ::statvfs*)> implementation) {
|
|
|
|
ReturnIsFileOnLstat(FILENAME);
|
|
|
|
EXPECT_CALL(fsimpl, statfs(StrEq(FILENAME), _)).WillRepeatedly(Invoke([implementation](const char*, struct ::statvfs *stat) {
|
|
|
|
implementation(stat);
|
|
|
|
}));
|
|
|
|
|
2017-12-01 16:01:49 +01:00
|
|
|
struct ::statvfs result{};
|
2014-11-28 22:11:26 +01:00
|
|
|
Statfs(FILENAME, &result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|