From 2a4d99cc48cf4dea21bbd31a69760ddad0fcf994 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 12 Jul 2017 22:04:17 +0100 Subject: Service creation refactor Move service create into Service class Move assertions from DryIce runtime into explicit icebox interface test --- icetray/dryice/Jamfile.jam | 1 - icetray/dryice/dryice.cpp | 9 +-------- icetray/icetray/icetrayService.cpp | 10 ++++++++-- icetray/icetray/icetrayService.h | 1 + icetray/unittests/Jamfile.jam | 9 +++++++++ icetray/unittests/testIceBoxInterface.cpp | 19 +++++++++++++++++++ 6 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 icetray/unittests/testIceBoxInterface.cpp diff --git a/icetray/dryice/Jamfile.jam b/icetray/dryice/Jamfile.jam index 6df0569..0be9092 100644 --- a/icetray/dryice/Jamfile.jam +++ b/icetray/dryice/Jamfile.jam @@ -12,7 +12,6 @@ lib dryice : ..//pthread ..//boost_system ..//boost_thread - ..//dl ../icetray//icetray : : . diff --git a/icetray/dryice/dryice.cpp b/icetray/dryice/dryice.cpp index 744e0a6..5223ca6 100644 --- a/icetray/dryice/dryice.cpp +++ b/icetray/dryice/dryice.cpp @@ -1,22 +1,15 @@ #include "dryice.h" #include -#include #include #include #include namespace IceTray { - typedef IceTray::Service *(* SetupFunction)(Ice::CommunicatorPtr); - DryIce * DryIce::currentDryIce = nullptr; DryIce::DryIce(const Ice::StringSeq & cmdline) { BOOST_ASSERT(!currentDryIce); - void * i = dlsym(NULL, "createIceTrayService"); - BOOST_VERIFY(i); - auto sf = (SetupFunction)i; - BOOST_VERIFY(sf); Ice::StringSeq args; Ice::InitializationData id; id.properties = Ice::createProperties(); @@ -24,7 +17,7 @@ namespace IceTray { id.properties->setProperty("DryIce.PoolProvider", "MockPool"); id.properties->parseCommandLineOptions("", cmdline); ic = Ice::initialize(args, id); - s = sf(nullptr); + s = Service::create(ic); s->start("DryIce", ic, {}); currentDryIce = this; } diff --git a/icetray/icetray/icetrayService.cpp b/icetray/icetray/icetrayService.cpp index d785632..d206c57 100644 --- a/icetray/icetray/icetrayService.cpp +++ b/icetray/icetray/icetrayService.cpp @@ -26,6 +26,12 @@ namespace IceTray { return current; } + Service * + Service::create(Ice::CommunicatorPtr) + { + return IceTray::ServiceFactory::createNew("default"); + } + void Service::start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq & args) { adp = ic->createObjectAdapter(name); @@ -80,9 +86,9 @@ namespace IceTray { extern "C" { DLL_PUBLIC IceBox::Service * - createIceTrayService(Ice::CommunicatorPtr) + createIceTrayService(Ice::CommunicatorPtr ic) { - return IceTray::ServiceFactory::createNew("default"); + return IceTray::Service::create(ic); } } diff --git a/icetray/icetray/icetrayService.h b/icetray/icetray/icetrayService.h index 63ccd7e..228d198 100644 --- a/icetray/icetray/icetrayService.h +++ b/icetray/icetray/icetrayService.h @@ -23,6 +23,7 @@ namespace IceTray { DatabasePoolPtr getConnectionPool(const Ice::CommunicatorPtr & ic, const std::string & type, const std::string & prefix); static Service * getCurrent(); + static Service * create(Ice::CommunicatorPtr); private: void configureLoggers(const Ice::ObjectAdapterPtr &, const Ice::PropertiesPtr &); diff --git a/icetray/unittests/Jamfile.jam b/icetray/unittests/Jamfile.jam index 8fd034a..ea78320 100644 --- a/icetray/unittests/Jamfile.jam +++ b/icetray/unittests/Jamfile.jam @@ -56,9 +56,18 @@ run testCommon boost_filesystem dbpp-postgresql + ..//dl : testIceTray ; +run + testIceBoxInterface.cpp + : : : + testCommon + testService + ..//dl + ; + run testIceTrayReplace.cpp testIceTrayService.ice diff --git a/icetray/unittests/testIceBoxInterface.cpp b/icetray/unittests/testIceBoxInterface.cpp new file mode 100644 index 0000000..13febe0 --- /dev/null +++ b/icetray/unittests/testIceBoxInterface.cpp @@ -0,0 +1,19 @@ +#define BOOST_TEST_MODULE TestIceBoxInterface +#include + +#include +#include + +BOOST_AUTO_TEST_CASE( IceBoxInterface ) +{ + typedef IceTray::Service *(* SetupFunction)(Ice::CommunicatorPtr); + + void * i = dlsym(NULL, "createIceTrayService"); + BOOST_REQUIRE(i); + auto sf = (SetupFunction)i; + BOOST_REQUIRE(sf); + auto service = sf(nullptr); + BOOST_REQUIRE(service); + delete service; +} + -- cgit v1.2.3