Split fuse tests into more test files

This commit is contained in:
Sebastian Messmer 2014-11-19 16:16:43 +01:00
parent 9553bf43e6
commit aaa4f57fc3
5 changed files with 62 additions and 32 deletions

View File

@ -0,0 +1,25 @@
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "test/testutils/FuseTest.h"
using namespace fspp;
using namespace fspp::fuse;
using ::testing::_;
using ::testing::StrEq;
typedef FuseTest FuseLstatTest;
TEST_F(FuseLstatTest, lstat) {
const char *filename = "/myfile";
EXPECT_CALL(fsimpl, lstat(StrEq(filename), _)).WillOnce(ReturnIsFileStat);
auto fs = TestFS();
auto realpath = fs->mountDir() / filename;
struct stat stat;
::lstat(realpath.c_str(), &stat);
EXPECT_TRUE(S_ISREG(stat.st_mode));
}

View File

@ -0,0 +1,24 @@
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "test/testutils/FuseTest.h"
using namespace fspp;
using namespace fspp::fuse;
using ::testing::_;
using ::testing::StrEq;
typedef FuseTest FuseOpenTest;
TEST_F(FuseOpenTest, openFile) {
const char *filename = "/myfile";
EXPECT_CALL(fsimpl, lstat(StrEq(filename), _)).WillOnce(ReturnIsFileStat);
EXPECT_CALL(fsimpl, openFile(StrEq(filename), OpenFlagsEq(O_RDWR)))
.Times(1);
auto fs = TestFS();
auto realpath = fs->mountDir() / filename;
::open(realpath.c_str(), O_RDWR);
}

View File

@ -1,7 +1,6 @@
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fspp/fuse/Fuse.h"
#include "test/testutils/FuseTest.h"
using namespace fspp;
@ -10,32 +9,9 @@ using namespace fspp::fuse;
using ::testing::_;
using ::testing::StrEq;
TEST_F(FuseTest, setupAndTearDown) {
typedef FuseTest BasicFuseTest;
TEST_F(BasicFuseTest, setupAndTearDown) {
//This test case simply checks whether a filesystem can be setup and teardown without crashing.
auto fs = TestFS();
}
TEST_F(FuseTest, lstat) {
const char *filename = "/myfile";
EXPECT_CALL(fsimpl, lstat(StrEq(filename), _)).WillOnce(ReturnIsFileStat);
auto fs = TestFS();
auto realpath = fs->mountDir() / filename;
struct stat stat;
::lstat(realpath.c_str(), &stat);
EXPECT_TRUE(S_ISREG(stat.st_mode));
}
TEST_F(FuseTest, openFile) {
const char *filename = "/myfile";
EXPECT_CALL(fsimpl, lstat(StrEq(filename), _)).WillOnce(ReturnIsFileStat);
EXPECT_CALL(fsimpl, openFile(StrEq(filename), OpenFlagsEq(O_RDWR)))
.Times(1);
auto fs = TestFS();
auto realpath = fs->mountDir() / filename;
::open(realpath.c_str(), O_RDWR);
}

View File

@ -0,0 +1,9 @@
#include "FuseTest.h"
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

@ -7,6 +7,7 @@
#include "fspp/impl/Filesystem.h"
#include "fspp/impl/FuseErrnoException.h"
#include "fspp/fuse/Fuse.h"
#include <boost/filesystem.hpp>
@ -127,9 +128,4 @@ MATCHER_P(OpenFlagsEq, expectedFlags, "") {
return expectedFlags == (O_ACCMODE & arg);
}
::testing::Action<void(const char*, struct ::stat*)> FuseTest::ReturnIsFileStat =
::testing::Invoke([](const char*, struct ::stat* result) {
result->st_mode = S_IFREG;
});
#endif