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 2007/06/15 13:38:01 UTC
svn commit: r547638 -
/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InterfaceAddressTest.java
Author: tellison
Date: Fri Jun 15 04:38:00 2007
New Revision: 547638
URL: http://svn.apache.org/viewvc?view=rev&rev=547638
Log:
Apply patch HARMONY-4180 ([classlib][luni][java6] New unit test for java.net.InterfaceAddress for java6)
Added:
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InterfaceAddressTest.java (with props)
Added: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InterfaceAddressTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InterfaceAddressTest.java?view=auto&rev=547638
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InterfaceAddressTest.java (added)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InterfaceAddressTest.java Fri Jun 15 04:38:00 2007
@@ -0,0 +1,170 @@
+/*
+ * 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.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.InterfaceAddress;
+import java.net.NetworkInterface;
+import java.util.Enumeration;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class InterfaceAddressTest extends TestCase {
+ private InterfaceAddress interfaceAddr;
+
+ private InterfaceAddress anotherInterfaceAddr;
+
+ /**
+ * @tests java.net.InterfaceAddress.hashCode()
+ *
+ * @since 1.6
+ */
+ public void test_hashCode() {
+ // RI may fail on this when both broadcast addresses are null
+ if (interfaceAddr != null) {
+ assertEquals(anotherInterfaceAddr, interfaceAddr);
+ assertEquals(anotherInterfaceAddr.hashCode(), interfaceAddr
+ .hashCode());
+ }
+ }
+
+ /**
+ * @tests java.net.InterfaceAddress.equals(Object)
+ *
+ * @since 1.6
+ */
+ public void test_equals_LObject() {
+ // RI may fail on this when both broadcast addresses are null
+ if (interfaceAddr != null) {
+ assertFalse(interfaceAddr.equals(null));
+ assertFalse(interfaceAddr.equals(new Object()));
+
+ assertTrue(interfaceAddr.equals(anotherInterfaceAddr));
+ assertNotSame(anotherInterfaceAddr, interfaceAddr);
+ }
+ }
+
+ /**
+ * @tests java.net.InterfaceAddress.toString()
+ *
+ * @since 1.6
+ */
+ public void test_toString() {
+ if (interfaceAddr != null) {
+ assertNotNull(interfaceAddr.toString());
+ assertEquals(anotherInterfaceAddr.toString(), interfaceAddr
+ .toString());
+ assertTrue(interfaceAddr.toString().contains("/"));
+ assertTrue(interfaceAddr.toString().contains("["));
+ assertTrue(interfaceAddr.toString().contains("]"));
+ }
+ }
+
+ /**
+ * @tests java.net.InterfaceAddress.getAddress()
+ *
+ * @since 1.6
+ */
+ public void test_getAddress() {
+ if (interfaceAddr != null) {
+ InetAddress addr1 = interfaceAddr.getAddress();
+ assertNotNull(addr1);
+ InetAddress addr2 = anotherInterfaceAddr.getAddress();
+ assertNotNull(addr2);
+ assertEquals(addr2, addr1);
+ }
+ }
+
+ /**
+ * @tests java.net.InterfaceAddress.getBroadcast()
+ *
+ * @since 1.6
+ */
+ public void test_getBroadcast() {
+ if (interfaceAddr != null) {
+ InetAddress addr = interfaceAddr.getAddress();
+ InetAddress addr1 = interfaceAddr.getBroadcast();
+ InetAddress addr2 = anotherInterfaceAddr.getBroadcast();
+ if (addr instanceof Inet4Address) {
+ assertEquals(addr2, addr1);
+ } else if (addr instanceof Inet6Address) {
+ assertNull(addr1);
+ assertNull(addr2);
+ }
+ }
+ }
+
+ /**
+ * @tests java.net.InterfaceAddress.getNetworkPrefixLength()
+ *
+ * @since 1.6
+ */
+ public void test_getNetworkPrefixLength() {
+ if (interfaceAddr != null) {
+ short prefix1 = interfaceAddr.getNetworkPrefixLength();
+ short prefix2 = anotherInterfaceAddr.getNetworkPrefixLength();
+ assertEquals(prefix2, prefix1);
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Enumeration<NetworkInterface> netifs = NetworkInterface
+ .getNetworkInterfaces();
+ NetworkInterface theInterface = null;
+ if (netifs != null) {
+ while (netifs.hasMoreElements()) {
+ theInterface = netifs.nextElement();
+ if (theInterface != null) {
+ List<InterfaceAddress> addrs = theInterface
+ .getInterfaceAddresses();
+ if (!(addrs == null || addrs.isEmpty())) {
+ interfaceAddr = addrs.get(0);
+ break;
+ }
+ }
+ }
+ }
+
+ // get another InterfaceAddress object if the interfaceAddr exists. It
+ // equals to interfaceAddr, but is not the same one.
+ if (theInterface != null && interfaceAddr != null) {
+ Enumeration<InetAddress> addresses = theInterface
+ .getInetAddresses();
+ if (addresses != null && addresses.hasMoreElements()) {
+ NetworkInterface anotherNetworkInter = NetworkInterface
+ .getByInetAddress(addresses.nextElement());
+ anotherInterfaceAddr = anotherNetworkInter
+ .getInterfaceAddresses().get(0);
+ }
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ interfaceAddr = null;
+ anotherInterfaceAddr = null;
+ super.tearDown();
+ }
+
+}
Propchange: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InterfaceAddressTest.java
------------------------------------------------------------------------------
svn:eol-style = native