harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r562231 - in /harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api: unix/org/apache/harmony/luni/tests/java/net/ windows/org/apache/harmony/luni/tests/java/net/
Date Thu, 02 Aug 2007 19:54:53 GMT
Author: tellison
Date: Thu Aug  2 12:54:52 2007
New Revision: 562231

URL: http://svn.apache.org/viewvc?view=rev&rev=562231
Log:
Apply patch for HARMONY-4182 ([classlib][luni][java6] New unit test for java.net.NetworkInterface
for java6)

Added:
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixNetworkInterfaceTest.java
  (with props)
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/net/
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/net/WinNetworkInterfaceTest.java
  (with props)

Added: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixNetworkInterfaceTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixNetworkInterfaceTest.java?view=auto&rev=562231
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixNetworkInterfaceTest.java
(added)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixNetworkInterfaceTest.java
Thu Aug  2 12:54:52 2007
@@ -0,0 +1,240 @@
+/* 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.NetworkInterface;
+import java.util.Enumeration;
+
+import junit.framework.TestCase;
+
+/**
+ * Please note that this case can only be passed on Linux with the user is
+ * 'root'.
+ * 
+ */
+public class UnixNetworkInterfaceTest extends TestCase {
+    private Enumeration<NetworkInterface> netifs = null;
+
+    private boolean valid = false;
+
+    /**
+     * @tests java.net.NetworkInterface#isUp()
+     * 
+     * @since 1.6
+     */
+    public void test_isUp() throws Exception {
+        while (netifs.hasMoreElements()) {
+            NetworkInterface netif = netifs.nextElement();
+            String name = netif.getName();
+            boolean up = netif.isUp();
+            // Down network interface will bring side effect on the
+            // platform. So chooses the already-down interface to up it.
+            if (!up && valid) {
+                String cmd = "ifconfig " + name + " up";
+                Process proc = Runtime.getRuntime().exec(cmd);
+                proc.waitFor();
+                assertEquals(name + " up should be " + !up, !up, netif.isUp());
+
+                cmd = "ifconfig " + name + " down";
+                proc = Runtime.getRuntime().exec(cmd);
+                proc.waitFor();
+                assertEquals(name + " up should be " + up, up, netif.isUp());
+            }
+        }
+    }
+
+    /**
+     * @tests java.net.NetworkInterface#supportsMulticast()
+     * 
+     * @since 1.6
+     */
+    public void test_supportsMulticast() throws Exception {
+        while (netifs.hasMoreElements()) {
+            NetworkInterface netif = netifs.nextElement();
+            String name = netif.getName();
+            boolean multicast = netif.supportsMulticast();
+            if (valid) {
+                String cmd = multicast ? "ifconfig " + name + " -multicast"
+                        : "ifconfig " + name + " multicast";
+                Process proc = Runtime.getRuntime().exec(cmd);
+                proc.waitFor();
+                assertEquals(name + " multicast should be " + !multicast,
+                        !multicast, netif.supportsMulticast());
+
+                cmd = multicast ? "ifconfig " + name + " multicast"
+                        : "ifconfig " + name + " -multicast";
+                proc = Runtime.getRuntime().exec(cmd);
+                proc.waitFor();
+                assertEquals(name + " multicast should be " + multicast,
+                        multicast, netif.supportsMulticast());
+            }
+        }
+    }
+
+    /**
+     * @tests java.net.NetworkInterface#getHardwareAddress()
+     * 
+     * @since 1.6
+     */
+    public void test_getHardwareAddress() throws Exception {
+        while (netifs.hasMoreElements()) {
+            NetworkInterface netif = netifs.nextElement();
+            String name = netif.getName();
+            byte[] hardAddr = netif.getHardwareAddress();
+
+            if (hardAddr != null && valid) {
+                String hardwareAddress = toHardwareAddress(hardAddr);
+                String newHardwareAddr = "0:11:25:1B:BD:FF";
+                String cmd = "ifconfig " + name + " hw ether "
+                        + newHardwareAddr;
+                Process proc = Runtime.getRuntime().exec(cmd);
+                proc.waitFor();
+                assertEquals(name + "'s hardware address should be"
+                        + newHardwareAddr, newHardwareAddr,
+                        toHardwareAddress(netif.getHardwareAddress()));
+
+                cmd = "ifconfig " + name + " hw ether " + hardwareAddress;
+                proc = Runtime.getRuntime().exec(cmd);
+                proc.waitFor();
+                assertEquals(name + "'s hardware address should be"
+                        + hardwareAddress, hardwareAddress,
+                        toHardwareAddress(netif.getHardwareAddress()));
+            }
+        }
+    }
+
+    /**
+     * @tests java.net.NetworkInterface#getMTU()
+     * 
+     * @since 1.6
+     */
+    public void test_getMTU() throws Exception {
+        while (netifs.hasMoreElements()) {
+            NetworkInterface netif = netifs.nextElement();
+            String name = netif.getName();
+            int mtu = netif.getMTU();
+            if (valid) {
+                String cmd = "ifconfig " + name + " mtu 1000";
+                Process proc = Runtime.getRuntime().exec(cmd);
+                proc.waitFor();
+                assertEquals(name + " MTU should be 1000", 1000, netif.getMTU());
+
+                cmd = "ifconfig " + name + " mtu " + mtu;
+                proc = Runtime.getRuntime().exec(cmd);
+                proc.waitFor();
+                assertEquals(name + " MTU should be " + mtu, mtu, netif
+                        .getMTU());
+            }
+        }
+    }
+
+    /**
+     * @tests java.net.NetworkInterface#getSubInterfaces()
+     * 
+     * @since 1.6
+     */
+    public void test_getSubInterfaces() throws Exception {
+        while (netifs.hasMoreElements()) {
+            NetworkInterface netif = netifs.nextElement();
+            Enumeration<NetworkInterface> subInterfaces1 = netif
+                    .getSubInterfaces();
+            Enumeration<NetworkInterface> subInterfaces2 = netif
+                    .getSubInterfaces();
+            while (subInterfaces1.hasMoreElements()
+                    && subInterfaces2.hasMoreElements() && valid) {
+                NetworkInterface sub1 = subInterfaces1.nextElement();
+                NetworkInterface sub2 = subInterfaces2.nextElement();
+                assertSame(sub1, sub2);
+                assertSame(netif, sub1.getParent());
+            }
+        }
+    }
+
+    /**
+     * @tests java.net.NetworkInterface#getParent()
+     * 
+     * @since 1.6
+     */
+    public void test_getParent() {
+        while (netifs.hasMoreElements()) {
+            NetworkInterface netif = netifs.nextElement();
+            Enumeration<NetworkInterface> subInterfaces = netif
+                    .getSubInterfaces();
+            boolean contains = false;
+            boolean hasSubInterfaces = false;
+            while (subInterfaces.hasMoreElements() && valid) {
+                hasSubInterfaces = true;
+                NetworkInterface sub = subInterfaces.nextElement();
+                NetworkInterface parent1 = sub.getParent();
+                NetworkInterface parent2 = sub.getParent();
+                assertSame(parent1, parent2);
+                if (netif.equals(parent1)) {
+                    contains = true;
+                    break;
+                }
+            }
+            assertEquals(hasSubInterfaces, contains);
+        }
+    }
+
+    /**
+     * 
+     * @tests java.net.NetworkInterface#isVirtual()
+     * 
+     * @since 1.6
+     */
+    public void test_isVirtual() {
+        while (netifs.hasMoreElements()) {
+            NetworkInterface netif = netifs.nextElement();
+            boolean virtual = netif.getParent() != null;
+            assertEquals(netif.getName() + " isVirtual() is" + !virtual,
+                    virtual, netif.isVirtual());
+            Enumeration<NetworkInterface> subInterfaces = netif
+                    .getSubInterfaces();
+            while (subInterfaces.hasMoreElements()) {
+                assertTrue(subInterfaces.nextElement().isVirtual());
+            }
+        }
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        netifs = NetworkInterface.getNetworkInterfaces();
+        valid = (netifs != null)
+                && System.getProperty("user.name").equals("root");
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        netifs = null;
+        valid = false;
+        super.tearDown();
+    }
+
+    private static String toHardwareAddress(byte[] hardAddr) {
+        StringBuilder builder = new StringBuilder();
+        for (byte b : hardAddr) {
+            builder.append(Integer.toHexString(b >= 0 ? b : b + 256)
+                    .toUpperCase());
+            if (hardAddr[hardAddr.length - 1] != b) {
+                builder.append(":");
+            }
+        }
+        return builder.toString();
+    }
+}

