libcryfs/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.cpp

25 lines
902 B
C++
Raw Normal View History

2014-11-25 16:47:36 +01:00
#include "FuseCreateAndOpenTest.h"
2017-09-11 15:37:06 +02:00
using cpputils::unique_ref;
using cpputils::make_unique_ref;
2014-11-25 16:47:36 +01:00
2017-09-11 15:37:06 +02:00
void FuseCreateAndOpenTest::CreateAndOpenFile(const std::string &filename, int flags) {
auto fs = TestFS();
2014-11-25 16:47:36 +01:00
2017-09-11 15:37:06 +02:00
auto fd = CreateAndOpenFileAllowErrors(fs.get(), filename, flags);
EXPECT_GE(fd->fd(), 0) << "Opening file failed";
}
int FuseCreateAndOpenTest::CreateAndOpenFileReturnError(const std::string &filename, int flags) {
auto fs = TestFS();
2017-09-11 15:37:06 +02:00
auto fd = CreateAndOpenFileAllowErrors(fs.get(), filename, flags);
return fd->errorcode();
}
2017-09-11 15:37:06 +02:00
unique_ref<OpenFileHandle> FuseCreateAndOpenTest::CreateAndOpenFileAllowErrors(const TempTestFS *fs, const std::string &filename, int flags) {
auto real_path = fs->mountDir() / filename;
auto fd = make_unique_ref<OpenFileHandle>(real_path.string().c_str(), flags | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
2017-09-11 15:37:06 +02:00
return fd;
2014-11-25 16:47:36 +01:00
}