diff options
Diffstat (limited to 'project2/ice/unittests/testClient.cpp')
| -rw-r--r-- | project2/ice/unittests/testClient.cpp | 98 |
1 files changed, 48 insertions, 50 deletions
diff --git a/project2/ice/unittests/testClient.cpp b/project2/ice/unittests/testClient.cpp index 55663a0..814a4d4 100644 --- a/project2/ice/unittests/testClient.cpp +++ b/project2/ice/unittests/testClient.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE Client #include <boost/test/unit_test.hpp> -#include <boost/filesystem/operations.hpp> +#include <filesystem> #include "iceClient.h" #include <Ice/ObjectAdapter.h> #include <Ice/Service.h> @@ -10,16 +10,15 @@ #include <scripts.h> #include <xmlScriptParser.h> #include <testScriptHost.h> -#include <scopeObject.h> +#include <scopeExit.h> #include <unittest.h> #include <unittestComplex.h> #include <testAppInstance.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 bindir = std::filesystem::canonical("/proc/self/exe").parent_path(); +const std::filesystem::path iceroot(XSTR(ROOT)); const auto headers = iceroot.parent_path().parent_path(); BOOST_TEST_DONT_PRINT_LOG_VALUE( ::UnitTestComplex::Date ); @@ -33,25 +32,25 @@ class Dummy : public UnitTest::SimpleInterface { UnitTest::SimplePtr SingleRow(const Ice::Current&) { - return new UnitTest::Simple { 3, "single" }; + return std::make_shared<UnitTest::Simple>( 3, "single" ); } UnitTest::Simples SomeRows(const Ice::Current&) { UnitTest::Simples rtn { - new UnitTest::Simple { 1, "test a" }, - new UnitTest::Simple { 2, "test b" } + std::make_shared<UnitTest::Simple>( 1, "test a" ), + std::make_shared<UnitTest::Simple>( 2, "test b" ) }; execCount += 1; return rtn; } - UnitTest::Simples SomeRowsParams(Ice::Int pi, const std::string & ps, const Ice::Current&) + 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" } + std::make_shared<UnitTest::Simple>( 0, "before" ), + std::make_shared<UnitTest::Simple>( pi, ps ), + std::make_shared<UnitTest::Simple>( 2, "after" ) }; execCount += 1; return rtn; @@ -62,7 +61,7 @@ class Dummy : public UnitTest::SimpleInterface { execCount += 1; } - void SomeTaskParams(Ice::Int a, const std::string & b, 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"); @@ -81,10 +80,10 @@ class DummyComplex : public UnitTestComplex::ComplexInterface { UnitTestComplex::ComplexPtr ComplexRow(const Ice::Current&) { - return new UnitTestComplex::Complex { 3, "single", new UnitTestComplex::Date { 1980, 7, 9, 1, 2, 3 } }; + return std::make_shared<UnitTestComplex::Complex>( 3, "single", std::make_shared<UnitTestComplex::Date>(1980, 7, 9, 1, 2, 3) ); } - void ComplexParam(Ice::Int a, const std::string & b, const UnitTestComplex::DatePtr & d, const Ice::Current&) + 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"); @@ -106,30 +105,29 @@ void commonTests(ExecContext * ec) { 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")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTestComplex-ComplexInterface-ComplexParam")); - BOOST_REQUIRE(ElementLoader::getFor("UnitTestComplex-ComplexInterface-ComplexRow")); + BOOST_REQUIRE(TaskFactory::get("UnitTest-SimpleInterface-SomeTask")); + BOOST_REQUIRE(TaskFactory::get("UnitTest-SimpleInterface-SomeTaskParams")); + BOOST_REQUIRE(RowSetFactory::get("UnitTest-SimpleInterface-SingleRow")); + BOOST_REQUIRE(RowSetFactory::get("UnitTest-SimpleInterface-SomeRows")); + BOOST_REQUIRE(RowSetFactory::get("UnitTest-SimpleInterface-SomeRowsParams")); + BOOST_REQUIRE(TaskFactory::get("UnitTestComplex-ComplexInterface-ComplexParam")); + BOOST_REQUIRE(RowSetFactory::get("UnitTestComplex-ComplexInterface-ComplexRow")); BOOST_TEST_CHECKPOINT("Load test script"); - ScriptReaderPtr r = new XmlScriptParser(iceroot / "testClient.xml"); + ScriptReaderPtr r = std::make_shared<XmlScriptParser>(iceroot / "testClient.xml"); BOOST_TEST_CHECKPOINT("Initialize ICE service"); - int paramCount = 0; - Ice::CommunicatorPtr ic = Ice::initialize(paramCount, NULL); + Ice::CommunicatorPtr ic = Ice::initialize(); 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")); + auto dummy = std::make_shared<Dummy>(); + auto dummyComplex = std::make_shared<DummyComplex>(); + adapter->add(dummy, Ice::stringToIdentity("testObject")); + adapter->add(dummyComplex, Ice::stringToIdentity("testObjectComplex")); adapter->activate(); - ScopeObject _([&ic]{ ic->destroy(); }); + AdHoc::ScopeExit _([&ic]{ ic->destroy(); }); BOOST_TEST_CHECKPOINT("Execute test script"); - boost::intrusive_ptr<TestScriptHost> sr = new TestScriptHost(r); + auto sr = std::make_shared<TestScriptHost>(r); BOOST_REQUIRE_EQUAL(dummy->execCount, 0); BOOST_REQUIRE_EQUAL(dummyComplex->execCount, 0); sr->process(ec); @@ -143,33 +141,33 @@ 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-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); + BOOST_REQUIRE_THROW(TaskFactory::get("UnitTest-SimpleInterface-SomeTask"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(TaskFactory::get("UnitTest-SimpleInterface-SomeTaskParams"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(RowSetFactory::get("UnitTest-SimpleInterface-SingleRow"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(RowSetFactory::get("UnitTest-SimpleInterface-SomeRows"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(RowSetFactory::get("UnitTest-SimpleInterface-SomeRowsParams"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(TaskFactory::get("UnitTestComplex-ComplexInterface-ComplexParam"), AdHoc::NoSuchPluginException); + BOOST_REQUIRE_THROW(RowSetFactory::get("UnitTestComplex-ComplexInterface-ComplexRow"), AdHoc::NoSuchPluginException); } -void test_client_run(ExecContext *, const boost::filesystem::path & tmpdir); +void test_client_run(ExecContext *, const std::filesystem::path & tmpdir); BOOST_FIXTURE_TEST_SUITE( Core, TestAppInstance ); BOOST_AUTO_TEST_CASE( test_client ) { - const boost::filesystem::path tmpdir = "/tmp/ut/project2.slice-client"; + const std::filesystem::path tmpdir = "/tmp/ut/project2.slice-client"; BOOST_TEST_CHECKPOINT("Clean up"); - boost::filesystem::remove_all(tmpdir); + std::filesystem::remove_all(tmpdir); test_client_run(this, tmpdir); test_client_run(this, tmpdir); - boost::filesystem::remove_all(tmpdir); + std::filesystem::remove_all(tmpdir); } BOOST_AUTO_TEST_SUITE_END(); -void test_client_run(ExecContext * ec, const boost::filesystem::path & tmpdir) +void test_client_run(ExecContext * ec, const std::filesystem::path & tmpdir) { BOOST_TEST_CHECKPOINT("Configure, compile, link, load"); TestOptionsSource::LoadTestOptions({ @@ -180,16 +178,16 @@ void test_client_run(ExecContext * ec, const boost::filesystem::path & tmpdir) { "ice.client.slicerclient", (iceroot / "unittestTypes.ice").string() }, { "ice.client.slicerclient", (iceroot / "unittest.ice").string() } }); - BOOST_REQUIRE(!boost::filesystem::exists(tmpdir / "unittest.so")); - 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")); + BOOST_REQUIRE(!std::filesystem::exists(tmpdir / "unittest.so")); + BOOST_REQUIRE(std::filesystem::exists(tmpdir / "unittest.client.so")); + BOOST_REQUIRE(!std::filesystem::exists(tmpdir / "unittestTypes.so")); + BOOST_REQUIRE(!std::filesystem::exists(tmpdir / "unittestTypes.client.so")); + BOOST_REQUIRE(!std::filesystem::exists(tmpdir / "unittestComplex.so")); + BOOST_REQUIRE(std::filesystem::exists(tmpdir / "unittestComplex.client.so")); commonTests(ec); TestOptionsSource::LoadTestOptions({ }); unloadTests(); - boost::filesystem::remove_all(tmpdir); + std::filesystem::remove_all(tmpdir); } |
