libcryfs/test/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.cpp
2015-02-17 00:48:49 +01:00

31 lines
723 B
C++

#include "FuseCreateAndOpenTest.h"
using ::testing::_;
int FuseCreateAndOpenTest::CreateAndOpenFile(const char *filename, int flags) {
int fd = CreateAndOpenFileAllowError(filename, flags);
EXPECT_GE(fd, 0);
return fd;
}
int FuseCreateAndOpenTest::CreateAndOpenFileReturnError(const char *filename, int flags) {
int fd = CreateAndOpenFileAllowError(filename, flags);
if (fd >= 0) {
return 0;
} else {
return -fd;
}
}
int FuseCreateAndOpenTest::CreateAndOpenFileAllowError(const char *filename, int flags) {
auto fs = TestFS();
auto realpath = fs->mountDir() / filename;
int fd = ::open(realpath.c_str(), flags | O_CREAT);
if (fd >= 0) {
return fd;
} else {
return -errno;
}
}