libcryfs/test/fspp/fuse/read/testutils/FuseReadTest.cpp

27 lines
799 B
C++
Raw Normal View History

2014-11-27 03:48:38 +01:00
#include "FuseReadTest.h"
void FuseReadTest::ReadFile(const char *filename, void *buf, size_t count, off_t offset) {
auto retval = ReadFileReturnError(filename, buf, count, offset);
EXPECT_EQ(0, retval.error);
EXPECT_EQ(count, retval.read_bytes);
2014-11-27 03:48:38 +01:00
}
FuseReadTest::ReadError FuseReadTest::ReadFileReturnError(const char *filename, void *buf, size_t count, off_t offset) {
2014-11-27 03:48:38 +01:00
auto fs = TestFS();
int fd = OpenFile(fs.get(), filename);
ReadError result;
errno = 0;
result.read_bytes = ::pread(fd, buf, count, offset);
result.error = errno;
return result;
2014-11-27 03:48:38 +01:00
}
int FuseReadTest::OpenFile(const TempTestFS *fs, const char *filename) {
auto realpath = fs->mountDir() / filename;
int fd = ::open(realpath.c_str(), O_RDONLY);
EXPECT_GE(fd, 0) << "Error opening file";
return fd;
}