diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-02-19 01:19:36 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-05-06 00:40:49 +0100 |
commit | 0e8a82f89a5293411cb877deb87703a352f8e421 (patch) | |
tree | 3a5b0a542b4bab4ae78a3c2ce5bcbf4fd4c06b56 | |
parent | Keep a copy of fuse operations map (diff) | |
download | netfs-0e8a82f89a5293411cb877deb87703a352f8e421.tar.bz2 netfs-0e8a82f89a5293411cb877deb87703a352f8e421.tar.xz netfs-0e8a82f89a5293411cb877deb87703a352f8e421.zip |
Refactor mocked stuff in wrappers for easy setup/teardown and expose the fuse operations map instead of the app instance
-rw-r--r-- | netfs/unittests/testCore.cpp | 72 |
1 files changed, 50 insertions, 22 deletions
diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 0f74925..495c5a7 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -35,6 +35,35 @@ class MockDaemon : public NetFSDaemon { } }; +class MockDaemonHost { + public: + MockDaemonHost() : + params({}), + ic(Ice::initialize(params)), + daemon(new MockDaemon(ic)) + { + ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); + daemon->start("NetFSDaemonAdapter", ic, {}); + + } + + ~MockDaemonHost() + { + delete daemon; + ic->destroy(); + } + + Ice::StringSeq params; + Ice::CommunicatorPtr ic; + NetFSDaemon * daemon; +}; +typedef boost::shared_ptr<MockDaemonHost> MockDaemonHostPtr; + +char * argv[] = { + strdup((RootDir / ":testvol").string().c_str()), + strdup((RootDir / "test").string().c_str()) +}; + class FuseMock : public NetFS::FuseApp { public: FuseMock(int & argc, char ** argv) : @@ -81,39 +110,38 @@ class FuseMock : public NetFS::FuseApp { fuse_context context; }; -char * argv[] = { - strdup((RootDir / ":testvol").string().c_str()), - strdup((RootDir / "test").string().c_str()) -}; - -class Core { +class FuseMockHost { public: - Core() : - params({}), - ic(Ice::initialize(params)), - daemon(new MockDaemon(ic)), + FuseMockHost() : argc(2), - fuse(new FuseMock(argc, argv)) + app(new FuseMock(argc, argv)), + fuse(&app->ops) { - ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); - daemon->start("NetFSDaemonAdapter", ic, {}); char ** a = argv; - FuseAppBase::run(argc, a, fuse); + FuseAppBase::run(argc, a, app); } - ~Core() + int argc; + FuseMock * app; + fuse_operations * fuse; +}; + +class Core { + public: + Core() : + ic(daemonHost.ic), + daemon(daemonHost.daemon), + fuse(fuseHost.fuse) { - delete fuse; - delete daemon; - ic->destroy(); } protected: - Ice::StringSeq params; + MockDaemonHost daemonHost; + FuseMockHost fuseHost; + Ice::CommunicatorPtr ic; - NetFSDaemon * daemon; - int argc; - FuseAppBase * fuse; + NetFSDaemon * const daemon; + fuse_operations * fuse;; }; BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) |