harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r390043 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/InetSocketAddress.java test/java/tests/api/java/net/AllTests.java test/java/tests/api/java/net/InetSocketAddressTest.java
Date Thu, 30 Mar 2006 09:29:26 GMT
Author: tellison
Date: Thu Mar 30 01:29:24 2006
New Revision: 390043

URL: http://svn.apache.org/viewcvs?rev=390043&view=rev
Log:
Apply patch HARMONY-224 (java.net.InetSocketAddress: one new J2SE 5 method "createUnresolved"
has not been implemented in Harmony)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetSocketAddressTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetSocketAddress.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetSocketAddress.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetSocketAddress.java?rev=390043&r1=390042&r2=390043&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetSocketAddress.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetSocketAddress.java
Thu Mar 30 01:29:24 2006
@@ -45,17 +45,42 @@
 	}
 
 	public InetSocketAddress(String host, int port) {
+		this(host,port,true);
+	}
+	
+	/*
+	 * Internal contructor for InetSocketAddress(String, int) and 
+	 * createUnresolved(String, int);
+	 */
+	InetSocketAddress(String host, int port, boolean needResolved){
 		if (host == null || port < 0 || port > 65535)
 			throw new IllegalArgumentException();
 		hostName = host;
 		this.port = port;
-		try {
-			addr = InetAddress.getByName(hostName);
-			hostName = addr.getHostName();
-		} catch (UnknownHostException e) {
+		if(needResolved){
+			try {
+				addr = InetAddress.getByName(hostName);
+				hostName = addr.getHostName();
+			} catch (UnknownHostException e) {
+			}
+		}else{
+			addr = null;
 		}
 	}
 
+	/**
+	 * Creats an <code>InetSocketAddress</code> without trying to resolve 
+	 * hostname into an InetAddress. The address field is marked as unresolved. 
+	 * @param host
+	 * @param port
+	 * @return an <code>InetSocketAddress</code> instance.
+	 * @throws IllegalArgumentException
+	 *             if host is null or the port is not in the range between 0 and 65535.  
+	 */
+	public static InetSocketAddress createUnresolved(String host, int port){
+		return new InetSocketAddress(host,port,false);
+	}
+	
 	public final int getPort() {
 		return port;
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java?rev=390043&r1=390042&r2=390043&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java
Thu Mar 30 01:29:24 2006
@@ -38,6 +38,7 @@
 		suite.addTestSuite(Inet4AddressTest.class);
 		suite.addTestSuite(Inet6AddressTest.class);
 		suite.addTestSuite(InetAddressTest.class);
+		suite.addTestSuite(InetSocketAddressTest.class);
 		suite.addTestSuite(JarURLConnectionTest.class);
 		suite.addTestSuite(MalformedURLExceptionTest.class);
 		suite.addTestSuite(MulticastSocketTest.class);
@@ -53,7 +54,7 @@
 		suite.addTestSuite(SocketPermissionTest.class);
 		suite.addTestSuite(UnknownHostExceptionTest.class);
 		suite.addTestSuite(UnknownServiceExceptionTest.class);
-                suite.addTestSuite(URITest.class);
+		suite.addTestSuite(URITest.class);
 		suite.addTestSuite(URISyntaxExceptionTest.class);
 		suite.addTestSuite(URLTest.class);
 		suite.addTestSuite(URLClassLoaderTest.class);

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetSocketAddressTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetSocketAddressTest.java?rev=390043&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetSocketAddressTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/InetSocketAddressTest.java
Thu Mar 30 01:29:24 2006
@@ -0,0 +1,74 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests.api.java.net;
+
+import java.net.InetSocketAddress;
+
+import junit.framework.TestCase;
+
+public class InetSocketAddressTest extends TestCase {
+
+	/**
+	 * @tests java.net.InetSocketAddress#createUnresolved(String, int)
+	 */
+	public void test_createUnresolvedLjava_lang_StringI() {
+		HostPortPair[] legalHostPortPairs = { new HostPortPair("127.0.0.1", 1234),
+				new HostPortPair("192.168.0.1", 10000), new HostPortPair("127.0.0", 0),
+				new HostPortPair("127.0.0", 65535),
+				new HostPortPair("strange host", 65535) };
+		for (int i = 0; i < legalHostPortPairs.length; i++) {
+			InetSocketAddress isa = InetSocketAddress.createUnresolved(
+					legalHostPortPairs[i].host, legalHostPortPairs[i].port);
+			assertTrue(isa.isUnresolved());
+			assertNull(isa.getAddress());
+			assertEquals(isa.getHostName(), legalHostPortPairs[i].host);
+			assertEquals(isa.getPort(), legalHostPortPairs[i].port);
+		}
+	}
+
+	/**
+	 * @tests java.net.InetSocketAddress#createUnresolved(String, int)
+	 */
+	public void test_createUnresolvedLjava_lang_StringI_IllegalArgumentException() {
+		HostPortPair[] illegalHostPortPairs = { new HostPortPair(null, 1),
+				new HostPortPair("host", -1), new HostPortPair("host", 65536) };
+		for (int i = 0; i < illegalHostPortPairs.length; i++) {
+			try {
+				InetSocketAddress.createUnresolved(
+						illegalHostPortPairs[i].host,
+						illegalHostPortPairs[i].port);
+				fail("should throw IllegalArgumentException, host = "
+						+ illegalHostPortPairs[i].host + ",port = "
+						+ illegalHostPortPairs[i].port);
+			} catch (IllegalArgumentException e) {
+				// expected
+			}
+		}
+	}
+
+	/*
+	 * inner class for createUnresolved test convenience.
+	 */
+	class HostPortPair {
+		String host;
+
+		int port;
+
+		public HostPortPair(String host, int port) {
+			this.host = host;
+			this.port = port;
+		}
+	};
+}



Mime
View raw message