You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2008/02/07 17:40:30 UTC

svn commit: r619493 [1/7] - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/

Author: tellison
Date: Thu Feb  7 08:40:26 2008
New Revision: 619493

URL: http://svn.apache.org/viewvc?rev=619493&view=rev
Log:
Additional test improvements in LUNI module, including formatting,
exception handling, and so on.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NoRouteToHostExceptionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketExceptionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketImplTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketPermissionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URISyntaxExceptionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URITest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLClassLoaderTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLDecoderTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLEncoderTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/UnknownHostExceptionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/UnknownServiceExceptionTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NoRouteToHostExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NoRouteToHostExceptionTest.java?rev=619493&r1=619492&r2=619493&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NoRouteToHostExceptionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NoRouteToHostExceptionTest.java Thu Feb  7 08:40:26 2008
@@ -21,50 +21,33 @@
 
 public class NoRouteToHostExceptionTest extends junit.framework.TestCase {
 
-	/**
-	 * @tests java.net.NoRouteToHostException#NoRouteToHostException()
-	 */
-	public void test_Constructor() {
-		// Test for method java.net.NoRouteToHostException()
+    /**
+     * @tests java.net.NoRouteToHostException#NoRouteToHostException()
+     */
+    public void test_Constructor() {
+        try {
+            if (true) {
+                throw new NoRouteToHostException();
+            }
+            fail("Failed to generate expected exception");
+        } catch (NoRouteToHostException e) {
+            // Expected
+        }
+    }
 
-		try {
-			if (true)
-				throw new NoRouteToHostException();
-		} catch (NoRouteToHostException e) {
-			return;
-		}
-		fail("Failed to generate expected exception");
-	}
-
-	/**
-	 * @tests java.net.NoRouteToHostException#NoRouteToHostException(java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_String() {
-		// Test for method java.net.NoRouteToHostException(java.lang.String)
-		// Cannot test correctly without changing some routing tables !!
-
-		try {
-			if (true)
-				throw new NoRouteToHostException("test");
-		} catch (NoRouteToHostException e) {
-			assertEquals("Threw exception with incorrect message", "test", e.getMessage()
-					);
-			return;
-		}
-		fail("Failed to generate expected exception");
-	}
-
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-	}
-
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
-	}
+    /**
+     * @tests java.net.NoRouteToHostException#NoRouteToHostException(java.lang.String)
+     */
+    public void test_ConstructorLjava_lang_String() {
+        // Cannot test correctly without changing some routing tables !!
+        try {
+            if (true) {
+                throw new NoRouteToHostException("test");
+            }
+            fail("Failed to generate expected exception");
+        } catch (NoRouteToHostException e) {
+            assertEquals("Threw exception with incorrect message", "test", e
+                    .getMessage());
+        }
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketExceptionTest.java?rev=619493&r1=619492&r2=619493&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketExceptionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketExceptionTest.java Thu Feb  7 08:40:26 2008
@@ -21,45 +21,31 @@
 
 public class SocketExceptionTest extends junit.framework.TestCase {
 
-	/**
-	 * @tests java.net.SocketException#SocketException()
-	 */
-	public void test_Constructor() {
-		try {
-			throw new SocketException();
-		} catch (SocketException e) {
-			return;
-		} catch (Exception e) {
-			fail("Exception during SocketException test : " + e.getMessage());
-		}
-		fail("Failed to generate expected exception");
-	}
+    /**
+     * @tests java.net.SocketException#SocketException()
+     */
+    public void test_Constructor() {
+        try {
+            if (true) {
+                throw new SocketException();
+            }
+            fail("Failed to generate expected exception");
+        } catch (SocketException e) {
+            // Expected
+        }
+    }
 
-	/**
-	 * @tests java.net.SocketException#SocketException(java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_String() {
-		try {
-			throw new SocketException("Some error message");
-		} catch (SocketException e) {
-			return;
-		} catch (Exception e) {
-			fail("Exception during SocketException test" + e.toString());
-		}
-		fail("Failed to generate expected exception");
-	}
-
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-	}
-
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
-	}
+    /**
+     * @tests java.net.SocketException#SocketException(java.lang.String)
+     */
+    public void test_ConstructorLjava_lang_String() {
+        try {
+            if (true) {
+                throw new SocketException("Some error message");
+            }
+            fail("Failed to generate expected exception");
+        } catch (SocketException e) {
+            // Expected
+        }
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketImplTest.java?rev=619493&r1=619492&r2=619493&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketImplTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketImplTest.java Thu Feb  7 08:40:26 2008
@@ -28,22 +28,24 @@
 
 public class SocketImplTest extends junit.framework.TestCase {
 
-	
-    public void test_Constructor_fd() throws Exception {
-        // regression test for Harmony-1117
+    /**
+     * @tests java.net.SocketImpl#SocketImpl()
+     */
+    public void test_Constructor_fd() {
+        // Regression test for HARMONY-1117
         MockSocketImpl mockSocketImpl = new MockSocketImpl();
         assertNull(mockSocketImpl.getFileDescriptor());
     }
-    
-	/*
-	* @tests java.net.SocketImpl#setPerformancePreference()
-	*/
-	public void test_setPerformancePreference_Int_Int_Int() throws Exception {
-		MockSocketImpl theSocket = new MockSocketImpl();
-		theSocket.setPerformancePreference(1,1,1);
-	}
 
-    /*
+    /**
+     * @tests java.net.SocketImpl#setPerformancePreference()
+     */
+    public void test_setPerformancePreference_Int_Int_Int() {
+        MockSocketImpl theSocket = new MockSocketImpl();
+        theSocket.setPerformancePreference(1, 1, 1);
+    }
+
+    /**
      * @tests java.net.SocketImpl#shutdownOutput()
      */
     public void test_shutdownOutput() {
@@ -55,90 +57,82 @@
             // expected
         }
     }
-    
-    /*
+
+    /**
      * @tests java.net.SocketImpl#shutdownOutput()
      */
     public void test_supportsUrgentData() {
         MockSocketImpl s = new MockSocketImpl();
         assertFalse(s.testSupportsUrgentData());
     }
-    
-	// the mock class for test, leave all method empty
-	class MockSocketImpl extends SocketImpl{
-		
-		protected void accept(SocketImpl newSocket) throws IOException {
-		}
-
-		protected int available() throws IOException {
-			return 0;
-		}
-
-		protected void bind(InetAddress address, int port) throws IOException {
-		}
-
-		protected void close() throws IOException {
-		}
-
-		protected void connect(String host, int port) throws IOException {
-		}
-
-		protected void connect(InetAddress address, int port) throws IOException {
-		}
-
-		protected void create(boolean isStreaming) throws IOException {
-		}
-
-		protected InputStream getInputStream() throws IOException {
-			return null;
-		}
-
-		public Object getOption(int optID) throws SocketException {
-			return null;
-		}
-
-		protected OutputStream getOutputStream() throws IOException {
-			return null;
-		}
-
-		protected void listen(int backlog) throws IOException {
-		}
-
-		public void setOption(int optID, Object val) throws SocketException {
-		}
-
-		protected void connect(SocketAddress remoteAddr, int timeout) throws IOException {
-		}
-
-		protected void sendUrgentData(int value) throws IOException {
-		}
-		
-		public void setPerformancePreference(int connectionTime,
-                int latency,
-                int bandwidth){
-			super.setPerformancePreferences(connectionTime, latency, bandwidth);
-		}
+
+    // the mock class for test, leave all methods empty
+    class MockSocketImpl extends SocketImpl {
+
+        protected void accept(SocketImpl newSocket) throws IOException {
+        }
+
+        protected int available() throws IOException {
+            return 0;
+        }
+
+        protected void bind(InetAddress address, int port) throws IOException {
+        }
+
+        protected void close() throws IOException {
+        }
+
+        protected void connect(String host, int port) throws IOException {
+        }
+
+        protected void connect(InetAddress address, int port)
+                throws IOException {
+        }
+
+        protected void create(boolean isStreaming) throws IOException {
+        }
+
+        protected InputStream getInputStream() throws IOException {
+            return null;
+        }
+
+        public Object getOption(int optID) throws SocketException {
+            return null;
+        }
+
+        protected OutputStream getOutputStream() throws IOException {
+            return null;
+        }
+
+        protected void listen(int backlog) throws IOException {
+        }
+
+        public void setOption(int optID, Object val) throws SocketException {
+        }
+
+        protected void connect(SocketAddress remoteAddr, int timeout)
+                throws IOException {
+        }
+
+        protected void sendUrgentData(int value) throws IOException {
+        }
+
+        public void setPerformancePreference(int connectionTime, int latency,
+                int bandwidth) {
+            super.setPerformancePreferences(connectionTime, latency, bandwidth);
+        }
 
         public FileDescriptor getFileDescriptor() {
             return super.getFileDescriptor();
         }
-        
+
         public void shutdownOutput() throws IOException {
             super.shutdownOutput();
         }
-        
-        public boolean testSupportsUrgentData(){
+
+        public boolean testSupportsUrgentData() {
             return super.supportsUrgentData();
         }
-        
-	}
-
-	protected void setUp() {
-	}
 
-	protected void tearDown() {
-	}
-
-	protected void doneSuite() {
-	}
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketPermissionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketPermissionTest.java?rev=619493&r1=619492&r2=619493&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketPermissionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketPermissionTest.java Thu Feb  7 08:40:26 2008
@@ -26,203 +26,171 @@
 
 public class SocketPermissionTest extends junit.framework.TestCase {
 
-	String starName = "*." + Support_Configuration.DomainAddress;
+    String starName = "*." + Support_Configuration.DomainAddress;
 
-	String wwwName = Support_Configuration.HomeAddress;
+    String wwwName = Support_Configuration.HomeAddress;
 
-	SocketPermission star_Resolve = new SocketPermission(starName, "resolve");
+    SocketPermission star_Resolve = new SocketPermission(starName, "resolve");
 
-	SocketPermission star_All = new SocketPermission(starName,
-			"listen,accept,connect");
+    SocketPermission star_All = new SocketPermission(starName,
+            "listen,accept,connect");
 
-	SocketPermission www_All = new SocketPermission(wwwName,
-			"connect,listen,accept");
-
-	SocketPermission copyOfWww_All = new SocketPermission(wwwName,
-			"connect,listen,accept");
-
-	/**
-	 * @tests java.net.SocketPermission#SocketPermission(java.lang.String,
-	 *        java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_StringLjava_lang_String() {
-		// Test for method java.net.SocketPermission(java.lang.String,
-		// java.lang.String)
-		assertTrue("Incorrect name", star_Resolve.getName().equals(starName));
-		assertEquals("Incorrect actions", 
-				"resolve", star_Resolve.getActions());
-
-		SocketPermission sp1 = new SocketPermission("", "connect");
-		assertEquals("Wrong name1", "localhost", sp1.getName());
-		SocketPermission sp2 = new SocketPermission(":80", "connect");
-		assertEquals("Wrong name2", ":80", sp2.getName());
-        
-		// regression for HARMONY-1462
+    SocketPermission www_All = new SocketPermission(wwwName,
+            "connect,listen,accept");
+
+    SocketPermission copyOfWww_All = new SocketPermission(wwwName,
+            "connect,listen,accept");
+
+    /**
+     * @tests java.net.SocketPermission#SocketPermission(java.lang.String,
+     *        java.lang.String)
+     */
+    public void test_ConstructorLjava_lang_StringLjava_lang_String() {
+        assertEquals("Incorrect name", starName, star_Resolve.getName());
+        assertEquals("Incorrect actions", "resolve", star_Resolve.getActions());
+
+        SocketPermission sp1 = new SocketPermission("", "connect");
+        assertEquals("Wrong name1", "localhost", sp1.getName());
+        SocketPermission sp2 = new SocketPermission(":80", "connect");
+        assertEquals("Wrong name2", ":80", sp2.getName());
+
+        // Regression for HARMONY-1462
         SocketPermission sp3 = new SocketPermission("localhost:*", "listen");
         assertEquals("Wrong name3", "localhost:*", sp3.getName());
-        // for all ports
+        // For all ports
         SocketPermission spAllPorts = new SocketPermission("localhost:0-65535",
                 "listen");
         assertTrue("Port range error", sp3.implies(spAllPorts));
         assertTrue("Port range error", spAllPorts.implies(sp3));
-	}
+    }
 
-	/**
-	 * @tests java.net.SocketPermission#equals(java.lang.Object)
-	 */
-	public void test_equalsLjava_lang_Object() {
-		// Test for method boolean
-		// java.net.SocketPermission.equals(java.lang.Object)
-		assertTrue("Different names but returned equal", !star_All
-				.equals(www_All));
-		assertTrue("Different actions but returned equal", !star_Resolve
-				.equals(star_All));
-		assertTrue("Same but returned unequal", www_All.equals(copyOfWww_All));
-		assertTrue("Returned true when compared to a String", !www_All
-				.equals(www_All.toString()));
-
-		SocketPermission sp1 = new SocketPermission("TEST1.com",
-				"resolve,connect");
-		SocketPermission sp2 = new SocketPermission("test1.com",
-				"resolve,connect");
-		assertTrue("Different cases should be equal", sp1.equals(sp2));
+    /**
+     * @tests java.net.SocketPermission#equals(java.lang.Object)
+     */
+    public void test_equalsLjava_lang_Object() {
+        assertTrue("Different names but returned equal", !star_All
+                .equals(www_All));
+        assertTrue("Different actions but returned equal", !star_Resolve
+                .equals(star_All));
+        assertTrue("Same but returned unequal", www_All.equals(copyOfWww_All));
+        assertTrue("Returned true when compared to a String", !www_All
+                .equals(www_All.toString()));
+
+        SocketPermission sp1 = new SocketPermission("TEST1.com",
+                "resolve,connect");
+        SocketPermission sp2 = new SocketPermission("test1.com",
+                "resolve,connect");
+        assertTrue("Different cases should be equal", sp1.equals(sp2));
 
         // Regression for HARMONY-1524
         assertFalse(sp1.equals(null));
-        
+
         // Regression for HARMONY-3333
         sp1 = new SocketPermission("TEST1.com:333", "resolve");
         sp2 = new SocketPermission("test1.com:444", "resolve");
         assertTrue("Different cases should be equal", sp1.equals(sp2));
-	}
 
-	/**
-	 * @tests java.net.SocketPermission#equals(java.lang.Object)
-	 */
-	public void test_equalsLjava_lang_Object_subtest0() {
-		SocketPermission sp1 = new SocketPermission(
-				Support_Configuration.InetTestAddress, "resolve,connect");
-		SocketPermission sp2 = new SocketPermission(
-				Support_Configuration.InetTestIP, "resolve,connect");
-		assertTrue("Same IP address should be equal", sp1.equals(sp2));
-
-	}
-
-	/**
-	 * @tests java.net.SocketPermission#getActions()
-	 */
-	public void test_getActions() {
-		// Test for method java.lang.String
-		// java.net.SocketPermission.getActions()
-		assertEquals("Incorrect actions", 
-				"resolve", star_Resolve.getActions());
-		assertEquals("Incorrect actions/not in canonical form", "connect,listen,accept,resolve", star_All
-				.getActions());
-	}
-
-	/**
-	 * @tests java.net.SocketPermission#implies(java.security.Permission)
-	 */
-	public void test_impliesLjava_security_Permission() {
-		// Test for method boolean
-		// java.net.SocketPermission.implies(java.security.Permission)
-		assertTrue("All should imply resolve", star_All.implies(star_Resolve));
-		
-        // regression for HARMONY-1200
-        assertFalse("Null should not be implied", star_All.implies((SocketPermission)null));
-        
-		assertTrue("Equals should imply eachother", www_All
-				.implies(copyOfWww_All));
-		assertTrue("Wild should imply normal", star_All.implies(www_All));
-		assertTrue("Normal shouldn't imply wildcard", !www_All
-				.implies(star_Resolve));
-		assertTrue("Resolve shouldn't imply all", !star_Resolve
-				.implies(star_All));
-		SocketPermission p1 = new SocketPermission(wwwName + ":80-81",
-				"connect");
-		SocketPermission p2 = new SocketPermission(wwwName + ":80", "connect");
-		assertTrue("Port 80 is implied by 80-81", p1.implies(p2));
-		p1 = new SocketPermission(wwwName + ":79-80", "connect");
-		assertTrue("Port 80 is implied by 79-80", p1.implies(p2));
-		p1 = new SocketPermission(wwwName + ":79-81", "connect");
-		assertTrue("Port 80 is implied by 79-81", p1.implies(p2));
-		p2 = new SocketPermission(wwwName + ":79-80", "connect");
-		assertTrue("Port 79-80 is implied by 79-81", p1.implies(p2));
-		p2 = new SocketPermission(wwwName, "resolve");
-		assertTrue(
-				"Any identical host should imply resolve regardless of the ports",
-				p1.implies(p2));
-
-		SocketPermission sp1 = new SocketPermission("www.Ibm.com", "resolve");
-		SocketPermission sp2 = new SocketPermission("www.IBM.com", "resolve");
-		assertTrue("SocketPermission is case sensitive", sp1.implies(sp2));
-
-		SocketPermission sp3 = new SocketPermission("*.ibm.com", "resolve");
-		assertTrue("SocketPermission wildcard is case sensitive", sp3
-				.implies(sp2));
-
-		InetAddress host = null;
-		try {
-			host = InetAddress.getByName(Support_Configuration.UnresolvedIP);
-		} catch (UnknownHostException e) {
-		}
-		
-		SocketPermission perm1 = new SocketPermission(
-				Support_Configuration.UnresolvedIP, "connect");
-		SocketPermission perm2 = new SocketPermission(
-				Support_Configuration.UnresolvedIP + ":80", "connect");
-		assertTrue("should imply port 80", perm1.implies(perm2));
-		PermissionCollection col = perm1.newPermissionCollection();
-		col.add(perm1);
-		assertTrue("collection should imply port 80", col.implies(perm2));
-
-	}
-
-	/**
-	 * @tests java.net.SocketPermission#newPermissionCollection()
-	 */
-	public void test_newPermissionCollection() {
-		// Test for method java.security.PermissionCollection
-		// java.net.SocketPermission.newPermissionCollection()
-		java.security.PermissionCollection pc = star_Resolve
-				.newPermissionCollection();
-		pc.add(star_Resolve);
-		pc.add(www_All);
-		assertTrue("Should imply all on " + wwwName, pc.implies(www_All));
-		assertTrue("Should imply resolve on " + starName, pc
-				.implies(star_Resolve));
-		assertTrue("Should not imply all on " + starName, !pc.implies(star_All));
-
-		// wipe out pc
-		pc = star_Resolve.newPermissionCollection();
-		pc.add(star_All);
-		assertTrue("Should imply resolve on " + starName, pc
-				.implies(star_Resolve));
-		assertTrue("Should imply all on " + wwwName, pc.implies(www_All));
-
-		pc = star_Resolve.newPermissionCollection();
-		SocketPermission p1 = new SocketPermission(wwwName + ":79-80",
-				"connect");
-		pc.add(p1);
-		SocketPermission p2 = new SocketPermission(wwwName, "resolve");
-		assertTrue(
-				"Any identical host should imply resolve regardless of the ports",
-				pc.implies(p2));
-		assertTrue("A different host should not imply resolve", !pc
-				.implies(star_Resolve));
-	}
-
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-	}
-
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
-	}
+        sp1 = new SocketPermission(Support_Configuration.InetTestAddress,
+                "resolve,connect");
+        sp2 = new SocketPermission(Support_Configuration.InetTestIP,
+                "resolve,connect");
+        assertEquals("Same IP address should be equal", sp1, sp2);
+    }
+
+    /**
+     * @tests java.net.SocketPermission#getActions()
+     */
+    public void test_getActions() {
+        assertEquals("Incorrect actions", "resolve", star_Resolve.getActions());
+        assertEquals("Incorrect actions/not in canonical form",
+                "connect,listen,accept,resolve", star_All.getActions());
+    }
+
+    /**
+     * @tests java.net.SocketPermission#implies(java.security.Permission)
+     */
+    public void test_impliesLjava_security_Permission() {
+        assertTrue("All should imply resolve", star_All.implies(star_Resolve));
+
+        // Regression for HARMONY-1200
+        assertFalse("Null should not be implied", star_All
+                .implies((SocketPermission) null));
+
+        assertTrue("Equals should imply eachother", www_All
+                .implies(copyOfWww_All));
+        assertTrue("Wild should imply normal", star_All.implies(www_All));
+        assertTrue("Normal shouldn't imply wildcard", !www_All
+                .implies(star_Resolve));
+        assertTrue("Resolve shouldn't imply all", !star_Resolve
+                .implies(star_All));
+        SocketPermission p1 = new SocketPermission(wwwName + ":80-81",
+                "connect");
+        SocketPermission p2 = new SocketPermission(wwwName + ":80", "connect");
+        assertTrue("Port 80 is implied by 80-81", p1.implies(p2));
+        p1 = new SocketPermission(wwwName + ":79-80", "connect");
+        assertTrue("Port 80 is implied by 79-80", p1.implies(p2));
+        p1 = new SocketPermission(wwwName + ":79-81", "connect");
+        assertTrue("Port 80 is implied by 79-81", p1.implies(p2));
+        p2 = new SocketPermission(wwwName + ":79-80", "connect");
+        assertTrue("Port 79-80 is implied by 79-81", p1.implies(p2));
+        p2 = new SocketPermission(wwwName, "resolve");
+        assertTrue(
+                "Any identical host should imply resolve regardless of the ports",
+                p1.implies(p2));
+
+        SocketPermission sp1 = new SocketPermission("www.Ibm.com", "resolve");
+        SocketPermission sp2 = new SocketPermission("www.IBM.com", "resolve");
+        assertTrue("SocketPermission is case sensitive", sp1.implies(sp2));
+
+        SocketPermission sp3 = new SocketPermission("*.ibm.com", "resolve");
+        assertTrue("SocketPermission wildcard is case sensitive", sp3
+                .implies(sp2));
+
+        InetAddress host = null;
+        try {
+            host = InetAddress.getByName(Support_Configuration.UnresolvedIP);
+        } catch (UnknownHostException e) {
+        }
+
+        SocketPermission perm1 = new SocketPermission(
+                Support_Configuration.UnresolvedIP, "connect");
+        SocketPermission perm2 = new SocketPermission(
+                Support_Configuration.UnresolvedIP + ":80", "connect");
+        assertTrue("should imply port 80", perm1.implies(perm2));
+        PermissionCollection col = perm1.newPermissionCollection();
+        col.add(perm1);
+        assertTrue("collection should imply port 80", col.implies(perm2));
+    }
+
+    /**
+     * @tests java.net.SocketPermission#newPermissionCollection()
+     */
+    public void test_newPermissionCollection() {
+        java.security.PermissionCollection pc = star_Resolve
+                .newPermissionCollection();
+        pc.add(star_Resolve);
+        pc.add(www_All);
+        assertTrue("Should imply all on " + wwwName, pc.implies(www_All));
+        assertTrue("Should imply resolve on " + starName, pc
+                .implies(star_Resolve));
+        assertTrue("Should not imply all on " + starName, !pc.implies(star_All));
+
+        // wipe out pc
+        pc = star_Resolve.newPermissionCollection();
+        pc.add(star_All);
+        assertTrue("Should imply resolve on " + starName, pc
+                .implies(star_Resolve));
+        assertTrue("Should imply all on " + wwwName, pc.implies(www_All));
+
+        pc = star_Resolve.newPermissionCollection();
+        SocketPermission p1 = new SocketPermission(wwwName + ":79-80",
+                "connect");
+        pc.add(p1);
+        SocketPermission p2 = new SocketPermission(wwwName, "resolve");
+        assertTrue(
+                "Any identical host should imply resolve regardless of the ports",
+                pc.implies(p2));
+        assertTrue("A different host should not imply resolve", !pc
+                .implies(star_Resolve));
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URISyntaxExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URISyntaxExceptionTest.java?rev=619493&r1=619492&r2=619493&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URISyntaxExceptionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URISyntaxExceptionTest.java Thu Feb  7 08:40:26 2008
@@ -21,102 +21,95 @@
 
 public class URISyntaxExceptionTest extends junit.framework.TestCase {
 
-	/**
-	 * @tests java.net.URISyntaxException#URISyntaxException(java.lang.String,
-	 *        java.lang.String, int)
-	 */
-	public void test_ConstructorLjava_lang_StringLjava_lang_StringI() {
-		// test for Constructor(String str, String problem, int index);
-		try {
-			new URISyntaxException(null, "problem", 2);
-			fail("Expected NullPointerException");
-		} catch (NullPointerException npe) {
-		}
-
-		try {
-			new URISyntaxException("str", null, 2);
-			fail("Expected NullPointerException");
-		} catch (NullPointerException npe) {
-		}
-
-		try {
-			new URISyntaxException("str", "problem", -2);
-			fail("Expected IllegalArgumentException");
-		} catch (IllegalArgumentException iae) {
-		}
-
-		URISyntaxException e = new URISyntaxException("str", "problem", 2);
-		assertEquals("returned incorrect reason", "problem", e.getReason());
-		assertEquals("returned incorrect input", "str", e.getInput());
-		assertEquals("returned incorrect index", 2, e.getIndex());
-	}
-
-	/**
-	 * @tests java.net.URISyntaxException#URISyntaxException(java.lang.String,
-	 *        java.lang.String)
-	 */
-	public void test_ConstructorLjava_lang_StringLjava_lang_String() {
-		// test for Constructor(String str, String problem);
-		try {
-			new URISyntaxException(null, "problem");
-			fail("Expected NullPointerException");
-		} catch (NullPointerException npe) {
-		}
-
-		try {
-			new URISyntaxException("str", null);
-			fail("Expected NullPointerException");
-		} catch (NullPointerException npe) {
-		}
-
-		URISyntaxException e = new URISyntaxException("str", "problem");
-		assertEquals("returned incorrect reason", "problem", e.getReason());
-		assertEquals("returned incorrect input", "str", e.getInput());
-		assertEquals("returned incorrect index", -1, e.getIndex());
-	}
-
-	/**
-	 * @tests java.net.URISyntaxException#getIndex()
-	 */
-	public void test_getIndex() {
-		// see constructor tests
-	}
-
-	/**
-	 * @tests java.net.URISyntaxException#getReason()
-	 */
-	public void test_getReason() {
-		// see constructor tests
-	}
-
-	/**
-	 * @tests java.net.URISyntaxException#getInput()
-	 */
-	public void test_getInput() {
-		// see constructor tests
-	}
-
-	/**
-	 * @tests java.net.URISyntaxException#getMessage()
-	 */
-	public void test_getMessage() {
-		// tests for java.lang.String getMessage()
-		Locale.setDefault(Locale.US);
-		URISyntaxException e = new URISyntaxException("str", "problem", 3);
-		assertEquals("Returned incorrect message", "problem at index 3: str", e
-				.getMessage());
-
-		e = new URISyntaxException("str", "problem");
-		assertEquals("Returned incorrect message", "problem: str", e
-				.getMessage());
-	}
-
-	protected void setUp() {
-	}
-
-	protected void tearDown() {
-	}
-
-	protected void doneSuite() {
-	}
+    /**
+     * @tests java.net.URISyntaxException#URISyntaxException(java.lang.String,
+     *        java.lang.String, int)
+     */
+    public void test_ConstructorLjava_lang_StringLjava_lang_StringI() {
+        try {
+            new URISyntaxException(null, "problem", 2);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException npe) {
+            // Expected
+        }
+
+        try {
+            new URISyntaxException("str", null, 2);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException npe) {
+            // Expected
+        }
+
+        try {
+            new URISyntaxException("str", "problem", -2);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException iae) {
+            // Expected
+        }
+
+        URISyntaxException e = new URISyntaxException("str", "problem", 2);
+        assertEquals("returned incorrect reason", "problem", e.getReason());
+        assertEquals("returned incorrect input", "str", e.getInput());
+        assertEquals("returned incorrect index", 2, e.getIndex());
+    }
+
+    /**
+     * @tests java.net.URISyntaxException#URISyntaxException(java.lang.String,
+     *        java.lang.String)
+     */
+    public void test_ConstructorLjava_lang_StringLjava_lang_String() {
+        try {
+            new URISyntaxException(null, "problem");
+            fail("Expected NullPointerException");
+        } catch (NullPointerException npe) {
+            // Expected
+        }
+
+        try {
+            new URISyntaxException("str", null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException npe) {
+            // Expected
+        }
+
+        URISyntaxException e = new URISyntaxException("str", "problem");
+        assertEquals("returned incorrect reason", "problem", e.getReason());
+        assertEquals("returned incorrect input", "str", e.getInput());
+        assertEquals("returned incorrect index", -1, e.getIndex());
+    }
+
+    /**
+     * @tests java.net.URISyntaxException#getIndex()
+     */
+    public void test_getIndex() {
+        // see constructor tests
+    }
+
+    /**
+     * @tests java.net.URISyntaxException#getReason()
+     */
+    public void test_getReason() {
+        // see constructor tests
+    }
+
+    /**
+     * @tests java.net.URISyntaxException#getInput()
+     */
+    public void test_getInput() {
+        // see constructor tests
+    }
+
+    /**
+     * @tests java.net.URISyntaxException#getMessage()
+     */
+    public void test_getMessage() {
+        Locale.setDefault(Locale.US);
+        URISyntaxException e = new URISyntaxException("str", "problem", 3);
+        assertEquals("Returned incorrect message", "problem at index 3: str", e
+                .getMessage());
+
+        e = new URISyntaxException("str", "problem");
+        assertEquals("Returned incorrect message", "problem: str", e
+                .getMessage());
+    }
 }