Created error path test cases for lstat
This commit is contained in:
parent
26c6267087
commit
0762c1dbde
43
src/test/fspp/fuse/lstat/FuseLstatErrorTest.cpp
Normal file
43
src/test/fspp/fuse/lstat/FuseLstatErrorTest.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "testutils/FuseLstatTest.h"
|
||||
|
||||
#include "fspp/impl/FuseErrnoException.h"
|
||||
|
||||
using ::testing::StrEq;
|
||||
using ::testing::_;
|
||||
using ::testing::Throw;
|
||||
|
||||
using fspp::FuseErrnoException;
|
||||
|
||||
class FuseLstatErrorTest: public FuseLstatTest {
|
||||
public:
|
||||
const int ERRCODE1 = EIO;
|
||||
const int ERRCODE2 = EACCES;
|
||||
const int ERRCODE3 = EBADF;
|
||||
};
|
||||
|
||||
TEST_F(FuseLstatErrorTest, ReturnNoError) {
|
||||
EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).Times(1).WillOnce(ReturnIsFile);
|
||||
int retval = LstatPathAllowErrors(FILENAME);
|
||||
EXPECT_EQ(retval, 0);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatErrorTest, ReturnError2) {
|
||||
EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).Times(1).WillOnce(Throw(FuseErrnoException(ERRCODE1)));
|
||||
int retval = LstatPathAllowErrors(FILENAME);
|
||||
EXPECT_EQ(retval, -1);
|
||||
EXPECT_EQ(ERRCODE1, errno);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatErrorTest, ReturnError3) {
|
||||
EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).Times(1).WillOnce(Throw(FuseErrnoException(ERRCODE2)));
|
||||
int retval = LstatPathAllowErrors(FILENAME);
|
||||
EXPECT_EQ(retval, -1);
|
||||
EXPECT_EQ(ERRCODE2, errno);
|
||||
}
|
||||
|
||||
TEST_F(FuseLstatErrorTest, ReturnError4) {
|
||||
EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).Times(1).WillOnce(Throw(FuseErrnoException(ERRCODE3)));
|
||||
int retval = LstatPathAllowErrors(FILENAME);
|
||||
EXPECT_EQ(retval, -1);
|
||||
EXPECT_EQ(ERRCODE3, errno);
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
//TODO Error cases
|
@ -10,12 +10,21 @@ void FuseLstatTest::LstatPath(const std::string &path) {
|
||||
LstatPath(path, &dummy);
|
||||
}
|
||||
|
||||
int FuseLstatTest::LstatPathAllowErrors(const std::string &path) {
|
||||
struct stat dummy;
|
||||
return LstatPathAllowErrors(path, &dummy);
|
||||
}
|
||||
|
||||
void FuseLstatTest::LstatPath(const std::string &path, struct stat *result) {
|
||||
int retval = LstatPathAllowErrors(path, result);
|
||||
EXPECT_EQ(0, retval) << "lstat syscall failed. errno: " << errno;
|
||||
}
|
||||
|
||||
int FuseLstatTest::LstatPathAllowErrors(const std::string &path, struct stat *result) {
|
||||
auto fs = TestFS();
|
||||
|
||||
auto realpath = fs->mountDir() / path;
|
||||
int retval = ::lstat(realpath.c_str(), result);
|
||||
EXPECT_EQ(0, retval) << "lstat syscall failed. errno: " << errno;
|
||||
return ::lstat(realpath.c_str(), result);
|
||||
}
|
||||
|
||||
struct stat FuseLstatTest::CallFileLstatWithImpl(function<void(struct stat*)> implementation) {
|
||||
|
@ -16,6 +16,8 @@ public:
|
||||
|
||||
void LstatPath(const std::string &path);
|
||||
void LstatPath(const std::string &path, struct stat *result);
|
||||
int LstatPathAllowErrors(const std::string &path);
|
||||
int LstatPathAllowErrors(const std::string &path, struct stat *result);
|
||||
|
||||
protected:
|
||||
struct stat CallFileLstatWithImpl(std::function<void(struct stat*)> implementation);
|
||||
|
Loading…
x
Reference in New Issue
Block a user