Initial revision

From-SVN: r102074
This commit is contained in:
Tom Tromey 2005-07-16 00:30:23 +00:00
parent 6f4434b39b
commit f911ba985a
4557 changed files with 1000262 additions and 0 deletions

View file

@ -0,0 +1 @@
Makefile.in

View file

@ -0,0 +1,87 @@
/*************************************************************************
/* BufferedByteOutputStreamTest.java -- Test {Buffered,ByteArray}OutputStream
/*
/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
/**
* Class to test BufferedOutputStream and ByteOutputStream
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class BufferedByteOutputStreamTest
{
public static void
main(String argv[])
{
System.out.println("Started test of BufferedOutputStream and ByteArrayOutputStream");
try
{
System.out.println("Test 1: Write Tests");
ByteArrayOutputStream baos = new ByteArrayOutputStream(24);
BufferedOutputStream bos = new BufferedOutputStream(baos, 12);
String str = "The Kroger on College Mall Rd. in Bloomington " +
"used to sell Kroger brand froze pizzas for 68 cents. " +
"I ate a lot of those in college. It was kind of embarrassing " +
"walking out of the grocery with nothing but 15 frozen pizzas.\n";
boolean passed = true;
byte[] buf = str.getBytes();
bos.write(buf, 0, 5);
if (baos.toByteArray().length != 0)
{
passed = false;
System.out.println("ByteArrayOutputStream has too many bytes #1");
}
bos.write(buf, 5, 8);
bos.write(buf, 13, 12);
bos.write(buf[25]);
bos.write(buf, 26, buf.length - 26);
bos.close();
String str2 = new String(baos.toByteArray());
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

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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

View file

@ -0,0 +1,241 @@
/*************************************************************************
/* BufferedInputStreamTest.java -- Tests BufferedInputStream'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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
public class BufferedInputStreamTest extends BufferedInputStream
{
public
BufferedInputStreamTest(InputStream in, int size)
{
super(in, size);
}
public static int
marktest(InputStream ins) throws IOException
{
BufferedInputStream bis = new BufferedInputStream(ins, 15);
int bytes_read;
int total_read = 0;
byte[] buf = new byte[12];
bytes_read = bis.read(buf);
total_read += bytes_read;
System.out.print(new String(buf, 0, bytes_read));
bytes_read = bis.read(buf);
total_read += bytes_read;
System.out.print(new String(buf, 0, bytes_read));
bis.mark(75);
bis.read();
bis.read(buf);
bis.read(buf);
bis.read(buf);
bis.reset();
bytes_read = bis.read(buf);
total_read += bytes_read;
System.out.print(new String(buf, 0, bytes_read));
bis.mark(555);
bytes_read = bis.read(buf);
total_read += bytes_read;
System.out.print(new String(buf, 0, bytes_read));
bis.reset();
bis.read(buf);
bytes_read = bis.read(buf);
total_read += bytes_read;
System.out.print(new String(buf, 0, bytes_read));
bytes_read = bis.read(buf);
total_read += bytes_read;
System.out.print(new String(buf, 0, bytes_read));
bis.mark(14);
bis.read(buf);
bis.reset();
bytes_read = bis.read(buf);
total_read += bytes_read;
System.out.print(new String(buf, 0, bytes_read));
while ((bytes_read = bis.read(buf)) != -1)
{
System.out.print(new String(buf, 0, bytes_read));
total_read += bytes_read;
}
return(total_read);
}
public static void
main(String[] argv)
{
System.out.println("Started test of BufferedInputStream");
try
{
System.out.println("Test 1: Protected Variables Test");
String str = "This is a test line of text for this pass";
StringBufferInputStream sbis = new StringBufferInputStream(str);
BufferedInputStreamTest bist = new BufferedInputStreamTest(sbis, 12);
bist.read();
bist.mark(5);
boolean passed = true;
if (bist.buf.length != 12)
{
passed = false;
System.out.println("buf.length is wrong. Expected 12, but got " +
bist.buf.length);
}
if (bist.count != 12)
{
passed = false;
System.out.println("count is wrong. Expected 12, but got " +
bist.count);
}
if (bist.marklimit != 5)
{
passed = false;
System.out.println("marklimit is wrong. Expected 5, but got " +
bist.marklimit);
}
if (bist.markpos != 1)
{
passed = false;
System.out.println("markpos is wrong. Expected 5, but got " +
bist.markpos);
}
if (bist.pos != 1)
{
passed = false;
System.out.println("pos is wrong. Expected 1, but got " +
bist.pos);
}
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);
}
try
{
System.out.println("Test 2: Simple Read Test");
String str = "One of my 8th grade teachers was Mr. Russell.\n" +
"He used to start each year off by telling the class that the\n" +
"earth was flat. He did it to teach people to question\n" +
"things they are told. But everybody knew that he did it\n" +
"so it lost its effect.\n";
StringBufferInputStream sbis = new StringBufferInputStream(str);
BufferedInputStream bis = new BufferedInputStream(sbis, 15);
byte[] buf = new byte[12];
int bytes_read;
while((bytes_read = bis.read(buf)) != -1)
System.out.print(new String(buf, 0, bytes_read));
bis.close();
System.out.println("PASSED: Simple Read Test");
}
catch (IOException e)
{
System.out.println("FAILED: Simple Read Test: " + e);
}
try
{
System.out.println("Test 3: First mark/reset Test");
String str = "My 6th grade teacher was named Mrs. Hostetler.\n" +
"She had a whole list of rules that you were supposed to follow\n" +
"in class and if you broke a rule she would make you write the\n" +
"rules out several times. The number varied depending on what\n" +
"rule you broke. Since I knew I would get in trouble, I would\n" +
"just go ahead and write out a few sets on the long school bus\n" +
"ride home so that if had to stay in during recess and write\n" +
"rules, five minutes later I could just tell the teacher I was\n" +
"done so I could go outside and play kickball.\n";
StringBufferInputStream sbis = new StringBufferInputStream(str);
int total_read = marktest(sbis);
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 4: Second mark/reset Test");
String str = "My first day of college was fun. A bunch of us\n" +
"got pretty drunk, then this guy named Rick Flake (I'm not\n" +
"making that name up) took a piss in the bed of a Physical\n" +
"Plant dept pickup truck. Later on we were walking across\n" +
"campus, saw a cop, and took off running for no reason.\n" +
"When we got back to the dorm we found an even drunker guy\n" +
"passed out in a shopping cart outside.\n";
ByteArrayInputStream sbis = new ByteArrayInputStream(str.getBytes());
int total_read = marktest(sbis);
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 BufferedInputStream");
} // main
} // class BufferedInputStreamTest

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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

View file

@ -0,0 +1,174 @@
/*************************************************************************
/* ByteArrayInputStreamTest.java -- Test ByteArrayInputStream'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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
public class ByteArrayInputStreamTest extends ByteArrayInputStream
{
public
ByteArrayInputStreamTest(byte[] b)
{
super(b);
}
public static void
main(String[] argv)
{
System.out.println("Starting test of ByteArrayInputStream.");
System.out.flush();
String str = "My sophomore year of college I moved out of the dorms. I\n" +
"moved in with three friends into a brand new townhouse in east\n" +
"Bloomington at 771 Woodbridge Drive. To this day that was the\n" +
"nicest place I've ever lived.\n";
byte[] str_bytes = str.getBytes();
System.out.println("Test 1: Protected Variables");
ByteArrayInputStreamTest bais = new ByteArrayInputStreamTest(str_bytes);
byte[] read_buf = new byte[12];
try
{
bais.read(read_buf);
bais.mark(0);
boolean passed = true;
if (bais.mark != read_buf.length)
{
passed = false;
System.out.println("The mark variable is wrong. Expected " +
read_buf.length + " and got " + bais.mark);
}
bais.read(read_buf);
if (bais.pos != (read_buf.length * 2))
{
passed = false;
System.out.println("The pos variable is wrong. Expected 24 and got " +
bais.pos);
}
if (bais.count != str_bytes.length)
{
passed = false;
System.out.println("The count variable is wrong. Expected " +
str_bytes.length + " and got " + bais.pos);
}
if (bais.buf != str_bytes)
{
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");
bais = new ByteArrayInputStreamTest(str_bytes);
try
{
int bytes_read, total_read = 0;
while ((bytes_read = bais.read(read_buf, 0, read_buf.length)) != -1)
{
System.out.print(new String(read_buf, 0, bytes_read));
total_read += bytes_read;
}
bais.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");
bais = new ByteArrayInputStreamTest(str_bytes);
try
{
boolean passed = true;
bais.read(read_buf);
if (bais.available() != (str_bytes.length - read_buf.length))
{
passed = false;
System.out.println("available() reported " + bais.available() +
" and " + (str_bytes.length - read_buf.length) +
" was expected");
}
if (bais.skip(5) != 5)
{
passed = false;
System.out.println("skip() didn't work");
}
if (bais.available() != (str_bytes.length - (read_buf.length + 5)))
{
passed = false;
System.out.println("skip() lied");
}
if (!bais.markSupported())
{
passed = false;
System.out.println("markSupported() should have returned true but returned false");
}
bais.mark(0);
int availsave = bais.available();
bais.read();
bais.reset();
if (bais.available() != availsave)
{
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 ByteArrayInputStream test");
}
}

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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");
}
}

View file

@ -0,0 +1,174 @@
/*************************************************************************
/* DataInputOutputTest.java -- Tests Data{Input,Output}Stream'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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
// Write some data using DataOutput and read it using DataInput.
public class DataInputOutputTest
{
public static void
runReadTest(String filename, int seq, String testname)
{
try
{
System.out.println("Test " + seq + ": " + testname);
FileInputStream fis = new FileInputStream(filename);
DataInputStream dis = new DataInputStream(fis);
boolean passed = true;
boolean b = dis.readBoolean();
if (b != true)
{
passed = false;
System.out.println("Failed to read boolean. Expected true and got false");
}
b = dis.readBoolean();
if (b != false)
{
passed = false;
System.out.println("Failed to read boolean. Expected false and got true");
}
byte bt = dis.readByte();
if (bt != 8)
{
passed = false;
System.out.println("Failed to read byte. Expected 8 and got "+ bt);
}
bt = dis.readByte();
if (bt != -122)
{
passed = false;
System.out.println("Failed to read byte. Expected -122 and got "+ bt);
}
char c = dis.readChar();
if (c != 'a')
{
passed = false;
System.out.println("Failed to read char. Expected a and got " + c);
}
c = dis.readChar();
if (c != '\uE2D2')
{
passed = false;
System.out.println("Failed to read char. Expected \\uE2D2 and got " + c);
}
short s = dis.readShort();
if (s != 32000)
{
passed = false;
System.out.println("Failed to read short. Expected 32000 and got " + s);
}
int i = dis.readInt();
if (i != 8675309)
{
passed = false;
System.out.println("Failed to read int. Expected 8675309 and got " + i);
}
long l = dis.readLong();
if (l != 696969696969L)
{
passed = false;
System.out.println("Failed to read long. Expected 696969696969 and got " + l);
}
float f = dis.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 = dis.readDouble();
if (d != 999999999.999)
{
passed = false;
System.out.println("Failed to read double. Expected 999999999.999 and got " + d);
}
String str = dis.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 = dis.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 DataInputStream and DataOutputStream");
try
{
System.out.println("Test 1: DataOutputStream write test");
FileOutputStream fos = new FileOutputStream("dataoutput.out");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(true);
dos.writeBoolean(false);
dos.writeByte((byte)8);
dos.writeByte((byte)-122);
dos.writeChar((char)'a');
dos.writeChar((char)'\uE2D2');
dos.writeShort((short)32000);
dos.writeInt((int)8675309);
dos.writeLong(696969696969L);
dos.writeFloat((float)3.1415);
dos.writeDouble((double)999999999.999);
dos.writeUTF("Testing code is such a boring activity but it must be done");
dos.writeUTF("a-->\u01FF\uA000\u6666\u0200RRR");
dos.close();
// We'll find out if this was really right later, but conditionally
// report success for now
System.out.println("PASSED: DataOutputStream write test");
}
catch(IOException e)
{
System.out.println("FAILED: DataOutputStream write test: " + e);
}
runReadTest("dataoutput.out", 2, "Read of JCL written data file");
runReadTest("dataoutput-jdk.out", 3, "Read of JDK written data file");
} // main
} // class DataInputOutputTest

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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");
}
}

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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

View file

@ -0,0 +1,75 @@
import java.io.*;
class GraphNode implements Serializable
{
GraphNode( String s )
{
this.s = s;
}
public String toString()
{
return this.s;
}
String s;
GraphNode a;
GraphNode b;
GraphNode c;
GraphNode d;
}
public class HairyGraph implements Serializable
{
GraphNode A;
GraphNode B;
GraphNode C;
GraphNode D;
HairyGraph()
{
A = new GraphNode( "A" );
B = new GraphNode( "B" );
C = new GraphNode( "C" );
D = new GraphNode( "D" );
A.a = B;
A.b = C;
A.c = D;
A.d = A;
B.a = C;
B.b = D;
B.c = A;
B.d = B;
C.a = D;
C.b = A;
C.c = B;
C.d = C;
D.a = A;
D.b = B;
D.c = C;
D.d = D;
}
public boolean equals( Object o )
{
HairyGraph hg = (HairyGraph)o;
return (A.a == B.d) && (A.a == C.c) && (A.a == D.b)
&& (A.b == B.a) && (A.b == C.d) && (A.b == D.c)
&& (A.c == B.b) && (A.c == C.a) && (A.c == D.d)
&& (A.d == B.c) && (A.d == C.b) && (A.d == D.a);
}
void printOneLevel( GraphNode gn )
{
System.out.println( "GraphNode< " + gn + ": " + gn.a + ", " + gn.b
+ ", " + gn.c + ", " + gn.d + " >" );
}
}

View file

@ -0,0 +1,119 @@
/*************************************************************************
/* LineNumberInputStreamTest.java -- Tests LineNumberInputStream'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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
public class LineNumberInputStreamTest
{
public static void
main(String[] argv)
{
System.out.println("Started test of LineNumberInputStream");
try
{
System.out.println("Test 1: First test series");
boolean passed = true;
String str = "I grew up by a small town called Laconia, Indiana\r" +
"which has a population of about 64 people. But I didn't live\r\n" +
"in town. I lived on a gravel road about 4 miles away\n" +
"They paved that road\n";
StringBufferInputStream sbis = new StringBufferInputStream(str);
LineNumberInputStream lnis = new LineNumberInputStream(sbis);
lnis.setLineNumber(2);
byte[] buf = new byte[32];
int bytes_read;
while ((bytes_read = lnis.read(buf)) != -1)
{
str = new String(buf, 0, bytes_read);
if (str.indexOf("\r") != -1)
{
passed = false;
System.out.println("\nFound an unexpected \\r\n");
}
System.out.print(str);
}
if (lnis.getLineNumber() != 6)
{
passed = false;
System.out.println("Line number was wrong. Expected 6 but got " +
lnis.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 = "One time I was playing kickball on the playground\n" +
"in 4th grade and my friends kept talking about how they smelled\n" +
"pot. I kept asking them what they smelled because I couldn't\n" +
"figure out how a pot could have a smell";
StringBufferInputStream sbis = new StringBufferInputStream(str);
LineNumberInputStream lnis = new LineNumberInputStream(sbis);
byte[] buf = new byte[32];
int bytes_read;
while ((bytes_read = lnis.read(buf)) != -1)
System.out.print(new String(buf, 0, bytes_read));
if (lnis.getLineNumber() != 3)
{
passed = false;
System.out.println("\nLine number was wrong. Expected 3 but got " +
lnis.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 LineNumberInputStream");
}
} // class LineNumberInputStreamTest

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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

View file

@ -0,0 +1,9 @@
## Input file for automake to generate the Makefile.in used by configure
JAVAROOT = .
check_JAVA = BufferedInputStreamTest.java ByteArrayInputStreamTest.java \
DataInputOutputTest.java LineNumberInputStreamTest.java \
PushbackInputStreamTest.java SequenceInputStreamTest.java \
StringBufferInputStreamTest.java

View file

@ -0,0 +1,39 @@
import java.io.*;
public class OOSCallDefault implements Serializable
{
int x;
double y;
transient String s;
OOSCallDefault( int X, double Y, String S )
{
x = X;
y = Y;
s = S;
}
public boolean equals( Object o )
{
OOSCallDefault oo = (OOSCallDefault)o;
return oo.x == x
&& oo.y == y
&& oo.s.equals( s );
}
private void writeObject( ObjectOutputStream oos ) throws IOException
{
oos.writeObject( s );
oos.defaultWriteObject();
oos.writeObject( s );
}
private void readObject( ObjectInputStream ois )
throws ClassNotFoundException, IOException
{
ois.readObject();
ois.defaultReadObject();
s = (String)ois.readObject();
}
}

View file

@ -0,0 +1,37 @@
import java.io.*;
public class OOSExtern extends OOSNoCallDefault implements Externalizable
{
public OOSExtern()
{}
OOSExtern( int X, String S, boolean B )
{
super( X, S, B );
}
public void writeExternal( ObjectOutput oo ) throws IOException
{
oo.writeInt( super.x );
oo.writeObject( super.s );
oo.writeBoolean( super.b );
}
public void readExternal( ObjectInput oi )
throws ClassNotFoundException, IOException
{
super.x = oi.readInt();
super.s = (String)oi.readObject();
super.b = oi.readBoolean();
}
public boolean equals( Object o )
{
OOSExtern e = (OOSExtern)o;
return e.x == super.x
&& e.s.equals( super.s )
&& e.b == super.b;
}
}

View file

@ -0,0 +1,42 @@
import java.io.*;
public class OOSNoCallDefault implements Serializable
{
int x;
String s;
boolean b;
OOSNoCallDefault()
{}
OOSNoCallDefault( int X, String S, boolean B )
{
x = X;
s = S;
b = B;
}
public boolean equals( Object o )
{
OOSNoCallDefault oo = (OOSNoCallDefault)o;
return oo.x == x
&& oo.b == b
&& oo.s.equals( s );
}
private void writeObject( ObjectOutputStream oos ) throws IOException
{
oos.writeInt( x );
oos.writeObject( s );
oos.writeBoolean( b );
}
private void readObject( ObjectInputStream ois )
throws ClassNotFoundException, IOException
{
x = ois.readInt();
s = (String)ois.readObject();
b = ois.readBoolean();
}
}

View file

@ -0,0 +1,65 @@
/*************************************************************************
/* ObjectInputStreamTest.java -- Tests ObjectInputStream class
/*
/* Copyright (c) 1998 by Free Software Foundation, Inc.
/*
/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.FileInputStream;
import java.io.ObjectInputStream;
public class ObjectInputStreamTest extends Test
{
public static void testSerial( Object obj, String filename )
{
try
{
ObjectInputStream ois =
new ObjectInputStream( new FileInputStream( filename ) );
Object read_object = ois.readObject();
ois.close();
if( read_object.equals( obj ) )
pass();
else
fail();
}
catch( Exception e )
{
e.printStackTrace();
fail();
}
}
public static void main( String[] args )
{
testSerial( new OOSCallDefault( 1, 3.14, "test" ),
"calldefault.data" );
System.out.println( "Object calling defaultWriteObject()" );
testSerial( new OOSNoCallDefault( 17, "no\ndefault", false ),
"nocalldefault.data" );
System.out.println( "Object not calling defaultWriteObject()" );
testSerial( new OOSExtern( -1, "", true ), "external.data" );
System.out.println( "Externalizable class" );
testSerial( new HairyGraph(), "graph.data" );
System.out.println( "Graph of objects with circular references" );
}
}

View file

@ -0,0 +1,157 @@
/*************************************************************************
/* ObjectOutputStreamTest.java -- Tests ObjectOutputStream class
/*
/* Copyright (c) 1998 by Free Software Foundation, Inc.
/*
/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import java.io.Serializable;
public class ObjectOutputStreamTest extends Test
{
public static void testSerial( Object obj, String filename )
{
if( writeMode )
{
try
{
ObjectOutputStream oos =
new ObjectOutputStream( new FileOutputStream( filename ) );
oos.writeObject( obj );
oos.close();
}
catch( ObjectStreamException e )
{}
catch( IOException ioe )
{
ioe.printStackTrace();
}
}
else
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try
{
ObjectOutputStream oos = new ObjectOutputStream( bytes );
oos.writeObject( obj );
oos.close();
}
catch( ObjectStreamException e )
{}
catch( IOException ioe )
{
fail();
return;
}
byte[] jcl_bytes = bytes.toByteArray();
int data;
FileInputStream jdk_file;
try
{
jdk_file = new FileInputStream( filename );
for( int i=0; i < jcl_bytes.length; i++ )
{
data = jdk_file.read();
if( data == -1 )
{
fail();
return;
}
if( (byte)data != jcl_bytes[i] )
{
fail();
return;
}
}
if( jdk_file.read() != -1 )
{
fail();
return;
}
}
catch( IOException e )
{
error();
return;
}
pass();
}
}
public static void main( String[] args )
{
writeMode = (args.length != 0);
testSerial( new OOSNotSerial(), "notserial.data" );
System.out.println( "Non-serializable class" );
testSerial( new OOSBadField( 1, 2, new OOSNotSerial() ),
"notserialfield.data" );
System.out.println( "Object with non-serializable field" );
testSerial( new OOSCallDefault( 1, 3.14, "test" ),
"calldefault.data" );
System.out.println( "Object calling defaultWriteObject()" );
testSerial( new OOSNoCallDefault( 17, "no\ndefault", false ),
"nocalldefault.data" );
System.out.println( "Object not calling defaultWriteObject()" );
testSerial( new OOSExtern( -1, "", true ), "external.data" );
System.out.println( "Externalizable class" );
testSerial( new HairyGraph(), "graph.data" );
System.out.println( "Graph of objects with circular references" );
}
public static boolean writeMode;
}
class OOSNotSerial {}
class OOSBadField implements Serializable
{
int x;
int y;
OOSNotSerial o;
OOSBadField( int X, int Y, OOSNotSerial O )
{
x = X;
y = Y;
o = O;
}
}

View file

@ -0,0 +1,282 @@
/*************************************************************************
/* ObjectStreamClassTest.java -- Tests ObjectStreamClass class
/*
/* Copyright (c) 1998 by Free Software Foundation, Inc.
/*
/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.Externalizable;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.Serializable;
import java.util.Hashtable;
import java.util.Vector;
public class ObjectStreamClassTest
{
public static void pass()
{
System.out.print( "PASSED: " );
}
public static void fail()
{
System.out.print( "FAILED: " );
}
public static void pass( boolean exp_pass )
{
if( exp_pass )
pass();
else
System.out.print( "XPASSED: " );
}
public static void fail( boolean exp_pass )
{
if( exp_pass )
fail();
else
System.out.print( "XFAIL: " );
}
public static void testLookup( Class cl, boolean non_null )
{
if( non_null == (ObjectStreamClass.lookup( cl ) != null) )
pass();
else
fail();
System.out.println( "lookup() for " + cl );
}
public static void testGetName( Class cl, String name )
{
if( ObjectStreamClass.lookup( cl ).getName().equals( name ) )
pass();
else
fail();
System.out.println( "getName() for " + cl );
}
public static void testForClass( Class cl, Class clazz )
{
if( ObjectStreamClass.lookup( cl ).forClass() == clazz )
pass();
else
fail();
System.out.println( "forClass() for " + cl );
}
public static void testSUID( Class cl, long suid )
{
testSUID( cl, suid, true );
}
public static void testSUID( Class cl, long suid, boolean exp_pass )
{
if( ObjectStreamClass.lookup( cl ).getSerialVersionUID() == suid )
pass( exp_pass );
else
fail( exp_pass );
System.out.println( "getSerialVersionUID() for " + cl );
}
public static void testHasWrite( Class cl, boolean has_write )
{
if( ObjectStreamClass.lookup( cl ).hasWriteMethod() == has_write )
pass();
else
fail();
System.out.println( "hasWriteMethod() for " + cl );
}
public static void testIsSerial( Class cl, boolean is_serial )
{
if( ObjectStreamClass.lookup( cl ).isSerializable() == is_serial )
pass();
else
fail();
System.out.println( "isSerializable() for " + cl );
}
public static void testIsExtern( Class cl, boolean is_extern )
{
if( ObjectStreamClass.lookup( cl ).isExternalizable() == is_extern )
pass();
else
fail();
System.out.println( "isExternalizable() for " + cl );
}
public static void main( String[] args )
{
try
{
// lookup
testLookup( Serial.class, true );
testLookup( NotSerial.class, false );
// getName
testGetName( java.lang.String.class, "java.lang.String" );
testGetName( java.util.Hashtable.class, "java.util.Hashtable" );
// forClass
testForClass( java.lang.String.class, java.lang.String.class );
testForClass( java.util.Vector.class, (new Vector()).getClass() );
// getSerialVersionUID
testSUID( A.class, 1577839372146469075L );
testSUID( B.class, -7069956958769787679L );
// NOTE: this fails for JDK 1.1.5v5 on linux because a non-null
// jmethodID is returned from
// GetStaticMethodID( env, C, "<clinit>", "()V" )
// even though class C does not have a class initializer.
// The JDK's serialver tool does not have this problem somehow.
// I have not tested this on other platforms.
testSUID( C.class, 7441756018870420732L, false );
testSUID( Defined.class, 17 );
testSUID( DefinedNotStatic.class, 8797806279193632512L );
testSUID( DefinedNotFinal.class, -1014973327673071657L );
// hasWriteMethod
testHasWrite( Serial.class, false );
testHasWrite( HasWrite.class, true );
testHasWrite( InherWrite.class, false );
testHasWrite( PubWrite.class, false );
testHasWrite( StaticWrite.class, false );
testHasWrite( ReturnWrite.class, false );
// isSerializable
testIsSerial( Serial.class, true );
testIsSerial( Extern.class, false );
testIsSerial( InherSerial.class, true );
testIsSerial( InherExtern.class, false );
// isExternalizable
testIsExtern( Serial.class, false );
testIsExtern( Extern.class, true );
testIsExtern( InherSerial.class, false );
testIsExtern( InherExtern.class, true );
}
catch( Exception e )
{
e.printStackTrace();
}
}
}
class NotSerial {}
class A implements Serializable
{
int b;
int a;
public int f() { return 0; }
float g() { return 3; }
private float c;
}
abstract class B extends A
{
private B( int[] ar ) {}
public B() {}
public static void foo() {}
public abstract void absfoo();
private static String s;
public int[] a;
static
{
s = "hello";
}
}
class C extends B implements Cloneable, Externalizable
{
public void absfoo() {}
public void readExternal( ObjectInput i ) {}
public void writeExternal( ObjectOutput o ) {}
}
class Defined implements Serializable
{
static final long serialVersionUID = 17;
}
class DefinedNotStatic implements Serializable
{
final long serialVersionUID = 17;
}
class DefinedNotFinal implements Serializable
{
static long serialVersionUID = 17;
}
class HasWrite implements Serializable
{
private void writeObject( ObjectOutputStream o ) {}
}
class InherWrite extends HasWrite {}
class PubWrite implements Serializable
{
public void writeObject( ObjectOutputStream o ) {}
}
class StaticWrite implements Serializable
{
private static void writeObject( ObjectOutputStream o ) {}
}
class ReturnWrite implements Serializable
{
private int writeObject( ObjectOutputStream o )
{
return -1;
}
}
class Serial implements Serializable {}
class Extern implements Externalizable
{
public void readExternal( ObjectInput i )
{}
public void writeExternal( ObjectOutput o )
{}
}
class InherExtern extends Extern implements Serializable {}
class InherSerial extends Serial {}

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
public class PipedReaderWriterTest
{
public static void
main(String[] argv) throws InterruptedException
{
// 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();
Thread.sleep(10); // 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

View file

@ -0,0 +1,134 @@
/*************************************************************************
/* PipedStreamTest.java -- Tests Piped{Input,Output}Stream'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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
public class PipedStreamTest
{
public static void
main(String[] argv) throws InterruptedException
{
// 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 PipedInputStream and " +
"PipedOutputStream");
System.out.println("Test 1: Basic piped stream test");
// Set up the thread to write
PipedStreamTestWriter pstw = new PipedStreamTestWriter();
String str = pstw.getStr();
PipedOutputStream pos = pstw.getStream();
// Now set up our reader
PipedInputStream pis = new PipedInputStream();
pis.connect(pos);
new Thread(pstw).start();
byte[] buf = new byte[12];
int bytes_read, total_read = 0;
while((bytes_read = pis.read(buf)) != -1)
{
System.out.print(new String(buf, 0, bytes_read));
System.out.flush();
Thread.sleep(10); // A short delay
total_read += bytes_read;
}
if (total_read == str.length())
System.out.println("PASSED: Basic piped stream test");
else
System.out.println("FAILED: Basic piped stream test");
}
catch (IOException e)
{
System.out.println("FAILED: Basic piped stream test: " + e);
}
}
} // class PipedStreamTest
class PipedStreamTestWriter implements Runnable
{
String str;
StringBufferInputStream sbis;
PipedOutputStream out;
public
PipedStreamTestWriter()
{
str = "I went to work for Andersen Consulting after I graduated\n" +
"from college. They sent me to their training facility in St. Charles,\n" +
"Illinois and tried to teach me COBOL. I didn't want to learn it.\n" +
"The instructors said I had a bad attitude and I got a green sheet\n" +
"which is a nasty note in your file saying what a jerk you are.\n";
sbis = new StringBufferInputStream(str);
out = new PipedOutputStream();
}
public PipedOutputStream
getStream()
{
return(out);
}
public String
getStr()
{
return(str);
}
public void
run()
{
byte[] buf = new byte[32];
int bytes_read;
try
{
int b = sbis.read();
out.write(b);
while ((bytes_read = sbis.read(buf)) != -1)
out.write(buf, 0, bytes_read);
out.close();
}
catch(IOException e)
{
System.out.println("FAILED: Basic piped stream test: " + e);
}
}
}

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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

View file

@ -0,0 +1,133 @@
/*************************************************************************
/* PushbackInputStreamTest.java -- Tests PushbackInputStream'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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
public class PushbackInputStreamTest extends PushbackInputStream
{
public
PushbackInputStreamTest(InputStream is, int size)
{
super(is, size);
}
public static void
main(String[] argv)
{
System.out.println("Started test of PushbackInputStream");
String str = "Once when I was in fourth grade, my friend Lloyd\n" +
"Saltsgaver and I got in trouble for kicking a bunch of\n" +
"Kindergartners off the horse swings so we could play a game\n" +
"of 'road hog'\n";
System.out.println("Test 1: Protected Variables Test");
{
PushbackInputStreamTest pist = new PushbackInputStreamTest(
new StringBufferInputStream(str), 15);
boolean passed = true;
if (pist.pos != pist.buf.length)
{
passed = false;
System.out.println("The pos variable is wrong. Expected " +
pist.buf.length + " but got " + pist.pos);
}
if (pist.buf.length != 15)
{
passed = false;
System.out.println("The buf.length is wrong. Expected 15" +
" but got " + pist.buf.length);
}
if (passed)
System.out.println("PASSED: Protected Variables Test");
else
System.out.println("FAILED: Protected Variables Test");
}
System.out.println("Test 2: Basic Unread Tests");
try
{
PushbackInputStreamTest pist = new PushbackInputStreamTest(
new StringBufferInputStream(str), 15);
byte[] read_buf1 = new byte[12];
byte[] read_buf2 = new byte[12];
boolean passed = true;
pist.read(read_buf1);
pist.unread(read_buf1);
pist.read(read_buf2);
for (int i = 0; i < read_buf1.length; i++)
{
if (read_buf1[i] != read_buf2[i])
passed = false;
}
pist.unread(read_buf2, 1, read_buf2.length - 1);
pist.unread(read_buf2[0]);
int bytes_read, total_read = 0;
while ((bytes_read = pist.read(read_buf1)) != -1)
{
System.out.print(new String(read_buf1, 0, bytes_read));
total_read += bytes_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
{
PushbackInputStreamTest pist = new PushbackInputStreamTest(
new StringBufferInputStream(str), 10);
byte[] read_buf = new byte[12];
pist.read(read_buf);
pist.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 PushbackInputStream");
} // main
} // class PushbackInputStreamTest

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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

View file

@ -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.

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 != 696969696969L)
{
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) 696969696969L);
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

View file

@ -0,0 +1,85 @@
/*************************************************************************
/* SequenceInputStreamTest.java -- Tests SequenceInputStream'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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
public class SequenceInputStreamTest
{
public static void
main(String argv[])
{
System.out.println("Started test of SequenceInputStream");
String str1 = "I don't believe in going to chain restaurants. I think\n" +
"they are evil. I can't believe all the suburban folks who go to \n";
String str2 = "places like the Olive Garden. Not only does the food make\n" +
"me want to puke, non of these chains has the slightest bit of character.\n";
byte[] buf = new byte[10];
System.out.println("Test 1: Simple read test");
try
{
StringBufferInputStream is1 = new StringBufferInputStream(str1);
ByteArrayInputStream is2 = new ByteArrayInputStream(str2.getBytes());
SequenceInputStream sis = new SequenceInputStream(is1, is2);
int bytes_read;
while((bytes_read = sis.read(buf)) != -1)
{
System.out.print(new String(buf,0,bytes_read));
}
sis.close();
System.out.println("PASSED: Simple read test");
}
catch(IOException e)
{
System.out.println("FAILED: Simple read test: " + e);
}
System.out.println("Test 2: close() test");
try
{
StringBufferInputStream is1 = new StringBufferInputStream(str1);
ByteArrayInputStream is2 = new ByteArrayInputStream(str2.getBytes());
SequenceInputStream sis = new SequenceInputStream(is1, is2);
sis.read(buf);
sis.close();
if (sis.read() != -1)
System.out.println("FAILED: close() test");
else
System.out.println("PASSED: close() test");
}
catch(IOException e)
{
System.out.println("FAILED: close() test: " + e);
}
System.out.println("Finished test of SequenceInputStream");
}
} // class SequenceInputStream

View file

@ -0,0 +1,94 @@
/*************************************************************************
/* StreamTokenizerTest.java -- Test the StreamTokenizer 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
public class StreamTokenizerTest
{
public static void
main(String[] argv)
{
System.out.println("Started test of StreamTokenizer");
try
{
System.out.println("Test 1: Basic Parsing Test");
StreamTokenizer st = new StreamTokenizer(new
FileInputStream("./stream-tokenizer.data"));
System.out.println("No tokens read: " + st.toString());
int j = 0;
for (;;)
{
int ttype = st.nextToken();
switch(ttype)
{
case StreamTokenizer.TT_NUMBER:
System.out.println("Read a number: " + st.toString());
break;
case StreamTokenizer.TT_WORD:
System.out.println("Read a word: " + st.toString());
++j;
if (j == 2)
{
st.ordinaryChar('/');
st.eolIsSignificant(true);
st.lowerCaseMode(true);
st.slashStarComments(true);
st.slashSlashComments(true);
}
break;
case StreamTokenizer.TT_EOL:
System.out.println("Read an EOL: " + st.toString());
break;
case StreamTokenizer.TT_EOF:
System.out.println("Read an EOF: " + st.toString());
case '\'':
case '"':
System.out.println("Got a quote:" + st.toString());
break;
default:
System.out.println("Got an ordinary:" + st.toString());
break;
}
if (ttype == StreamTokenizer.TT_EOF)
break;
}
System.out.println("PASSED: Basic Parsing Test");
}
catch(IOException e)
{
System.out.println("FAILED: Basic Parsing Test: " + e);
}
System.out.println("Finished test of StreamTokenizer");
}
} // class StreamTokenizerTest

View file

@ -0,0 +1,163 @@
/*************************************************************************
/* StringBufferInputStreamTest.java -- Test StringBufferInputStream'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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
public class StringBufferInputStreamTest extends StringBufferInputStream
{
public
StringBufferInputStreamTest(String b)
{
super(b);
}
public static void
main(String[] argv)
{
System.out.println("Starting test of StringBufferInputStream.");
System.out.flush();
String str = "Between my freshman and sophomore years of high school\n" +
"we moved into a brand new building. The old high school was turned\n" +
"into an elementary school.\n";
System.out.println("Test 1: Protected Variables");
StringBufferInputStreamTest sbis = new StringBufferInputStreamTest(str);
byte[] read_buf = new byte[12];
try
{
sbis.read(read_buf);
sbis.mark(0);
boolean passed = true;
sbis.read(read_buf);
if (sbis.pos != (read_buf.length * 2))
{
passed = false;
System.out.println("The pos variable is wrong. Expected 24 and got " +
sbis.pos);
}
if (sbis.count != str.length())
{
passed = false;
System.out.println("The count variable is wrong. Expected " +
str.length() + " and got " + sbis.pos);
}
if (sbis.buffer != str)
{
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");
sbis = new StringBufferInputStreamTest(str);
try
{
int bytes_read, total_read = 0;
while ((bytes_read = sbis.read(read_buf, 0, read_buf.length)) != -1)
{
System.out.print(new String(read_buf, 0, bytes_read));
total_read += bytes_read;
}
sbis.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");
sbis = new StringBufferInputStreamTest(str);
try
{
boolean passed = true;
sbis.read(read_buf);
if (sbis.available() != (str.length() - read_buf.length))
{
passed = false;
System.out.println("available() reported " + sbis.available() +
" and " + (str.length() - read_buf.length) +
" was expected");
}
if (sbis.skip(5) != 5)
{
passed = false;
System.out.println("skip() didn't work");
}
if (sbis.available() != (str.length() - (read_buf.length + 5)))
{
passed = false;
System.out.println("skip() lied");
}
if (sbis.markSupported())
{
passed = false;
System.out.println("markSupported() should have returned false but returned true");
}
int availsave = sbis.available();
sbis.reset();
if (sbis.pos != 0)
{
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 StringBufferInputStream test");
}
}

View file

@ -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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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

View file

@ -0,0 +1,52 @@
/*************************************************************************
/* Test.java -- Base class for test classes
/*
/* Copyright (c) 1998 by Free Software Foundation, Inc.
/*
/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
public class Test
{
public static void error()
{
System.out.print( "ERROR: " );
}
public static void pass()
{
System.out.print( "PASSED: " );
}
public static void fail()
{
System.out.print( "FAILED: " );
}
public static void pass( boolean exp_pass )
{
if( exp_pass )
pass();
else
System.out.print( "XPASSED: " );
}
public static void fail( boolean exp_pass )
{
if( exp_pass )
fail();
else
System.out.print( "XFAIL: " );
}
}

View file

@ -0,0 +1,100 @@
/*************************************************************************
/* UTF8EncodingTest.java -- A quick test of the UTF8 encoding
/*
/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
/*************************************************************************/
import java.io.*;
public class UTF8EncodingTest
{
public static void main(String[] argv)
{
System.out.println("Started test of UTF8 encoding handling");
String str1 = "This is the first line of text\n";
String str2 = "This has some \u01FF\uA000\u6666\u0200 weird characters\n";
System.out.println("Test 1: Write test");
try
{
FileOutputStream fos = new FileOutputStream("utf8test.out");
OutputStreamWriter osr = new OutputStreamWriter(fos, "UTF8");
osr.write(str1);
osr.write(str2);
osr.close();
System.out.println("PASSED: Write test (conditionally)");
}
catch(IOException e)
{
System.out.println("FAILED: Write Test: " + e);
}
System.out.println("Test 2: Read JDK file test");
try
{
FileInputStream fis = new FileInputStream("utf8test-jdk.out");
InputStreamReader isr = new InputStreamReader(fis, "UTF8");
char[] buf = new char[255];
int chars_read = isr.read(buf, 0, str1.length());
String str3 = new String(buf, 0, chars_read);
chars_read = isr.read(buf, 0, str2.length());
String str4 = new String(buf, 0, chars_read);
if (!str1.equals(str3) || !str2.equals(str4))
System.out.println("FAILED: Read JDK file test");
else
System.out.println("PASSED: Read JDK file test");
}
catch(IOException e)
{
System.out.println("FAILED: Read JDK file test: " + e);
}
System.out.println("Test 3: Read classpath file test");
try
{
FileInputStream fis = new FileInputStream("utf8test.out");
InputStreamReader isr = new InputStreamReader(fis, "UTF8");
char[] buf = new char[255];
int chars_read = isr.read(buf, 0, str1.length());
String str3 = new String(buf, 0, chars_read);
chars_read = isr.read(buf, 0, str2.length());
String str4 = new String(buf, 0, chars_read);
if (!str1.equals(str3) || !str2.equals(str4))
System.out.println("FAILED: Read classpath file test");
else
System.out.println("PASSED: Read classpath file test");
}
catch(IOException e)
{
System.out.println("FAILED: Read classpath file test: " + e);
}
System.out.println("Finished test of UTF8 encoding handling");
}
} // class UTF8EncodingTest

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,8 @@
-.1254.ab8/this is to the end of the line
'This would be a string of quoted text'|||||||
'\277\444\\\r\n'
LOWER case ME
ARE/*C type comments
recognized even with EOL signficant?*/
What//is up with C++ comments?
Will this be pushed back?

View file

@ -0,0 +1,2 @@
This is the first line of text
This has some ǿꀀ晦Ȁ weird characters