diff --git a/tests/src/java/com/threerings/io/FrameTest.java b/tests/src/java/com/threerings/io/FrameTest.java index 25063edf4..20facd2c3 100644 --- a/tests/src/java/com/threerings/io/FrameTest.java +++ b/tests/src/java/com/threerings/io/FrameTest.java @@ -1,7 +1,7 @@ // -// $Id: FrameTest.java,v 1.7 2002/04/15 16:34:36 shaper Exp $ +// $Id: FrameTest.java,v 1.8 2002/07/23 05:56:53 mdb Exp $ -package com.threerings.presents.io; +package com.threerings.io; import java.io.*; diff --git a/tests/src/java/com/threerings/io/StreamableTest.java b/tests/src/java/com/threerings/io/StreamableTest.java new file mode 100644 index 000000000..b36e526cf --- /dev/null +++ b/tests/src/java/com/threerings/io/StreamableTest.java @@ -0,0 +1,128 @@ +// +// $Id: StreamableTest.java,v 1.1 2002/07/23 05:56:53 mdb Exp $ + +package com.threerings.io; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import junit.framework.Test; +import junit.framework.TestCase; + +/** + * Tests the {@link Streamable} class. + */ +public class StreamableTest extends TestCase +{ + public static class Widget extends SimpleStreamableObject + { + public boolean bool1 = true; + public byte byte1 = Byte.MAX_VALUE; + public char char1 = 'a'; + public short short1 = Short.MAX_VALUE; + public int int1 = Integer.MAX_VALUE; + public long long1 = Long.MAX_VALUE; + public float float1 = Float.MAX_VALUE; + public double double1 = Double.MAX_VALUE; + public String string1 = "one"; + + public boolean[] bools = new boolean[] { true, false, true }; + public byte[] bytes = new byte[] { Byte.MAX_VALUE, 2, 3 }; + public short[] shorts = new short[] { Short.MAX_VALUE, 2, 3 }; + public char[] chars = new char[] { 'a', 'b', 'c' }; + public int[] ints = new int[] { Integer.MAX_VALUE, 2, 3 }; + public long[] longs = new long[] { Long.MAX_VALUE, 2, 3 }; + public float[] floats = new float[] { Float.MAX_VALUE, 2, 3 }; + public double[] doubles = new double[] { Double.MAX_VALUE, 2, 3 }; + + public Wocket wocket1 = new Wocket(); + public Wocket[] wockets = new Wocket[] { new Wocket(), new Wocket() }; + public Wicket[] wickets = new Wicket[] { + new Wicket(), new Wicket(), new Wicket() }; + } + + public static class Wocket extends SimpleStreamableObject + { + public byte bizyte = 15; + public short shizort = Short.MAX_VALUE; + public double dizouble = Math.PI; + } + + public static final class Wicket extends SimpleStreamableObject + { + public byte bizyte = 15; + public short shizort = Short.MAX_VALUE; + public double dizouble = Math.PI; + + public void writeObject (ObjectOutputStream out) + throws IOException + { + out.defaultWriteObject(); + out.writeInt(_fizzle); + } + + public void readObject (ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + _fizzle = in.readInt(); + } + + protected void toString (StringBuffer buf) + { + super.toString(buf); + buf.append(", fizzle=").append(_fizzle); + } + + protected int _fizzle = 19; + } + + public StreamableTest () + { + super(StreamableTest.class.getName()); + } + + public void runTest () + { + try { + // create an object graph to be streamed + Widget w = new Widget(); + + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + ObjectOutputStream oout = new ObjectOutputStream(bout); + oout.writeObject(w); + w.string1 = "two"; + oout.writeObject(w); + w.string1 = "three"; + oout.writeObject(w); + + byte[] data = bout.toByteArray(); +// System.out.println(data.length + " bytes were written."); + + ByteArrayInputStream bin = new ByteArrayInputStream(data); + ObjectInputStream oin = new ObjectInputStream(bin); +// System.out.println(oin.readObject()); +// System.out.println(oin.readObject()); +// System.out.println(oin.readObject()); + oin.readObject(); + oin.readObject(); + oin.readObject(); + + } catch (Exception e) { + e.printStackTrace(); + fail("Urk " + e); + } + } + + public static Test suite () + { + return new StreamableTest(); + } + + public static void main (String[] args) + { + StreamableTest test = new StreamableTest(); + test.runTest(); + } +} diff --git a/tests/src/java/com/threerings/io/StreamableUtilTest.java b/tests/src/java/com/threerings/io/StreamableUtilTest.java deleted file mode 100644 index 07da1e843..000000000 --- a/tests/src/java/com/threerings/io/StreamableUtilTest.java +++ /dev/null @@ -1,128 +0,0 @@ -// -// $Id: StreamableUtilTest.java,v 1.2 2002/04/15 16:34:36 shaper Exp $ - -package com.threerings.presents.io; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; - -import java.util.Arrays; - -import junit.framework.Test; -import junit.framework.TestCase; - -import com.samskivert.util.StringUtil; - -/** - * Tests the {@link StreamableUtil} class. - */ -public class StreamableUtilTest extends TestCase -{ - public StreamableUtilTest () - { - super(StreamableUtilTest.class.getName()); - } - - public static class Boink extends SimpleStreamableObject - { - public String foo; - public int bar; - public float baz; - - public Boink () - { - } - - public Boink (String foo, int bar, float baz) - { - this.foo = foo; - this.bar = bar; - this.baz = baz; - } - - public boolean equals (Object other) - { - Boink bo = (Boink)other; - return (bo.foo.equals(foo) && - bo.bar == bar && - bo.baz == baz); - } - } - - public static class Blink extends Boink - { - public int bizz; - - public Blink () - { - } - - public Blink (String foo, int bar, float baz, int bizz ) - { - super(foo, bar, baz); - this.bizz = bizz; - } - - public boolean equals (Object other) - { - Blink bo = (Blink)other; - return (bo.foo.equals(foo) && - bo.bar == bar && - bo.baz == baz && - bo.bizz == bizz); - } - } - - public void runTest () - { - int bcount = 15; - Boink[] boinks = new Boink[bcount]; - for (int i = 0; i < bcount; i++) { - if (i % 2 == 0) { - boinks[i] = new Boink(Integer.toString(i), i, - (float)i + (float)0.5); - } else { - boinks[i] = new Blink(Integer.toString(i), i, - (float)i + (float)0.5, 100-i); - } - } - // System.out.println("boinks: " + StringUtil.toString(boinks)); - - try { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - DataOutputStream dout = new DataOutputStream(bout); - StreamableUtil.writeStreamables(dout, boinks); - dout.flush(); - - byte[] data = bout.toByteArray(); - // System.out.println(bcount + " boinks takes up " + - // data.length + " bytes."); - - ByteArrayInputStream bin = new ByteArrayInputStream(data); - DataInputStream din = new DataInputStream(bin); - Boink[] nboinks = (Boink[])StreamableUtil.readStreamables(din); - - // make sure all went well - assertTrue("boinks == nboinks", Arrays.equals(boinks, nboinks)); - - // System.out.println("nboinks: " + StringUtil.toString(nboinks)); - - } catch (Exception e) { - e.printStackTrace(System.err); - fail("exception: " + e); - } - } - - public static Test suite () - { - return new StreamableUtilTest(); - } - - public static void main (String[] args) - { - StreamableUtilTest test = new StreamableUtilTest(); - test.runTest(); - } -}