Added testcases for unlink()
This commit is contained in:
parent
6b4497bab2
commit
0f2f6fb9bc
@ -28,8 +28,8 @@ public:
|
||||
virtual void access(const boost::filesystem::path &path, int mask) = 0;
|
||||
virtual void mkdir(const boost::filesystem::path &path, mode_t mode) = 0;
|
||||
virtual void rmdir(const boost::filesystem::path &path) = 0;
|
||||
//TODO Unit-Tests for all functions below
|
||||
virtual void unlink(const boost::filesystem::path &path) = 0;
|
||||
//TODO Unit-Tests for all functions below
|
||||
virtual void rename(const boost::filesystem::path &from, const boost::filesystem::path &to) = 0;
|
||||
virtual std::unique_ptr<std::vector<std::string>> readDir(const boost::filesystem::path &path) = 0;
|
||||
virtual void utimens(const boost::filesystem::path &path, const timespec times[2]) = 0;
|
||||
|
27
src/test/fspp/fuse/unlink/FuseUnlinkErrorTest.cpp
Normal file
27
src/test/fspp/fuse/unlink/FuseUnlinkErrorTest.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "testutils/FuseUnlinkTest.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "fspp/fuse/FuseErrnoException.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::StrEq;
|
||||
using ::testing::Throw;
|
||||
using ::testing::WithParamInterface;
|
||||
using ::testing::Values;
|
||||
|
||||
using namespace fspp::fuse;
|
||||
|
||||
class FuseUnlinkErrorTest: public FuseUnlinkTest, public WithParamInterface<int> {
|
||||
};
|
||||
INSTANTIATE_TEST_CASE_P(FuseUnlinkErrorTest, FuseUnlinkErrorTest, Values(EACCES, EBUSY, EFAULT, EIO, EISDIR, ELOOP, ENAMETOOLONG, ENOENT, ENOMEM, ENOTDIR, EPERM, EROFS, EINVAL));
|
||||
|
||||
TEST_P(FuseUnlinkErrorTest, ReturnedErrorIsCorrect) {
|
||||
ReturnIsFileOnLstat(FILENAME);
|
||||
EXPECT_CALL(fsimpl, unlink(StrEq(FILENAME)))
|
||||
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
|
||||
|
||||
int retval = UnlinkAllowError(FILENAME);
|
||||
EXPECT_EQ(GetParam(), errno);
|
||||
EXPECT_EQ(-1, retval);
|
||||
}
|
46
src/test/fspp/fuse/unlink/FuseUnlinkFilenameTest.cpp
Normal file
46
src/test/fspp/fuse/unlink/FuseUnlinkFilenameTest.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "testutils/FuseUnlinkTest.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::StrEq;
|
||||
using ::testing::Return;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::Action;
|
||||
|
||||
class FuseUnlinkFilenameTest: public FuseUnlinkTest {
|
||||
};
|
||||
|
||||
TEST_F(FuseUnlinkFilenameTest, Unlink) {
|
||||
ReturnIsFileOnLstat("/mydir");
|
||||
EXPECT_CALL(fsimpl, unlink(StrEq("/mydir")))
|
||||
// After rmdir was called, lstat should return that it doesn't exist anymore
|
||||
// This is needed to make the ::rmdir() syscall pass.
|
||||
.Times(1).WillOnce(FromNowOnReturnDoesntExistOnLstat());
|
||||
|
||||
Unlink("/mydir");
|
||||
}
|
||||
|
||||
TEST_F(FuseUnlinkFilenameTest, UnlinkNested) {
|
||||
ReturnIsDirOnLstat("/mydir");
|
||||
ReturnIsFileOnLstat("/mydir/mysubdir");
|
||||
EXPECT_CALL(fsimpl, unlink(StrEq("/mydir/mysubdir")))
|
||||
// After rmdir was called, lstat should return that it doesn't exist anymore
|
||||
// This is needed to make the ::rmdir() syscall pass.
|
||||
.Times(1).WillOnce(FromNowOnReturnDoesntExistOnLstat());
|
||||
|
||||
Unlink("/mydir/mysubdir");
|
||||
}
|
||||
|
||||
TEST_F(FuseUnlinkFilenameTest, UnlinkNested2) {
|
||||
ReturnIsDirOnLstat("/mydir");
|
||||
ReturnIsDirOnLstat("/mydir/mydir2");
|
||||
ReturnIsFileOnLstat("/mydir/mydir2/mydir3");
|
||||
EXPECT_CALL(fsimpl, unlink(StrEq("/mydir/mydir2/mydir3")))
|
||||
// After rmdir was called, lstat should return that it doesn't exist anymore
|
||||
// This is needed to make the ::rmdir() syscall pass.
|
||||
.Times(1).WillOnce(FromNowOnReturnDoesntExistOnLstat());
|
||||
|
||||
Unlink("/mydir/mydir2/mydir3");
|
||||
}
|
22
src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.cpp
Normal file
22
src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <test/fspp/fuse/unlink/testutils/FuseUnlinkTest.h>
|
||||
|
||||
using ::testing::Action;
|
||||
using ::testing::Invoke;
|
||||
|
||||
void FuseUnlinkTest::Unlink(const char *filename) {
|
||||
int retval = UnlinkAllowError(filename);
|
||||
EXPECT_EQ(0, retval);
|
||||
}
|
||||
|
||||
int FuseUnlinkTest::UnlinkAllowError(const char *filename) {
|
||||
auto fs = TestFS();
|
||||
|
||||
auto realpath = fs->mountDir() / filename;
|
||||
return ::unlink(realpath.c_str());
|
||||
}
|
||||
|
||||
Action<void(const char*)> FuseUnlinkTest::FromNowOnReturnDoesntExistOnLstat() {
|
||||
return Invoke([this](const char *filename) {
|
||||
ReturnDoesntExistOnLstat(filename);
|
||||
});
|
||||
}
|
17
src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.h
Normal file
17
src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#ifndef TEST_FSPP_FUSE_UNLINK_TESTUTILS_FUSEUNLINKTEST_H_
|
||||
#define TEST_FSPP_FUSE_UNLINK_TESTUTILS_FUSEUNLINKTEST_H_
|
||||
|
||||
#include "test/testutils/FuseTest.h"
|
||||
|
||||
class FuseUnlinkTest: public FuseTest {
|
||||
public:
|
||||
const char *FILENAME = "/myfile";
|
||||
|
||||
void Unlink(const char *filename);
|
||||
int UnlinkAllowError(const char *filename);
|
||||
|
||||
::testing::Action<void(const char*)> FromNowOnReturnDoesntExistOnLstat();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user