diff options
-rw-r--r-- | Jamroot.jam | 7 | ||||
-rw-r--r-- | project2/ice/Jamfile.jam | 2 | ||||
-rw-r--r-- | project2/ice/iceClient.h | 1 | ||||
-rw-r--r-- | project2/ice/iceConvert.h | 14 | ||||
-rw-r--r-- | project2/ice/iceModule.h | 1 | ||||
-rw-r--r-- | project2/ice/slice2Daemon.cpp | 10 | ||||
-rw-r--r-- | project2/ice/unittests/Jamfile.jam | 32 | ||||
-rw-r--r-- | project2/ice/unittests/conversions.cpp | 44 | ||||
-rw-r--r-- | project2/ice/unittests/data/unittest-data.xml | 5 | ||||
-rw-r--r-- | project2/ice/unittests/expected/clientPresenter.log | 9 | ||||
-rw-r--r-- | project2/ice/unittests/lib/testrows.xml | 7 | ||||
-rw-r--r-- | project2/ice/unittests/tasks/UnitTestComplex/ComplexInterface/ComplexParam.xml | 8 | ||||
-rw-r--r-- | project2/ice/unittests/testClient.cpp | 50 | ||||
-rw-r--r-- | project2/ice/unittests/testClient.xml | 6 | ||||
-rw-r--r-- | project2/ice/unittests/testClientCompile.cpp | 10 | ||||
-rw-r--r-- | project2/ice/unittests/testDaemon.cpp | 65 | ||||
-rw-r--r-- | project2/ice/unittests/testDaemonCompile.cpp | 5 | ||||
-rw-r--r-- | project2/ice/unittests/unittestComplex.ice | 30 | ||||
-rw-r--r-- | project2/ice/unittests/views/UnitTestComplex/ComplexInterface/ComplexRow.xml | 5 |
19 files changed, 272 insertions, 39 deletions
diff --git a/Jamroot.jam b/Jamroot.jam index 396dfd0..fe9fa3f 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -3,11 +3,16 @@ import slice ; using gcc : : [ os.environ CXX ] ; +variant component ; + project : requirements <variant>release:<cflags>"-std=c++0x" + <variant>release:<linkflags>"-Wl,-z,defs,--warn-once" <variant>debug:<cflags>"-W -Wall -Werror -Wwrite-strings -std=c++0x" - <linkflags>"-Wl,-z,defs,--warn-once" + <variant>debug:<linkflags>"-Wl,-z,defs,--warn-once" + <variant>component:<cflags>"-W -Wall -Werror -Wwrite-strings -std=c++0x -fPIC" + <variant>component:<linkflags>"-Wl,-z,lazy,--warn-once,-fPIC" ; diff --git a/project2/ice/Jamfile.jam b/project2/ice/Jamfile.jam index fe224b2..d90ec9f 100644 --- a/project2/ice/Jamfile.jam +++ b/project2/ice/Jamfile.jam @@ -75,5 +75,7 @@ lib p2ice : <library>slicer <library>IceUtil <library>boost_filesystem + : : + <linkflags>-rdynamic ; diff --git a/project2/ice/iceClient.h b/project2/ice/iceClient.h index 93042fd..1d198f1 100644 --- a/project2/ice/iceClient.h +++ b/project2/ice/iceClient.h @@ -3,7 +3,6 @@ #include <variables.h> #include <commonObjects.h> -#include <Ice/Ice.h> #include "iceDataSource.h" class IceClientBase { diff --git a/project2/ice/iceConvert.h b/project2/ice/iceConvert.h index 86e42d4..7d68b9f 100644 --- a/project2/ice/iceConvert.h +++ b/project2/ice/iceConvert.h @@ -2,8 +2,7 @@ #define ICECONVERT_H #include <variableType.h> -#include <boost/function.hpp> -#include <Ice/Ice.h> +#include <IceUtil/Optional.h> template <typename IceType> class IceConvert { @@ -32,16 +31,5 @@ class IceConvert<IceUtil::Optional<IceOptionalType>> { } }; -typedef boost::function<void(const std::string &)> IceEachDataMemberName; -typedef boost::function<void(VariableType)> IceEachDataMemberValue; - -template <typename RowType> -class IceType { - public: - static void CreateColumns(const IceEachDataMemberName & func); - static void ForEachDataMember(const IceInternal::Handle< RowType > & ptr, const IceEachDataMemberValue & func); - static void ForEachDataMember(const RowType & ptr, const IceEachDataMemberValue & func); -}; - #endif diff --git a/project2/ice/iceModule.h b/project2/ice/iceModule.h index 168e134..fcdd3e4 100644 --- a/project2/ice/iceModule.h +++ b/project2/ice/iceModule.h @@ -8,6 +8,7 @@ #include <safeMapFind.h> #include <boost/function.hpp> #include <slicer/modelParts.h> +#include "iceConvert.h" typedef std::map<std::string, VariableType> ParamMap; class IceDaemon; diff --git a/project2/ice/slice2Daemon.cpp b/project2/ice/slice2Daemon.cpp index 05be959..98a3883 100644 --- a/project2/ice/slice2Daemon.cpp +++ b/project2/ice/slice2Daemon.cpp @@ -88,14 +88,8 @@ Slice2Daemon::visitParameterMap(const Slice::OperationPtr & o) fprintf(code, "\t\t\t\tParamMap params {\n"); BOOST_FOREACH(const auto & p, o->parameters()) { Slice::StructPtr s = dynamic_cast<Slice::Struct *>(p->type().get()); - if (s) { - BOOST_FOREACH(const auto & m, s->dataMembers()) { - fprintf(code, "\t\t\t\t\t\t{\"%s.%s\", %s.%s},\n", p->name().c_str(), m->name().c_str(), p->name().c_str(), m->name().c_str()); - } - } - else { - fprintf(code, "\t\t\t\t\t\t{\"%s\", %s},\n", p->name().c_str(), p->name().c_str()); - } + fprintf(code, "\t\t\t\t\t\t{\"%s\", IceConvert< %s >::ToVariable(%s) },\n", + p->name().c_str(), Slice::typeToString(p->type()).c_str(), p->name().c_str()); } fprintf(code, "\t\t\t\t\t};\n"); } diff --git a/project2/ice/unittests/Jamfile.jam b/project2/ice/unittests/Jamfile.jam index ee31919..8e83b1c 100644 --- a/project2/ice/unittests/Jamfile.jam +++ b/project2/ice/unittests/Jamfile.jam @@ -1,25 +1,37 @@ import testing ; +lib unittestc : + unittestComplex.ice conversions.cpp + : + <slicer>yes + <library>..//slicer + <variant>component + <include>.. + <include>../../common + <include>../../lib + <include>../../../libmisc + <library>..//glibmm + : : + <include>. + ; + lib unittest : - [ glob *.ice ] + unittest.ice unittestTypes.ice : <slicer>no - <library>..//Ice - <library>..//IceUtil - <library>..//pthread + <library>..//slicer + <variant>component : : <include>. <library>..//pthread ; lib unittestr : - [ glob *.ice ] + unittest.ice unittestTypes.ice : <slicer>yes - <library>..//Ice <library>..//slicer - <library>..//IceUtil - <library>..//pthread + <variant>component : : <include>. <library>..//pthread @@ -49,6 +61,7 @@ unit-test testClient : <define>ROOT=\"$(me)\" <dependency>unittest.ice <library>unittestr + <library>unittestc <implicit-dependency>unittestr <library>..//p2iceclient <library>../../ut//p2ut @@ -81,6 +94,7 @@ unit-test testDaemon : <define>ROOT=\"$(me)\" <dependency>unittest.ice <library>unittestr + <library>unittestc <implicit-dependency>unittestr <library>..//p2icedaemon <library>../../ut//p2ut @@ -95,5 +109,7 @@ unit-test testDaemon : <dependency>tasks/UnitTest/SimpleInterface/SomeTaskParams.xml <dependency>views/UnitTest/SimpleInterface/SomeRows.xml <dependency>views/UnitTest/SimpleInterface/SomeRowsParams.xml + <dependency>views/UnitTestComplex/ComplexInterface/ComplexRow.xml + <dependency>tasks/UnitTestComplex/ComplexInterface/ComplexParam.xml ; diff --git a/project2/ice/unittests/conversions.cpp b/project2/ice/unittests/conversions.cpp new file mode 100644 index 0000000..e6be3f8 --- /dev/null +++ b/project2/ice/unittests/conversions.cpp @@ -0,0 +1,44 @@ +#include <unittestComplex.h> +#include "iceConvert.h" +#include <logger.h> + +namespace Slicer { + boost::posix_time::ptime + dateTimeToPTime(const UnitTestComplex::DatePtr & dt) + { + Logger()->messagebf(LOG_DEBUG, "%s", __PRETTY_FUNCTION__); + return boost::posix_time::ptime( + boost::gregorian::date(dt->year, dt->month, dt->day), + boost::posix_time::time_duration(dt->hours, dt->minutes, dt->seconds)); + } + + UnitTestComplex::DatePtr + ptimeToDateTime(const boost::posix_time::ptime & pt) + { + Logger()->messagebf(LOG_DEBUG, "%s", __PRETTY_FUNCTION__); + return new UnitTestComplex::Date { + pt.date().year(), + pt.date().month(), + pt.date().day(), + pt.time_of_day().hours(), + pt.time_of_day().minutes(), + pt.time_of_day().seconds() }; + } +} + +template<> +::UnitTestComplex::DatePtr +IceConvert< ::UnitTestComplex::DatePtr >::FromVariable(const VariableType & vt) +{ + Logger()->messagebf(LOG_DEBUG, "%s", __PRETTY_FUNCTION__); + return Slicer::ptimeToDateTime(vt); +} + +template<> +VariableType +IceConvert< ::UnitTestComplex::DatePtr >::ToVariable(const ::UnitTestComplex::DatePtr & d) +{ + Logger()->messagebf(LOG_DEBUG, "%s", __PRETTY_FUNCTION__); + return Slicer::dateTimeToPTime(d); +} + diff --git a/project2/ice/unittests/data/unittest-data.xml b/project2/ice/unittests/data/unittest-data.xml index d4b76df..9b4b474 100644 --- a/project2/ice/unittests/data/unittest-data.xml +++ b/project2/ice/unittests/data/unittest-data.xml @@ -1,5 +1,10 @@ <?xml version="1.0"?> <root> + <complex> + <a>4</a> + <b>complex</b> + <d>1980-07-09 01:02:03</d> + </complex> <record> <a>1</a> <b>first</b> diff --git a/project2/ice/unittests/expected/clientPresenter.log b/project2/ice/unittests/expected/clientPresenter.log index cebd0bf..6114459 100644 --- a/project2/ice/unittests/expected/clientPresenter.log +++ b/project2/ice/unittests/expected/clientPresenter.log @@ -35,3 +35,12 @@ addNamedValue: b=after finishRow finishArray: (1) finishRowSet +addNewRowSet: complex +addNewArray: rec(1) +addNewRow: rec +addNamedValue: a=3 +addNamedValue: b=single +addNamedValue: d=1980-Jul-09 01:02:03 +finishRow +finishArray: (1) +finishRowSet diff --git a/project2/ice/unittests/lib/testrows.xml b/project2/ice/unittests/lib/testrows.xml index 75578d6..e6d1af6 100644 --- a/project2/ice/unittests/lib/testrows.xml +++ b/project2/ice/unittests/lib/testrows.xml @@ -2,6 +2,13 @@ <p2:xpathrows xmlns:p2="http://project2.randomdan.homeip.net" name="filelist"> <url><root source="config" name="dataroot"/>/unittest-data.xml</url> <filterviews> + <complex root="/root/complex[1]"> + <fields> + <a xpath="a"/> + <b xpath="b"/> + <d xpath="d"/> + </fields> + </complex> <single root="/root/record[3]"> <fields> <a xpath="a"/> diff --git a/project2/ice/unittests/tasks/UnitTestComplex/ComplexInterface/ComplexParam.xml b/project2/ice/unittests/tasks/UnitTestComplex/ComplexInterface/ComplexParam.xml new file mode 100644 index 0000000..4d81c9e --- /dev/null +++ b/project2/ice/unittests/tasks/UnitTestComplex/ComplexInterface/ComplexParam.xml @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<block xmlns:p2="http://project2.randomdan.homeip.net" xmlns:xi="http://www.w3.org/2001/XInclude"> + <p2:DummyComplexParamTask> + <a source="param" name="a"/> + <b source="param" name="b"/> + <d source="param" name="d"/> + </p2:DummyComplexParamTask> +</block> diff --git a/project2/ice/unittests/testClient.cpp b/project2/ice/unittests/testClient.cpp index 4c89184..687ba73 100644 --- a/project2/ice/unittests/testClient.cpp +++ b/project2/ice/unittests/testClient.cpp @@ -2,6 +2,8 @@ #include <boost/test/unit_test.hpp> #include <boost/filesystem/operations.hpp> #include "iceClient.h" +#include <Ice/ObjectAdapter.h> +#include <Ice/Service.h> #include <testOptionsSource.h> #include <task.h> #include <exceptions.h> @@ -10,13 +12,17 @@ #include <testScriptHost.h> #include <scopeObject.h> #include <unittest.h> +#include <unittestComplex.h> #define XSTR(s) STR(s) #define STR(s) #s const auto bindir = boost::filesystem::canonical("/proc/self/exe").parent_path(); +const auto componentdir = bindir.parent_path() / "component"; const boost::filesystem::path iceroot(XSTR(ROOT)); const auto headers = iceroot.parent_path().parent_path(); +BOOST_TEST_DONT_PRINT_LOG_VALUE( ::UnitTestComplex::Date ); + class Dummy : public UnitTest::SimpleInterface { public: Dummy() : @@ -55,8 +61,38 @@ class Dummy : public UnitTest::SimpleInterface { execCount += 1; } - void SomeTaskParams(Ice::Int, const std::string&, const Ice::Current&) + void SomeTaskParams(Ice::Int a, const std::string & b, const Ice::Current&) + { + BOOST_REQUIRE_EQUAL(a, 1); + BOOST_REQUIRE_EQUAL(b, "first"); + execCount += 1; + } + + unsigned int execCount; +}; + +class DummyComplex : public UnitTestComplex::ComplexInterface { + public: + DummyComplex() : + execCount(0) + { + } + + UnitTestComplex::ComplexPtr ComplexRow(const Ice::Current&) + { + return new UnitTestComplex::Complex { 3, "single", new UnitTestComplex::Date { 1980, 7, 9, 1, 2, 3 } }; + } + + void ComplexParam(Ice::Int a, const std::string & b, const UnitTestComplex::DatePtr & d, const Ice::Current&) { + BOOST_REQUIRE_EQUAL(a, 1); + BOOST_REQUIRE_EQUAL(b, "first"); + BOOST_REQUIRE_EQUAL(d->year, 1980); + BOOST_REQUIRE_EQUAL(d->month, 7); + BOOST_REQUIRE_EQUAL(d->day, 9); + BOOST_REQUIRE_EQUAL(d->hours, 1); + BOOST_REQUIRE_EQUAL(d->minutes, 2); + BOOST_REQUIRE_EQUAL(d->seconds, 3); execCount += 1; } @@ -74,6 +110,8 @@ commonTests() BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SingleRow")); BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRows")); BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams")); + BOOST_REQUIRE(ElementLoader::getFor("UnitTestComplex-ComplexInterface-ComplexParam")); + BOOST_REQUIRE(ElementLoader::getFor("UnitTestComplex-ComplexInterface-ComplexRow")); BOOST_TEST_CHECKPOINT("Load test script"); ScriptReaderPtr r = new XmlScriptParser(iceroot / "testClient.xml"); @@ -83,15 +121,19 @@ commonTests() Ice::CommunicatorPtr ic = Ice::initialize(paramCount, NULL); auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12000"); IceUtil::Handle<Dummy> dummy = new Dummy(); + IceUtil::Handle<DummyComplex> dummyComplex = new DummyComplex(); adapter->add(dummy, ic->stringToIdentity("testObject")); + adapter->add(dummyComplex, ic->stringToIdentity("testObjectComplex")); adapter->activate(); ScopeObject _([&ic]{ ic->destroy(); }); BOOST_TEST_CHECKPOINT("Execute test script"); boost::intrusive_ptr<TestScriptHost> sr = new TestScriptHost(r); BOOST_REQUIRE_EQUAL(dummy->execCount, 0); + BOOST_REQUIRE_EQUAL(dummyComplex->execCount, 0); sr->process(NULL); BOOST_REQUIRE_EQUAL(dummy->execCount, 4); + BOOST_REQUIRE_EQUAL(dummyComplex->execCount, 1); BOOST_REQUIRE_EQUAL(sr->GetPresenterData(), iceroot / "expected" / "clientPresenter.log"); } @@ -105,6 +147,8 @@ unloadTests() BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SingleRow"), NotSupported); BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRows"), NotSupported); BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams"), NotSupported); + BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTestComplex-ComplexInterface-ComplexParam"), NotSupported); + BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTestComplex-ComplexInterface-ComplexRow"), NotSupported); } void test_client_run(const boost::filesystem::path & tmpdir); @@ -122,10 +166,10 @@ void test_client_run(const boost::filesystem::path & tmpdir) { BOOST_TEST_CHECKPOINT("Configure, compile, link, load"); TestOptionsSource::LoadTestOptions({ - { "library", (bindir / "slicer-yes" / "libunittestr.so").string() }, { "common.datasourceRoot", iceroot.string() }, { "ice.compile.tmpdir", tmpdir.string() }, { "ice.compile.headers", headers.string() }, + { "ice.client.slicerclient", (iceroot / "unittestComplex.ice").string() }, { "ice.client.slicerclient", (iceroot / "unittestTypes.ice").string() }, { "ice.client.slicerclient", (iceroot / "unittest.ice").string() } }); @@ -133,6 +177,8 @@ void test_client_run(const boost::filesystem::path & tmpdir) BOOST_REQUIRE(boost::filesystem::exists(tmpdir / "unittest.client.so")); BOOST_REQUIRE(!boost::filesystem::exists(tmpdir / "unittestTypes.so")); BOOST_REQUIRE(!boost::filesystem::exists(tmpdir / "unittestTypes.client.so")); + BOOST_REQUIRE(!boost::filesystem::exists(tmpdir / "unittestComplex.so")); + BOOST_REQUIRE(boost::filesystem::exists(tmpdir / "unittestComplex.client.so")); commonTests(); TestOptionsSource::LoadTestOptions({ }); diff --git a/project2/ice/unittests/testClient.xml b/project2/ice/unittests/testClient.xml index c8fb208..9a9d6f0 100644 --- a/project2/ice/unittests/testClient.xml +++ b/project2/ice/unittests/testClient.xml @@ -6,7 +6,13 @@ <p2:UnitTest-SimpleInterface-SingleRow name="row" datasource="unittest-ice-datasource" objectId="testObject" /> <p2:UnitTest-SimpleInterface-SomeRows name="rows" datasource="unittest-ice-datasource" objectId="testObject" /> <p2:UnitTest-SimpleInterface-SomeRowsParams name="rowsParams" datasource="unittest-ice-datasource" objectId="testObject" a="2" b="second" /> + + <p2:UnitTestComplex-ComplexInterface-ComplexParam datasource="unittest-ice-datasource" objectId="testObjectComplex" a="1" b="first" d="1980-07-09 01:02:03" /> + <p2:UnitTestComplex-ComplexInterface-ComplexRow name="complex" datasource="unittest-ice-datasource" objectId="testObjectComplex" /> + <p2:view source="row" recordname="rec" rootname="row" /> <p2:view source="rows" recordname="rec" rootname="somerows" /> <p2:view source="rowsParams" recordname="rec" rootname="somerowsparams" /> + + <p2:view source="complex" recordname="rec" rootname="complex" /> </test> diff --git a/project2/ice/unittests/testClientCompile.cpp b/project2/ice/unittests/testClientCompile.cpp index 213497e..2792ef0 100644 --- a/project2/ice/unittests/testClientCompile.cpp +++ b/project2/ice/unittests/testClientCompile.cpp @@ -12,6 +12,7 @@ #define XSTR(s) STR(s) #define STR(s) #s const auto bindir = boost::filesystem::canonical("/proc/self/exe").parent_path(); +const auto componentdir = bindir.parent_path() / "component"; const boost::filesystem::path iceroot(XSTR(ROOT)); const auto headers = iceroot.parent_path().parent_path(); @@ -22,6 +23,7 @@ commonTests() BOOST_TEST_CHECKPOINT("Verify loaded"); BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTask")); BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTaskParams")); + BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SingleRow")); BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRows")); BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams")); } @@ -33,12 +35,15 @@ unloadTests() BOOST_TEST_CHECKPOINT("Verify unloaded"); BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTask"), NotSupported); BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTaskParams"), NotSupported); + BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SingleRow"), NotSupported); BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRows"), NotSupported); BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams"), NotSupported); } BOOST_AUTO_TEST_CASE( compile_client_full ) { + TestOptionsSource::LoadTestOptions({ }); + const boost::filesystem::path tmpdir = "/tmp/ut/project2.slice-clientCompile/full"; BOOST_TEST_CHECKPOINT("Clean up"); boost::filesystem::remove_all(tmpdir); @@ -69,7 +74,7 @@ BOOST_AUTO_TEST_CASE( compile_client_clientOnly ) BOOST_TEST_CHECKPOINT("Configure, compile, link, load"); TestOptionsSource::LoadTestOptions({ - { "library", (bindir / "libunittest.so").string() }, + { "library", (componentdir / "libunittest.so").string() }, { "common.datasourceRoot", iceroot.string() }, { "ice.compile.tmpdir", tmpdir.string() }, { "ice.compile.headers", headers.string() }, @@ -88,13 +93,14 @@ BOOST_AUTO_TEST_CASE( compile_client_clientOnly ) BOOST_AUTO_TEST_CASE( compile_client_slicer ) { + TestOptionsSource::LoadTestOptions({ }); const boost::filesystem::path tmpdir = "/tmp/ut/project2.slice-clientCompile/slicer"; BOOST_TEST_CHECKPOINT("Clean up"); boost::filesystem::remove_all(tmpdir); BOOST_TEST_CHECKPOINT("Configure, compile, link, load"); TestOptionsSource::LoadTestOptions({ - { "library", (bindir / "slicer-yes" / "libunittestr.so").string() }, + { "library", (componentdir / "slicer-yes" / "libunittestr.so").string() }, { "common.datasourceRoot", iceroot.string() }, { "ice.compile.tmpdir", tmpdir.string() }, { "ice.compile.headers", headers.string() }, diff --git a/project2/ice/unittests/testDaemon.cpp b/project2/ice/unittests/testDaemon.cpp index e1b1b9e..1c53d6c 100644 --- a/project2/ice/unittests/testDaemon.cpp +++ b/project2/ice/unittests/testDaemon.cpp @@ -3,6 +3,7 @@ #include <boost/filesystem/operations.hpp> #include <testOptionsSource.h> #include <unittest.h> +#include <unittestComplex.h> #include <iceDaemon.h> #include <task.h> #include <logger.h> @@ -11,6 +12,7 @@ #define XSTR(s) STR(s) #define STR(s) #s const auto bindir = boost::filesystem::canonical("/proc/self/exe").parent_path(); +const auto componentdir = bindir.parent_path() / "component"; const boost::filesystem::path iceroot(XSTR(ROOT)); const auto headers = iceroot.parent_path().parent_path(); @@ -56,23 +58,60 @@ unsigned int DummyParamTask::execCount = 0; VariableType DummyParamTask::execA; VariableType DummyParamTask::execB; +class DummyComplexParamTask : public Task { + public: + DummyComplexParamTask(ScriptNodePtr n) : + SourceObject(n), + Task(n), + a(n, "a"), + b(n, "b"), + d(n, "d") + { } + void execute(ExecContext * ec) const + { + Logger()->messagebf(LOG_DEBUG, "%s: %d", __PRETTY_FUNCTION__, __LINE__); + execCount += 1; + execA = a(ec); + execB = b(ec); + execD = d(ec); + } + + const Variable a; + const Variable b; + const Variable d; + + static unsigned int execCount; + static VariableType execA; + static VariableType execB; + static VariableType execD; +}; +DECLARE_LOADER("DummyComplexParamTask", DummyComplexParamTask); +unsigned int DummyComplexParamTask::execCount = 0; +VariableType DummyComplexParamTask::execA; +VariableType DummyComplexParamTask::execB; +VariableType DummyComplexParamTask::execD; + static void commonTests() { BOOST_TEST_CHECKPOINT("Verify loaded"); BOOST_REQUIRE(IceDaemonAdapterHandlerLoader::getFor("UnitTest-SimpleInterface")); + BOOST_REQUIRE(IceDaemonAdapterHandlerLoader::getFor("UnitTestComplex-ComplexInterface")); 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"); + BOOST_TEST_CHECKPOINT("Create and verify proxies"); 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(); + UnitTestComplex::ComplexInterfacePrx sic = UnitTestComplex::ComplexInterfacePrx::checkedCast(ic->stringToProxy("UnitTestComplexComplexInterface:tcp -p 12024")); + BOOST_REQUIRE(sic); + sic->ice_ping(); BOOST_TEST_CHECKPOINT("Call view (single)"); auto single = si->SingleRow(); @@ -124,6 +163,26 @@ commonTests() BOOST_REQUIRE_EQUAL(2, DummyParamTask::execA.as<int>()); BOOST_REQUIRE_EQUAL("second", DummyParamTask::execB.as<std::string>()); + BOOST_TEST_CHECKPOINT("Call complex rows"); + auto comp = sic->ComplexRow(); + BOOST_REQUIRE_EQUAL(4, comp->a); + BOOST_REQUIRE_EQUAL("complex", comp->b); + BOOST_REQUIRE_EQUAL(1980, comp->d->year); + BOOST_REQUIRE_EQUAL(7, comp->d->month); + BOOST_REQUIRE_EQUAL(9, comp->d->day); + BOOST_REQUIRE_EQUAL(1, comp->d->hours); + BOOST_REQUIRE_EQUAL(2, comp->d->minutes); + BOOST_REQUIRE_EQUAL(3, comp->d->seconds); + + BOOST_TEST_CHECKPOINT("Call with complex param"); + BOOST_REQUIRE_EQUAL(0, DummyComplexParamTask::execCount); + sic->ComplexParam(4, "complex", new UnitTestComplex::Date { 1980, 7, 9, 1, 2, 3}); + BOOST_REQUIRE_EQUAL(1, DummyComplexParamTask::execCount); + BOOST_REQUIRE_EQUAL(4, DummyComplexParamTask::execA.as<int>()); + BOOST_REQUIRE_EQUAL("complex", DummyComplexParamTask::execB.as<std::string>()); + BOOST_REQUIRE_EQUAL(boost::posix_time::ptime(boost::gregorian::date(1980, 7, 9), boost::posix_time::time_duration(1, 2, 3)), + DummyComplexParamTask::execD.as<boost::posix_time::ptime>()); + id->shutdown(); run.join(); } @@ -146,12 +205,12 @@ BOOST_AUTO_TEST_CASE( test_daemon ) 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.string() }, { "ice.compile.headers", headers.string() }, + { "ice.daemon.slicerdaemon", (iceroot / "unittestComplex.ice").string() }, { "ice.daemon.slicerdaemon", (iceroot / "unittestTypes.ice").string() }, { "ice.daemon.slicerdaemon", (iceroot / "unittest.ice").string() } }); @@ -159,6 +218,8 @@ BOOST_AUTO_TEST_CASE( test_daemon ) BOOST_REQUIRE(boost::filesystem::exists(tmpdir / "unittest.daemon.so")); BOOST_REQUIRE(!boost::filesystem::exists(tmpdir / "unittestTypes.so")); BOOST_REQUIRE(!boost::filesystem::exists(tmpdir / "unittestTypes.daemon.so")); + BOOST_REQUIRE(!boost::filesystem::exists(tmpdir / "unittestComplex.so")); + BOOST_REQUIRE(boost::filesystem::exists(tmpdir / "unittestComplex.daemon.so")); commonTests(); TestOptionsSource::LoadTestOptions({ }); diff --git a/project2/ice/unittests/testDaemonCompile.cpp b/project2/ice/unittests/testDaemonCompile.cpp index ecbef13..0f6b4fa 100644 --- a/project2/ice/unittests/testDaemonCompile.cpp +++ b/project2/ice/unittests/testDaemonCompile.cpp @@ -8,6 +8,7 @@ #define XSTR(s) STR(s) #define STR(s) #s const auto bindir = boost::filesystem::canonical("/proc/self/exe").parent_path(); +const auto componentdir = bindir.parent_path() / "component"; const boost::filesystem::path iceroot(XSTR(ROOT)); const auto headers = iceroot.parent_path().parent_path(); @@ -58,7 +59,7 @@ BOOST_AUTO_TEST_CASE( compile_daemon_daemonOnly ) BOOST_TEST_CHECKPOINT("Configure, compile, link, load"); TestOptionsSource::LoadTestOptions({ - { "library", (bindir / "libunittest.so").string() }, + { "library", (componentdir / "libunittest.so").string() }, { "ice.compile.tmpdir", tmpdir.string() }, { "ice.compile.headers", headers.string() }, { "ice.daemon.slicedaemon", (iceroot / "unittestTypes.ice").string() }, @@ -82,7 +83,7 @@ BOOST_AUTO_TEST_CASE( compile_daemon_slicer ) BOOST_TEST_CHECKPOINT("Configure, compile, link, load"); TestOptionsSource::LoadTestOptions({ - { "library", (bindir / "slicer-yes" / "libunittestr.so").string() }, + { "library", (componentdir / "slicer-yes" / "libunittestr.so").string() }, { "ice.compile.tmpdir", tmpdir.string() }, { "ice.compile.headers", headers.string() }, { "ice.daemon.slicerdaemon", (iceroot / "unittestTypes.ice").string() }, diff --git a/project2/ice/unittests/unittestComplex.ice b/project2/ice/unittests/unittestComplex.ice new file mode 100644 index 0000000..a22b294 --- /dev/null +++ b/project2/ice/unittests/unittestComplex.ice @@ -0,0 +1,30 @@ +[["cpp:include:boost/date_time/posix_time/posix_time_types.hpp"]] + +module UnitTestComplex { + class Date { + int year; + int month; + int day; + int hours; + int minutes; + int seconds; + }; + + class Complex { + int a; + string b; + [ "slicer:conversion:boost.posix_time.ptime:ptimeToDateTime:dateTimeToPTime" ] + Date d; + }; + + interface ComplexInterface { + ["project2:rows"] + Complex ComplexRow(); + + ["project2:task"] + void ComplexParam(int a, string b, Date d); + }; + + sequence<Complex> Complexes; +}; + diff --git a/project2/ice/unittests/views/UnitTestComplex/ComplexInterface/ComplexRow.xml b/project2/ice/unittests/views/UnitTestComplex/ComplexInterface/ComplexRow.xml new file mode 100644 index 0000000..a5e7f42 --- /dev/null +++ b/project2/ice/unittests/views/UnitTestComplex/ComplexInterface/ComplexRow.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="complex"/> +</block> |