Fix test cases

This commit is contained in:
Sebastian Messmer 2014-11-25 13:07:15 +01:00
parent 5e13b65427
commit c2c53676d9
4 changed files with 28 additions and 29 deletions

View File

@ -36,7 +36,7 @@ TEST_P(FuseOpenFileDescriptorTest, TestReturnedFileDescriptor) {
ReturnIsFileOnLstat(FILENAME); ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _)) EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _))
.Times(1).WillOnce(Return(GetParam())); .Times(1).WillOnce(Return(GetParam()));
EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1); EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(0));
OpenAndReadFile(FILENAME); OpenAndReadFile(FILENAME);
} }

View File

@ -5,6 +5,7 @@
using ::testing::_; using ::testing::_;
using ::testing::StrEq; using ::testing::StrEq;
using ::testing::Return;
class FuseOpenFilenameTest: public FuseOpenTest { class FuseOpenFilenameTest: public FuseOpenTest {
public: public:
@ -13,7 +14,7 @@ public:
TEST_F(FuseOpenFilenameTest, OpenFile) { TEST_F(FuseOpenFilenameTest, OpenFile) {
ReturnIsFileOnLstat("/myfile"); ReturnIsFileOnLstat("/myfile");
EXPECT_CALL(fsimpl, openFile(StrEq("/myfile"), _)) EXPECT_CALL(fsimpl, openFile(StrEq("/myfile"), _))
.Times(1); .Times(1).WillOnce(Return(0));
OpenFile("/myfile", O_RDONLY); OpenFile("/myfile", O_RDONLY);
} }
@ -22,7 +23,7 @@ TEST_F(FuseOpenFilenameTest, OpenFileNested) {
ReturnIsDirOnLstat("/mydir"); ReturnIsDirOnLstat("/mydir");
ReturnIsFileOnLstat("/mydir/myfile"); ReturnIsFileOnLstat("/mydir/myfile");
EXPECT_CALL(fsimpl, openFile(StrEq("/mydir/myfile"), _)) EXPECT_CALL(fsimpl, openFile(StrEq("/mydir/myfile"), _))
.Times(1); .Times(1).WillOnce(Return(0));
OpenFile("/mydir/myfile", O_RDONLY); OpenFile("/mydir/myfile", O_RDONLY);
} }
@ -32,7 +33,7 @@ TEST_F(FuseOpenFilenameTest, OpenFileNested2) {
ReturnIsDirOnLstat("/mydir/mydir2"); ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsFileOnLstat("/mydir/mydir2/myfile"); ReturnIsFileOnLstat("/mydir/mydir2/myfile");
EXPECT_CALL(fsimpl, openFile(StrEq("/mydir/mydir2/myfile"), _)) EXPECT_CALL(fsimpl, openFile(StrEq("/mydir/mydir2/myfile"), _))
.Times(1); .Times(1).WillOnce(Return(0));
OpenFile("/mydir/mydir2/myfile", O_RDONLY); OpenFile("/mydir/mydir2/myfile", O_RDONLY);
} }

View File

@ -4,6 +4,7 @@ using ::testing::_;
using ::testing::StrEq; using ::testing::StrEq;
using ::testing::WithParamInterface; using ::testing::WithParamInterface;
using ::testing::Values; using ::testing::Values;
using ::testing::Return;
class FuseOpenFlagsTest: public FuseOpenTest, public WithParamInterface<int> { class FuseOpenFlagsTest: public FuseOpenTest, public WithParamInterface<int> {
}; };
@ -12,7 +13,7 @@ INSTANTIATE_TEST_CASE_P(FuseOpenFlagsTest, FuseOpenFlagsTest, Values(O_RDWR, O_R
TEST_P(FuseOpenFlagsTest, testFlags) { TEST_P(FuseOpenFlagsTest, testFlags) {
ReturnIsFileOnLstat(FILENAME); ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), OpenFlagsEq(GetParam()))) EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), OpenFlagsEq(GetParam())))
.Times(1); .Times(1).WillOnce(Return(0));
OpenFile(FILENAME, GetParam()); OpenFile(FILENAME, GetParam());
} }

