diff options
author | Dan Goodliffe <randomdan@riogrande.random.lan> | 2014-11-29 01:38:17 +0000 |
---|---|---|
committer | Dan Goodliffe <randomdan@riogrande.random.lan> | 2014-11-29 01:38:17 +0000 |
commit | 1d5bf41b6ecad150d76a98e6138b796c91f542df (patch) | |
tree | b4008ec78daa3664a67aebdcbe77946e767ebcec | |
parent | Merge remote-tracking branch 'origin/master' into slicer (diff) | |
download | project2-1d5bf41b6ecad150d76a98e6138b796c91f542df.tar.bz2 project2-1d5bf41b6ecad150d76a98e6138b796c91f542df.tar.xz project2-1d5bf41b6ecad150d76a98e6138b796c91f542df.zip |
Unit tests for daemon and fixes for highlighted issues
-rw-r--r-- | project2/ice/iceDaemon.cpp | 26 | ||||
-rw-r--r-- | project2/ice/iceViewSerializer.cpp | 15 | ||||
-rw-r--r-- | project2/ice/unittests/Jamfile.jam | 14 | ||||
-rw-r--r-- | project2/ice/unittests/data/unittest-data.xml | 19 | ||||
-rw-r--r-- | project2/ice/unittests/lib/testrows.xml | 19 | ||||
-rw-r--r-- | project2/ice/unittests/tasks/UnitTest/SimpleInterface/SomeTask.xml | 4 | ||||
-rw-r--r-- | project2/ice/unittests/tasks/UnitTest/SimpleInterface/SomeTaskParams.xml | 7 | ||||
-rw-r--r-- | project2/ice/unittests/testDaemon.cpp | 108 | ||||
-rw-r--r-- | project2/ice/unittests/views/UnitTest/SimpleInterface/SomeRows.xml | 5 | ||||
-rw-r--r-- | project2/ice/unittests/views/UnitTest/SimpleInterface/SomeRowsParams.xml | 5 |
10 files changed, 206 insertions, 16 deletions
diff --git a/project2/ice/iceDaemon.cpp b/project2/ice/iceDaemon.cpp index a8fb8c2..7f506d4 100644 --- a/project2/ice/iceDaemon.cpp +++ b/project2/ice/iceDaemon.cpp @@ -68,23 +68,24 @@ IceDaemon::shutdown() const void IceDaemon::run() const { - Logger()->messagebf(LOG_INFO, " %s starting...", __PRETTY_FUNCTION__); + Logger()->messagebf(LOG_DEBUG, " %s creating adapter %s [%s]...", __PRETTY_FUNCTION__, adapterName, adapterEndpoint); Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints(adapterName, adapterEndpoint); + + Logger()->messagebf(LOG_DEBUG, " %s installing servants...", __PRETTY_FUNCTION__); std::set<IceDaemonAdapterHandlerPtr> interfaces; InstanceSet<IceDaemonAdapterHandlerLoader>::OnAll([this, adapter, &interfaces](IceDaemonAdapterHandlerLoader * loader) { IceDaemonAdapterHandlerPtr interfacePtr = loader->create(); interfacePtr->add(adapter, this, ic); interfaces.insert(interfacePtr); }); + + Logger()->messagebf(LOG_DEBUG, " %s starting...", __PRETTY_FUNCTION__); adapter->activate(); + Logger()->messagebf(LOG_INFO, " %s running...", __PRETTY_FUNCTION__); - BOOST_FOREACH(const auto & interfacePtr, interfaces) { - interfacePtr->remove(adapter, ic); - } ic->waitForShutdown(); - Logger()->messagebf(LOG_INFO, " %s stopped...", __PRETTY_FUNCTION__); - Logger()->messagebf(LOG_INFO, "<<< %s", __PRETTY_FUNCTION__); + Logger()->messagebf(LOG_INFO, " %s stopped", __PRETTY_FUNCTION__); } class IceDaemonViewHost : public virtual CommonObjects, public virtual CheckHost { @@ -98,7 +99,9 @@ class IceDaemonViewHost : public virtual CommonObjects, public virtual CheckHost void executeView(RowSetPresenterPtr presenter, ExecContext * ec) const { loadScriptComponents(); + Logger()->messagebf(LOG_DEBUG, "%s: run %d checks", __PRETTY_FUNCTION__, CheckHost::checks.size()); runChecks(ec); + Logger()->messagebf(LOG_DEBUG, "%s: execute view", __PRETTY_FUNCTION__); view->execute(presenter.get(), ec); // Caches might open transactions BOOST_FOREACH(const CommonObjects::DataSources::value_type & ds, CommonObjects::datasources) { @@ -136,22 +139,25 @@ void IceDaemon::executeView(const std::string & name, Slicer::ModelPartPtr p, const ParamMap & pm) const { ScriptNodePtr s = ScriptReader::resolveScript(IceDaemon::viewRoot, name, false)->root(); - IceDaemonViewHost f(s); + boost::intrusive_ptr<IceDaemonViewHost> v = new IceDaemonViewHost(s); IceCallContext icc(pm); - f.executeView(new IceViewSerializer(p), &icc); + v->executeView(new IceViewSerializer(p), &icc); } class IceDaemonTaskHost : public TaskHost { public: IceDaemonTaskHost(ScriptNodePtr s) : SourceObject(s), + CommonObjects(s), CheckHost(s), TaskHost(s) { } void executeTask(ExecContext * ec) const { + Logger()->messagebf(LOG_DEBUG, "%s: run %d checks", __PRETTY_FUNCTION__, CheckHost::checks.size()); runChecks(ec); + Logger()->messagebf(LOG_DEBUG, "%s: execute %d tasks", __PRETTY_FUNCTION__, TaskHost::tasks.size()); execute(ec); } }; @@ -160,9 +166,9 @@ void IceDaemon::executeTask(const std::string & name, const ParamMap & pm) const { ScriptNodePtr s = ScriptReader::resolveScript(IceDaemon::taskRoot, name, false)->root(); - IceDaemonTaskHost t(s); + boost::intrusive_ptr<IceDaemonTaskHost> t = new IceDaemonTaskHost(s); IceCallContext icc(pm); - t.executeTask(&icc); + t->executeTask(&icc); } IceCompile::CPtr diff --git a/project2/ice/iceViewSerializer.cpp b/project2/ice/iceViewSerializer.cpp index 2a95f9f..b690224 100644 --- a/project2/ice/iceViewSerializer.cpp +++ b/project2/ice/iceViewSerializer.cpp @@ -1,5 +1,6 @@ #include "iceViewSerializer.h" #include <slicer/serializer.h> +#include <logger.h> using namespace Slicer; @@ -7,8 +8,8 @@ class Assign : public ValueSource, public TValueSource<boost::posix_time::ptime> { public: Assign(const VariableType & v) : vt(v) - { - } + { + } void set(boost::posix_time::ptime & v) const override { v = vt; } void set(bool & v) const override { v = vt; } @@ -37,6 +38,12 @@ IceViewSerializer::addNamedValue(const Glib::ustring & name, const VariableType if (field) { field->SetValue(new Assign(vt)); } + else { + Logger()->messagebf(LOG_INFO, "%s: Field not found", __PRETTY_FUNCTION__); + } + } + else { + Logger()->messagebf(LOG_WARNING, "%s: No active row", __PRETTY_FUNCTION__); } } @@ -44,11 +51,15 @@ void IceViewSerializer::addNewRow(const Glib::ustring & name) const { rowmpp = mpp->GetChild(name); + if (rowmpp) { + rowmpp->Create(); + } } void IceViewSerializer::finishRow() const { + rowmpp->Complete(); rowmpp = NULL; } diff --git a/project2/ice/unittests/Jamfile.jam b/project2/ice/unittests/Jamfile.jam index a793918..b23579d 100644 --- a/project2/ice/unittests/Jamfile.jam +++ b/project2/ice/unittests/Jamfile.jam @@ -7,6 +7,9 @@ lib unittest : <library>..//Ice <library>..//IceUtil <library>..//pthread + : : + <include>. + <library>..//pthread ; lib unittestr : @@ -19,6 +22,7 @@ lib unittestr : <library>..//pthread : : <include>. + <library>..//pthread ; path-constant me : . ; @@ -86,9 +90,11 @@ unit-test testDaemon : <library>..//Ice <library>..//IceUtil <library>..//boost_filesystem -#<dependency>testDaemon/task.xml -#<dependency>testDaemon/taskParams.xml -#<dependency>testDaemon/view.xml -#<dependency>testDaemon/viewParams.xml + <dependency>data/unittest-data.xml + <dependency>lib/testrows.xml + <dependency>tasks/UnitTest/SimpleInterface/SomeTask.xml + <dependency>tasks/UnitTest/SimpleInterface/SomeTaskParams.xml + <dependency>views/UnitTest/SimpleInterface/SomeRows.xml + <dependency>views/UnitTest/SimpleInterface/SomeRowsParams.xml ; diff --git a/project2/ice/unittests/data/unittest-data.xml b/project2/ice/unittests/data/unittest-data.xml new file mode 100644 index 0000000..d4b76df --- /dev/null +++ b/project2/ice/unittests/data/unittest-data.xml @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<root> + <record> + <a>1</a> + <b>first</b> + </record> + <record> + <a>2</a> + <b>second</b> + </record> + <record> + <a>1</a> + <b>third</b> + </record> + <record> + <a>2</a> + <b>first</b> + </record> +</root> diff --git a/project2/ice/unittests/lib/testrows.xml b/project2/ice/unittests/lib/testrows.xml new file mode 100644 index 0000000..876e311 --- /dev/null +++ b/project2/ice/unittests/lib/testrows.xml @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<p2:xpathrows xmlns:p2="http://project2.randomdan.homeip.net" name="filelist"> + <url><root source="config" name="dataroot"/>/unittest-data.xml</url> + <filterviews> + <default root="/root/record"> + <fields> + <a xpath="a"/> + <b xpath="b"/> + </fields> + </default> + <params> + <root>/root/record[a=<a source="param" name="a"/> or b='<b source="param" name="b"/>']</root> + <fields> + <a xpath="a"/> + <b xpath="b"/> + </fields> + </params> + </filterviews> +</p2:xpathrows> diff --git a/project2/ice/unittests/tasks/UnitTest/SimpleInterface/SomeTask.xml b/project2/ice/unittests/tasks/UnitTest/SimpleInterface/SomeTask.xml new file mode 100644 index 0000000..e042d7b --- /dev/null +++ b/project2/ice/unittests/tasks/UnitTest/SimpleInterface/SomeTask.xml @@ -0,0 +1,4 @@ +<?xml version="1.0"?> +<block xmlns:p2="http://project2.randomdan.homeip.net" xmlns:xi="http://www.w3.org/2001/XInclude"> + <p2:DummyTask /> +</block> diff --git a/project2/ice/unittests/tasks/UnitTest/SimpleInterface/SomeTaskParams.xml b/project2/ice/unittests/tasks/UnitTest/SimpleInterface/SomeTaskParams.xml new file mode 100644 index 0000000..67f1cc8 --- /dev/null +++ b/project2/ice/unittests/tasks/UnitTest/SimpleInterface/SomeTaskParams.xml @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<block xmlns:p2="http://project2.randomdan.homeip.net" xmlns:xi="http://www.w3.org/2001/XInclude"> + <p2:DummyParamTask> + <a source="param" name="a"/> + <b source="param" name="b"/> + </p2:DummyParamTask> +</block> diff --git a/project2/ice/unittests/testDaemon.cpp b/project2/ice/unittests/testDaemon.cpp index ce2630c..9e86a03 100644 --- a/project2/ice/unittests/testDaemon.cpp +++ b/project2/ice/unittests/testDaemon.cpp @@ -4,6 +4,9 @@ #include <testOptionsSource.h> #include <unittest.h> #include <iceDaemon.h> +#include <task.h> +#include <logger.h> +#include <variables.h> #define XSTR(s) STR(s) #define STR(s) #s @@ -11,12 +14,112 @@ const auto bindir = boost::filesystem::canonical("/proc/self/exe").parent_path() const boost::filesystem::path iceroot(XSTR(ROOT)); const auto headers = iceroot.parent_path().parent_path(); +class DummyTask : public Task { + public: + DummyTask(ScriptNodePtr n) : SourceObject(n), Task(n) { } + void execute(ExecContext *) const + { + Logger()->messagebf(LOG_DEBUG, "%s: %d", __PRETTY_FUNCTION__, __LINE__); + execCount += 1; + } + + static unsigned int execCount; +}; +DECLARE_LOADER("DummyTask", DummyTask); +unsigned int DummyTask::execCount = 0; + +class DummyParamTask : public Task { + public: + DummyParamTask(ScriptNodePtr n) : + SourceObject(n), + Task(n), + a(n, "a"), + b(n, "b") + { } + void execute(ExecContext * ec) const + { + Logger()->messagebf(LOG_DEBUG, "%s: %d", __PRETTY_FUNCTION__, __LINE__); + execCount += 1; + execA = a(ec); + execB = b(ec); + } + + const Variable a; + const Variable b; + + static unsigned int execCount; + static VariableType execA; + static VariableType execB; +}; +DECLARE_LOADER("DummyParamTask", DummyParamTask); +unsigned int DummyParamTask::execCount = 0; +VariableType DummyParamTask::execA; +VariableType DummyParamTask::execB; + static void commonTests() { BOOST_TEST_CHECKPOINT("Verify loaded"); BOOST_REQUIRE(IceDaemonAdapterHandlerLoader::getFor("UnitTest")); + + int dummy = 0; + BOOST_TEST_CHECKPOINT("Run daemon"); + DaemonPtr id = new IceDaemon(dummy, NULL); + std::thread run(&Daemon::run, id.get()); + + BOOST_TEST_CHECKPOINT("Create and verify proxy"); + Ice::CommunicatorPtr ic = Ice::initialize(dummy, NULL); + UnitTest::SimpleInterfacePrx si = UnitTest::SimpleInterfacePrx::checkedCast(ic->stringToProxy("UnitTestSimpleInterface:tcp -p 12024")); + BOOST_REQUIRE(si); + si->ice_ping(); + + BOOST_TEST_CHECKPOINT("Call view (no parameters)"); + auto rows = si->SomeRows(); + BOOST_REQUIRE_EQUAL(4, rows.size()); + BOOST_REQUIRE(rows[0]); + BOOST_REQUIRE(rows[1]); + BOOST_REQUIRE(rows[2]); + BOOST_REQUIRE(rows[3]); + BOOST_REQUIRE_EQUAL(1, rows[0]->a); + BOOST_REQUIRE_EQUAL("first", rows[0]->b); + BOOST_REQUIRE_EQUAL(2, rows[1]->a); + BOOST_REQUIRE_EQUAL("second", rows[1]->b); + BOOST_REQUIRE_EQUAL(1, rows[2]->a); + BOOST_REQUIRE_EQUAL("third", rows[2]->b); + BOOST_REQUIRE_EQUAL(2, rows[3]->a); + BOOST_REQUIRE_EQUAL("first", rows[3]->b); + + BOOST_TEST_CHECKPOINT("Call view (parameters)"); + auto paramRows = si->SomeRowsParams(1, "first"); + BOOST_REQUIRE_EQUAL(3, paramRows.size()); + BOOST_REQUIRE_EQUAL(1, paramRows[0]->a); + BOOST_REQUIRE_EQUAL("first", paramRows[0]->b); + BOOST_REQUIRE_EQUAL(1, paramRows[1]->a); + BOOST_REQUIRE_EQUAL("third", paramRows[1]->b); + BOOST_REQUIRE_EQUAL(2, paramRows[2]->a); + BOOST_REQUIRE_EQUAL("first", paramRows[2]->b); + + BOOST_TEST_CHECKPOINT("Call task (no parameters)"); + BOOST_REQUIRE_EQUAL(0, DummyTask::execCount); + si->SomeTask(); + BOOST_REQUIRE_EQUAL(1, DummyTask::execCount); + si->SomeTask(); + BOOST_REQUIRE_EQUAL(2, DummyTask::execCount); + + BOOST_TEST_CHECKPOINT("Call task (parameters)"); + BOOST_REQUIRE_EQUAL(0, DummyParamTask::execCount); + si->SomeTaskParams(1, "first"); + BOOST_REQUIRE_EQUAL(1, DummyParamTask::execCount); + BOOST_REQUIRE_EQUAL(1, DummyParamTask::execA.as<int>()); + BOOST_REQUIRE_EQUAL("first", DummyParamTask::execB.as<std::string>()); + si->SomeTaskParams(2, "second"); + BOOST_REQUIRE_EQUAL(2, DummyParamTask::execCount); + BOOST_REQUIRE_EQUAL(2, DummyParamTask::execA.as<int>()); + BOOST_REQUIRE_EQUAL("second", DummyParamTask::execB.as<std::string>()); + + id->shutdown(); + run.join(); } static @@ -34,8 +137,13 @@ BOOST_AUTO_TEST_CASE( test_daemon ) boost::filesystem::remove_all(tmpdir); BOOST_TEST_CHECKPOINT("Configure, compile, link, load"); + TestOptionsSource::LoadTestOptions({ }); TestOptionsSource::LoadTestOptions({ + { "application.dataroot", "file://" + (iceroot / "data").string() }, { "library", (bindir / "slicer-yes" / "libunittestr.so").string() }, + { "ice.daemon.adapterEndpoint", "tcp -p 12024" }, + { "ice.daemon.viewRoot", (iceroot / "views").string() }, + { "ice.daemon.taskRoot", (iceroot / "tasks").string() }, { "ice.compile.tmpdir", tmpdir }, { "ice.compile.headers", headers.string() }, { "ice.daemon.slicerdaemon", (iceroot / "unittest.ice").string() } diff --git a/project2/ice/unittests/views/UnitTest/SimpleInterface/SomeRows.xml b/project2/ice/unittests/views/UnitTest/SimpleInterface/SomeRows.xml new file mode 100644 index 0000000..b4950e3 --- /dev/null +++ b/project2/ice/unittests/views/UnitTest/SimpleInterface/SomeRows.xml @@ -0,0 +1,5 @@ +<?xml version="1.0"?> +<block xmlns:p2="http://project2.randomdan.homeip.net" xmlns:xi="http://www.w3.org/2001/XInclude"> + <xi:include href="../../../lib/testrows.xml"/> + <p2:flatview source="filelist" recordname="element" filter="default"/> +</block> diff --git a/project2/ice/unittests/views/UnitTest/SimpleInterface/SomeRowsParams.xml b/project2/ice/unittests/views/UnitTest/SimpleInterface/SomeRowsParams.xml new file mode 100644 index 0000000..d8a3f21 --- /dev/null +++ b/project2/ice/unittests/views/UnitTest/SimpleInterface/SomeRowsParams.xml @@ -0,0 +1,5 @@ +<?xml version="1.0"?> +<block xmlns:p2="http://project2.randomdan.homeip.net" xmlns:xi="http://www.w3.org/2001/XInclude"> + <xi:include href="../../../lib/testrows.xml"/> + <p2:flatview source="filelist" recordname="element" filter="params"/> +</block> |