Implemented fsync test cases

This commit is contained in:
Sebastian Messmer 2014-11-28 11:57:20 +01:00
parent 8862c16ef7
commit bd8fc1de6e
4 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,28 @@
#include "testutils/FuseFsyncTest.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 FuseFsyncErrorTest: public FuseFsyncTest, public WithParamInterface<int> {
};
INSTANTIATE_TEST_CASE_P(FuseFsyncErrorTest, FuseFsyncErrorTest, Values(EBADF, EIO, EROFS, EINVAL));
TEST_P(FuseFsyncErrorTest, ReturnedErrorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, fsync(0))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int retval = FsyncFileAllowError(FILENAME);
EXPECT_EQ(GetParam(), errno);
EXPECT_EQ(-1, retval);
}

View File

@ -0,0 +1,26 @@
#include "testutils/FuseFsyncTest.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 FuseFsyncFileDescriptorTest: public FuseFsyncTest, public WithParamInterface<int> {
};
INSTANTIATE_TEST_CASE_P(FuseFsyncFileDescriptorTest, FuseFsyncFileDescriptorTest, Values(0,1,10,1000,1024*1024*1024));
TEST_P(FuseFsyncFileDescriptorTest, FileDescriptorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
OnOpenReturnFileDescriptor(FILENAME, GetParam());
EXPECT_CALL(fsimpl, fsync(Eq(GetParam())))
.Times(1).WillOnce(Return());
FsyncFile(FILENAME);
}

View File

@ -0,0 +1,20 @@
#include "FuseFsyncTest.h"
void FuseFsyncTest::FsyncFile(const char *filename) {
int retval = FsyncFileAllowError(filename);
EXPECT_EQ(0, retval);
}
int FuseFsyncTest::FsyncFileAllowError(const char *filename) {
auto fs = TestFS();
int fd = OpenFile(fs.get(), filename);
return ::fsync(fd);
}
int FuseFsyncTest::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;
}

View File

@ -0,0 +1,18 @@
#pragma once
#ifndef TEST_FSPP_FUSE_FSYNC_TESTUTILS_FUSEFSYNCTEST_H_
#define TEST_FSPP_FUSE_FSYNC_TESTUTILS_FUSEFSYNCTEST_H_
#include "test/testutils/FuseTest.h"
class FuseFsyncTest: public FuseTest {
public:
const char *FILENAME = "/myfile";
void FsyncFile(const char *filename);
int FsyncFileAllowError(const char *filename);
private:
int OpenFile(const TempTestFS *fs, const char *filename);
};
#endif