harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r411083 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/Inet6Address.java main/java/java/net/NetworkInterface.java test/java/tests/api/java/net/Inet6AddressTest.java
Date Fri, 02 Jun 2006 08:05:13 GMT
Author: mloenko
Date: Fri Jun  2 01:05:12 2006
New Revision: 411083

URL: http://svn.apache.org/viewvc?rev=411083&view=rev
Log:
fixes for HARMONY-500
Java 5 Enhancement: java.net.Inet6Address needs read/write scope_ifname_set and ifname in
serialization

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetworkInterface.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet6AddressTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java?rev=411083&r1=411082&r2=411083&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java
Fri Jun  2 01:05:12 2006
@@ -44,7 +44,7 @@
 	/*
 	 * scoped interface.
 	 */
-	private transient NetworkInterface scopedIf = null;
+	transient NetworkInterface scopedIf = null;
 
 	Inet6Address(byte address[]) {
 		ipaddress = address;
@@ -416,7 +416,9 @@
 	private static final ObjectStreamField[] serialPersistentFields = {
 			new ObjectStreamField("ipaddress", new byte[0].getClass()),
 			new ObjectStreamField("scope_id", Integer.TYPE),
-			new ObjectStreamField("scope_id_set", Boolean.TYPE) };
+			new ObjectStreamField("scope_id_set", Boolean.TYPE),
+            new ObjectStreamField("scope_ifname_set", Boolean.TYPE),
+            new ObjectStreamField("ifname", String.class),};
 
 	private void writeObject(ObjectOutputStream stream) throws IOException {
 		ObjectOutputStream.PutField fields = stream.putFields();
@@ -428,7 +430,8 @@
 
 		fields.put("scope_id", scope_id);
 		fields.put("scope_id_set", scope_id_set);
-
+        fields.put("scope_ifname_set", scope_ifname_set);
+        fields.put("ifname", ifname);
 		stream.writeFields();
 	}
 
@@ -438,6 +441,11 @@
 		ipaddress = (byte[]) fields.get("ipaddress", null);
 		scope_id = fields.get("scope_id", 0);
 		scope_id_set = fields.get("scope_id_set", false);
+        ifname = (String)fields.get("ifname", null);
+        scope_ifname_set = fields.get("scope_ifname_set", false);
+        if (scope_ifname_set){
+            scopedIf = NetworkInterface.getByName(ifname);
+        }
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetworkInterface.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetworkInterface.java?rev=411083&r1=411082&r2=411083&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetworkInterface.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetworkInterface.java
Fri Jun  2 01:05:12 2006
@@ -296,6 +296,19 @@
         if (interfaces == null) {
             return null;
         }
+
+        for (NetworkInterface netif : interfaces) {
+            for (InetAddress addr : netif.addresses) {
+                if (16 == addr.ipaddress.length) {
+                    if (addr.isLinkLocalAddress() || addr.isSiteLocalAddress()) {
+                        ((Inet6Address) addr).scopedIf = netif;
+                        ((Inet6Address) addr).ifname = netif.name;
+                        ((Inet6Address) addr).scope_ifname_set = true;
+                    }
+                }
+            }
+        }
+
         return (new Vector<NetworkInterface>(Arrays.asList(interfaces)))
                 .elements();
     }
@@ -305,8 +318,7 @@
      * are equal. The object must be an instance of NetworkInterface with the
      * same name, displayName and list of network interfaces to be the same
      * 
-     * @param obj
-     *            the object to compare
+     * @param obj the object to compare
      * @return true if the specified object is equal to this NetworkInterfcae,
      *         false otherwise
      * 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet6AddressTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet6AddressTest.java?rev=411083&r1=411082&r2=411083&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet6AddressTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet6AddressTest.java
Fri Jun  2 01:05:12 2006
@@ -20,8 +20,12 @@
 import java.net.NetworkInterface;
 import java.net.UnknownHostException;
 
+import tests.util.SerializationTester;
+
 public class Inet6AddressTest extends junit.framework.TestCase {
 
+    private static final String SERIALIZATION_FILE_NAME = "serialization/java/net/Inet6Address.golden.ser";
+
 	/**
 	 * @tests java.net.Inet6Address#isMulticastAddress()
 	 */
@@ -957,4 +961,36 @@
 
 		return fullString.toUpperCase();
 	}
+
+    /*
+     * Test serialization/deserilazation.
+     */
+    public void testSerialization() throws Exception {       
+        byte[] localv6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };        
+        Inet6Address ia = (Inet6Address) InetAddress.getByAddress(localv6);
+        Inet6Address deIA = (Inet6Address) SerializationTester
+                .getDeserilizedObject(ia);
+        byte[] deAddr = deIA.getAddress();
+        for (int i = 0; i < localv6.length; i++) {
+            assertEquals(localv6[i], deAddr[i]);
+        }
+        assertEquals(ia.getScopeId(), deIA.getScopeId());
+        assertEquals(ia.getScopedInterface(), deIA.getScopedInterface());
+    }
+
+    /*
+     * Test serialization/deserilazation compatibility with RI.
+     */
+    public void testSerializationCompatibility() throws Exception {
+        byte[] localv6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
+        Inet6Address ia = (Inet6Address) InetAddress.getByAddress(localv6);
+        Inet6Address deIA = (Inet6Address) SerializationTester.readObject(ia,
+                SERIALIZATION_FILE_NAME);
+        byte[] deAddr = deIA.getAddress();
+        for (int i = 0; i < localv6.length; i++) {
+            assertEquals(localv6[i], deAddr[i]);
+        }
+        assertEquals(ia.getScopeId(), deIA.getScopeId());
+        assertEquals(ia.getScopedInterface(), deIA.getScopedInterface());
+    }
 }



Mime
View raw message