Improve Path Parameter Tests (they now also test that the return value is success)

This commit is contained in:
Sebastian Messmer 2014-11-20 13:19:15 +01:00
parent 8ddf18666c
commit 5a77f791b6
2 changed files with 26 additions and 21 deletions

View File

@ -30,16 +30,17 @@ public:
const off_t SIZE2 = 4096;
const off_t SIZE3 = 1024*1024*1024;
int LstatPath(const string &path) {
void LstatPath(const string &path) {
struct stat dummy;
return LstatPath(path, &dummy);
LstatPath(path, &dummy);
}
int LstatPath(const string &path, struct stat *result) {
void LstatPath(const string &path, struct stat *result) {
auto fs = TestFS();
auto realpath = fs->mountDir() / path;
return ::lstat(realpath.c_str(), result);
int retval = ::lstat(realpath.c_str(), result);
EXPECT_EQ(0, retval) << "lstat syscall failed. errno: " << errno;
}
struct stat CallLstatWithMode(mode_t mode) {
@ -110,8 +111,7 @@ private:
}));
struct stat result;
int retval = LstatPath(FILENAME, &result);
EXPECT_EQ(0, retval) << "lstat syscall failed. errno: " << errno;
LstatPath(FILENAME, &result);
return result;
}
@ -119,31 +119,31 @@ private:
TEST_F(FuseLstatTest, PathParameterIsCorrectRoot) {
EXPECT_CALL(fsimpl, lstat(StrEq("/"), _)).Times(1);
EXPECT_CALL(fsimpl, lstat(StrEq("/"), _)).Times(1).WillOnce(ReturnIsDir);
LstatPath("/");
}
TEST_F(FuseLstatTest, PathParameterIsCorrectSimpleFile) {
EXPECT_CALL(fsimpl, lstat(StrEq("/myfile"), _)).Times(1);
EXPECT_CALL(fsimpl, lstat(StrEq("/myfile"), _)).Times(1).WillOnce(ReturnIsFile);
LstatPath("/myfile");
}
TEST_F(FuseLstatTest, PathParameterIsCorrectSimpleDir) {
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir"), _)).Times(1);
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir"), _)).Times(1).WillOnce(ReturnIsDir);
LstatPath("/mydir/");
}
TEST_F(FuseLstatTest, PathParameterIsCorrectNestedFile) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir/mydir2/myfile"), _)).Times(1);
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir/mydir2/myfile"), _)).Times(1).WillOnce(ReturnIsFile);
LstatPath("/mydir/mydir2/myfile");
}
TEST_F(FuseLstatTest, PathParameterIsCorrectNestedDir) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir/mydir2/mydir3"), _)).Times(1);
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir/mydir2/mydir3"), _)).Times(1).WillOnce(ReturnIsDir);
LstatPath("/mydir/mydir2/mydir3/");
}
@ -231,3 +231,4 @@ TEST_F(FuseLstatTest, ReturnedDirSizeIsCorrect3) {
//TODO st_atim
//TODO st_mtim
//TODO st_ctim
//TODO Error cases

View File

@ -121,20 +121,24 @@ public:
MockFilesystem fsimpl;
::testing::Action<void(const char*, struct ::stat*)> ReturnIsFile =
::testing::Invoke([](const char*, struct ::stat* result) {
result->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
result->st_nlink = 1;
});
::testing::Action<void(const char*, struct ::stat*)> ReturnIsDir =
::testing::Invoke([](const char*, struct ::stat* result) {
result->st_mode = S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH;
result->st_nlink = 1;
});
void ReturnIsFileOnLstat(const bf::path &path) {
EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.c_str()), ::testing::_)).WillRepeatedly(
::testing::Invoke([](const char*, struct ::stat* result) {
result->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
result->st_nlink = 1;
}));
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(
::testing::Invoke([](const char*, struct ::stat* result) {
result->st_mode = S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH;
result->st_nlink = 1;
}));
EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.c_str()), ::testing::_)).WillRepeatedly(ReturnIsDir);
}
};