diff options
author | Benoit Foucher <benoit@zeroc.com> | 2013-02-11 16:07:16 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2013-02-11 16:07:16 +0100 |
commit | 0a52973ce569827357cfa9ac0a2e96c09ffbf7cc (patch) | |
tree | f219b25bebeca4f1e9e58e7174fe7870675b6246 /cpp/test/Ice/binding/AllTests.cpp | |
parent | Add Makefile.mak rule to register assemblies in source dir. (diff) | |
download | ice-0a52973ce569827357cfa9ac0a2e96c09ffbf7cc.tar.bz2 ice-0a52973ce569827357cfa9ac0a2e96c09ffbf7cc.tar.xz ice-0a52973ce569827357cfa9ac0a2e96c09ffbf7cc.zip |
Fixed ICE-5215: IPv6 support enabled by default
Diffstat (limited to 'cpp/test/Ice/binding/AllTests.cpp')
-rw-r--r-- | cpp/test/Ice/binding/AllTests.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
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(); } |