libcryfs/test/fspp/fuse/ftruncate/testutils/FuseFTruncateTest.cpp

29 lines
796 B
C++
Raw Normal View History

2014-11-25 18:54:33 +01:00
#include "FuseFTruncateTest.h"
using cpputils::unique_ref;
using cpputils::make_unique_ref;
2014-11-25 18:54:33 +01:00
void FuseFTruncateTest::FTruncateFile(const char *filename, off_t size) {
int error = FTruncateFileReturnError(filename, size);
EXPECT_EQ(0, error);
2014-11-25 18:54:33 +01:00
}
int FuseFTruncateTest::FTruncateFileReturnError(const char *filename, off_t size) {
2014-11-25 18:54:33 +01:00
auto fs = TestFS();
auto fd = OpenFile(fs.get(), filename);
int retval = ::ftruncate(fd->fd(), size);
if (0 == retval) {
return 0;
} else {
return errno;
}
2014-11-25 18:54:33 +01:00
}
unique_ref<OpenFileHandle> FuseFTruncateTest::OpenFile(const TempTestFS *fs, const char *filename) {
2014-11-25 18:54:33 +01:00
auto realpath = fs->mountDir() / filename;
auto fd = make_unique_ref<OpenFileHandle>(realpath.c_str(), O_RDWR);
EXPECT_GE(fd->fd(), 0) << "Error opening file";
2014-11-25 18:54:33 +01:00
return fd;
}