2014-11-25 18:43:50 +01:00
|
|
|
#include "FuseFstatTest.h"
|
|
|
|
|
|
|
|
using ::testing::StrEq;
|
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::Return;
|
|
|
|
|
|
|
|
int FuseFstatTest::CreateFile(const TempTestFS *fs, const std::string &filename) {
|
|
|
|
int fd = CreateFileAllowErrors(fs, filename);
|
|
|
|
EXPECT_GE(fd, 0) << "Opening file failed";
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2014-12-06 15:33:01 +01:00
|
|
|
int FuseFstatTest::CreateFileReturnError(const TempTestFS *fs, const std::string &filename) {
|
|
|
|
int fd = CreateFileAllowErrors(fs, filename);
|
|
|
|
if (fd >= 0) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return -fd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 18:43:50 +01:00
|
|
|
int FuseFstatTest::CreateFileAllowErrors(const TempTestFS *fs, const std::string &filename) {
|
|
|
|
auto real_path = fs->mountDir() / filename;
|
2014-12-06 15:33:01 +01:00
|
|
|
int fd = ::open(real_path.c_str(), O_RDWR | O_CREAT);
|
|
|
|
if (fd >= 0) {
|
|
|
|
return fd;
|
|
|
|
} else {
|
|
|
|
return -errno;
|
|
|
|
}
|
2014-11-25 18:43:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FuseFstatTest::OnCreateAndOpenReturnFileDescriptor(const char *filename, int descriptor) {
|
|
|
|
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(filename), _)).Times(1).WillOnce(Return(descriptor));
|
|
|
|
}
|