diff options
Diffstat (limited to 'project2/ice/unittests/testClient.cpp')
-rw-r--r-- | project2/ice/unittests/testClient.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/project2/ice/unittests/testClient.cpp b/project2/ice/unittests/testClient.cpp new file mode 100644 index 0000000..ee87f1b --- /dev/null +++ b/project2/ice/unittests/testClient.cpp @@ -0,0 +1,114 @@ +#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; + execCount += 1; + return rtn; + } + + UnitTest::Simples SomeRowsParams(Ice::Int, const std::string&, const Ice::Current&) + { + UnitTest::Simples rtn; + 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); +} + +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( compile_client_clientOnlySlicer ) +{ + const std::string tmpdir = "/tmp/ut/project2.slice/clientOnlySlicer"; + 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(); +} + |