Add asunit tests for generated streamables
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6198 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings {
|
||||
import asunit.textui.TestRunner;
|
||||
|
||||
[SWF(width='1000', height='800')]
|
||||
public class NaryaRunner extends TestRunner
|
||||
{
|
||||
|
||||
public function NaryaRunner()
|
||||
{
|
||||
start(AllTests, null, TestRunner.SHOW_TRACE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
import asunit.framework.TestSuite;
|
||||
import com.threerings.io.StreamableTest;
|
||||
|
||||
class AllTests extends TestSuite
|
||||
{
|
||||
public function AllTests()
|
||||
{
|
||||
addTest(new StreamableTest());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
// GENERATED PREAMBLE START
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
package com.threerings.io {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.SimpleStreamableObject;
|
||||
import com.threerings.util.Long;
|
||||
import com.threerings.io.TypedArray;
|
||||
import flash.utils.ByteArray;
|
||||
// GENERATED PREAMBLE END
|
||||
|
||||
import com.threerings.util.Util;
|
||||
|
||||
// GENERATED CLASSDECL START
|
||||
public class ASStreamableSubset extends SimpleStreamableObject
|
||||
{
|
||||
public function ASStreamableSubset ()
|
||||
{}
|
||||
// GENERATED CLASSDECL END
|
||||
|
||||
public static function createWithJavaDefaults () :ASStreamableSubset
|
||||
{
|
||||
var sub :ASStreamableSubset = new ASStreamableSubset();
|
||||
sub.fillWithJavaDefaults();
|
||||
return sub;
|
||||
}
|
||||
|
||||
public function fillWithJavaDefaults () :void
|
||||
{
|
||||
bool1 = true;
|
||||
short2 = 2;
|
||||
int3 = 3;
|
||||
long4 = Long.fromNumber(4);
|
||||
float5 = 5;
|
||||
double6 = 6;
|
||||
char7 = 7;
|
||||
byte8 = 8;
|
||||
string1 = "one";
|
||||
bools = TypedArray.create(Boolean, [true, false, true]);
|
||||
bytes = new ByteArray();
|
||||
bytes.writeByte(1);
|
||||
bytes.writeByte(2);
|
||||
bytes.writeByte(3);
|
||||
ints = TypedArray.create(int, [1, 2, 3]);
|
||||
}
|
||||
|
||||
public function equals (o :ASStreamableSubset) :Boolean
|
||||
{
|
||||
return bool1 === o.bool1 && short2 === o.short2 && int3 === o.int3 && long4.equals(o.long4) &&
|
||||
float5 === o.float5 && double6 === o.double6 && char7 === o.char7 &&
|
||||
byte8 === o.byte8 && string1 === o.string1 && nullString1 === o.nullString1 &&
|
||||
Util.equals(bools, o.bools) && Util.equals(bytes, o.bytes) &&
|
||||
Util.equals(ints, o.ints) && Util.equals(nullBools, o.nullBools) &&
|
||||
Util.equals(nullBytes, o.nullBytes) && Util.equals(nullInts, o.nullInts);
|
||||
|
||||
}
|
||||
|
||||
// GENERATED STREAMING START
|
||||
public var bool1 :Boolean;
|
||||
public var short2 :int;
|
||||
public var int3 :int;
|
||||
public var long4 :Long;
|
||||
public var float5 :Number;
|
||||
public var double6 :Number;
|
||||
public var char7 :int;
|
||||
public var byte8 :int;
|
||||
public var string1 :String;
|
||||
public var nullString1 :String;
|
||||
public var bools :TypedArray;
|
||||
public var bytes :ByteArray;
|
||||
public var ints :TypedArray;
|
||||
public var nullBools :TypedArray;
|
||||
public var nullBytes :ByteArray;
|
||||
public var nullInts :TypedArray;
|
||||
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
bool1 = ins.readBoolean();
|
||||
short2 = ins.readShort();
|
||||
int3 = ins.readInt();
|
||||
long4 = ins.readLong();
|
||||
float5 = ins.readFloat();
|
||||
double6 = ins.readDouble();
|
||||
char7 = ins.readShort();
|
||||
byte8 = ins.readByte();
|
||||
string1 = ins.readField(String);
|
||||
nullString1 = ins.readField(String);
|
||||
bools = ins.readField(TypedArray.getJavaType(Boolean));
|
||||
bytes = ins.readField(ByteArray);
|
||||
ints = ins.readField(TypedArray.getJavaType(int));
|
||||
nullBools = ins.readField(TypedArray.getJavaType(Boolean));
|
||||
nullBytes = ins.readField(ByteArray);
|
||||
nullInts = ins.readField(TypedArray.getJavaType(int));
|
||||
}
|
||||
|
||||
override public function writeObject (out :ObjectOutputStream) :void
|
||||
{
|
||||
super.writeObject(out);
|
||||
out.writeBoolean(bool1);
|
||||
out.writeShort(short2);
|
||||
out.writeInt(int3);
|
||||
out.writeLong(long4);
|
||||
out.writeFloat(float5);
|
||||
out.writeDouble(double6);
|
||||
out.writeShort(char7);
|
||||
out.writeByte(byte8);
|
||||
out.writeField(string1);
|
||||
out.writeField(nullString1);
|
||||
out.writeField(bools);
|
||||
out.writeField(bytes);
|
||||
out.writeField(ints);
|
||||
out.writeField(nullBools);
|
||||
out.writeField(nullBytes);
|
||||
out.writeField(nullInts);
|
||||
}
|
||||
// GENERATED STREAMING END
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.io {
|
||||
import com.threerings.util.StringUtil;
|
||||
import com.threerings.util.Name;
|
||||
import flash.utils.ByteArray;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.presents.peer.data.ClientInfo;
|
||||
|
||||
import asunit.framework.TestCase;
|
||||
|
||||
public class StreamableTest extends TestCase
|
||||
{
|
||||
public function testStreamingToSelf ():void
|
||||
{
|
||||
var sub:ASStreamableSubset = ASStreamableSubset.createWithJavaDefaults();
|
||||
var written:ByteArray = new ByteArray();
|
||||
var output:ObjectOutputStream = new ObjectOutputStream(written);
|
||||
output.writeObject(sub);
|
||||
written.position = 0;
|
||||
var input:ObjectInputStream = new ObjectInputStream(written);
|
||||
var read:ASStreamableSubset = input.readObject(ASStreamableSubset);
|
||||
assertTrue(sub.equals(read));
|
||||
}
|
||||
|
||||
public function testStreamingFromJava () :void
|
||||
{
|
||||
var sub:ASStreamableSubset = ASStreamableSubset.createWithJavaDefaults();
|
||||
var javaData:ByteArray = StringUtil.unhexlate(
|
||||
"ffff0024636f6d2e746872656572696e67732e696f2e415353747265616d61626c65537562736574" +
|
||||
"01000200000003000000000000000440a0000040180000000000000007080100036f6e6500010000" +
|
||||
"000301000101000000030102030100000003000000010000000200000003000000");
|
||||
var input:ObjectInputStream = new ObjectInputStream(javaData);
|
||||
var read :ASStreamableSubset = input.readObject(ASStreamableSubset);
|
||||
assertTrue(sub.equals(read));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.threerings.io;
|
||||
|
||||
//
|
||||
//$Id$
|
||||
//
|
||||
//Narya library - tools for developing networked games
|
||||
//Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
//http://www.threerings.net/code/narya/
|
||||
//
|
||||
//This library is free software; you can redistribute it and/or modify it
|
||||
//under the terms of the GNU Lesser General Public License as published
|
||||
//by the Free Software Foundation; either version 2.1 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//This library 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
|
||||
//Lesser General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU Lesser General Public
|
||||
//License along with this library; if not, write to the Free Software
|
||||
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
public class ASStreamableSubset extends SimpleStreamableObject
|
||||
{
|
||||
public boolean bool1 = true;
|
||||
public short short2 = 2;
|
||||
public int int3 = 3;
|
||||
public long long4 = 4;
|
||||
public float float5 = 5;
|
||||
public double double6 = 6;
|
||||
public char char7 = (char)7;
|
||||
public byte byte8 = 8;
|
||||
|
||||
public String string1 = "one";
|
||||
public String nullString1;
|
||||
|
||||
public boolean[] bools = new boolean[] { true, false, true };
|
||||
public byte[] bytes = new byte[] { 1, 2, 3 };
|
||||
public int[] ints = new int[] { 1, 2, 3 };
|
||||
|
||||
public boolean[] nullBools;
|
||||
public byte[] nullBytes;
|
||||
public int[] nullInts;
|
||||
|
||||
@Override
|
||||
public boolean equals (Object other)
|
||||
{
|
||||
if (!(other instanceof ASStreamableSubset)) {
|
||||
return false;
|
||||
}
|
||||
ASStreamableSubset ow = (ASStreamableSubset)other;
|
||||
return bool1 == ow.bool1 && byte8 == ow.byte8 && char7 == ow.char7 && short2 == ow.short2
|
||||
&& int3 == ow.int3 && long4 == ow.long4
|
||||
&& float5 == ow.float5
|
||||
&& double6 == ow.double6
|
||||
&&
|
||||
|
||||
Objects.equal(string1, ow.string1)
|
||||
&& Objects.equal(nullString1, ow.nullString1)
|
||||
&&
|
||||
|
||||
Arrays.equals(bools, ow.bools) && Arrays.equals(bytes, ow.bytes)
|
||||
&& Arrays.equals(ints, ow.ints) &&
|
||||
|
||||
Arrays.equals(nullBools, ow.nullBools) && Arrays.equals(nullBytes, ow.nullBytes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user