2014-11-25 14:29:44 +01:00
|
|
|
#include "testutils/FuseFstatTest.h"
|
|
|
|
|
2015-02-17 00:48:49 +01:00
|
|
|
#include "../../../fuse/FuseErrnoException.h"
|
2014-11-25 14:29:44 +01:00
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::StrEq;
|
|
|
|
using ::testing::WithParamInterface;
|
|
|
|
using ::testing::Values;
|
|
|
|
using ::testing::Eq;
|
|
|
|
using ::testing::Return;
|
|
|
|
using ::testing::Throw;
|
|
|
|
|
2014-11-28 14:46:45 +01:00
|
|
|
using namespace fspp::fuse;
|
2014-11-25 14:29:44 +01:00
|
|
|
|
|
|
|
// Cite from FUSE documentation on the fgetattr function:
|
|
|
|
// "Currently this is only called after the create() method if that is implemented (see above).
|
|
|
|
// Later it may be called for invocations of fstat() too."
|
|
|
|
// So we need to issue a create to get our fstat called.
|
|
|
|
|
|
|
|
class FuseFstatErrorTest: public FuseFstatTest, public WithParamInterface<int> {
|
|
|
|
public:
|
|
|
|
int CreateFileAllowErrors(const TempTestFS *fs, const std::string &filename) {
|
|
|
|
auto real_path = fs->mountDir() / filename;
|
2015-11-24 14:33:17 +01:00
|
|
|
#if __GNUC__ == 4 && __GNUC_MINOR__ == 8
|
|
|
|
return ::open(real_path.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
|
|
|
#else
|
2014-11-25 14:29:44 +01:00
|
|
|
return ::open(real_path.c_str(), O_RDWR | O_CREAT);
|
2015-11-24 14:33:17 +01:00
|
|
|
#endif
|
2014-11-25 14:29:44 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
INSTANTIATE_TEST_CASE_P(FuseFstatErrorTest, FuseFstatErrorTest, Values(EACCES, EBADF, EFAULT, ELOOP, ENAMETOOLONG, ENOENT, ENOMEM, ENOTDIR, EOVERFLOW));
|
|
|
|
|
2014-11-25 14:58:00 +01:00
|
|
|
TEST_P(FuseFstatErrorTest, ReturnedErrorCodeIsCorrect) {
|
2014-11-25 14:29:44 +01:00
|
|
|
ReturnDoesntExistOnLstat(FILENAME);
|
2014-11-25 18:43:50 +01:00
|
|
|
OnCreateAndOpenReturnFileDescriptor(FILENAME, 0);
|
2014-11-25 14:29:44 +01:00
|
|
|
|
|
|
|
EXPECT_CALL(fsimpl, fstat(Eq(0), _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
|
|
|
|
|
|
|
|
auto fs = TestFS();
|
|
|
|
|
2014-12-06 15:33:01 +01:00
|
|
|
int error = CreateFileReturnError(fs.get(), FILENAME);
|
|
|
|
EXPECT_EQ(GetParam(), error);
|
2014-11-25 14:29:44 +01:00
|
|
|
}
|