void Client::run(int argc, char** argv) { Ice::CommunicatorHolder communicator = initialize(argc, argv); TestIntfPrxPtr allTests(Test::TestHelper*); TestIntfPrxPtr t = allTests(this); t->shutdown(); }
int run(int, char**, const Ice::CommunicatorPtr& communicator) { TestIntfPrxPtr allTests(const Ice::CommunicatorPtr&); TestIntfPrxPtr Test = allTests(communicator); Test->shutdown(); return EXIT_SUCCESS; }
string getAdapterNameWithAMI(const TestIntfPrxPtr& test) { #ifdef ICE_CPP11_MAPPING return test->getAdapterName_async().get(); #else GetAdapterNameCBPtr cb = new GetAdapterNameCB(); test->begin_getAdapterName( newCallback_TestIntf_getAdapterName(cb, &GetAdapterNameCB::response, &GetAdapterNameCB::exception)); return cb->getResult(); #endif }
TestIntfPrxPtr createTestIntfPrx(vector<RemoteObjectAdapterPrxPtr>& adapters) { Ice::EndpointSeq endpoints; TestIntfPrxPtr test; for(vector<RemoteObjectAdapterPrxPtr>::const_iterator p = adapters.begin(); p != adapters.end(); ++p) { test = (*p)->getTestIntf(); Ice::EndpointSeq edpts = test->ice_getEndpoints(); endpoints.insert(endpoints.end(), edpts.begin(), edpts.end()); } return ICE_UNCHECKED_CAST(TestIntfPrx, test->ice_endpoints(endpoints)); }
void allTests(Test::TestHelper* helper) { Ice::CommunicatorPtr communicator = helper->communicator(); string sref = "test:" + helper->getTestEndpoint(); Ice::ObjectPrxPtr obj = communicator->stringToProxy(sref); test(obj); int proxyPort = communicator->getProperties()->getPropertyAsInt("Ice.HTTPProxyPort"); if(proxyPort == 0) { proxyPort = communicator->getProperties()->getPropertyAsInt("Ice.SOCKSProxyPort"); } TestIntfPrxPtr test = ICE_CHECKED_CAST(TestIntfPrx, obj); test(test); cout << "testing connection... " << flush; { test->ice_ping(); } cout << "ok" << endl; cout << "testing connection information... " << flush; { Ice::IPConnectionInfoPtr info = getIPConnectionInfo(test->ice_getConnection()->getInfo()); test(info->remotePort == proxyPort); // make sure we are connected to the proxy port. } cout << "ok" << endl; cout << "shutting down server... " << flush; { test->shutdown(); } cout << "ok" << endl; cout << "testing connection failure... " << flush; { try { test->ice_ping(); test(false); } catch(const Ice::LocalException&) { } } cout << "ok" << endl; }
void allTests(Test::TestHelper* helper) { Ice::CommunicatorPtr communicator = helper->communicator(); cout << "testing proxy endpoint information... " << flush; { Ice::ObjectPrxPtr p1 = communicator->stringToProxy("test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:" "udp -h udphost -p 10001 --interface eth0 --ttl 5 --sourceAddress 10.10.10.10:" "opaque -e 1.8 -t 100 -v ABCD"); Ice::EndpointSeq endps = p1->ice_getEndpoints(); Ice::EndpointInfoPtr info = endps[0]->getInfo(); Ice::TCPEndpointInfoPtr ipEndpoint = getTCPEndpointInfo(info); test(ipEndpoint); test(ipEndpoint->host == "tcphost"); test(ipEndpoint->port == 10000); test(ipEndpoint->timeout == 1200); #if !defined(ICE_OS_UWP) test(ipEndpoint->sourceAddress == "10.10.10.10"); #endif test(ipEndpoint->compress); test(!ipEndpoint->datagram()); test((ipEndpoint->type() == Ice::TCPEndpointType && !ipEndpoint->secure()) || (ipEndpoint->type() == Ice::SSLEndpointType && ipEndpoint->secure()) || (ipEndpoint->type() == Ice::WSEndpointType && !ipEndpoint->secure()) || (ipEndpoint->type() == Ice::WSSEndpointType && ipEndpoint->secure())); test((ipEndpoint->type() == Ice::TCPEndpointType && ICE_DYNAMIC_CAST(Ice::TCPEndpointInfo, info)) || (ipEndpoint->type() == Ice::SSLEndpointType && ICE_DYNAMIC_CAST(IceSSL::EndpointInfo, info)) || (ipEndpoint->type() == Ice::WSEndpointType && ICE_DYNAMIC_CAST(Ice::WSEndpointInfo, info)) || (ipEndpoint->type() == Ice::WSSEndpointType && ICE_DYNAMIC_CAST(Ice::WSEndpointInfo, info))); Ice::UDPEndpointInfoPtr udpEndpoint = ICE_DYNAMIC_CAST(Ice::UDPEndpointInfo, endps[1]->getInfo()); test(udpEndpoint); test(udpEndpoint->host == "udphost"); test(udpEndpoint->port == 10001); #if !defined(ICE_OS_UWP) test(udpEndpoint->sourceAddress == "10.10.10.10"); #endif test(udpEndpoint->mcastInterface == "eth0"); test(udpEndpoint->mcastTtl == 5); test(udpEndpoint->timeout == -1); test(!udpEndpoint->compress); test(!udpEndpoint->secure()); test(udpEndpoint->datagram()); test(udpEndpoint->type() == Ice::UDPEndpointType); Ice::OpaqueEndpointInfoPtr opaqueEndpoint = ICE_DYNAMIC_CAST(Ice::OpaqueEndpointInfo, endps[2]->getInfo()); test(opaqueEndpoint); Ice::EncodingVersion rev; rev.major = 1; rev.minor = 8; test(opaqueEndpoint->rawEncoding == rev); } cout << "ok" << endl; string defaultHost = communicator->getProperties()->getProperty("Ice.Default.Host"); #ifdef ICE_OS_UWP bool uwp = true; #else bool uwp = false; #endif if(!uwp || (communicator->getProperties()->getProperty("Ice.Default.Protocol") != "ssl" && communicator->getProperties()->getProperty("Ice.Default.Protocol") != "wss")) { cout << "test object adapter endpoint information... " << flush; { communicator->getProperties()->setProperty("TestAdapter.Endpoints", "default -h 127.0.0.1 -t 15000:udp -h 127.0.0.1"); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter"); Ice::EndpointSeq endpoints = adapter->getEndpoints(); test(endpoints.size() == 2); Ice::EndpointSeq publishedEndpoints = adapter->getPublishedEndpoints(); test(endpoints == publishedEndpoints); Ice::TCPEndpointInfoPtr ipEndpoint = getTCPEndpointInfo(endpoints[0]->getInfo()); test(ipEndpoint); test(ipEndpoint->type() == Ice::TCPEndpointType || ipEndpoint->type() == Ice::SSLEndpointType || ipEndpoint->type() == Ice::WSEndpointType || ipEndpoint->type() == Ice::WSSEndpointType); test(ipEndpoint->host == "127.0.0.1"); test(ipEndpoint->port > 0); test(ipEndpoint->timeout == 15000); Ice::UDPEndpointInfoPtr udpEndpoint = ICE_DYNAMIC_CAST(Ice::UDPEndpointInfo, endpoints[1]->getInfo()); test(udpEndpoint); test(udpEndpoint->host == "127.0.0.1"); test(udpEndpoint->datagram()); test(udpEndpoint->port > 0); endpoints.pop_back(); test(endpoints.size() == 1); adapter->setPublishedEndpoints(endpoints); publishedEndpoints = adapter->getPublishedEndpoints(); test(endpoints == publishedEndpoints); adapter->destroy(); int port = helper->getTestPort(1); ostringstream portStr; portStr << port; communicator->getProperties()->setProperty("TestAdapter.Endpoints", "default -h * -p " + portStr.str()); communicator->getProperties()->setProperty("TestAdapter.PublishedEndpoints", helper->getTestEndpoint(1)); adapter = communicator->createObjectAdapter("TestAdapter"); endpoints = adapter->getEndpoints(); test(endpoints.size() >= 1); publishedEndpoints = adapter->getPublishedEndpoints(); test(publishedEndpoints.size() == 1); for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) { ipEndpoint = getTCPEndpointInfo((*p)->getInfo()); test(ipEndpoint->port == port); } ipEndpoint = getTCPEndpointInfo(publishedEndpoints[0]->getInfo()); test(ipEndpoint->host == helper->getTestHost()); test(ipEndpoint->port == port); adapter->destroy(); } cout << "ok" << endl; } string endpoints = helper->getTestEndpoint() + ":" + helper->getTestEndpoint("udp") + " -c"; int port = helper->getTestPort(); Ice::ObjectPrxPtr base = communicator->stringToProxy("test:" + endpoints); TestIntfPrxPtr testIntf = ICE_CHECKED_CAST(TestIntfPrx, base); cout << "test connection endpoint information... " << flush; { Ice::EndpointInfoPtr info = base->ice_getConnection()->getEndpoint()->getInfo(); Ice::TCPEndpointInfoPtr tcpinfo = getTCPEndpointInfo(info); test(tcpinfo->port == port); test(!tcpinfo->compress); test(tcpinfo->host == defaultHost); ostringstream os; Ice::Context ctx = testIntf->getEndpointInfoAsContext(); test(ctx["host"] == tcpinfo->host); test(ctx["compress"] == "false"); istringstream is(ctx["port"]); int portCtx; is >> portCtx; test(portCtx > 0); info = base->ice_datagram()->ice_getConnection()->getEndpoint()->getInfo(); Ice::UDPEndpointInfoPtr udp = ICE_DYNAMIC_CAST(Ice::UDPEndpointInfo, info); test(udp); test(udp->port == portCtx); test(udp->host == defaultHost); } cout << "ok" << endl; cout << "testing connection information... " << flush; { Ice::ConnectionPtr connection = base->ice_getConnection(); connection->setBufferSize(1024, 2048); Ice::TCPConnectionInfoPtr info = getTCPConnectionInfo(connection->getInfo()); test(info); test(!info->incoming); test(info->adapterName.empty()); test(info->localPort > 0); test(info->remotePort == port); if(defaultHost == "127.0.0.1") { test(info->remoteAddress == defaultHost); test(info->localAddress == defaultHost); } #if !defined(ICE_OS_UWP) test(info->rcvSize >= 1024); test(info->sndSize >= 2048); #endif ostringstream os; Ice::Context ctx = testIntf->getConnectionInfoAsContext(); test(ctx["incoming"] == "true"); test(ctx["adapterName"] == "TestAdapter"); test(ctx["remoteAddress"] == info->localAddress); test(ctx["localAddress"] == info->remoteAddress); os.str(""); os << info->localPort; test(ctx["remotePort"] == os.str()); os.str(""); os << info->remotePort; test(ctx["localPort"] == os.str()); if(base->ice_getConnection()->type() == "ws" || base->ice_getConnection()->type() == "wss") { Ice::HeaderDict headers; Ice::WSConnectionInfoPtr wsinfo = ICE_DYNAMIC_CAST(Ice::WSConnectionInfo, connection->getInfo()); test(wsinfo); headers = wsinfo->headers; if(base->ice_getConnection()->type() == "wss") { IceSSL::ConnectionInfoPtr wssinfo = ICE_DYNAMIC_CAST(IceSSL::ConnectionInfo, wsinfo->underlying); test(wssinfo->verified); #if !defined(ICE_OS_UWP) && TARGET_OS_IPHONE==0 test(!wssinfo->certs.empty()); #endif } test(headers["Upgrade"] == "websocket"); test(headers["Connection"] == "Upgrade"); test(headers["Sec-WebSocket-Protocol"] == "ice.zeroc.com"); test(headers.find("Sec-WebSocket-Accept") != headers.end()); test(ctx["ws.Upgrade"] == "websocket"); test(ctx["ws.Connection"] == "Upgrade"); test(ctx["ws.Sec-WebSocket-Protocol"] == "ice.zeroc.com"); test(ctx["ws.Sec-WebSocket-Version"] == "13"); test(ctx.find("ws.Sec-WebSocket-Key") != ctx.end()); } connection = base->ice_datagram()->ice_getConnection(); connection->setBufferSize(2048, 1024); Ice::UDPConnectionInfoPtr udpinfo = ICE_DYNAMIC_CAST(Ice::UDPConnectionInfo, connection->getInfo()); test(!udpinfo->incoming); test(udpinfo->adapterName.empty()); test(udpinfo->localPort > 0); test(udpinfo->remotePort == port); if(defaultHost == "127.0.0.1") { test(udpinfo->remoteAddress == defaultHost); test(udpinfo->localAddress == defaultHost); } #if !defined(ICE_OS_UWP) test(udpinfo->rcvSize >= 2048); test(udpinfo->sndSize >= 1024); #endif } cout << "ok" << endl; testIntf->shutdown(); communicator->shutdown(); communicator->waitForShutdown(); }
void allTests(Test::TestHelper* helper, int num) { CommunicatorPtr communicator = helper->communicator(); vector<ControllerPrxPtr> proxies; vector<ControllerPrxPtr> indirectProxies; for(int i = 0; i < num; ++i) { { ostringstream os; os << "controller" << i; proxies.push_back(ICE_UNCHECKED_CAST(ControllerPrx, communicator->stringToProxy(os.str()))); } { ostringstream os; os << "controller" << i << "@control" << i; indirectProxies.push_back(ICE_UNCHECKED_CAST(ControllerPrx, communicator->stringToProxy(os.str()))); } } cout << "testing indirect proxies... " << flush; { for(vector<ControllerPrxPtr>::const_iterator p = indirectProxies.begin(); p != indirectProxies.end(); ++p) { (*p)->ice_ping(); } } cout << "ok" << endl; cout << "testing well-known proxies... " << flush; { for(vector<ControllerPrxPtr>::const_iterator p = proxies.begin(); p != proxies.end(); ++p) { (*p)->ice_ping(); } } cout << "ok" << endl; cout << "testing object adapter registration... " << flush; { try { communicator->stringToProxy("object @ oa1")->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } proxies[0]->activateObjectAdapter("oa", "oa1", ""); try { communicator->stringToProxy("object @ oa1")->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { } proxies[0]->deactivateObjectAdapter("oa"); try { communicator->stringToProxy("object @ oa1")->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } } cout << "ok" << endl; cout << "testing object adapter migration..." << flush; { proxies[0]->activateObjectAdapter("oa", "oa1", ""); proxies[0]->addObject("oa", "object"); communicator->stringToProxy("object @ oa1")->ice_ping(); proxies[0]->removeObject("oa", "object"); proxies[0]->deactivateObjectAdapter("oa"); proxies[1]->activateObjectAdapter("oa", "oa1", ""); proxies[1]->addObject("oa", "object"); communicator->stringToProxy("object @ oa1")->ice_ping(); proxies[1]->removeObject("oa", "object"); proxies[1]->deactivateObjectAdapter("oa"); } cout << "ok" << endl; cout << "testing object migration..." << flush; { proxies[0]->activateObjectAdapter("oa", "oa1", ""); proxies[1]->activateObjectAdapter("oa", "oa2", ""); proxies[0]->addObject("oa", "object"); communicator->stringToProxy("object @ oa1")->ice_ping(); communicator->stringToProxy("object")->ice_ping(); proxies[0]->removeObject("oa", "object"); proxies[1]->addObject("oa", "object"); communicator->stringToProxy("object @ oa2")->ice_ping(); communicator->stringToProxy("object")->ice_ping(); proxies[1]->removeObject("oa", "object"); try { communicator->stringToProxy("object @ oa1")->ice_ping(); } catch(const Ice::ObjectNotExistException&) { } try { communicator->stringToProxy("object @ oa2")->ice_ping(); } catch(const Ice::ObjectNotExistException&) { } proxies[0]->deactivateObjectAdapter("oa"); proxies[1]->deactivateObjectAdapter("oa"); } cout << "ok" << endl; cout << "testing replica groups..." << flush; { proxies[0]->activateObjectAdapter("oa", "oa1", "rg"); proxies[1]->activateObjectAdapter("oa", "oa2", "rg"); proxies[2]->activateObjectAdapter("oa", "oa3", "rg"); proxies[0]->addObject("oa", "object"); proxies[1]->addObject("oa", "object"); proxies[2]->addObject("oa", "object"); communicator->stringToProxy("object @ oa1")->ice_ping(); communicator->stringToProxy("object @ oa2")->ice_ping(); communicator->stringToProxy("object @ oa3")->ice_ping(); communicator->stringToProxy("object @ rg")->ice_ping(); set<string> adapterIds; adapterIds.insert("oa1"); adapterIds.insert("oa2"); adapterIds.insert("oa3"); TestIntfPrxPtr intf = ICE_UNCHECKED_CAST(TestIntfPrx, communicator->stringToProxy("object")); intf = intf->ice_connectionCached(false)->ice_locatorCacheTimeout(0); while(!adapterIds.empty()) { adapterIds.erase(intf->getAdapterId()); } while(true) { adapterIds.insert("oa1"); adapterIds.insert("oa2"); adapterIds.insert("oa3"); intf = ICE_UNCHECKED_CAST(TestIntfPrx, communicator->stringToProxy("object @ rg"))->ice_connectionCached(false); int nRetry = 100; while(!adapterIds.empty() && --nRetry > 0) { adapterIds.erase(intf->getAdapterId()); } if(nRetry > 0) { break; } // The previous locator lookup probably didn't return all the replicas... try again. communicator->stringToProxy("object @ rg")->ice_locatorCacheTimeout(0)->ice_ping(); } proxies[0]->deactivateObjectAdapter("oa"); proxies[1]->deactivateObjectAdapter("oa"); test(ICE_UNCHECKED_CAST(TestIntfPrx, communicator->stringToProxy("object @ rg"))->getAdapterId() == "oa3"); proxies[2]->deactivateObjectAdapter("oa"); proxies[0]->activateObjectAdapter("oa", "oa1", "rg"); proxies[0]->addObject("oa", "object"); test(ICE_UNCHECKED_CAST(TestIntfPrx, communicator->stringToProxy("object @ rg"))->getAdapterId() == "oa1"); proxies[0]->deactivateObjectAdapter("oa"); } cout << "ok" << endl; cout << "testing invalid lookup endpoints... " << flush; { string multicast; if(communicator->getProperties()->getProperty("Ice.IPv6") == "1") { multicast = "\"ff15::1\""; } else { multicast = "239.255.0.1"; } { Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); initData.properties->setProperty("IceDiscovery.Lookup", "udp -h " + multicast + " --interface unknown"); Ice::CommunicatorPtr com = Ice::initialize(initData); test(com->getDefaultLocator()); try { com->stringToProxy("controller0@control0")->ice_ping(); test(false); } catch(const Ice::LocalException&) { } com->destroy(); } { Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); string intf = initData.properties->getProperty("IceDiscovery.Interface"); if(!intf.empty()) { intf = " --interface \"" + intf + "\""; } string port = initData.properties->getProperty("IceDiscovery.Port"); initData.properties->setProperty("IceDiscovery.Lookup", "udp -h " + multicast + " --interface unknown:" + "udp -h " + multicast + " -p " + port + intf); Ice::CommunicatorPtr com = Ice::initialize(initData); test(com->getDefaultLocator()); com->stringToProxy("controller0@control0")->ice_ping(); com->destroy(); } } cout << "ok" << endl; cout << "shutting down... " << flush; for(vector<ControllerPrxPtr>::const_iterator p = proxies.begin(); p != proxies.end(); ++p) { (*p)->shutdown(); } cout << "ok" << endl; }
TestIntfPrxPtr allTests(const Ice::CommunicatorPtr& communicator) { string ref = "test:" + getTestEndpoint(communicator, 0); Ice::ObjectPrxPtr obj = communicator->stringToProxy(ref); test(obj); TestIntfPrxPtr proxy = ICE_CHECKED_CAST(TestIntfPrx, obj); test(proxy); cout << "testing enum values... " << flush; test(static_cast<int>(ICE_ENUM(ByteEnum, benum1)) == 0); test(static_cast<int>(ICE_ENUM(ByteEnum, benum2)) == 1); test(static_cast<int>(ICE_ENUM(ByteEnum, benum3)) == ByteConst1); test(static_cast<int>(ICE_ENUM(ByteEnum, benum4)) == ByteConst1 + 1); test(static_cast<int>(ICE_ENUM(ByteEnum, benum5)) == ShortConst1); test(static_cast<int>(ICE_ENUM(ByteEnum, benum6)) == ShortConst1 + 1); test(static_cast<int>(ICE_ENUM(ByteEnum, benum7)) == IntConst1); test(static_cast<int>(ICE_ENUM(ByteEnum, benum8)) == IntConst1 + 1); test(static_cast<int>(ICE_ENUM(ByteEnum, benum9)) == LongConst1); test(static_cast<int>(ICE_ENUM(ByteEnum, benum10)) == LongConst1 + 1); test(static_cast<int>(ICE_ENUM(ByteEnum, benum11)) == ByteConst2); test(static_cast<int>(ICE_ENUM(ShortEnum, senum1)) == 3); test(static_cast<int>(ICE_ENUM(ShortEnum, senum2)) == 4); test(static_cast<int>(ICE_ENUM(ShortEnum, senum3)) == ByteConst1); test(static_cast<int>(ICE_ENUM(ShortEnum, senum4)) == ByteConst1 + 1); test(static_cast<int>(ICE_ENUM(ShortEnum, senum5)) == ShortConst1); test(static_cast<int>(ICE_ENUM(ShortEnum, senum6)) == ShortConst1 + 1); test(static_cast<int>(ICE_ENUM(ShortEnum, senum7)) == IntConst1); test(static_cast<int>(ICE_ENUM(ShortEnum, senum8)) == IntConst1 + 1); test(static_cast<int>(ICE_ENUM(ShortEnum, senum9)) == LongConst1); test(static_cast<int>(ICE_ENUM(ShortEnum, senum10)) == LongConst1 + 1); test(static_cast<int>(ICE_ENUM(ShortEnum, senum11)) == ShortConst2); test(static_cast<int>(ICE_ENUM(IntEnum, ienum1)) == 0); test(static_cast<int>(ICE_ENUM(IntEnum, ienum2)) == 1); test(static_cast<int>(ICE_ENUM(IntEnum, ienum3)) == ByteConst1); test(static_cast<int>(ICE_ENUM(IntEnum, ienum4)) == ByteConst1 + 1); test(static_cast<int>(ICE_ENUM(IntEnum, ienum5)) == ShortConst1); test(static_cast<int>(ICE_ENUM(IntEnum, ienum6)) == ShortConst1 + 1); test(static_cast<int>(ICE_ENUM(IntEnum, ienum7)) == IntConst1); test(static_cast<int>(ICE_ENUM(IntEnum, ienum8)) == IntConst1 + 1); test(static_cast<int>(ICE_ENUM(IntEnum, ienum9)) == LongConst1); test(static_cast<int>(ICE_ENUM(IntEnum, ienum10)) == LongConst1 + 1); test(static_cast<int>(ICE_ENUM(IntEnum, ienum11)) == IntConst2); test(static_cast<int>(ICE_ENUM(IntEnum, ienum12)) == LongConst2); test(static_cast<int>(ICE_ENUM(SimpleEnum, red)) == 0); test(static_cast<int>(ICE_ENUM(SimpleEnum, green)) == 1); test(static_cast<int>(ICE_ENUM(SimpleEnum, blue)) == 2); cout << "ok" << endl; #ifndef ICE_CPP11_MAPPING cout << "testing enum streaming... " << flush; Ice::ByteSeq bytes; const bool encoding_1_0 = communicator->getProperties()->getProperty("Ice.Default.EncodingVersion") == "1.0"; { Ice::OutputStream out(communicator); out.write(ICE_ENUM(ByteEnum, benum11)); out.finished(bytes); test(bytes.size() == 1); // ByteEnum should require one byte } { Ice::OutputStream out(communicator); out.write(ICE_ENUM(ShortEnum, senum11)); out.finished(bytes); test(bytes.size() == (encoding_1_0 ? 2 : 5)); } { Ice::OutputStream out(communicator); out.write(ICE_ENUM(IntEnum, ienum11)); out.finished(bytes); test(bytes.size() == (encoding_1_0 ? 4 : 5)); } { Ice::OutputStream out(communicator); out.write(ICE_ENUM(SimpleEnum, blue)); out.finished(bytes); test(bytes.size() == 1); // SimpleEnum should require one byte } cout << "ok" << endl; #endif cout << "testing enum operations... " << flush; ByteEnum byteEnum; test(proxy->opByte(ICE_ENUM(ByteEnum, benum1), byteEnum) == ICE_ENUM(ByteEnum, benum1)); test(byteEnum == ICE_ENUM(ByteEnum, benum1)); test(proxy->opByte(ICE_ENUM(ByteEnum, benum11), byteEnum) == ICE_ENUM(ByteEnum, benum11)); test(byteEnum == ICE_ENUM(ByteEnum, benum11)); ShortEnum shortEnum; test(proxy->opShort(ICE_ENUM(ShortEnum, senum1), shortEnum) == ICE_ENUM(ShortEnum, senum1)); test(shortEnum == ICE_ENUM(ShortEnum, senum1)); test(proxy->opShort(ICE_ENUM(ShortEnum, senum11), shortEnum) == ICE_ENUM(ShortEnum, senum11)); test(shortEnum == ICE_ENUM(ShortEnum, senum11)); IntEnum intEnum; test(proxy->opInt(ICE_ENUM(IntEnum, ienum1), intEnum) == ICE_ENUM(IntEnum, ienum1)); test(intEnum == ICE_ENUM(IntEnum, ienum1)); test(proxy->opInt(ICE_ENUM(IntEnum, ienum11), intEnum) == ICE_ENUM(IntEnum, ienum11)); test(intEnum == ICE_ENUM(IntEnum, ienum11)); test(proxy->opInt(ICE_ENUM(IntEnum, ienum12), intEnum) == ICE_ENUM(IntEnum, ienum12)); test(intEnum == ICE_ENUM(IntEnum, ienum12)); SimpleEnum s; test(proxy->opSimple(ICE_ENUM(SimpleEnum, green), s) == ICE_ENUM(SimpleEnum, green)); test(s == ICE_ENUM(SimpleEnum, green)); cout << "ok" << endl; cout << "testing enum sequences operations... " << flush; { ByteEnum values[] = { ICE_ENUM(ByteEnum, benum1), ICE_ENUM(ByteEnum, benum2), ICE_ENUM(ByteEnum, benum3), ICE_ENUM(ByteEnum, benum4), ICE_ENUM(ByteEnum, benum5), ICE_ENUM(ByteEnum, benum6), ICE_ENUM(ByteEnum, benum7), ICE_ENUM(ByteEnum, benum8), ICE_ENUM(ByteEnum, benum9), ICE_ENUM(ByteEnum, benum10), ICE_ENUM(ByteEnum, benum11) }; ByteEnumSeq b1(&values[0], &values[0] + sizeof(values) / sizeof(ByteEnum)); ByteEnumSeq b2; ByteEnumSeq b3 = proxy->opByteSeq(b1, b2); for(size_t i = 0; i < b1.size(); ++i) { test(b1[i] == b2[i]); test(b1[i] == b3[i]); } } { ShortEnum values[] = { ICE_ENUM(ShortEnum, senum1), ICE_ENUM(ShortEnum, senum2), ICE_ENUM(ShortEnum, senum3), ICE_ENUM(ShortEnum, senum4), ICE_ENUM(ShortEnum, senum5), ICE_ENUM(ShortEnum, senum6), ICE_ENUM(ShortEnum, senum7), ICE_ENUM(ShortEnum, senum8), ICE_ENUM(ShortEnum, senum9), ICE_ENUM(ShortEnum, senum10), ICE_ENUM(ShortEnum, senum11) }; ShortEnumSeq s1(&values[0], &values[0] + sizeof(values) / sizeof(ShortEnum)); ShortEnumSeq s2; ShortEnumSeq s3 = proxy->opShortSeq(s1, s2); for(size_t i = 0; i < s1.size(); ++i) { test(s1[i] == s2[i]); test(s1[i] == s3[i]); } } { IntEnum values[] = { ICE_ENUM(IntEnum, ienum1), ICE_ENUM(IntEnum, ienum2), ICE_ENUM(IntEnum, ienum3), ICE_ENUM(IntEnum, ienum4), ICE_ENUM(IntEnum, ienum5), ICE_ENUM(IntEnum, ienum6), ICE_ENUM(IntEnum, ienum7), ICE_ENUM(IntEnum, ienum8), ICE_ENUM(IntEnum, ienum9), ICE_ENUM(IntEnum, ienum10), ICE_ENUM(IntEnum, ienum11) }; IntEnumSeq i1(&values[0], &values[0] + sizeof(values) / sizeof(IntEnum)); IntEnumSeq i2; IntEnumSeq i3 = proxy->opIntSeq(i1, i2); for(size_t i = 0; i < i1.size(); ++i) { test(i1[i] == i2[i]); test(i1[i] == i3[i]); } } { SimpleEnum values[] = { ICE_ENUM(SimpleEnum, red), ICE_ENUM(SimpleEnum, green), ICE_ENUM(SimpleEnum, blue) }; SimpleEnumSeq s1(&values[0], &values[0] + sizeof(values) / sizeof(SimpleEnum)); SimpleEnumSeq s2; SimpleEnumSeq s3 = proxy->opSimpleSeq(s1, s2); for(size_t i = 0; i < s1.size(); ++i) { test(s1[i] == s2[i]); test(s1[i] == s3[i]); } } cout << "ok" << endl; cout << "testing enum exceptions... " << flush; try { proxy->opByte(static_cast<ByteEnum>(-1), byteEnum); // Negative enumerators are not supported test(false); } catch(const Ice::MarshalException&) { } try { proxy->opByte(static_cast<ByteEnum>(127), byteEnum); // Invalid enumerator test(false); } catch(const Ice::MarshalException&) { } try { proxy->opShort(static_cast<ShortEnum>(-1), shortEnum); // Negative enumerators are not supported test(false); } catch(const Ice::MarshalException&) { } try { proxy->opShort(static_cast<ShortEnum>(0), shortEnum); // Invalid enumerator test(false); } catch(const Ice::MarshalException&) { } try { proxy->opShort(static_cast<ShortEnum>(32767), shortEnum); // Invalid enumerator test(false); } catch(const Ice::MarshalException&) { } try { proxy->opInt(static_cast<IntEnum>(-1), intEnum); // Negative enumerators are not supported test(false); } catch(const Ice::MarshalException&) { } cout << "ok" << endl; return proxy; }
TestIntfPrxPtr allTests(const Ice::CommunicatorPtr& communicator) { Ice::ObjectPrxPtr obj = communicator->stringToProxy("Test:" + getTestEndpoint(communicator, 0)); TestIntfPrxPtr test = ICE_CHECKED_CAST(TestIntfPrx, obj); cout << "base... " << flush; { try { test->baseAsBase(); test(false); } catch(const Base& b) { test(b.b == "Base.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->baseAsBase_async(); try { result.get(); test(false); } catch(const Base& b) { test(b.b == "Base.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_baseAsBase( newCallback_TestIntf_baseAsBase(cb, &Callback::response, &Callback::exception_baseAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of unknown derived... " << flush; { try { test->unknownDerivedAsBase(); test(false); } catch(const Base& b) { test(b.b == "UnknownDerived.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of unknown derived (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->unknownDerivedAsBase_async(); try { result.get(); test(false); } catch(const Base& b) { test(b.b == "UnknownDerived.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_unknownDerivedAsBase( newCallback_TestIntf_unknownDerivedAsBase(cb, &Callback::response, &Callback::exception_unknownDerivedAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "non-slicing of known derived as base... " << flush; { try { test->knownDerivedAsBase(); test(false); } catch(const KnownDerived& k) { test(k.b == "KnownDerived.b"); test(k.kd == "KnownDerived.kd"); test(k.ice_id() == "::Test::KnownDerived"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "non-slicing of known derived as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownDerivedAsBase_async(); try { result.get(); test(false); } catch(const KnownDerived& k) { test(k.b == "KnownDerived.b"); test(k.kd == "KnownDerived.kd"); test(k.ice_id() == "::Test::KnownDerived"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownDerivedAsBase( newCallback_TestIntf_knownDerivedAsBase(cb, &Callback::response, &Callback::exception_knownDerivedAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "non-slicing of known derived as derived... " << flush; { try { test->knownDerivedAsKnownDerived(); test(false); } catch(const KnownDerived& k) { test(k.b == "KnownDerived.b"); test(k.kd == "KnownDerived.kd"); test(k.ice_id() == "::Test::KnownDerived"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "non-slicing of known derived as derived (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownDerivedAsKnownDerived_async(); try { result.get(); } catch(const KnownDerived& k) { test(k.b == "KnownDerived.b"); test(k.kd == "KnownDerived.kd"); test(k.ice_id() == "::Test::KnownDerived"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownDerivedAsKnownDerived( newCallback_TestIntf_knownDerivedAsKnownDerived(cb, &Callback::response, &Callback::exception_knownDerivedAsKnownDerived)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of unknown intermediate as base... " << flush; { try { test->unknownIntermediateAsBase(); test(false); } catch(const Base& b) { test(b.b == "UnknownIntermediate.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of unknown intermediate as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->unknownIntermediateAsBase_async(); try { result.get(); test(false); } catch(const Base& b) { test(b.b == "UnknownIntermediate.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_unknownIntermediateAsBase( newCallback_TestIntf_unknownIntermediateAsBase(cb, &Callback::response, &Callback::exception_unknownIntermediateAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of known intermediate as base... " << flush; { try { test->knownIntermediateAsBase(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "KnownIntermediate.b"); test(ki.ki == "KnownIntermediate.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of known intermediate as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownIntermediateAsBase_async(); try { result.get(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "KnownIntermediate.b"); test(ki.ki == "KnownIntermediate.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownIntermediateAsBase( newCallback_TestIntf_knownIntermediateAsBase(cb, &Callback::response, &Callback::exception_knownIntermediateAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of known most derived as base... " << flush; { try { test->knownMostDerivedAsBase(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of known most derived as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownMostDerivedAsBase_async(); try { result.get(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownMostDerivedAsBase( newCallback_TestIntf_knownMostDerivedAsBase(cb, &Callback::response, &Callback::exception_knownMostDerivedAsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "non-slicing of known intermediate as intermediate... " << flush; { try { test->knownIntermediateAsKnownIntermediate(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "KnownIntermediate.b"); test(ki.ki == "KnownIntermediate.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "non-slicing of known intermediate as intermediate (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownIntermediateAsKnownIntermediate_async(); try { result.get(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "KnownIntermediate.b"); test(ki.ki == "KnownIntermediate.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownIntermediateAsKnownIntermediate( newCallback_TestIntf_knownIntermediateAsKnownIntermediate(cb, &Callback::response, &Callback::exception_knownIntermediateAsKnownIntermediate)); cb->check(); #endif } cout << "ok" << endl; cout << "non-slicing of known most derived exception as intermediate... " << flush; { try { test->knownMostDerivedAsKnownIntermediate(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "non-slicing of known most derived as intermediate (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownMostDerivedAsKnownIntermediate_async(); try { result.get(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownMostDerivedAsKnownIntermediate( newCallback_TestIntf_knownMostDerivedAsKnownIntermediate(cb, &Callback::response, &Callback::exception_knownMostDerivedAsKnownIntermediate)); cb->check(); #endif } cout << "ok" << endl; cout << "non-slicing of known most derived as most derived... " << flush; { try { test->knownMostDerivedAsKnownMostDerived(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "non-slicing of known most derived as most derived (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->knownMostDerivedAsKnownMostDerived_async(); try { result.get(); test(false); } catch(const KnownMostDerived& kmd) { test(kmd.b == "KnownMostDerived.b"); test(kmd.ki == "KnownMostDerived.ki"); test(kmd.kmd == "KnownMostDerived.kmd"); test(kmd.ice_id() == "::Test::KnownMostDerived"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_knownMostDerivedAsKnownMostDerived( newCallback_TestIntf_knownMostDerivedAsKnownMostDerived(cb, &Callback::response, &Callback::exception_knownMostDerivedAsKnownMostDerived)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of unknown most derived, known intermediate as base... " << flush; { try { test->unknownMostDerived1AsBase(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "UnknownMostDerived1.b"); test(ki.ki == "UnknownMostDerived1.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of unknown most derived, known intermediate as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->unknownMostDerived1AsBase_async(); try { result.get(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "UnknownMostDerived1.b"); test(ki.ki == "UnknownMostDerived1.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_unknownMostDerived1AsBase( newCallback_TestIntf_unknownMostDerived1AsBase(cb, &Callback::response, &Callback::exception_unknownMostDerived1AsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of unknown most derived, known intermediate as intermediate... " << flush; { try { test->unknownMostDerived1AsKnownIntermediate(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "UnknownMostDerived1.b"); test(ki.ki == "UnknownMostDerived1.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of unknown most derived, known intermediate as intermediate (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->unknownMostDerived1AsKnownIntermediate_async(); try { result.get(); test(false); } catch(const KnownIntermediate& ki) { test(ki.b == "UnknownMostDerived1.b"); test(ki.ki == "UnknownMostDerived1.ki"); test(ki.ice_id() == "::Test::KnownIntermediate"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_unknownMostDerived1AsKnownIntermediate( newCallback_TestIntf_unknownMostDerived1AsKnownIntermediate(cb, &Callback::response, &Callback::exception_unknownMostDerived1AsKnownIntermediate)); cb->check(); #endif } cout << "ok" << endl; cout << "slicing of unknown most derived, unknown intermediate as base... " << flush; { try { test->unknownMostDerived2AsBase(); test(false); } catch(const Base& b) { test(b.b == "UnknownMostDerived2.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } } cout << "ok" << endl; cout << "slicing of unknown most derived, unknown intermediate as base (AMI)... " << flush; { #ifdef ICE_CPP11_MAPPING auto result = test->unknownMostDerived2AsBase_async(); try { result.get(); test(false); } catch(const Base& b) { test(b.b == "UnknownMostDerived2.b"); test(b.ice_id() == "::Test::Base"); } catch(...) { test(false); } #else CallbackPtr cb = new Callback; test->begin_unknownMostDerived2AsBase( newCallback_TestIntf_unknownMostDerived2AsBase(cb, &Callback::response, &Callback::exception_unknownMostDerived2AsBase)); cb->check(); #endif } cout << "ok" << endl; cout << "unknown most derived in compact format... " << flush; { try { test->unknownMostDerived2AsBaseCompact(); test(false); } catch(const Base&) { // // For the 1.0 encoding, the unknown exception is sliced to Base. // test(test->ice_getEncodingVersion() == Ice::Encoding_1_0); } catch(const Ice::UnknownUserException&) { // // An UnknownUserException is raised for the compact format because the // most-derived type is unknown and the exception cannot be sliced. // test(test->ice_getEncodingVersion() != Ice::Encoding_1_0); } catch(const Ice::OperationNotExistException&) { } catch(...) { test(false); } } cout << "ok" << endl; cout << "preserved exceptions... " << flush; string localOAEndpoint; { ostringstream ostr; if(communicator->getProperties()->getProperty("Ice.Default.Protocol") == "bt") { ostr << "default -a *"; } else { ostr << "default -h *"; } localOAEndpoint = ostr.str(); } { Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("Relay", localOAEndpoint); RelayPrxPtr relay = ICE_UNCHECKED_CAST(RelayPrx, adapter->addWithUUID(ICE_MAKE_SHARED(RelayI))); adapter->activate(); try { test->relayKnownPreservedAsBase(relay); test(false); } catch(const KnownPreservedDerived& ex) { test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); } catch(const Ice::OperationNotExistException&) { } catch(const Ice::LocalException& ex) { cout << endl << "** OOPS" << endl << ex << endl; test(false); } catch(...) { test(false); } try { test->relayKnownPreservedAsKnownPreserved(relay); test(false); } catch(const KnownPreservedDerived& ex) { test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); } catch(const Ice::OperationNotExistException&) { } catch(...) { test(false); } try { test->relayUnknownPreservedAsBase(relay); test(false); } catch(const Preserved2& ex) { test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); test(ex.p1->ice_id() == PreservedClass::ice_staticId()); PreservedClassPtr pc = ICE_DYNAMIC_CAST(PreservedClass, ex.p1); test(pc->bc == "bc"); test(pc->pc == "pc"); test(ex.p2 == ex.p1); } catch(const Ice::OperationNotExistException&) { } catch(const KnownPreservedDerived& ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(test->ice_getEncodingVersion() == Ice::Encoding_1_0); test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); } catch(...) { test(false); } try { test->relayUnknownPreservedAsKnownPreserved(relay); test(false); } catch(const Ice::OperationNotExistException&) { } catch(const Preserved2& ex) { test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); test(ex.p1->ice_id() == PreservedClass::ice_staticId()); PreservedClassPtr pc = ICE_DYNAMIC_CAST(PreservedClass, ex.p1); test(pc->bc == "bc"); test(pc->pc == "pc"); test(ex.p2 == ex.p1); } catch(const KnownPreservedDerived& ex) { // // For the 1.0 encoding, the unknown exception is sliced to KnownPreserved. // test(test->ice_getEncodingVersion() == Ice::Encoding_1_0); test(ex.b == "base"); test(ex.kp == "preserved"); test(ex.kpd == "derived"); } catch(...) { test(false); } adapter->destroy(); } cout << "ok" << endl; return test; }
void allTests(const Ice::CommunicatorPtr& communicator, const string& ref) { ServerManagerPrxPtr manager = ICE_CHECKED_CAST(ServerManagerPrx, communicator->stringToProxy(ref)); TestLocatorPrxPtr locator = ICE_UNCHECKED_CAST(TestLocatorPrx, communicator->getDefaultLocator()); test(manager); TestLocatorRegistryPrxPtr registry = ICE_CHECKED_CAST(TestLocatorRegistryPrx, locator->getRegistry()); test(registry); cout << "testing stringToProxy... " << flush; Ice::ObjectPrxPtr base = communicator->stringToProxy("test @ TestAdapter"); Ice::ObjectPrxPtr base2 = communicator->stringToProxy("test @ TestAdapter"); Ice::ObjectPrxPtr base3 = communicator->stringToProxy("test"); Ice::ObjectPrxPtr base4 = communicator->stringToProxy("ServerManager"); Ice::ObjectPrxPtr base5 = communicator->stringToProxy("test2"); Ice::ObjectPrxPtr base6 = communicator->stringToProxy("test @ ReplicatedAdapter"); cout << "ok" << endl; cout << "testing ice_locator and ice_getLocator... " << flush; test(Ice::proxyIdentityEqual(base->ice_getLocator(), communicator->getDefaultLocator())); Ice::LocatorPrxPtr anotherLocator = ICE_UNCHECKED_CAST(Ice::LocatorPrx, communicator->stringToProxy("anotherLocator")); base = base->ice_locator(anotherLocator); test(Ice::proxyIdentityEqual(base->ice_getLocator(), anotherLocator)); communicator->setDefaultLocator(ICE_NULLPTR); base = communicator->stringToProxy("test @ TestAdapter"); test(!base->ice_getLocator()); base = base->ice_locator(anotherLocator); test(Ice::proxyIdentityEqual(base->ice_getLocator(), anotherLocator)); communicator->setDefaultLocator(locator); base = communicator->stringToProxy("test @ TestAdapter"); test(Ice::proxyIdentityEqual(base->ice_getLocator(), communicator->getDefaultLocator())); // // We also test ice_router/ice_getRouter (perhaps we should add a // test/Ice/router test?) // test(!base->ice_getRouter()); Ice::RouterPrxPtr anotherRouter = ICE_UNCHECKED_CAST(Ice::RouterPrx, communicator->stringToProxy("anotherRouter")); base = base->ice_router(anotherRouter); test(Ice::proxyIdentityEqual(base->ice_getRouter(), anotherRouter)); Ice::RouterPrxPtr router = ICE_UNCHECKED_CAST(Ice::RouterPrx, communicator->stringToProxy("dummyrouter")); communicator->setDefaultRouter(router); base = communicator->stringToProxy("test @ TestAdapter"); test(Ice::proxyIdentityEqual(base->ice_getRouter(), communicator->getDefaultRouter())); communicator->setDefaultRouter(0); base = communicator->stringToProxy("test @ TestAdapter"); test(!base->ice_getRouter()); cout << "ok" << endl; cout << "starting server... " << flush; manager->startServer(); cout << "ok" << endl; cout << "testing checked cast... " << flush; TestIntfPrxPtr obj = ICE_CHECKED_CAST(TestIntfPrx, base); test(obj); TestIntfPrxPtr obj2 = ICE_CHECKED_CAST(TestIntfPrx, base2); test(obj2); TestIntfPrxPtr obj3 = ICE_CHECKED_CAST(TestIntfPrx, base3); test(obj3); ServerManagerPrxPtr obj4 = ICE_CHECKED_CAST(ServerManagerPrx, base4); test(obj4); TestIntfPrxPtr obj5 = ICE_CHECKED_CAST(TestIntfPrx, base5); test(obj5); TestIntfPrxPtr obj6 = ICE_CHECKED_CAST(TestIntfPrx, base6); test(obj6); cout << "ok" << endl; cout << "testing id@AdapterId indirect proxy... " << flush; obj->shutdown(); manager->startServer(); try { obj2->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing id@ReplicaGroupId indirect proxy... " << flush; obj->shutdown(); manager->startServer(); try { obj6->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing identity indirect proxy... " << flush; obj->shutdown(); manager->startServer(); try { obj3->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } try { obj2->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } obj->shutdown(); manager->startServer(); try { obj2->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } try { obj3->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } obj->shutdown(); manager->startServer(); try { obj2->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } obj->shutdown(); manager->startServer(); try { obj3->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } obj->shutdown(); manager->startServer(); try { obj2->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } obj->shutdown(); manager->startServer(); try { obj5->ice_ping(); } catch(const Ice::LocalException& ex) { cerr << ex << endl; test(false); } cout << "ok" << endl; cout << "testing proxy with unknown identity... " << flush; try { base = communicator->stringToProxy("unknown/unknown"); base->ice_ping(); test(false); } catch (const Ice::NotRegisteredException& ex) { test(ex.kindOfObject == "object"); test(ex.id == "unknown/unknown"); } cout << "ok" << endl; cout << "testing proxy with unknown adapter... " << flush; try { base = communicator->stringToProxy("test @ TestAdapterUnknown"); base->ice_ping(); test(false); } catch (const Ice::NotRegisteredException& ex) { test(ex.kindOfObject == "object adapter"); test(ex.id == "TestAdapterUnknown"); } cout << "ok" << endl; cout << "testing locator cache timeout... " << flush; int count = locator->getRequestCount(); communicator->stringToProxy("test@TestAdapter")->ice_locatorCacheTimeout(0)->ice_ping(); // No locator cache. test(++count == locator->getRequestCount()); communicator->stringToProxy("test@TestAdapter")->ice_locatorCacheTimeout(0)->ice_ping(); // No locator cache. test(++count == locator->getRequestCount()); communicator->stringToProxy("test@TestAdapter")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout. test(count == locator->getRequestCount()); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1300)); communicator->stringToProxy("test@TestAdapter")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout. test(++count == locator->getRequestCount()); communicator->stringToProxy("test")->ice_locatorCacheTimeout(0)->ice_ping(); // No locator cache. count += 2; test(count == locator->getRequestCount()); communicator->stringToProxy("test")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout test(count == locator->getRequestCount()); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1300)); communicator->stringToProxy("test")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout count += 2; test(count == locator->getRequestCount()); communicator->stringToProxy("test@TestAdapter")->ice_locatorCacheTimeout(-1)->ice_ping(); test(count == locator->getRequestCount()); communicator->stringToProxy("test")->ice_locatorCacheTimeout(-1)->ice_ping(); test(count == locator->getRequestCount()); communicator->stringToProxy("test@TestAdapter")->ice_ping(); test(count == locator->getRequestCount()); communicator->stringToProxy("test")->ice_ping(); test(count == locator->getRequestCount()); test(communicator->stringToProxy("test")->ice_locatorCacheTimeout(99)->ice_getLocatorCacheTimeout() == 99); cout << "ok" << endl; cout << "testing proxy from server... " << flush; obj = ICE_CHECKED_CAST(TestIntfPrx, communicator->stringToProxy("test@TestAdapter")); HelloPrxPtr hello = obj->getHello(); test(hello->ice_getAdapterId() == "TestAdapter"); hello->sayHello(); hello = obj->getReplicatedHello(); test(hello->ice_getAdapterId() == "ReplicatedAdapter"); hello->sayHello(); cout << "ok" << endl; cout << "testing locator request queuing... " << flush; hello = obj->getReplicatedHello()->ice_locatorCacheTimeout(0)->ice_connectionCached(false); count = locator->getRequestCount(); hello->ice_ping(); test(++count == locator->getRequestCount()); int i; #ifdef ICE_CPP11_MAPPING list<future<void>> results; for(i = 0; i < 1000; i++) { auto result = make_shared<promise<void>>(); hello->sayHello_async( [result]() { result->set_value(); }, [result](exception_ptr) { test(false); }); results.push_back(result->get_future()); } for(auto& result : results) { result.get(); } results.clear(); test(locator->getRequestCount() > count && locator->getRequestCount() < count + 999); if(locator->getRequestCount() > count + 800) { cout << "queuing = " << locator->getRequestCount() - count; } count = locator->getRequestCount(); hello = hello->ice_adapterId("unknown"); for(i = 0; i < 1000; i++) { auto result = make_shared<promise<void>>(); hello->sayHello_async( [result]() { test(false); }, [result](exception_ptr ex) { try { rethrow_exception(ex); } catch(const Ice::NotRegisteredException&) { result->set_value(); } catch(...) { test(false); } }); results.push_back(result->get_future()); } for(auto& result : results) { result.get(); } results.clear(); // Take into account the retries. test(locator->getRequestCount() > count && locator->getRequestCount() < count + 1999); if(locator->getRequestCount() > count + 800) { cout << "queuing = " << locator->getRequestCount() - count; } #else list<Ice::AsyncResultPtr> results; AMICallbackPtr cb = new AMICallback; for(i = 0; i < 1000; i++) { Ice::AsyncResultPtr result = hello->begin_sayHello( newCallback_Hello_sayHello(cb, &AMICallback::response1, &AMICallback::exception1)); results.push_back(result); } while(!results.empty()) { Ice::AsyncResultPtr result = results.front(); results.pop_front(); result->waitForCompleted(); } test(locator->getRequestCount() > count && locator->getRequestCount() < count + 999); if(locator->getRequestCount() > count + 800) { cout << "queuing = " << locator->getRequestCount() - count; } count = locator->getRequestCount(); hello = hello->ice_adapterId("unknown"); for(i = 0; i < 1000; i++) { Ice::AsyncResultPtr result = hello->begin_sayHello( newCallback_Hello_sayHello(cb, &AMICallback::response2, &AMICallback::exception2)); results.push_back(result); } while(!results.empty()) { Ice::AsyncResultPtr result = results.front(); results.pop_front(); result->waitForCompleted(); } // Take into account the retries. test(locator->getRequestCount() > count && locator->getRequestCount() < count + 1999); if(locator->getRequestCount() > count + 800) { cout << "queuing = " << locator->getRequestCount() - count; } #endif cout << "ok" << endl; cout << "testing adapter locator cache... " << flush; try { communicator->stringToProxy("test@TestAdapter3")->ice_ping(); test(false); } catch(const Ice::NotRegisteredException& ex) { test(ex.kindOfObject == "object adapter"); test(ex.id == "TestAdapter3"); } registry->setAdapterDirectProxy("TestAdapter3", locator->findAdapterById("TestAdapter")); try { communicator->stringToProxy("test@TestAdapter3")->ice_ping(); registry->setAdapterDirectProxy("TestAdapter3", communicator->stringToProxy("dummy:tcp")); communicator->stringToProxy("test@TestAdapter3")->ice_ping(); } catch(const Ice::LocalException&) { test(false); } try { communicator->stringToProxy("test@TestAdapter3")->ice_locatorCacheTimeout(0)->ice_ping(); test(false); } catch(const Ice::LocalException&) { } try { communicator->stringToProxy("test@TestAdapter3")->ice_ping(); test(false); } catch(const Ice::LocalException&) { } registry->setAdapterDirectProxy("TestAdapter3", locator->findAdapterById("TestAdapter")); try { communicator->stringToProxy("test@TestAdapter3")->ice_ping(); } catch(const Ice::LocalException&) { test(false); } cout << "ok" <<endl; cout << "testing well-known object locator cache... " << flush; registry->addObject(communicator->stringToProxy("test3@TestUnknown")); try { communicator->stringToProxy("test3")->ice_ping(); test(false); } catch(const Ice::NotRegisteredException& ex) { test(ex.kindOfObject == "object adapter"); test(ex.id == "TestUnknown"); } registry->addObject(communicator->stringToProxy("test3@TestAdapter4")); // Update registry->setAdapterDirectProxy("TestAdapter4", communicator->stringToProxy("dummy:tcp")); try { communicator->stringToProxy("test3")->ice_ping(); test(false); } catch(const Ice::LocalException&) { } registry->setAdapterDirectProxy("TestAdapter4", locator->findAdapterById("TestAdapter")); try { communicator->stringToProxy("test3")->ice_ping(); } catch(const Ice::LocalException&) { test(false); } registry->setAdapterDirectProxy("TestAdapter4", communicator->stringToProxy("dummy:tcp")); try { communicator->stringToProxy("test3")->ice_ping(); } catch(const Ice::LocalException&) { test(false); } try { communicator->stringToProxy("test@TestAdapter4")->ice_locatorCacheTimeout(0)->ice_ping(); test(false); } catch(const Ice::LocalException&) { } try { communicator->stringToProxy("test@TestAdapter4")->ice_ping(); test(false); } catch(const Ice::LocalException&) { } try { communicator->stringToProxy("test3")->ice_ping(); test(false); } catch(const Ice::LocalException&) { } registry->addObject(communicator->stringToProxy("test3@TestAdapter")); try { communicator->stringToProxy("test3")->ice_ping(); } catch(const Ice::LocalException&) { test(false); } registry->addObject(communicator->stringToProxy("test4")); try { communicator->stringToProxy("test4")->ice_ping(); test(false); } catch(const Ice::NoEndpointException&) { } cout << "ok" << endl; cout << "testing locator cache background updates... " << flush; { Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); initData.properties->setProperty("Ice.BackgroundLocatorCacheUpdates", "1"); Ice::CommunicatorPtr ic = Ice::initialize(initData); registry->setAdapterDirectProxy("TestAdapter5", locator->findAdapterById("TestAdapter")); registry->addObject(communicator->stringToProxy("test3@TestAdapter")); int count = locator->getRequestCount(); ic->stringToProxy("test@TestAdapter5")->ice_locatorCacheTimeout(0)->ice_ping(); // No locator cache. ic->stringToProxy("test3")->ice_locatorCacheTimeout(0)->ice_ping(); // No locator cache. count += 3; test(count == locator->getRequestCount()); registry->setAdapterDirectProxy("TestAdapter5", 0); registry->addObject(communicator->stringToProxy("test3:tcp")); ic->stringToProxy("test@TestAdapter5")->ice_locatorCacheTimeout(10)->ice_ping(); // 10s timeout. ic->stringToProxy("test3")->ice_locatorCacheTimeout(10)->ice_ping(); // 10s timeout. test(count == locator->getRequestCount()); IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1200)); // The following request should trigger the background updates but still use the cached endpoints // and therefore succeed. ic->stringToProxy("test@TestAdapter5")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout. ic->stringToProxy("test3")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout. try { while(true) { ic->stringToProxy("test@TestAdapter5")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout. IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(10)); } } catch(const Ice::LocalException&) { // Expected to fail once they endpoints have been updated in the background. } try { while(true) { ic->stringToProxy("test3")->ice_locatorCacheTimeout(1)->ice_ping(); // 1s timeout. IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(10)); } } catch(const Ice::LocalException&) { // Expected to fail once they endpoints have been updated in the background. } ic->destroy(); } cout << "ok" << endl; cout << "testing proxy from server after shutdown... " << flush; hello = obj->getReplicatedHello(); obj->shutdown(); manager->startServer(); hello->sayHello(); cout << "ok" << endl; cout << "testing object migration... " << flush; hello = ICE_CHECKED_CAST(HelloPrx, communicator->stringToProxy("hello")); obj->migrateHello(); hello->ice_getConnection()->close(false); hello->sayHello(); obj->migrateHello(); hello->sayHello(); obj->migrateHello(); hello->sayHello(); cout << "ok" << endl; cout << "testing locator encoding resolution... " << flush; hello = ICE_CHECKED_CAST(HelloPrx, communicator->stringToProxy("hello")); count = locator->getRequestCount(); communicator->stringToProxy("test@TestAdapter")->ice_encodingVersion(Ice::Encoding_1_1)->ice_ping(); test(count == locator->getRequestCount()); communicator->stringToProxy("test@TestAdapter10")->ice_encodingVersion(Ice::Encoding_1_0)->ice_ping(); test(++count == locator->getRequestCount()); communicator->stringToProxy("test -e 1.0@TestAdapter10-2")->ice_ping(); test(++count == locator->getRequestCount()); cout << "ok" << endl; cout << "shutdown server... " << flush; obj->shutdown(); cout << "ok" << endl; cout << "testing whether server is gone... " << flush; try { obj2->ice_ping(); test(false); } catch(const Ice::LocalException&) { } try { obj3->ice_ping(); test(false); } catch(const Ice::LocalException&) { } try { obj5->ice_ping(); test(false); } catch(const Ice::LocalException&) { } cout << "ok" << endl; string host = communicator->getProperties()->getPropertyAsIntWithDefault("Ice.IPv6", 0) == 0 ? "127.0.0.1" : "\"0:0:0:0:0:0:0:1\""; if(communicator->getProperties()->getProperty("Ice.Default.Host") == host) { cout << "testing indirect proxies to collocated objects... " << flush; // // Set up test for calling a collocated object through an indirect, adapterless reference. // Ice::PropertiesPtr properties = communicator->getProperties(); properties->setProperty("Ice.PrintAdapterReady", "0"); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("Hello", "default"); adapter->setLocator(locator); Ice::Identity id; id.name = IceUtil::generateUUID(); registry->addObject(adapter->add(ICE_MAKE_SHARED(HelloI), id)); adapter->activate(); HelloPrxPtr helloPrx = ICE_CHECKED_CAST(HelloPrx, communicator->stringToProxy(communicator->identityToString(id))); test(!helloPrx->ice_getConnection()); adapter->deactivate(); cout << "ok" << endl; } cout << "shutdown server manager... " << flush; manager->shutdown(); cout << "ok" << endl; }
void allTests(const Ice::CommunicatorPtr& communicator) { string ref = "communicator:" + getTestEndpoint(communicator, 0); RemoteCommunicatorPrxPtr com = ICE_UNCHECKED_CAST(RemoteCommunicatorPrx, communicator->stringToProxy(ref)); RandomNumberGenerator rng; cout << "testing binding with single endpoint... " << flush; { RemoteObjectAdapterPrxPtr adapter = com->createObjectAdapter("Adapter", "default"); TestIntfPrxPtr test1 = adapter->getTestIntf(); TestIntfPrxPtr test2 = adapter->getTestIntf(); test(test1->ice_getConnection() == test2->ice_getConnection()); test1->ice_ping(); test2->ice_ping(); com->deactivateObjectAdapter(adapter); TestIntfPrxPtr test3 = ICE_UNCHECKED_CAST(TestIntfPrx, test1); test(test3->ice_getConnection() == test1->ice_getConnection()); test(test3->ice_getConnection() == test2->ice_getConnection()); try { test3->ice_ping(); test(false); } catch(const Ice::ConnectFailedException&) { } } cout << "ok" << endl; cout << "testing binding with multiple endpoints... " << flush; { vector<RemoteObjectAdapterPrxPtr> adapters; adapters.push_back(com->createObjectAdapter("Adapter11", "default")); adapters.push_back(com->createObjectAdapter("Adapter12", "default")); adapters.push_back(com->createObjectAdapter("Adapter13", "default")); // // Ensure that when a connection is opened it's reused for new // proxies and that all endpoints are eventually tried. // set<string> names; names.insert("Adapter11"); names.insert("Adapter12"); names.insert("Adapter13"); while(!names.empty()) { vector<RemoteObjectAdapterPrxPtr> adpts = adapters; TestIntfPrxPtr test1 = createTestIntfPrx(adpts); random_shuffle(adpts.begin(), adpts.end(), rng); TestIntfPrxPtr test2 = createTestIntfPrx(adpts); random_shuffle(adpts.begin(), adpts.end(), rng); TestIntfPrxPtr test3 = createTestIntfPrx(adpts); test(test1->ice_getConnection() == test2->ice_getConnection()); test(test2->ice_getConnection() == test3->ice_getConnection()); names.erase(test1->getAdapterName()); test1->ice_getConnection()->close(false); } // // Ensure that the proxy correctly caches the connection (we // always send the request over the same connection.) // { for(vector<RemoteObjectAdapterPrxPtr>::const_iterator p = adapters.begin(); p != adapters.end(); ++p) { (*p)->getTestIntf()->ice_ping(); } TestIntfPrxPtr test = createTestIntfPrx(adapters); string name = test->getAdapterName(); const int nRetry = 10; int i; for(i = 0; i < nRetry && test->getAdapterName() == name; i++); test(i == nRetry); for(vector<RemoteObjectAdapterPrxPtr>::const_iterator q = adapters.begin(); q != adapters.end(); ++q) { (*q)->getTestIntf()->ice_getConnection()->close(false); } } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapters. // com->deactivateObjectAdapter(adapters[0]); names.insert("Adapter12"); names.insert("Adapter13"); while(!names.empty()) { vector<RemoteObjectAdapterPrxPtr> adpts = adapters; TestIntfPrxPtr test1 = createTestIntfPrx(adpts); random_shuffle(adpts.begin(), adpts.end(), rng); TestIntfPrxPtr test2 = createTestIntfPrx(adpts); random_shuffle(adpts.begin(), adpts.end(), rng); TestIntfPrxPtr test3 = createTestIntfPrx(adpts); test(test1->ice_getConnection() == test2->ice_getConnection()); test(test2->ice_getConnection() == test3->ice_getConnection()); names.erase(test1->getAdapterName()); test1->ice_getConnection()->close(false); } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapter. // com->deactivateObjectAdapter(adapters[2]); TestIntfPrxPtr test = createTestIntfPrx(adapters); test(test->getAdapterName() == "Adapter12"); deactivate(com, adapters); } cout << "ok" << endl; cout << "testing binding with multiple random endpoints... " << flush; { vector<RemoteObjectAdapterPrxPtr> adapters; adapters.push_back(com->createObjectAdapter("AdapterRandom11", "default")); adapters.push_back(com->createObjectAdapter("AdapterRandom12", "default")); adapters.push_back(com->createObjectAdapter("AdapterRandom13", "default")); adapters.push_back(com->createObjectAdapter("AdapterRandom14", "default")); adapters.push_back(com->createObjectAdapter("AdapterRandom15", "default")); #ifdef _WIN32 int count = 60; #else int count = 20; #endif int adapterCount = static_cast<int>(adapters.size()); while(--count > 0) { #ifdef _WIN32 if(count == 10) { com->deactivateObjectAdapter(adapters[4]); --adapterCount; } vector<TestIntfPrxPtr> proxies; proxies.resize(10); #else if(count < 60 && count % 10 == 0) { com->deactivateObjectAdapter(adapters[count / 10 - 1]); --adapterCount; } vector<TestIntfPrxPtr> proxies; proxies.resize(40); #endif unsigned int i; for(i = 0; i < proxies.size(); ++i) { vector<RemoteObjectAdapterPrxPtr> adpts; adpts.resize(IceUtilInternal::random(static_cast<int>(adapters.size()))); if(adpts.empty()) { adpts.resize(1); } for(vector<RemoteObjectAdapterPrxPtr>::iterator p = adpts.begin(); p != adpts.end(); ++p) { *p = adapters[IceUtilInternal::random(static_cast<int>(adapters.size()))]; } proxies[i] = createTestIntfPrx(adpts); } for(i = 0; i < proxies.size(); i++) { #ifdef ICE_CPP11_MAPPING proxies[i]->getAdapterName_async(); #else proxies[i]->begin_getAdapterName(); #endif } for(i = 0; i < proxies.size(); i++) { try { proxies[i]->ice_ping(); } catch(const Ice::LocalException&) { } } set<Ice::ConnectionPtr> connections; for(i = 0; i < proxies.size(); i++) { if(proxies[i]->ice_getCachedConnection()) { connections.insert(proxies[i]->ice_getCachedConnection()); } } test(static_cast<int>(connections.size()) <= adapterCount); for(vector<RemoteObjectAdapterPrxPtr>::const_iterator q = adapters.begin(); q != adapters.end(); ++q) { try { (*q)->getTestIntf()->ice_getConnection()->close(false); } catch(const Ice::LocalException&) { // Expected if adapter is down. } } } } cout << "ok" << endl; cout << "testing binding with multiple endpoints and AMI... " << flush; { vector<RemoteObjectAdapterPrxPtr> adapters; adapters.push_back(com->createObjectAdapter("AdapterAMI11", "default")); adapters.push_back(com->createObjectAdapter("AdapterAMI12", "default")); adapters.push_back(com->createObjectAdapter("AdapterAMI13", "default")); // // Ensure that when a connection is opened it's reused for new // proxies and that all endpoints are eventually tried. // set<string> names; names.insert("AdapterAMI11"); names.insert("AdapterAMI12"); names.insert("AdapterAMI13"); while(!names.empty()) { vector<RemoteObjectAdapterPrxPtr> adpts = adapters; TestIntfPrxPtr test1 = createTestIntfPrx(adpts); random_shuffle(adpts.begin(), adpts.end(), rng); TestIntfPrxPtr test2 = createTestIntfPrx(adpts); random_shuffle(adpts.begin(), adpts.end(), rng); TestIntfPrxPtr test3 = createTestIntfPrx(adpts); test(test1->ice_getConnection() == test2->ice_getConnection()); test(test2->ice_getConnection() == test3->ice_getConnection()); names.erase(getAdapterNameWithAMI(test1)); test1->ice_getConnection()->close(false); } // // Ensure that the proxy correctly caches the connection (we // always send the request over the same connection.) // { for(vector<RemoteObjectAdapterPrxPtr>::const_iterator p = adapters.begin(); p != adapters.end(); ++p) { (*p)->getTestIntf()->ice_ping(); } TestIntfPrxPtr test = createTestIntfPrx(adapters); string name = getAdapterNameWithAMI(test); const int nRetry = 10; int i; for(i = 0; i < nRetry && getAdapterNameWithAMI(test) == name; i++); test(i == nRetry); for(vector<RemoteObjectAdapterPrxPtr>::const_iterator q = adapters.begin(); q != adapters.end(); ++q) { (*q)->getTestIntf()->ice_getConnection()->close(false); } } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapters. // com->deactivateObjectAdapter(adapters[0]); names.insert("AdapterAMI12"); names.insert("AdapterAMI13"); while(!names.empty()) { vector<RemoteObjectAdapterPrxPtr> adpts = adapters; TestIntfPrxPtr test1 = createTestIntfPrx(adpts); random_shuffle(adpts.begin(), adpts.end(), rng); TestIntfPrxPtr test2 = createTestIntfPrx(adpts); random_shuffle(adpts.begin(), adpts.end(), rng); TestIntfPrxPtr test3 = createTestIntfPrx(adpts); test(test1->ice_getConnection() == test2->ice_getConnection()); test(test2->ice_getConnection() == test3->ice_getConnection()); names.erase(test1->getAdapterName()); test1->ice_getConnection()->close(false); } // // Deactivate an adapter and ensure that we can still // establish the connection to the remaining adapter. // com->deactivateObjectAdapter(adapters[2]); TestIntfPrxPtr test = createTestIntfPrx(adapters); test(test->getAdapterName() == "AdapterAMI12"); deactivate(com, adapters); } cout << "ok" << endl; cout << "testing random endpoint selection... " << flush; { vector<RemoteObjectAdapterPrxPtr> adapters; adapters.push_back(com->createObjectAdapter("Adapter21", "default")); adapters.push_back(com->createObjectAdapter("Adapter22", "default")); adapters.push_back(com->createObjectAdapter("Adapter23", "default")); TestIntfPrxPtr test = createTestIntfPrx(adapters); test(test->ice_getEndpointSelection() == Ice::Random); set<string> names; names.insert("Adapter21"); names.insert("Adapter22"); names.insert("Adapter23"); while(!names.empty()) { names.erase(test->getAdapterName()); test->ice_getConnection()->close(false); } test = ICE_UNCHECKED_CAST(TestIntfPrx, test->ice_endpointSelection(Ice::Random)); test(test->ice_getEndpointSelection() == Ice::Random); names.insert("Adapter21"); names.insert("Adapter22"); names.insert("Adapter23"); while(!names.empty()) { names.erase(test->getAdapterName()); test->ice_getConnection()->close(false); } deactivate(com, adapters); } cout << "ok" << endl; cout << "testing ordered endpoint selection... " << flush; { vector<RemoteObjectAdapterPrxPtr> adapters; adapters.push_back(com->createObjectAdapter("Adapter31", "default")); adapters.push_back(com->createObjectAdapter("Adapter32", "default")); adapters.push_back(com->createObjectAdapter("Adapter33", "default")); TestIntfPrxPtr test = createTestIntfPrx(adapters); test = ICE_UNCHECKED_CAST(TestIntfPrx, test->ice_endpointSelection(Ice::Ordered)); test(test->ice_getEndpointSelection() == Ice::Ordered); const int nRetry = 5; int i; // // Ensure that endpoints are tried in order by deactiving the adapters // one after the other. // for(i = 0; i < nRetry && test->getAdapterName() == "Adapter31"; i++); #if TARGET_OS_IPHONE > 0 if(i != nRetry) { test->ice_getConnection()->close(false); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter31"; i++); } #endif test(i == nRetry); com->deactivateObjectAdapter(adapters[0]); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter32"; i++); #if TARGET_OS_IPHONE > 0 if(i != nRetry) { test->ice_getConnection()->close(false); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter32"; i++); } #endif test(i == nRetry); com->deactivateObjectAdapter(adapters[1]); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter33"; i++); #if TARGET_OS_IPHONE > 0 if(i != nRetry) { test->ice_getConnection()->close(false); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter33"; i++); } #endif test(i == nRetry); com->deactivateObjectAdapter(adapters[2]); try { test->getAdapterName(); } catch(const Ice::ConnectFailedException&) { } Ice::EndpointSeq endpoints = test->ice_getEndpoints(); adapters.clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.push_back(com->createObjectAdapter("Adapter36", endpoints[2]->toString())); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter36"; i++); #if TARGET_OS_IPHONE > 0 if(i != nRetry) { test->ice_getConnection()->close(false); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter36"; i++); } #endif test(i == nRetry); test->ice_getConnection()->close(false); adapters.push_back(com->createObjectAdapter("Adapter35", endpoints[1]->toString())); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter35"; i++); #if TARGET_OS_IPHONE > 0 if(i != nRetry) { test->ice_getConnection()->close(false); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter35"; i++); } #endif test(i == nRetry); test->ice_getConnection()->close(false); adapters.push_back(com->createObjectAdapter("Adapter34", endpoints[0]->toString())); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter34"; i++); #if TARGET_OS_IPHONE > 0 if(i != nRetry) { test->ice_getConnection()->close(false); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter34"; i++); } #endif test(i == nRetry); deactivate(com, adapters); } cout << "ok" << endl; cout << "testing per request binding with single endpoint... " << flush; { RemoteObjectAdapterPrxPtr adapter = com->createObjectAdapter("Adapter41", "default"); TestIntfPrxPtr test1 = ICE_UNCHECKED_CAST(TestIntfPrx, adapter->getTestIntf()->ice_connectionCached(false)); TestIntfPrxPtr test2 = ICE_UNCHECKED_CAST(TestIntfPrx, adapter->getTestIntf()->ice_connectionCached(false)); test(!test1->ice_isConnectionCached()); test(!test2->ice_isConnectionCached()); test(test1->ice_getConnection() == test2->ice_getConnection()); test1->ice_ping(); com->deactivateObjectAdapter(adapter); TestIntfPrxPtr test3 = ICE_UNCHECKED_CAST(TestIntfPrx, test1); try { test(test3->ice_getConnection() == test1->ice_getConnection()); test(false); } catch(const Ice::ConnectFailedException&) { } } cout << "ok" << endl; cout << "testing per request binding with multiple endpoints... " << flush; { vector<RemoteObjectAdapterPrxPtr> adapters; adapters.push_back(com->createObjectAdapter("Adapter51", "default")); adapters.push_back(com->createObjectAdapter("Adapter52", "default")); adapters.push_back(com->createObjectAdapter("Adapter53", "default")); TestIntfPrxPtr test = ICE_UNCHECKED_CAST(TestIntfPrx, createTestIntfPrx(adapters)->ice_connectionCached(false)); test(!test->ice_isConnectionCached()); set<string> names; names.insert("Adapter51"); names.insert("Adapter52"); names.insert("Adapter53"); while(!names.empty()) { names.erase(test->getAdapterName()); } com->deactivateObjectAdapter(adapters[0]); names.insert("Adapter52"); names.insert("Adapter53"); while(!names.empty()) { names.erase(test->getAdapterName()); } com->deactivateObjectAdapter(adapters[2]); test(test->getAdapterName() == "Adapter52"); deactivate(com, adapters); } cout << "ok" << endl; cout << "testing per request binding with multiple endpoints and AMI... " << flush; { vector<RemoteObjectAdapterPrxPtr> adapters; adapters.push_back(com->createObjectAdapter("AdapterAMI51", "default")); adapters.push_back(com->createObjectAdapter("AdapterAMI52", "default")); adapters.push_back(com->createObjectAdapter("AdapterAMI53", "default")); TestIntfPrxPtr test = ICE_UNCHECKED_CAST(TestIntfPrx, createTestIntfPrx(adapters)->ice_connectionCached(false)); test(!test->ice_isConnectionCached()); set<string> names; names.insert("AdapterAMI51"); names.insert("AdapterAMI52"); names.insert("AdapterAMI53"); while(!names.empty()) { names.erase(getAdapterNameWithAMI(test)); } com->deactivateObjectAdapter(adapters[0]); names.insert("AdapterAMI52"); names.insert("AdapterAMI53"); while(!names.empty()) { names.erase(getAdapterNameWithAMI(test)); } com->deactivateObjectAdapter(adapters[2]); test(test->getAdapterName() == "AdapterAMI52"); deactivate(com, adapters); } cout << "ok" << endl; cout << "testing per request binding and ordered endpoint selection... " << flush; { vector<RemoteObjectAdapterPrxPtr> adapters; adapters.push_back(com->createObjectAdapter("Adapter61", "default")); adapters.push_back(com->createObjectAdapter("Adapter62", "default")); adapters.push_back(com->createObjectAdapter("Adapter63", "default")); TestIntfPrxPtr test = createTestIntfPrx(adapters); test = ICE_UNCHECKED_CAST(TestIntfPrx, test->ice_endpointSelection(Ice::Ordered)); test(test->ice_getEndpointSelection() == Ice::Ordered); test = ICE_UNCHECKED_CAST(TestIntfPrx, test->ice_connectionCached(false)); test(!test->ice_isConnectionCached()); const int nRetry = 5; int i; // // Ensure that endpoints are tried in order by deactiving the adapters // one after the other. // for(i = 0; i < nRetry && test->getAdapterName() == "Adapter61"; i++); #if TARGET_OS_IPHONE > 0 test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. #else test(i == nRetry); #endif com->deactivateObjectAdapter(adapters[0]); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter62"; i++); #if TARGET_OS_IPHONE > 0 test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. #else test(i == nRetry); #endif com->deactivateObjectAdapter(adapters[1]); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter63"; i++); #if TARGET_OS_IPHONE > 0 test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. #else test(i == nRetry); #endif com->deactivateObjectAdapter(adapters[2]); try { test->getAdapterName(); } catch(const Ice::ConnectFailedException&) { } Ice::EndpointSeq endpoints = test->ice_getEndpoints(); adapters.clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.push_back(com->createObjectAdapter("Adapter66", endpoints[2]->toString())); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter66"; i++); #if TARGET_OS_IPHONE > 0 test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. #else test(i == nRetry); #endif adapters.push_back(com->createObjectAdapter("Adapter65", endpoints[1]->toString())); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter65"; i++); #if TARGET_OS_IPHONE > 0 test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. #else test(i == nRetry); #endif adapters.push_back(com->createObjectAdapter("Adapter64", endpoints[0]->toString())); for(i = 0; i < nRetry && test->getAdapterName() == "Adapter64"; i++); #if TARGET_OS_IPHONE > 0 test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. #else test(i == nRetry); #endif deactivate(com, adapters); } cout << "ok" << endl; cout << "testing per request binding and ordered endpoint selection and AMI... " << flush; { vector<RemoteObjectAdapterPrxPtr> adapters; adapters.push_back(com->createObjectAdapter("AdapterAMI61", "default")); adapters.push_back(com->createObjectAdapter("AdapterAMI62", "default")); adapters.push_back(com->createObjectAdapter("AdapterAMI63", "default")); TestIntfPrxPtr test = createTestIntfPrx(adapters); test = ICE_UNCHECKED_CAST(TestIntfPrx, test->ice_endpointSelection(Ice::Ordered)); test(test->ice_getEndpointSelection() == Ice::Ordered); test = ICE_UNCHECKED_CAST(TestIntfPrx, test->ice_connectionCached(false)); test(!test->ice_isConnectionCached()); const int nRetry = 5; int i; // // Ensure that endpoints are tried in order by deactiving the adapters // one after the other. // for(i = 0; i < nRetry && getAdapterNameWithAMI(test) == "AdapterAMI61"; i++); #if TARGET_OS_IPHONE > 0 test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. #else test(i == nRetry); #endif com->deactivateObjectAdapter(adapters[0]); for(i = 0; i < nRetry && getAdapterNameWithAMI(test) == "AdapterAMI62"; i++); #if TARGET_OS_IPHONE > 0 test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. #else test(i == nRetry); #endif com->deactivateObjectAdapter(adapters[1]); for(i = 0; i < nRetry && getAdapterNameWithAMI(test) == "AdapterAMI63"; i++); #if TARGET_OS_IPHONE > 0 test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. #else test(i == nRetry); #endif com->deactivateObjectAdapter(adapters[2]); try { test->getAdapterName(); } catch(const Ice::ConnectFailedException&) { } Ice::EndpointSeq endpoints = test->ice_getEndpoints(); adapters.clear(); // // Now, re-activate the adapters with the same endpoints in the opposite // order. // adapters.push_back(com->createObjectAdapter("AdapterAMI66", endpoints[2]->toString())); for(i = 0; i < nRetry && getAdapterNameWithAMI(test) == "AdapterAMI66"; i++); #if TARGET_OS_IPHONE > 0 test(i >= nRetry - 1); // WORKAROUND: for connection establishment hang. #else test(i == nRetry); #endif adapters.push_back(com->createObjectAdapter("AdapterAMI65", endpoints[1]->toString())); for(i = 0; i < nRetry && getAdapterNameWithAMI(test) == "AdapterAMI65"; i++); test(i == nRetry); adapters.push_back(com->createObjectAdapter("AdapterAMI64", endpoints[0]->toString())); for(i = 0; i < nRetry && getAdapterNameWithAMI(test) == "AdapterAMI64"; i++); test(i == nRetry); deactivate(com, adapters); } cout << "ok" << endl; cout << "testing endpoint mode filtering... " << flush; { vector<RemoteObjectAdapterPrxPtr> adapters; adapters.push_back(com->createObjectAdapter("Adapter71", "default")); adapters.push_back(com->createObjectAdapter("Adapter72", "udp")); TestIntfPrxPtr test = createTestIntfPrx(adapters); test(test->getAdapterName() == "Adapter71"); TestIntfPrxPtr testUDP = ICE_UNCHECKED_CAST(TestIntfPrx, test->ice_datagram()); test(test->ice_getConnection() != testUDP->ice_getConnection()); try { testUDP->getAdapterName(); } catch(const Ice::TwowayOnlyException&) { } catch(const IceUtil::IllegalArgumentException&) { } } cout << "ok" << endl; if(!communicator->getProperties()->getProperty("Ice.Plugin.IceSSL").empty() && communicator->getProperties()->getProperty("Ice.Default.Protocol") == "ssl") { cout << "testing unsecure vs. secure endpoints... " << flush; { vector<RemoteObjectAdapterPrxPtr> adapters; adapters.push_back(com->createObjectAdapter("Adapter81", "ssl")); adapters.push_back(com->createObjectAdapter("Adapter82", "tcp")); TestIntfPrxPtr test = createTestIntfPrx(adapters); int i; for(i = 0; i < 5; i++) { test(test->getAdapterName() == "Adapter82"); test->ice_getConnection()->close(false); } TestIntfPrxPtr testSecure = ICE_UNCHECKED_CAST(TestIntfPrx, test->ice_secure(true)); test(testSecure->ice_isSecure()); testSecure = ICE_UNCHECKED_CAST(TestIntfPrx, test->ice_secure(false)); test(!testSecure->ice_isSecure()); testSecure = ICE_UNCHECKED_CAST(TestIntfPrx, test->ice_secure(true)); test(testSecure->ice_isSecure()); test(test->ice_getConnection() != testSecure->ice_getConnection()); com->deactivateObjectAdapter(adapters[1]); for(i = 0; i < 5; i++) { test(test->getAdapterName() == "Adapter81"); test->ice_getConnection()->close(false); } com->createObjectAdapter("Adapter83", (test->ice_getEndpoints()[1])->toString()); // Reactive tcp OA. for(i = 0; i < 5; i++) { test(test->getAdapterName() == "Adapter83"); test->ice_getConnection()->close(false); } com->deactivateObjectAdapter(adapters[0]); try { testSecure->ice_ping(); test(false); } catch(const Ice::ConnectFailedException&) { } deactivate(com, adapters); } cout << "ok" << endl; } { cout << "testing ipv4 & ipv6 connections... " << flush; Ice::PropertiesPtr ipv4 = Ice::createProperties(); ipv4->setProperty("Ice.IPv4", "1"); ipv4->setProperty("Ice.IPv6", "0"); ipv4->setProperty("Adapter.Endpoints", "tcp -h localhost"); Ice::PropertiesPtr ipv6 = Ice::createProperties(); ipv6->setProperty("Ice.IPv4", "0"); ipv6->setProperty("Ice.IPv6", "1"); ipv6->setProperty("Adapter.Endpoints", "tcp -h localhost"); Ice::PropertiesPtr bothPreferIPv4 = Ice::createProperties(); bothPreferIPv4->setProperty("Ice.IPv4", "1"); bothPreferIPv4->setProperty("Ice.IPv6", "1"); bothPreferIPv4->setProperty("Ice.PreferIPv6Address", "0"); bothPreferIPv4->setProperty("Adapter.Endpoints", "tcp -h localhost"); Ice::PropertiesPtr bothPreferIPv6 = Ice::createProperties(); bothPreferIPv6->setProperty("Ice.IPv4", "1"); bothPreferIPv6->setProperty("Ice.IPv6", "1"); bothPreferIPv6->setProperty("Ice.PreferIPv6Address", "1"); bothPreferIPv6->setProperty("Adapter.Endpoints", "tcp -h localhost"); vector<Ice::PropertiesPtr> clientProps; clientProps.push_back(ipv4); clientProps.push_back(ipv6); clientProps.push_back(bothPreferIPv4); clientProps.push_back(bothPreferIPv6); Ice::PropertiesPtr anyipv4 = ipv4->clone(); anyipv4->setProperty("Adapter.Endpoints", "tcp -p 12012"); anyipv4->setProperty("Adapter.PublishedEndpoints", "tcp -h 127.0.0.1 -p 12012"); Ice::PropertiesPtr anyipv6 = ipv6->clone(); anyipv6->setProperty("Adapter.Endpoints", "tcp -p 12012"); anyipv6->setProperty("Adapter.PublishedEndpoints", "tcp -h \"::1\" -p 12012"); Ice::PropertiesPtr anyboth = Ice::createProperties(); anyboth->setProperty("Ice.IPv4", "1"); anyboth->setProperty("Ice.IPv6", "1"); anyboth->setProperty("Adapter.Endpoints", "tcp -p 12012"); anyboth->setProperty("Adapter.PublishedEndpoints", "tcp -h \"::1\" -p 12012:tcp -h 127.0.0.1 -p 12012"); Ice::PropertiesPtr localipv4 = ipv4->clone(); localipv4->setProperty("Adapter.Endpoints", "tcp -h 127.0.0.1"); Ice::PropertiesPtr localipv6 = ipv6->clone(); localipv6->setProperty("Adapter.Endpoints", "tcp -h \"::1\""); vector<Ice::PropertiesPtr> serverProps = clientProps; serverProps.push_back(anyipv4); serverProps.push_back(anyipv6); serverProps.push_back(anyboth); serverProps.push_back(localipv4); serverProps.push_back(localipv6); #if defined(_WIN32) && !defined(ICE_OS_WINRT) OSVERSIONINFO ver; ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); # if defined(_MSC_VER) && _MSC_VER >= 1800 # pragma warning (disable : 4996) # endif GetVersionEx(&ver); # if defined(_MSC_VER) && _MSC_VER >= 1800 # pragma warning (default : 4996) # endif const bool dualStack = ver.dwMajorVersion >= 6; // Windows XP IPv6 doesn't support dual-stack #else const bool dualStack = true; #endif bool ipv6NotSupported = false; for(vector<Ice::PropertiesPtr>::const_iterator p = serverProps.begin(); p != serverProps.end(); ++p) { Ice::InitializationData serverInitData; serverInitData.properties = *p; Ice::CommunicatorPtr serverCommunicator = Ice::initialize(serverInitData); Ice::ObjectAdapterPtr oa; try { oa = serverCommunicator->createObjectAdapter("Adapter"); oa->activate(); } catch(const Ice::DNSException&) { serverCommunicator->destroy(); continue; // IP version not supported. } catch(const Ice::SocketException&) { if(*p == ipv6) { ipv6NotSupported = true; } serverCommunicator->destroy(); continue; // IP version not supported. } // Ensure the published endpoints are actually valid. On // Fedora, binding to "localhost" with IPv6 only works but // resolving localhost don't return the IPv6 adress. Ice::ObjectPrxPtr prx = oa->createProxy(serverCommunicator->stringToIdentity("dummy")); try { prx->ice_collocationOptimized(false)->ice_ping(); } catch(const Ice::LocalException&) { serverCommunicator->destroy(); continue; // IP version not supported. } string strPrx = prx->ice_toString(); for(vector<Ice::PropertiesPtr>::const_iterator q = clientProps.begin(); q != clientProps.end(); ++q) { Ice::InitializationData clientInitData; clientInitData.properties = *q; Ice::CommunicatorHolder clientCommunicator = Ice::initialize(clientInitData); Ice::ObjectPrxPtr prx = clientCommunicator->stringToProxy(strPrx); try { prx->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { // Expected, no object registered. } catch(const Ice::DNSException&) { // Expected if no IPv4 or IPv6 address is // associated to localhost or if trying to connect // to an any endpoint with the wrong IP version, // e.g.: resolving an IPv4 address when only IPv6 // is enabled fails with a DNS exception. } catch(const Ice::SocketException&) { test((*p == ipv4 && *q == ipv6) || (*p == ipv6 && *q == ipv4) || (*p == bothPreferIPv4 && *q == ipv6) || (*p == bothPreferIPv6 && *q == ipv4) || (*p == bothPreferIPv6 && *q == ipv6 && ipv6NotSupported) || (*p == anyipv4 && *q == ipv6) || (*p == anyipv6 && *q == ipv4) || (*p == anyboth && *q == ipv4 && !dualStack) || (*p == localipv4 && *q == ipv6) || (*p == localipv6 && *q == ipv4) || (*p == ipv6 && *q == bothPreferIPv4) || (*p == ipv6 && *q == bothPreferIPv6) || (*p == bothPreferIPv6 && *q == ipv6)); } } serverCommunicator->destroy(); } cout << "ok" << endl; } com->shutdown(); }
TestIntfPrxPtr allTests(const CommunicatorPtr& communicator) { const string endp = getTestEndpoint(communicator, 0); cout << "testing stringToProxy... " << flush; ObjectPrxPtr base = communicator->stringToProxy("asm:" + endp); test(base); cout << "ok" << endl; cout << "testing checked cast... " << flush; TestIntfPrxPtr obj = ICE_CHECKED_CAST(TestIntfPrx, base); test(obj); #ifdef ICE_CPP11_MAPPING test(Ice::targetEquals(obj, base)); #else test(obj == base); #endif cout << "ok" << endl; cout << "testing ice_ids... " << flush; try { ObjectPrxPtr o = communicator->stringToProxy("category/locate:" + endp); o->ice_ids(); test(false); } catch(const UnknownUserException& ex) { test(ex.unknown == "::Test::TestIntfUserException"); } catch(...) { test(false); } try { ObjectPrxPtr o = communicator->stringToProxy("category/finished:" + endp); o->ice_ids(); test(false); } catch(const UnknownUserException& ex) { test(ex.unknown == "::Test::TestIntfUserException"); } catch(...) { test(false); } cout << "ok" << endl; cout << "testing servant locator..." << flush; base = communicator->stringToProxy("category/locate:" + endp); obj = ICE_CHECKED_CAST(TestIntfPrx, base); try { ICE_CHECKED_CAST(TestIntfPrx, communicator->stringToProxy("category/unknown:" + getTestEndpoint(communicator, 0))); } catch(const ObjectNotExistException&) { } cout << "ok" << endl; cout << "testing default servant locator..." << flush; base = communicator->stringToProxy("anothercategory/locate:" + endp); obj = ICE_CHECKED_CAST(TestIntfPrx, base); base = communicator->stringToProxy("locate:" + endp); obj = ICE_CHECKED_CAST(TestIntfPrx, base); try { ICE_CHECKED_CAST(TestIntfPrx, communicator->stringToProxy("anothercategory/unknown:" + getTestEndpoint(communicator, 0))); } catch(const ObjectNotExistException&) { } try { ICE_CHECKED_CAST(TestIntfPrx, communicator->stringToProxy("unknown:" + endp)); } catch(const Ice::ObjectNotExistException&) { } cout << "ok" << endl; cout << "testing locate exceptions... " << flush; base = communicator->stringToProxy("category/locate:" + endp); obj = ICE_CHECKED_CAST(TestIntfPrx, base); testExceptions(obj); cout << "ok" << endl; cout << "testing finished exceptions... " << flush; base = communicator->stringToProxy("category/finished:" + endp); obj = ICE_CHECKED_CAST(TestIntfPrx, base); testExceptions(obj); // // Only call these for category/finished. // try { obj->asyncResponse(); } catch(const TestIntfUserException&) { test(false); } catch(const TestImpossibleException&) { // // Called by finished(). // } try { obj->asyncException(); } catch(const TestIntfUserException&) { test(false); } catch(const TestImpossibleException&) { // // Called by finished(). // } cout << "ok" << endl; cout << "testing servant locator removal... " << flush; base = communicator->stringToProxy("test/activation:" + endp); TestActivationPrxPtr activation = ICE_CHECKED_CAST(TestActivationPrx, base); activation->activateServantLocator(false); try { obj->ice_ping(); test(false); } catch(const Ice::ObjectNotExistException&) { cout << "ok" << endl; } cout << "testing servant locator addition... " << flush; activation->activateServantLocator(true); try { obj->ice_ping(); cout << "ok" << endl; } catch(...) { test(false); } return obj; }
void testExceptions(const TestIntfPrxPtr& obj) { try { obj->requestFailedException(); test(false); } catch(const ObjectNotExistException& ex) { test(ex.id == obj->ice_getIdentity()); test(ex.facet == obj->ice_getFacet()); test(ex.operation == "requestFailedException"); } catch(...) { test(false); } try { obj->unknownUserException(); test(false); } catch(const UnknownUserException& ex) { test(ex.unknown == "reason"); } catch(...) { test(false); } try { obj->unknownLocalException(); test(false); } catch(const UnknownLocalException& ex) { test(ex.unknown == "reason"); } catch(...) { test(false); } try { obj->unknownException(); test(false); } catch(const UnknownException& ex) { test(ex.unknown == "reason"); } catch(...) { test(false); } try { obj->userException(); test(false); } catch(const UnknownUserException& ex) { test(ex.unknown == "::Test::TestIntfUserException"); } catch(const Ice::OperationNotExistException&) { } catch(...) { test(false); } try { obj->localException(); test(false); } catch(const UnknownLocalException& ex) { test(ex.unknown.find("Ice::SocketException") != string::npos); } catch(...) { test(false); } try { obj->stdException(); test(false); } catch(const Ice::OperationNotExistException&) { } catch(const UnknownException& ex) { test(ex.unknown == "std::exception: Hello"); } catch(...) { test(false); } try { obj->cppException(); test(false); } catch(const UnknownException& ex) { test(ex.unknown == "unknown c++ exception"); } catch(const Ice::OperationNotExistException&) { } catch(...) { test(false); } try { obj->unknownExceptionWithServantException(); test(false); } catch(const UnknownException& ex) { test(ex.unknown == "reason"); } catch(...) { test(false); } try { obj->impossibleException(false); test(false); } catch(const UnknownUserException&) { // Operation doesn't throw, but locate() and finished() throw TestIntfUserException. } catch(...) { test(false); } try { obj->impossibleException(true); test(false); } catch(const UnknownUserException&) { // Operation doesn't throw, but locate() and finished() throw TestIntfUserException. } catch(...) { test(false); } try { obj->intfUserException(false); test(false); } catch(const TestImpossibleException&) { // Operation doesn't throw, but locate() and finished() throw TestImpossibleException. } catch(...) { test(false); } try { obj->intfUserException(true); test(false); } catch(const TestImpossibleException&) { // Operation throws TestIntfUserException, but locate() and finished() throw TestImpossibleException. } catch(...) { test(false); } }