summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--netfs/unittests/Jamfile.jam2
-rw-r--r--netfs/unittests/mockMount.cpp72
-rw-r--r--netfs/unittests/mockMount.h36
-rw-r--r--netfs/unittests/testFuse.cpp80
4 files changed, 110 insertions, 80 deletions
diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam
index fc9d00b..e811c57 100644
--- a/netfs/unittests/Jamfile.jam
+++ b/netfs/unittests/Jamfile.jam
@@ -24,7 +24,7 @@ lib testMocks :
<library>../fuse//netfs-client
<library>../ice//netfs-api
<library>..//adhocutil
- <define>BOOST_TEST_DYN_LINK
+ <define>BOOST_TEST_NO_MAIN
<library>boost_utf
<define>ROOT=\"$(me)\"
: :
diff --git a/netfs/unittests/mockMount.cpp b/netfs/unittests/mockMount.cpp
new file mode 100644
index 0000000..7655296
--- /dev/null
+++ b/netfs/unittests/mockMount.cpp
@@ -0,0 +1,72 @@
+#include "mockMount.h"
+#include <boost/test/included/unit_test.hpp>
+#include <filesystem>
+
+const std::string testEndpoint("tcp -h localhost -p 12015");
+const std::string testUri("tcp://localhost:12015/testvol");
+
+FuseMountPoint::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
+FuseMountPoint::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::~FuseMountPoint()
+{
+ stop();
+ std::filesystem::remove(mntpnt);
+ ::fuse_destroy(fs);
+ ::fuse_opt_free_args(&fargs);
+}
+
+void
+FuseMountPoint::stop()
+{
+ if (th) {
+ ::fuse_unmount(fs);
+ th->join();
+ th.reset();
+ }
+}
+
+struct fuse_context *
+FuseMountPoint::fuse_get_context()
+{
+ return ::fuse_get_context();
+}
+
+char *
+FuseMountPoint::vstrdupf(const char * fmt, va_list args)
+{
+ char * out {};
+ BOOST_REQUIRE_GE(vasprintf(&out, fmt, args), 0);
+ BOOST_REQUIRE(out);
+ return out;
+}
+
+void
+FuseMountPoint::vlogf(int, const char * fmt, va_list args) const noexcept
+{
+ std::unique_ptr<char, void (*)(void *)> msg(vstrdupf(fmt, args), std::free);
+ static std::mutex btm;
+ ScopeLock(btm) {
+ BOOST_TEST_MESSAGE(msg.get());
+ }
+}
diff --git a/netfs/unittests/mockMount.h b/netfs/unittests/mockMount.h
new file mode 100644
index 0000000..38fb2ee
--- /dev/null
+++ b/netfs/unittests/mockMount.h
@@ -0,0 +1,36 @@
+#ifndef MOCKMOUNT_H
+#define MOCKMOUNT_H
+
+#include "mockDaemon.h"
+#include <definedDirs.h>
+#include <fuseApp.h>
+#include <memory>
+#include <thread>
+#include <visibility.h>
+
+inline const std::filesystem::path mntpnt {binDir / "mnt"};
+
+class DLL_PUBLIC FuseMountPoint : public MockDaemonHost, public NetFS::FuseApp {
+public:
+ FuseMountPoint();
+
+ void start();
+
+ ~FuseMountPoint() override;
+
+ void stop();
+
+ SPECIAL_MEMBERS_DELETE(FuseMountPoint);
+
+ struct fuse_context * fuse_get_context() override;
+
+ static char * vstrdupf(const char * fmt, va_list args);
+
+ void vlogf(int, const char * fmt, va_list args) const noexcept override;
+
+ struct fuse * fs;
+ struct fuse_args fargs;
+ std::unique_ptr<std::thread> th;
+};
+
+#endif
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) \