Testcases for fdatasync
This commit is contained in:
parent
595593a97c
commit
2ca7c293b9
@ -23,8 +23,8 @@ public:
|
||||
virtual int read(int descriptor, void *buf, size_t count, off_t offset) = 0;
|
||||
virtual void write(int descriptor, const void *buf, size_t count, off_t offset) = 0;
|
||||
virtual void fsync(int descriptor) = 0;
|
||||
//TODO Unit-Tests for all functions below
|
||||
virtual void fdatasync(int descriptor) = 0;
|
||||
//TODO Unit-Tests for all functions below
|
||||
virtual void access(const boost::filesystem::path &path, int mask) = 0;
|
||||
virtual void mkdir(const boost::filesystem::path &path, mode_t mode) = 0;
|
||||
virtual void rmdir(const boost::filesystem::path &path) = 0;
|
||||
|
28
src/test/fspp/fuse/fdatasync/FuseFdatasyncErrorTest.cpp
Normal file
28
src/test/fspp/fuse/fdatasync/FuseFdatasyncErrorTest.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "testutils/FuseFdatasyncTest.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "fspp/impl/FuseErrnoException.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::StrEq;
|
||||
using ::testing::Throw;
|
||||
using ::testing::WithParamInterface;
|
||||
using ::testing::Values;
|
||||
|
||||
using namespace fspp;
|
||||
|
||||
class FuseFdatasyncErrorTest: public FuseFdatasyncTest, public WithParamInterface<int> {
|
||||
};
|
||||
INSTANTIATE_TEST_CASE_P(FuseFdatasyncErrorTest, FuseFdatasyncErrorTest, Values(EBADF, EIO, EROFS, EINVAL));
|
||||
|
||||
TEST_P(FuseFdatasyncErrorTest, ReturnedErrorIsCorrect) {
|
||||
ReturnIsFileOnLstat(FILENAME);
|
||||
OnOpenReturnFileDescriptor(FILENAME, 0);
|
||||
EXPECT_CALL(fsimpl, fdatasync(0))
|
||||
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
|
||||
|
||||
int retval = FdatasyncFileAllowError(FILENAME);
|
||||
EXPECT_EQ(GetParam(), errno);
|
||||
EXPECT_EQ(-1, retval);
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#include "testutils/FuseFdatasyncTest.h"
|
||||
|
||||
#include "fspp/impl/FuseErrnoException.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::StrEq;
|
||||
using ::testing::WithParamInterface;
|
||||
using ::testing::Values;
|
||||
using ::testing::Eq;
|
||||
using ::testing::Return;
|
||||
|
||||
using namespace fspp;
|
||||
|
||||
class FuseFdatasyncFileDescriptorTest: public FuseFdatasyncTest, public WithParamInterface<int> {
|
||||
};
|
||||
INSTANTIATE_TEST_CASE_P(FuseFdatasyncFileDescriptorTest, FuseFdatasyncFileDescriptorTest, Values(0,1,10,1000,1024*1024*1024));
|
||||
|
||||
|
||||
TEST_P(FuseFdatasyncFileDescriptorTest, FileDescriptorIsCorrect) {
|
||||
ReturnIsFileOnLstat(FILENAME);
|
||||
OnOpenReturnFileDescriptor(FILENAME, GetParam());
|
||||
EXPECT_CALL(fsimpl, fdatasync(Eq(GetParam())))
|
||||
.Times(1).WillOnce(Return());
|
||||
|
||||
FdatasyncFile(FILENAME);
|
||||
}
|
20
src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.cpp
Normal file
20
src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "FuseFdatasyncTest.h"
|
||||
|
||||
void FuseFdatasyncTest::FdatasyncFile(const char *filename) {
|
||||
int retval = FdatasyncFileAllowError(filename);
|
||||
EXPECT_EQ(0, retval);
|
||||
}
|
||||
|
||||
int FuseFdatasyncTest::FdatasyncFileAllowError(const char *filename) {
|
||||
auto fs = TestFS();
|
||||
|
||||
int fd = OpenFile(fs.get(), filename);
|
||||
return ::fdatasync(fd);
|
||||
}
|
||||
|
||||
int FuseFdatasyncTest::OpenFile(const TempTestFS *fs, const char *filename) {
|
||||
auto realpath = fs->mountDir() / filename;
|
||||
int fd = ::open(realpath.c_str(), O_RDWR);
|
||||
EXPECT_GE(fd, 0) << "Error opening file";
|
||||
return fd;
|
||||
}
|
18
src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.h
Normal file
18
src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#ifndef TEST_FSPP_FUSE_FDATASYNC_TESTUTILS_FUSEFDATASYNCTEST_H_
|
||||
#define TEST_FSPP_FUSE_FDATASYNC_TESTUTILS_FUSEFDATASYNCTEST_H_
|
||||
|
||||
#include "test/testutils/FuseTest.h"
|
||||
|
||||
class FuseFdatasyncTest: public FuseTest {
|
||||
public:
|
||||
const char *FILENAME = "/myfile";
|
||||
|
||||
void FdatasyncFile(const char *filename);
|
||||
int FdatasyncFileAllowError(const char *filename);
|
||||
|
||||
private:
|
||||
int OpenFile(const TempTestFS *fs, const char *filename);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user