harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r648995 [1/3] - in /harmony/enhanced/classlib/trunk/modules/luni/src/test: api/common/org/apache/harmony/luni/tests/java/net/ resources/serialization/org/apache/harmony/luni/tests/java/net/
Date Thu, 17 Apr 2008 08:23:01 GMT
Author: tonywu
Date: Thu Apr 17 01:22:53 2008
New Revision: 648995

URL: http://svn.apache.org/viewvc?rev=648995&view=rev
Log:
Apply patch for HARMONY-5733 ([classlib][luni][test] Add some tests for uncovered classes
in java.net package)

Added:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTimeoutExceptionTest.java
  (with props)
    harmony/enhanced/classlib/trunk/modules/luni/src/test/resources/serialization/org/apache/harmony/luni/tests/java/net/SocketTimeoutExceptionTest.golden.ser
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/DatagramSocketTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/ServerSocketTest.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/SocketTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URITest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/DatagramSocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/DatagramSocketTest.java?rev=648995&r1=648994&r2=648995&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/DatagramSocketTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/DatagramSocketTest.java
Thu Apr 17 01:22:53 2008
@@ -23,6 +23,7 @@
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
 import java.net.DatagramSocketImpl;
+import java.net.DatagramSocketImplFactory;
 import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
@@ -35,6 +36,8 @@
 import java.net.UnknownHostException;
 import java.util.Date;
 
+import org.apache.harmony.luni.net.SocketImplProvider;
+
 import tests.support.Support_Configuration;
 import tests.support.Support_PortManager;
 
@@ -930,6 +933,38 @@
             // expected;
         } finally {
             d.close();
+        }
+    }
+    
+    /**
+     * @tests {@link java.net.DatagramSocket#setDatagramSocketImplFactory(DatagramSocketImplFactory)}
+     */
+    public void test_set_Datagram_SocketImpl_Factory() throws IOException {
+        DatagramSocketImplFactory factory = new MockDatagramSocketImplFactory();
+        // Should not throw SocketException when set DatagramSocketImplFactory
+        // for the first time.
+        DatagramSocket.setDatagramSocketImplFactory(factory);
+
+        try {
+            DatagramSocket.setDatagramSocketImplFactory(null);
+            fail("Should throw SocketException");
+        } catch (SocketException e) {
+            // Expected
+        }
+
+        try {
+            DatagramSocket.setDatagramSocketImplFactory(factory);
+            fail("Should throw SocketException");
+        } catch (SocketException e) {
+            // Expected
+        }
+    }
+
+    private class MockDatagramSocketImplFactory implements
+            DatagramSocketImplFactory {
+
+        public DatagramSocketImpl createDatagramSocketImpl() {
+            return SocketImplProvider.getDatagramSocketImpl();
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java?rev=648995&r1=648994&r2=648995&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/HttpURLConnectionTest.java
Thu Apr 17 01:22:53 2008
@@ -24,6 +24,7 @@
 import java.net.CacheResponse;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
+import java.net.ProtocolException;
 import java.net.ResponseCache;
 import java.net.SocketPermission;
 import java.net.URI;
@@ -581,6 +582,72 @@
         assertNull(uc.getErrorStream());        
         uc.disconnect();
         assertNull(uc.getErrorStream());
+    }
+    
+    /**
+     * @tests {@link java.net.HttpURLConnection#setFollowRedirects(boolean)}
+     * @tests {@link java.net.HttpURLConnection#getFollowRedirects()}
+     */
+    public void test_followRedirects() {
+        assertTrue("The default value of followRedirects is not true",
+                HttpURLConnection.getFollowRedirects());
+
+        HttpURLConnection.setFollowRedirects(false);
+        assertFalse(HttpURLConnection.getFollowRedirects());
+
+        HttpURLConnection.setFollowRedirects(true);
+        assertTrue(HttpURLConnection.getFollowRedirects());
+    }
+
+    /**
+     * @throws ProtocolException 
+     * @tests {@link java.net.HttpURLConnection#setRequestMethod(String)}
+     * @tests {@link java.net.HttpURLConnection#getRequestMethod()}
+     */
+    public void test_requestMethod() throws MalformedURLException, ProtocolException{
+        URL url = new URL("http://harmony.apache.org/");
+        
+        HttpURLConnection con = new MyHttpURLConnection(url);
+        assertEquals("The default value of requestMethod is not \"GET\"", "GET",
+                con.getRequestMethod());
+
+        String[] methods = { "GET", "DELETE", "HEAD", "OPTIONS", "POST", "PUT",
+                "TRACE" };
+        // Nomal set. Should not throw ProtocolException
+        for (String method : methods) {
+            con.setRequestMethod(method);
+            assertEquals("The value of requestMethod is not " + method, method,
+                    con.getRequestMethod());
+        }
+            
+        try {
+            con.setRequestMethod("Wrong method");
+            fail("Should throw ProtocolException");
+        } catch (ProtocolException e) {
+            // Expected
+        }
+    }
+
+    private static class MyHttpURLConnection extends HttpURLConnection {
+
+        protected MyHttpURLConnection(URL url) {
+            super(url);
+        }
+
+        @Override
+        public void disconnect() {
+            // do nothing
+        }
+
+        @Override
+        public boolean usingProxy() {
+            return false;
+        }
+
+        @Override
+        public void connect() throws IOException {
+            // do nothing
+        }
     }
     
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java?rev=648995&r1=648994&r2=648995&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java
Thu Apr 17 01:22:53 2008
@@ -854,6 +854,19 @@
 		assertNull(v6Addr.getScopedInterface());
 	}
 
