From c61e27b24e7a2bfd5a1fbae6afba7d7b5c1fcad3 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Thu, 20 Nov 2014 15:15:24 +0100 Subject: [PATCH] Separate lstat tests into separate classes --- src/test/fspp/fuse/FuseLstatTest.cpp | 244 ++++++++++++++------------- 1 file changed, 123 insertions(+), 121 deletions(-) diff --git a/src/test/fspp/fuse/FuseLstatTest.cpp b/src/test/fspp/fuse/FuseLstatTest.cpp index 8da30e86..7914e35a 100644 --- a/src/test/fspp/fuse/FuseLstatTest.cpp +++ b/src/test/fspp/fuse/FuseLstatTest.cpp @@ -20,17 +20,6 @@ using std::function; class FuseLstatTest: public FuseTest { public: const char *FILENAME = "/myfile"; - const mode_t MODE_FILE = S_IFREG | S_IRUSR | S_IWGRP | S_IXOTH; - const mode_t MODE_DIR = S_IFDIR | S_IWUSR | S_IXGRP | S_IROTH; - const uid_t UID1 = 0; - const uid_t UID2 = 10; - const gid_t GID1 = 0; - const gid_t GID2 = 10; - const off_t SIZE1 = 0; - const off_t SIZE2 = 4096; - const off_t SIZE3 = 1024*1024*1024; - const nlink_t NLINK1 = 1; - const nlink_t NLINK2 = 5; void LstatPath(const string &path) { struct stat dummy; @@ -45,67 +34,7 @@ public: EXPECT_EQ(0, retval) << "lstat syscall failed. errno: " << errno; } - struct stat CallLstatWithMode(mode_t mode) { - return CallLstatWithModeAndImpl(mode, [](struct stat*){}); - } - - struct stat CallFileLstatWithUid(uid_t uid) { - return CallFileLstatWithImpl(LstatUidImpl(uid)); - } - - struct stat CallDirLstatWithUid(uid_t uid) { - return CallDirLstatWithImpl(LstatUidImpl(uid)); - } - - struct stat CallFileLstatWithGid(gid_t gid) { - return CallFileLstatWithImpl(LstatGidImpl(gid)); - } - - struct stat CallDirLstatWithGid(gid_t gid) { - return CallDirLstatWithImpl(LstatGidImpl(gid)); - } - - struct stat CallFileLstatWithSize(off_t size) { - return CallFileLstatWithImpl(LstatSizeImpl(size)); - } - - struct stat CallDirLstatWithSize(off_t size) { - return CallDirLstatWithImpl(LstatSizeImpl(size)); - } - - struct stat CallFileLstatWithNlink(nlink_t nlink) { - return CallFileLstatWithImpl(LstatNlinkImpl(nlink)); - } - - struct stat CallDirLstatWithNlink(nlink_t nlink) { - return CallDirLstatWithImpl(LstatNlinkImpl(nlink)); - } -private: - - static function LstatUidImpl(uid_t uid) { - return [uid] (struct stat *stat) { - stat->st_uid = uid; - }; - } - - static function LstatGidImpl(gid_t gid) { - return [gid] (struct stat *stat) { - stat->st_gid = gid; - }; - } - - static function LstatSizeImpl(off_t size) { - return [size] (struct stat *stat) { - stat->st_size = size; - }; - } - - static function LstatNlinkImpl(nlink_t nlink) { - return [nlink] (struct stat *stat) { - stat->st_nlink = nlink; - }; - } - +protected: struct stat CallFileLstatWithImpl(function implementation) { return CallLstatWithModeAndImpl(S_IFREG, implementation); } @@ -114,13 +43,6 @@ private: return CallLstatWithModeAndImpl(S_IFDIR, implementation); } - struct stat CallLstatWithModeAndImpl(mode_t mode, function implementation) { - return CallLstatWithImpl([mode, implementation] (struct stat *stat) { - stat->st_mode = mode; - implementation(stat); - }); - } - struct stat CallLstatWithImpl(function implementation) { EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).WillRepeatedly(Invoke([implementation](const char*, struct ::stat *stat) { implementation(stat); @@ -131,6 +53,86 @@ private: return result; } + +private: + + struct stat CallLstatWithModeAndImpl(mode_t mode, function implementation) { + return CallLstatWithImpl([mode, implementation] (struct stat *stat) { + stat->st_mode = mode; + implementation(stat); + }); + } +}; + +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: + function SetPropertyImpl(Property value) { + return [this, value] (struct stat *stat) { + set(stat, value); + }; + } + virtual void set(struct stat *stat, Property value) = 0; +}; + +class FuseLstatReturnPropertyModeTest: 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; + + struct stat CallLstatWithValue(mode_t mode) { + return CallLstatWithImpl([mode] (struct stat *stat) { + stat->st_mode = mode; + }); + } +}; + +class FuseLstatReturnPropertyUidTest: public FuseLstatReturnPropertyTest { +public: + const uid_t UID1 = 0; + const uid_t UID2 = 10; +private: + void set(struct stat *stat, uid_t value) override { + stat->st_uid = value; + } +}; + +class FuseLstatReturnPropertyGidTest: public FuseLstatReturnPropertyTest { +public: + const gid_t GID1 = 0; + const gid_t GID2 = 10; +private: + void set(struct stat *stat, gid_t value) override { + stat->st_gid = value; + } +}; + +class FuseLstatReturnPropertySizeTest: public FuseLstatReturnPropertyTest { +public: + const off_t SIZE1 = 0; + const off_t SIZE2 = 4096; + const off_t SIZE3 = 1024*1024*1024; +private: + void set(struct stat *stat, off_t value) override { + stat->st_size = value; + } +}; + +class FuseLstatReturnPropertyNlinkTest: public FuseLstatReturnPropertyTest { +public: + const nlink_t NLINK1 = 1; + const nlink_t NLINK2 = 5; +private: + void set(struct stat *stat, nlink_t value) override { + stat->st_nlink = value; + } }; @@ -163,103 +165,103 @@ TEST_F(FuseLstatTest, PathParameterIsCorrectNestedDir) { LstatPath("/mydir/mydir2/mydir3/"); } -TEST_F(FuseLstatTest, ReturnedFileModeIsCorrect) { - struct ::stat result = CallLstatWithMode(MODE_FILE); - EXPECT_EQ(MODE_FILE, result.st_mode); +TEST_F(FuseLstatReturnPropertyModeTest, ReturnedModeIsCorrect1) { + struct ::stat result = CallLstatWithValue(MODE1); + EXPECT_EQ(MODE1, result.st_mode); } -TEST_F(FuseLstatTest, ReturnedDirModeIsCorrect) { - struct ::stat result = CallLstatWithMode(MODE_DIR); - EXPECT_EQ(MODE_DIR, result.st_mode); +TEST_F(FuseLstatReturnPropertyModeTest, ReturnedModeIsCorrect2) { + struct ::stat result = CallLstatWithValue(MODE2); + EXPECT_EQ(MODE2, result.st_mode); } -TEST_F(FuseLstatTest, ReturnedFileUidIsCorrect1) { - struct ::stat result = CallFileLstatWithUid(UID1); +TEST_F(FuseLstatReturnPropertyUidTest, ReturnedFileUidIsCorrect1) { + struct ::stat result = CallFileLstatWithValue(UID1); EXPECT_EQ(UID1, result.st_uid); } -TEST_F(FuseLstatTest, ReturnedFileUidIsCorrect2) { - struct ::stat result = CallFileLstatWithUid(UID2); +TEST_F(FuseLstatReturnPropertyUidTest, ReturnedFileUidIsCorrect2) { + struct ::stat result = CallFileLstatWithValue(UID2); EXPECT_EQ(UID2, result.st_uid); } -TEST_F(FuseLstatTest, ReturnedDirUidIsCorrect1) { - struct ::stat result = CallDirLstatWithUid(UID1); +TEST_F(FuseLstatReturnPropertyUidTest, ReturnedDirUidIsCorrect1) { + struct ::stat result = CallDirLstatWithValue(UID1); EXPECT_EQ(UID1, result.st_uid); } -TEST_F(FuseLstatTest, ReturnedDirUidIsCorrect2) { - struct ::stat result = CallDirLstatWithUid(UID2); +TEST_F(FuseLstatReturnPropertyUidTest, ReturnedDirUidIsCorrect2) { + struct ::stat result = CallDirLstatWithValue(UID2); EXPECT_EQ(UID2, result.st_uid); } -TEST_F(FuseLstatTest, ReturnedFileGidIsCorrect1) { - struct ::stat result = CallFileLstatWithUid(GID1); +TEST_F(FuseLstatReturnPropertyGidTest, ReturnedFileGidIsCorrect1) { + struct ::stat result = CallFileLstatWithValue(GID1); EXPECT_EQ(GID1, result.st_gid); } -TEST_F(FuseLstatTest, ReturnedFileGidIsCorrect2) { - struct ::stat result = CallFileLstatWithGid(GID2); +TEST_F(FuseLstatReturnPropertyGidTest, ReturnedFileGidIsCorrect2) { + struct ::stat result = CallFileLstatWithValue(GID2); EXPECT_EQ(GID2, result.st_gid); } -TEST_F(FuseLstatTest, ReturnedDirGidIsCorrect1) { - struct ::stat result = CallDirLstatWithGid(GID1); +TEST_F(FuseLstatReturnPropertyGidTest, ReturnedDirGidIsCorrect1) { + struct ::stat result = CallDirLstatWithValue(GID1); EXPECT_EQ(GID1, result.st_gid); } -TEST_F(FuseLstatTest, ReturnedDirGidIsCorrect2) { - struct ::stat result = CallDirLstatWithGid(GID2); +TEST_F(FuseLstatReturnPropertyGidTest, ReturnedDirGidIsCorrect2) { + struct ::stat result = CallDirLstatWithValue(GID2); EXPECT_EQ(GID2, result.st_gid); } -TEST_F(FuseLstatTest, ReturnedFileSizeIsCorrect1) { - struct ::stat result = CallFileLstatWithSize(SIZE1); +TEST_F(FuseLstatReturnPropertySizeTest, ReturnedFileSizeIsCorrect1) { + struct ::stat result = CallDirLstatWithValue(SIZE1); EXPECT_EQ(SIZE1, result.st_size); } -TEST_F(FuseLstatTest, ReturnedFileSizeIsCorrect2) { - struct ::stat result = CallFileLstatWithSize(SIZE2); +TEST_F(FuseLstatReturnPropertySizeTest, ReturnedFileSizeIsCorrect2) { + struct ::stat result = CallDirLstatWithValue(SIZE2); EXPECT_EQ(SIZE2, result.st_size); } -TEST_F(FuseLstatTest, ReturnedFileSizeIsCorrect3) { - struct ::stat result = CallFileLstatWithSize(SIZE3); +TEST_F(FuseLstatReturnPropertySizeTest, ReturnedFileSizeIsCorrect3) { + struct ::stat result = CallDirLstatWithValue(SIZE3); EXPECT_EQ(SIZE3, result.st_size); } -TEST_F(FuseLstatTest, ReturnedDirSizeIsCorrect1) { - struct ::stat result = CallDirLstatWithSize(SIZE1); +TEST_F(FuseLstatReturnPropertySizeTest, ReturnedDirSizeIsCorrect1) { + struct ::stat result = CallDirLstatWithValue(SIZE1); EXPECT_EQ(SIZE1, result.st_size); } -TEST_F(FuseLstatTest, ReturnedDirSizeIsCorrect2) { - struct ::stat result = CallDirLstatWithSize(SIZE2); +TEST_F(FuseLstatReturnPropertySizeTest, ReturnedDirSizeIsCorrect2) { + struct ::stat result = CallDirLstatWithValue(SIZE2); EXPECT_EQ(SIZE2, result.st_size); } -TEST_F(FuseLstatTest, ReturnedDirSizeIsCorrect3) { - struct ::stat result = CallDirLstatWithSize(SIZE3); +TEST_F(FuseLstatReturnPropertySizeTest, ReturnedDirSizeIsCorrect3) { + struct ::stat result = CallDirLstatWithValue(SIZE3); EXPECT_EQ(SIZE3, result.st_size); } -TEST_F(FuseLstatTest, ReturnedFileNlinkIsCorrect1) { - struct ::stat result = CallFileLstatWithNlink(NLINK1); +TEST_F(FuseLstatReturnPropertyNlinkTest, ReturnedFileNlinkIsCorrect1) { + struct ::stat result = CallDirLstatWithValue(NLINK1); EXPECT_EQ(NLINK1, result.st_nlink); } -TEST_F(FuseLstatTest, ReturnedFileNlinkIsCorrect2) { - struct ::stat result = CallFileLstatWithNlink(NLINK2); +TEST_F(FuseLstatReturnPropertyNlinkTest, ReturnedFileNlinkIsCorrect2) { + struct ::stat result = CallDirLstatWithValue(NLINK2); EXPECT_EQ(NLINK2, result.st_nlink); } -TEST_F(FuseLstatTest, ReturnedDirNlinkIsCorrect1) { - struct ::stat result = CallDirLstatWithNlink(NLINK1); +TEST_F(FuseLstatReturnPropertyNlinkTest, ReturnedDirNlinkIsCorrect1) { + struct ::stat result = CallDirLstatWithValue(NLINK1); EXPECT_EQ(NLINK1, result.st_nlink); } -TEST_F(FuseLstatTest, ReturnedDirNlinkIsCorrect2) { - struct ::stat result = CallDirLstatWithNlink(NLINK2); +TEST_F(FuseLstatReturnPropertyNlinkTest, ReturnedDirNlinkIsCorrect2) { + struct ::stat result = CallDirLstatWithValue(NLINK2); EXPECT_EQ(NLINK2, result.st_nlink); }