Propchange: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/net/UnixNetworkInterfaceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/net/WinNetworkInterfaceTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/net/WinNetworkInterfaceTest.java?view=auto&rev=562231
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/net/WinNetworkInterfaceTest.java
(added)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/net/WinNetworkInterfaceTest.java
Thu Aug  2 12:54:52 2007
@@ -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.io.IOException;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.util.ArrayList;
+import java.util.Enumeration;
+
+import junit.framework.TestCase;
+
+
+public class WinNetworkInterfaceTest extends TestCase {
+    // Regression Test for Harmony-2290
+    public void test_isReachableLjava_net_NetworkInterfaceII_loopbackInterface()
+            throws IOException {
+        final int TTL = 20;
+        final int TIME_OUT = 3000;
+
+        NetworkInterface loopbackInterface = null;
+        ArrayList<InetAddress> localAddresses = new ArrayList<InetAddress>();
+        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
+                .getNetworkInterfaces();
+        while (networkInterfaces.hasMoreElements()) {
+            NetworkInterface networkInterface = networkInterfaces.nextElement();
+            Enumeration<InetAddress> addresses = networkInterface
+                    .getInetAddresses();
+            while (addresses.hasMoreElements()) {
+                InetAddress address = addresses.nextElement();
+                if (address.isLoopbackAddress()) {
+                    loopbackInterface = networkInterface;
+                } else {
+                    localAddresses.add(address);
+                }
+            }
+        }
+
+        // loopbackInterface can reach local address
+        if (null != loopbackInterface) {
+            for (InetAddress destAddress : localAddresses) {
+                System.out.println(destAddress);
+                assertTrue(destAddress.isReachable(loopbackInterface, TTL,
+                        TIME_OUT));
+            }
+        }
+
+        // loopback Interface cannot reach outside address
+        // InetAddress destAddress = InetAddress.getByName("www.google.com");
+        // assertFalse(destAddress.isReachable(loopbackInterface, TTL,
+        // TIME_OUT));
+    }
+}

Propchange: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/net/WinNetworkInterfaceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message