2014-11-25 16:47:36 +01:00
|
|
|
#include "FuseCreateAndOpenTest.h"
|
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
|
|
|
|
int FuseCreateAndOpenTest::CreateAndOpenFile(const char *filename, int flags) {
|
|
|
|
int fd = CreateAndOpenFileAllowError(filename, flags);
|
|
|
|
EXPECT_GE(fd, 0);
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2014-12-06 15:33:01 +01:00
|
|
|
int FuseCreateAndOpenTest::CreateAndOpenFileReturnError(const char *filename, int flags) {
|
|
|
|
int fd = CreateAndOpenFileAllowError(filename, flags);
|
|
|
|
if (fd >= 0) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return -fd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 16:47:36 +01:00
|
|
|
int FuseCreateAndOpenTest::CreateAndOpenFileAllowError(const char *filename, int flags) {
|
|
|
|
auto fs = TestFS();
|
|
|
|
|
|
|
|
auto realpath = fs->mountDir() / filename;
|
2015-11-24 14:33:17 +01:00
|
|
|
int fd = ::open(realpath.c_str(), flags | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
2014-12-06 15:33:01 +01:00
|
|
|
if (fd >= 0) {
|
|
|
|
return fd;
|
|
|
|
} else {
|
|
|
|
return -errno;
|
|
|
|
}
|
2014-11-25 16:47:36 +01:00
|
|
|
}
|