Added some lstat tests

This commit is contained in:
Sebastian Messmer 2014-11-19 17:03:06 +01:00
parent aaa4f57fc3
commit 2128147f96
4 changed files with 58 additions and 16 deletions

View File

@ -8,18 +8,51 @@ using namespace fspp::fuse;
using ::testing::_;
using ::testing::StrEq;
using ::testing::Action;
using ::testing::Invoke;
typedef FuseTest FuseLstatTest;
using std::vector;
using std::string;
TEST_F(FuseLstatTest, lstat) {
const char *filename = "/myfile";
EXPECT_CALL(fsimpl, lstat(StrEq(filename), _)).WillOnce(ReturnIsFileStat);
class FuseLstatTest: public FuseTest {
public:
struct stat LstatPath(const string &path) {
auto fs = TestFS();
auto fs = TestFS();
auto realpath = fs->mountDir() / path;
struct stat stat;
::lstat(realpath.c_str(), &stat);
auto realpath = fs->mountDir() / filename;
struct stat stat;
::lstat(realpath.c_str(), &stat);
return stat;
}
};
EXPECT_TRUE(S_ISREG(stat.st_mode));
TEST_F(FuseLstatTest, PathParameterIsCorrectRoot) {
EXPECT_CALL(fsimpl, lstat(StrEq("/"), _)).Times(1);
LstatPath("/");
}
TEST_F(FuseLstatTest, PathParameterIsCorrectSimpleFile) {
EXPECT_CALL(fsimpl, lstat(StrEq("/myfile"), _)).Times(1);
LstatPath("/myfile");
}
TEST_F(FuseLstatTest, PathParameterIsCorrectSimpleDir) {
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir"), _)).Times(1);
LstatPath("/mydir/");
}
TEST_F(FuseLstatTest, PathParameterIsCorrectNestedFile) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir/mydir2/myfile"), _)).Times(1);
LstatPath("/mydir/mydir2/myfile");
}
TEST_F(FuseLstatTest, PathParameterIsCorrectNestedDir) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
EXPECT_CALL(fsimpl, lstat(StrEq("/mydir/mydir2/mydir3"), _)).Times(1);
LstatPath("/mydir/mydir2/mydir3/");
}

View File

@ -13,7 +13,7 @@ typedef FuseTest FuseOpenTest;
TEST_F(FuseOpenTest, openFile) {
const char *filename = "/myfile";
EXPECT_CALL(fsimpl, lstat(StrEq(filename), _)).WillOnce(ReturnIsFileStat);
ReturnIsFileOnLstat(filename);
EXPECT_CALL(fsimpl, openFile(StrEq(filename), OpenFlagsEq(O_RDWR)))
.Times(1);

View File

@ -2,8 +2,3 @@
using ::testing::Action;
using ::testing::Invoke;
Action<void(const char*, struct ::stat*)> FuseTest::ReturnIsFileStat =
Invoke([](const char*, struct ::stat* result) {
result->st_mode = S_IFREG;
});

View File

@ -121,7 +121,21 @@ public:
MockFilesystem fsimpl;
static ::testing::Action<void(const char*, struct ::stat*)> ReturnIsFileStat;
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;
}));
}
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;
}));
}
};
MATCHER_P(OpenFlagsEq, expectedFlags, "") {