2014-11-20 15:35:52 +01:00
|
|
|
#pragma once
|
2015-10-15 13:04:57 +02:00
|
|
|
#ifndef MESSMER_FSPP_TEST_FUSE_LSTAT_TESTUTILS_FUSELSTATTEST_H_
|
|
|
|
#define MESSMER_FSPP_TEST_FUSE_LSTAT_TESTUTILS_FUSELSTATTEST_H_
|
2014-11-20 15:35:52 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <functional>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2015-02-17 00:48:49 +01:00
|
|
|
#include "../../../testutils/FuseTest.h"
|
2014-11-20 15:35:52 +01:00
|
|
|
|
2014-11-20 20:04:39 +01:00
|
|
|
// This class offers some utility functions for testing lstat().
|
2014-11-20 15:35:52 +01:00
|
|
|
class FuseLstatTest: public FuseTest {
|
2014-11-20 20:04:39 +01:00
|
|
|
protected:
|
2014-11-20 15:35:52 +01:00
|
|
|
const char *FILENAME = "/myfile";
|
|
|
|
|
2014-11-20 20:04:39 +01:00
|
|
|
// Set up a temporary filesystem (using the fsimpl mock in FuseTest as filesystem implementation)
|
|
|
|
// and call the lstat syscall on the given (filesystem-relative) path.
|
2014-11-20 15:35:52 +01:00
|
|
|
void LstatPath(const std::string &path);
|
2014-11-20 20:04:39 +01:00
|
|
|
// Same as LstatPath above, but also return the result of the lstat syscall.
|
2018-09-16 03:02:03 +02:00
|
|
|
void LstatPath(const std::string &path, fspp::fuse::STAT *result);
|
2014-11-20 20:04:39 +01:00
|
|
|
|
|
|
|
// These two functions are the same as LstatPath above, but they don't fail the test when the lstat syscall
|
2014-12-06 15:33:01 +01:00
|
|
|
// crashes. Instead, they return the value of errno after calling ::lstat.
|
|
|
|
int LstatPathReturnError(const std::string &path);
|
2018-09-16 03:02:03 +02:00
|
|
|
int LstatPathReturnError(const std::string &path, fspp::fuse::STAT *result);
|
2014-11-20 15:35:52 +01:00
|
|
|
|
2018-09-16 03:02:03 +02:00
|
|
|
// You can specify an implementation, which can modify the (fspp::fuse::STAT *) result,
|
2014-11-20 20:04:39 +01:00
|
|
|
// our fuse mock filesystem implementation will then return this to fuse on an lstat call.
|
|
|
|
// This functions then set up a temporary filesystem with this mock, call lstat on a filesystem node
|
2018-09-16 03:02:03 +02:00
|
|
|
// and return the (fspp::fuse::STAT) returned from an lstat syscall to this filesystem.
|
|
|
|
fspp::fuse::STAT CallLstatWithImpl(std::function<void(fspp::fuse::STAT*)> implementation);
|
2014-11-20 20:04:39 +01:00
|
|
|
|
2018-09-16 03:02:03 +02:00
|
|
|
// These two functions are like CallLstatWithImpl, but they also modify the (fspp::fuse::STAT).st_mode
|
2014-11-20 20:04:39 +01:00
|
|
|
// field, so the node accessed is specified to be a file/directory.
|
2018-09-16 03:02:03 +02:00
|
|
|
fspp::fuse::STAT CallFileLstatWithImpl(std::function<void(fspp::fuse::STAT*)> implementation);
|
|
|
|
fspp::fuse::STAT CallDirLstatWithImpl(std::function<void(fspp::fuse::STAT*)> implementation);
|
2014-11-20 15:35:52 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2018-09-16 03:02:03 +02:00
|
|
|
fspp::fuse::STAT CallLstatWithModeAndImpl(mode_t mode, std::function<void(fspp::fuse::STAT*)> implementation);
|
2014-11-20 15:35:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|