diff options
author | Dan Goodliffe <daniel.goodliffe@pressassociation.com> | 2015-02-16 17:12:57 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-05-06 00:40:49 +0100 |
commit | 221514b72f4214ac2d4383a7381eb970a77a8d2e (patch) | |
tree | d4b2b3a79249dc69c0922cf5d52c8c23992c884f | |
parent | runint doesn't need a pointer to itself passing in (diff) | |
download | netfs-221514b72f4214ac2d4383a7381eb970a77a8d2e.tar.bz2 netfs-221514b72f4214ac2d4383a7381eb970a77a8d2e.tar.xz netfs-221514b72f4214ac2d4383a7381eb970a77a8d2e.zip |
Add the start of some test framework, complete with hacky initialisations
-rw-r--r-- | netfs/Jamfile.jam | 1 | ||||
-rw-r--r-- | netfs/unittests/Jamfile.jam | 28 | ||||
-rw-r--r-- | netfs/unittests/client.xml | 14 | ||||
-rw-r--r-- | netfs/unittests/daemon.xml | 19 | ||||
-rw-r--r-- | netfs/unittests/testCore.cpp | 95 |
5 files changed, 157 insertions, 0 deletions
diff --git a/netfs/Jamfile.jam b/netfs/Jamfile.jam index 70cd2d9..6df8110 100644 --- a/netfs/Jamfile.jam +++ b/netfs/Jamfile.jam @@ -18,6 +18,7 @@ lib slicer-xml : : : : <include>/usr/include/slicer ; build-project daemon ; build-project fuse ; +build-project unittests ; explicit install ; package.install install : : fuse//netfs : daemon//netfsd ; diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam new file mode 100644 index 0000000..1c16bc7 --- /dev/null +++ b/netfs/unittests/Jamfile.jam @@ -0,0 +1,28 @@ +import testing ; + +lib boost_utf : : <name>boost_unit_test_framework ; +lib boost_system ; +lib boost_filesystem ; +lib IceUtil ; +lib Ice ; + +path-constant me : . ; + +run + testCore.cpp + : : + client.xml + daemon.xml + : + <define>BOOST_TEST_DYN_LINK + <library>IceUtil + <library>Ice + <library>boost_system + <library>boost_filesystem + <library>boost_utf + <library>../daemon//netfsd + <library>../fuse//netfsClient + <library>../ice//netfsComms + <define>ROOT=\"$(me)\" + : testCore ; + diff --git a/netfs/unittests/client.xml b/netfs/unittests/client.xml new file mode 100644 index 0000000..c159a24 --- /dev/null +++ b/netfs/unittests/client.xml @@ -0,0 +1,14 @@ +<?xml version="1.0"?> +<config> + <resources> + <resource> + <name>testvol</name> + <resource> + <export>unittest</export> + <endpoints> + <endpoint>tcp -h localhost -p 4000</endpoint> + </endpoints> + </resource> + </resource> + </resources> +</config> diff --git a/netfs/unittests/daemon.xml b/netfs/unittests/daemon.xml new file mode 100644 index 0000000..8bf58a9 --- /dev/null +++ b/netfs/unittests/daemon.xml @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<config> + <hosts> + <host> + <hostname>unittest</hostname> + <host> + <endpoint>tcp -p 4000:udp -p 10000</endpoint> + </host> + </host> + </hosts> + <exports> + <export> + <name>unittest</name> + <export> + <root>/usr/portage</root> + </export> + </export> + </exports> +</config> diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp new file mode 100644 index 0000000..b9a1836 --- /dev/null +++ b/netfs/unittests/testCore.cpp @@ -0,0 +1,95 @@ +#define BOOST_TEST_MODULE TestNetFSCore +#include <boost/test/unit_test.hpp> +#include <boost/filesystem/operations.hpp> +#include <Ice/ObjectAdapter.h> +#include <Ice/Service.h> +#include <daemon.h> +#include <service.h> +#include <fuseApp.h> +#include <boost/filesystem/path.hpp> + +#ifndef ROOT +#error "ROOT needs to be defined at compilation time" +#endif + +#define XSTR(s) STR(s) +#define STR(s) #s +const boost::filesystem::path RootDir(XSTR(ROOT)); + +class FuseMock : public NetFS::FuseApp { + public: + FuseMock(int & argc, char ** argv) : + NetFS::FuseApp(argc, argv) + { + ::memset(&context, 0, sizeof(fuse_context)); + } + + 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; + } + private: + fuse_context context; +}; + +char * argv[] = { + strdup((RootDir / "client.xml:testvol").string().c_str()), + strdup((RootDir / "test").string().c_str()) +}; + +class Core { + public: + Core() : + params({}), + ic(Ice::initialize(params)), + daemon(ic), + argc(2), + fuse(new FuseMock(argc, argv)) + { + ic->getProperties()->setProperty("NetFSD.ConfigPath", (RootDir / "daemon.xml").string()); + ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); + daemon.start("NetFSDaemonAdapter", ic, {}); + char ** a = argv; + fuse->runint(argc, a); + fuse->init(NULL); + } + + ~Core() + { + delete fuse; + ic->destroy(); + } + + protected: + Ice::StringSeq params; + Ice::CommunicatorPtr ic; + NetFSDaemon daemon; + int argc; + FuseAppBase * fuse; +}; + +BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) + +BOOST_AUTO_TEST_CASE ( daemonInitialised ) +{ + auto service = NetFS::ServicePrx::checkedCast(ic->stringToProxy("Service")); + BOOST_REQUIRE(service); + service->ice_ping(); +} + +BOOST_AUTO_TEST_CASE ( clientInitialised ) +{ + struct statvfs s; + fuse->statfs("/", &s); +} + +BOOST_AUTO_TEST_SUITE_END(); + |