diff options
Diffstat (limited to 'cpp/test')
-rw-r--r-- | cpp/test/Ice/background/EndpointI.cpp | 8 | ||||
-rw-r--r-- | cpp/test/Ice/background/EndpointI.h | 4 | ||||
-rw-r--r-- | cpp/test/Ice/binding/AllTests.cpp | 118 | ||||
-rw-r--r-- | cpp/test/Ice/stringConverter/Client.cpp | 4 |
4 files changed, 127 insertions, 7 deletions
diff --git a/cpp/test/Ice/background/EndpointI.cpp b/cpp/test/Ice/background/EndpointI.cpp index 52e2a23e513..33a3ba3b744 100644 --- a/cpp/test/Ice/background/EndpointI.cpp +++ b/cpp/test/Ice/background/EndpointI.cpp @@ -142,10 +142,10 @@ EndpointI::transceiver(IceInternal::EndpointIPtr& endpoint) const } vector<IceInternal::ConnectorPtr> -EndpointI::connectors() const +EndpointI::connectors(Ice::EndpointSelectionType selType) const { _configuration->checkConnectorsException(); - vector<IceInternal::ConnectorPtr> c = _endpoint->connectors(); + vector<IceInternal::ConnectorPtr> c = _endpoint->connectors(selType); for(vector<IceInternal::ConnectorPtr>::iterator p = c.begin(); p != c.end(); ++p) { *p = new Connector(*p); @@ -154,7 +154,7 @@ EndpointI::connectors() const } void -EndpointI::connectors_async(const IceInternal::EndpointI_connectorsPtr& cb) const +EndpointI::connectors_async(Ice::EndpointSelectionType selType, const IceInternal::EndpointI_connectorsPtr& cb) const { class Callback : public IceInternal::EndpointI_connectors { @@ -189,7 +189,7 @@ EndpointI::connectors_async(const IceInternal::EndpointI_connectorsPtr& cb) cons try { _configuration->checkConnectorsException(); - _endpoint->connectors_async(new Callback(cb)); + _endpoint->connectors_async(selType, new Callback(cb)); } catch(const Ice::LocalException& ex) { diff --git a/cpp/test/Ice/background/EndpointI.h b/cpp/test/Ice/background/EndpointI.h index a3d1fcbef8c..27747143ce5 100644 --- a/cpp/test/Ice/background/EndpointI.h +++ b/cpp/test/Ice/background/EndpointI.h @@ -28,8 +28,8 @@ public: virtual IceInternal::EndpointIPtr connectionId(const ::std::string&) const; virtual IceInternal::EndpointIPtr compress(bool) const; virtual IceInternal::TransceiverPtr transceiver(IceInternal::EndpointIPtr&) const; - virtual std::vector<IceInternal::ConnectorPtr> connectors() const; - virtual void connectors_async(const IceInternal::EndpointI_connectorsPtr&) const; + virtual std::vector<IceInternal::ConnectorPtr> connectors(Ice::EndpointSelectionType) const; + virtual void connectors_async(Ice::EndpointSelectionType, const IceInternal::EndpointI_connectorsPtr&) const; virtual IceInternal::AcceptorPtr acceptor(IceInternal::EndpointIPtr&, const std::string&) const; virtual std::vector<IceInternal::EndpointIPtr> expand() const; virtual bool equivalent(const IceInternal::EndpointIPtr&) const; diff --git a/cpp/test/Ice/binding/AllTests.cpp b/cpp/test/Ice/binding/AllTests.cpp index d2e203eb571..4fa1956cd86 100644 --- a/cpp/test/Ice/binding/AllTests.cpp +++ b/cpp/test/Ice/binding/AllTests.cpp @@ -788,5 +788,123 @@ allTests(const Ice::CommunicatorPtr& communicator) 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); + + 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&) + { + continue; // IP version not supported. + } + catch(const Ice::SocketException&) + { + continue; // IP version not supported. + } + + string strPrx = oa->createProxy(serverCommunicator->stringToIdentity("dummy"))->ice_toString(); + for(vector<Ice::PropertiesPtr>::const_iterator q = clientProps.begin(); q != clientProps.end(); ++q) + { + Ice::InitializationData clientInitData; + clientInitData.properties = *q; + Ice::CommunicatorPtr clientCommunicator = Ice::initialize(clientInitData); + Ice::ObjectPrx 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 == anyipv4 && *q == ipv6) || (*p == anyipv6 && *q == ipv4) || + (*p == localipv4 && *q == ipv6) || (*p == localipv6 && *q == ipv4)); + continue; + } + clientCommunicator->destroy(); + } + serverCommunicator->destroy(); + } + + cout << "ok" << endl; + } + com->shutdown(); } diff --git a/cpp/test/Ice/stringConverter/Client.cpp b/cpp/test/Ice/stringConverter/Client.cpp index 048e2bf8f86..36c72599db0 100644 --- a/cpp/test/Ice/stringConverter/Client.cpp +++ b/cpp/test/Ice/stringConverter/Client.cpp @@ -132,7 +132,9 @@ Client::run(int, char*[]) // // Create server communicator and OA // - Ice::CommunicatorPtr serverCommunicator = Ice::initialize(); + Ice::InitializationData initData; + initData.properties = communicator()->getProperties()->clone(); + Ice::CommunicatorPtr serverCommunicator = Ice::initialize(initData); Ice::ObjectAdapterPtr oa = serverCommunicator->createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost"); Ice::ObjectPtr servant = new MyObjectI; |