2014-11-27 03:48:38 +01:00
|
|
|
#include "FuseReadTest.h"
|
|
|
|
|
2017-08-25 01:14:16 +02:00
|
|
|
using cpputils::make_unique_ref;
|
|
|
|
using cpputils::unique_ref;
|
|
|
|
|
2014-11-27 03:48:38 +01:00
|
|
|
void FuseReadTest::ReadFile(const char *filename, void *buf, size_t count, off_t offset) {
|
2014-12-06 15:33:01 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-12-06 15:33:01 +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();
|
|
|
|
|
2017-08-25 01:14:16 +02:00
|
|
|
auto fd = OpenFile(fs.get(), filename);
|
2014-12-06 15:33:01 +01:00
|
|
|
|
2017-12-01 16:01:49 +01:00
|
|
|
ReadError result{};
|
2014-12-06 15:33:01 +01:00
|
|
|
errno = 0;
|
2017-08-25 01:14:16 +02:00
|
|
|
result.read_bytes = ::pread(fd->fd(), buf, count, offset);
|
2014-12-06 15:33:01 +01:00
|
|
|
result.error = errno;
|
|
|
|
return result;
|
2014-11-27 03:48:38 +01:00
|
|
|
}
|
|
|
|
|
2017-08-25 01:14:16 +02:00
|
|
|
unique_ref<OpenFileHandle> FuseReadTest::OpenFile(const TempTestFS *fs, const char *filename) {
|
2014-11-27 03:48:38 +01:00
|
|
|
auto realpath = fs->mountDir() / filename;
|
2018-05-21 01:20:38 +02:00
|
|
|
auto fd = make_unique_ref<OpenFileHandle>(realpath.string().c_str(), O_RDONLY);
|
2017-08-25 01:14:16 +02:00
|
|
|
EXPECT_GE(fd->fd(), 0) << "Error opening file";
|
2014-11-27 03:48:38 +01:00
|
|
|
return fd;
|
|
|
|
}
|