diff --git a/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.cpp b/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.cpp index d354a931..2bc08a45 100644 --- a/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.cpp +++ b/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.cpp @@ -14,7 +14,3 @@ int FuseCreateAndOpenTest::CreateAndOpenFileAllowError(const char *filename, int auto realpath = fs->mountDir() / filename; return ::open(realpath.c_str(), flags | O_CREAT); } - -void FuseCreateAndOpenTest::ReturnIsFileOnFstat(int descriptor) { - EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstat); -} diff --git a/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.h b/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.h index a2aa5b9e..f81b544a 100644 --- a/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.h +++ b/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.h @@ -10,7 +10,6 @@ public: int CreateAndOpenFile(const char *FILENAME, int flags); int CreateAndOpenFileAllowError(const char *FILENAME, int flags); - void ReturnIsFileOnFstat(int descriptor); }; MATCHER_P(OpenFlagsEq, expectedFlags, "") { diff --git a/src/test/fspp/fuse/fstat/FuseFstatErrorTest.cpp b/src/test/fspp/fuse/fstat/FuseFstatErrorTest.cpp index 05fdffe4..7c795229 100644 --- a/src/test/fspp/fuse/fstat/FuseFstatErrorTest.cpp +++ b/src/test/fspp/fuse/fstat/FuseFstatErrorTest.cpp @@ -28,7 +28,7 @@ INSTANTIATE_TEST_CASE_P(FuseFstatErrorTest, FuseFstatErrorTest, Values(EACCES, E TEST_P(FuseFstatErrorTest, ReturnedErrorCodeIsCorrect) { ReturnDoesntExistOnLstat(FILENAME); - EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _)).Times(1).WillOnce(Return(0)); + OnCreateAndOpenReturnFileDescriptor(FILENAME, 0); EXPECT_CALL(fsimpl, fstat(Eq(0), _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); diff --git a/src/test/fspp/fuse/fstat/FuseFstatParameterTest.cpp b/src/test/fspp/fuse/fstat/FuseFstatParameterTest.cpp index 26e4a65b..23fb6c63 100644 --- a/src/test/fspp/fuse/fstat/FuseFstatParameterTest.cpp +++ b/src/test/fspp/fuse/fstat/FuseFstatParameterTest.cpp @@ -29,7 +29,8 @@ INSTANTIATE_TEST_CASE_P(FuseFstatParameterTest, FuseFstatParameterTest, Values(0 TEST_P(FuseFstatParameterTest, FileDescriptorIsCorrect) { ReturnDoesntExistOnLstat(FILENAME); - EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _)).Times(1).WillOnce(Return(GetParam())); + OnCreateAndOpenReturnFileDescriptor(FILENAME, GetParam()); + EXPECT_CALL(fsimpl, fstat(Eq(GetParam()), _)).Times(1).WillOnce(ReturnIsFileFstat); CallFstat(FILENAME); diff --git a/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.cpp b/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.cpp new file mode 100644 index 00000000..778ca0af --- /dev/null +++ b/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.cpp @@ -0,0 +1,20 @@ +#include "FuseFstatTest.h" + +using ::testing::StrEq; +using ::testing::_; +using ::testing::Return; + +int FuseFstatTest::CreateFile(const TempTestFS *fs, const std::string &filename) { + int fd = CreateFileAllowErrors(fs, filename); + EXPECT_GE(fd, 0) << "Opening file failed"; + return fd; +} + +int FuseFstatTest::CreateFileAllowErrors(const TempTestFS *fs, const std::string &filename) { + auto real_path = fs->mountDir() / filename; + return ::open(real_path.c_str(), O_RDWR | O_CREAT); +} + +void FuseFstatTest::OnCreateAndOpenReturnFileDescriptor(const char *filename, int descriptor) { + EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(filename), _)).Times(1).WillOnce(Return(descriptor)); +} diff --git a/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.h b/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.h index 60ce4dc2..58a76706 100644 --- a/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.h +++ b/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.h @@ -6,15 +6,9 @@ class FuseFstatTest: public FuseTest { public: - int CreateFile(const TempTestFS *fs, const std::string &filename) { - int fd = CreateFileAllowErrors(fs, filename); - EXPECT_GE(fd, 0) << "Opening file failed"; - return fd; - } - int CreateFileAllowErrors(const TempTestFS *fs, const std::string &filename) { - auto real_path = fs->mountDir() / filename; - return ::open(real_path.c_str(), O_RDWR | O_CREAT); - } + int CreateFile(const TempTestFS *fs, const std::string &filename); + int CreateFileAllowErrors(const TempTestFS *fs, const std::string &filename); + void OnCreateAndOpenReturnFileDescriptor(const char *filename, int descriptor); }; diff --git a/src/test/testutils/FuseTest.cpp b/src/test/testutils/FuseTest.cpp index 8911deb2..d032d79b 100644 --- a/src/test/testutils/FuseTest.cpp +++ b/src/test/testutils/FuseTest.cpp @@ -1,7 +1,28 @@ #include "FuseTest.h" -using ::testing::Action; -using ::testing::Invoke; +using ::testing::StrEq; +using ::testing::_; +using ::testing::Return; MockFilesystem::MockFilesystem() {} MockFilesystem::~MockFilesystem() {} + +void FuseTest::OnOpenReturnFileDescriptor(const char *filename, int descriptor) { + EXPECT_CALL(fsimpl, openFile(StrEq(filename), _)).Times(1).WillOnce(Return(descriptor)); +} + +void FuseTest::ReturnIsFileOnLstat(const bf::path &path) { + EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.c_str()), ::testing::_)).WillRepeatedly(ReturnIsFile); +} + +void FuseTest::ReturnIsDirOnLstat(const bf::path &path) { + EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.c_str()), ::testing::_)).WillRepeatedly(ReturnIsDir); +} + +void FuseTest::ReturnDoesntExistOnLstat(const bf::path &path) { + EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.c_str()), ::testing::_)).WillRepeatedly(ReturnDoesntExist); +} + +void FuseTest::ReturnIsFileOnFstat(int descriptor) { + EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstat); +} diff --git a/src/test/testutils/FuseTest.h b/src/test/testutils/FuseTest.h index 0f8ef05c..c1634b8f 100644 --- a/src/test/testutils/FuseTest.h +++ b/src/test/testutils/FuseTest.h @@ -145,17 +145,11 @@ public: ::testing::Action ReturnDoesntExist = ::testing::Throw(fspp::FuseErrnoException(ENOENT)); - void ReturnIsFileOnLstat(const bf::path &path) { - EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.c_str()), ::testing::_)).WillRepeatedly(ReturnIsFile); - } - - void ReturnIsDirOnLstat(const bf::path &path) { - EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.c_str()), ::testing::_)).WillRepeatedly(ReturnIsDir); - } - - void ReturnDoesntExistOnLstat(const bf::path &path) { - EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.c_str()), ::testing::_)).WillRepeatedly(ReturnDoesntExist); - } + void ReturnIsFileOnLstat(const bf::path &path); + void ReturnIsDirOnLstat(const bf::path &path); + void ReturnDoesntExistOnLstat(const bf::path &path); + void OnOpenReturnFileDescriptor(const char *filename, int descriptor); + void ReturnIsFileOnFstat(int descriptor); }; #endif