Added some more lstat tests
This commit is contained in:
parent
36c0ed2348
commit
8ddf18666c
@ -17,7 +17,8 @@ using namespace fspp::fuse;
|
||||
|
||||
namespace {
|
||||
int fusepp_getattr(const char *path, struct stat *stbuf) {
|
||||
return FUSE_OBJ->getattr(bf::path(path), stbuf);
|
||||
int rs = FUSE_OBJ->getattr(bf::path(path), stbuf);
|
||||
return rs;
|
||||
}
|
||||
|
||||
int fusepp_fgetattr(const char *path, struct stat *stbuf, fuse_file_info *fileinfo) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "test/testutils/FuseTest.h"
|
||||
|
||||
using namespace fspp;
|
||||
@ -13,21 +15,105 @@ using ::testing::Invoke;
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::function;
|
||||
|
||||
class FuseLstatTest: public FuseTest {
|
||||
public:
|
||||
const char *FILENAME = "/myfile";
|
||||
const mode_t MODE1 = S_IFREG | S_IRUSR | S_IWGRP | S_IXOTH;
|
||||
const mode_t MODE2 = S_IFDIR | S_IWUSR | S_IXGRP | S_IROTH;
|
||||
const mode_t MODE_FILE = S_IFREG | S_IRUSR | S_IWGRP | S_IXOTH;
|
||||
const mode_t MODE_DIR = S_IFDIR | S_IWUSR | S_IXGRP | S_IROTH;
|
||||
const uid_t UID1 = 0;
|
||||
const uid_t UID2 = 10;
|
||||
const gid_t GID1 = 0;
|
||||
const gid_t GID2 = 10;
|
||||
const off_t SIZE1 = 0;
|
||||
const off_t SIZE2 = 4096;
|
||||
const off_t SIZE3 = 1024*1024*1024;
|
||||
|
||||
struct stat LstatPath(const string &path) {
|
||||
int LstatPath(const string &path) {
|
||||
struct stat dummy;
|
||||
return LstatPath(path, &dummy);
|
||||
}
|
||||
|
||||
int LstatPath(const string &path, struct stat *result) {
|
||||
auto fs = TestFS();
|
||||
|
||||
auto realpath = fs->mountDir() / path;
|
||||
struct stat stat;
|
||||
::lstat(realpath.c_str(), &stat);
|
||||
return ::lstat(realpath.c_str(), result);
|
||||
}
|
||||
|
||||
return stat;
|
||||
struct stat CallLstatWithMode(mode_t mode) {
|
||||
return CallLstatWithModeAndImpl(mode, [](struct stat*){});
|
||||
}
|
||||
|
||||
struct stat CallFileLstatWithUid(uid_t uid) {
|
||||
return CallFileLstatWithImpl(LstatUidImpl(uid));
|
||||
}
|
||||
|
||||
struct stat CallDirLstatWithUid(uid_t uid) {
|
||||
return CallDirLstatWithImpl(LstatUidImpl(uid));
|
||||
}
|
||||
|
||||
struct stat CallFileLstatWithGid(gid_t gid) {
|
||||
return CallFileLstatWithImpl(LstatGidImpl(gid));
|
||||
}
|
||||
|
||||
struct stat CallDirLstatWithGid(gid_t gid) {
|
||||
return CallDirLstatWithImpl(LstatGidImpl(gid));
|
||||
}
|
||||
|
||||
struct stat CallFileLstatWithSize(off_t size) {
|
||||
return CallFileLstatWithImpl(LstatSizeImpl(size));
|
||||
}
|
||||
|
||||
struct stat CallDirLstatWithSize(off_t size) {
|
||||
return CallDirLstatWithImpl(LstatSizeImpl(size));
|
||||
}
|
||||
private:
|
||||
|
||||
static function<void(struct stat*)> LstatUidImpl(uid_t uid) {
|
||||
return [uid] (struct stat *stat) {
|
||||
stat->st_uid = uid;
|
||||
};
|
||||
}
|
||||
|
||||
static function<void(struct stat*)> LstatGidImpl(gid_t gid) {
|
||||
return [gid] (struct stat *stat) {
|
||||
stat->st_gid = gid;
|
||||
};
|
||||
}
|
||||
|
||||
static function<void(struct stat*)> LstatSizeImpl(off_t size) {
|
||||
return [size] (struct stat *stat) {
|
||||
stat->st_size = size;
|
||||
};
|
||||
}
|
||||
|
||||
struct stat CallFileLstatWithImpl(function<void(struct stat*)> implementation) {
|
||||
return CallLstatWithModeAndImpl(S_IFREG, implementation);
|
||||
}
|
||||
|
||||
struct stat CallDirLstatWithImpl(function<void(struct stat*)> implementation) {
|
||||
return CallLstatWithModeAndImpl(S_IFDIR, implementation);
|
||||
}
|
||||
|
||||
struct stat CallLstatWithModeAndImpl(mode_t mode, function<void(struct stat*)> implementation) {
|
||||
return CallLstatWithImpl([mode, implementation] (struct stat *stat) {
|
||||
stat->st_mode = mode;
|
||||
implementation(stat);
|
||||
});
|
||||
}
|
||||
|
||||
struct stat CallLstatWithImpl(function<void(struct stat*)> implementation) {
|
||||
EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).WillRepeatedly(Invoke([implementation](const char*, struct ::stat *stat) {
|
||||
implementation(stat);
|
||||
}));
|
||||
|
||||
struct stat result;
|
||||
int retval = LstatPath(FILENAME, &result);
|
||||
EXPECT_EQ(0, retval) << "lstat syscall failed. errno: " << errno;
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
@ -61,20 +147,87 @@ TEST_F(FuseLstatTest, PathParameterIsCorrectNestedDir) {
|
||||
LstatPath("/mydir/mydir2/mydir3/");
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedModeIsCorrect1) {
|
||||
EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).WillRepeatedly(Invoke([this](const char*, struct ::stat *stat) {
|
||||
stat->st_mode = MODE1;
|
||||
}));
|
||||
|
||||
struct ::stat result = LstatPath(FILENAME);
|
||||
EXPECT_EQ(MODE1, result.st_mode);
|
||||
TEST_F(FuseLstatTest, ReturnedFileModeIsCorrect) {
|
||||
struct ::stat result = CallLstatWithMode(MODE_FILE);
|
||||
EXPECT_EQ(MODE_FILE, result.st_mode);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedModeIsCorrect2) {
|
||||
EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).WillRepeatedly(Invoke([this](const char*, struct ::stat *stat) {
|
||||
stat->st_mode = MODE2;
|
||||
}));
|
||||
|
||||
struct ::stat result = LstatPath(FILENAME);
|
||||
EXPECT_EQ(MODE2, result.st_mode);
|
||||
TEST_F(FuseLstatTest, ReturnedDirModeIsCorrect) {
|
||||
struct ::stat result = CallLstatWithMode(MODE_DIR);
|
||||
EXPECT_EQ(MODE_DIR, result.st_mode);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedFileUidIsCorrect1) {
|
||||
struct ::stat result = CallFileLstatWithUid(UID1);
|
||||
EXPECT_EQ(UID1, result.st_uid);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedFileUidIsCorrect2) {
|
||||
struct ::stat result = CallFileLstatWithUid(UID2);
|
||||
EXPECT_EQ(UID2, result.st_uid);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedDirUidIsCorrect1) {
|
||||
struct ::stat result = CallDirLstatWithUid(UID1);
|
||||
EXPECT_EQ(UID1, result.st_uid);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedDirUidIsCorrect2) {
|
||||
struct ::stat result = CallDirLstatWithUid(UID2);
|
||||
EXPECT_EQ(UID2, result.st_uid);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedFileGidIsCorrect1) {
|
||||
struct ::stat result = CallFileLstatWithUid(GID1);
|
||||
EXPECT_EQ(GID1, result.st_gid);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedFileGidIsCorrect2) {
|
||||
struct ::stat result = CallFileLstatWithGid(GID2);
|
||||
EXPECT_EQ(GID2, result.st_gid);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedDirGidIsCorrect1) {
|
||||
struct ::stat result = CallDirLstatWithGid(GID1);
|
||||
EXPECT_EQ(GID1, result.st_gid);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedDirGidIsCorrect2) {
|
||||
struct ::stat result = CallDirLstatWithGid(GID2);
|
||||
EXPECT_EQ(GID2, result.st_gid);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedFileSizeIsCorrect1) {
|
||||
struct ::stat result = CallFileLstatWithSize(SIZE1);
|
||||
EXPECT_EQ(SIZE1, result.st_size);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedFileSizeIsCorrect2) {
|
||||
struct ::stat result = CallFileLstatWithSize(SIZE2);
|
||||
EXPECT_EQ(SIZE2, result.st_size);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedFileSizeIsCorrect3) {
|
||||
struct ::stat result = CallFileLstatWithSize(SIZE3);
|
||||
EXPECT_EQ(SIZE3, result.st_size);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedDirSizeIsCorrect1) {
|
||||
struct ::stat result = CallDirLstatWithSize(SIZE1);
|
||||
EXPECT_EQ(SIZE1, result.st_size);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedDirSizeIsCorrect2) {
|
||||
struct ::stat result = CallDirLstatWithSize(SIZE2);
|
||||
EXPECT_EQ(SIZE2, result.st_size);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatTest, ReturnedDirSizeIsCorrect3) {
|
||||
struct ::stat result = CallDirLstatWithSize(SIZE3);
|
||||
EXPECT_EQ(SIZE3, result.st_size);
|
||||
}
|
||||
|
||||
//TODO st_nlink?
|
||||
//TODO st_atim
|
||||
//TODO st_mtim
|
||||
//TODO st_ctim
|
||||
|
Loading…
Reference in New Issue
Block a user