Test refactoring
This commit is contained in:
parent
62b0d0fc08
commit
5438ab05bd
@ -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);
|
||||
}
|
||||
|
@ -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, "") {
|
||||
|
@ -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())));
|
||||
|
||||
|
@ -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);
|
||||
|
20
src/test/fspp/fuse/fstat/testutils/FuseFstatTest.cpp
Normal file
20
src/test/fspp/fuse/fstat/testutils/FuseFstatTest.cpp
Normal file
@ -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));
|
||||
}
|
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -145,17 +145,11 @@ public:
|
||||
|
||||
::testing::Action<void(const char*, struct ::stat*)> 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
|
||||
|
Loading…
Reference in New Issue
Block a user