libcryfs/test/fspp/fuse/statfs/testutils/FuseStatfsTest.cpp

45 lines
1.1 KiB
C++
Raw Normal View History

2014-11-28 22:11:26 +01:00
#include "FuseStatfsTest.h"
using std::function;
using ::testing::Invoke;
void FuseStatfsTest::Statfs(const std::string &path) {
struct ::statvfs dummy{};
2014-11-28 22:11:26 +01:00
Statfs(path, &dummy);
}
int FuseStatfsTest::StatfsReturnError(const std::string &path) {
struct ::statvfs dummy{};
return StatfsReturnError(path, &dummy);
2014-11-28 22:11:26 +01:00
}
void FuseStatfsTest::Statfs(const std::string &path, struct ::statvfs *result) {
int error = StatfsReturnError(path, result);
EXPECT_EQ(0, error) << "lstat syscall failed. errno: " << errno;
2014-11-28 22:11:26 +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;
int retval = ::statvfs(realpath.string().c_str(), result);
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);
2021-04-21 08:09:00 +02:00
EXPECT_CALL(*fsimpl, statfs(testing::_)).WillRepeatedly(Invoke([implementation](struct ::statvfs *stat) {
2014-11-28 22:11:26 +01:00
implementation(stat);
}));
struct ::statvfs result{};
2014-11-28 22:11:26 +01:00
Statfs(FILENAME, &result);
return result;
}