This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: NetworkInterface tests


This adds an internal consistency check for java.net.NetworkInterface,
which tests if:

  - you get the same interface if you use getByName and getByAddress for
all interfaces returned by getNetworkInterfaces.
  - there's only one interface with each given name returned by
getNetworkInterfaces.
  - getNetworkInterfaces returns at least one interface.
  - each interface returned has at least one address.

I'm also removing a bogus check from the existing getByName test: it
assumes that there is an interface named "lo" on the system, which isn't
true. On OS X the loopback interface is called "lo0". We can't make
assumptions about how network interfaces are named.

2006-09-09  Casey Marshall  <csm@gnu.org>

	* gnu/testlet/java/net/NetworkInterface/Consistency.java: new
	test.
	* gnu/testlet/java/net/NetworkInterface/getByName.java (test):
	don't test for interfaces named "lo".

### Eclipse Workspace Patch 1.0
#P mauve
Index: gnu/testlet/java/net/NetworkInterface/getByName.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/net/NetworkInterface/getByName.java,v
retrieving revision 1.1
diff -u -r1.1 getByName.java
--- gnu/testlet/java/net/NetworkInterface/getByName.java	7 May 2004 10:44:31 -0000	1.1
+++ gnu/testlet/java/net/NetworkInterface/getByName.java	9 Sep 2006 21:41:53 -0000
@@ -46,21 +46,12 @@
     }
     
     try {
-      netif = NetworkInterface.getByName("lo");
-      
-      h.check(netif != null, "- 2 - return value expected to be non-null");
-    }
-    catch (Exception e) {
-      h.fail("- 2 - no exeption expected");
-    }
-
-    try {
       netif = NetworkInterface.getByName("abcde");
 
-      h.check(netif == null, "- 3 - return value expected to be null");
+      h.check(netif == null, "- 2 - return value expected to be null");
     }
     catch (Exception e) {
-      h.fail("- 3 - no exeption expected");
+      h.fail("- 2 - no exeption expected");
     }
   }
 }
Index: gnu/testlet/java/net/NetworkInterface/Consistency.java
===================================================================
RCS file: gnu/testlet/java/net/NetworkInterface/Consistency.java
diff -N gnu/testlet/java/net/NetworkInterface/Consistency.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/net/NetworkInterface/Consistency.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,101 @@
+/* Consistency.java -- test NetworkInterface API consistency.
+   Copyright (C) 2006  Casey Marshall <csm@gnu.org>
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.  */
+
+// Tags: JDK1.4
+
+package gnu.testlet.java.net.NetworkInterface;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.util.Enumeration;
+import java.util.HashSet;
+
+/**
+ * @author csm
+ *
+ */
+public class Consistency
+  implements Testlet
+{
+
+  /* (non-Javadoc)
+   * @see gnu.testlet.Testlet#test(gnu.testlet.TestHarness)
+   */
+  public void test(TestHarness harness)
+  {
+    Enumeration ifs = null;
+    harness.checkPoint("getNetworkInterfaces");
+    try
+      {
+        ifs = NetworkInterface.getNetworkInterfaces();
+        harness.check(ifs != null);
+      }
+    catch (Exception x)
+      {
+        harness.fail("getNetworkInterfaces");
+        harness.debug(x);
+        return;
+      }
+    
+    harness.check(ifs.hasMoreElements(), "getNetworkInterfaces returns something");
+    
+    HashSet names = new HashSet();
+    while (ifs.hasMoreElements())
+      {
+        NetworkInterface netif = (NetworkInterface) ifs.nextElement();
+        harness.checkPoint("consistency - " + netif.getName());
+        harness.check(!names.contains(netif.getName()), "duplicate entries");
+        names.add(netif.getName());
+
+        try
+          {
+            NetworkInterface netif2 = NetworkInterface.getByName(netif.getName());
+            harness.check(netif2 != null);
+            harness.check(netif.equals(netif2));
+          }
+        catch (Exception x)
+          {
+            harness.fail("getByName unexpected exception");
+            harness.debug(x);
+          }
+        
+        Enumeration addrs = netif.getInetAddresses();
+        harness.check(addrs.hasMoreElements());
+        
+        while (addrs.hasMoreElements())
+          {
+            try
+              {
+                InetAddress addr = (InetAddress) addrs.nextElement();
+                NetworkInterface netif2 = NetworkInterface.getByInetAddress(addr);
+                harness.check(netif2 != null);
+                harness.check(netif.equals(netif2));
+              }
+            catch (Exception x)
+              {
+                harness.fail("getByAddress unexpected exception");
+                harness.debug(x);
+              }
+          }
+      }
+  }
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]