From bbdfc5c2340a7454b13bc7f417d5a1cadb752fe7 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sun, 22 Jan 2017 01:11:26 +0000 Subject: [PATCH] Simplify FsppNodeTest --- src/fspp/fstest/FsppNodeTest_Stat.h | 6 +- src/fspp/fstest/testutils/FsppNodeTest.h | 76 ++++++------------------ 2 files changed, 22 insertions(+), 60 deletions(-) diff --git a/src/fspp/fstest/FsppNodeTest_Stat.h b/src/fspp/fstest/FsppNodeTest_Stat.h index be0df419..d531d07c 100644 --- a/src/fspp/fstest/FsppNodeTest_Stat.h +++ b/src/fspp/fstest/FsppNodeTest_Stat.h @@ -19,7 +19,7 @@ public: // Test cases only run for file nodes template -class FsppNodeTest_Stat_FileOnly: public FileSystemTest, public FsppNodeTest_File_Helper {}; +class FsppNodeTest_Stat_FileOnly: public FileSystemTest, public FsppNodeTestHelper {}; TYPED_TEST_CASE_P(FsppNodeTest_Stat_FileOnly); @@ -39,7 +39,7 @@ TYPED_TEST_P(FsppNodeTest_Stat_FileOnly, FileIsFile) { // Test cases only run for dir nodes template -class FsppNodeTest_Stat_DirOnly: public FileSystemTest, public FsppNodeTest_Dir_Helper {}; +class FsppNodeTest_Stat_DirOnly: public FileSystemTest, public FsppNodeTestHelper {}; TYPED_TEST_CASE_P(FsppNodeTest_Stat_DirOnly); @@ -53,7 +53,7 @@ TYPED_TEST_P(FsppNodeTest_Stat_DirOnly, DirIsDir) { // Test cases only run for symlink nodes template -class FsppNodeTest_Stat_SymlinkOnly: public FileSystemTest, public FsppNodeTest_Symlink_Helper {}; +class FsppNodeTest_Stat_SymlinkOnly: public FileSystemTest, public FsppNodeTestHelper {}; TYPED_TEST_CASE_P(FsppNodeTest_Stat_SymlinkOnly); diff --git a/src/fspp/fstest/testutils/FsppNodeTest.h b/src/fspp/fstest/testutils/FsppNodeTest.h index c3375678..e9fa23c8 100644 --- a/src/fspp/fstest/testutils/FsppNodeTest.h +++ b/src/fspp/fstest/testutils/FsppNodeTest.h @@ -7,12 +7,19 @@ #include #include -// TODO separation into File/Dir/Symlink Helpers probably not needed anymore - -class FsppNodeTestBase { +class FsppNodeTestHelper { public: - virtual void IN_STAT(fspp::Node *node, std::function callback) = 0; - virtual void EXPECT_SIZE(uint64_t expectedSize, fspp::Node *node) = 0; + void IN_STAT(fspp::Node *file, std::function callback) { + struct stat st; + file->stat(&st); + callback(st); + } + + void EXPECT_SIZE(uint64_t expectedSize, fspp::Node *node) { + IN_STAT(node, [expectedSize] (struct stat st) { + EXPECT_EQ(expectedSize, (uint64_t)st.st_size); + }); + } }; /** @@ -24,56 +31,11 @@ public: * See FsppNodeTest_Rename for an example. */ template -class FsppNodeTest: public virtual FsppNodeTestBase, public virtual FileSystemTest { +class FsppNodeTest: public virtual FsppNodeTestHelper, public virtual FileSystemTest { public: virtual cpputils::unique_ref CreateNode(const boost::filesystem::path &path) = 0; }; -class FsppNodeTest_File_Helper: public virtual FsppNodeTestBase { -public: - void IN_STAT(fspp::Node *file, std::function callback) override { - struct stat st; - file->stat(&st); - callback(st); - } - - void EXPECT_SIZE(uint64_t expectedSize, fspp::Node *node) override { - IN_STAT(node, [expectedSize] (struct stat st) { - EXPECT_EQ(expectedSize, (uint64_t)st.st_size); - }); - } -}; - -class FsppNodeTest_Dir_Helper: public virtual FsppNodeTestBase { -public: - void IN_STAT(fspp::Node *file, std::function callback) override { - struct stat st; - file->stat(&st); - callback(st); - } - - void EXPECT_SIZE(uint64_t expectedSize, fspp::Node *node) override { - IN_STAT(node, [expectedSize] (struct stat st) { - EXPECT_EQ(expectedSize, (uint64_t)st.st_size); - }); - } -}; - -class FsppNodeTest_Symlink_Helper: public virtual FsppNodeTestBase { -public: - void IN_STAT(fspp::Node *file, std::function callback) override { - struct stat st; - file->stat(&st); - callback(st); - } - - void EXPECT_SIZE(uint64_t expectedSize, fspp::Node *node) override { - IN_STAT(node, [expectedSize] (struct stat st) { - EXPECT_EQ(expectedSize, (uint64_t)st.st_size); - }); - } -}; - #define _REGISTER_SINGLE_NODE_TEST_CASE(r, Class, Name) \ TYPED_TEST_P(Class, Name) { \ this->BOOST_PP_CAT(Test_,Name)(); \ @@ -85,11 +47,11 @@ public: #define _REGISTER_FILE_TEST_CASE(Class, ...) \ template \ - class Class##_FileNode: public Class, public FsppNodeTest_File_Helper { \ + class Class##_FileNode: public Class, public virtual FsppNodeTestHelper { \ public: \ cpputils::unique_ref CreateNode(const boost::filesystem::path &path) override { \ this->CreateFile(path); \ - return this->Load(path); \ + return this->Load(path); \ } \ }; \ TYPED_TEST_CASE_P(Class##_FileNode); \ @@ -97,11 +59,11 @@ public: #define _REGISTER_DIR_TEST_CASE(Class, ...) \ template \ - class Class##_DirNode: public Class, public FsppNodeTest_Dir_Helper { \ + class Class##_DirNode: public Class, public virtual FsppNodeTestHelper { \ public: \ cpputils::unique_ref CreateNode(const boost::filesystem::path &path) override { \ this->CreateDir(path); \ - return this->Load(path); \ + return this->Load(path); \ } \ }; \ TYPED_TEST_CASE_P(Class##_DirNode); \ @@ -109,11 +71,11 @@ public: #define _REGISTER_SYMLINK_TEST_CASE(Class, ...) \ template \ - class Class##_SymlinkNode: public Class, public FsppNodeTest_Symlink_Helper { \ + class Class##_SymlinkNode: public Class, public virtual FsppNodeTestHelper { \ public: \ cpputils::unique_ref CreateNode(const boost::filesystem::path &path) override { \ this->CreateSymlink(path); \ - return this->Load(path); \ + return this->Load(path); \ } \ }; \ TYPED_TEST_CASE_P(Class##_SymlinkNode); \