Testcases for access()
This commit is contained in:
parent
2ca7c293b9
commit
f4e3ad7e5b
@ -24,8 +24,8 @@ public:
|
||||
virtual void write(int descriptor, const void *buf, size_t count, off_t offset) = 0;
|
||||
virtual void fsync(int descriptor) = 0;
|
||||
virtual void fdatasync(int descriptor) = 0;
|
||||
//TODO Unit-Tests for all functions below
|
||||
virtual void access(const boost::filesystem::path &path, int mask) = 0;
|
||||
//TODO Unit-Tests for all functions below
|
||||
virtual void mkdir(const boost::filesystem::path &path, mode_t mode) = 0;
|
||||
virtual void rmdir(const boost::filesystem::path &path) = 0;
|
||||
virtual void unlink(const boost::filesystem::path &path) = 0;
|
||||
|
27
src/test/fspp/fuse/access/FuseAccessErrorTest.cpp
Normal file
27
src/test/fspp/fuse/access/FuseAccessErrorTest.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "testutils/FuseAccessTest.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "fspp/impl/FuseErrnoException.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::StrEq;
|
||||
using ::testing::Throw;
|
||||
using ::testing::WithParamInterface;
|
||||
using ::testing::Values;
|
||||
|
||||
using namespace fspp;
|
||||
|
||||
class FuseAccessErrorTest: public FuseAccessTest, public WithParamInterface<int> {
|
||||
};
|
||||
INSTANTIATE_TEST_CASE_P(FuseAccessErrorTest, FuseAccessErrorTest, Values(EACCES, ELOOP, ENAMETOOLONG, ENOENT, ENOTDIR, EROFS, EFAULT, EINVAL, EIO, ENOMEM, ETXTBSY));
|
||||
|
||||
TEST_P(FuseAccessErrorTest, ReturnedErrorIsCorrect) {
|
||||
ReturnIsFileOnLstat(FILENAME);
|
||||
EXPECT_CALL(fsimpl, access(StrEq(FILENAME), _))
|
||||
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
|
||||
|
||||
int retval = AccessFileAllowError(FILENAME, 0);
|
||||
EXPECT_EQ(GetParam(), errno);
|
||||
EXPECT_EQ(-1, retval);
|
||||
}
|
38
src/test/fspp/fuse/access/FuseAccessFilenameTest.cpp
Normal file
38
src/test/fspp/fuse/access/FuseAccessFilenameTest.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "testutils/FuseAccessTest.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::StrEq;
|
||||
using ::testing::Return;
|
||||
|
||||
class FuseAccessFilenameTest: public FuseAccessTest {
|
||||
};
|
||||
|
||||
TEST_F(FuseAccessFilenameTest, AccessFile) {
|
||||
ReturnIsFileOnLstat("/myfile");
|
||||
EXPECT_CALL(fsimpl, access(StrEq("/myfile"), _))
|
||||
.Times(1).WillOnce(Return());
|
||||
|
||||
AccessFile("/myfile", 0);
|
||||
}
|
||||
|
||||
TEST_F(FuseAccessFilenameTest, AccessFileNested) {
|
||||
ReturnIsDirOnLstat("/mydir");
|
||||
ReturnIsFileOnLstat("/mydir/myfile");
|
||||
EXPECT_CALL(fsimpl, access(StrEq("/mydir/myfile"), _))
|
||||
.Times(1).WillOnce(Return());
|
||||
|
||||
AccessFile("/mydir/myfile", 0);
|
||||
}
|
||||
|
||||
TEST_F(FuseAccessFilenameTest, AccessFileNested2) {
|
||||
ReturnIsDirOnLstat("/mydir");
|
||||
ReturnIsDirOnLstat("/mydir/mydir2");
|
||||
ReturnIsFileOnLstat("/mydir/mydir2/myfile");
|
||||
EXPECT_CALL(fsimpl, access(StrEq("/mydir/mydir2/myfile"), _))
|
||||
.Times(1).WillOnce(Return());
|
||||
|
||||
AccessFile("/mydir/mydir2/myfile", 0);
|
||||
}
|
23
src/test/fspp/fuse/access/FuseAccessModeTest.cpp
Normal file
23
src/test/fspp/fuse/access/FuseAccessModeTest.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "testutils/FuseAccessTest.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::StrEq;
|
||||
using ::testing::Return;
|
||||
using ::testing::WithParamInterface;
|
||||
using ::testing::Values;
|
||||
|
||||
class FuseAccessModeTest: public FuseAccessTest, public WithParamInterface<int> {
|
||||
};
|
||||
INSTANTIATE_TEST_CASE_P(FuseAccessModeTest, FuseAccessModeTest, Values(0, F_OK, R_OK, W_OK, X_OK, R_OK|W_OK, W_OK|X_OK, R_OK|X_OK, R_OK|W_OK|X_OK));
|
||||
|
||||
|
||||
TEST_P(FuseAccessModeTest, AccessFile) {
|
||||
ReturnIsFileOnLstat(FILENAME);
|
||||
EXPECT_CALL(fsimpl, access(StrEq(FILENAME), GetParam()))
|
||||
.Times(1).WillOnce(Return());
|
||||
|
||||
AccessFile(FILENAME, GetParam());
|
||||
}
|
13
src/test/fspp/fuse/access/testutils/FuseAccessTest.cpp
Normal file
13
src/test/fspp/fuse/access/testutils/FuseAccessTest.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "FuseAccessTest.h"
|
||||
|
||||
void FuseAccessTest::AccessFile(const char *filename, int mode) {
|
||||
int retval = AccessFileAllowError(filename, mode);
|
||||
EXPECT_EQ(0, retval);
|
||||
}
|
||||
|
||||
int FuseAccessTest::AccessFileAllowError(const char *filename, int mode) {
|
||||
auto fs = TestFS();
|
||||
|
||||
auto realpath = fs->mountDir() / filename;
|
||||
return ::access(realpath.c_str(), mode);
|
||||
}
|
15
src/test/fspp/fuse/access/testutils/FuseAccessTest.h
Normal file
15
src/test/fspp/fuse/access/testutils/FuseAccessTest.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#ifndef TEST_FSPP_FUSE_ACCESS_TESTUTILS_FUSEACCESSTEST_H_
|
||||
#define TEST_FSPP_FUSE_ACCESS_TESTUTILS_FUSEACCESSTEST_H_
|
||||
|
||||
#include "test/testutils/FuseTest.h"
|
||||
|
||||
class FuseAccessTest: public FuseTest {
|
||||
public:
|
||||
const char *FILENAME = "/myfile";
|
||||
|
||||
void AccessFile(const char *filename, int mode);
|
||||
int AccessFileAllowError(const char *filename, int mode);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user