diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-12-16 21:04:33 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-12-16 21:04:33 +0000 |
commit | 6d20e27d6b965b774e52ac1f3fbd58fc307c2465 (patch) | |
tree | 5e3625a41d0a449ac298bd829cd528f5db5763b9 /netfs/unittests/testFuse.cpp | |
parent | Psycho-rebased branch mapper on top of netfs-1.4 (diff) | |
download | netfs-6d20e27d6b965b774e52ac1f3fbd58fc307c2465.tar.bz2 netfs-6d20e27d6b965b774e52ac1f3fbd58fc307c2465.tar.xz netfs-6d20e27d6b965b774e52ac1f3fbd58fc307c2465.zip |
Factor FuseMountPoint mock into its own file
Diffstat (limited to 'netfs/unittests/testFuse.cpp')
-rw-r--r-- | netfs/unittests/testFuse.cpp | 80 |
1 files changed, 1 insertions, 79 deletions
diff --git a/netfs/unittests/testFuse.cpp b/netfs/unittests/testFuse.cpp index b0603b0..dd773b2 100644 --- a/netfs/unittests/testFuse.cpp +++ b/netfs/unittests/testFuse.cpp @@ -1,5 +1,6 @@ #define BOOST_TEST_MODULE TestNetFSFuse #include "mockDaemon.h" +#include "mockMount.h" #include <boost/test/unit_test.hpp> #include <c++11Helpers.h> #include <cache.impl.h> @@ -12,85 +13,6 @@ #include <ostream> #include <thread> -static const std::filesystem::path mntpnt {binDir / "mnt"}; -const std::string testEndpoint("tcp -h localhost -p 12015"); -const std::string testUri("tcp://localhost:12015/testvol"); - -class FuseMountPoint : public MockDaemonHost, public NetFS::FuseApp { -public: - FuseMountPoint() : - MockDaemonHost(::testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()}), - NetFS::FuseApp({::testUri}), fargs {} - { - std::filesystem::remove_all(mntpnt); - std::filesystem::create_directory(mntpnt); - ::fuse_opt_add_arg(&fargs, selfExe.c_str()); - ::fuse_opt_add_arg(&fargs, "-onoauto_cache"); - ::fuse_opt_add_arg(&fargs, "-oattr_timeout=0"); - ::fuse_opt_add_arg(&fargs, "-oac_attr_timeout=0"); - fs = ::fuse_new(&fargs, &operations, sizeof(fuse_operations), this); - BOOST_REQUIRE(fs); - } - - void - start() - { - BOOST_REQUIRE(!th); - BOOST_REQUIRE_EQUAL(0, ::fuse_mount(fs, mntpnt.c_str())); - th = std::make_unique<std::thread>(::fuse_loop, fs); - BOOST_REQUIRE(th); - } - - ~FuseMountPoint() override - { - stop(); - std::filesystem::remove(mntpnt); - ::fuse_destroy(fs); - ::fuse_opt_free_args(&fargs); - } - - void - stop() - { - if (th) { - ::fuse_unmount(fs); - th->join(); - th.reset(); - } - } - - SPECIAL_MEMBERS_DELETE(FuseMountPoint); - - struct fuse_context * - fuse_get_context() override - { - return ::fuse_get_context(); - } - - static inline char * - vstrdupf(const char * fmt, va_list args) - { - char * out {}; - BOOST_REQUIRE_GE(vasprintf(&out, fmt, args), 0); - BOOST_REQUIRE(out); - return out; - } - - void - vlogf(int, const char * fmt, va_list args) const noexcept override - { - std::unique_ptr<char, void (*)(void *)> msg(vstrdupf(fmt, args), std::free); - static std::mutex btm; - ScopeLock(btm) { - BOOST_TEST_MESSAGE(msg.get()); - } - } - - struct fuse * fs; - struct fuse_args fargs; - std::unique_ptr<std::thread> th; -}; - #define BOOST_CHECK_EQUAL_FIELD(left, right, field) BOOST_CHECK_EQUAL((left).field, (right).field); #define BOOST_CHECK_EQUAL_STAT(left, right) \ |