summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAaron M. Renn <arenn@urbanophile.com>1998-05-18 00:34:12 +0000
committerAaron M. Renn <arenn@urbanophile.com>1998-05-18 00:34:12 +0000
commitcef12ba87faabdb23fc796df9046ddf61247e325 (patch)
treef19569ad75e9695f2448093caeed508768f9a5cb /test
parente5cd4c332de77192e9beb4b0533a2e6ffe0e0cd1 (diff)
downloadclasspath-cef12ba87faabdb23fc796df9046ddf61247e325.tar.gz
Initial Checkin
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am4
-rw-r--r--test/java.net/ClientDatagram.java112
-rw-r--r--test/java.net/ClientSocket.java189
-rw-r--r--test/java.net/Makefile.am9
-rw-r--r--test/java.net/MulticastClient.java65
-rw-r--r--test/java.net/MulticastServer.java57
-rw-r--r--test/java.net/ServerDatagram.java52
-rw-r--r--test/java.net/ServerSocketTest.java53
-rw-r--r--test/java.net/SubSocket.java6
-rw-r--r--test/java.net/TestNameLookups.java103
-rw-r--r--test/java.net/URLTest.java150
-rwxr-xr-xtest/java.net/runtest32
12 files changed, 832 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 000000000..1376de35c
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,4 @@
+## Input file for automake to generate the Makefile.in used by configure
+
+SUBDIRS = java.net
+
diff --git a/test/java.net/ClientDatagram.java b/test/java.net/ClientDatagram.java
new file mode 100644
index 000000000..6ec98258e
--- /dev/null
+++ b/test/java.net/ClientDatagram.java
@@ -0,0 +1,112 @@
+/* Class to test Datagrams from a client perspective */
+
+import java.io.*;
+import java.net.*;
+
+public class ClientDatagram
+{
+
+public static void
+main(String[] argv) throws IOException
+{
+ System.out.println("Starting datagram tests");
+
+ byte[] buf = new byte[2048];
+ DatagramPacket p = new DatagramPacket(buf, buf.length);
+ InetAddress addr = InetAddress.getByName("localhost");
+
+ /* Execute the daytime UDP service on localhost. You may need to
+ enable this in inetd to make the test work */
+ System.out.println("Test 1: Simple daytime test");
+ try
+ {
+
+ DatagramSocket s = new DatagramSocket();
+
+ System.out.println("Socket bound to " + s.getLocalAddress() +
+ ":" + s.getLocalPort());
+
+ byte[] sbuf = { 'H', 'I' };
+ DatagramPacket spack = new DatagramPacket(sbuf, sbuf.length, addr, 13);
+
+ s.send(spack);
+ s.receive(p);
+
+ System.out.println("Received " + p.getLength() + " bytes from " +
+ p.getAddress() + ":" + p.getPort());
+
+ byte[] tmp = new byte[p.getLength()];
+ for (int i = 0; i < p.getLength(); i++)
+ tmp[i] = buf[i];
+
+ System.out.print("Data: " + new String(tmp));
+
+ s.close();
+ System.out.println("PASSED simple datagram test");
+ }
+ catch(Exception e)
+ {
+ System.out.println("FAILED simple datagram test: " + e);
+ }
+
+ System.out.println("Test 2: Specific host/port binding");
+ try
+ {
+ DatagramSocket s = new DatagramSocket(8765, addr);
+ if (s.getLocalPort() != 8765)
+ throw new IOException("Bound to wrong port: " + s.getLocalPort());
+
+ if (!s.getLocalAddress().equals(addr))
+ throw new IOException("Bound to wrong host:" + s.getLocalAddress());
+
+ s.close();
+ System.out.println("PASSED specific host/port binding test");
+ }
+ catch (Exception e)
+ {
+ System.out.println("FAILED specific host/port binding: " + e);
+ }
+
+ System.out.println("Test 3: Socket Options test");
+ try
+ {
+ DatagramSocket s = new DatagramSocket();
+ System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
+ System.out.println("Setting SO_TIMEOUT to 170");
+ s.setSoTimeout(170);
+ System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
+ System.out.println("Setting SO_TIMEOUT to 0");
+ s.setSoTimeout(0);
+ System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
+ s.close();
+ }
+ catch(Exception e)
+ {
+ System.out.println("WARNING: Problem with SO_TIMEOUT test: " + e.getMessage());
+ System.out.println("This is ok on Linux");
+ }
+
+ System.out.println("Test 4: Max values test");
+ try
+ {
+// ServerDatagram sd = new ServerDatagram(37900);
+// sd.run();
+
+ DatagramSocket s = new DatagramSocket();
+ byte[] sbuf = new byte[65332];
+ DatagramPacket spack = new DatagramPacket(sbuf, sbuf.length,
+ addr, 37900);
+
+ s.send(spack);
+ s.close();
+ }
+ catch (Exception e)
+ {
+ System.out.println("FAILED max values test: " + e);
+ }
+
+ System.out.println("Datagram testing complete");
+}
+
+}
+
diff --git a/test/java.net/ClientSocket.java b/test/java.net/ClientSocket.java
new file mode 100644
index 000000000..53a498b34
--- /dev/null
+++ b/test/java.net/ClientSocket.java
@@ -0,0 +1,189 @@
+/* A class to test my client TCP socket implementation */
+
+import java.net.*;
+import java.io.*;
+
+public class ClientSocket extends Object
+{
+public static void
+main(String[] argv) throws IOException
+{
+ System.out.println("Starting client stream socket test");
+
+ /* Simple connection and read test */
+ System.out.println("Test 1: Connection to daytime port on local host");
+ try
+ {
+ InetAddress addr = InetAddress.getByName("127.0.0.1");
+
+ Socket s = new Socket(addr, 13);
+
+ InputStream is = s.getInputStream();
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
+
+ for (String str = br.readLine(); ; str = br.readLine())
+ {
+ if (str == null)
+ break;
+ System.out.println(str);
+ }
+ s.close();
+ System.out.println("PASSED: daytime test");
+ }
+ catch(IOException e)
+ {
+ System.out.println("FAILED: daytime test: " + e);
+ }
+
+ /* Simple connection refused test */
+ System.out.println("Test 2: Connection refused test");
+ try
+ {
+ InetAddress addr = InetAddress.getByName("127.0.0.1");
+
+ Socket s = new Socket(addr, 47);
+ s.close();
+
+ System.out.print("WARNING: Cannot perform connection refused test");
+ System.out.println(" because someone is listening on localhost:47");
+ }
+ catch(IOException e)
+ {
+ System.out.println("PASSED: connection refused test: " + e.getMessage());
+ }
+
+ /* Socket attributes test */
+ System.out.println("Test 3: Connection attributes");
+ try
+ {
+ Socket s = new Socket("www.netscape.com", 80);
+
+ String laddr = s.getLocalAddress().getHostName();
+ int lport = s.getLocalPort();
+ String raddr = s.getInetAddress().getHostName();
+ int rport = s.getPort();
+
+ System.out.println("Local Address is: " + laddr);
+ System.out.println("Local Port is: " + lport);
+ System.out.println("Remote Address is: " + raddr);
+ System.out.println("Remote Port is: " + rport);
+ System.out.println("Socket.toString is: " + s);
+
+ if ( (laddr == null) ||
+ ((lport < 0) || (lport > 65535)) ||
+ (raddr.indexOf("netscape.com") == -1) ||
+ (rport != 80))
+ System.out.println("FAILED: connection attribute test");
+ else
+ System.out.println("PASSED: connection attribute test");
+
+ s.close();
+ }
+ catch(IOException e)
+ {
+ System.out.println("FAILED: connection attributes test: " + e.getMessage());
+ }
+
+ /* Socket options test */
+ System.out.println("Test 4: Socket options");
+ Socket s = new Socket("127.0.0.1", 23);
+
+ try
+ {
+ // SO_TIMEOUT
+ System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
+ System.out.println("Setting SO_TIMEOUT to 142");
+ s.setSoTimeout(142);
+ System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
+ System.out.println("Setting SO_TIMEOUT to 0");
+ s.setSoTimeout(0);
+ System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
+ }
+ catch (IOException e)
+ {
+ System.out.println("WARNING: SO_TIMEOUT problem: " + e.getMessage());
+ System.out.println("This is ok on Linux");
+ }
+ try
+ {
+ // Try TCP_NODELAY
+ System.out.println("TCP_NODELAY = " + s.getTcpNoDelay());
+ System.out.println("Setting TCP_NODELAY to true");
+ s.setTcpNoDelay(true);
+ System.out.println("TCP_NODELAY = " + s.getTcpNoDelay());
+ System.out.println("Setting TCP_NODELAY to false");
+ s.setTcpNoDelay(false);
+ System.out.println("TCP_NODELAY = " + s.getTcpNoDelay());
+
+ // Try SO_LINGER
+ System.out.println("SO_LINGER = " + s.getSoLinger());
+ System.out.println("Setting SO_LINGER to 100");
+ s.setSoLinger(true, 100);
+ System.out.println("SO_LINGER = " + s.getSoLinger());
+ System.out.println("Setting SO_LINGER to off");
+ s.setSoLinger(false, 0);
+ System.out.println("SO_LINGER = " + s.getSoLinger());
+
+ System.out.println("PASSED: socket options test");
+ }
+ catch(IOException e)
+ {
+ System.out.println("FAILED: socket options test: " + e.getMessage());
+ }
+ s.close();
+
+ /* Simple read/write test */
+ System.out.println("Test 5: Simple read/write test");
+ try
+ {
+ System.out.println("Downloading the Transmeta homepage");
+ s = new Socket("www.transmeta.com", 80);
+
+ BufferedReader in = new BufferedReader(new
+ InputStreamReader(s.getInputStream()));
+ PrintWriter out = new PrintWriter(new
+ OutputStreamWriter(s.getOutputStream()));
+
+ out.print("GET /\r\n");
+ out.flush();
+
+ for (String str = in.readLine(); ; str = in.readLine())
+ {
+ if (str == null)
+ break;
+ System.out.println(str);
+ }
+
+ s.close();
+ System.out.println("PASSED: simple read/write test");
+ }
+ catch(IOException e)
+ {
+ System.out.println("FAILED: simple read/write test: " + e.getMessage());
+ }
+
+ /* Connect to our server socket */
+ System.out.println("Test 6: Connect to ServerSocket");
+ try
+ {
+ s = new Socket("localhost", 9999);
+
+ PrintWriter out = new PrintWriter(new
+ OutputStreamWriter(s.getOutputStream()));
+
+ out.println("Hello, there server socket");
+ out.print("I'm dun");
+ out.flush();
+ s.close();
+ System.out.println("PASSED: connect to server socket");
+ }
+ catch(Exception e)
+ {
+ System.out.println("FAILED: connect to server socket: " + e);
+ }
+
+ System.out.println("Client stream socket test complete");
+}
+
+}
+
diff --git a/test/java.net/Makefile.am b/test/java.net/Makefile.am
new file mode 100644
index 000000000..f57f67fbb
--- /dev/null
+++ b/test/java.net/Makefile.am
@@ -0,0 +1,9 @@
+## Input file for automake to generate the Makefile.in used by configure
+
+JAVAROOT = .
+
+check_JAVA = ClientDatagram.java ClientSocket.java MulticastClient.java \
+ MulticastServer.java ServerDatagram.java ServerSocketTest.java \
+ SubSocket.java TestNameLookups.java URLTest.java
+
+EXTRA_DIST = BUGS runtest
diff --git a/test/java.net/MulticastClient.java b/test/java.net/MulticastClient.java
new file mode 100644
index 000000000..8dc18fe82
--- /dev/null
+++ b/test/java.net/MulticastClient.java
@@ -0,0 +1,65 @@
+/* Test Multicast Sockets */
+
+import java.net.*;
+import java.io.*;
+
+public class MulticastClient
+{
+
+public static void
+main(String[] argv) throws IOException
+{
+ System.out.println("Starting multicast tests");
+ System.out.println("NOTE: You need to do an 'ifconfig <interface> " +
+ "multicast' or this will fail on linux");
+
+ byte[] buf = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o','r','l','d' };
+
+ /* Simple Send */
+ System.out.println("Test 1: Multicast send/receive test");
+ try
+ {
+ InetAddress addr = InetAddress.getByName("234.0.0.1");
+
+ MulticastSocket s = new MulticastSocket();
+ DatagramPacket p = new DatagramPacket(buf, buf.length, addr, 3333);
+
+ s.joinGroup(addr);
+ s.send(p);
+ s.close();
+ }
+ catch(IOException e)
+ {
+ System.out.println("FAILED: simple multicast send: " + e);
+ }
+
+ /* Options */
+ System.out.println("Test 2: Multicast socket options");
+ try
+ {
+ InetAddress addr;
+ MulticastSocket s = new MulticastSocket();
+
+ System.out.println("TTL = " + s.getTTL());
+ System.out.println("Setting TTT to 121");
+ s.setTTL((byte)12);
+ System.out.println("TTL = " + s.getTTL());
+
+ InetAddress oaddr = s.getInterface();
+ System.out.println("Multicast Interface = " + oaddr);
+ System.out.println("Setting interface to localhost");
+ addr = InetAddress.getByName("198.211.138.177");
+ s.setInterface(addr);
+ System.out.println("Multicast Interface = " + s.getInterface());
+ System.out.println("Setting interface to " + oaddr);
+ s.setInterface(oaddr);
+ System.out.println("Multicast Interface = " + s.getInterface());
+ }
+ catch(IOException e)
+ {
+ System.out.println("FAILED: multicast options: " + e);
+ }
+}
+
+}
+
diff --git a/test/java.net/MulticastServer.java b/test/java.net/MulticastServer.java
new file mode 100644
index 000000000..1a54f99eb
--- /dev/null
+++ b/test/java.net/MulticastServer.java
@@ -0,0 +1,57 @@
+/* Mulitcast Server Socket for testing */
+
+import java.io.*;
+import java.net.*;
+
+public class MulticastServer
+{
+
+private MulticastSocket s;
+
+public static void
+main(String[] argv) throws IOException
+{
+ MulticastServer ms = new MulticastServer(3333);
+ ms.run();
+}
+
+public
+MulticastServer(int port) throws IOException
+{
+ s = new MulticastSocket(port);
+ System.out.println("Server multicast socket created");
+}
+
+public void
+run()
+{
+ try
+ {
+ byte[] buf = new byte[255];
+
+ DatagramPacket p = new DatagramPacket(buf, buf.length);
+ InetAddress addr = InetAddress.getByName("234.0.0.1");
+
+ p.setLength(buf.length);
+
+ System.out.println("Joining multicast group");
+ s.joinGroup(addr);
+ System.out.print("Receiving ...");
+ s.receive(p);
+ System.out.println("");
+ s.leaveGroup(addr);
+ System.out.println("ServerDatagram: received " + p.getLength() +
+ " bytes from " + p.getAddress().getHostName() + ":" +
+ p.getPort());
+ System.out.println("Data: " + new String(p.getData()));
+
+ System.out.println("PASSED multicast server test");
+ }
+ catch (IOException e)
+ {
+ System.out.println("FAILED: MulticastServer caught an exception: " + e);
+ }
+}
+
+}
+
diff --git a/test/java.net/ServerDatagram.java b/test/java.net/ServerDatagram.java
new file mode 100644
index 000000000..17ce44a27
--- /dev/null
+++ b/test/java.net/ServerDatagram.java
@@ -0,0 +1,52 @@
+/* Server Datagram Socket for testing */
+
+import java.io.*;
+import java.net.*;
+
+public class ServerDatagram implements Runnable
+{
+
+private DatagramSocket s;
+
+public static void
+main(String[] argv) throws IOException
+{
+ ServerDatagram sd = new ServerDatagram(37900);
+ sd.run();
+}
+
+public
+ServerDatagram(int port) throws SocketException
+{
+ s = new DatagramSocket(port);
+ System.out.println("Server datagram socket created");
+}
+
+public void
+run()
+{
+ try
+ {
+ byte[] buf = new byte[65535];
+
+ DatagramPacket p = new DatagramPacket(buf, buf.length);
+
+ p.setLength(buf.length);
+
+ s.receive(p);
+ System.out.println("ServerDatagram: received " + p.getLength() +
+ " bytes from " + p.getAddress().getHostName() + ":" +
+ p.getPort());
+
+ if (p.getLength() != 65332)
+ throw new IOException("Incorrect data size");
+ System.out.println("PASSED max values test");
+ }
+ catch (IOException e)
+ {
+ System.out.print("FAILED: ServerDatagram caught an exception: " + e);
+ }
+}
+
+}
+
diff --git a/test/java.net/ServerSocketTest.java b/test/java.net/ServerSocketTest.java
new file mode 100644
index 000000000..f444963a9
--- /dev/null
+++ b/test/java.net/ServerSocketTest.java
@@ -0,0 +1,53 @@
+/* Class to test server sockets */
+
+import java.io.*;
+import java.net.*;
+
+public class ServerSocketTest extends ServerSocket
+{
+
+public
+ServerSocketTest(int port) throws IOException
+{
+ super(port);
+}
+
+public static void
+main(String[] argv)
+{
+ System.out.println("Starting up server socket");
+
+ try {
+ ServerSocketTest ss = new ServerSocketTest(9999);
+
+ System.out.println("Created server socket bound to port " +
+ ss.getLocalPort() + " on local address " +
+ ss.getInetAddress());
+
+ SubSocket s = new SubSocket();
+ ss.implAccept(s);
+// Socket s = ss.accept();
+
+ System.out.println("Got a connection from " + s.getInetAddress() +
+ " on port " + s.getPort());
+
+ BufferedReader br = new BufferedReader(new
+ InputStreamReader(s.getInputStream()));
+
+ for (String str = br.readLine(); ; str = br.readLine())
+ {
+ if (str == null)
+ break;
+ System.out.println(str);
+ }
+ s.close();
+ ss.close();
+ System.out.println("PASSED: server socket test");
+ }
+ catch (Exception e) {
+ System.out.println("FAILED: server socket test: " + e);
+ }
+}
+
+}
+
diff --git a/test/java.net/SubSocket.java b/test/java.net/SubSocket.java
new file mode 100644
index 000000000..97da4471c
--- /dev/null
+++ b/test/java.net/SubSocket.java
@@ -0,0 +1,6 @@
+/* Quick and dirty Socket subclass */
+
+public class SubSocket extends java.net.Socket
+{
+}
+
diff --git a/test/java.net/TestNameLookups.java b/test/java.net/TestNameLookups.java
new file mode 100644
index 000000000..592d9e01f
--- /dev/null
+++ b/test/java.net/TestNameLookups.java
@@ -0,0 +1,103 @@
+/* A class to test my java.net.InetAddress implementation */
+
+import java.net.*;
+
+public class TestNameLookups extends Object
+{
+public static void
+main(String[] argv) throws UnknownHostException
+{
+ InetAddress addr;
+
+ System.out.println("Started address lookup test");
+
+ /* Test local host */
+ try
+ {
+ addr = InetAddress.getLocalHost();
+
+ System.out.println("The local hostname is " + addr.getHostName() +
+ " with an IP address of " + addr.getHostAddress());
+ }
+ catch(UnknownHostException e)
+ {
+ System.out.println("WARNING: Can't resolve local hostname");
+ }
+
+ /* Test simple lookup by IP */
+ addr = InetAddress.getByName("18.159.0.42");
+
+ System.out.println("Looked up IP addres 18.159.0.42 and got back a " +
+ "hostname of " + addr.getHostName());
+
+ /* Test failed reverse lookup of IP */
+ addr = InetAddress.getByName("194.72.246.154");
+
+ System.out.println("Looked up IP addres 194.72.246.154 and got back a " +
+ "hostname of " + addr.getHostName());
+
+ /* Test mangled/invalid IP's */
+ try { addr = InetAddress.getByName("122.24.1."); }
+ catch (UnknownHostException e) {
+ System.out.println("Passed bad IP test 1");
+ }
+
+ try { addr = InetAddress.getByName("122.24.52"); }
+ catch (UnknownHostException e) {
+ System.out.println("Passed bad IP test 2");
+ }
+
+ try { addr = InetAddress.getByName("122.256.52.1"); }
+ catch (UnknownHostException e) {
+ System.out.println("Passed bad IP test 3");
+ }
+
+ /* Test simple lookup by name with external info */
+ addr = InetAddress.getByName("www.starnews.com");
+ System.out.println("Looked up host www.starnews.com and got back an " +
+ "IP address of " + addr.getHostAddress());
+ byte[] octets = addr.getAddress();
+ System.out.println("Raw Address Bytes: octet1=" + (int)octets[0] +
+ " octets2=" + (int)octets[1] + " octet3=" + (int)octets[2] +
+ " octets4=" + (int)octets[3]);
+ System.out.println("toString() returned: " + addr.toString());
+ System.out.println("isMulticastAddress returned: "
+ + addr.isMulticastAddress());
+
+ /* Test complex lookup */
+ System.out.println("Looking up all addresses for indiana.edu ...");
+ InetAddress[] list = InetAddress.getAllByName("indiana.edu");
+ for (int i = 0; i < list.length; i++)
+ {
+ addr = list[i];
+
+ System.out.println(" Hostname: " + addr.getHostName() +
+ " IP Address: " + addr.getHostAddress());
+ }
+
+ /* Test equality */
+ InetAddress addr1 = InetAddress.getByName("www.urbanophile.com");
+ InetAddress addr2 = InetAddress.getByName("www.urbanophile.com");
+
+ if (addr1.equals(addr2) && addr2.equals(addr1))
+ System.out.println("Passed equality test #1");
+ else
+ System.out.println("Failed equality test #1");
+
+ addr1 = InetAddress.getByName("www.ac.com");
+ addr2 = InetAddress.getByName("www.hungry.com");
+
+ if (!addr1.equals(addr2) && !addr2.equals(addr1))
+ System.out.println("Passed equality test #2");
+ else
+ System.out.println("Failed equality test #2");
+
+ /* Quick test to see if it looks like we're caching things */
+ addr1 = InetAddress.getByName("www.urbanophile.com");
+ System.out.println("Got " + addr1.getHostName() + " " + addr1.getHostAddress());
+ addr2 = InetAddress.getByName("www.hungry.com");
+ System.out.println("Got " + addr2.getHostName() + " " + addr2.getHostAddress());
+}
+
+}
+
diff --git a/test/java.net/URLTest.java b/test/java.net/URLTest.java
new file mode 100644
index 000000000..82d0929f4
--- /dev/null
+++ b/test/java.net/URLTest.java
@@ -0,0 +1,150 @@
+/* Test URL's */
+
+import java.net.*;
+import java.io.*;
+
+public class URLTest
+{
+
+public static void
+main(String argv[])
+{
+ System.out.println("Starting URL tests");
+
+ /* Simple URL test */
+
+ System.out.println("Test 1: Simple URL test");
+
+ try
+ {
+ URL url = new URL("http", "www.fsf.org", 80, "/");
+
+ if (!url.getProtocol().equals("http") ||
+ !url.getHost().equals("www.fsf.org") ||
+ url.getPort() != 80 ||
+ !url.getFile().equals("/"))
+ System.out.println("FAILED: Simple URL test");
+
+ System.out.println("URL is: " + url.toString());
+
+ URLConnection uc = url.openConnection();
+
+ if (uc instanceof HttpURLConnection)
+ System.out.println("Got the expected connection type");
+
+ HttpURLConnection hc = (HttpURLConnection)uc;
+
+ hc.connect();
+
+ System.out.println("Dumping response headers");
+ for (int i = 0; ; i++)
+ {
+ String key = hc.getHeaderFieldKey(i);
+ if (key == null)
+ break;
+
+ System.out.println(key + ": " + hc.getHeaderField(i));
+ }
+
+ System.out.println("Dumping contents");
+ BufferedReader br = new BufferedReader(new
+ InputStreamReader(hc.getInputStream()));
+
+ for (String str = br.readLine(); str != null; str = br.readLine())
+ System.out.println(str);
+
+ hc.disconnect();
+
+ System.out.println("Content Type: " + hc.getContentType());
+ System.out.println("Content Encoding: " + hc.getContentEncoding());
+ System.out.println("Content Length: " + hc.getContentLength());
+ System.out.println("Date: " + hc.getDate());
+ System.out.println("Expiration: " + hc.getExpiration());
+ System.out.println("Last Modified: " + hc.getLastModified());
+
+ System.out.println("PASSED: Simple URL test");
+ }
+ catch(IOException e)
+ {
+ System.out.println("FAILED: Simple URL test: " + e);
+ }
+
+ // Parsing test
+ System.out.println("Test 2: URL parsing test");
+ try
+ {
+ URL url = new URL("http://www.urbanophile.com/arenn/trans/trans.html#mis");
+ if (!url.toString().equals(
+ "http://www.urbanophile.com/arenn/trans/trans.html#mis"))
+ System.out.println("FAILED: Parse URL test: " + url.toString());
+ else {
+ System.out.println("Parsed ok: " + url.toString());
+ url = new URL("http://www.foo.com:8080/#");
+ if (!url.toString().equals("http://www.foo.com:8080/#"))
+ System.out.println("FAILED: Parse URL test: " + url.toString());
+ else {
+ System.out.println("Parsed ok: " + url.toString());
+ url = new URL("http://www.bar.com/test:file/");
+ if (!url.toString().equals("http://www.bar.com/test:file/"))
+ System.out.println("FAILED: Parse URL test: " + url.toString());
+ else {
+ System.out.println("Parsed ok: " + url.toString());
+ url = new URL("http://www.gnu.org");
+ if (!url.toString().equals("http://www.gnu.org/"))
+ System.out.println("FAILED: Parse URL test: " + url.toString());
+ else {
+ System.out.println("Parsed ok: " + url.toString());
+ url = new URL("HTTP://www.fsf.org/");
+ if (!url.toString().equals("http://www.fsf.org/"))
+ System.out.println("FAILED: Parse URL test: " + url.toString());
+ else {
+ System.out.println("Parsed ok: " + url.toString());
+ System.out.println("PASSED: URL parse test");
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ System.out.println("FAILED: URL parsing test: " + e);
+ }
+
+ // getContent test
+ System.out.println("Test 3: getContent test");
+ try
+ {
+ URL url = new URL("http://localhost/~arenn/services.txt");
+
+ Object obj = url.getContent();
+ System.out.println("Object type is: " + obj.getClass().getName());
+
+ if (obj instanceof InputStream)
+ {
+ System.out.println("Got InputStream, so dumping contents");
+ BufferedReader br = new BufferedReader(new
+ InputStreamReader((InputStream)obj));
+
+ for (String str = br.readLine(); str != null; str = br.readLine())
+ System.out.println(str);
+
+ br.close();
+ }
+ else
+ {
+ System.out.println("FAILED: Object is not an InputStream");
+ }
+
+ System.out.println("PASSED: getContent test");
+ }
+ catch (IOException e)
+ {
+ System.out.println("FAILED: getContent test: " + e);
+ }
+
+ System.out.println("URL test complete");
+}
+
+}
+
diff --git a/test/java.net/runtest b/test/java.net/runtest
new file mode 100755
index 000000000..4439aa099
--- /dev/null
+++ b/test/java.net/runtest
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+echo "Running java.net tests"
+echo "I assume japhar is in /usr/local/japhar"
+echo "Please make sure background processes don't block on a tty write"
+echo "Please do an 'ifconfig multicast' and 'ifconfig allmulti' on your"
+echo "network interfaces"
+
+export CLASSPATH=.:/usr/local/japhar/share
+export PATH=$PATH:/usr/local/japhar/bin
+
+echo "Executing name lookup test ..."
+japhar TestNameLookups
+
+echo "Executing stream socket tests ..."
+japhar ServerSocketTest &
+japhar ClientSocket
+
+echo "Executing datagram socket tests ..."
+japhar ServerDatagram &
+japhar ClientDatagram
+
+echo "Executing multicast socket tests ..."
+japhar MulticastServer &
+japhar MulticastClient
+
+echo "Executing URL tests ..."
+japhar URLTest
+
+echo "java.net Testing complete."
+exit 0
+