diff options
Diffstat (limited to 'project2/ice/unittests/testClient.cpp')
-rw-r--r-- | project2/ice/unittests/testClient.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/project2/ice/unittests/testClient.cpp b/project2/ice/unittests/testClient.cpp new file mode 100644 index 0000000..e5d45b7 --- /dev/null +++ b/project2/ice/unittests/testClient.cpp @@ -0,0 +1,122 @@ +#define BOOST_TEST_MODULE Client +#include <boost/test/unit_test.hpp> +#include <boost/filesystem/operations.hpp> +#include "iceClient.h" +#include <testOptionsSource.h> +#include <task.h> +#include <exceptions.h> +#include <scripts.h> +#include <xmlScriptParser.h> +#include <testScriptHost.h> +#include <scopeObject.h> +#include <unittest.h> + +#define XSTR(s) STR(s) +#define STR(s) #s +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 Dummy : public UnitTest::SimpleInterface { + public: + Dummy() : + execCount(0) + { + } + + UnitTest::Simples SomeRows(const Ice::Current&) + { + UnitTest::Simples rtn { + new UnitTest::Simple { 1, "test a" }, + new UnitTest::Simple { 2, "test b" } + }; + execCount += 1; + return rtn; + } + + UnitTest::Simples SomeRowsParams(Ice::Int pi, const std::string & ps, const Ice::Current&) + { + UnitTest::Simples rtn { + new UnitTest::Simple { 0, "before" }, + new UnitTest::Simple { pi, ps }, + new UnitTest::Simple { 2, "after" } + }; + execCount += 1; + return rtn; + } + + void SomeTask(const Ice::Current&) + { + execCount += 1; + } + + void SomeTaskParams(Ice::Int, const std::string&, const Ice::Current&) + { + execCount += 1; + } + + unsigned int execCount; +}; + + +static +void +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-SomeRows")); + BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams")); + + BOOST_TEST_CHECKPOINT("Load test script"); + ScriptReaderPtr r = new XmlScriptParser(iceroot / "testClient.xml"); + + BOOST_TEST_CHECKPOINT("Initialize ICE service"); + int paramCount = 0; + Ice::CommunicatorPtr ic = Ice::initialize(paramCount, NULL); + auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12000"); + IceUtil::Handle<Dummy> dummy = new Dummy(); + adapter->add(dummy, ic->stringToIdentity("testObject")); + 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); + sr->process(NULL); + BOOST_REQUIRE_EQUAL(dummy->execCount, 4); + BOOST_REQUIRE_EQUAL(sr->GetPresenterData(), iceroot / "expected" / "clientPresenter.log"); +} + +static +void +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-SomeRows"), NotSupported); + BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams"), NotSupported); +} + +BOOST_AUTO_TEST_CASE( test_client ) +{ + const std::string tmpdir = "/tmp/ut/project2.slice-client"; + 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() }, + { "common.datasourceRoot", iceroot.string() }, + { "ice.compile.tmpdir", tmpdir }, + { "ice.compile.headers", headers.string() }, + { "ice.client.slicerclient", (iceroot / "unittest.ice").string() } + }); + commonTests(); + + TestOptionsSource::LoadTestOptions({ }); + unloadTests(); +} + |