+    /**
+     * @tests {@link java.net.Inet6Address#hashCode()}
+     */
+    public void test_hashCode() throws UnknownHostException{
+        byte[] addr = { (byte) 0xFE, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x11,
+                0x25, (byte) 0xFF, (byte) 0xFE, (byte) 0xF8, (byte) 0x7C,
+                (byte) 0xB2 };
+        Inet6Address address1, address2;
+        
+        address1 = Inet6Address.getByAddress("123", addr, 0);
+        address2 = Inet6Address.getByAddress("1234", addr, 0);
+        assertEquals(address1.hashCode(), address2.hashCode());
+    }
 	
 	int bytesToInt(byte bytes[], int start) {
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/ServerSocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/ServerSocketTest.java?rev=648995&r1=648994&r2=648995&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/ServerSocketTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/ServerSocketTest.java
Thu Apr 17 01:22:53 2008
@@ -30,10 +30,13 @@
 import java.net.SocketAddress;
 import java.net.SocketException;
 import java.net.SocketImpl;
+import java.net.SocketImplFactory;
 import java.net.UnknownHostException;
 import java.util.Date;
 import java.util.Properties;
 
+import org.apache.harmony.luni.net.SocketImplProvider;
+
 import tests.support.Support_Configuration;
 import tests.support.Support_Exec;
 
@@ -306,11 +309,32 @@
     /**
      * @tests java.net.ServerSocket#setSocketFactory(java.net.SocketImplFactory)
      */
-    public void test_setSocketFactoryLjava_net_SocketImplFactory() {
-        // Test for method void
-        // java.net.ServerSocket.setSocketFactory(java.net.SocketImplFactory)
+    public void test_setSocketFactoryLjava_net_SocketImplFactory()
+            throws IOException {
+        SocketImplFactory factory = new MockSocketImplFactory();
+        // Should not throw SocketException when set DatagramSocketImplFactory
+        // for the first time.
+        ServerSocket.setSocketFactory(factory);
 
-        // TODO : Implementation
+        try {
+            ServerSocket.setSocketFactory(null);
+            fail("Should throw SocketException");
+        } catch (SocketException e) {
+            // Expected
+        }
+
+        try {
+            ServerSocket.setSocketFactory(factory);
+            fail("Should throw SocketException");
+        } catch (SocketException e) {
+            // Expected
+        }
+    }
+
+    private static class MockSocketImplFactory implements SocketImplFactory {
+        public SocketImpl createSocketImpl() {
+            return SocketImplProvider.getServerSocketImpl();
+        }
     }
 
     /**

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=648995&r1=648994&r2=648995&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 Apr 17 01:22:53 2008
@@ -57,9 +57,22 @@
             // expected
         }
     }
+    
+    /**
+     * @tests java.net.SocketImpl#shutdownInput()
+     */
+    public void test_shutdownInput() {
+        MockSocketImpl s = new MockSocketImpl();
+        try {
+            s.shutdownInput();
+            fail("This method is still not implemented yet,It should throw IOException.");
+        } catch (IOException e) {
+            // Expected
+        }
+    }
 
     /**
-     * @tests java.net.SocketImpl#shutdownOutput()
+     * @tests java.net.SocketImpl#supportsUrgentData()
      */
     public void test_supportsUrgentData() {
         MockSocketImpl s = new MockSocketImpl();
@@ -128,6 +141,10 @@
 
         public void shutdownOutput() throws IOException {
             super.shutdownOutput();
+        }
+        
+        public void shutdownInput() throws IOException{
+            super.shutdownInput();
         }
 
         public boolean testSupportsUrgentData() {

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=648995&r1=648994&r2=648995&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 Apr 17 01:22:53 2008
@@ -22,6 +22,8 @@
 import java.net.UnknownHostException;
 import java.security.PermissionCollection;
 
+import org.apache.harmony.testframework.serialization.SerializationTest;
+
 import tests.support.Support_Configuration;
 
 public class SocketPermissionTest extends junit.framework.TestCase {
@@ -192,5 +194,14 @@
                 pc.implies(p2));
         assertTrue("A different host should not imply resolve", !pc
                 .implies(star_Resolve));
+    }
+    
+    /**
+     * @tests serialization/deserialization.
+     */
+    public void testSerializationSelf() throws Exception {
+        SocketPermission permission = new SocketPermission("harmony.apache.org", "connect");;
+
+        SerializationTest.verifySelf(permission);
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=648995&r1=648994&r2=648995&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
Thu Apr 17 01:22:53 2008
@@ -31,10 +31,13 @@
 import java.net.SocketAddress;
 import java.net.SocketException;
 import java.net.SocketImpl;
+import java.net.SocketImplFactory;
 import java.net.SocketTimeoutException;
 import java.net.UnknownHostException;
 import java.security.Permission;
 
+import org.apache.harmony.luni.net.SocketImplProvider;
+
 import tests.support.Support_Configuration;
 
 public class SocketTest extends SocketTestCase {
@@ -2060,5 +2063,37 @@
         assertEquals("Returned incorrect string", expected, client.toString());
         client.close();
         server.close();
+    }
+    
+    /**
+     * @tests {@link java.net.Socket#setSocketImplFactory(SocketImplFactory)}
+     */
+    public void test_setSocketFactoryLjava_net_SocketImplFactory()
+            throws IOException {
+        SocketImplFactory factory = new MockSocketImplFactory();
+        // Should not throw SocketException when set DatagramSocketImplFactory
+        // for the first time.
+        Socket.setSocketImplFactory(factory);
+
+        try {
+            Socket.setSocketImplFactory(null);
+            fail("Should throw SocketException");
+        } catch (SocketException e) {
+            // Expected
+        }
+
+        try {
+            Socket.setSocketImplFactory(factory);
+            fail("Should throw SocketException");
+        } catch (SocketException e) {
+            // Expected
+        }
+    }
+
+    private class MockSocketImplFactory implements SocketImplFactory {
+
+        public SocketImpl createSocketImpl() {
+            return SocketImplProvider.getServerSocketImpl();
+        }
     }
 }

Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTimeoutExceptionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTimeoutExceptionTest.java?rev=648995&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTimeoutExceptionTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTimeoutExceptionTest.java
Thu Apr 17 01:22:53 2008
@@ -0,0 +1,67 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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 org.apache.harmony.luni.tests.java.net;
+
+import java.net.SocketTimeoutException;
+
+import org.apache.harmony.testframework.serialization.SerializationTest;
+
+public class SocketTimeoutExceptionTest extends junit.framework.TestCase {
+
+    /**
+     * @tests {@link java.net.SocketTimeoutException#SocketTimeoutException()}
+     */
+    public void test_Constructor() {
+        SocketTimeoutException e = new SocketTimeoutException();
+        assertNull(e.getMessage());
+        assertNull(e.getLocalizedMessage());
+        assertNull(e.getCause());
+    }
+
+    /**
+     * @tests {@link java.net.SocketTimeoutException#SocketTimeoutException(String)}
+     */
+    public void test_ConstructorLjava_lang_String() {
+        SocketTimeoutException e = new SocketTimeoutException("fixture");
+        assertEquals("fixture", e.getMessage());
+        assertNull(e.getCause());
+    }
+
+    /**
+     * @tests serialization/deserialization.
+     */
+    public void testSerializationSelf() throws Exception {
+        SerializationTest.verifySelf(new SocketTimeoutException());
+    }
+
+    /**
+     * @tests serialization/deserialization compatibility with RI.
+     */
+    public void testSerializationCompatibility() throws Exception {
+        SerializationTest.verifyGolden(this, new SocketTimeoutException());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTimeoutExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message