diff --git a/src/test/fspp/fuse/lstat/FuseLstatPathParameterTest.cpp b/src/test/fspp/fuse/lstat/FuseLstatPathParameterTest.cpp index 0e0f1b47..deee7967 100644 --- a/src/test/fspp/fuse/lstat/FuseLstatPathParameterTest.cpp +++ b/src/test/fspp/fuse/lstat/FuseLstatPathParameterTest.cpp @@ -1,4 +1,4 @@ -#include "FuseLstatTest.h" +#include "testutils/FuseLstatTest.h" using ::testing::_; using ::testing::StrEq; diff --git a/src/test/fspp/fuse/lstat/FuseLstatReturnGidTest.cpp b/src/test/fspp/fuse/lstat/FuseLstatReturnGidTest.cpp index cf64c769..bdb38b3e 100644 --- a/src/test/fspp/fuse/lstat/FuseLstatReturnGidTest.cpp +++ b/src/test/fspp/fuse/lstat/FuseLstatReturnGidTest.cpp @@ -1,6 +1,6 @@ -#include "FuseLstatReturnTest.h" +#include "testutils/FuseLstatReturnTest.h" -class FuseLstatReturnPropertyGidTest: public FuseLstatReturnPropertyTest { +class FuseLstatReturnGidTest: public FuseLstatReturnTest { public: const gid_t GID1 = 0; const gid_t GID2 = 10; @@ -10,22 +10,22 @@ private: } }; -TEST_F(FuseLstatReturnPropertyGidTest, ReturnedFileGidIsCorrect1) { +TEST_F(FuseLstatReturnGidTest, ReturnedFileGidIsCorrect1) { struct ::stat result = CallFileLstatWithValue(GID1); EXPECT_EQ(GID1, result.st_gid); } -TEST_F(FuseLstatReturnPropertyGidTest, ReturnedFileGidIsCorrect2) { +TEST_F(FuseLstatReturnGidTest, ReturnedFileGidIsCorrect2) { struct ::stat result = CallFileLstatWithValue(GID2); EXPECT_EQ(GID2, result.st_gid); } -TEST_F(FuseLstatReturnPropertyGidTest, ReturnedDirGidIsCorrect1) { +TEST_F(FuseLstatReturnGidTest, ReturnedDirGidIsCorrect1) { struct ::stat result = CallDirLstatWithValue(GID1); EXPECT_EQ(GID1, result.st_gid); } -TEST_F(FuseLstatReturnPropertyGidTest, ReturnedDirGidIsCorrect2) { +TEST_F(FuseLstatReturnGidTest, ReturnedDirGidIsCorrect2) { struct ::stat result = CallDirLstatWithValue(GID2); EXPECT_EQ(GID2, result.st_gid); } diff --git a/src/test/fspp/fuse/lstat/FuseLstatReturnModeTest.cpp b/src/test/fspp/fuse/lstat/FuseLstatReturnModeTest.cpp index 40427eed..fc43a3d8 100644 --- a/src/test/fspp/fuse/lstat/FuseLstatReturnModeTest.cpp +++ b/src/test/fspp/fuse/lstat/FuseLstatReturnModeTest.cpp @@ -1,6 +1,6 @@ -#include "FuseLstatReturnTest.h" +#include "testutils/FuseLstatReturnTest.h" -class FuseLstatReturnPropertyModeTest: public FuseLstatTest { +class FuseLstatReturnModeTest: public FuseLstatTest { public: const mode_t MODE1 = S_IFREG | S_IRUSR | S_IWGRP | S_IXOTH; const mode_t MODE2 = S_IFDIR | S_IWUSR | S_IXGRP | S_IROTH; @@ -12,12 +12,12 @@ public: } }; -TEST_F(FuseLstatReturnPropertyModeTest, ReturnedModeIsCorrect1) { +TEST_F(FuseLstatReturnModeTest, ReturnedModeIsCorrect1) { struct ::stat result = CallLstatWithValue(MODE1); EXPECT_EQ(MODE1, result.st_mode); } -TEST_F(FuseLstatReturnPropertyModeTest, ReturnedModeIsCorrect2) { +TEST_F(FuseLstatReturnModeTest, ReturnedModeIsCorrect2) { struct ::stat result = CallLstatWithValue(MODE2); EXPECT_EQ(MODE2, result.st_mode); } diff --git a/src/test/fspp/fuse/lstat/FuseLstatReturnNlinkTest.cpp b/src/test/fspp/fuse/lstat/FuseLstatReturnNlinkTest.cpp index 081dd7d9..2b048ad4 100644 --- a/src/test/fspp/fuse/lstat/FuseLstatReturnNlinkTest.cpp +++ b/src/test/fspp/fuse/lstat/FuseLstatReturnNlinkTest.cpp @@ -1,6 +1,6 @@ -#include "FuseLstatReturnTest.h" +#include "testutils/FuseLstatReturnTest.h" -class FuseLstatReturnPropertyNlinkTest: public FuseLstatReturnPropertyTest { +class FuseLstatReturnNlinkTest: public FuseLstatReturnTest { public: const nlink_t NLINK1 = 1; const nlink_t NLINK2 = 5; @@ -10,22 +10,22 @@ private: } }; -TEST_F(FuseLstatReturnPropertyNlinkTest, ReturnedFileNlinkIsCorrect1) { +TEST_F(FuseLstatReturnNlinkTest, ReturnedFileNlinkIsCorrect1) { struct ::stat result = CallDirLstatWithValue(NLINK1); EXPECT_EQ(NLINK1, result.st_nlink); } -TEST_F(FuseLstatReturnPropertyNlinkTest, ReturnedFileNlinkIsCorrect2) { +TEST_F(FuseLstatReturnNlinkTest, ReturnedFileNlinkIsCorrect2) { struct ::stat result = CallDirLstatWithValue(NLINK2); EXPECT_EQ(NLINK2, result.st_nlink); } -TEST_F(FuseLstatReturnPropertyNlinkTest, ReturnedDirNlinkIsCorrect1) { +TEST_F(FuseLstatReturnNlinkTest, ReturnedDirNlinkIsCorrect1) { struct ::stat result = CallDirLstatWithValue(NLINK1); EXPECT_EQ(NLINK1, result.st_nlink); } -TEST_F(FuseLstatReturnPropertyNlinkTest, ReturnedDirNlinkIsCorrect2) { +TEST_F(FuseLstatReturnNlinkTest, ReturnedDirNlinkIsCorrect2) { struct ::stat result = CallDirLstatWithValue(NLINK2); EXPECT_EQ(NLINK2, result.st_nlink); } diff --git a/src/test/fspp/fuse/lstat/FuseLstatReturnSizeTest.cpp b/src/test/fspp/fuse/lstat/FuseLstatReturnSizeTest.cpp index e4ae6d51..5714be39 100644 --- a/src/test/fspp/fuse/lstat/FuseLstatReturnSizeTest.cpp +++ b/src/test/fspp/fuse/lstat/FuseLstatReturnSizeTest.cpp @@ -1,6 +1,6 @@ -#include "FuseLstatReturnTest.h" +#include "testutils/FuseLstatReturnTest.h" -class FuseLstatReturnPropertySizeTest: public FuseLstatReturnPropertyTest { +class FuseLstatReturnSizeTest: public FuseLstatReturnTest { public: const off_t SIZE1 = 0; const off_t SIZE2 = 4096; @@ -11,32 +11,32 @@ private: } }; -TEST_F(FuseLstatReturnPropertySizeTest, ReturnedFileSizeIsCorrect1) { +TEST_F(FuseLstatReturnSizeTest, ReturnedFileSizeIsCorrect1) { struct ::stat result = CallDirLstatWithValue(SIZE1); EXPECT_EQ(SIZE1, result.st_size); } -TEST_F(FuseLstatReturnPropertySizeTest, ReturnedFileSizeIsCorrect2) { +TEST_F(FuseLstatReturnSizeTest, ReturnedFileSizeIsCorrect2) { struct ::stat result = CallDirLstatWithValue(SIZE2); EXPECT_EQ(SIZE2, result.st_size); } -TEST_F(FuseLstatReturnPropertySizeTest, ReturnedFileSizeIsCorrect3) { +TEST_F(FuseLstatReturnSizeTest, ReturnedFileSizeIsCorrect3) { struct ::stat result = CallDirLstatWithValue(SIZE3); EXPECT_EQ(SIZE3, result.st_size); } -TEST_F(FuseLstatReturnPropertySizeTest, ReturnedDirSizeIsCorrect1) { +TEST_F(FuseLstatReturnSizeTest, ReturnedDirSizeIsCorrect1) { struct ::stat result = CallDirLstatWithValue(SIZE1); EXPECT_EQ(SIZE1, result.st_size); } -TEST_F(FuseLstatReturnPropertySizeTest, ReturnedDirSizeIsCorrect2) { +TEST_F(FuseLstatReturnSizeTest, ReturnedDirSizeIsCorrect2) { struct ::stat result = CallDirLstatWithValue(SIZE2); EXPECT_EQ(SIZE2, result.st_size); } -TEST_F(FuseLstatReturnPropertySizeTest, ReturnedDirSizeIsCorrect3) { +TEST_F(FuseLstatReturnSizeTest, ReturnedDirSizeIsCorrect3) { struct ::stat result = CallDirLstatWithValue(SIZE3); EXPECT_EQ(SIZE3, result.st_size); } diff --git a/src/test/fspp/fuse/lstat/FuseLstatReturnTest.h b/src/test/fspp/fuse/lstat/FuseLstatReturnTest.h deleted file mode 100644 index 313f3b1b..00000000 --- a/src/test/fspp/fuse/lstat/FuseLstatReturnTest.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#ifndef TEST_FSPP_FUSE_LSTAT_FUSELSTATRETURNTEST_H_ -#define TEST_FSPP_FUSE_LSTAT_FUSELSTATRETURNTEST_H_ - -#include "FuseLstatTest.h" - -template -class FuseLstatReturnPropertyTest: public FuseLstatTest { -public: - struct stat CallFileLstatWithValue(Property value) { - return CallFileLstatWithImpl(SetPropertyImpl(value)); - } - struct stat CallDirLstatWithValue(Property value) { - return CallDirLstatWithImpl(SetPropertyImpl(value)); - } -private: - std::function SetPropertyImpl(Property value) { - return [this, value] (struct stat *stat) { - set(stat, value); - }; - } - virtual void set(struct stat *stat, Property value) = 0; -}; - - -#endif diff --git a/src/test/fspp/fuse/lstat/FuseLstatReturnUidTest.cpp b/src/test/fspp/fuse/lstat/FuseLstatReturnUidTest.cpp index b679003a..0f7b4912 100644 --- a/src/test/fspp/fuse/lstat/FuseLstatReturnUidTest.cpp +++ b/src/test/fspp/fuse/lstat/FuseLstatReturnUidTest.cpp @@ -1,6 +1,6 @@ -#include "FuseLstatReturnTest.h" +#include "testutils/FuseLstatReturnTest.h" -class FuseLstatReturnPropertyUidTest: public FuseLstatReturnPropertyTest { +class FuseLstatReturnUidTest: public FuseLstatReturnTest { public: const uid_t UID1 = 0; const uid_t UID2 = 10; @@ -10,22 +10,22 @@ private: } }; -TEST_F(FuseLstatReturnPropertyUidTest, ReturnedFileUidIsCorrect1) { +TEST_F(FuseLstatReturnUidTest, ReturnedFileUidIsCorrect1) { struct ::stat result = CallFileLstatWithValue(UID1); EXPECT_EQ(UID1, result.st_uid); } -TEST_F(FuseLstatReturnPropertyUidTest, ReturnedFileUidIsCorrect2) { +TEST_F(FuseLstatReturnUidTest, ReturnedFileUidIsCorrect2) { struct ::stat result = CallFileLstatWithValue(UID2); EXPECT_EQ(UID2, result.st_uid); } -TEST_F(FuseLstatReturnPropertyUidTest, ReturnedDirUidIsCorrect1) { +TEST_F(FuseLstatReturnUidTest, ReturnedDirUidIsCorrect1) { struct ::stat result = CallDirLstatWithValue(UID1); EXPECT_EQ(UID1, result.st_uid); } -TEST_F(FuseLstatReturnPropertyUidTest, ReturnedDirUidIsCorrect2) { +TEST_F(FuseLstatReturnUidTest, ReturnedDirUidIsCorrect2) { struct ::stat result = CallDirLstatWithValue(UID2); EXPECT_EQ(UID2, result.st_uid); } diff --git a/src/test/fspp/fuse/lstat/FuseLstatTest.h b/src/test/fspp/fuse/lstat/FuseLstatTest.h deleted file mode 100644 index a651d6f9..00000000 --- a/src/test/fspp/fuse/lstat/FuseLstatTest.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once -#ifndef TEST_FSPP_FUSE_LSTAT_FUSELSTATTEST_H_ -#define TEST_FSPP_FUSE_LSTAT_FUSELSTATTEST_H_ - -#include "gmock/gmock.h" - -#include -#include -#include - -#include "test/testutils/FuseTest.h" - -class FuseLstatTest: public FuseTest { -public: - const char *FILENAME = "/myfile"; - - void LstatPath(const std::string &path) { - struct stat dummy; - LstatPath(path, &dummy); - } - - void LstatPath(const std::string &path, struct stat *result) { - auto fs = TestFS(); - - auto realpath = fs->mountDir() / path; - int retval = ::lstat(realpath.c_str(), result); - EXPECT_EQ(0, retval) << "lstat syscall failed. errno: " << errno; - } - -protected: - struct stat CallFileLstatWithImpl(std::function implementation) { - return CallLstatWithModeAndImpl(S_IFREG, implementation); - } - - struct stat CallDirLstatWithImpl(std::function implementation) { - return CallLstatWithModeAndImpl(S_IFDIR, implementation); - } - - struct stat CallLstatWithImpl(std::function implementation) { - EXPECT_CALL(fsimpl, lstat(::testing::StrEq(FILENAME), ::testing::_)).WillRepeatedly(::testing::Invoke([implementation](const char*, struct ::stat *stat) { - implementation(stat); - })); - - struct stat result; - LstatPath(FILENAME, &result); - - return result; - } - -private: - - struct stat CallLstatWithModeAndImpl(mode_t mode, std::function implementation) { - return CallLstatWithImpl([mode, implementation] (struct stat *stat) { - stat->st_mode = mode; - implementation(stat); - }); - } -}; - -#endif diff --git a/src/test/fspp/fuse/lstat/testutils/FuseLstatReturnTest.h b/src/test/fspp/fuse/lstat/testutils/FuseLstatReturnTest.h new file mode 100644 index 00000000..8dae044c --- /dev/null +++ b/src/test/fspp/fuse/lstat/testutils/FuseLstatReturnTest.h @@ -0,0 +1,37 @@ +#pragma once +#ifndef TEST_FSPP_FUSE_LSTAT_FUSELSTATRETURNTEST_H_ +#define TEST_FSPP_FUSE_LSTAT_FUSELSTATRETURNTEST_H_ + +#include "FuseLstatTest.h" + +template +class FuseLstatReturnTest: public FuseLstatTest { +public: + struct stat CallFileLstatWithValue(Property value); + struct stat CallDirLstatWithValue(Property value); + +private: + std::function SetPropertyImpl(Property value); + + virtual void set(struct stat *stat, Property value) = 0; +}; + +template +struct stat FuseLstatReturnTest::CallFileLstatWithValue(Property value) { + return CallFileLstatWithImpl(SetPropertyImpl(value)); +} + +template +struct stat FuseLstatReturnTest::CallDirLstatWithValue(Property value) { + return CallDirLstatWithImpl(SetPropertyImpl(value)); +} + +template +std::function FuseLstatReturnTest::SetPropertyImpl(Property value) { + return [this, value] (struct stat *stat) { + set(stat, value); + }; +} + + +#endif diff --git a/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.cpp b/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.cpp new file mode 100644 index 00000000..656df198 --- /dev/null +++ b/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.cpp @@ -0,0 +1,45 @@ +#include "FuseLstatTest.h" + +using std::function; +using ::testing::StrEq; +using ::testing::_; +using ::testing::Invoke; + +void FuseLstatTest::LstatPath(const std::string &path) { + struct stat dummy; + LstatPath(path, &dummy); +} + +void FuseLstatTest::LstatPath(const std::string &path, struct stat *result) { + auto fs = TestFS(); + + auto realpath = fs->mountDir() / path; + int retval = ::lstat(realpath.c_str(), result); + EXPECT_EQ(0, retval) << "lstat syscall failed. errno: " << errno; +} + +struct stat FuseLstatTest::CallFileLstatWithImpl(function implementation) { + return CallLstatWithModeAndImpl(S_IFREG, implementation); +} + +struct stat FuseLstatTest::CallDirLstatWithImpl(function implementation) { + return CallLstatWithModeAndImpl(S_IFDIR, implementation); +} + +struct stat FuseLstatTest::CallLstatWithImpl(function implementation) { + EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).WillRepeatedly(Invoke([implementation](const char*, struct ::stat *stat) { + implementation(stat); + })); + + struct stat result; + LstatPath(FILENAME, &result); + + return result; +} + +struct stat FuseLstatTest::CallLstatWithModeAndImpl(mode_t mode, function implementation) { + return CallLstatWithImpl([mode, implementation] (struct stat *stat) { + stat->st_mode = mode; + implementation(stat); + }); +} diff --git a/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.h b/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.h new file mode 100644 index 00000000..729597a6 --- /dev/null +++ b/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.h @@ -0,0 +1,30 @@ +#pragma once +#ifndef TEST_FSPP_FUSE_LSTAT_FUSELSTATTEST_H_ +#define TEST_FSPP_FUSE_LSTAT_FUSELSTATTEST_H_ + +#include "gmock/gmock.h" + +#include +#include +#include + +#include "test/testutils/FuseTest.h" + +class FuseLstatTest: public FuseTest { +public: + const char *FILENAME = "/myfile"; + + void LstatPath(const std::string &path); + void LstatPath(const std::string &path, struct stat *result); + +protected: + struct stat CallFileLstatWithImpl(std::function implementation); + struct stat CallDirLstatWithImpl(std::function implementation); + struct stat CallLstatWithImpl(std::function implementation); + +private: + + struct stat CallLstatWithModeAndImpl(mode_t mode, std::function implementation); +}; + +#endif