Created error path test cases for lstat

This commit is contained in:
Sebastian Messmer 2014-11-20 16:48:58 +01:00
parent 26c6267087
commit 0762c1dbde
4 changed files with 56 additions and 6 deletions

View 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);
}

View File

@ -1,4 +0,0 @@
#include "gtest/gtest.h"
#include "gmock/gmock.h"
//TODO Error cases

View File

@ -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) {

View File

@ -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);