View File

@ -68,29 +68,26 @@ public:
class FuseTest: public ::testing::Test { class FuseTest: public ::testing::Test {
public: public:
FuseTest(): fsimpl() { FuseTest(): fsimpl() {
/*auto defaultAction = Throw(fspp::FuseErrnoException(EIO)); auto defaultAction = ::testing::Throw(fspp::FuseErrnoException(EIO));
ON_CALL(fsimpl, openFile(_,_)).WillByDefault(defaultAction); ON_CALL(fsimpl, openFile(::testing::_,::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, closeFile(_)).WillByDefault(defaultAction); ON_CALL(fsimpl, closeFile(::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, lstat(_,_)).WillByDefault(Invoke([](const char *path, struct ::stat *) { ON_CALL(fsimpl, lstat(::testing::_,::testing::_)).WillByDefault(defaultAction);
printf("LSTAT\n");fflush(stdout); ON_CALL(fsimpl, fstat(::testing::_,::testing::_)).WillByDefault(defaultAction);
throw fspp::FuseErrnoException(EIO); ON_CALL(fsimpl, truncate(::testing::_,::testing::_)).WillByDefault(defaultAction);
})); ON_CALL(fsimpl, ftruncate(::testing::_,::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, fstat(_,_)).WillByDefault(defaultAction); ON_CALL(fsimpl, read(::testing::_,::testing::_,::testing::_,::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, truncate(_,_)).WillByDefault(defaultAction); ON_CALL(fsimpl, write(::testing::_,::testing::_,::testing::_,::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, ftruncate(_,_)).WillByDefault(defaultAction); ON_CALL(fsimpl, fsync(::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, read(_,_,_,_)).WillByDefault(defaultAction); ON_CALL(fsimpl, fdatasync(::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, write(_,_,_,_)).WillByDefault(defaultAction); ON_CALL(fsimpl, access(::testing::_,::testing:: _)).WillByDefault(defaultAction);
ON_CALL(fsimpl, fsync(_)).WillByDefault(defaultAction); ON_CALL(fsimpl, createAndOpenFile(::testing::_,::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, fdatasync(_)).WillByDefault(defaultAction); ON_CALL(fsimpl, mkdir(::testing::_, ::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, access(_, _)).WillByDefault(defaultAction); ON_CALL(fsimpl, rmdir(::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, createAndOpenFile(_,_)).WillByDefault(defaultAction); ON_CALL(fsimpl, unlink(::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, mkdir(_, _)).WillByDefault(defaultAction); ON_CALL(fsimpl, rename(::testing::_,::testing:: _)).WillByDefault(defaultAction);
ON_CALL(fsimpl, rmdir(_)).WillByDefault(defaultAction); ON_CALL(fsimpl, readDir(::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, unlink(_)).WillByDefault(defaultAction); ON_CALL(fsimpl, utimens(::testing::_, ::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, rename(_, _)).WillByDefault(defaultAction); ON_CALL(fsimpl, statfs(::testing::_, ::testing::_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, readDir(_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, utimens(_, _)).WillByDefault(defaultAction);
ON_CALL(fsimpl, statfs(_, _)).WillByDefault(defaultAction);*/
} }
class TempTestFS { class TempTestFS {
@ -120,7 +117,7 @@ public:
return std::make_unique<TempTestFS>(&fsimpl); return std::make_unique<TempTestFS>(&fsimpl);
} }
::testing::StrictMock<MockFilesystem> fsimpl; MockFilesystem fsimpl;
::testing::Action<void(const char*, struct ::stat*)> ReturnIsFile = ::testing::Action<void(const char*, struct ::stat*)> ReturnIsFile =
::testing::Invoke([](const char*, struct ::stat* result) { ::testing::Invoke([](const char*, struct ::stat* result) {