Initial revision
From-SVN: r102074
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Makefile.in
|
||||
@@ -0,0 +1,4 @@
|
||||
## Input file for automake to generate the Makefile.in used by configure
|
||||
|
||||
SUBDIRS = java.net java.io java.util gnu.java.lang.reflect
|
||||
|
||||
Executable
+98
@@ -0,0 +1,98 @@
|
||||
import java.io.*;
|
||||
import gnu.java.lang.*;
|
||||
import java.lang.reflect.*;
|
||||
|
||||
public class OutputClass {
|
||||
public static void main(String[] args) {
|
||||
for(int i=1;i<args.length;i++) {
|
||||
if(args[i].endsWith(".class")) {
|
||||
args[i] = args[i].substring(0,args[i].length()-6);
|
||||
}
|
||||
args[i] = args[i].replace('/','.');
|
||||
try {
|
||||
try {
|
||||
OutputClass.outputClass(Class.forName(args[i]),System.out);
|
||||
} catch(ClassNotFoundException E) {
|
||||
new PrintStream(new FileOutputStream(args[i]+".out-"+args[0])).println(args[i] + ": class missing.");
|
||||
}
|
||||
} catch(IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void outputClass(Class c, PrintStream out) {
|
||||
out.println(c.getName() + ":class:" + Modifier.toString(sanitizeModifier(c.getModifiers())));
|
||||
// Put implemented interfaces here
|
||||
Field[] f = ClassHelper.getAllFields(c);
|
||||
for(int i=0;i<f.length;i++) {
|
||||
if(Modifier.isPublic(f[i].getModifiers()) || Modifier.isProtected(f[i].getModifiers())) {
|
||||
out.println(
|
||||
c.getName()
|
||||
+ ":field:"
|
||||
+ Modifier.toString(sanitizeModifier(f[i].getModifiers()))
|
||||
+ " "
|
||||
+ f[i].getType().getName()
|
||||
+ " "
|
||||
+ ClassHelper.getTruncatedName(f[i].getName()));
|
||||
}
|
||||
}
|
||||
|
||||
Method[] m = ClassHelper.getAllMethods(c);
|
||||
for(int i=0;i<m.length;i++) {
|
||||
if(Modifier.isPublic(m[i].getModifiers()) || Modifier.isProtected(m[i].getModifiers())) {
|
||||
out.println(
|
||||
c.getName()
|
||||
+ ":method:"
|
||||
+ Modifier.toString(sanitizeModifier(m[i].getModifiers()))
|
||||
+ " "
|
||||
+ m[i].getReturnType().getName()
|
||||
+ " "
|
||||
+ ClassHelper.getTruncatedName(m[i].getName())
|
||||
+ "("
|
||||
+ printArgs(m[i].getParameterTypes())
|
||||
+ ")"
|
||||
+ printExceptions(m[i].getExceptionTypes()));
|
||||
}
|
||||
}
|
||||
|
||||
Constructor[] cl = c.getDeclaredConstructors();
|
||||
for(int i=0;i<cl.length;i++) {
|
||||
if(Modifier.isPublic(cl[i].getModifiers()) || Modifier.isProtected(cl[i].getModifiers())) {
|
||||
out.println(
|
||||
c.getName()
|
||||
+ ":constructor:"
|
||||
+ Modifier.toString(sanitizeModifier(cl[i].getModifiers()))
|
||||
+ " "
|
||||
+ ClassHelper.getTruncatedName(cl[i].getName())
|
||||
+ "("
|
||||
+ printArgs(cl[i].getParameterTypes())
|
||||
+ ")"
|
||||
+ printExceptions(m[i].getExceptionTypes()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static String printArgs(Class[] args) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for(int i=0;i<args.length;i++) {
|
||||
sb.append(args[i]);
|
||||
if(i!=args.length-1) {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static String printExceptions(Class[] exceptions) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for(int i=0;i<exceptions.length;i++) {
|
||||
sb.append(" ");
|
||||
sb.append(exceptions[i].getName());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static int sanitizeModifier(int modifier) {
|
||||
return modifier & ~(Modifier.SYNCHRONIZED | Modifier.TRANSIENT | Modifier.VOLATILE | Modifier.NATIVE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Makefile.in
|
||||
@@ -0,0 +1,5 @@
|
||||
## Input file for automake to generate the Makefile.in used by configure
|
||||
|
||||
JAVAROOT = .
|
||||
|
||||
check_JAVA = TypeSignatureTest.java
|
||||
@@ -0,0 +1,196 @@
|
||||
/*************************************************************************
|
||||
/* TypeSignatureTest.java -- Tests TypeSignature 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.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Member;
|
||||
|
||||
import gnu.java.lang.reflect.TypeSignature;
|
||||
|
||||
public class TypeSignatureTest
|
||||
{
|
||||
public static void pass()
|
||||
{
|
||||
System.out.print( "PASSED: " );
|
||||
}
|
||||
|
||||
public static void fail()
|
||||
{
|
||||
System.out.print( "FAILED: " );
|
||||
}
|
||||
|
||||
public static void testClass( Class clazz, String type_code )
|
||||
{
|
||||
if( TypeSignature.getEncodingOfClass( clazz ).equals( type_code ) )
|
||||
pass();
|
||||
else
|
||||
fail();
|
||||
|
||||
System.out.println( "class encoding of " + clazz );
|
||||
}
|
||||
|
||||
public static void testGetClass( Class clazz, String type_code )
|
||||
throws ClassNotFoundException
|
||||
{
|
||||
if( TypeSignature.getClassForEncoding( type_code ).equals( clazz ) )
|
||||
pass();
|
||||
else
|
||||
fail();
|
||||
|
||||
System.out.println( "class from encoding " + type_code );
|
||||
}
|
||||
|
||||
public static void testConstructor( Constructor c, String type_code )
|
||||
{
|
||||
if( TypeSignature.getEncodingOfConstructor( c ).equals( type_code ) )
|
||||
pass();
|
||||
else
|
||||
fail();
|
||||
|
||||
System.out.println( "constructor encoding of " + c );
|
||||
}
|
||||
|
||||
public static void testMethod( Method m, String type_code )
|
||||
{
|
||||
if( TypeSignature.getEncodingOfMethod( m ).equals( type_code ) )
|
||||
pass();
|
||||
else
|
||||
fail();
|
||||
|
||||
System.out.println( "method encoding of " + m );
|
||||
}
|
||||
|
||||
public static void testMember( Member m, String type_code )
|
||||
{
|
||||
if( TypeSignature.getEncodingOfMember( m ).equals( type_code ) )
|
||||
pass();
|
||||
else
|
||||
fail();
|
||||
|
||||
System.out.println( "member encoding of " + m );
|
||||
}
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
try
|
||||
{
|
||||
// test getEncodingOfClass
|
||||
testClass( Boolean.TYPE, "Z" );
|
||||
testClass( Byte.TYPE, "B" );
|
||||
testClass( Character.TYPE, "C" );
|
||||
testClass( Double.TYPE, "D" );
|
||||
testClass( Float.TYPE, "F" );
|
||||
testClass( Integer.TYPE, "I" );
|
||||
testClass( Long.TYPE, "J" );
|
||||
testClass( Short.TYPE, "S" );
|
||||
testClass( (new int[] {}).getClass(), "[I" );
|
||||
testClass( (new float[][][] {}).getClass(), "[[[F" );
|
||||
testClass( String.class, "Ljava/lang/String;" );
|
||||
testClass( TypeSignatureTest.class, "LTypeSignatureTest;" );
|
||||
|
||||
// test named inner-class
|
||||
TypeSignatureTest tst = new TypeSignatureTest();
|
||||
Inner i = tst.new Inner();
|
||||
testClass( i.getClass(),
|
||||
"LTypeSignatureTest$Inner;" );
|
||||
|
||||
// test anonymous inner-class
|
||||
Anon anon = new Anon() { public void f() {} };
|
||||
testClass( anon.getClass(), "LTypeSignatureTest$1;" );
|
||||
|
||||
//test getEncodingOfConstructor
|
||||
testConstructor( String.class.getConstructor( new Class[] {} ),
|
||||
"()V" );
|
||||
testConstructor(
|
||||
String.class.getConstructor( new Class[]
|
||||
{ (new byte[]{}).getClass() } ),
|
||||
"([B)V" );
|
||||
|
||||
testConstructor(
|
||||
String.class.getConstructor( new Class[] { StringBuffer.class } ),
|
||||
"(Ljava/lang/StringBuffer;)V" );
|
||||
|
||||
// test getEncodingOfMethod
|
||||
testMethod(
|
||||
String.class.getMethod( "lastIndexOf",
|
||||
new Class[] { Integer.TYPE, Integer.TYPE } ),
|
||||
"(II)I" );
|
||||
|
||||
testMethod(
|
||||
String.class.getMethod( "length", new Class[] {} ),
|
||||
"()I" );
|
||||
|
||||
testMethod(
|
||||
TypeSignatureTest.class.getMethod( "pass", new Class[] {} ),
|
||||
"()V" );
|
||||
|
||||
testMember(
|
||||
TypeSignatureTest.class.getField( "i" ),
|
||||
"I" );
|
||||
|
||||
testMember(
|
||||
TypeSignatureTest.class.getField( "s" ),
|
||||
"Ljava/lang/String;" );
|
||||
|
||||
testMember(
|
||||
TypeSignatureTest.class.getField( "o" ),
|
||||
"[[Ljava/lang/Object;" );
|
||||
|
||||
// test getClassForEncoding
|
||||
testGetClass( Boolean.TYPE, "Z" );
|
||||
testGetClass( Byte.TYPE, "B" );
|
||||
testGetClass( Character.TYPE, "C" );
|
||||
testGetClass( Double.TYPE, "D" );
|
||||
testGetClass( Float.TYPE, "F" );
|
||||
testGetClass( Integer.TYPE, "I" );
|
||||
testGetClass( Long.TYPE, "J" );
|
||||
testGetClass( Short.TYPE, "S" );
|
||||
testGetClass( (new int[] {}).getClass(), "[I" );
|
||||
testGetClass( (new float[][][] {}).getClass(), "[[[F" );
|
||||
testGetClass( String.class, "Ljava/lang/String;" );
|
||||
testGetClass( TypeSignatureTest.class, "LTypeSignatureTest;" );
|
||||
|
||||
// test named inner-class
|
||||
testGetClass( i.getClass(),
|
||||
"LTypeSignatureTest$Inner;" );
|
||||
|
||||
// test anonymous inner-class
|
||||
testGetClass( anon.getClass(), "LTypeSignatureTest$1;" );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int i;
|
||||
public String s;
|
||||
public Object[][] o;
|
||||
|
||||
|
||||
class Inner
|
||||
{}
|
||||
}
|
||||
|
||||
|
||||
interface Anon
|
||||
{
|
||||
public void f();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import java.beans.*;
|
||||
|
||||
public class DescriptorTest implements Runnable {
|
||||
public static void main(String[] args) {
|
||||
new DescriptorTest().run();
|
||||
}
|
||||
|
||||
interface TestClass {
|
||||
public String[] getTest();
|
||||
public void setTest(String[] test);
|
||||
public String getTest(int i);
|
||||
public void setTest(int i, String name);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
new PropertyDescriptor("class",java.lang.Object.class);
|
||||
System.out.println("PASSED: Property Object.class");
|
||||
} catch(IntrospectionException e) {
|
||||
System.out.println("FAILED: Property Object.class");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
new IndexedPropertyDescriptor("test",TestClass.class);
|
||||
System.out.println("PASSED: Indexed Property Component.location");
|
||||
} catch(IntrospectionException e) {
|
||||
System.out.println("FAILED: Indexed Property Component.location");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
new EventSetDescriptor(java.awt.Button.class,"action",java.awt.event.ActionListener.class,"actionPerformed");
|
||||
System.out.println("PASSED: Event Set Button.action");
|
||||
} catch(IntrospectionException e) {
|
||||
System.out.println("FAILED: Event Set Button.action");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
new MethodDescriptor(java.awt.Component.class.getMethod("getLocation",new Class[0]));
|
||||
System.out.println("PASSED: Method Component.getLocation");
|
||||
} catch(NoSuchMethodException e) {
|
||||
System.out.println("FAILED: No such method: Component.getLocation()");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import java.beans.*;
|
||||
|
||||
public class IntrospectorTest {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
BeanInfo b = Introspector.getBeanInfo(java.awt.Component.class);
|
||||
if(b.getPropertyDescriptors().length == 6
|
||||
&& b.getEventSetDescriptors().length == 5
|
||||
&& b.getMethodDescriptors().length == 128) {
|
||||
System.out.println("PASSED: Introspector.getBeanInfo(java.awt.Component.class)");
|
||||
} else {
|
||||
System.out.println("FAILED: Introspector.getBeanInfo(java.awt.Component.class)");
|
||||
}
|
||||
b = Introspector.getBeanInfo(java.util.BitSet.class);
|
||||
if(b.getPropertyDescriptors().length == 2
|
||||
&& b.getEventSetDescriptors().length == 0
|
||||
&& b.getMethodDescriptors().length == 17) {
|
||||
System.out.println("PASSED: Introspector.getBeanInfo(java.util.BitSet.class)");
|
||||
} else {
|
||||
System.out.println("FAILED: Introspector.getBeanInfo(java.util.BitSet.class)");
|
||||
}
|
||||
b = Introspector.getBeanInfo(java.lang.Object.class);
|
||||
if(b.getPropertyDescriptors().length == 1
|
||||
&& b.getEventSetDescriptors().length == 0
|
||||
&& b.getMethodDescriptors().length == 9) {
|
||||
System.out.println("PASSED: Introspector.getBeanInfo(java.lang.Object.class)");
|
||||
} else {
|
||||
System.out.println("FAILED: Introspector.getBeanInfo(java.lang.Object.class)");
|
||||
}
|
||||
b = Introspector.getBeanInfo(java.applet.Applet.class);
|
||||
if(b.getPropertyDescriptors().length == 24
|
||||
&& b.getEventSetDescriptors().length == 6
|
||||
&& b.getMethodDescriptors().length == 168) {
|
||||
System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class)");
|
||||
} else {
|
||||
System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class)");
|
||||
}
|
||||
b = Introspector.getBeanInfo(java.awt.Button.class);
|
||||
if(b.getPropertyDescriptors().length == 8
|
||||
&& b.getEventSetDescriptors().length == 6
|
||||
&& b.getMethodDescriptors().length == 134) {
|
||||
System.out.println("PASSED: Introspector.getBeanInfo(java.awt.Button.class)");
|
||||
} else {
|
||||
System.out.println("FAILED: Introspector.getBeanInfo(java.awt.Button.class)");
|
||||
}
|
||||
b = Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Panel.class);
|
||||
if(b.getPropertyDescriptors().length == 8
|
||||
&& b.getEventSetDescriptors().length == 0
|
||||
&& b.getMethodDescriptors().length == 22) {
|
||||
System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Panel.class)");
|
||||
} else {
|
||||
System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length);
|
||||
System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Panel.class)");
|
||||
}
|
||||
b = Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Component.class);
|
||||
if(b.getPropertyDescriptors().length == 18
|
||||
&& b.getEventSetDescriptors().length == 1
|
||||
&& b.getMethodDescriptors().length == 65) {
|
||||
System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Component.class)");
|
||||
} else {
|
||||
System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length);
|
||||
System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,java.awt.Component.class)");
|
||||
}
|
||||
b = Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class);
|
||||
if(b.getPropertyDescriptors().length == 24
|
||||
&& b.getEventSetDescriptors().length == 6
|
||||
&& b.getMethodDescriptors().length == 160) {
|
||||
System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class)");
|
||||
} else {
|
||||
System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length);
|
||||
System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class)");
|
||||
}
|
||||
|
||||
b = Introspector.getBeanInfo(java.applet.Applet.class,null);
|
||||
if(b.getPropertyDescriptors().length == 24
|
||||
&& b.getEventSetDescriptors().length == 6
|
||||
&& b.getMethodDescriptors().length == 168) {
|
||||
System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class,java.lang.Object.class)");
|
||||
} else {
|
||||
System.out.println(b.getPropertyDescriptors().length + " " + b.getEventSetDescriptors().length + " " + b.getMethodDescriptors().length);
|
||||
System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class,null)");
|
||||
}
|
||||
|
||||
b = Introspector.getBeanInfo(java.applet.Applet.class);
|
||||
if(b.getPropertyDescriptors().length == 24
|
||||
&& b.getEventSetDescriptors().length == 6
|
||||
&& b.getMethodDescriptors().length == 168) {
|
||||
System.out.println("PASSED: Introspector.getBeanInfo(java.applet.Applet.class) 2nd time");
|
||||
} else {
|
||||
System.out.println("FAILED: Introspector.getBeanInfo(java.applet.Applet.class) 2nd time");
|
||||
}
|
||||
} catch(IntrospectionException e) {
|
||||
System.out.println("FAILED: IntrospectionException");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.util.Hashtable;
|
||||
|
||||
public class PropertyChangeSupportTest implements Runnable {
|
||||
class Source {
|
||||
PropertyChangeSupport support = new PropertyChangeSupport(this);
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
support.addPropertyChangeListener(l);
|
||||
}
|
||||
public void addPropertyChangeListener(String s, PropertyChangeListener l) {
|
||||
support.addPropertyChangeListener(s,l);
|
||||
}
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
support.removePropertyChangeListener(l);
|
||||
}
|
||||
public void removePropertyChangeListener(String s, PropertyChangeListener l) {
|
||||
support.removePropertyChangeListener(s,l);
|
||||
}
|
||||
|
||||
void changeProperty(String name) {
|
||||
support.firePropertyChange(name,"old","new");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class Listener implements PropertyChangeListener {
|
||||
Hashtable numEventsReceived = new Hashtable();
|
||||
int getNumEvents(String propertyName) {
|
||||
Integer i = (Integer)numEventsReceived.get(propertyName);
|
||||
try {
|
||||
return i.intValue();
|
||||
} catch(NullPointerException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
Integer i = (Integer)numEventsReceived.get(e.getPropertyName());
|
||||
try {
|
||||
int newI = i.intValue() + 1;
|
||||
numEventsReceived.put(e.getPropertyName(), new Integer(newI));
|
||||
} catch(NullPointerException exc) {
|
||||
numEventsReceived.put(e.getPropertyName(), new Integer(1));
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
numEventsReceived = new Hashtable();
|
||||
}
|
||||
}
|
||||
|
||||
public void setProperties(Source s) {
|
||||
s.changeProperty("foo");
|
||||
s.changeProperty("foo");
|
||||
s.changeProperty("foo");
|
||||
s.changeProperty("bar");
|
||||
s.changeProperty("bar");
|
||||
s.changeProperty("foobar");
|
||||
}
|
||||
|
||||
public void shouldEqual(Listener l, int foo, int bar, int foobar, String testName) {
|
||||
String whatsWrong = "";
|
||||
if(l.getNumEvents("foo") != foo) {
|
||||
whatsWrong += ("foo(" + l.getNumEvents("foo") + ") != " + foo);
|
||||
}
|
||||
if(l.getNumEvents("bar") != bar) {
|
||||
whatsWrong += (" bar(" + l.getNumEvents("bar") + ") != " + bar);
|
||||
}
|
||||
if(l.getNumEvents("foobar") != foobar) {
|
||||
whatsWrong += (" foobar(" + l.getNumEvents("foobar") + ") != " + foobar);
|
||||
}
|
||||
|
||||
if(!whatsWrong.equals("")) {
|
||||
System.out.println("FAILURE: " + testName + ": " + whatsWrong);
|
||||
} else {
|
||||
System.out.println("Success: " + testName);
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Source s = new Source();
|
||||
|
||||
/* Test: single multi-property adds */
|
||||
Listener l = new Listener();
|
||||
s.addPropertyChangeListener(l);
|
||||
setProperties(s);
|
||||
shouldEqual(l, 3, 2, 1, "single multi-property adds");
|
||||
|
||||
/* Test: multiple listeners */
|
||||
Listener l2 = new Listener();
|
||||
s.addPropertyChangeListener(l2);
|
||||
setProperties(s);
|
||||
shouldEqual(l, 6, 4, 2, "multiple listeners-l");
|
||||
shouldEqual(l2, 3, 2, 1, "multiple listeners-l2");
|
||||
|
||||
/* Test: multiple multi-property adds */
|
||||
s.addPropertyChangeListener(l);
|
||||
setProperties(s);
|
||||
shouldEqual(l, 12, 8, 4, "multiple multi-property adds-l");
|
||||
shouldEqual(l2, 6, 4, 2, "multiple multi-property adds-l2");
|
||||
|
||||
/* Test: remove multi-property add */
|
||||
s.removePropertyChangeListener(l);
|
||||
setProperties(s);
|
||||
shouldEqual(l, 15, 10, 5, "remove multi-property add-l");
|
||||
shouldEqual(l2, 9, 6, 3, "remove multi-property add-l2");
|
||||
|
||||
|
||||
s.removePropertyChangeListener(l);
|
||||
s.removePropertyChangeListener(l2);
|
||||
l.reset();
|
||||
l2.reset();
|
||||
|
||||
/* ENABLE THIS IF YOU THINK RESET ISN'T HAPPENING
|
||||
shouldEqual(l, 0, 0, 0, "RESET-l");
|
||||
shouldEqual(l2, 0, 0, 0, "RESET-l2");
|
||||
setProperties(s);
|
||||
shouldEqual(l, 0, 0, 0, "RESET_AGAIN-l");
|
||||
shouldEqual(l2, 0, 0, 0, "RESET_AGAIN-l2");
|
||||
*/
|
||||
|
||||
|
||||
/* Test: single property listener */
|
||||
s.addPropertyChangeListener("foo", l);
|
||||
setProperties(s);
|
||||
shouldEqual(l, 3, 0, 0, "single property listener");
|
||||
|
||||
/* Test: multiple different properties */
|
||||
s.addPropertyChangeListener("bar", l);
|
||||
setProperties(s);
|
||||
shouldEqual(l, 6, 2, 0, "multiple different properties");
|
||||
|
||||
/* Test: multiple of same property */
|
||||
s.addPropertyChangeListener("foo", l);
|
||||
setProperties(s);
|
||||
shouldEqual(l, 12, 4, 0, "multiple of same property");
|
||||
|
||||
/* Test: multiple single-property listeners */
|
||||
s.addPropertyChangeListener("foo", l2);
|
||||
setProperties(s);
|
||||
shouldEqual(l, 18, 6, 0, "multiple single-property listeners-l");
|
||||
shouldEqual(l2, 3, 0, 0, "multiple single-property listeners-l2");
|
||||
|
||||
/* Test: remove single-property add */
|
||||
s.removePropertyChangeListener("foo", l);
|
||||
setProperties(s);
|
||||
shouldEqual(l, 21, 8, 0, "remove single-property add-l");
|
||||
shouldEqual(l2, 6, 0, 0, "remove single-property add-l2");
|
||||
|
||||
|
||||
s.removePropertyChangeListener("foo", l);
|
||||
s.removePropertyChangeListener("bar", l);
|
||||
s.removePropertyChangeListener("foo", l2);
|
||||
l.reset();
|
||||
l2.reset();
|
||||
|
||||
/* ENABLE THIS IF YOU THINK RESET ISN'T HAPPENING
|
||||
shouldEqual(l, 0, 0, 0, "RESET-l");
|
||||
shouldEqual(l2, 0, 0, 0, "RESET-l2");
|
||||
setProperties(s);
|
||||
shouldEqual(l, 0, 0, 0, "RESET_AGAIN-l");
|
||||
shouldEqual(l2, 0, 0, 0, "RESET_AGAIN-l2");
|
||||
*/
|
||||
|
||||
/* Test: multiple- and single-property interaction */
|
||||
s.addPropertyChangeListener(l);
|
||||
s.addPropertyChangeListener("foo", l);
|
||||
setProperties(s);
|
||||
shouldEqual(l, 6, 2, 1, "multiple- and single-property interaction");
|
||||
|
||||
/* Test: multiple- and single-property interaction: multiple-listener removal */
|
||||
s.removePropertyChangeListener(l);
|
||||
setProperties(s);
|
||||
shouldEqual(l, 9, 2, 1, "multiple- and single-property interaction: multiple-listener removal");
|
||||
|
||||
/* Test: hasListeners() with multiple cases */
|
||||
if(s.support.hasListeners("foo")) {
|
||||
System.out.println("Success: hasListeners() returning true");
|
||||
} else {
|
||||
System.out.println("FAILURE: hasListeners() returning true");
|
||||
}
|
||||
if(s.support.hasListeners("bar")) {
|
||||
System.out.println("FAILURE: hasListeners() returning false");
|
||||
} else {
|
||||
System.out.println("Success: hasListeners() returning false");
|
||||
}
|
||||
s.addPropertyChangeListener(l);
|
||||
if(s.support.hasListeners("bar")) {
|
||||
System.out.println("Success: hasListeners() with all-event listeners");
|
||||
} else {
|
||||
System.out.println("FAILURE: hasListeners() with all-event listeners");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new PropertyChangeSupportTest().run();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Makefile.in
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 + " >" );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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" );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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 {}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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: " );
|
||||
}
|
||||
}
|
||||
@@ -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.
@@ -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?
|
||||
@@ -0,0 +1,2 @@
|
||||
This is the first line of text
|
||||
This has some ǿꀀ晦Ȁ weird characters
|
||||
@@ -0,0 +1 @@
|
||||
Makefile.in
|
||||
@@ -0,0 +1,184 @@
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
public class ArrayTest {
|
||||
public static void main(String[] args) {
|
||||
System.loadLibrary("javalangreflect");
|
||||
|
||||
Object[] objArray = new Object[9];
|
||||
boolean[] boolArray = new boolean[9];
|
||||
double[] doubleArray = new double[9];
|
||||
byte[] byteArray = new byte[9];
|
||||
char[] charArray = new char[9];
|
||||
|
||||
try {
|
||||
Boolean[][] blahArray = (Boolean[][])Array.newInstance(java.lang.Boolean.class,new int[]{9,1});
|
||||
System.out.print(blahArray != null ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
E.printStackTrace();
|
||||
}
|
||||
System.out.println(": newInstance(Class,int[])");
|
||||
|
||||
try {
|
||||
boolean[] blahArray = (boolean[])Array.newInstance(java.lang.Boolean.TYPE, 9);
|
||||
System.out.print(blahArray != null ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
E.printStackTrace();
|
||||
}
|
||||
System.out.println(": newInstance(<primitive Class>,int)");
|
||||
|
||||
try {
|
||||
objArray = (Object[])Array.newInstance(java.lang.Object.class, 9);
|
||||
System.out.print(objArray != null ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": newInstance(Class,int)");
|
||||
|
||||
try {
|
||||
Boolean obj = new Boolean(true);
|
||||
Array.set(objArray,0,obj);
|
||||
System.out.print(objArray[0] == obj ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": set()");
|
||||
|
||||
try {
|
||||
Array.setBoolean(boolArray,1,true);
|
||||
System.out.print(boolArray[1] == true ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": setBoolean()");
|
||||
|
||||
try {
|
||||
Array.setByte(byteArray,2,(byte)2);
|
||||
System.out.print(byteArray[2] == 2 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": setByte()");
|
||||
|
||||
try {
|
||||
Array.setShort(doubleArray,3,(short)3);
|
||||
System.out.print(doubleArray[3] == 3 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": setShort()");
|
||||
|
||||
try {
|
||||
Array.setChar(charArray,4,(char)4);
|
||||
System.out.print(charArray[4] == 4 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": setChar()");
|
||||
|
||||
try {
|
||||
Array.setInt(doubleArray,5,5);
|
||||
System.out.print(doubleArray[5] == 5 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": setInt()");
|
||||
|
||||
try {
|
||||
Array.setLong(doubleArray,6,6);
|
||||
System.out.print(doubleArray[6] == 6 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": setLong()");
|
||||
|
||||
try {
|
||||
Array.setFloat(doubleArray,7,7);
|
||||
System.out.print(doubleArray[7] == 7 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": setFloat()");
|
||||
|
||||
try {
|
||||
Array.setDouble(doubleArray,8,8);
|
||||
System.out.print(doubleArray[8] == 8 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": setDouble()");
|
||||
|
||||
try {
|
||||
Boolean obj = (Boolean)Array.get(objArray,0);
|
||||
System.out.print(obj != null ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": get()");
|
||||
|
||||
try {
|
||||
boolArray[1] = true;
|
||||
System.out.print(Array.getBoolean(boolArray,1) == true ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": getBoolean()");
|
||||
|
||||
try {
|
||||
byteArray[2] = (byte)2;
|
||||
System.out.print(Array.getByte(byteArray,2) == 2 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": getByte()");
|
||||
|
||||
try {
|
||||
byteArray[3] = (byte)3;
|
||||
System.out.print(Array.getShort(byteArray,3) == 3 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": getShort()");
|
||||
|
||||
try {
|
||||
charArray[4] = (char)4;
|
||||
System.out.print(Array.getChar(charArray,4) == 4 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": getChar()");
|
||||
|
||||
try {
|
||||
byteArray[5] = (byte)5;
|
||||
System.out.print(Array.getInt(byteArray,5) == 5 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": getInt()");
|
||||
|
||||
try {
|
||||
byteArray[6] = (byte)6;
|
||||
System.out.print(Array.getLong(byteArray,6) == 6 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": getLong()");
|
||||
|
||||
try {
|
||||
byteArray[7] = (byte)7;
|
||||
System.out.print(Array.getFloat(byteArray,7) == 7 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": getFloat()");
|
||||
|
||||
try {
|
||||
doubleArray[8] = 8;
|
||||
System.out.print(Array.getDouble(doubleArray,8) == 8 ? "PASSED" : "FAILED");
|
||||
} catch(Exception E) {
|
||||
System.out.print("FAILED");
|
||||
}
|
||||
System.out.println(": getDouble()");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
## Input file for automake to generate the Makefile.in used by configure
|
||||
|
||||
check_JAVA = ArrayTest.java
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Makefile.in
|
||||
@@ -0,0 +1,5 @@
|
||||
Why can I only send a 65332 sized UDP packet? Is there that much UDP overhead?
|
||||
|
||||
Setting the multicast interface doesn't seem to work.
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/* Class to test Datagrams from a client perspective */
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
public class ClientDatagram
|
||||
{
|
||||
|
||||
public static void
|
||||
main(String[] argv) throws IOException
|
||||
{
|
||||
System.out.println("Starting datagram tests");
|
||||
|
||||
byte[] buf = new byte[2048];
|
||||
DatagramPacket p = new DatagramPacket(buf, buf.length);
|
||||
InetAddress addr = InetAddress.getByName("localhost");
|
||||
|
||||
/* Execute the daytime UDP service on localhost. You may need to
|
||||
enable this in inetd to make the test work */
|
||||
System.out.println("Test 1: Simple daytime test");
|
||||
try
|
||||
{
|
||||
|
||||
DatagramSocket s = new DatagramSocket();
|
||||
|
||||
System.out.println("Socket bound to " + s.getLocalAddress() +
|
||||
":" + s.getLocalPort());
|
||||
|
||||
byte[] sbuf = { 'H', 'I' };
|
||||
DatagramPacket spack = new DatagramPacket(sbuf, sbuf.length, addr, 13);
|
||||
|
||||
s.send(spack);
|
||||
s.receive(p);
|
||||
|
||||
System.out.println("Received " + p.getLength() + " bytes from " +
|
||||
p.getAddress() + ":" + p.getPort());
|
||||
|
||||
byte[] tmp = new byte[p.getLength()];
|
||||
for (int i = 0; i < p.getLength(); i++)
|
||||
tmp[i] = buf[i];
|
||||
|
||||
System.out.print("Data: " + new String(tmp));
|
||||
|
||||
s.close();
|
||||
System.out.println("PASSED simple datagram test");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("FAILED simple datagram test: " + e);
|
||||
}
|
||||
|
||||
System.out.println("Test 2: Specific host/port binding");
|
||||
try
|
||||
{
|
||||
DatagramSocket s = new DatagramSocket(8765, addr);
|
||||
if (s.getLocalPort() != 8765)
|
||||
throw new IOException("Bound to wrong port: " + s.getLocalPort());
|
||||
|
||||
if (!s.getLocalAddress().equals(addr))
|
||||
throw new IOException("Bound to wrong host:" + s.getLocalAddress());
|
||||
|
||||
s.close();
|
||||
System.out.println("PASSED specific host/port binding test");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("FAILED specific host/port binding: " + e);
|
||||
}
|
||||
|
||||
System.out.println("Test 3: Socket Options test");
|
||||
try
|
||||
{
|
||||
DatagramSocket s = new DatagramSocket();
|
||||
System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
|
||||
System.out.println("Setting SO_TIMEOUT to 170");
|
||||
s.setSoTimeout(170);
|
||||
System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
|
||||
System.out.println("Setting SO_TIMEOUT to 0");
|
||||
s.setSoTimeout(0);
|
||||
System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
|
||||
s.close();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("WARNING: Problem with SO_TIMEOUT test: " + e.getMessage());
|
||||
System.out.println("This is ok on Linux");
|
||||
}
|
||||
|
||||
System.out.println("Test 4: Max values test");
|
||||
try
|
||||
{
|
||||
// ServerDatagram sd = new ServerDatagram(37900);
|
||||
// sd.run();
|
||||
|
||||
DatagramSocket s = new DatagramSocket();
|
||||
byte[] sbuf = new byte[65332];
|
||||
DatagramPacket spack = new DatagramPacket(sbuf, sbuf.length,
|
||||
addr, 37900);
|
||||
|
||||
s.send(spack);
|
||||
s.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("FAILED max values test: " + e);
|
||||
}
|
||||
|
||||
System.out.println("Datagram testing complete");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
/* A class to test my client TCP socket implementation */
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
public class ClientSocket extends Object
|
||||
{
|
||||
public static void
|
||||
main(String[] argv) throws IOException
|
||||
{
|
||||
System.out.println("Starting client stream socket test");
|
||||
|
||||
/* Simple connection and read test */
|
||||
System.out.println("Test 1: Connection to daytime port on local host");
|
||||
try
|
||||
{
|
||||
InetAddress addr = InetAddress.getByName("127.0.0.1");
|
||||
|
||||
Socket s = new Socket(addr, 13);
|
||||
|
||||
InputStream is = s.getInputStream();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
for (String str = br.readLine(); ; str = br.readLine())
|
||||
{
|
||||
if (str == null)
|
||||
break;
|
||||
System.out.println(str);
|
||||
}
|
||||
s.close();
|
||||
System.out.println("PASSED: daytime test");
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
System.out.println("FAILED: daytime test: " + e);
|
||||
}
|
||||
|
||||
/* Simple connection refused test */
|
||||
System.out.println("Test 2: Connection refused test");
|
||||
try
|
||||
{
|
||||
InetAddress addr = InetAddress.getByName("127.0.0.1");
|
||||
|
||||
Socket s = new Socket(addr, 47);
|
||||
s.close();
|
||||
|
||||
System.out.print("WARNING: Cannot perform connection refused test");
|
||||
System.out.println(" because someone is listening on localhost:47");
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
System.out.println("PASSED: connection refused test: " + e.getMessage());
|
||||
}
|
||||
|
||||
/* Socket attributes test */
|
||||
System.out.println("Test 3: Connection attributes");
|
||||
try
|
||||
{
|
||||
Socket s = new Socket("www.netscape.com", 80);
|
||||
|
||||
String laddr = s.getLocalAddress().getHostName();
|
||||
int lport = s.getLocalPort();
|
||||
String raddr = s.getInetAddress().getHostName();
|
||||
int rport = s.getPort();
|
||||
|
||||
System.out.println("Local Address is: " + laddr);
|
||||
System.out.println("Local Port is: " + lport);
|
||||
System.out.println("Remote Address is: " + raddr);
|
||||
System.out.println("Remote Port is: " + rport);
|
||||
System.out.println("Socket.toString is: " + s);
|
||||
|
||||
if ( (laddr == null) ||
|
||||
((lport < 0) || (lport > 65535)) ||
|
||||
(raddr.indexOf("netscape.com") == -1) ||
|
||||
(rport != 80))
|
||||
System.out.println("FAILED: connection attribute test");
|
||||
else
|
||||
System.out.println("PASSED: connection attribute test");
|
||||
|
||||
s.close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
System.out.println("FAILED: connection attributes test: " + e.getMessage());
|
||||
}
|
||||
|
||||
/* Socket options test */
|
||||
System.out.println("Test 4: Socket options");
|
||||
Socket s = new Socket("127.0.0.1", 23);
|
||||
|
||||
try
|
||||
{
|
||||
// SO_TIMEOUT
|
||||
System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
|
||||
System.out.println("Setting SO_TIMEOUT to 142");
|
||||
s.setSoTimeout(142);
|
||||
System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
|
||||
System.out.println("Setting SO_TIMEOUT to 0");
|
||||
s.setSoTimeout(0);
|
||||
System.out.println("SO_TIMEOUT = " + s.getSoTimeout());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("WARNING: SO_TIMEOUT problem: " + e.getMessage());
|
||||
System.out.println("This is ok on Linux");
|
||||
}
|
||||
try
|
||||
{
|
||||
// Try TCP_NODELAY
|
||||
System.out.println("TCP_NODELAY = " + s.getTcpNoDelay());
|
||||
System.out.println("Setting TCP_NODELAY to true");
|
||||
s.setTcpNoDelay(true);
|
||||
System.out.println("TCP_NODELAY = " + s.getTcpNoDelay());
|
||||
System.out.println("Setting TCP_NODELAY to false");
|
||||
s.setTcpNoDelay(false);
|
||||
System.out.println("TCP_NODELAY = " + s.getTcpNoDelay());
|
||||
|
||||
// Try SO_LINGER
|
||||
System.out.println("SO_LINGER = " + s.getSoLinger());
|
||||
System.out.println("Setting SO_LINGER to 100");
|
||||
s.setSoLinger(true, 100);
|
||||
System.out.println("SO_LINGER = " + s.getSoLinger());
|
||||
System.out.println("Setting SO_LINGER to off");
|
||||
s.setSoLinger(false, 0);
|
||||
System.out.println("SO_LINGER = " + s.getSoLinger());
|
||||
|
||||
System.out.println("PASSED: socket options test");
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
System.out.println("FAILED: socket options test: " + e.getMessage());
|
||||
}
|
||||
s.close();
|
||||
|
||||
/* Simple read/write test */
|
||||
System.out.println("Test 5: Simple read/write test");
|
||||
try
|
||||
{
|
||||
System.out.println("Downloading the Transmeta homepage");
|
||||
s = new Socket("www.transmeta.com", 80);
|
||||
|
||||
BufferedReader in = new BufferedReader(new
|
||||
InputStreamReader(s.getInputStream()));
|
||||
PrintWriter out = new PrintWriter(new
|
||||
OutputStreamWriter(s.getOutputStream()));
|
||||
|
||||
out.print("GET /\r\n");
|
||||
out.flush();
|
||||
|
||||
for (String str = in.readLine(); ; str = in.readLine())
|
||||
{
|
||||
if (str == null)
|
||||
break;
|
||||
System.out.println(str);
|
||||
}
|
||||
|
||||
s.close();
|
||||
System.out.println("PASSED: simple read/write test");
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
System.out.println("FAILED: simple read/write test: " + e.getMessage());
|
||||
}
|
||||
|
||||
/* Connect to our server socket */
|
||||
System.out.println("Test 6: Connect to ServerSocket");
|
||||
try
|
||||
{
|
||||
s = new Socket("localhost", 9999);
|
||||
|
||||
PrintWriter out = new PrintWriter(new
|
||||
OutputStreamWriter(s.getOutputStream()));
|
||||
|
||||
out.println("Hello, there server socket");
|
||||
out.print("I'm dun");
|
||||
out.flush();
|
||||
s.close();
|
||||
System.out.println("PASSED: connect to server socket");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.println("FAILED: connect to server socket: " + e);
|
||||
}
|
||||
|
||||
System.out.println("Client stream socket test complete");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
## Input file for automake to generate the Makefile.in used by configure
|
||||
|
||||
JAVAROOT = .
|
||||
|
||||
check_JAVA = ClientDatagram.java ClientSocket.java MulticastClient.java \
|
||||
MulticastServer.java ServerDatagram.java ServerSocketTest.java \
|
||||
SubSocket.java TestNameLookups.java URLTest.java
|
||||
|
||||
EXTRA_DIST = BUGS runtest
|
||||
@@ -0,0 +1,65 @@
|
||||
/* Test Multicast Sockets */
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
public class MulticastClient
|
||||
{
|
||||
|
||||
public static void
|
||||
main(String[] argv) throws IOException
|
||||
{
|
||||
System.out.println("Starting multicast tests");
|
||||
System.out.println("NOTE: You need to do an 'ifconfig <interface> " +
|
||||
"multicast' or this will fail on linux");
|
||||
|
||||
byte[] buf = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W', 'o','r','l','d' };
|
||||
|
||||
/* Simple Send */
|
||||
System.out.println("Test 1: Multicast send/receive test");
|
||||
try
|
||||
{
|
||||
InetAddress addr = InetAddress.getByName("234.0.0.1");
|
||||
|
||||
MulticastSocket s = new MulticastSocket();
|
||||
DatagramPacket p = new DatagramPacket(buf, buf.length, addr, 3333);
|
||||
|
||||
s.joinGroup(addr);
|
||||
s.send(p);
|
||||
s.close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
System.out.println("FAILED: simple multicast send: " + e);
|
||||
}
|
||||
|
||||
/* Options */
|
||||
System.out.println("Test 2: Multicast socket options");
|
||||
try
|
||||
{
|
||||
InetAddress addr;
|
||||
MulticastSocket s = new MulticastSocket();
|
||||
|
||||
System.out.println("TTL = " + s.getTTL());
|
||||
System.out.println("Setting TTT to 121");
|
||||
s.setTTL((byte)12);
|
||||
System.out.println("TTL = " + s.getTTL());
|
||||
|
||||
InetAddress oaddr = s.getInterface();
|
||||
System.out.println("Multicast Interface = " + oaddr);
|
||||
System.out.println("Setting interface to localhost");
|
||||
addr = InetAddress.getByName("198.211.138.177");
|
||||
s.setInterface(addr);
|
||||
System.out.println("Multicast Interface = " + s.getInterface());
|
||||
System.out.println("Setting interface to " + oaddr);
|
||||
s.setInterface(oaddr);
|
||||
System.out.println("Multicast Interface = " + s.getInterface());
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
System.out.println("FAILED: multicast options: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/* Mulitcast Server Socket for testing */
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
public class MulticastServer
|
||||
{
|
||||
|
||||
private MulticastSocket s;
|
||||
|
||||
public static void
|
||||
main(String[] argv) throws IOException
|
||||
{
|
||||
MulticastServer ms = new MulticastServer(3333);
|
||||
ms.run();
|
||||
}
|
||||
|
||||
public
|
||||
MulticastServer(int port) throws IOException
|
||||
{
|
||||
s = new MulticastSocket(port);
|
||||
System.out.println("Server multicast socket created");
|
||||
}
|
||||
|
||||
public void
|
||||
run()
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] buf = new byte[255];
|
||||
|
||||
DatagramPacket p = new DatagramPacket(buf, buf.length);
|
||||
InetAddress addr = InetAddress.getByName("234.0.0.1");
|
||||
|
||||
p.setLength(buf.length);
|
||||
|
||||
System.out.println("Joining multicast group");
|
||||
s.joinGroup(addr);
|
||||
System.out.print("Receiving ...");
|
||||
s.receive(p);
|
||||
System.out.println("");
|
||||
s.leaveGroup(addr);
|
||||
System.out.println("ServerDatagram: received " + p.getLength() +
|
||||
" bytes from " + p.getAddress().getHostName() + ":" +
|
||||
p.getPort());
|
||||
System.out.println("Data: " + new String(p.getData()));
|
||||
|
||||
System.out.println("PASSED multicast server test");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("FAILED: MulticastServer caught an exception: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/* Server Datagram Socket for testing */
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
public class ServerDatagram implements Runnable
|
||||
{
|
||||
|
||||
private DatagramSocket s;
|
||||
|
||||
public static void
|
||||
main(String[] argv) throws IOException
|
||||
{
|
||||
ServerDatagram sd = new ServerDatagram(37900);
|
||||
sd.run();
|
||||
}
|
||||
|
||||
public
|
||||
ServerDatagram(int port) throws SocketException
|
||||
{
|
||||
s = new DatagramSocket(port);
|
||||
System.out.println("Server datagram socket created");
|
||||
}
|
||||
|
||||
public void
|
||||
run()
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] buf = new byte[65535];
|
||||
|
||||
DatagramPacket p = new DatagramPacket(buf, buf.length);
|
||||
|
||||
p.setLength(buf.length);
|
||||
|
||||
s.receive(p);
|
||||
System.out.println("ServerDatagram: received " + p.getLength() +
|
||||
" bytes from " + p.getAddress().getHostName() + ":" +
|
||||
p.getPort());
|
||||
|
||||
if (p.getLength() != 65332)
|
||||
throw new IOException("Incorrect data size");
|
||||
System.out.println("PASSED max values test");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.print("FAILED: ServerDatagram caught an exception: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/* Class to test server sockets */
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
public class ServerSocketTest extends ServerSocket
|
||||
{
|
||||
|
||||
public
|
||||
ServerSocketTest(int port) throws IOException
|
||||
{
|
||||
super(port);
|
||||
}
|
||||
|
||||
public static void
|
||||
main(String[] argv)
|
||||
{
|
||||
System.out.println("Starting up server socket");
|
||||
|
||||
try {
|
||||
ServerSocketTest ss = new ServerSocketTest(9999);
|
||||
|
||||
System.out.println("Created server socket bound to port " +
|
||||
ss.getLocalPort() + " on local address " +
|
||||
ss.getInetAddress());
|
||||
|
||||
SubSocket s = new SubSocket();
|
||||
ss.implAccept(s);
|
||||
// Socket s = ss.accept();
|
||||
|
||||
System.out.println("Got a connection from " + s.getInetAddress() +
|
||||
" on port " + s.getPort());
|
||||
|
||||
BufferedReader br = new BufferedReader(new
|
||||
InputStreamReader(s.getInputStream()));
|
||||
|
||||
for (String str = br.readLine(); ; str = br.readLine())
|
||||
{
|
||||
if (str == null)
|
||||
break;
|
||||
System.out.println(str);
|
||||
}
|
||||
s.close();
|
||||
ss.close();
|
||||
System.out.println("PASSED: server socket test");
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("FAILED: server socket test: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
/* Quick and dirty Socket subclass */
|
||||
|
||||
public class SubSocket extends java.net.Socket
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/* A class to test my java.net.InetAddress implementation */
|
||||
|
||||
import java.net.*;
|
||||
|
||||
public class TestNameLookups extends Object
|
||||
{
|
||||
public static void
|
||||
main(String[] argv) throws UnknownHostException
|
||||
{
|
||||
InetAddress addr;
|
||||
|
||||
System.out.println("Started address lookup test");
|
||||
|
||||
/* Test local host */
|
||||
try
|
||||
{
|
||||
addr = InetAddress.getLocalHost();
|
||||
|
||||
System.out.println("The local hostname is " + addr.getHostName() +
|
||||
" with an IP address of " + addr.getHostAddress());
|
||||
}
|
||||
catch(UnknownHostException e)
|
||||
{
|
||||
System.out.println("WARNING: Can't resolve local hostname");
|
||||
}
|
||||
|
||||
/* Test simple lookup by IP */
|
||||
addr = InetAddress.getByName("18.159.0.42");
|
||||
|
||||
System.out.println("Looked up IP addres 18.159.0.42 and got back a " +
|
||||
"hostname of " + addr.getHostName());
|
||||
|
||||
/* Test failed reverse lookup of IP */
|
||||
addr = InetAddress.getByName("194.72.246.154");
|
||||
|
||||
System.out.println("Looked up IP addres 194.72.246.154 and got back a " +
|
||||
"hostname of " + addr.getHostName());
|
||||
|
||||
/* Test mangled/invalid IP's */
|
||||
try { addr = InetAddress.getByName("122.24.1."); }
|
||||
catch (UnknownHostException e) {
|
||||
System.out.println("Passed bad IP test 1");
|
||||
}
|
||||
|
||||
try { addr = InetAddress.getByName("122.24.52"); }
|
||||
catch (UnknownHostException e) {
|
||||
System.out.println("Passed bad IP test 2");
|
||||
}
|
||||
|
||||
try { addr = InetAddress.getByName("122.256.52.1"); }
|
||||
catch (UnknownHostException e) {
|
||||
System.out.println("Passed bad IP test 3");
|
||||
}
|
||||
|
||||
/* Test simple lookup by name with external info */
|
||||
addr = InetAddress.getByName("www.starnews.com");
|
||||
System.out.println("Looked up host www.starnews.com and got back an " +
|
||||
"IP address of " + addr.getHostAddress());
|
||||
byte[] octets = addr.getAddress();
|
||||
System.out.println("Raw Address Bytes: octet1=" + (int)octets[0] +
|
||||
" octets2=" + (int)octets[1] + " octet3=" + (int)octets[2] +
|
||||
" octets4=" + (int)octets[3]);
|
||||
System.out.println("toString() returned: " + addr.toString());
|
||||
System.out.println("isMulticastAddress returned: "
|
||||
+ addr.isMulticastAddress());
|
||||
|
||||
/* Test complex lookup */
|
||||
System.out.println("Looking up all addresses for indiana.edu ...");
|
||||
InetAddress[] list = InetAddress.getAllByName("indiana.edu");
|
||||
for (int i = 0; i < list.length; i++)
|
||||
{
|
||||
addr = list[i];
|
||||
|
||||
System.out.println(" Hostname: " + addr.getHostName() +
|
||||
" IP Address: " + addr.getHostAddress());
|
||||
}
|
||||
|
||||
/* Test equality */
|
||||
InetAddress addr1 = InetAddress.getByName("www.urbanophile.com");
|
||||
InetAddress addr2 = InetAddress.getByName("www.urbanophile.com");
|
||||
|
||||
if (addr1.equals(addr2) && addr2.equals(addr1))
|
||||
System.out.println("Passed equality test #1");
|
||||
else
|
||||
System.out.println("Failed equality test #1");
|
||||
|
||||
addr1 = InetAddress.getByName("www.ac.com");
|
||||
addr2 = InetAddress.getByName("www.hungry.com");
|
||||
|
||||
if (!addr1.equals(addr2) && !addr2.equals(addr1))
|
||||
System.out.println("Passed equality test #2");
|
||||
else
|
||||
System.out.println("Failed equality test #2");
|
||||
|
||||
/* Quick test to see if it looks like we're caching things */
|
||||
addr1 = InetAddress.getByName("www.urbanophile.com");
|
||||
System.out.println("Got " + addr1.getHostName() + " " + addr1.getHostAddress());
|
||||
addr2 = InetAddress.getByName("www.hungry.com");
|
||||
System.out.println("Got " + addr2.getHostName() + " " + addr2.getHostAddress());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/* Test URL's */
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
public class URLTest
|
||||
{
|
||||
|
||||
public static void
|
||||
main(String argv[])
|
||||
{
|
||||
System.out.println("Starting URL tests");
|
||||
|
||||
/* Simple URL test */
|
||||
|
||||
System.out.println("Test 1: Simple URL test");
|
||||
|
||||
try
|
||||
{
|
||||
URL url = new URL("http", "www.fsf.org", 80, "/");
|
||||
|
||||
if (!url.getProtocol().equals("http") ||
|
||||
!url.getHost().equals("www.fsf.org") ||
|
||||
url.getPort() != 80 ||
|
||||
!url.getFile().equals("/"))
|
||||
System.out.println("FAILED: Simple URL test");
|
||||
|
||||
System.out.println("URL is: " + url.toString());
|
||||
|
||||
URLConnection uc = url.openConnection();
|
||||
|
||||
if (uc instanceof HttpURLConnection)
|
||||
System.out.println("Got the expected connection type");
|
||||
|
||||
HttpURLConnection hc = (HttpURLConnection)uc;
|
||||
|
||||
hc.connect();
|
||||
|
||||
System.out.flush();
|
||||
System.out.println("Dumping response headers");
|
||||
for (int i = 0; ; i++)
|
||||
{
|
||||
String key = hc.getHeaderFieldKey(i);
|
||||
if (key == null)
|
||||
break;
|
||||
|
||||
System.out.println(key + ": " + hc.getHeaderField(i));
|
||||
}
|
||||
|
||||
System.out.flush();
|
||||
System.out.println("Dumping contents");
|
||||
|
||||
BufferedReader br = new BufferedReader(new
|
||||
InputStreamReader(hc.getInputStream()));
|
||||
|
||||
for (String str = br.readLine(); str != null; str = br.readLine())
|
||||
{
|
||||
System.out.println(str);
|
||||
}
|
||||
System.out.flush();
|
||||
|
||||
hc.disconnect();
|
||||
|
||||
System.out.println("Content Type: " + hc.getContentType());
|
||||
System.out.println("Content Encoding: " + hc.getContentEncoding());
|
||||
System.out.println("Content Length: " + hc.getContentLength());
|
||||
System.out.println("Date: " + hc.getDate());
|
||||
System.out.println("Expiration: " + hc.getExpiration());
|
||||
System.out.println("Last Modified: " + hc.getLastModified());
|
||||
|
||||
System.out.println("PASSED: Simple URL test");
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
System.out.println("FAILED: Simple URL test: " + e);
|
||||
}
|
||||
|
||||
// Parsing test
|
||||
System.out.println("Test 2: URL parsing test");
|
||||
try
|
||||
{
|
||||
URL url = new URL("http://www.urbanophile.com/arenn/trans/trans.html#mis");
|
||||
if (!url.toString().equals(
|
||||
"http://www.urbanophile.com/arenn/trans/trans.html#mis"))
|
||||
System.out.println("FAILED: Parse URL test: " + url.toString());
|
||||
else {
|
||||
System.out.println("Parsed ok: " + url.toString());
|
||||
url = new URL("http://www.foo.com:8080/#");
|
||||
if (!url.toString().equals("http://www.foo.com:8080/#"))
|
||||
System.out.println("FAILED: Parse URL test: " + url.toString());
|
||||
else {
|
||||
System.out.println("Parsed ok: " + url.toString());
|
||||
url = new URL("http://www.bar.com/test:file/");
|
||||
if (!url.toString().equals("http://www.bar.com/test:file/"))
|
||||
System.out.println("FAILED: Parse URL test: " + url.toString());
|
||||
else {
|
||||
System.out.println("Parsed ok: " + url.toString());
|
||||
url = new URL("http://www.gnu.org");
|
||||
if (!url.toString().equals("http://www.gnu.org/"))
|
||||
System.out.println("FAILED: Parse URL test: " + url.toString());
|
||||
else {
|
||||
System.out.println("Parsed ok: " + url.toString());
|
||||
url = new URL("HTTP://www.fsf.org/");
|
||||
if (!url.toString().equals("http://www.fsf.org/"))
|
||||
System.out.println("FAILED: Parse URL test: " + url.toString());
|
||||
else {
|
||||
System.out.println("Parsed ok: " + url.toString());
|
||||
System.out.println("PASSED: URL parse test");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("FAILED: URL parsing test: " + e);
|
||||
}
|
||||
|
||||
// getContent test
|
||||
System.out.println("Test 3: getContent test");
|
||||
try
|
||||
{
|
||||
URL url = new URL("http://localhost/~arenn/services.txt");
|
||||
|
||||
Object obj = url.getContent();
|
||||
System.out.println("Object type is: " + obj.getClass().getName());
|
||||
|
||||
if (obj instanceof InputStream)
|
||||
{
|
||||
System.out.println("Got InputStream, so dumping contents");
|
||||
BufferedReader br = new BufferedReader(new
|
||||
InputStreamReader((InputStream)obj));
|
||||
|
||||
for (String str = br.readLine(); str != null; str = br.readLine())
|
||||
System.out.println(str);
|
||||
|
||||
br.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("FAILED: Object is not an InputStream");
|
||||
}
|
||||
|
||||
System.out.println("PASSED: getContent test");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("FAILED: getContent test: " + e);
|
||||
}
|
||||
|
||||
System.out.println("URL test complete");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Running java.net tests"
|
||||
echo "I assume japhar is in /usr/local/japhar"
|
||||
echo "Please make sure background processes don't block on a tty write"
|
||||
echo "Please do an 'ifconfig multicast' and 'ifconfig allmulti' on your"
|
||||
echo "network interfaces"
|
||||
|
||||
export CLASSPATH=.:/usr/local/japhar/share
|
||||
export PATH=$PATH:/usr/local/japhar/bin
|
||||
|
||||
echo "Executing name lookup test ..."
|
||||
japhar TestNameLookups
|
||||
|
||||
echo "Executing stream socket tests ..."
|
||||
japhar ServerSocketTest &
|
||||
japhar ClientSocket
|
||||
|
||||
echo "Executing datagram socket tests ..."
|
||||
japhar ServerDatagram &
|
||||
japhar ClientDatagram
|
||||
|
||||
echo "Executing multicast socket tests ..."
|
||||
japhar MulticastServer &
|
||||
japhar MulticastClient
|
||||
|
||||
echo "Executing URL tests ..."
|
||||
japhar URLTest
|
||||
|
||||
echo "java.net Testing complete."
|
||||
exit 0
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Makefile.in
|
||||
@@ -0,0 +1,271 @@
|
||||
//////
|
||||
// There should be a copyright thing here but I'm in too much of a hurry to add
|
||||
// one right now. I don't care much what the copyright is though so if someone
|
||||
// wants to put the appropriate one here, go right ahead (I think GPL probably
|
||||
// unless that causes a problem with running on proprietory JVMs or testing
|
||||
// proprietory class libraries or anything.
|
||||
//////
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Test of most of the methods in the Arrays class. The class prints out a
|
||||
* single pass/fail message, and enumerates all failures. The message is in the
|
||||
* PASS: or FAIL: format that dejagnu uses, but other than that I don't know
|
||||
* enough to make it a "proper" testsuite.
|
||||
*/
|
||||
public class ArraysTest {
|
||||
|
||||
static int passed = 0;
|
||||
static int failed = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
testBool();
|
||||
testByte();
|
||||
testChar();
|
||||
testShort();
|
||||
testInt();
|
||||
testLong();
|
||||
testFloat();
|
||||
testDouble();
|
||||
testObject();
|
||||
if (failed != 0) {
|
||||
System.out.println(" (" + failed + " fails and " + passed + " passes).");
|
||||
} else {
|
||||
System.out.println("PASSED: [Arrays] All " + passed + " tests.");
|
||||
}
|
||||
}
|
||||
|
||||
static void testBool() {
|
||||
boolean[] a1 = new boolean[] {true, false, false, true, true, false, true};
|
||||
boolean[] a2 = new boolean[] {false, false, false, true, true, true, true};
|
||||
boolean[] a3 = new boolean[] {true, false, false, true, true, false, true};
|
||||
passfail("boolean equals", !Arrays.equals(a1, a2) && Arrays.equals(a1, a3));
|
||||
Arrays.fill(a1, false);
|
||||
boolean filled = true;
|
||||
for (int i = 0; filled && i < a1.length; i++) {
|
||||
filled = a1[i] == false;
|
||||
}
|
||||
passfail("boolean fill", filled);
|
||||
}
|
||||
|
||||
static void testByte() {
|
||||
byte[] a1 = new byte[] {3, -2, 0, 1, 4, 0, -5};
|
||||
byte[] a2 = new byte[] {-5, -2, 0, 0, 1, 3, 4};
|
||||
boolean firstEq = Arrays.equals(a1, a2);
|
||||
Arrays.sort(a1);
|
||||
boolean sorted = true;
|
||||
for (int i = 0; sorted && i < a1.length - 1; i++) {
|
||||
sorted = !(a1[i] > a1[i+1]); // the odd way of writing <= is so that we
|
||||
// aren't tooo mean to NaNs
|
||||
}
|
||||
passfail("byte sort", sorted);
|
||||
passfail("byte search", Arrays.binarySearch(a2, (byte)1) == 4 &&
|
||||
Arrays.binarySearch(a2, (byte)-1) == -3);
|
||||
passfail("byte equals", !firstEq && Arrays.equals(a1, a2));
|
||||
Arrays.fill(a1, (byte)6);
|
||||
boolean filled = true;
|
||||
for (int i = 0; filled && i < a1.length; i++) {
|
||||
filled = a1[i] == (byte)6;
|
||||
}
|
||||
passfail("byte fill", filled);
|
||||
}
|
||||
|
||||
static void testChar() {
|
||||
char[] a1 = new char[] {'i', 'd', 'f', 'g', 'j', 'f', 'a'};
|
||||
char[] a2 = new char[] {'a', 'd', 'f', 'f', 'g', 'i', 'j'};
|
||||
boolean firstEq = Arrays.equals(a1, a2);
|
||||
Arrays.sort(a1);
|
||||
boolean sorted = true;
|
||||
for (int i = 0; sorted && i < a1.length - 1; i++) {
|
||||
sorted = !(a1[i] > a1[i+1]); // the odd way of writing <= is so that we
|
||||
// aren't tooo mean to NaNs
|
||||
}
|
||||
passfail("char sort", sorted);
|
||||
passfail("char search", Arrays.binarySearch(a2, 'i') == 5 &&
|
||||
Arrays.binarySearch(a2, 'e') == -3);
|
||||
passfail("char equals", !firstEq && Arrays.equals(a1, a2));
|
||||
Arrays.fill(a1, 'Q');
|
||||
boolean filled = true;
|
||||
for (int i = 0; filled && i < a1.length; i++) {
|
||||
filled = a1[i] == 'Q';
|
||||
}
|
||||
passfail("char fill", filled);
|
||||
}
|
||||
|
||||
static void testShort() {
|
||||
short[] a1 = new short[] {3, -2, 0, 1, 4, 0, -5};
|
||||
short[] a2 = new short[] {-5, -2, 0, 0, 1, 3, 4};
|
||||
boolean firstEq = Arrays.equals(a1, a2);
|
||||
Arrays.sort(a1);
|
||||
boolean sorted = true;
|
||||
for (int i = 0; sorted && i < a1.length - 1; i++) {
|
||||
sorted = !(a1[i] > a1[i+1]); // the odd way of writing <= is so that we
|
||||
// aren't tooo mean to NaNs
|
||||
}
|
||||
passfail("short sort", sorted);
|
||||
passfail("short search", Arrays.binarySearch(a2, (short)1) == 4 &&
|
||||
Arrays.binarySearch(a2, (short)-1) == -3);
|
||||
passfail("short equals", !firstEq && Arrays.equals(a1, a2));
|
||||
Arrays.fill(a1, (short)6);
|
||||
boolean filled = true;
|
||||
for (int i = 0; filled && i < a1.length; i++) {
|
||||
filled = a1[i] == (short)6;
|
||||
}
|
||||
passfail("short fill", filled);
|
||||
}
|
||||
|
||||
static void testInt() {
|
||||
int[] a1 = new int[] {3, -2, 0, 1, 4, 0, -5};
|
||||
int[] a2 = new int[] {-5, -2, 0, 0, 1, 3, 4};
|
||||
boolean firstEq = Arrays.equals(a1, a2);
|
||||
Arrays.sort(a1);
|
||||
boolean sorted = true;
|
||||
for (int i = 0; sorted && i < a1.length - 1; i++) {
|
||||
sorted = !(a1[i] > a1[i+1]); // the odd way of writing <= is so that we
|
||||
// aren't tooo mean to NaNs
|
||||
}
|
||||
passfail("int sort", sorted);
|
||||
passfail("int search", Arrays.binarySearch(a2, 1) == 4 &&
|
||||
Arrays.binarySearch(a2, -1) == -3);
|
||||
passfail("int equals", !firstEq && Arrays.equals(a1, a2));
|
||||
Arrays.fill(a1, 6);
|
||||
boolean filled = true;
|
||||
for (int i = 0; filled && i < a1.length; i++) {
|
||||
filled = a1[i] == 6;
|
||||
}
|
||||
passfail("int fill", filled);
|
||||
}
|
||||
|
||||
static void testLong() {
|
||||
long[] a1 = new long[] {3, -2, 0, 1, 4, 0, -5};
|
||||
long[] a2 = new long[] {-5, -2, 0, 0, 1, 3, 4};
|
||||
boolean firstEq = Arrays.equals(a1, a2);
|
||||
Arrays.sort(a1);
|
||||
boolean sorted = true;
|
||||
for (int i = 0; sorted && i < a1.length - 1; i++) {
|
||||
sorted = !(a1[i] > a1[i+1]); // the odd way of writing <= is so that we
|
||||
// aren't tooo mean to NaNs
|
||||
}
|
||||
passfail("long sort", sorted);
|
||||
passfail("long search", Arrays.binarySearch(a2, 1L) == 4 &&
|
||||
Arrays.binarySearch(a2, -1L) == -3);
|
||||
passfail("long equals", !firstEq && Arrays.equals(a1, a2));
|
||||
Arrays.fill(a1, 6L);
|
||||
boolean filled = true;
|
||||
for (int i = 0; filled && i < a1.length; i++) {
|
||||
filled = a1[i] == 6L;
|
||||
}
|
||||
passfail("long fill", filled);
|
||||
}
|
||||
|
||||
static void testFloat() {
|
||||
float[] a1 = new float[] {-4.0f, 75.3f, Float.POSITIVE_INFINITY, -0.0f,
|
||||
-3324.342f, 0.0f, 3.14f, 2.5f, 1.0f, 1.0f};
|
||||
float[] a2 = new float[] {-3324.342f, -4.0f, -0.0f, 0.0f, 1.0f, 1.0f, 2.5f,
|
||||
3.14f, 75.3f, Float.POSITIVE_INFINITY};
|
||||
boolean firstEq = Arrays.equals(a1, a2);
|
||||
Arrays.sort(a1);
|
||||
boolean sorted = true;
|
||||
for (int i = 0; sorted && i < a1.length - 1; i++) {
|
||||
sorted = !(a1[i] > a1[i+1]); // the odd way of writing <= is so that we
|
||||
// aren't tooo mean to NaNs
|
||||
}
|
||||
passfail("float sort", sorted);
|
||||
passfail("float search", Arrays.binarySearch(a2, 3.14f) == 7 &&
|
||||
Arrays.binarySearch(a2, -1.0f) == -3);
|
||||
passfail("float equals", !firstEq && Arrays.equals(a1, a2));
|
||||
Arrays.fill(a1, 27.0f);
|
||||
boolean filled = true;
|
||||
for (int i = 0; filled && i < a1.length; i++) {
|
||||
filled = a1[i] == 27.0f;
|
||||
}
|
||||
passfail("float fill", filled);
|
||||
}
|
||||
|
||||
static void testDouble() {
|
||||
double[] a1 = new double[] {-4.0d, 75.3d, Double.POSITIVE_INFINITY, -0.0d,
|
||||
-3324.342d, 0.0d, 3.14d, 2.5d, 1.0d, 1.0d};
|
||||
double[] a2 = new double[] {-3324.342d, -4.0d, -0.0d, 0.0d, 1.0d, 1.0d,
|
||||
2.5d, 3.14d, 75.3d, Double.POSITIVE_INFINITY};
|
||||
boolean firstEq = Arrays.equals(a1, a2);
|
||||
Arrays.sort(a1);
|
||||
boolean sorted = true;
|
||||
for (int i = 0; sorted && i < a1.length - 1; i++) {
|
||||
sorted = !(a1[i] > a1[i+1]); // the odd way of writing <= is so that we
|
||||
// aren't tooo mean to NaNs
|
||||
}
|
||||
passfail("double sort", sorted);
|
||||
passfail("double search", Arrays.binarySearch(a2, 3.14d) == 7 &&
|
||||
Arrays.binarySearch(a2, -1.0d) == -3);
|
||||
passfail("double equals", !firstEq && Arrays.equals(a1, a2));
|
||||
Arrays.fill(a1, 27.0d);
|
||||
boolean filled = true;
|
||||
for (int i = 0; filled && i < a1.length; i++) {
|
||||
filled = a1[i] == 27.0d;
|
||||
}
|
||||
passfail("double fill", filled);
|
||||
}
|
||||
|
||||
static void testObject() {
|
||||
String[] a1 = new String[] {"this", "is", "a", "string", "test", "which",
|
||||
"will", "hopefully", "demonstrate", "that",
|
||||
"sorting", "works"};
|
||||
String[] a2 = new String[] {"a", "demonstrate", "hopefully", "is",
|
||||
"sorting", "string", "test", "that", "this",
|
||||
"which", "will", "works"};
|
||||
String[] a3 = new String[] {"this", "is", "a", "reverse", "string", "test",
|
||||
"which", "will", "hopefully", "demonstrate",
|
||||
"that", "sorting", "works", "with",
|
||||
"comparators"};
|
||||
String[] a4 = new String[] {"works", "with", "will", "which", "this",
|
||||
"that", "test", "string", "sorting", "reverse",
|
||||
"is", "hopefully", "demonstrate", "comparators",
|
||||
"a"};
|
||||
final String list = "[works, with, will, which, this, that, test, string," +
|
||||
" sorting, reverse, is, hopefully, demonstrate," +
|
||||
" comparators, a]";
|
||||
boolean firstEq = Arrays.equals(a1, a2);
|
||||
Arrays.sort(a1);
|
||||
boolean sorted = true;
|
||||
for (int i = 0; sorted && i < a1.length - 1; i++) {
|
||||
sorted = a1[i].compareTo(a1[i+1]) <= 0;
|
||||
}
|
||||
passfail("object sort", sorted);
|
||||
passfail("object search", Arrays.binarySearch(a2, "hopefully") == 2 &&
|
||||
Arrays.binarySearch(a2, "strange") == -6);
|
||||
passfail("object equals", !firstEq && Arrays.equals(a1, a2));
|
||||
Arrays.fill(a1, "blah");
|
||||
boolean filled = true;
|
||||
for (int i = 0; filled && i < a1.length; i++) {
|
||||
filled = a1[i].equals("blah");
|
||||
}
|
||||
passfail("object fill", filled);
|
||||
Comparator c = new ReverseOrder();
|
||||
Arrays.sort(a3, c);
|
||||
passfail("comparator sort", Arrays.equals(a3, a4));
|
||||
passfail("comparator search", Arrays.binarySearch(a4, "sorting", c) == 8 &&
|
||||
Arrays.binarySearch(a4, "nice", c) == -11);
|
||||
|
||||
// toList doesn't exist -gcb
|
||||
// passfail("toList toString", Arrays.toList(a4).toString().equals(list));
|
||||
}
|
||||
|
||||
static void passfail(String desc, boolean didpass) {
|
||||
if (didpass) {
|
||||
passed++;
|
||||
} else {
|
||||
if (failed++ != 0) {
|
||||
System.out.print(", " + desc);
|
||||
} else {
|
||||
System.out.print("FAILED: [Arrays] " + desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ReverseOrder implements Comparator {
|
||||
public int compare(Object a, Object b) {
|
||||
return -((Comparable)a).compareTo(b);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
## Input file for automake to generate the Makefile.in used by configure
|
||||
|
||||
check_JAVA = ArraysTest.java
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
public class JNILinkTest {
|
||||
static {
|
||||
System.loadLibrary("jnilinktest");
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
MethodTester m = new MethodTester();
|
||||
Data1 d1 = new Data1();
|
||||
Data2 d2 = new Data2();
|
||||
int NUM_TESTS=4;
|
||||
for(int i=0;i<NUM_TESTS;i++) {
|
||||
try {
|
||||
if(m.test1(d1,d2))
|
||||
System.out.println("SUCCEED: test1");
|
||||
else
|
||||
System.out.println("FAIL: test1");
|
||||
} catch(Exception E) {
|
||||
System.out.println("FAIL: test1 (exception)");
|
||||
}
|
||||
}
|
||||
for(int i=0;i<NUM_TESTS;i++) {
|
||||
try {
|
||||
if(m.test2(d1,d2))
|
||||
System.out.println("SUCCEED: test2");
|
||||
else
|
||||
System.out.println("FAIL: test2");
|
||||
} catch(Exception E) {
|
||||
System.out.println("FAIL: test2");
|
||||
}
|
||||
}
|
||||
for(int i=0;i<NUM_TESTS;i++) {
|
||||
try {
|
||||
if(m.test3(d1,d2))
|
||||
System.out.println("SUCCEED: test3");
|
||||
else
|
||||
System.out.println("FAIL: test3");
|
||||
} catch(Exception E) {
|
||||
System.out.println("FAIL: test3");
|
||||
}
|
||||
}
|
||||
for(int i=0;i<NUM_TESTS;i++) {
|
||||
try {
|
||||
if(m.test4(d1,d2))
|
||||
System.out.println("SUCCEED: test4");
|
||||
else
|
||||
System.out.println("FAIL: test4");
|
||||
} catch(Exception E) {
|
||||
System.out.println("FAIL: test4");
|
||||
}
|
||||
}
|
||||
for(int i=0;i<NUM_TESTS;i++) {
|
||||
try {
|
||||
if(m.test5(d1,d2))
|
||||
System.out.println("SUCCEED: test5");
|
||||
else
|
||||
System.out.println("FAIL: test5");
|
||||
} catch(Exception E) {
|
||||
System.out.println("FAIL: test5");
|
||||
}
|
||||
}
|
||||
for(int i=0;i<NUM_TESTS;i++) {
|
||||
try {
|
||||
if(m.test6(d1,d2))
|
||||
System.out.println("SUCCEED: test6");
|
||||
else
|
||||
System.out.println("FAIL: test6");
|
||||
} catch(Exception E) {
|
||||
System.out.println("FAIL: test5");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MethodTester {
|
||||
// class test
|
||||
native boolean test1(Data1 d1, Data2 d2);
|
||||
// field test
|
||||
native boolean test2(Data1 d1, Data2 d2);
|
||||
// static field test
|
||||
native boolean test3(Data1 d1, Data2 d2);
|
||||
// method test
|
||||
native boolean test4(Data1 d1, Data2 d2);
|
||||
// static method test
|
||||
native boolean test5(Data1 d1, Data2 d2);
|
||||
// final method test
|
||||
native boolean test6(Data1 d1, Data2 d2);
|
||||
}
|
||||
|
||||
class Data1 {
|
||||
static boolean staticVar = true;
|
||||
private boolean instanceVar = true;
|
||||
static boolean staticMethod() { return true; }
|
||||
boolean instanceMethod() { return true; }
|
||||
boolean finalMethod() { return true; }
|
||||
}
|
||||
|
||||
class Data2 extends Data1 {
|
||||
static boolean staticVar = false;
|
||||
private boolean instanceVar = false;
|
||||
static boolean staticMethod() { return false; }
|
||||
boolean instanceMethod() { return false; }
|
||||
boolean finalMethod() { return false; }
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
#include "MethodTester.h"
|
||||
#include <jnilink.h>
|
||||
#include <jcl.h>
|
||||
|
||||
static linkPtr t1_1=NULL;
|
||||
static linkPtr t1_2=NULL;
|
||||
static linkPtr t2=NULL;
|
||||
static linkPtr t3=NULL;
|
||||
static linkPtr t4=NULL;
|
||||
static linkPtr t5=NULL;
|
||||
static linkPtr t6=NULL;
|
||||
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test1
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test1
|
||||
(JNIEnv * env, jobject thisObj, jobject d1, jobject d2) {
|
||||
if(LINK_LinkClass(env,&t1_1,"Data1") == NULL || LINK_LinkClass(env,&t1_2,"Data2") == NULL)
|
||||
return JNI_FALSE;
|
||||
if(!(*env)->IsAssignableFrom(env, LINK_ResolveClass(env,t1_1), LINK_ResolveClass(env,t1_2))
|
||||
&& (*env)->IsAssignableFrom(env, LINK_ResolveClass(env,t1_2), LINK_ResolveClass(env,t1_1))) {
|
||||
return JNI_TRUE;
|
||||
} else {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test2
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test2
|
||||
(JNIEnv * env, jobject thisObj, jobject d1, jobject d2) {
|
||||
jclass c1 = (*env)->GetObjectClass(env,d1);
|
||||
jclass c2 = (*env)->GetObjectClass(env,d2);
|
||||
if(LINK_LinkField(env,&t2,c1,"instanceVar","Z") == NULL)
|
||||
return JNI_FALSE;
|
||||
return (*env)->GetBooleanField(env,d1,LINK_ResolveField(env,t2))
|
||||
&& (*env)->GetBooleanField(env,d2,LINK_ResolveField(env,t2));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test3
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test3
|
||||
(JNIEnv * env, jobject thisObj, jobject d1, jobject d2) {
|
||||
jclass c1 = (*env)->GetObjectClass(env,d1);
|
||||
jclass c2 = (*env)->GetObjectClass(env,d2);
|
||||
if(LINK_LinkStaticField(env,&t3,c1,"staticVar","Z") == NULL)
|
||||
return JNI_FALSE;
|
||||
return (*env)->GetStaticBooleanField(env,d1,LINK_ResolveStaticField(env,t3))
|
||||
&& (*env)->GetStaticBooleanField(env,d2,LINK_ResolveStaticField(env,t3));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test4
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test4
|
||||
(JNIEnv * env, jobject thisObj, jobject d1, jobject d2) {
|
||||
jclass c1 = (*env)->GetObjectClass(env,d1);
|
||||
jclass c2 = (*env)->GetObjectClass(env,d2);
|
||||
jmethodID m1;
|
||||
jmethodID m2;
|
||||
if(LINK_LinkMethod(env,&t4,c1,"instanceMethod","()Z") == NULL)
|
||||
return JNI_FALSE;
|
||||
m1 = LINK_ResolveMethod(env,t4);
|
||||
m2 = LINK_ResolveMethod(env,t4);
|
||||
return (*env)->CallBooleanMethod(env,d1,m1)
|
||||
&& !(*env)->CallBooleanMethod(env,d2,m2);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test5
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test5
|
||||
(JNIEnv * env, jobject thisObj, jobject d1, jobject d2) {
|
||||
jclass c1 = (*env)->GetObjectClass(env,d1);
|
||||
jclass c2 = (*env)->GetObjectClass(env,d2);
|
||||
if(LINK_LinkStaticMethod(env,&t5,c1,"staticMethod","()Z") == NULL)
|
||||
return JNI_FALSE;
|
||||
return (*env)->CallStaticBooleanMethod(env,c1,LINK_ResolveStaticMethod(env,t5))
|
||||
&& (*env)->CallStaticBooleanMethod(env,c2,LINK_ResolveStaticMethod(env,t5));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test6
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test6
|
||||
(JNIEnv * env, jobject thisObj, jobject d1, jobject d2) {
|
||||
jclass c1 = (*env)->GetObjectClass(env,d1);
|
||||
jclass c2 = (*env)->GetObjectClass(env,d2);
|
||||
if(LINK_LinkMethod(env,&t6,c1,"finalMethod","()Z") == NULL)
|
||||
return JNI_FALSE;
|
||||
return (*env)->CallBooleanMethod(env,d1,LINK_ResolveMethod(env,t6))
|
||||
&& !(*env)->CallBooleanMethod(env,d2,LINK_ResolveMethod(env,t6));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class MethodTester */
|
||||
|
||||
#ifndef _Included_MethodTester
|
||||
#define _Included_MethodTester
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test1
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test1
|
||||
(JNIEnv *, jobject, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test2
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test2
|
||||
(JNIEnv *, jobject, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test3
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test3
|
||||
(JNIEnv *, jobject, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test4
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test4
|
||||
(JNIEnv *, jobject, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test5
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test5
|
||||
(JNIEnv *, jobject, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: MethodTester
|
||||
* Method: test6
|
||||
* Signature: (LData1;LData2;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_MethodTester_test6
|
||||
(JNIEnv *, jobject, jobject, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,162 @@
|
||||
#include "PrimlibInterface.h"
|
||||
#include <primlib.h>
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapBoolean
|
||||
* Signature: (Ljava/lang/Object;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_PrimlibInterface_unwrapBoolean
|
||||
(JNIEnv * env, jclass thisClass, jobject o) {
|
||||
return PRIMLIB_UnwrapBoolean(env, o);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapByte
|
||||
* Signature: (Ljava/lang/Object;)B
|
||||
*/
|
||||
JNIEXPORT jbyte JNICALL Java_PrimlibInterface_unwrapByte
|
||||
(JNIEnv * env, jclass thisClass, jobject o) {
|
||||
return PRIMLIB_UnwrapByte(env, o);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapShort
|
||||
* Signature: (Ljava/lang/Object;)S
|
||||
*/
|
||||
JNIEXPORT jshort JNICALL Java_PrimlibInterface_unwrapShort
|
||||
(JNIEnv * env, jclass thisClass, jobject o) {
|
||||
return PRIMLIB_UnwrapShort(env, o);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapChar
|
||||
* Signature: (Ljava/lang/Object;)C
|
||||
*/
|
||||
JNIEXPORT jchar JNICALL Java_PrimlibInterface_unwrapChar
|
||||
(JNIEnv * env, jclass thisClass, jobject o) {
|
||||
return PRIMLIB_UnwrapChar(env, o);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapInt
|
||||
* Signature: (Ljava/lang/Object;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_PrimlibInterface_unwrapInt
|
||||
(JNIEnv * env, jclass thisClass, jobject o) {
|
||||
return PRIMLIB_UnwrapInt(env, o);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapLong
|
||||
* Signature: (Ljava/lang/Object;)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_PrimlibInterface_unwrapLong
|
||||
(JNIEnv * env, jclass thisClass, jobject o) {
|
||||
return PRIMLIB_UnwrapLong(env, o);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapFloat
|
||||
* Signature: (Ljava/lang/Object;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_PrimlibInterface_unwrapFloat
|
||||
(JNIEnv * env, jclass thisClass, jobject o) {
|
||||
return PRIMLIB_UnwrapFloat(env, o);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapDouble
|
||||
* Signature: (Ljava/lang/Object;)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_PrimlibInterface_unwrapDouble
|
||||
(JNIEnv * env, jclass thisClass, jobject o) {
|
||||
return PRIMLIB_UnwrapDouble(env, o);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapBoolean
|
||||
* Signature: (Z)Ljava/lang/Boolean;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapBoolean
|
||||
(JNIEnv * env, jclass thisClass, jboolean val) {
|
||||
return PRIMLIB_WrapBoolean(env, val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapByte
|
||||
* Signature: (B)Ljava/lang/Byte;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapByte
|
||||
(JNIEnv * env, jclass thisClass, jbyte val) {
|
||||
return PRIMLIB_WrapByte(env, val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapShort
|
||||
* Signature: (S)Ljava/lang/Short;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapShort
|
||||
(JNIEnv * env, jclass thisClass, jshort val) {
|
||||
return PRIMLIB_WrapShort(env, val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapChar
|
||||
* Signature: (C)Ljava/lang/Character;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapChar
|
||||
(JNIEnv * env, jclass thisClass, jchar val) {
|
||||
return PRIMLIB_WrapChar(env, val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapInt
|
||||
* Signature: (I)Ljava/lang/Integer;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapInt
|
||||
(JNIEnv * env, jclass thisClass, jint val) {
|
||||
return PRIMLIB_WrapInt(env, val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapLong
|
||||
* Signature: (J)Ljava/lang/Long;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapLong
|
||||
(JNIEnv * env, jclass thisClass, jlong val) {
|
||||
return PRIMLIB_WrapLong(env, val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapFloat
|
||||
* Signature: (F)Ljava/lang/Float;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapFloat
|
||||
(JNIEnv * env, jclass thisClass, jfloat val) {
|
||||
return PRIMLIB_WrapFloat(env, val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapDouble
|
||||
* Signature: (D)Ljava/lang/Double;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapDouble
|
||||
(JNIEnv * env, jclass thisClass, jdouble val) {
|
||||
return PRIMLIB_WrapDouble(env, val);
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class PrimlibInterface */
|
||||
|
||||
#ifndef _Included_PrimlibInterface
|
||||
#define _Included_PrimlibInterface
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapBoolean
|
||||
* Signature: (Ljava/lang/Object;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_PrimlibInterface_unwrapBoolean
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapByte
|
||||
* Signature: (Ljava/lang/Object;)B
|
||||
*/
|
||||
JNIEXPORT jbyte JNICALL Java_PrimlibInterface_unwrapByte
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapShort
|
||||
* Signature: (Ljava/lang/Object;)S
|
||||
*/
|
||||
JNIEXPORT jshort JNICALL Java_PrimlibInterface_unwrapShort
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapChar
|
||||
* Signature: (Ljava/lang/Object;)C
|
||||
*/
|
||||
JNIEXPORT jchar JNICALL Java_PrimlibInterface_unwrapChar
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapInt
|
||||
* Signature: (Ljava/lang/Object;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_PrimlibInterface_unwrapInt
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapLong
|
||||
* Signature: (Ljava/lang/Object;)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_PrimlibInterface_unwrapLong
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapFloat
|
||||
* Signature: (Ljava/lang/Object;)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_PrimlibInterface_unwrapFloat
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: unwrapDouble
|
||||
* Signature: (Ljava/lang/Object;)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_PrimlibInterface_unwrapDouble
|
||||
(JNIEnv *, jclass, jobject);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapBoolean
|
||||
* Signature: (Z)Ljava/lang/Boolean;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapBoolean
|
||||
(JNIEnv *, jclass, jboolean);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapByte
|
||||
* Signature: (B)Ljava/lang/Byte;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapByte
|
||||
(JNIEnv *, jclass, jbyte);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapShort
|
||||
* Signature: (S)Ljava/lang/Short;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapShort
|
||||
(JNIEnv *, jclass, jshort);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapChar
|
||||
* Signature: (C)Ljava/lang/Character;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapChar
|
||||
(JNIEnv *, jclass, jchar);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapInt
|
||||
* Signature: (I)Ljava/lang/Integer;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapInt
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapLong
|
||||
* Signature: (J)Ljava/lang/Long;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapLong
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapFloat
|
||||
* Signature: (F)Ljava/lang/Float;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapFloat
|
||||
(JNIEnv *, jclass, jfloat);
|
||||
|
||||
/*
|
||||
* Class: PrimlibInterface
|
||||
* Method: wrapDouble
|
||||
* Signature: (D)Ljava/lang/Double;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_PrimlibInterface_wrapDouble
|
||||
(JNIEnv *, jclass, jdouble);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,88 @@
|
||||
public class PrimlibTest {
|
||||
static {
|
||||
System.loadLibrary("jnilinktest");
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
Object[] o = new Object[8];
|
||||
o[0] = new Boolean(true);
|
||||
o[1] = new Byte((byte)1);
|
||||
o[2] = new Short((short)2);
|
||||
o[3] = new Character((char)3);
|
||||
o[4] = new Integer(4);
|
||||
o[5] = new Long(5L);
|
||||
o[6] = new Float(6F);
|
||||
o[7] = new Double(7D);
|
||||
|
||||
String[] s = {"boolean", "byte", "short", "char", "int", "long", "float", "double"};
|
||||
for(int i=0;i<8;i++) {
|
||||
try {
|
||||
System.out.println(PrimlibInterface.unwrapBoolean(o[i]) ? "CONVERTED: UnwrapBoolean(" + s[i] + ")" : "INCORRECT: UnwrapBoolean(" + s[i] + ")");
|
||||
} catch(Exception E) {
|
||||
System.out.println("EXCEPTION: UnwrapBoolean(" + s[i] + ")");
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(PrimlibInterface.unwrapByte(o[i]) == i ? "CONVERTED: UnwrapByte(" + s[i] + ")" : "INCORRECT: UnwrapByte(" + s[i] + ")");
|
||||
} catch(Exception E) {
|
||||
System.out.println("EXCEPTION: UnwrapByte(" + s[i] + ")");
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(PrimlibInterface.unwrapShort(o[i]) == i ? "CONVERTED: UnwrapShort(" + s[i] + ")" : "INCORRECT: UnwrapShort(" + s[i] + ")");
|
||||
} catch(Exception E) {
|
||||
System.out.println("EXCEPTION: UnwrapShort(" + s[i] + ")");
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(PrimlibInterface.unwrapChar(o[i]) == i ? "CONVERTED: UnwrapChar(" + s[i] + ")" : "INCORRECT: UnwrapChar(" + s[i] + ")");
|
||||
} catch(Exception E) {
|
||||
System.out.println("EXCEPTION: UnwrapChar(" + s[i] + ")");
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(PrimlibInterface.unwrapInt(o[i]) == i ? "CONVERTED: UnwrapInt(" + s[i] + ")" : "INCORRECT: UnwrapInt(" + s[i] + ")");
|
||||
} catch(Exception E) {
|
||||
System.out.println("EXCEPTION: UnwrapInt(" + s[i] + ")");
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(PrimlibInterface.unwrapLong(o[i]) == i ? "CONVERTED: UnwrapLong(" + s[i] + ")" : "INCORRECT: UnwrapLong(" + s[i] + ")");
|
||||
} catch(Exception E) {
|
||||
System.out.println("EXCEPTION: UnwrapLong(" + s[i] + ")");
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(PrimlibInterface.unwrapFloat(o[i]) == i ? "CONVERTED: UnwrapFloat(" + s[i] + ")" : "INCORRECT: UnwrapFloat(" + s[i] + ")");
|
||||
} catch(Exception E) {
|
||||
System.out.println("EXCEPTION: UnwrapFloat(" + s[i] + ")");
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(PrimlibInterface.unwrapDouble(o[i]) == i ? "CONVERTED: UnwrapDouble(" + s[i] + ")" : "INCORRECT: UnwrapDouble(" + s[i] + ")");
|
||||
} catch(Exception E) {
|
||||
System.out.println("EXCEPTION: UnwrapDouble(" + s[i] + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PrimlibInterface {
|
||||
static native boolean unwrapBoolean(Object o);
|
||||
static native byte unwrapByte(Object o);
|
||||
static native short unwrapShort(Object o);
|
||||
static native char unwrapChar(Object o);
|
||||
static native int unwrapInt(Object o);
|
||||
static native long unwrapLong(Object o);
|
||||
static native float unwrapFloat(Object o);
|
||||
static native double unwrapDouble(Object o);
|
||||
|
||||
static native Boolean wrapBoolean(boolean val);
|
||||
static native Byte wrapByte(byte val);
|
||||
static native Short wrapShort(short val);
|
||||
static native Character wrapChar(char val);
|
||||
static native Integer wrapInt(int val);
|
||||
static native Long wrapLong(long val);
|
||||
static native Float wrapFloat(float val);
|
||||
static native Double wrapDouble(double val);
|
||||
}
|
||||
Reference in New Issue
Block a user