diff options
author | Jose <jose@zeroc.com> | 2012-08-10 23:53:37 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2012-08-10 23:53:37 +0200 |
commit | 1d5c04bb8c0e786a717e36467e17f34bcc4f1d95 (patch) | |
tree | c1c91f034589260e97033131061d536ecfc2b9cb /cpp/test | |
parent | ICE-4702 - Poor hash algorithm (diff) | |
download | ice-1d5c04bb8c0e786a717e36467e17f34bcc4f1d95.tar.bz2 ice-1d5c04bb8c0e786a717e36467e17f34bcc4f1d95.tar.xz ice-1d5c04bb8c0e786a717e36467e17f34bcc4f1d95.zip |
C++11 ami lambda support
Diffstat (limited to 'cpp/test')
-rw-r--r-- | cpp/test/Ice/ami/AllTests.cpp | 437 | ||||
-rwxr-xr-x | cpp/test/Ice/custom/AllTests.cpp | 832 | ||||
-rw-r--r-- | cpp/test/Ice/dispatcher/AllTests.cpp | 4 | ||||
-rw-r--r-- | cpp/test/Ice/dispatcher/Client.cpp | 13 | ||||
-rw-r--r-- | cpp/test/Ice/dispatcher/Server.cpp | 9 | ||||
-rw-r--r-- | cpp/test/Ice/info/Makefile.mak | 2 | ||||
-rw-r--r-- | cpp/test/Ice/invoke/AllTests.cpp | 99 | ||||
-rw-r--r-- | cpp/test/Ice/operations/OnewaysNewAMI.cpp | 79 | ||||
-rw-r--r-- | cpp/test/Ice/operations/TwowaysNewAMI.cpp | 505 | ||||
-rw-r--r-- | cpp/test/IceUtil/unicode/Client.cpp | 8 |
10 files changed, 1968 insertions, 20 deletions
diff --git a/cpp/test/Ice/ami/AllTests.cpp b/cpp/test/Ice/ami/AllTests.cpp index 8fd66031174..4fdfb66dd44 100644 --- a/cpp/test/Ice/ami/AllTests.cpp +++ b/cpp/test/Ice/ami/AllTests.cpp @@ -945,6 +945,50 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 async callback... " << flush; + { + AsyncCallbackPtr cb = new AsyncCallback(); + Ice::Context ctx; + + p->begin_ice_isA(Test::TestIntf::ice_staticId(), [=](const ::Ice::AsyncResultPtr& r){ cb->isA(r); }); + cb->check(); + p->begin_ice_isA(Test::TestIntf::ice_staticId(), ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->isA(r); }); + cb->check(); + + p->begin_ice_ping([=](const ::Ice::AsyncResultPtr& r){ cb->ping(r); }); + cb->check(); + p->begin_ice_ping(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->ping(r); }); + cb->check(); + + p->begin_ice_id([=](const ::Ice::AsyncResultPtr& r){ cb->id(r); }); + cb->check(); + p->begin_ice_id(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->id(r); }); + cb->check(); + + p->begin_ice_ids([=](const ::Ice::AsyncResultPtr& r){ cb->ids(r); }); + cb->check(); + p->begin_ice_ids(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->ids(r); }); + cb->check(); + + p->begin_op([=](const ::Ice::AsyncResultPtr& r){ cb->op(r); }); + cb->check(); + p->begin_op(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->op(r); }); + cb->check(); + + p->begin_opWithResult([=](const ::Ice::AsyncResultPtr& r){ cb->opWithResult(r); }); + cb->check(); + p->begin_opWithResult(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->opWithResult(r); }); + cb->check(); + + p->begin_opWithUE([=](const ::Ice::AsyncResultPtr& r){ cb->opWithUE(r); }); + cb->check(); + p->begin_opWithUE(ctx, [=](const ::Ice::AsyncResultPtr& r){ cb->opWithUE(r); }); + cb->check(); + } + cout << "ok" << endl; +#endif cout << "testing response callback... " << flush; { @@ -1031,6 +1075,58 @@ allTests(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing C++11 response callback... " << flush; + { + ResponseCallbackPtr cb = new ResponseCallback(); + Ice::Context ctx; + + p->begin_ice_isA(Test::TestIntf::ice_staticId(), [=](bool is){ cb->isA(is); }); + cb->check(); + + p->begin_ice_isA(Test::TestIntf::ice_staticId(), ctx, [=](bool is){ cb->isA(is); }); + cb->check(); + + p->begin_ice_ping([=](){ cb->ping(); }); + cb->check(); + + p->begin_ice_ping(ctx, [=](){ cb->ping(); }); + cb->check(); + + + p->begin_ice_id([=](const string& id){ cb->id(id); }); + cb->check(); + + p->begin_ice_id(ctx, [=](const string& id){ cb->id(id); }); + cb->check(); + + p->begin_ice_ids([=](const Ice::StringSeq& ids){ cb->ids(ids); }); + cb->check(); + + p->begin_ice_ids(ctx, [=](const Ice::StringSeq& ids){ cb->ids(ids); }); + cb->check(); + + p->begin_op([=](){ cb->op(); }); + cb->check(); + + p->begin_op(ctx, [=](){ cb->op(); }); + cb->check(); + + p->begin_opWithResult([=](int ret){ cb->opWithResult(ret); }); + cb->check(); + + p->begin_opWithResult(ctx, [=](int ret){ cb->opWithResult(ret); }); + cb->check(); + + p->begin_opWithUE([](){ test(false); }, [=](const Ice::Exception& ex){ cb->opWithUE(ex); }); + cb->check(); + + p->begin_opWithUE(ctx, [](){ test(false); }, [=](const Ice::Exception& ex){ cb->opWithUE(ex); }); + cb->check(); + } + cout << "ok" << endl; +#endif + cout << "testing local exceptions... " << flush; { Test::TestIntfPrx indirect = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); @@ -1111,7 +1207,7 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; - + cout << "testing local exceptions with response callback... " << flush; { Test::TestIntfPrx i = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); @@ -1151,6 +1247,30 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing local exceptions with C++11 response callback... " << flush; + { + Test::TestIntfPrx i = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); + ExceptionCallbackPtr cb = new ExceptionCallback(); + + i->begin_ice_isA(Test::TestIntf::ice_staticId(), std::function<void (bool)>([](bool){ test(false); }), [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_ice_ping([](){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_ice_id([](const string&){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_ice_ids([](const Ice::StringSeq&){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_op([](){ test(false); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + } + cout << "ok" << endl; +#endif cout << "testing exception callback... " << flush; { @@ -1200,6 +1320,32 @@ allTests(const Ice::CommunicatorPtr& communicator) cbWC->check(); } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 exception callback... " << flush; + { + Test::TestIntfPrx i = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); + ExceptionCallbackPtr cb = new ExceptionCallback(); + + i->begin_ice_isA(Test::TestIntf::ice_staticId(), nullptr, [=](const Ice::Exception& ex){cb->ex(ex); }); + cb->check(); + + i->begin_op(nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + i->begin_opWithUE(nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + // Ensures no exception is called when response is received + p->begin_ice_isA(Test::TestIntf::ice_staticId(), nullptr, [=](const Ice::Exception& ex){ cb->noEx(ex); }); + p->begin_op(nullptr, [=](const Ice::Exception& ex){ cb->noEx(ex); }); + + // If response is a user exception, it should be received. + p->begin_opWithUE(nullptr, [=](const Ice::Exception& ex){ cb->opWithUE(ex); }); + cb->check(); + } + cout << "ok" << endl; +#endif cout << "testing sent callback... " << flush; { @@ -1280,6 +1426,79 @@ allTests(const Ice::CommunicatorPtr& communicator) } } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 sent callback... " << flush; + { + SentCallbackPtr cb = new SentCallback; + + p->begin_ice_isA("", [=](bool v){ cb->isA(v); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_ice_ping([=](){ cb->ping(); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_ice_id([=](const string& id){ cb->id(id); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_ice_ids([=](const Ice::StringSeq& ids){ cb->ids(ids); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + + p->begin_op([=](){ cb->op(); }, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_op([=](){ cb->op(); }, + nullptr, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + p->begin_op(nullptr, + [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + + vector<SentCallbackPtr> cbs; + Ice::ByteSeq seq; + seq.resize(1024); // Make sure the request doesn't compress too well. + for(Ice::ByteSeq::iterator q = seq.begin(); q != seq.end(); ++q) + { + *q = static_cast<Ice::Byte>(IceUtilInternal::random(255)); + } + testController->holdAdapter(); + try + { + cb = new SentCallback(); + while(p->begin_opWithPayload(seq, nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }, + [=](bool sent){ cb->sent(sent); })->sentSynchronously()) + { + cbs.push_back(cb); + cb = new SentCallback(); + } + } + catch(...) + { + testController->resumeAdapter(); + throw; + } + testController->resumeAdapter(); + for(vector<SentCallbackPtr>::const_iterator r = cbs.begin(); r != cbs.end(); r++) + { + (*r)->check(); + } + } + cout << "ok" << endl; +#endif cout << "testing illegal arguments... " << flush; { @@ -1427,6 +1646,32 @@ allTests(const Ice::CommunicatorPtr& communicator) } } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing unexpected exceptions from C++11 callback... " << flush; + { + Test::TestIntfPrx q = Test::TestIntfPrx::uncheckedCast(p->ice_adapterId("dummy")); + ThrowType throwEx[] = { LocalException, UserException, StandardException, OtherException }; + + for(int i = 0; i < 4; ++i) + { + ThrowerPtr cb = new Thrower(throwEx[i]); + + p->begin_op([=](){ cb->op(); }, [=](const Ice::Exception& ex){ cb->noEx(ex); }); + cb->check(); + + p->begin_op([=](){ cb->op(); }, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + + p->begin_op([=](){ cb->noOp(); }, [=](const Ice::Exception& ex){ cb->noEx(ex); }, [=](bool sent){ cb->sent(sent); }); + cb->check(); + + q->begin_op(nullptr, [=](const Ice::Exception& ex){ cb->ex(ex); }); + cb->check(); + } + } + cout << "ok" << endl; +#endif cout << "testing batch requests with proxy... " << flush; { @@ -1566,6 +1811,43 @@ allTests(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing C++11 batch requests with proxy... " << flush; + { + + { + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = b1->begin_ice_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(2)); + } + + { + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->ice_getConnection()->close(false); + FlushExCallbackPtr cb = new FlushExCallback(); + Ice::AsyncResultPtr r = b1->begin_ice_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(!r->isSent()); + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + } + cout << "ok" << endl; +#endif cout << "testing batch requests with connection... " << flush; { CookiePtr cookie = new Cookie(5); @@ -1702,6 +1984,48 @@ allTests(const Ice::CommunicatorPtr& communicator) } } cout << "ok" << endl; + +#ifdef ICE_CPP11 + cout << "testing C++11 batch requests with connection... " << flush; + { + { + // + // Without cookie. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = b1->ice_getConnection()->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(2)); + } + + { + // + // Exception without cookie. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->ice_getConnection()->close(false); + FlushExCallbackPtr cb = new FlushExCallback(); + Ice::AsyncResultPtr r = b1->ice_getConnection()->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(!r->isSent()); + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + } + cout << "ok" << endl; +#endif cout << "testing batch requests with communicator... " << flush; { @@ -1973,6 +2297,117 @@ allTests(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing C++11 batch requests with communicator... " << flush; + { + { + // + // Without cookie - 1 connection. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(2)); + } + + { + // + // Exception without cookie - 1 connection. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + b1->opBatch(); + b1->ice_getConnection()->close(false); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); // Exceptions are ignored! + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + + { + // + // 2 connections. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + Test::TestIntfPrx b2 = p->ice_connectionId("2")->ice_batchOneway(); + b2->ice_getConnection(); // Ensure connection is established. + b1->opBatch(); + b1->opBatch(); + b2->opBatch(); + b2->opBatch(); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); + test(r->isCompleted()); + test(p->waitForBatch(4)); + } + + { + // + // Exception - 2 connections - 1 failure. + // + // All connections should be flushed even if there are failures on some connections. + // Exceptions should not be reported. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + Test::TestIntfPrx b2 = p->ice_connectionId("2")->ice_batchOneway(); + b2->ice_getConnection(); // Ensure connection is established. + b1->opBatch(); + b2->opBatch(); + b1->ice_getConnection()->close(false); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); // Exceptions are ignored! + test(r->isCompleted()); + test(p->waitForBatch(1)); + } + + { + // + // Exception - 2 connections - 2 failures. + // + // The sent callback should be invoked even if all connections fail. + // + test(p->opBatchCount() == 0); + Test::TestIntfPrx b1 = p->ice_batchOneway(); + Test::TestIntfPrx b2 = p->ice_connectionId("2")->ice_batchOneway(); + b2->ice_getConnection(); // Ensure connection is established. + b1->opBatch(); + b2->opBatch(); + b1->ice_getConnection()->close(false); + b2->ice_getConnection()->close(false); + FlushCallbackPtr cb = new FlushCallback(); + Ice::AsyncResultPtr r = communicator->begin_flushBatchRequests( + [=](const Ice::Exception& ex){ cb->exception(ex);}, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + test(r->isSent()); // Exceptions are ignored! + test(r->isCompleted()); + test(p->opBatchCount() == 0); + } + } + cout << "ok" << endl; +#endif cout << "testing AsyncResult operations... " << flush; { { diff --git a/cpp/test/Ice/custom/AllTests.cpp b/cpp/test/Ice/custom/AllTests.cpp index a4c3983c919..9206e98c3ac 100755 --- a/cpp/test/Ice/custom/AllTests.cpp +++ b/cpp/test/Ice/custom/AllTests.cpp @@ -1448,6 +1448,23 @@ public: test(false); } } + + void throwExcept1(const Ice::Exception& ex, const wstring& in) + { + try + { + ex.ice_throw(); + } + catch(const Test1::WstringException& e) + { + test(e.reason == in); + called(); + } + catch(...) + { + test(false); + } + } void throwExcept2(const Ice::AsyncResultPtr& result) { @@ -1467,10 +1484,28 @@ public: test(false); } } + + void throwExcept2(const Ice::Exception& ex, const wstring& in) + { + try + { + ex.ice_throw(); + } + catch(const Test2::WstringException& e) + { + test(e.reason == in); + called(); + } + catch(...) + { + test(false); + } + } void - noEx(const Ice::Exception&, const InParamPtr&) + noEx(const Ice::Exception& ex, const InParamPtr&) { + cerr << ex << endl; test(false); } }; @@ -3519,6 +3554,724 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing alternate sequences with C++11 AMI callbacks... " << flush; + + { + Test::DoubleSeq in(5); + in[0] = 3.14; + in[1] = 1 / 3; + in[2] = 0.375; + in[3] = 4 / 3; + in[4] = -5.725; + Ice::Double inArray[5]; + for(int i = 0; i < 5; ++i) + { + inArray[i] = in[i]; + } + pair<const Ice::Double*, const Ice::Double*> inPair(inArray, inArray + 5); + + CallbackPtr cb = new Callback(); + t->begin_opDoubleArray(inPair, + [=](const pair<const Ice::Double*, const Ice::Double*>& p1, const pair<const Ice::Double*, const Ice::Double*>& p2) + { + cb->opDoubleArray(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::BoolSeq in(5); + in[0] = false; + in[1] = true; + in[2] = true; + in[3] = false; + in[4] = true; + bool inArray[5]; + for(int i = 0; i < 5; ++i) + { + inArray[i] = in[i]; + } + pair<const bool*, const bool*> inPair(inArray, inArray + 5); + + CallbackPtr cb = new Callback(); + t->begin_opBoolArray(inPair, + [=](const pair<const bool*, const bool*>& p1, const pair<const bool*, const bool*>& p2) + { + cb->opBoolArray(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Ice::Byte in[5]; + in[0] = '1'; + in[1] = '2'; + in[2] = '3'; + in[3] = '4'; + in[4] = '5'; + pair<const Ice::Byte*, const Ice::Byte*> inPair(in, in + 5); + + CallbackPtr cb = new Callback(); + t->begin_opByteArray(inPair, + [=](const pair<const Ice::Byte*, const Ice::Byte*>& p1, + const pair<const Ice::Byte*, const Ice::Byte*>& p2) + { + cb->opByteArray(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::VariableList in; + Test::Variable inArray[5]; + inArray[0].s = "These"; + in.push_back(inArray[0]); + inArray[1].s = "are"; + in.push_back(inArray[1]); + inArray[2].s = "five"; + in.push_back(inArray[2]); + inArray[3].s = "short"; + in.push_back(inArray[3]); + inArray[4].s = "strings."; + in.push_back(inArray[4]); + pair<const Test::Variable*, const Test::Variable*> inPair(inArray, inArray + 5); + + CallbackPtr cb = new Callback(); + t->begin_opVariableArray(inPair, + [=](const pair<const Test::Variable*, const Test::Variable*>& p1, + const pair<const Test::Variable*, const Test::Variable*>& p2) + { + cb->opVariableArray(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::BoolSeq in(5); + in[0] = false; + in[1] = true; + in[2] = true; + in[3] = false; + in[4] = true; + pair<Test::BoolSeq::const_iterator, Test::BoolSeq::const_iterator> inPair(in.begin(), in.end()); + + CallbackPtr cb = new Callback(); + t->begin_opBoolRange(inPair, + [=](const pair<Test::BoolSeq::const_iterator, Test::BoolSeq::const_iterator>& p1, + const pair<Test::BoolSeq::const_iterator, Test::BoolSeq::const_iterator>& p2) + { + cb->opBoolRange(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::ByteList in; + in.push_back('1'); + in.push_back('2'); + in.push_back('3'); + in.push_back('4'); + in.push_back('5'); + pair<Test::ByteList::const_iterator, Test::ByteList::const_iterator> inPair(in.begin(), in.end()); + + CallbackPtr cb = new Callback(); + t->begin_opByteRange(inPair, + [=](const pair<Test::ByteList::const_iterator, Test::ByteList::const_iterator>& p1, + const pair<Test::ByteList::const_iterator, Test::ByteList::const_iterator>& p2) + { + cb->opByteRange(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::VariableList in; + Test::Variable v; + v.s = "These"; + in.push_back(v); + v.s = "are"; + in.push_back(v); + v.s = "five"; + in.push_back(v); + v.s = "short"; + in.push_back(v); + v.s = "strings."; + in.push_back(v); + pair<Test::VariableList::const_iterator, Test::VariableList::const_iterator> inPair(in.begin(), in.end()); + + CallbackPtr cb = new Callback(); + t->begin_opVariableRange(inPair, + [=](const pair<Test::VariableList::const_iterator, Test::VariableList::const_iterator>& p1, + const pair<Test::VariableList::const_iterator, Test::VariableList::const_iterator>& p2) + { + cb->opVariableRange(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::BoolSeq in(5); + in[0] = false; + in[1] = true; + in[2] = true; + in[3] = false; + in[4] = true; + bool inArray[5]; + for(int i = 0; i < 5; ++i) + { + inArray[i] = in[i]; + } + pair<const bool*, const bool*> inPair(inArray, inArray + 5); + + CallbackPtr cb = new Callback(); + Test::Callback_TestIntf_opBoolRangeTypePtr callback = + Test::newCallback_TestIntf_opBoolRangeType(cb, &Callback::opBoolRangeType, &Callback::noEx); + t->begin_opBoolRangeType(inPair, callback, newInParam(inPair)); + cb->check(); + } + + { + Test::ByteList in; + in.push_back('1'); + in.push_back('2'); + in.push_back('3'); + in.push_back('4'); + in.push_back('5'); + pair<Test::ByteList::const_iterator, Test::ByteList::const_iterator> inPair(in.begin(), in.end()); + + CallbackPtr cb = new Callback(); + t->begin_opByteRangeType(inPair, + [=](const pair<Test::ByteList::const_iterator, Test::ByteList::const_iterator>& p1, + const pair<Test::ByteList::const_iterator, Test::ByteList::const_iterator>& p2) + { + cb->opByteRangeType(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + Test::VariableList in; + deque<Test::Variable> inSeq; + Test::Variable v; + v.s = "These"; + in.push_back(v); + inSeq.push_back(v); + v.s = "are"; + in.push_back(v); + inSeq.push_back(v); + v.s = "five"; + in.push_back(v); + inSeq.push_back(v); + v.s = "short"; + in.push_back(v); + inSeq.push_back(v); + v.s = "strings."; + in.push_back(v); + inSeq.push_back(v); + pair<deque<Test::Variable>::const_iterator, deque<Test::Variable>::const_iterator> inPair(inSeq.begin(), + inSeq.end()); + + CallbackPtr cb = new Callback(); + t->begin_opVariableRangeType(inPair, + [=](const pair<deque<Test::Variable>::const_iterator, deque<Test::Variable>::const_iterator>& p1, + const pair<deque<Test::Variable>::const_iterator, deque<Test::Variable>::const_iterator>& p2) + { + cb->opVariableRangeType(p1, p2, newInParam(inPair)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(inPair)); + }); + cb->check(); + } + + { + deque<bool> in(5); + in[0] = false; + in[1] = true; + in[2] = true; + in[3] = false; + in[4] = true; + + CallbackPtr cb = new Callback(); + t->begin_opBoolSeq(in, + [=](const deque<bool>& p1, const deque<bool>& p2) + { + cb->opBoolSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list<bool> in; + in.push_back(false); + in.push_back(true); + in.push_back(true); + in.push_back(false); + in.push_back(true); + + CallbackPtr cb = new Callback(); + t->begin_opBoolList(in, + [=](const list<bool>& p1, const list<bool>& p2) + { + cb->opBoolList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque< ::Ice::Byte> in(5); + in[0] = '1'; + in[1] = '2'; + in[2] = '3'; + in[3] = '4'; + in[4] = '5'; + + CallbackPtr cb = new Callback(); + t->begin_opByteSeq(in, + [=](const deque< ::Ice::Byte>& p1, const deque< ::Ice::Byte>& p2) + { + cb->opByteSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list< ::Ice::Byte> in; + in.push_back('1'); + in.push_back('2'); + in.push_back('3'); + in.push_back('4'); + in.push_back('5'); + + CallbackPtr cb = new Callback(); + t->begin_opByteList(in, + [=](const list< ::Ice::Byte>& p1, const list< ::Ice::Byte>& p2) + { + cb->opByteList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + MyByteSeq in(5); + int i = 0; + for(MyByteSeq::iterator p = in.begin(); p != in.end(); ++p) + { + *p = '1' + i++; + } + + CallbackPtr cb = new Callback(); + t->begin_opMyByteSeq(in, + [=](const MyByteSeq& p1, const MyByteSeq& p2) + { + cb->opMyByteSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque<string> in(5); + in[0] = "These"; + in[1] = "are"; + in[2] = "five"; + in[3] = "short"; + in[4] = "strings."; + + CallbackPtr cb = new Callback(); + t->begin_opStringSeq(in, + [=](const deque<string>& p1, const deque<string>& p2) + { + cb->opStringSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list<string> in; + in.push_back("These"); + in.push_back("are"); + in.push_back("five"); + in.push_back("short"); + in.push_back("strings."); + + CallbackPtr cb = new Callback(); + t->begin_opStringList(in, + [=](const list<string>& p1, const list<string>& p2) + { + cb->opStringList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque<Test::Fixed> in(5); + in[0].s = 1; + in[1].s = 2; + in[2].s = 3; + in[3].s = 4; + in[4].s = 5; + + CallbackPtr cb = new Callback(); + t->begin_opFixedSeq(in, + [=](const deque<Test::Fixed>& p1, const deque<Test::Fixed>& p2) + { + cb->opFixedSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list<Test::Fixed> in(5); + short num = 1; + for(list<Test::Fixed>::iterator p = in.begin(); p != in.end(); ++p) + { + (*p).s = num++; + } + + CallbackPtr cb = new Callback(); + t->begin_opFixedList(in, + [=](const list<Test::Fixed> p1, const list<Test::Fixed> p2) + { + cb->opFixedList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque<Test::Variable> in(5); + in[0].s = "These"; + in[1].s = "are"; + in[2].s = "five"; + in[3].s = "short"; + in[4].s = "strings."; + + CallbackPtr cb = new Callback(); + t->begin_opVariableSeq(in, + [=](const deque<Test::Variable>& p1, const deque<Test::Variable>& p2) + { + cb->opVariableSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list<Test::Variable> in; + Test::Variable v; + v.s = "These"; + in.push_back(v); + v.s = "are"; + in.push_back(v); + v.s = "five"; + in.push_back(v); + v.s = "short"; + in.push_back(v); + v.s = "strings."; + in.push_back(v); + + CallbackPtr cb = new Callback(); + t->begin_opVariableList(in, + [=](const list<Test::Variable>& p1, const list<Test::Variable>& p2) + { + cb->opVariableList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque<Test::StringStringDict> in(5); + in[0]["A"] = "a"; + in[1]["B"] = "b"; + in[2]["C"] = "c"; + in[3]["D"] = "d"; + in[4]["E"] = "e"; + + CallbackPtr cb = new Callback(); + t->begin_opStringStringDictSeq(in, + [=](const deque<Test::StringStringDict>& p1, const deque<Test::StringStringDict>& p2) + { + cb->opStringStringDictSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list<Test::StringStringDict> in; + Test::StringStringDict ssd; + ssd["A"] = "a"; + in.push_back(ssd); + ssd["B"] = "b"; + in.push_back(ssd); + ssd["C"] = "c"; + in.push_back(ssd); + ssd["D"] = "d"; + in.push_back(ssd); + ssd["E"] = "e"; + in.push_back(ssd); + + CallbackPtr cb = new Callback(); + t->begin_opStringStringDictList(in, + [=](const list<Test::StringStringDict>& p1, + const list<Test::StringStringDict>& p2) + { + cb->opStringStringDictList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque<Test::E> in(5); + in[0] = Test::E1; + in[1] = Test::E2; + in[2] = Test::E3; + in[3] = Test::E1; + in[4] = Test::E3; + + CallbackPtr cb = new Callback(); + t->begin_opESeq(in, + [=](const deque<Test::E>& p1, const deque<Test::E>& p2) + { + cb->opESeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list<Test::E> in; + in.push_back(Test::E1); + in.push_back(Test::E2); + in.push_back(Test::E3); + in.push_back(Test::E1); + in.push_back(Test::E3); + + CallbackPtr cb = new Callback(); + t->begin_opEList(in, + [=](const list<Test::E>& p1, const list<Test::E>& p2) + { + cb->opEList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque<Test::CPrx> in(5); + in[0] = Test::CPrx::uncheckedCast(communicator->stringToProxy("C1:default -p 12010 -t 10000")); + in[1] = Test::CPrx::uncheckedCast(communicator->stringToProxy("C2:default -p 12010 -t 10001")); + in[2] = Test::CPrx::uncheckedCast(communicator->stringToProxy("C3:default -p 12010 -t 10002")); + in[3] = Test::CPrx::uncheckedCast(communicator->stringToProxy("C4:default -p 12010 -t 10003")); + in[4] = Test::CPrx::uncheckedCast(communicator->stringToProxy("C5:default -p 12010 -t 10004")); + + CallbackPtr cb = new Callback(); + t->begin_opCPrxSeq(in, + [=](const deque<Test::CPrx>& p1, const deque<Test::CPrx>& p2) + { + cb->opCPrxSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list<Test::CPrx> in; + in.push_back(Test::CPrx::uncheckedCast(communicator->stringToProxy("C1:default -p 12010 -t 10000"))); + in.push_back(Test::CPrx::uncheckedCast(communicator->stringToProxy("C2:default -p 12010 -t 10001"))); + in.push_back(Test::CPrx::uncheckedCast(communicator->stringToProxy("C3:default -p 12010 -t 10002"))); + in.push_back(Test::CPrx::uncheckedCast(communicator->stringToProxy("C4:default -p 12010 -t 10003"))); + in.push_back(Test::CPrx::uncheckedCast(communicator->stringToProxy("C5:default -p 12010 -t 10004"))); + + CallbackPtr cb = new Callback(); + t->begin_opCPrxList(in, + [=](const list<Test::CPrx>& p1, const list<Test::CPrx>& p2) + { + cb->opCPrxList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + deque<Test::CPtr> in(5); + in[0] = new Test::C(); + in[1] = in[0]; + in[2] = in[0]; + in[3] = in[0]; + in[4] = in[0]; + + CallbackPtr cb = new Callback(); + t->begin_opCSeq(in, + [=](const deque<Test::CPtr>& p1, const deque<Test::CPtr>& p2) + { + cb->opCSeq(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + list<Test::CPtr> in; + in.push_back(new Test::C()); + in.push_back(new Test::C()); + in.push_back(new Test::C()); + in.push_back(new Test::C()); + in.push_back(new Test::C()); + + CallbackPtr cb = new Callback(); + t->begin_opCList(in, + [=](const list<Test::CPtr>& p1, const list<Test::CPtr>& p2) + { + cb->opCList(p1, p2, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + + { + Test::ByteSeq in; + in.push_back('1'); + in.push_back('2'); + in.push_back('3'); + in.push_back('4'); + + CallbackPtr cb = new Callback(); + t->begin_opOutArrayByteSeq(in, + [=](const ::std::pair<const ::Ice::Byte*, const ::Ice::Byte*>& p1) + { + cb->opOutArrayByteSeq(p1, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + + { + Test::ByteSeq in; + in.push_back('1'); + in.push_back('2'); + in.push_back('3'); + in.push_back('4'); + + CallbackPtr cb = new Callback(); + t->begin_opOutRangeByteSeq(in, + [=](const ::std::pair< ::Test::ByteSeq::const_iterator, ::Test::ByteSeq::const_iterator>& p1) + { + cb->opOutRangeByteSeq(p1, newInParam(in)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(in)); + }); + cb->check(); + } + cout << "ok" << endl; +#endif } cout << "testing class mapped structs ... " << flush; @@ -3568,6 +4321,25 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) cb->check(); } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing class mapped structs with C++11 AMI... " << flush; + { + CallbackPtr cb = new Callback(); + t->begin_opClassStruct(cs, csseq1, + [=](const ::Test::ClassStructPtr& p1, + const ::Test::ClassStructPtr& p2, + const ::Test::ClassStructSeq& p3) + { + cb->opClassStruct(p1, p2, p3, newInParam(make_pair(cs, csseq1))); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(make_pair(cs, csseq1))); + }); + cb->check(); + } + cout << "ok" << endl; +#endif } cout << "testing wstring... " << flush; @@ -3622,6 +4394,21 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) newInParam(wstr)); cb->check(); } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback(); + wsc1->begin_opString(wstr, + [=](const wstring& p1, const wstring& p2) + { + cb->opString(p1, p2, newInParam(wstr)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(wstr)); + }); + cb->check(); + } +#endif } ret = wsc2->opString(wstr, out); @@ -3648,6 +4435,27 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) &Callback::noEx), newInParam(wstr)); cb->check(); } + { + CallbackPtr cb = new Callback(); + wsc2->begin_opString(wstr, Test2::newCallback_WstringClass_opString(cb, &Callback::opString, + &Callback::noEx), newInParam(wstr)); + cb->check(); + } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback(); + wsc2->begin_opString(wstr, + [=](const wstring& p1, const wstring& p2) + { + cb->opString(p1, p2, newInParam(wstr)); + }, + [=](const Ice::Exception& ex) + { + cb->noEx(ex, newInParam(wstr)); + }); + cb->check(); + } +#endif } Test1::WstringStruct wss1; @@ -3697,6 +4505,17 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) wsc1->begin_throwExcept(wstr, Ice::newCallback(cb, &Callback::throwExcept1), newInParam(wstr)); cb->check(); } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback(); + wsc1->begin_throwExcept(wstr, nullptr, + [=](const Ice::Exception& ex) + { + cb->throwExcept1(ex, wstr); + }); + cb->check(); + } +#endif } try @@ -3732,6 +4551,17 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) wsc2->begin_throwExcept(wstr, Ice::newCallback(cb, &Callback::throwExcept2), newInParam(wstr)); cb->check(); } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback(); + wsc2->begin_throwExcept(wstr, nullptr, + [=](const Ice::Exception& ex) + { + cb->throwExcept2(ex, wstr); + }); + cb->check(); + } +#endif } cout << "ok" << endl; diff --git a/cpp/test/Ice/dispatcher/AllTests.cpp b/cpp/test/Ice/dispatcher/AllTests.cpp index 48af9c3754d..9bb283b6a07 100644 --- a/cpp/test/Ice/dispatcher/AllTests.cpp +++ b/cpp/test/Ice/dispatcher/AllTests.cpp @@ -104,7 +104,11 @@ allTests(const Ice::CommunicatorPtr& communicator) Test::TestIntfControllerPrx testController = Test::TestIntfControllerPrx::uncheckedCast(obj); +#ifdef ICE_CPP11 + cout << "testing C++11 dispatcher... " << flush; +#else cout << "testing dispatcher... " << flush; +#endif { p->op(); diff --git a/cpp/test/Ice/dispatcher/Client.cpp b/cpp/test/Ice/dispatcher/Client.cpp index da86ee480af..8060023eeac 100644 --- a/cpp/test/Ice/dispatcher/Client.cpp +++ b/cpp/test/Ice/dispatcher/Client.cpp @@ -29,13 +29,24 @@ main(int argc, char* argv[]) { int status; Ice::CommunicatorPtr communicator; - + try { Ice::InitializationData initData; initData.properties = Ice::createProperties(argc, argv); +#ifdef ICE_CPP11 + Ice::DispatcherPtr dispatcher = new Dispatcher(); + initData.dispatcher = Ice::newDispatcher( + [=](const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr& conn) + { + dispatcher->dispatch(call, conn); + }); +#else initData.dispatcher = new Dispatcher(); +#endif communicator = Ice::initialize(argc, argv, initData); + + status = run(argc, argv, communicator); } catch(const Ice::Exception& ex) diff --git a/cpp/test/Ice/dispatcher/Server.cpp b/cpp/test/Ice/dispatcher/Server.cpp index e517301982b..53e4ce4a359 100644 --- a/cpp/test/Ice/dispatcher/Server.cpp +++ b/cpp/test/Ice/dispatcher/Server.cpp @@ -50,7 +50,16 @@ main(int argc, char* argv[]) { Ice::InitializationData initData; initData.properties = Ice::createProperties(argc, argv); +#ifdef ICE_CPP11 + Ice::DispatcherPtr dispatcher = new Dispatcher(); + initData.dispatcher = Ice::newDispatcher( + [=](const Ice::DispatcherCallPtr& call, const Ice::ConnectionPtr& conn) + { + dispatcher->dispatch(call, conn); + }); +#else initData.dispatcher = new Dispatcher(); +#endif communicator = Ice::initialize(argc, argv, initData); status = run(argc, argv, communicator); } diff --git a/cpp/test/Ice/info/Makefile.mak b/cpp/test/Ice/info/Makefile.mak index 683d8b5d0b8..bfafa223556 100644 --- a/cpp/test/Ice/info/Makefile.mak +++ b/cpp/test/Ice/info/Makefile.mak @@ -40,7 +40,7 @@ CPPFLAGS = -I. -I../../include $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN !if "$(WINRT)" != "yes"
LD_TESTFLAGS = $(LD_EXEFLAGS) $(SETARGV)
-LIBS = $(LIBS) icessl$(LIBSUFFIX).lib
+LIBS = $(LIBS) icessl$(LIBSUFFIX).lib
!else
LD_TESTFLAGS = $(LD_DLLFLAGS) /export:dllMain
!endif
diff --git a/cpp/test/Ice/invoke/AllTests.cpp b/cpp/test/Ice/invoke/AllTests.cpp index b51ab5469a7..5b8cde9fc4b 100644 --- a/cpp/test/Ice/invoke/AllTests.cpp +++ b/cpp/test/Ice/invoke/AllTests.cpp @@ -155,6 +155,26 @@ public: test(false); } } + + void opStringPairNC(bool ok, const pair<const Ice::Byte*, const Ice::Byte*>& outParams) + { + if(ok) + { + Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); + in->startEncapsulation(); + string s; + in->read(s); + test(s == testString); + in->read(s); + test(s == testString); + in->endEncapsulation(); + called(); + } + else + { + test(false); + } + } void opStringWC(bool ok, const Ice::ByteSeq& outParams, const CookiePtr& cookie) { @@ -201,6 +221,32 @@ public: } } } + + void opExceptionPairNC(bool ok, const pair<const Ice::Byte*, const Ice::Byte*>& outParams) + { + if(ok) + { + test(false); + } + else + { + Ice::InputStreamPtr in = Ice::createInputStream(_communicator, outParams); + in->startEncapsulation(); + try + { + in->throwException(); + } + catch(const Test::MyException&) + { + in->endEncapsulation(); + called(); + } + catch(...) + { + test(false); + } + } + } void opExceptionWC(bool ok, const Ice::ByteSeq& outParams, const CookiePtr& cookie) { @@ -479,6 +525,59 @@ allTests(const Ice::CommunicatorPtr& communicator) } cout << "ok" << endl; +#ifdef ICE_CPP11 + cout << "testing asynchronous ice_invoke with C++11 style callbacks... " << flush; + + { + Ice::ByteSeq inEncaps, outEncaps; + Ice::OutputStreamPtr out = Ice::createOutputStream(communicator); + out->startEncapsulation(); + out->write(testString); + out->endEncapsulation(); + out->finished(inEncaps); + + CallbackPtr cb = new Callback(communicator, false); + Ice::Context ctx; + cl->begin_ice_invoke("opString", Ice::Normal, inEncaps, ctx, + [=](bool ret, const vector< ::Ice::Byte>& args) + { + cb->opStringNC(ret, args); + }); + cb->check(); + + cb = new Callback(communicator, false); + pair<const ::Ice::Byte*, const ::Ice::Byte*> inPair(&inEncaps[0], &inEncaps[0] + inEncaps.size()); + cl->begin_ice_invoke("opString", Ice::Normal, inPair, + [=](bool ret, const pair<const Ice::Byte*, const Ice::Byte*>& args) + { + cb->opStringPairNC(ret, args); + }); + cb->check(); + } + + { + Ice::ByteSeq inEncaps, outEncaps; + CallbackPtr cb = new Callback(communicator, false); + cl->begin_ice_invoke("opException", Ice::Normal, inEncaps, + [=](bool ret, const vector< ::Ice::Byte>& args) + { + cb->opExceptionNC(ret, args); + } + ); + cb->check(); + + pair<const ::Ice::Byte*, const ::Ice::Byte*> inPair(static_cast< ::Ice::Byte*>(0), static_cast< ::Ice::Byte*>(0)); + cb = new Callback(communicator, false); + cl->begin_ice_invoke("opException", Ice::Normal, inPair, + [=](bool ret, const pair<const Ice::Byte*, const Ice::Byte*>& args) + { + cb->opExceptionPairNC(ret, args); + }); + cb->check(); + } + + cout << "ok" << endl; +#endif return cl; } diff --git a/cpp/test/Ice/operations/OnewaysNewAMI.cpp b/cpp/test/Ice/operations/OnewaysNewAMI.cpp index 21127c66d3c..e82afcab5f9 100644 --- a/cpp/test/Ice/operations/OnewaysNewAMI.cpp +++ b/cpp/test/Ice/operations/OnewaysNewAMI.cpp @@ -85,7 +85,7 @@ onewaysNewAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& Test::MyClassPrx p = Test::MyClassPrx::uncheckedCast(proxy->ice_oneway()); { - CallbackPtr cb = new Callback; + CallbackPtr cb = new Callback; Ice::Callback_Object_ice_pingPtr callback = Ice::newCallback_Object_ice_ping(cb, &Callback::noException, &Callback::sent); p->begin_ice_ping(callback); @@ -159,4 +159,81 @@ onewaysNewAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& { } } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback; + p->begin_ice_ping(nullptr, + [=](const Ice::Exception& ex){ cb->noException(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + } + + { + try + { + p->begin_ice_isA(Test::MyClass::ice_staticId(), [=](bool){ test(false); }); + test(false); + } + catch(const IceUtil::IllegalArgumentException&) + { + } + } + + { + try + { + p->begin_ice_id([=](const string&){ test(false); }); + test(false); + } + catch(const IceUtil::IllegalArgumentException&) + { + } + } + + { + try + { + p->begin_ice_ids([=](const Ice::StringSeq&){ test(false); }); + test(false); + } + catch(const IceUtil::IllegalArgumentException&) + { + } + } + + { + CallbackPtr cb = new Callback; + p->begin_opVoid(nullptr, + [=](const Ice::Exception& ex){ cb->noException(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opIdempotent(nullptr, + [=](const Ice::Exception& ex){ cb->noException(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opNonmutating(nullptr, + [=](const Ice::Exception& ex){ cb->noException(ex); }, + [=](bool sent){ cb->sent(sent); }); + cb->check(); + } + + { + try + { + p->begin_opByte(Ice::Byte(0xff), Ice::Byte(0x0f), [=](const Ice::Byte&, const Ice::Byte&){ test(false); }); + test(false); + } + catch(const IceUtil::IllegalArgumentException&) + { + } + } +#endif } diff --git a/cpp/test/Ice/operations/TwowaysNewAMI.cpp b/cpp/test/Ice/operations/TwowaysNewAMI.cpp index 0b156c55651..212bc12d6fd 100644 --- a/cpp/test/Ice/operations/TwowaysNewAMI.cpp +++ b/cpp/test/Ice/operations/TwowaysNewAMI.cpp @@ -556,8 +556,6 @@ twowaysNewAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& } { - Ice::Double d = 1278312346.0 / 13.0; - Test::DoubleS ds(5, d); CallbackPtr cb = new Callback; Test::Callback_MyClass_opBytePtr callback = Test::newCallback_MyClass_opByte(cb, &Callback::opByte, @@ -566,16 +564,6 @@ twowaysNewAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& cb->check(); } - - { - CallbackPtr cb = new Callback; - Test::Callback_MyClass_opVoidPtr callback = Test::newCallback_MyClass_opVoid(cb, - &Callback::opVoid, - &Callback::exCB); - p->begin_opVoid(callback); - cb->check(); - } - { CallbackPtr cb = new Callback; Test::Callback_MyClass_opBoolPtr callback = Test::newCallback_MyClass_opBool(cb, @@ -1067,4 +1055,497 @@ twowaysNewAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& derived->begin_opDerived(callback); cb->check(); } +#ifdef ICE_CPP11 + { + CallbackPtr cb = new Callback; + p->begin_ice_ping([=](){ cb->ping(); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_ice_isA(Test::MyClass::ice_staticId(), [=](bool isA){ cb->isA(isA); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_ice_id([=](const string& id){ cb->id(id); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_ice_ids([=](const Ice::StringSeq& ids){ cb->ids(ids); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opVoid([=](){ cb->opVoid(); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opByte(Ice::Byte(0xff), Ice::Byte(0x0f), + [=](const Ice::Byte& p1, const Ice::Byte& p2){ cb->opByte(p1, p2); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Test::Callback_MyClass_opBoolPtr callback = Test::newCallback_MyClass_opBool(cb, + &Callback::opBool, + &Callback::exCB); + p->begin_opBool(true, false, [=](bool p1, bool p2){ cb->opBool(p1, p2); }, [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opShortIntLong(10, 11, 12, + [=](Ice::Long p1, Ice::Short p2, Ice::Int p3, Ice::Long p4){ cb->opShortIntLong(p1, p2, p3, p4); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opFloatDouble(Ice::Float(3.14), Ice::Double(1.1E10), + [=](Ice::Double p1, Ice::Float p2, Ice::Double p3){ cb->opFloatDouble(p1, p2, p3); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opString("hello", "world", + [=](const string& p1, const string& p2){ cb->opString(p1, p2); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opMyEnum(Test::enum2, + [=](Test::MyEnum p1, Test::MyEnum p2){ cb->opMyEnum(p1, p2); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback(communicator); + p->begin_opMyClass(p, + [=](const Test::MyClassPrx& p1, const Test::MyClassPrx p2, const Test::MyClassPrx p3) + { + cb->opMyClass(p1, p2, p3); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::Structure si1; + si1.p = p; + si1.e = Test::enum3; + si1.s.s = "abc"; + Test::Structure si2; + si2.p = 0; + si2.e = Test::enum2; + si2.s.s = "def"; + + CallbackPtr cb = new Callback(communicator); + p->begin_opStruct(si1, si2, + [=](const Test::Structure& p1, const Test::Structure& p2) + { + cb->opStruct(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::ByteS bsi1; + Test::ByteS bsi2; + + bsi1.push_back(Ice::Byte(0x01)); + bsi1.push_back(Ice::Byte(0x11)); + bsi1.push_back(Ice::Byte(0x12)); + bsi1.push_back(Ice::Byte(0x22)); + + bsi2.push_back(Ice::Byte(0xf1)); + bsi2.push_back(Ice::Byte(0xf2)); + bsi2.push_back(Ice::Byte(0xf3)); + bsi2.push_back(Ice::Byte(0xf4)); + + CallbackPtr cb = new Callback; + Test::Callback_MyClass_opByteSPtr callback = Test::newCallback_MyClass_opByteS(cb, + &Callback::opByteS, + &Callback::exCB); + p->begin_opByteS(bsi1, bsi2, + [=](const Test::ByteS& p1, const Test::ByteS& p2) + { + cb->opByteS(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::BoolS bsi1; + Test::BoolS bsi2; + + bsi1.push_back(true); + bsi1.push_back(true); + bsi1.push_back(false); + + bsi2.push_back(false); + + CallbackPtr cb = new Callback; + p->begin_opBoolS(bsi1, bsi2, + [=](const Test::BoolS& p1, const Test::BoolS& p2) + { + cb->opBoolS(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::ShortS ssi; + Test::IntS isi; + Test::LongS lsi; + + ssi.push_back(1); + ssi.push_back(2); + ssi.push_back(3); + + isi.push_back(5); + isi.push_back(6); + isi.push_back(7); + isi.push_back(8); + + lsi.push_back(10); + lsi.push_back(30); + lsi.push_back(20); + + CallbackPtr cb = new Callback; + p->begin_opShortIntLongS(ssi, isi, lsi, + [=](const Test::LongS& p1, const Test::ShortS& p2, const Test::IntS& p3, const Test::LongS& p4) + { + cb->opShortIntLongS(p1, p2, p3, p4); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::FloatS fsi; + Test::DoubleS dsi; + + fsi.push_back(Ice::Float(3.14)); + fsi.push_back(Ice::Float(1.11)); + + dsi.push_back(Ice::Double(1.1E10)); + dsi.push_back(Ice::Double(1.2E10)); + dsi.push_back(Ice::Double(1.3E10)); + + CallbackPtr cb = new Callback; + p->begin_opFloatDoubleS(fsi, dsi, + [=](const Test::DoubleS& p1, const Test::FloatS& p2, const Test::DoubleS& p3) + { + cb->opFloatDoubleS(p1, p2, p3); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::StringS ssi1; + Test::StringS ssi2; + + ssi1.push_back("abc"); + ssi1.push_back("de"); + ssi1.push_back("fghi"); + + ssi2.push_back("xyz"); + + CallbackPtr cb = new Callback; + p->begin_opStringS(ssi1, ssi2, + [=](const Test::StringS& p1, const Test::StringS& p2) + { + cb->opStringS(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::ByteSS bsi1; + bsi1.resize(2); + Test::ByteSS bsi2; + bsi2.resize(2); + + bsi1[0].push_back(Ice::Byte(0x01)); + bsi1[0].push_back(Ice::Byte(0x11)); + bsi1[0].push_back(Ice::Byte(0x12)); + bsi1[1].push_back(Ice::Byte(0xff)); + + bsi2[0].push_back(Ice::Byte(0x0e)); + bsi2[1].push_back(Ice::Byte(0xf2)); + bsi2[1].push_back(Ice::Byte(0xf1)); + + CallbackPtr cb = new Callback; + p->begin_opByteSS(bsi1, bsi2, + [=](const Test::ByteSS& p1, const Test::ByteSS& p2) + { + cb->opByteSS(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::FloatSS fsi; + fsi.resize(3); + Test::DoubleSS dsi; + dsi.resize(1); + + fsi[0].push_back(Ice::Float(3.14)); + fsi[1].push_back(Ice::Float(1.11)); + + dsi[0].push_back(Ice::Double(1.1E10)); + dsi[0].push_back(Ice::Double(1.2E10)); + dsi[0].push_back(Ice::Double(1.3E10)); + + CallbackPtr cb = new Callback; + p->begin_opFloatDoubleSS(fsi, dsi, + [=](const Test::DoubleSS& p1, const Test::FloatSS& p2, const Test::DoubleSS& p3) + { + cb->opFloatDoubleSS(p1, p2, p3); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::StringSS ssi1; + ssi1.resize(2); + Test::StringSS ssi2; + ssi2.resize(3); + + ssi1[0].push_back("abc"); + ssi1[1].push_back("de"); + ssi1[1].push_back("fghi"); + + ssi2[2].push_back("xyz"); + + CallbackPtr cb = new Callback; + p->begin_opStringSS(ssi1, ssi2, + [=](const Test::StringSS& p1, const Test::StringSS& p2) + { + cb->opStringSS(p1, p2); + }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::ByteBoolD di1; + di1[10] = true; + di1[100] = false; + Test::ByteBoolD di2; + di2[10] = true; + di2[11] = false; + di2[101] = true; + + CallbackPtr cb = new Callback; + p->begin_opByteBoolD(di1, di2, + [=](const Test::ByteBoolD& p1, const Test::ByteBoolD& p2) + { + cb->opByteBoolD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + Test::ShortIntD di1; + di1[110] = -1; + di1[1100] = 123123; + Test::ShortIntD di2; + di2[110] = -1; + di2[111] = -100; + di2[1101] = 0; + + CallbackPtr cb = new Callback; + p->begin_opShortIntD(di1, di2, + [=](const Test::ShortIntD& p1, const Test::ShortIntD& p2) + { + cb->opShortIntD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + Test::LongFloatD di1; + di1[999999110] = Ice::Float(-1.1); + di1[999999111] = Ice::Float(123123.2); + Test::LongFloatD di2; + di2[999999110] = Ice::Float(-1.1); + di2[999999120] = Ice::Float(-100.4); + di2[999999130] = Ice::Float(0.5); + + CallbackPtr cb = new Callback; + p->begin_opLongFloatD(di1, di2, + [=](const Test::LongFloatD& p1, const Test::LongFloatD& p2) + { + cb->opLongFloatD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + Test::StringStringD di1; + di1["foo"] = "abc -1.1"; + di1["bar"] = "abc 123123.2"; + Test::StringStringD di2; + di2["foo"] = "abc -1.1"; + di2["FOO"] = "abc -100.4"; + di2["BAR"] = "abc 0.5"; + + CallbackPtr cb = new Callback; + p->begin_opStringStringD(di1, di2, + [=](const Test::StringStringD& p1, const Test::StringStringD& p2) + { + cb->opStringStringD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + Test::StringMyEnumD di1; + di1["abc"] = Test::enum1; + di1[""] = Test::enum2; + Test::StringMyEnumD di2; + di2["abc"] = Test::enum1; + di2["qwerty"] = Test::enum3; + di2["Hello!!"] = Test::enum2; + + CallbackPtr cb = new Callback; + p->begin_opStringMyEnumD(di1, di2, + [=](const Test::StringMyEnumD& p1, const Test::StringMyEnumD& p2) + { + cb->opStringMyEnumD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + Test::MyStruct s11 = { 1, 1 }; + Test::MyStruct s12 = { 1, 2 }; + Test::MyStructMyEnumD di1; + di1[s11] = Test::enum1; + di1[s12] = Test::enum2; + + Test::MyStruct s22 = { 2, 2 }; + Test::MyStruct s23 = { 2, 3 }; + Test::MyStructMyEnumD di2; + di2[s11] = Test::enum1; + di2[s22] = Test::enum3; + di2[s23] = Test::enum2; + + CallbackPtr cb = new Callback; + p->begin_opMyStructMyEnumD(di1, di2, + [=](const Test::MyStructMyEnumD& p1, const Test::MyStructMyEnumD& p2) + { + cb->opMyStructMyEnumD(p1, p2); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + + { + const int lengths[] = { 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 }; + + for(unsigned int l = 0; l != sizeof(lengths) / sizeof(*lengths); ++l) + { + Test::IntS s; + for(int i = 0; i < lengths[l]; ++i) + { + s.push_back(i); + } + CallbackPtr cb = new Callback; + p->begin_opIntS(s, + [=](const Test::IntS& p1) + { + cb->opIntS(p1); + }, + [=](const Ice::Exception& ex) + { + cb->exCB(ex); + }); + cb->check(); + } + } + + { + Ice::Double d = 1278312346.0 / 13.0; + Test::DoubleS ds(5, d); + CallbackPtr cb = new Callback; + p->begin_opDoubleMarshaling(d, ds, + [=](){ cb->opDoubleMarshaling(); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + Test::Callback_MyClass_opIdempotentPtr callback = + Test::newCallback_MyClass_opIdempotent(cb, &Callback::opIdempotent, &Callback::exCB); + p->begin_opIdempotent([=](){ cb->opIdempotent(); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + CallbackPtr cb = new Callback; + p->begin_opNonmutating([=](){ cb->opNonmutating(); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } + + { + Test::MyDerivedClassPrx derived = Test::MyDerivedClassPrx::checkedCast(p); + test(derived); + CallbackPtr cb = new Callback; + derived->begin_opDerived([=](){ cb->opDerived(); }, + [=](const Ice::Exception& ex){ cb->exCB(ex); }); + cb->check(); + } +#endif } diff --git a/cpp/test/IceUtil/unicode/Client.cpp b/cpp/test/IceUtil/unicode/Client.cpp index 0e9881deec5..c2184556ca7 100644 --- a/cpp/test/IceUtil/unicode/Client.cpp +++ b/cpp/test/IceUtil/unicode/Client.cpp @@ -13,6 +13,8 @@ #ifdef _WIN32 # include <io.h> +#else +# include <unistd.h> #endif using namespace IceUtil; @@ -209,9 +211,9 @@ main(int argc, char* argv[]) test(fd > 0); #if defined(_MSC_VER) test(_close(fd) == 0); -#else - test(close(fd) == 0); -#endif +# else + test(::close(fd) == 0); +# endif FILE* f = IceUtilInternal::fopen(filepath, "r"); test(f != 0); |