Test cases for new utimens interface

This commit is contained in:
Sebastian Messmer 2016-02-09 09:36:07 +01:00
parent a583ff6970
commit 9fcc54d8b1
7 changed files with 29 additions and 30 deletions

View File

@ -15,9 +15,9 @@ INSTANTIATE_TEST_CASE_P(FuseUtimensErrorTest, FuseUtimensErrorTest, Values(EACCE
TEST_P(FuseUtimensErrorTest, ReturnedErrorIsCorrect) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, utimens(StrEq(FILENAME), _))
EXPECT_CALL(fsimpl, utimens(StrEq(FILENAME), _, _))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = UtimensReturnError(FILENAME, TIMEVALUES);
int error = UtimensReturnError(FILENAME, TIMEVALUE, TIMEVALUE);
EXPECT_EQ(GetParam(), error);
}

View File

@ -9,54 +9,54 @@ class FuseUtimensFilenameTest: public FuseUtimensTest {
TEST_F(FuseUtimensFilenameTest, UtimensFile) {
ReturnIsFileOnLstat("/myfile");
EXPECT_CALL(fsimpl, utimens(StrEq("/myfile"), _))
EXPECT_CALL(fsimpl, utimens(StrEq("/myfile"), _, _))
.Times(1).WillOnce(Return());
Utimens("/myfile", TIMEVALUES);
Utimens("/myfile", TIMEVALUE, TIMEVALUE);
}
TEST_F(FuseUtimensFilenameTest, UtimensFileNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsFileOnLstat("/mydir/myfile");
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/myfile"), _))
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/myfile"), _, _))
.Times(1).WillOnce(Return());
Utimens("/mydir/myfile", TIMEVALUES);
Utimens("/mydir/myfile", TIMEVALUE, TIMEVALUE);
}
TEST_F(FuseUtimensFilenameTest, UtimensFileNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsFileOnLstat("/mydir/mydir2/myfile");
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/mydir2/myfile"), _))
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/mydir2/myfile"), _, _))
.Times(1).WillOnce(Return());
Utimens("/mydir/mydir2/myfile", TIMEVALUES);
Utimens("/mydir/mydir2/myfile", TIMEVALUE, TIMEVALUE);
}
TEST_F(FuseUtimensFilenameTest, UtimensDir) {
ReturnIsDirOnLstat("/mydir");
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir"), _))
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir"), _, _))
.Times(1).WillOnce(Return());
Utimens("/mydir", TIMEVALUES);
Utimens("/mydir", TIMEVALUE, TIMEVALUE);
}
TEST_F(FuseUtimensFilenameTest, UtimensDirNested) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/mydir2"), _))
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/mydir2"), _, _))
.Times(1).WillOnce(Return());
Utimens("/mydir/mydir2", TIMEVALUES);
Utimens("/mydir/mydir2", TIMEVALUE, TIMEVALUE);
}
TEST_F(FuseUtimensFilenameTest, UtimensDirNested2) {
ReturnIsDirOnLstat("/mydir");
ReturnIsDirOnLstat("/mydir/mydir2");
ReturnIsDirOnLstat("/mydir/mydir2/mydir3");
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/mydir2/mydir3"), _))
EXPECT_CALL(fsimpl, utimens(StrEq("/mydir/mydir2/mydir3"), _, _))
.Times(1).WillOnce(Return());
Utimens("/mydir/mydir2/mydir3", TIMEVALUES);
Utimens("/mydir/mydir2/mydir3", TIMEVALUE, TIMEVALUE);
}

View File

@ -24,8 +24,8 @@ INSTANTIATE_TEST_CASE_P(FuseUtimensTimeParameterTest, FuseUtimensTimeParameterTe
TEST_P(FuseUtimensTimeParameterTest, Utimens) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, utimens(StrEq(FILENAME), TimeSpecEq(GetParam())))
EXPECT_CALL(fsimpl, utimens(StrEq(FILENAME), TimeSpecEq(GetParam()[0]), TimeSpecEq(GetParam()[1])))
.Times(1).WillOnce(Return());
Utimens(FILENAME, GetParam());
Utimens(FILENAME, GetParam()[0], GetParam()[1]);
}

