Author: tabish Date: Tue Feb 9 15:47:43 2010 New Revision: 908082 URL: http://svn.apache.org/viewvc?rev=908082&view=rev Log: Fix for: http://issues.apache.org/activemq/browse/AMQCPP-285 with updated unit test. Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/ (props changed) activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/internal/net/URIHelper.cpp activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/internal/net/URIHelperTest.cpp activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/internal/net/URIHelperTest.h Propchange: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Tue Feb 9 15:47:43 2010 @@ -1 +1 @@ -/activemq/activemq-cpp/trunk:890958-890972,891025,902255 +/activemq/activemq-cpp/trunk:890958-890972,891025,902255,908080 Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/internal/net/URIHelper.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/internal/net/URIHelper.cpp?rev=908082&r1=908081&r2=908082&view=diff ============================================================================== --- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/internal/net/URIHelper.cpp (original) +++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/internal/net/URIHelper.cpp Tue Feb 9 15:47:43 2010 @@ -153,7 +153,7 @@ result.setPath( temp ); } - std::size_t pathIndex = 0; + std::size_t pathIndex = 0; if( index2 != std::string::npos ) { pathIndex += index2; } @@ -487,7 +487,7 @@ //////////////////////////////////////////////////////////////////////////////// bool URIHelper::isValidIPv4Address( const std::string& host ) { - std::size_t index; + std::size_t index; std::size_t index2; try { @@ -500,13 +500,13 @@ } index2 = host.find( '.', index + 1 ); - num = Integer::parseInt( host.substr( index + 1, index2 ) ); + num = Integer::parseInt( host.substr( index + 1, index2 - index - 1 ) ); if( num < 0 || num > 255 ) { return false; } index = host.find( '.', index2 + 1 ); - num = Integer::parseInt( host.substr( index2 + 1, index ) ); + num = Integer::parseInt( host.substr( index2 + 1, index - index2 - 1 ) ); if( num < 0 || num > 255 ) { return false; } Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/internal/net/URIHelperTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/internal/net/URIHelperTest.cpp?rev=908082&r1=908081&r2=908082&view=diff ============================================================================== --- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/internal/net/URIHelperTest.cpp (original) +++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/internal/net/URIHelperTest.cpp Tue Feb 9 15:47:43 2010 @@ -150,3 +150,41 @@ URISyntaxException ); } } + +//////////////////////////////////////////////////////////////////////////////// +void URIHelperTest::isValidIPv4Address() { + + URIHelper uriHelper; + + std::vector validIPs; + std::vector invalidIPs; + + validIPs.push_back( "127.0.0.1" ); + validIPs.push_back( "192.168.2.1" ); + validIPs.push_back( "255.255.255.255" ); + validIPs.push_back( "0.0.0.0" ); + validIPs.push_back( "1.12.123.0" ); + + invalidIPs.push_back( "256.66.2.1" ); + invalidIPs.push_back( "172.66.512.1" ); + invalidIPs.push_back( "172.257.12.1" ); + invalidIPs.push_back( "172.66.51.1024" ); + invalidIPs.push_back( "172.66..1" ); + invalidIPs.push_back( "172...1" ); + invalidIPs.push_back( "172..." ); + invalidIPs.push_back( ".0.0.0.0" ); + invalidIPs.push_back( "0.A.0.0" ); + invalidIPs.push_back( "0.1.0.0." ); + + std::vector::const_iterator address = validIPs.begin(); + for( ; address != validIPs.end(); ++address ) { + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Valid address tested as invalid", + true, uriHelper.isValidIPv4Address( *address ) ); + } + + address = invalidIPs.begin(); + for( ; address != invalidIPs.end(); ++address ) { + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Invalid address tested as valid", + false, uriHelper.isValidIPv4Address( *address ) ); + } +} Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/internal/net/URIHelperTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/internal/net/URIHelperTest.h?rev=908082&r1=908081&r2=908082&view=diff ============================================================================== --- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/internal/net/URIHelperTest.h (original) +++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/internal/net/URIHelperTest.h Tue Feb 9 15:47:43 2010 @@ -29,6 +29,7 @@ CPPUNIT_TEST_SUITE( URIHelperTest ); CPPUNIT_TEST( testParseURI ); + CPPUNIT_TEST( isValidIPv4Address ); CPPUNIT_TEST_SUITE_END(); public: @@ -37,6 +38,8 @@ virtual ~URIHelperTest() {} void testParseURI(); + void isValidIPv4Address(); + };