diff options
author | Aaron M. Renn <arenn@urbanophile.com> | 1998-08-02 00:40:14 +0000 |
---|---|---|
committer | Aaron M. Renn <arenn@urbanophile.com> | 1998-08-02 00:40:14 +0000 |
commit | a8ffef5b2767ef3d4848ee6498d0502c0908193f (patch) | |
tree | 85d9907ff6c5d50920d5e65bf1c63b7e2e81d11f /test | |
parent | 82f129735a99b3fbf0b72c2e45d1282dcae23694 (diff) | |
download | classpath-a8ffef5b2767ef3d4848ee6498d0502c0908193f.tar.gz |
Initial Checkin
Diffstat (limited to 'test')
-rw-r--r-- | test/java.io/BufferedCharWriterTest.java | 89 | ||||
-rw-r--r-- | test/java.io/BufferedReaderTest.java | 200 | ||||
-rw-r--r-- | test/java.io/CharArrayReaderTest.java | 169 | ||||
-rw-r--r-- | test/java.io/FileInputStreamTest.java | 71 | ||||
-rw-r--r-- | test/java.io/FileOutputStreamTest.java | 81 | ||||
-rw-r--r-- | test/java.io/FileReaderTest.java | 69 | ||||
-rw-r--r-- | test/java.io/FileTest.java | 205 | ||||
-rw-r--r-- | test/java.io/FileWriterTest.java | 85 | ||||
-rw-r--r-- | test/java.io/LineNumberReaderTest.java | 120 | ||||
-rw-r--r-- | test/java.io/PipedReaderWriterTest.java | 136 | ||||
-rw-r--r-- | test/java.io/PrintStreamTest.java | 83 | ||||
-rw-r--r-- | test/java.io/PrintWriterTest.java | 83 | ||||
-rw-r--r-- | test/java.io/PushbackReaderTest.java | 115 | ||||
-rw-r--r-- | test/java.io/README | 12 | ||||
-rw-r--r-- | test/java.io/RandomAccessFileTest.java | 269 | ||||
-rw-r--r-- | test/java.io/StringWriterTest.java | 91 |
16 files changed, 1878 insertions, 0 deletions
diff --git a/test/java.io/BufferedCharWriterTest.java b/test/java.io/BufferedCharWriterTest.java new file mode 100644 index 000000000..43e175e4e --- /dev/null +++ b/test/java.io/BufferedCharWriterTest.java @@ -0,0 +1,89 @@ +/************************************************************************* +/* BufferedCharWriterTest.java -- Test {Buffered,CharArray}Writer +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +/** + * Class to test BufferedWriter and CharArrayWriter + * + * @version 0.0 + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public class BufferedCharWriterTest +{ + +public static void +main(String argv[]) +{ + System.out.println("Started test of BufferedWriter and CharArrayWriter"); + + try + { + System.out.println("Test 1: Write Tests"); + + CharArrayWriter caw = new CharArrayWriter(24); + BufferedWriter bw = new BufferedWriter(caw, 12); + + String str = "I used to live right behind this super-cool bar in\n" + + "Chicago called Lounge Ax. They have the best music of pretty\n" + + "much anyplace in town with a great atmosphere and $1 Huber\n" + + "on tap. I go to tons of shows there, even though I moved.\n"; + + boolean passed = true; + + char[] buf = new char[str.length()]; + str.getChars(0, str.length(), buf, 0); + + bw.write(buf, 0, 5); + if (caw.toCharArray().length != 0) + { + passed = false; + System.out.println("CharArrayWriter has too many bytes #1"); + } + bw.write(buf, 5, 8); + bw.write(buf, 13, 12); + bw.write(buf[25]); + bw.write(buf, 26, buf.length - 26); + bw.close(); + + String str2 = new String(caw.toCharArray()); + if (!str.equals(str2)) + { + passed = false; + System.out.println("Unexpected string: " + str2); + } + + if (passed) + System.out.println("PASSED: Write Tests"); + else + System.out.println("FAILED: Write Tests"); + } + catch(IOException e) + { + System.out.println("FAILED: Write Tests: " + e); + } + + System.out.println("Finished test of BufferedOutputStream and ByteArrayOutputStream"); +} + +} // class BufferedByteOutputStreamTest + diff --git a/test/java.io/BufferedReaderTest.java b/test/java.io/BufferedReaderTest.java new file mode 100644 index 000000000..3124959e2 --- /dev/null +++ b/test/java.io/BufferedReaderTest.java @@ -0,0 +1,200 @@ +/************************************************************************* +/* BufferedReaderTest.java -- Tests BufferedReader's +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class BufferedReaderTest extends CharArrayReader +{ + +// Hehe. We override CharArrayReader.markSupported() in order to return +// false so that we can test BufferedReader's handling of mark/reset in +// both the case where the underlying stream does and does not support +// mark/reset +public boolean +markSupported() +{ + return(false); +} + +public +BufferedReaderTest(char[] buf) +{ + super(buf); +} + +public static int +marktest(Reader ins) throws IOException +{ + BufferedReader br = new BufferedReader(ins, 15); + + int chars_read; + int total_read = 0; + char[] buf = new char[12]; + + chars_read = br.read(buf); + total_read += chars_read; + System.out.print(new String(buf, 0, chars_read)); + + chars_read = br.read(buf); + total_read += chars_read; + System.out.print(new String(buf, 0, chars_read)); + + br.mark(75); + br.read(); + br.read(buf); + br.read(buf); + br.read(buf); + br.reset(); + + chars_read = br.read(buf); + total_read += chars_read; + System.out.print(new String(buf, 0, chars_read)); + + br.mark(555); + + chars_read = br.read(buf); + total_read += chars_read; + System.out.print(new String(buf, 0, chars_read)); + + br.reset(); + + br.read(buf); + chars_read = br.read(buf); + total_read += chars_read; + System.out.print(new String(buf, 0, chars_read)); + + chars_read = br.read(buf); + total_read += chars_read; + System.out.print(new String(buf, 0, chars_read)); + + br.mark(14); + + br.read(buf); + + br.reset(); + + chars_read = br.read(buf); + total_read += chars_read; + System.out.print(new String(buf, 0, chars_read)); + + while ((chars_read = br.read(buf)) != -1) + { + System.out.print(new String(buf, 0, chars_read)); + total_read += chars_read; + } + + return(total_read); +} + +public static void +main(String[] argv) +{ + System.out.println("Started test of BufferedReader"); + + try + { + System.out.println("Test 1: Simple Read Test"); + + String str = "My 5th grade teacher was named Mr. Thompson. Terry\n" + + "George Thompson to be precise. He had these sideburns like\n" + + "Isaac Asimov's, only uglier. One time he had a contest and said\n" + + "that if any kid who could lift 50lbs worth of weights on a barbell\n" + + "all the way over their head, he would shave it off. Nobody could\n" + + "though. One time I guess I made a comment about how stupid his\n" + + "sideburns worked and he not only kicked me out of class, he called\n" + + "my mother. Jerk.\n"; + + StringReader sr = new StringReader(str); + BufferedReader br = new BufferedReader(sr, 15); + + char[] buf = new char[12]; + int chars_read; + while((chars_read = br.read(buf)) != -1) + System.out.print(new String(buf, 0, chars_read)); + + br.close(); + System.out.println("PASSED: Simple Read Test"); + } + catch (IOException e) + { + System.out.println("FAILED: Simple Read Test: " + e); + } + + try + { + System.out.println("Test 2: First mark/reset Test"); + + String str = "Growing up in a rural area brings such delights. One\n" + + "time my uncle called me up and asked me to come over and help him\n" + + "out with something. Since he lived right across the field, I\n" + + "walked right over. Turned out he wanted me to come down to the\n" + + "barn and help him castrate a calf. Oh, that was fun. Not.\n"; + + StringReader sr = new StringReader(str); +// BufferedReader br = new BufferedReader(sr); + + int total_read = marktest(sr); + + if (total_read == str.length()) + System.out.println("PASSED: First mark/reset Test"); + else + System.out.println("FAILED: First mark/reset Test"); + } + catch (IOException e) + { + System.out.println("FAILED: First mark/reset Test: " + e); + } + + try + { + System.out.println("Test 3: Second mark/reset Test"); + + String str = "Growing up we heated our house with a wood stove. That\n" + + "thing could pump out some BTU's, let me tell you. No matter how\n" + + "cold it got outside, it was always warm inside. Of course the\n" + + "downside is that somebody had to chop the wood for the stove. That\n" + + "somebody was me. I was slave labor. My uncle would go back and\n" + + "chain saw up dead trees and I would load the wood in wagons and\n" + + "split it with a maul. Somehow my no account brother always seemed\n" + + "to get out of having to work.\n"; + + char[] buf = new char[str.length()]; + str.getChars(0, str.length(), buf, 0); + BufferedReaderTest brt = new BufferedReaderTest(buf); +// BufferedReader br = new BufferedReader(car); + + int total_read = marktest(brt); + + if (total_read == str.length()) + System.out.println("PASSED: Second mark/reset Test"); + else + System.out.println("FAILED: Second mark/reset Test"); + } + catch (IOException e) + { + System.out.println("FAILED: Second mark/reset Test: " + e); + } + + System.out.println("Finished test of BufferedReader"); +} // main + +} // class BufferedReaderTest + diff --git a/test/java.io/CharArrayReaderTest.java b/test/java.io/CharArrayReaderTest.java new file mode 100644 index 000000000..e0cde60fa --- /dev/null +++ b/test/java.io/CharArrayReaderTest.java @@ -0,0 +1,169 @@ +/************************************************************************* +/* CharArrayReaderTest.java -- Test CharArrayReaders's of course +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class CharArrayReaderTest extends CharArrayReader +{ + +public +CharArrayReaderTest(char[] b) +{ + super(b); +} + +public static void +main(String[] argv) +{ + System.out.println("Starting test of CharArrayReader."); + System.out.flush(); + + String str = "In junior high, I did a lot writing. I wrote a science\n" + + "fiction novel length story that was called 'The Destruction of\n" + + "Planet Earth'. All the characters in the story were my friends \n" + + "from school because I couldn't think up any cool names."; + + char[] str_chars = new char[str.length()]; + str.getChars(0, str.length(), str_chars, 0); + + System.out.println("Test 1: Protected Variables"); + + CharArrayReaderTest car = new CharArrayReaderTest(str_chars); + char[] read_buf = new char[12]; + + try + { + car.read(read_buf); + car.mark(0); + + boolean passed = true; + + if (car.markedPos != read_buf.length) + { + passed = false; + System.out.println("The mark variable is wrong. Expected " + + read_buf.length + " and got " + car.markedPos); + } + car.read(read_buf); + if (car.pos != (read_buf.length * 2)) + { + passed = false; + System.out.println("The pos variable is wrong. Expected 24 and got " + + car.pos); + } + if (car.count != str_chars.length) + { + passed = false; + System.out.println("The count variable is wrong. Expected " + + str_chars.length + " and got " + car.pos); + } + if (car.buf != str_chars) + { + passed = false; + System.out.println("The buf variable is not correct"); + } + + if (passed) + System.out.println("PASSED: Protected Variables Test"); + else + System.out.println("FAILED: Protected Variables Test"); + } + catch (IOException e) + { + System.out.println("FAILED: Protected Variables Test: " + e); + } + + System.out.println("Test 2: Simple Read Test"); + + car = new CharArrayReaderTest(str_chars); + + try + { + int chars_read, total_read = 0; + while ((chars_read = car.read(read_buf, 0, read_buf.length)) != -1) + { + System.out.print(new String(read_buf, 0, chars_read)); + total_read += chars_read; + } + + car.close(); + if (total_read == str.length()) + System.out.println("PASSED: Simple Read Test"); + else + System.out.println("FAILED: Simple Read Test"); + } + catch (IOException e) + { + System.out.println("FAILED: Simple Read Test: " + e); + } + + System.out.println("Test 3: mark/reset/available/skip test"); + car = new CharArrayReaderTest(str_chars); + + try + { + boolean passed = true; + + car.read(read_buf); + if (!car.ready()) + { + passed = false; + System.out.println("ready() reported false and should have " + + "reported true."); + } + + if (car.skip(5) != 5) + { + passed = false; + System.out.println("skip() didn't work"); + } + + if (!car.markSupported()) + { + passed = false; + System.out.println("markSupported() should have returned true but returned false"); + } + + car.mark(0); + int pos_save = car.pos; + car.read(); + car.reset(); + if (car.pos != pos_save) + { + passed = false; + System.out.println("mark/reset failed to work"); + } + + if (passed) + System.out.println("PASSED: mark/reset/available/skip test"); + else + System.out.println("FAILED: mark/reset/available/skip test"); + } + catch(IOException e) + { + System.out.println("FAILED: mark/reset/available/skip test: " + e); + } + + System.out.println("Finished CharArrayReader test"); +} + +} + diff --git a/test/java.io/FileInputStreamTest.java b/test/java.io/FileInputStreamTest.java new file mode 100644 index 000000000..1eb92f0ff --- /dev/null +++ b/test/java.io/FileInputStreamTest.java @@ -0,0 +1,71 @@ +/************************************************************************* +/* FileInputStreamTest.java -- Test of FileInputStream class +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class FileInputStreamTest +{ + +public static void +main(String[] argv) +{ + System.out.println("Starting test of FileInputStream"); + + System.out.println("Test 1: File Read Test"); + try + { + FileInputStream fis = new FileInputStream("/etc/services"); + + System.out.println("Available: " + fis.available()); + System.out.println("FileDescriptor: " + fis.getFD()); + System.out.println("Dumping file. Note that first 100 bytes will be skipped"); + fis.skip(100); + + byte[] buf = new byte[32]; + int bytes_read = 0; + + while((bytes_read = fis.read(buf)) != -1) + System.out.print(new String(buf, 0, bytes_read)); + + fis.close(); + System.out.println("PASSED: File read test"); + } + catch(IOException e) + { + System.out.println("FAILED: File read test: " + e); + } + + System.out.println("Test 2: File Not Found Test"); + try + { + FileInputStream fis = new FileInputStream("/etc/yourmommasawhore"); + System.out.println("FAILED: File Not Found Test"); + } + catch (FileNotFoundException e) + { + System.out.println("PASSED: File Not Found Test"); + } + + System.out.println("Finished test of FileInputStream"); +} + +} // class FileInputStreamTest + diff --git a/test/java.io/FileOutputStreamTest.java b/test/java.io/FileOutputStreamTest.java new file mode 100644 index 000000000..27578cc6c --- /dev/null +++ b/test/java.io/FileOutputStreamTest.java @@ -0,0 +1,81 @@ +/************************************************************************* +/* FileOutputStreamTest.java -- Test of FileOutputStream class +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class FileOutputStreamTest +{ + +public static void +main(String[] argv) +{ + System.out.println("Starting test of FileOutputStream"); + + System.out.println("Test 1: File Write Test"); + try + { + String s1 = "Ok, what are some of the great flame wars that we have " + + "had lately. Let us see, there was emacs vs. xemacs, " + + "KDE vs. Gnome, and Tcl vs. Guile"; + + String s2 = "Operating systems I have known include: solaris, sco, " + + "hp-ux, linux, freebsd, winblows, os400, mvs, tpf, its, multics"; + + //File f = File.createTempFile("fostest", new File("/tmp")); + File f = new File("/tmp/000000"); + FileOutputStream fos = new FileOutputStream(f.getPath()); + + fos.write(s1.getBytes(), 0, 32); + fos.write(s1.getBytes(), 32, s1.getBytes().length - 32); + fos.close(); + + fos = new FileOutputStream(f.getPath(), true); + fos.write(s2.getBytes()); + fos.close(); + + if (f.length() != (s1.length() + s2.length())) + throw new IOException("Incorrect number of bytes written"); + + f.delete(); + + System.out.println("PASSED: File Write Test"); + } + catch(IOException e) + { + System.out.println("FAILED: File Write Test: " + e); + } + + System.out.println("Test 2: Permission Denied Test"); + try + { + FileOutputStream fos = new FileOutputStream("/etc/newtempfile"); + System.out.println("FAILED: Permission Denied Test"); + } + catch (IOException e) + { + System.out.println("PASSED: Permission Denied Test: " + e); + } + + System.out.println("Finished test of FileOutputStream"); +} + +} // class FileOutputStreamTest + diff --git a/test/java.io/FileReaderTest.java b/test/java.io/FileReaderTest.java new file mode 100644 index 000000000..58b290e0e --- /dev/null +++ b/test/java.io/FileReaderTest.java @@ -0,0 +1,69 @@ +/************************************************************************* +/* FileReaderTest.java -- Test of FileReader and InputStreamReader classes +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class FileReaderTest +{ + +public static void +main(String[] argv) +{ + System.out.println("Starting test of FileReader and InputStreamReader"); + + System.out.println("Test 1: File Read Test"); + try + { + FileReader fr = new FileReader("/etc/services"); + + System.out.println("Dumping file. Note that first 100 bytes will be skipped"); + fr.skip(100); + + char[] buf = new char[32]; + int chars_read = 0; + + while((chars_read = fr.read(buf)) != -1) + System.out.print(new String(buf, 0, chars_read)); + + fr.close(); + System.out.println("PASSED: File read test"); + } + catch(IOException e) + { + System.out.println("FAILED: File read test: " + e); + } + + System.out.println("Test 2: File Not Found Test"); + try + { + FileReader fr = new FileReader("/etc/yourmommasawhore"); + System.out.println("FAILED: File Not Found Test"); + } + catch (FileNotFoundException e) + { + System.out.println("PASSED: File Not Found Test"); + } + + System.out.println("Finished test of FileReader"); +} + +} // class FileReaderTest + diff --git a/test/java.io/FileTest.java b/test/java.io/FileTest.java new file mode 100644 index 000000000..a555c5938 --- /dev/null +++ b/test/java.io/FileTest.java @@ -0,0 +1,205 @@ +/************************************************************************* +/* File.java -- Tests File class +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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, version 2. (see COPYING) +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class FileTest +{ + +static PrintWriter pw; + +public static void +dumpFile(File f) throws IOException +{ + pw.println("Name: " + f.getName()); + pw.println("Parent: " + f.getParent()); + pw.println("Path: " + f.getPath()); + pw.println("Absolute: " + f.getAbsolutePath()); + pw.println("Canonical: " + f.getCanonicalPath()); + pw.println("String: " + f.toString()); +} + +public static void +deleteTempDirs() throws IOException +{ + File f = new File("tempfiletest/tmp/tmp"); + if (!f.delete()) + throw new IOException("Could not delete " + f.getPath()); + + f = new File("tempfiletest/tmp"); + if (!f.delete()) + throw new IOException("Could not delete " + f.getPath()); + + f = new File("tempfiletest/"); + if (!f.delete()) + throw new IOException("Could not delete " + f.getPath()); +} + +public static void main(String[] argv) +{ + System.out.println("Started test of File"); + + // This test writes a bunch of things to a file. That file should + // be "diff-ed" against one generated when this test is run against + // the JDK java.io package. + System.out.println("Test 1: Path Operations Test"); + try + { + pw = new PrintWriter(new OutputStreamWriter(new + FileOutputStream("./file-test.out"))); + + dumpFile(new File("/")); + dumpFile(new File("~arenn/foo")); + dumpFile(new File("foo")); + dumpFile(new File("../../../jcl/")); + dumpFile(new File("/tmp/bar.txt")); + dumpFile(new File("/usr")); + dumpFile(new File("../..")); + pw.flush(); + + File f = new File("gimme"); + if (f.isAbsolute()) + throw new IOException("isAbsolute() failed"); + + f = new File("/etc/services"); + if (!f.isFile()) + throw new IOException("isFile() failed"); + + pw.println("length: " + f.length()); + pw.println("lastModified: " + f.lastModified()); + pw.println("hashCode: " + f.hashCode()); + + f = new File("/etc/"); + if (!f.isDirectory()) + throw new IOException("isDirectory() failed"); + + pw.close(); + System.out.println("PASSED: Conditionally Passed Path Operations Test"); + } + catch(IOException e) + { + System.out.println("FAILED: Path Operations Test: " + e); + pw.close(); + } + + System.out.println("Test 2: File/Directory Manipulation Test"); + try + { + File f = new File("filetest"); + if (!f.exists()) + throw new IOException("The filetest directory doesn't exist"); + + String[] filelist = f.list(); + if ((filelist == null) || (filelist.length != 3)) + throw new IOException("Failed to read directory list"); + + for (int i = 0; i < filelist.length; i++) + System.out.println(filelist[i]); + + System.out.println("Listing /etc/"); + f = new File("/etc/"); + filelist = f.list(); + for (int i = 0; i < filelist.length; i++) + System.out.println(filelist[i]); + + f = new File("tempfiletest/tmp/tmp"); + if (!f.mkdirs()) + throw new IOException("Failed to create directories: " + f.getPath()); + + deleteTempDirs(); + + f = new File("tempfiletest/tmp/tmp/"); + if (!f.mkdirs()) + throw new IOException("Failed to create directories: " + f.getPath()); + + deleteTempDirs(); + + //f = File.createTempFile("tempfile#old", new File(".")); + f = new File("000000"); + + if (!f.renameTo(new File("tempfiletemp"))) + throw new IOException("Failed to rename file: " + f.getPath()); + + if (!f.delete()) + throw new IOException("Failed to delete file: " + f.getPath()); + + System.out.println("PASSED: File/Directory Manipulation Test"); + } + catch(IOException e) + { + System.out.println("FAILED: File/Directory Manipulation Test: " + e); + } + + System.out.println("Test 3: Read/Write Permissions Test"); + try + { + if ((new File("/")).canWrite() == true) + throw new IOException("Permission to write / unexpectedly"); + + if ((new File("/etc/services")).canRead() == false) + throw new IOException("No permission to read /etc/services"); + + System.out.println("PASSED: Read/Write Permissions Test"); + } + catch (IOException e) + { + System.out.println("FAILED: Read/Write Permissions Test: " + e); + } + + System.out.println("Test 4: Name Comparison Tests"); + try + { + File f1, f2; + + f1 = new File("/etc/"); + f2 = new File("/etc/"); + if (!f1.equals(f2)) + throw new IOException(f1 + " " + f2); + + f2 = new File("/etc"); + if (f1.equals(f2)) + throw new IOException(f1 + " " + f2); +/* + f1 = new File("a"); + f2 = new File("b"); + if (f1.compareTo(f2) >= 0) + throw new IOException(f1 + " " + f2); + + f1 = new File("z"); + f2 = new File("y"); + if (f1.compareTo(f2) <= 0) + throw new IOException(f1 + " " + f2); + + f1 = new File("../../jcl/"); + f2 = new File(".././.././jcl/."); + if (f1.compareTo(f2) != 0) + throw new IOException(f1 + " " + f2); +*/ + System.out.println("PASSED: Name Comparison Tests"); + } + catch (IOException e) + { + System.out.println("FAILED: Name Comparison Tests: " + e); + } + + System.out.println("Finished test of File"); +} +} + diff --git a/test/java.io/FileWriterTest.java b/test/java.io/FileWriterTest.java new file mode 100644 index 000000000..3f898099b --- /dev/null +++ b/test/java.io/FileWriterTest.java @@ -0,0 +1,85 @@ +/************************************************************************* +/* FileWriterTest.java -- Test of FileWriter and OutputStreamWriter classes +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class FileWriterTest +{ + +public static void +main(String[] argv) +{ + System.out.println("Starting test of FileWriter and OutputStreamWriter"); + + System.out.println("Test 1: File Write Test"); + try + { + String s1 = "Ok, what are some of the great flame wars that we have " + + "had lately. Let us see, there was emacs vs. xemacs, " + + "KDE vs. Gnome, and Tcl vs. Guile"; + + String s2 = "Operating systems I have known include: solaris, sco, " + + "hp-ux, linux, freebsd, winblows, os400, mvs, tpf, its, multics"; + + //File f = File.createTempFile("fostest", new File("/tmp")); + File f = new File("/tmp/000001"); + FileWriter fw = new FileWriter(f.getPath()); + + char buf[] = new char[s1.length()]; + s1.getChars(0, s1.length(), buf, 0); + fw.write(buf, 0, 32); + fw.write(buf, 32, s1.getBytes().length - 32); + fw.close(); + + fw = new FileWriter(f.getPath(), true); + buf = new char[s2.length()]; + s2.getChars(0, s2.length(), buf, 0); + fw.write(buf); + fw.close(); + + if (f.length() != (s1.length() + s2.length())) + throw new IOException("Incorrect number of chars written"); + + f.delete(); + + System.out.println("PASSED: File Write Test"); + } + catch(IOException e) + { + System.out.println("FAILED: File Write Test: " + e); + } + + System.out.println("Test 2: Permission Denied Test"); + try + { + FileWriter fw = new FileWriter("/etc/newtempfile"); + System.out.println("FAILED: Permission Denied Test"); + } + catch (IOException e) + { + System.out.println("PASSED: Permission Denied Test: " + e); + } + + System.out.println("Finished test of FileWriter"); +} + +} // class FileWriter + diff --git a/test/java.io/LineNumberReaderTest.java b/test/java.io/LineNumberReaderTest.java new file mode 100644 index 000000000..5eb2b1479 --- /dev/null +++ b/test/java.io/LineNumberReaderTest.java @@ -0,0 +1,120 @@ +/************************************************************************* +/* LineNumberReaderTest.java -- Tests LineNumberReader's +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class LineNumberReaderTest +{ + +public static void +main(String[] argv) +{ + System.out.println("Started test of LineNumberReader"); + + try + { + System.out.println("Test 1: First test series"); + + boolean passed = true; + + String str = "In 6th grade I had a crush on this girl named Leanne\n" + + "Dean. I thought she was pretty hot. I saw her at my ten year\n" + + "high school reunion. I still think she's pretty hot. (She's\n" + + "married to my brother's college roommate).\n"; + + StringReader sbr = new StringReader(str); + LineNumberReader lnr = new LineNumberReader(sbr); + + lnr.setLineNumber(2); + + char[] buf = new char[32]; + int chars_read; + while ((chars_read = lnr.read(buf)) != -1) + { + str = new String(buf, 0, chars_read); + if (str.indexOf("\r") != -1) + { + passed = false; + System.out.println("\nFound an unexpected \\r\n"); + } + + System.out.print(str); + } + + if (lnr.getLineNumber() != 6) + { + passed = false; + System.out.println("Line number was wrong. Expected 6 but got " + + lnr.getLineNumber()); + } + + if (passed) + System.out.println("PASSED: First test series"); + else + System.out.println("FAILED: First test series"); + } + catch(IOException e) + { + System.out.println("FAILED: First test series: " + e); + } + + try + { + System.out.println("Test 2: Second test series"); + + boolean passed = true; + + String str = "Exiting off the expressway in Chicago is not an easy\n" + + "thing to do. For example, at Fullerton you have to run a\n" + + "gauntlet of people selling flowers, begging for money, or trying\n" + + "to 'clean' your windshield for tips."; + + StringReader sbr = new StringReader(str); + LineNumberReader lnr = new LineNumberReader(sbr); + + char[] buf = new char[32]; + int chars_read; + while ((chars_read = lnr.read(buf)) != -1) + System.out.print(new String(buf, 0, chars_read)); + System.out.println(""); + + if (lnr.getLineNumber() != 3) + { + passed = false; + System.out.println("\nLine number was wrong. Expected 3 but got " + + lnr.getLineNumber()); + } + + if (passed) + System.out.println("PASSED: Second test series"); + else + System.out.println("FAILED: Second test series"); + } + catch(IOException e) + { + System.out.println("FAILED: Second test series: " + e); + } + + System.out.println("Finished test of LineNumberReader"); +} + +} // class LineNumberReaderTest + diff --git a/test/java.io/PipedReaderWriterTest.java b/test/java.io/PipedReaderWriterTest.java new file mode 100644 index 000000000..92b496cd3 --- /dev/null +++ b/test/java.io/PipedReaderWriterTest.java @@ -0,0 +1,136 @@ +/************************************************************************* +/* PipedReaderWriterTest.java -- Tests Piped{Reader,Writers}'s +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class PipedReaderWriterTest +{ + +public static void +main(String[] argv) +{ + // Set up a reasonable buffer size for this test if one is not already + // specified + String prop = System.getProperty("gnu.java.io.pipe_size"); +// if (prop == null) +// System.setProperty("gnu.java.io.pipe_size", "32"); + + try + { + System.out.println("Started test of PipedReader and PipedWriter"); + + System.out.println("Test 1: Basic pipe test"); + + // Set up the thread to write + PipedTestWriter ptw = new PipedTestWriter(); + String str = ptw.getStr(); + PipedWriter pw = ptw.getWriter(); + + // Now set up our reader + PipedReader pr = new PipedReader(); + pr.connect(pw); + new Thread(ptw).start(); + + char[] buf = new char[12]; + int chars_read, total_read = 0; + while((chars_read = pr.read(buf)) != -1) + { + System.out.print(new String(buf, 0, chars_read)); + System.out.flush(); + System.gc(); // A short delay + total_read += chars_read; + } + + if (total_read == str.length()) + System.out.println("PASSED: Basic pipe test"); + else + System.out.println("FAILED: Basic pipe test"); + } + catch (IOException e) + { + System.out.println("FAILED: Basic pipe test: " + e); + } +} + +} // class PipedReaderWriterTest + +class PipedTestWriter implements Runnable +{ + +String str; +StringReader sbr; +PipedWriter out; + +public +PipedTestWriter() +{ + str = "In college, there was a tradition going for a while that people\n" + + "would get together and hang out at Showalter Fountain - in the center\n" + + "of Indiana University's campus - around midnight. It was mostly folks\n" + + "from the computer lab and just people who liked to use the Forum\n" + + "bbs system on the VAX. IU pulled the plug on the Forum after I left\n" + + "despite its huge popularity. Now they claim they are just giving\n" + + "students what they want by cutting deals to make the campus all\n" + + "Microsoft.\n"; + + sbr = new StringReader(str); + + out = new PipedWriter(); +} + +public PipedWriter +getWriter() +{ + return(out); +} + +public String +getStr() +{ + return(str); +} + +public void +run() +{ + char[] buf = new char[32]; + + int chars_read; + + try + { + int b = sbr.read(); + out.write(b); + + while ((chars_read = sbr.read(buf)) != -1) + out.write(buf, 0, chars_read); + + out.close(); + } + catch(IOException e) + { + System.out.println("FAILED: Basic pipe test: " + e); + } + +} + +} // PipedTestWriter + diff --git a/test/java.io/PrintStreamTest.java b/test/java.io/PrintStreamTest.java new file mode 100644 index 000000000..11496a65f --- /dev/null +++ b/test/java.io/PrintStreamTest.java @@ -0,0 +1,83 @@ +/************************************************************************* +/* PrintStreamTest.java -- Test of the PrintStream class +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class PrintStreamTest +{ + +public static void main(String[] argv) throws IOException +{ + System.out.println("Started test of PrintStream"); + System.out.println("Test 1: Printing Test"); + + char[] carray = { 'h', 'i' }; + byte[] barray = { 'b', 'y', 'e' }; + + PrintStream ps = new PrintStream(new FileOutputStream("printstream.out")); + ps.print(true); + ps.print('|'); + ps.print(false); + ps.print('|'); + ps.print('A'); + ps.print('|'); + ps.flush(); + ps.print(0xFFFFF); + ps.print('|'); + ps.print(0xFFFFFFFFFFL); + ps.print('|'); + ps.print(3.141592); + ps.print('|'); + ps.print((double)99999999999.9999); + ps.print('|'); + ps.print(carray); + ps.print('|'); + ps.print("This is a string"); + ps.print('|'); + ps.print(ps); + ps.println(); + ps.println(true); + ps.println(false); + ps.println('A'); + ps.flush(); + ps.println(0xFFFFF); + ps.println(0xFFFFFFFFFFL); + ps.println(3.141592); + ps.println((double)99999999999.9999); + ps.println(carray); + ps.println("This is a string"); + ps.println(ps); + ps.write('B'); + ps.println(); + ps.write(barray, 0, barray.length); + ps.println(); + ps.close(); + + if (ps.checkError()) + System.out.println("FAILED: Printing Test"); + else + System.out.println("PASSED: Printing Test"); + + System.out.println("PASSED: Test of PrintStream"); +} + +} // class PrintStreamTest + diff --git a/test/java.io/PrintWriterTest.java b/test/java.io/PrintWriterTest.java new file mode 100644 index 000000000..8568e019f --- /dev/null +++ b/test/java.io/PrintWriterTest.java @@ -0,0 +1,83 @@ +/************************************************************************* +/* PrintWriterTest.java -- Test of the PrintWriter class +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class PrintWriterTest +{ + +public static void main(String[] argv) throws IOException +{ + System.out.println("Started test of PrintWriter"); + System.out.println("Test 1: Printing Test"); + + char[] carray = { 'h', 'i' }; + char[] carray2 = { 'b', 'y', 'e' }; + + PrintWriter pw = new PrintWriter(new FileWriter("printwriter.out")); + pw.print(true); + pw.print('|'); + pw.print(false); + pw.print('|'); + pw.print('A'); + pw.print('|'); + pw.flush(); + pw.print(0xFFFFF); + pw.print('|'); + pw.print(0xFFFFFFFFFFL); + pw.print('|'); + pw.print(3.141592); + pw.print('|'); + pw.print((double)99999999999.9999); + pw.print('|'); + pw.print(carray); + pw.print('|'); + pw.print("This is a string"); + pw.print('|'); + pw.print(pw); + pw.println(); + pw.println(true); + pw.println(false); + pw.println('A'); + pw.flush(); + pw.println(0xFFFFF); + pw.println(0xFFFFFFFFFFL); + pw.println(3.141592); + pw.println((double)99999999999.9999); + pw.println(carray); + pw.println("This is a string"); + pw.println(pw); + pw.write('B'); + pw.println(); + pw.write(carray2, 0, carray2.length); + pw.println(); + pw.close(); + + if (pw.checkError()) + System.out.println("FAILED: Printing Test"); + else + System.out.println("PASSED: Printing Test"); + + System.out.println("PASSED: Test of PrintWriter"); +} + +} // class PrintWriterTest + diff --git a/test/java.io/PushbackReaderTest.java b/test/java.io/PushbackReaderTest.java new file mode 100644 index 000000000..e651cd8e4 --- /dev/null +++ b/test/java.io/PushbackReaderTest.java @@ -0,0 +1,115 @@ +/************************************************************************* +/* PushbackReaderTest.java -- Tests PushbackReader's of course +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +public class PushbackReaderTest extends PushbackReader +{ + +public +PushbackReaderTest(Reader r, int size) +{ + super(r, size); +} + +public static void +main(String[] argv) +{ + System.out.println("Started test of PushbackReader"); + + String str = "I used to idolize my older cousin Kurt. I wanted to be\n" + + "just like him when I was a kid. (Now we are as different as night\n" + + "and day - but still like each other). One thing he did for a while\n" + + "was set traps for foxes thinking he would make money off sellnig furs.\n" + + "Now I never saw a fox in all my years of Southern Indiana. That\n" + + "didn't deter us. One time we went out in the middle of winter to\n" + + "check our traps. It was freezing and I stepped onto a frozen over\n" + + "stream. The ice broke and I got my foot soak. Despite the fact that\n" + + "it made me look like a girl, I turned around and went straight home.\n" + + "Good thing too since I couldn't even feel my foot by the time I got\n" + + "there.\n"; + + System.out.println("Test 1: Basic Unread Tests"); + try + { + PushbackReaderTest prt = new PushbackReaderTest( + new StringReader(str), 15); + + char[] read_buf1 = new char[12]; + char[] read_buf2 = new char[12]; + + boolean passed = true; + + prt.read(read_buf1); + prt.unread(read_buf1); + prt.read(read_buf2); + + for (int i = 0; i < read_buf1.length; i++) + { + if (read_buf1[i] != read_buf2[i]) + passed = false; + } + + prt.unread(read_buf2, 1, read_buf2.length - 1); + prt.unread(read_buf2[0]); + + int chars_read, total_read = 0; + while ((chars_read = prt.read(read_buf1)) != -1) + { + System.out.print(new String(read_buf1, 0, chars_read)); + total_read += chars_read; + } + + if (total_read != str.length()) + passed = false; + + if (passed) + System.out.println("PASSED: Basic Unread Tests"); + else + System.out.println("FAILED: Basic Unread Tests"); + } + catch(IOException e) + { + System.out.println("FAILED: Basic Unread Tests: " + e); + } + + System.out.println("Test 3: Buffer Overflow Test"); + try + { + PushbackReaderTest prt = new PushbackReaderTest( + new StringReader(str), 10); + + char[] read_buf = new char[12]; + + prt.read(read_buf); + prt.unread(read_buf); + System.out.println("FAILED: Buffer Overflow Test"); + } + catch(IOException e) + { + System.out.println("PASSED: Buffer Overflow Test: " + e); + } + + System.out.println("Finished tests of PushbackReader"); +} // main + +} // class PushbackReaderTest + diff --git a/test/java.io/README b/test/java.io/README new file mode 100644 index 000000000..d5ab4f549 --- /dev/null +++ b/test/java.io/README @@ -0,0 +1,12 @@ +This directory contains tests for the java.io package. Some important +things to note: + +-- The file dataoutput-jdk.out is the results of the DataInputOutputTest + test run through the JDK. It is needed for the real test so please + don't delete it. + +-- The directory filetest and its contents are used for the FileTest test. + If that test bombs in the middle, it may leave the directory renamed + to something else. In that case, you will need to rename it back + manually to re-run the test after making fixes. + diff --git a/test/java.io/RandomAccessFileTest.java b/test/java.io/RandomAccessFileTest.java new file mode 100644 index 000000000..a07ba571d --- /dev/null +++ b/test/java.io/RandomAccessFileTest.java @@ -0,0 +1,269 @@ +/************************************************************************* +/* RandomAccessFileTest.java -- Tests RandomAccessFile's +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +// Write some data using DataOutput and read it using DataInput. + +public class RandomAccessFileTest +{ + +public static void +runReadTest(String filename, int seq, String testname) +{ + try + { + System.out.println("Test " + seq + ": " + testname); + + RandomAccessFile ras = new RandomAccessFile(filename, "r"); + + boolean passed = true; + + boolean b = ras.readBoolean(); + if (b != true) + { + passed = false; + System.out.println("Failed to read boolean. Expected true and got false"); + } + b = ras.readBoolean(); + if (b != false) + { + passed = false; + System.out.println("Failed to read boolean. Expected false and got true"); + } + byte bt = ras.readByte(); + if (bt != 8) + { + passed = false; + System.out.println("Failed to read byte. Expected 8 and got "+ bt); + } + bt = ras.readByte(); + if (bt != -122) + { + passed = false; + System.out.println("Failed to read byte. Expected -122 and got "+ bt); + } + char c = ras.readChar(); + if (c != 'a') + { + passed = false; + System.out.println("Failed to read char. Expected a and got " + c); + } + c = ras.readChar(); + if (c != '\uE2D2') + { + passed = false; + System.out.println("Failed to read char. Expected \\uE2D2 and got " + c); + } + short s = ras.readShort(); + if (s != 32000) + { + passed = false; + System.out.println("Failed to read short. Expected 32000 and got " + s); + } + int i = ras.readInt(); + if (i != 8675309) + { + passed = false; + System.out.println("Failed to read int. Expected 8675309 and got " + i); + } + long l = ras.readLong(); + if (l != 696969696969) + { + passed = false; + System.out.println("Failed to read long. Expected 696969696969 and got " + l); + } + float f = ras.readFloat(); + if (!Float.toString(f).equals("3.1415")) + { + passed = false; + System.out.println("Failed to read float. Expected 3.1415 and got " + f); + } + double d = ras.readDouble(); + if (d != 999999999.999) + { + passed = false; + System.out.println("Failed to read double. Expected 999999999.999 and got " + d); + } + String str = ras.readUTF(); + if (!str.equals("Testing code is such a boring activity but it must be done")) + { + passed = false; + System.out.println("Read unexpected String: " + str); + } + str = ras.readUTF(); + if (!str.equals("a-->\u01FF\uA000\u6666\u0200RRR")) + { + passed = false; + System.out.println("Read unexpected String: " + str); + } + + if (passed) + System.out.println("PASSED: " + testname + " read test"); + else + System.out.println("FAILED: " + testname + " read test"); + } + catch (IOException e) + { + System.out.println("FAILED: " + testname + " read test: " + e); + } + +} + +public static void +main(String[] argv) +{ + System.out.println("Started test of RandomAccessFile"); + + System.out.println("Test 1: RandomAccessFile write test"); + try + { + RandomAccessFile raf = new RandomAccessFile("dataoutput.out", "rw"); + + raf.writeBoolean(true); + raf.writeBoolean(false); + raf.writeByte((byte)8); + raf.writeByte((byte)-122); + raf.writeChar((char)'a'); + raf.writeChar((char)'\uE2D2'); + raf.writeShort((short)32000); + raf.writeInt((int)8675309); + raf.writeLong((long)696969696969); + raf.writeFloat((float)3.1415); + raf.writeDouble((double)999999999.999); + raf.writeUTF("Testing code is such a boring activity but it must be done"); + raf.writeUTF("a-->\u01FF\uA000\u6666\u0200RRR"); + raf.close(); + + // We'll find out if this was really right later, but conditionally + // report success for now + System.out.println("PASSED: RandomAccessFile write test"); + } + catch(IOException e) + { + System.out.println("FAILED: RandomAccessFile write test: " + e); + } + + runReadTest("dataoutput.out", 2, "Read of JCL written data file"); + runReadTest("dataoutput-jdk.out", 3, "Read of JDK written data file"); + + System.out.println("Test 2: Seek Test"); + try + { + RandomAccessFile raf = new RandomAccessFile("/etc/services", "r"); + + System.out.println("Length: " + raf.length()); + + raf.skipBytes(24); + if (raf.getFilePointer() != 24) + throw new IOException("Unexpected file pointer value " + + raf.getFilePointer()); + + raf.seek(0); + if (raf.getFilePointer() != 0) + throw new IOException("Unexpected file pointer value " + + raf.getFilePointer()); + + raf.seek(100); + if (raf.getFilePointer() != 100) + throw new IOException("Unexpected file pointer value " + + raf.getFilePointer()); + + System.out.println("PASSED: Seek Test"); + } + catch(IOException e) + { + System.out.println("FAILED: Seek Test: " + e); + } + + System.out.println("Test 3: Validation Test"); + boolean failed = false; + try + { + new RandomAccessFile("/vmlinuz", "rwx"); + System.out.println("Did not detect invalid mode"); + failed = true; + } + catch (IllegalArgumentException e) { ; } + catch (IOException e) { ; } + + try + { + new RandomAccessFile("/vmlinuz", "rw"); + System.out.println("Did not detect read only file opened for write"); + failed = true; + } + catch (IOException e) { ; } + + try + { + new RandomAccessFile("/sherlockholmes", "r"); + System.out.println("Did not detect non-existent file"); + failed = true; + } + catch (IOException e) { ; } + + try + { + RandomAccessFile raf = new RandomAccessFile("/etc/services", "r"); + raf.seek(raf.length()); + raf.write('\n'); + System.out.println("Did not detect invalid write operation on read only file"); + failed = true; + } + catch (IOException e) { ; } + + if (failed) + System.out.println("FAILED: Validation Test"); + else + System.out.println("PASSED: Validation Test"); + +/* + System.out.println("Test 4: Set File Length Rest"); + try + { + File f = new File("tmptmptmp"); + RandomAccessFile raf = new RandomAccessFile("tmptmptmp", "rw"); + + raf.setLength(50L); + if (raf.length() != 50) + throw new IOException("Bad length on extending file of " + raf.length()); + + raf.setLength(25L); + if (raf.length() != 25) + throw new IOException("Bad length on extending file of " + raf.length()); + + raf.close(); + f.delete(); + + System.out.println("PASSED: Set File Length Test"); + } + catch(IOException e) + { + System.out.println("FAILED: Set File Length Test: " + e); + (new File("tmptmptmp")).delete(); + } +*/ + System.out.println("Finished test of RandomAccessFile"); +} // main + +} // class DataInputOutputTest + diff --git a/test/java.io/StringWriterTest.java b/test/java.io/StringWriterTest.java new file mode 100644 index 000000000..f6f11ad99 --- /dev/null +++ b/test/java.io/StringWriterTest.java @@ -0,0 +1,91 @@ +/************************************************************************* +/* StringWriterTest.java -- Test StringWriter +/* +/* Copyright (c) 1998 Free Software Foundation, Inc. +/* Written by Aaron M. Renn (arenn@urbanophile.com) +/* +/* This program 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 of the License, or +/* (at your option) any later version. +/* +/* This program 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 this program; if not, write to the Free Software Foundation +/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA +/*************************************************************************/ + +import java.io.*; + +/** + * Class to test StringWriter. This is just a rehash of the + * BufferedCharWriterTest using a StringWriter instead of a + * CharArrayWriter underneath. + * + * @version 0.0 + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public class StringWriterTest +{ + +public static void +main(String argv[]) +{ + System.out.println("Started test of StringWriter"); + + try + { + System.out.println("Test 1: Write Tests"); + + StringWriter sw = new StringWriter(24); + BufferedWriter bw = new BufferedWriter(sw, 12); + + String str = "There are a ton of great places to see live, original\n" + + "music in Chicago. Places like Lounge Ax, Schuba's, the Empty\n" + + "Bottle, and even the dreaded Metro with their sometimes asshole\n" + + "bouncers.\n"; + + boolean passed = true; + + char[] buf = new char[str.length()]; + str.getChars(0, str.length(), buf, 0); + + bw.write(buf, 0, 5); + if (sw.toString().length() != 0) + { + passed = false; + System.out.println("StringWriter has too many bytes #1"); + } + bw.write(buf, 5, 8); + bw.write(buf, 13, 12); + bw.write(buf[25]); + bw.write(buf, 26, buf.length - 26); + bw.close(); + + String str2 = sw.toString(); + if (!str.equals(str2)) + { + passed = false; + System.out.println("Unexpected string: " + str2); + } + + if (passed) + System.out.println("PASSED: Write Tests"); + else + System.out.println("FAILED: Write Tests"); + } + catch(IOException e) + { + System.out.println("FAILED: Write Tests: " + e); + } + + System.out.println("Finished test of BufferedOutputStream and ByteArrayOutputStream"); +} + +} // class BufferedByteOutputStreamTest + |