libcryfs/test/fspp/fuse/write/testutils/FuseWriteTest.cpp

30 lines
1.0 KiB
C++
Raw Normal View History

2014-11-27 16:40:22 +01:00
#include "FuseWriteTest.h"
using cpputils::unique_ref;
using cpputils::make_unique_ref;
2018-09-15 23:32:58 +02:00
void FuseWriteTest::WriteFile(const char *filename, const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
auto retval = WriteFileReturnError(filename, buf, count, offset);
EXPECT_EQ(0, retval.error);
EXPECT_EQ(count, retval.written_bytes);
2014-11-27 16:40:22 +01:00
}
2018-09-15 23:32:58 +02:00
FuseWriteTest::WriteError FuseWriteTest::WriteFileReturnError(const char *filename, const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
2014-11-27 16:40:22 +01:00
auto fs = TestFS();
auto fd = OpenFile(fs.get(), filename);
WriteError result{};
errno = 0;
2018-09-15 23:32:58 +02:00
result.written_bytes = fspp::num_bytes_t(::pwrite(fd->fd(), buf, count.value(), offset.value()));
result.error = errno;
return result;
2014-11-27 16:40:22 +01:00
}
unique_ref<OpenFileHandle> FuseWriteTest::OpenFile(const TempTestFS *fs, const char *filename) {
2014-11-27 16:40:22 +01:00
auto realpath = fs->mountDir() / filename;
auto fd = make_unique_ref<OpenFileHandle>(realpath.string().c_str(), O_WRONLY);
EXPECT_GE(fd->fd(), 0) << "Error opening file";
2014-11-27 16:40:22 +01:00
return fd;
}