Updates relating to the new streamable world order.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1610 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -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.*;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user