diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-07-15 00:37:03 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-07-19 15:47:56 +0100 |
commit | 0e1525c54e190b8869afe789db599b74543b7b72 (patch) | |
tree | d35c11d5d634083aac03155b928137ac64203847 | |
parent | Refactor mocked daemon and sandbox export into it's own files (diff) | |
download | netfs-0e1525c54e190b8869afe789db599b74543b7b72.tar.bz2 netfs-0e1525c54e190b8869afe789db599b74543b7b72.tar.xz netfs-0e1525c54e190b8869afe789db599b74543b7b72.zip |
Refactor mocked fuse client into it's own files
-rw-r--r-- | netfs/unittests/Jamfile.jam | 2 | ||||
-rw-r--r-- | netfs/unittests/mockFuse.cpp | 68 | ||||
-rw-r--r-- | netfs/unittests/mockFuse.h | 39 | ||||
-rw-r--r-- | netfs/unittests/testCore.cpp | 86 |
4 files changed, 114 insertions, 81 deletions
diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam index ac6ec38..3b4694b 100644 --- a/netfs/unittests/Jamfile.jam +++ b/netfs/unittests/Jamfile.jam @@ -9,7 +9,7 @@ lib Ice ; path-constant me : . ; run - testCore.cpp mockDaemon.cpp + testCore.cpp mockDaemon.cpp mockFuse.cpp : : : <define>BOOST_TEST_DYN_LINK diff --git a/netfs/unittests/mockFuse.cpp b/netfs/unittests/mockFuse.cpp new file mode 100644 index 0000000..7f9790b --- /dev/null +++ b/netfs/unittests/mockFuse.cpp @@ -0,0 +1,68 @@ +#include "mockFuse.h" + +FuseMock::FuseMock(const std::string & ep, int & argc, char ** argv) : + NetFS::FuseApp(argc, argv), + testEndpoint(ep) +{ + ::memset(&context, 0, sizeof(fuse_context)); + context.pid = getpid(); + context.uid = getuid(); + context.gid = getgid(); +} + +struct fuse_context * +FuseMock::fuse_get_context() +{ + return &context; +} + +int +FuseMock::fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt [], fuse_opt_proc_t proc) +{ + for (int n = 0; n < args->argc; n += 1) { + proc(data, args->argv[n], n, args); + } + return 0; +} + +int +FuseMock::main(int &, char **, const struct fuse_operations * o) +{ + o->init(NULL); + ops = *o; + return 0; +} + +NetFS::Client::ConfigurationPtr +FuseMock::ReadConfiguration(const std::string &) const +{ + return new NetFS::Client::Configuration( + { + { "testvol", new NetFS::Client::Resource("testvol", "Service", { testEndpoint }) } + }); +} + +/* +FuseMockHost::FuseMockHost() : + argc(2), + app(new FuseMock(argc, argv)), + fuse(&app->ops) +{ + char ** a = argv; + FuseAppBase::run(argc, a, app); +} +*/ + +FuseMockHost::FuseMockHost(const std::string & ep, int c, char ** v) : + argc(c), + app(new FuseMock(ep, c, v)), + fuse(&app->ops) +{ + FuseAppBase::run(argc, v, app); +} + +FuseMockHost::~FuseMockHost() +{ + delete app; +} + diff --git a/netfs/unittests/mockFuse.h b/netfs/unittests/mockFuse.h new file mode 100644 index 0000000..3ca88fe --- /dev/null +++ b/netfs/unittests/mockFuse.h @@ -0,0 +1,39 @@ +#ifndef MOCKFUSE_H +#define MOCKFUSE_H + +#include <fuseApp.h> + +class FuseMock : public NetFS::FuseApp { + public: + FuseMock(const std::string &, int & argc, char ** argv); + + struct fuse_context * fuse_get_context() override; + int fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt [], fuse_opt_proc_t proc) override; + int main(int &, char **, const struct fuse_operations * o) override; + + fuse_operations ops; + + protected: + virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const override; + + private: + const std::string testEndpoint; + fuse_context context; +}; + +class FuseMockHost { + public: + FuseMockHost(const std::string &, int c, char ** v); + ~FuseMockHost(); + + private: + int argc; + FuseMock * app; + + public: + fuse_operations * fuse; +}; + + +#endif + diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 440fd29..6589838 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -6,7 +6,7 @@ #include <Ice/ObjectAdapter.h> #include <Ice/Service.h> #include "mockDaemon.h" -#include <fuseApp.h> +#include "mockFuse.h" #include <boost/filesystem/path.hpp> #ifndef ROOT @@ -18,90 +18,16 @@ const boost::filesystem::path RootDir(XSTR(ROOT)); const std::string testEndpoint("tcp -h localhost -p 12012"); -char * argv[] = { +char * defaultFuseArgv[] = { strdup((RootDir / ":testvol").string().c_str()), strdup((RootDir / "test").string().c_str()) }; -class FuseMock : public NetFS::FuseApp { - public: - FuseMock(int & argc, char ** argv) : - NetFS::FuseApp(argc, argv) - { - ::memset(&context, 0, sizeof(fuse_context)); - context.pid = getpid(); - context.uid = getuid(); - context.gid = getgid(); - } - - struct fuse_context * fuse_get_context() override - { - return &context; - } - - int fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt [], fuse_opt_proc_t proc) override - { - for (int n = 0; n < args->argc; n += 1) { - proc(data, args->argv[n], n, args); - } - return 0; - } - - int main(int &, char **, const struct fuse_operations * o) override - { - o->init(NULL); - ops = *o; - return 0; - } - - fuse_operations ops; - - protected: - virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const override - { - return new NetFS::Client::Configuration( - { - { "testvol", new NetFS::Client::Resource("testvol", "Service", { testEndpoint }) } - }); - } - - private: - fuse_context context; -}; - -class FuseMockHost { - public: - FuseMockHost() : - argc(2), - app(new FuseMock(argc, argv)), - fuse(&app->ops) - { - char ** a = argv; - FuseAppBase::run(argc, a, app); - } - - FuseMockHost(int c, char ** v) : - argc(c), - app(new FuseMock(c, v)), - fuse(&app->ops) - { - FuseAppBase::run(argc, v, app); - } - - ~FuseMockHost() - { - delete app; - } - - int argc; - FuseMock * app; - fuse_operations * fuse; -}; - class Core { public: Core() : daemonHost(testEndpoint), + fuseHost(testEndpoint, 2, defaultFuseArgv), ic(daemonHost.ic), fuse(fuseHost.fuse) { @@ -135,7 +61,7 @@ BOOST_AUTO_TEST_SUITE_END(); BOOST_AUTO_TEST_CASE ( createAndDaemonRestart ) { MockDaemonHost daemon(testEndpoint); - FuseMockHost fuse; + FuseMockHost fuse(testEndpoint, 2, defaultFuseArgv); struct statvfs s; BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); @@ -183,14 +109,14 @@ BOOST_AUTO_TEST_CASE ( withRouter ) } BOOST_SCOPE_EXIT_END; { - char * argv[] = { + char * glacierFuseArgv[] = { strdup((RootDir / ":testvol").string().c_str()), strdup((RootDir / "test").string().c_str()), strdup("--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 4063") }; MockDaemonHost daemon(testEndpoint); - FuseMockHost fuse(3, argv); + FuseMockHost fuse(testEndpoint, 3, glacierFuseArgv); struct statvfs s; BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); |