summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-12-30 02:18:04 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2016-12-30 02:18:04 +0000
commitd2a0b38591a3d229d3b6b45ad679602dfea1ff77 (patch)
treecf6a89e0fbcdaf45f1e1a0e07c5db7f877b42462
parentChange return of setup function and service reference to be icetray specific (diff)
downloadicetray-0.1.1.tar.bz2
icetray-0.1.1.tar.xz
icetray-0.1.1.zip
Add method for replacing a named object added default adapter during service creation, such as for mocking out/stubbing in test casesicetray-0.1.1
-rw-r--r--icetray/dryice/dryice.cpp9
-rw-r--r--icetray/dryice/dryice.h2
-rw-r--r--icetray/unittests/Jamfile.jam17
-rw-r--r--icetray/unittests/testIceTrayReplace.cpp51
4 files changed, 79 insertions, 0 deletions
diff --git a/icetray/dryice/dryice.cpp b/icetray/dryice/dryice.cpp
index cdb11e1..744e0a6 100644
--- a/icetray/dryice/dryice.cpp
+++ b/icetray/dryice/dryice.cpp
@@ -3,6 +3,7 @@
#include <dlfcn.h>
#include <factory.h>
#include <Ice/Initialize.h>
+#include <Ice/ObjectAdapter.h>
namespace IceTray {
typedef IceTray::Service *(* SetupFunction)(Ice::CommunicatorPtr);
@@ -41,6 +42,14 @@ namespace IceTray {
}
}
+ void
+ DryIce::replace(const std::string & name, Ice::ObjectPtr replacement)
+ {
+ auto id = ic->stringToIdentity(name);
+ s->adp->remove(id);
+ s->adp->add(replacement, id);
+ }
+
DryIceClient::DryIceClient()
{
}
diff --git a/icetray/dryice/dryice.h b/icetray/dryice/dryice.h
index 998f76d..bd8443f 100644
--- a/icetray/dryice/dryice.h
+++ b/icetray/dryice/dryice.h
@@ -20,6 +20,8 @@ namespace IceTray {
friend class DryIceClient;
static DryIce * currentDryIce;
+ void replace(const std::string &, Ice::ObjectPtr);
+
Ice::CommunicatorPtr ic;
IceTray::ServicePtr s;
};
diff --git a/icetray/unittests/Jamfile.jam b/icetray/unittests/Jamfile.jam
index 4cd0977..aab3114 100644
--- a/icetray/unittests/Jamfile.jam
+++ b/icetray/unittests/Jamfile.jam
@@ -39,6 +39,23 @@ run
testIceTray ;
run
+ testIceTrayReplace.cpp
+ testIceTrayService.ice
+ testIceTrayServiceI.cpp
+ testIceTrayServiceTestSql.sql
+ subdir/some.sql
+ subdir/a/more.sql
+ :
+ testIceTrayService.sql
+ : :
+ <icetray.sql.namespace>TestIceTray::sql
+ <library>testCommon
+ <library>boost_filesystem
+ <library>dbpp-postgresql
+ :
+ testIceTrayReplace ;
+
+run
testDefaultPool.cpp
: : :
<library>testCommon
diff --git a/icetray/unittests/testIceTrayReplace.cpp b/icetray/unittests/testIceTrayReplace.cpp
new file mode 100644
index 0000000..afbab51
--- /dev/null
+++ b/icetray/unittests/testIceTrayReplace.cpp
@@ -0,0 +1,51 @@
+#define BOOST_TEST_MODULE TestIceTray
+#include <boost/test/unit_test.hpp>
+
+#include <dryice.h>
+#include <Ice/Communicator.h>
+#include "testIceTrayServiceI.h"
+
+#include <pq-mock.h>
+#include <definedDirs.h>
+
+namespace TestIceTray {
+ class DummyTestIceTrayServiceI : public TestIceTrayService {
+ public:
+ DummyTestIceTrayServiceI() { }
+
+ void method1(const Ice::Current &) override { }
+ void method2(Ice::Int, const std::string &, const Ice::Current &) override { }
+ };
+}
+
+class Service : public IceTray::DryIce {
+ public:
+ Service()
+ {
+ replace("test", new TestIceTray::DummyTestIceTrayServiceI());
+ }
+};
+
+BOOST_GLOBAL_FIXTURE( Service );
+
+class Client : public IceTray::DryIceClient {
+ public:
+ Client() :
+ p(getProxy<TestIceTray::TestIceTrayServicePrx>("test"))
+ {
+ }
+ TestIceTray::TestIceTrayServicePrx p;
+};
+
+BOOST_FIXTURE_TEST_SUITE( client, Client );
+
+BOOST_AUTO_TEST_CASE( services )
+{
+ BOOST_REQUIRE(p);
+ p->ice_ping();
+ p->method1();
+ p->method2(1, "test");
+}
+
+BOOST_AUTO_TEST_SUITE_END();
+