Turned into JUnit unit test.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@602 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,37 +1,44 @@
|
|||||||
//
|
//
|
||||||
// $Id: FrameTest.java,v 1.4 2001/11/08 02:07:36 mdb Exp $
|
// $Id: FrameTest.java,v 1.5 2001/11/08 02:21:23 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.presents.io;
|
package com.threerings.presents.io;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public class FrameTest
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import com.samskivert.test.TestUtil;
|
||||||
|
|
||||||
|
public class FrameTest extends TestCase
|
||||||
{
|
{
|
||||||
public static void writeFrames (OutputStream out)
|
public FrameTest ()
|
||||||
|
{
|
||||||
|
super(FrameTest.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeFrames (OutputStream out)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
FramingOutputStream fout = new FramingOutputStream();
|
FramingOutputStream fout = new FramingOutputStream();
|
||||||
DataOutputStream dout = new DataOutputStream(fout);
|
DataOutputStream dout = new DataOutputStream(fout);
|
||||||
|
|
||||||
// create a few frames and write them to the output stream
|
// create a few frames and write them to the output stream
|
||||||
dout.writeUTF("This is a test.");
|
dout.writeUTF(STRING1);
|
||||||
dout.writeUTF("This is only a test.");
|
dout.writeUTF(STRING2);
|
||||||
dout.writeUTF("If this were not a test, there would be " +
|
dout.writeUTF(STRING3);
|
||||||
"meaningful data in this frame and someone " +
|
|
||||||
"would probably be enjoying themselves.");
|
|
||||||
fout.writeFrameAndReset(out);
|
fout.writeFrameAndReset(out);
|
||||||
|
|
||||||
dout.writeUTF("Now is the time for all good men to come to the " +
|
dout.writeUTF(STRING4);
|
||||||
"aid of their country.");
|
dout.writeUTF(STRING5);
|
||||||
dout.writeUTF("Every good boy deserves fudge.");
|
dout.writeUTF(STRING6);
|
||||||
dout.writeUTF("The quick brown fox jumped over the lazy cow.");
|
|
||||||
fout.writeFrameAndReset(out);
|
fout.writeFrameAndReset(out);
|
||||||
|
|
||||||
dout.writeUTF("Third time is the charm.");
|
dout.writeUTF(STRING7);
|
||||||
fout.writeFrameAndReset(out);
|
fout.writeFrameAndReset(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void readFrames (InputStream in)
|
public void readFrames (InputStream in)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
FramedInputStream fin = new FramedInputStream();
|
FramedInputStream fin = new FramedInputStream();
|
||||||
@@ -39,25 +46,25 @@ public class FrameTest
|
|||||||
|
|
||||||
// read the first frame
|
// read the first frame
|
||||||
fin.readFrame(in);
|
fin.readFrame(in);
|
||||||
System.out.println(din.readUTF());
|
assert("string1", STRING1.equals(din.readUTF()));
|
||||||
System.out.println(din.readUTF());
|
assert("string2", STRING2.equals(din.readUTF()));
|
||||||
System.out.println(din.readUTF());
|
assert("string3", STRING3.equals(din.readUTF()));
|
||||||
System.out.println("This should be -1: " + fin.read());
|
assert("hit eof", fin.read() == -1);
|
||||||
|
|
||||||
// read the second frame
|
// read the second frame
|
||||||
fin.readFrame(in);
|
fin.readFrame(in);
|
||||||
System.out.println(din.readUTF());
|
assert("string4", STRING4.equals(din.readUTF()));
|
||||||
System.out.println(din.readUTF());
|
assert("string5", STRING5.equals(din.readUTF()));
|
||||||
System.out.println(din.readUTF());
|
assert("string6", STRING6.equals(din.readUTF()));
|
||||||
System.out.println("This should be -1: " + fin.read());
|
assert("hit eof", fin.read() == -1);
|
||||||
|
|
||||||
// read the third frame
|
// read the third frame
|
||||||
fin.readFrame(in);
|
fin.readFrame(in);
|
||||||
System.out.println(din.readUTF());
|
assert("string7", STRING7.equals(din.readUTF()));
|
||||||
System.out.println("This should be -1: " + fin.read());
|
assert("hit eof", fin.read() == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main (String[] args)
|
public void runTest ()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
@@ -71,4 +78,24 @@ public class FrameTest
|
|||||||
ioe.printStackTrace(System.err);
|
ioe.printStackTrace(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Test suite ()
|
||||||
|
{
|
||||||
|
return new FrameTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final String STRING1 = "This is a test.";
|
||||||
|
protected static final String STRING2 = "This is only a test.";
|
||||||
|
protected static final String STRING3 =
|
||||||
|
"If this were not a test, there would be meaningful data in " +
|
||||||
|
"this frame and someone would probably be enjoying themselves.";
|
||||||
|
|
||||||
|
protected static final String STRING4 =
|
||||||
|
"Now is the time for all good men to come to the aid of " +
|
||||||
|
"their country.";
|
||||||
|
protected static final String STRING5 = "Every good boy deserves fudge.";
|
||||||
|
protected static final String STRING6 =
|
||||||
|
"The quick brown fox jumped over the lazy dog.";
|
||||||
|
|
||||||
|
protected static final String STRING7 = "Third time is the charm.";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user