View File

@ -3,19 +3,19 @@
#include <utime.h>
#include <sys/time.h>
void FuseUtimensTest::Utimens(const char *filename, const timespec times[2]) {
int error = UtimensReturnError(filename, times);
void FuseUtimensTest::Utimens(const char *filename, timespec lastAccessTime, timespec lastModificationTime) {
int error = UtimensReturnError(filename, lastAccessTime, lastModificationTime);
EXPECT_EQ(0, error);
}
int FuseUtimensTest::UtimensReturnError(const char *filename, const timespec times[2]) {
int FuseUtimensTest::UtimensReturnError(const char *filename, timespec lastAccessTime, timespec lastModificationTime) {
auto fs = TestFS();
auto realpath = fs->mountDir() / filename;
struct timeval casted_times[2];
TIMESPEC_TO_TIMEVAL(&casted_times[0], &times[0]);
TIMESPEC_TO_TIMEVAL(&casted_times[1], &times[1]);
TIMESPEC_TO_TIMEVAL(&casted_times[0], &lastAccessTime);
TIMESPEC_TO_TIMEVAL(&casted_times[1], &lastModificationTime);
int retval = ::utimes(realpath.c_str(), casted_times);
if (0 == retval) {
return 0;

View File

@ -7,17 +7,16 @@
class FuseUtimensTest: public FuseTest {
public:
const char *FILENAME = "/myfile";
struct timespec TIMEVALUES[2] = {makeTimespec(0,0), makeTimespec(0,0)};
timespec TIMEVALUE = makeTimespec(0,0);
void Utimens(const char *filename, const timespec times[2]);
int UtimensReturnError(const char *filename, const timespec times[2]);
void Utimens(const char *filename, timespec lastAccessTime, timespec lastModificationTime);
int UtimensReturnError(const char *filename, timespec lastAccessTime, timespec lastModificationTime);
static struct timespec makeTimespec(time_t tv_sec, long tv_nsec);
};
MATCHER_P(TimeSpecEq, expected, "") {
return expected[0].tv_sec == arg[0].tv_sec && expected[0].tv_nsec == arg[0].tv_nsec &&
expected[1].tv_sec == arg[1].tv_sec && expected[1].tv_nsec == arg[1].tv_nsec;
return expected.tv_sec == arg.tv_sec && expected.tv_nsec == arg.tv_nsec;
}
#endif

View File

@ -36,7 +36,7 @@ FuseTest::FuseTest(): fsimpl() {
ON_CALL(fsimpl, unlink(_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, rename(_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, readDir(_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, utimens(_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, utimens(_,_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, statfs(_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, chmod(_,_)).WillByDefault(defaultAction);
ON_CALL(fsimpl, chown(_,_,_)).WillByDefault(defaultAction);

View File

@ -68,10 +68,10 @@ public:
return cpputils::nullcheck(std::unique_ptr<std::vector<fspp::Dir::Entry>>(readDir(path.c_str()))).value();
}
MOCK_METHOD1(readDir, std::vector<fspp::Dir::Entry>*(const char*));
void utimens(const boost::filesystem::path &path, const timespec ts[2]) override {
return utimens(path.c_str(), ts);
void utimens(const boost::filesystem::path &path, timespec lastAccessTime, timespec lastModificationTime) override {
return utimens(path.c_str(), lastAccessTime, lastModificationTime);
}
MOCK_METHOD2(utimens, void(const char*,const timespec[2]));
MOCK_METHOD3(utimens, void(const char*, timespec, timespec));
MOCK_PATH_METHOD2(statfs, void, struct statvfs*);
void createSymlink(const boost::filesystem::path &to, const boost::filesystem::path &from, uid_t uid, gid_t gid) override {
return createSymlink(to.c_str(), from.c_str(), uid, gid);