From e7181c3c8b7680b58ae1020b3c1d243ef28fdb6f Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Thu, 20 Nov 2014 20:04:39 +0100 Subject: [PATCH] Comments --- .../fuse/{FuseTest.cpp => BasicFuseTest.cpp} | 2 +- .../fspp/fuse/lstat/FuseLstatErrorTest.cpp | 2 ++ .../lstat/testutils/FuseLstatReturnTest.h | 6 ++++++ .../fspp/fuse/lstat/testutils/FuseLstatTest.h | 19 ++++++++++++++++--- 4 files changed, 25 insertions(+), 4 deletions(-) rename src/test/fspp/fuse/{FuseTest.cpp => BasicFuseTest.cpp} (74%) diff --git a/src/test/fspp/fuse/FuseTest.cpp b/src/test/fspp/fuse/BasicFuseTest.cpp similarity index 74% rename from src/test/fspp/fuse/FuseTest.cpp rename to src/test/fspp/fuse/BasicFuseTest.cpp index a5550bed..2615a6c4 100644 --- a/src/test/fspp/fuse/FuseTest.cpp +++ b/src/test/fspp/fuse/BasicFuseTest.cpp @@ -11,7 +11,7 @@ using ::testing::StrEq; typedef FuseTest BasicFuseTest; +//This test case simply checks whether a filesystem can be setup and teardown without crashing. TEST_F(BasicFuseTest, setupAndTearDown) { - //This test case simply checks whether a filesystem can be setup and teardown without crashing. auto fs = TestFS(); } diff --git a/src/test/fspp/fuse/lstat/FuseLstatErrorTest.cpp b/src/test/fspp/fuse/lstat/FuseLstatErrorTest.cpp index da7a9294..f87ca39e 100644 --- a/src/test/fspp/fuse/lstat/FuseLstatErrorTest.cpp +++ b/src/test/fspp/fuse/lstat/FuseLstatErrorTest.cpp @@ -17,7 +17,9 @@ INSTANTIATE_TEST_CASE_P(LstatErrorCodes, FuseLstatErrorTest, Values(EACCES, EBAD TEST_F(FuseLstatErrorTest, ReturnNoError) { EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).Times(1).WillOnce(ReturnIsFile); + errno = 0; int retval = LstatPathAllowErrors(FILENAME); + EXPECT_EQ(errno, 0); EXPECT_EQ(retval, 0); } diff --git a/src/test/fspp/fuse/lstat/testutils/FuseLstatReturnTest.h b/src/test/fspp/fuse/lstat/testutils/FuseLstatReturnTest.h index 8dae044c..7f62c285 100644 --- a/src/test/fspp/fuse/lstat/testutils/FuseLstatReturnTest.h +++ b/src/test/fspp/fuse/lstat/testutils/FuseLstatReturnTest.h @@ -4,15 +4,21 @@ #include "FuseLstatTest.h" +// This class offers test helpers for testing (struct stat) entries. We return them from +// our mock filesystem, set up a temporary filesystem, call lstat syscall on it, and +// then check the return value. template class FuseLstatReturnTest: public FuseLstatTest { public: + // Set the specified (struct stat) entry to the given value, and test whether it is correctly returned from the syscall. + // The CallFile[...] version tests it on a file node of the filesystem, the CallDir[...] version on a dir node. struct stat CallFileLstatWithValue(Property value); struct stat CallDirLstatWithValue(Property value); private: std::function SetPropertyImpl(Property value); + // Override this function to specify, how to set the specified (struct stat) entry on the passed (struct stat *) object. virtual void set(struct stat *stat, Property value) = 0; }; diff --git a/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.h b/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.h index 5ad68549..961d56fb 100644 --- a/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.h +++ b/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.h @@ -10,19 +10,32 @@ #include "test/testutils/FuseTest.h" +// This class offers some utility functions for testing lstat(). class FuseLstatTest: public FuseTest { -public: +protected: const char *FILENAME = "/myfile"; + // Set up a temporary filesystem (using the fsimpl mock in FuseTest as filesystem implementation) + // and call the lstat syscall on the given (filesystem-relative) path. void LstatPath(const std::string &path); + // Same as LstatPath above, but also return the result of the lstat syscall. void LstatPath(const std::string &path, struct stat *result); + + // These two functions are the same as LstatPath above, but they don't fail the test when the lstat syscall + // crashes. Instead, they return the result value of the lstat syscall. int LstatPathAllowErrors(const std::string &path); int LstatPathAllowErrors(const std::string &path, struct stat *result); -protected: + // You can specify an implementation, which can modify the (struct stat *) result, + // our fuse mock filesystem implementation will then return this to fuse on an lstat call. + // This functions then set up a temporary filesystem with this mock, call lstat on a filesystem node + // and return the (struct stat) returned from an lstat syscall to this filesystem. + struct stat CallLstatWithImpl(std::function implementation); + + // These two functions are like CallLstatWithImpl, but they also modify the (struct stat).st_mode + // field, so the node accessed is specified to be a file/directory. struct stat CallFileLstatWithImpl(std::function implementation); struct stat CallDirLstatWithImpl(std::function implementation); - struct stat CallLstatWithImpl(std::function implementation); private: