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:
Charlie Groves
2010-10-15 00:42:12 +00:00
parent 9e5d4b95fa
commit 377fafae1e
7 changed files with 465 additions and 0 deletions
+35
View File
@@ -80,6 +80,22 @@
</receiver>
</target>
<!-- generates sender and decoder classes for all invocation -->
<!-- receiver declarations -->
<target name="genascript">
<taskdef name="ascript" classpathref="classpath"
classname="com.threerings.presents.tools.GenActionScriptStreamableTask"/>
<!-- make sure the receiver class files are all compiled -->
<javac srcdir="src/java" destdir="${classes.dir}"
debug="on" deprecation="on" source="1.5" target="1.5">
<classpath refid="classpath"/>
<include name="**/ASStreamableSubset.java"/>
</javac>
<!-- now generate the associated files -->
<ascript header="../lib/SOURCE_HEADER" classpathref="classpath" asroot="src/as">
<fileset dir="src/java" includes="**/ASStreamableSubset.java"/>
</ascript>
</target>
<!-- prepares the application directories -->
<target name="prepare">
<mkdir dir="${deploy.dir}"/>
@@ -162,6 +178,25 @@
</java>
</target>
<target name="astest" depends="prepare">
<!-- Generate astest-config.xml for Flash Player and general compilation -->
<copy file="etc/astest-config.xml.in" tofile="${deploy.dir}/astest-config.xml">
<filterset>
<filter token="flex_sdk_dir" value="${flexsdk.dir}"/>
<filter token="lib_name" value="${lib.name}"/>
</filterset>
</copy>
<java jar="${flexsdk.dir}/lib/mxmlc.jar" fork="true" failonerror="true">
<arg value="-load-config"/>
<arg value="${deploy.dir}/astest-config.xml"/>
<arg value="-source-path+=../src/as/"/>
<arg value="-source-path+=src/as"/>
<arg value="-output=dist/naryatest.swf"/>
<arg value="src/as/com/threerings/NaryaRunner.as"/>
</java>
</target>
<!-- run the tests -->
<property name="test" value=""/>
<target name="tests" depends="compile" description="Run the tests.">
+111
View File
@@ -0,0 +1,111 @@
<?xml version="1.0"?>
<flex-config>
<compiler>
<accessible>false</accessible>
<allow-source-path-overlap>false</allow-source-path-overlap>
<as3>true</as3>
<source-path>
<path-element>../src/as</path-element>
</source-path>
<library-path>
<path-element>@flex_sdk_dir@/frameworks/libs</path-element>
<path-element>../../dist/lib/ooolib.swc</path-element>
<path-element>../../dist/lib/corelib.swc</path-element>
<path-element>../../dist/lib/asunit.swc</path-element>
</library-path>
<external-library-path>
<path-element>@flex_sdk_dir@/frameworks/libs/player/{targetPlayerMajorVersion}</path-element>
</external-library-path>
<locale>
<locale-element>en_US</locale-element>
</locale>
<fonts>
<advanced-anti-aliasing>true</advanced-anti-aliasing>
<max-cached-fonts>20</max-cached-fonts>
<max-glyphs-per-face>1000</max-glyphs-per-face>
<managers>
<manager-class>flash.fonts.JREFontManager</manager-class>
<manager-class>flash.fonts.AFEFontManager</manager-class>
<manager-class>flash.fonts.BatikFontManager</manager-class>
</managers>
<local-fonts-snapshot>@flex_sdk_dir@/frameworks/localFonts.ser</local-fonts-snapshot>
</fonts>
<namespaces>
<namespace>
<uri>http://www.adobe.com/2006/mxml</uri>
<manifest>@flex_sdk_dir@/frameworks/mxml-manifest.xml</manifest>
</namespace>
</namespaces>
<incremental>false</incremental>
<optimize>true</optimize>
<debug>true</debug>
<show-actionscript-warnings>true</show-actionscript-warnings>
<show-binding-warnings>true</show-binding-warnings>
<show-shadowed-device-font-warnings>true</show-shadowed-device-font-warnings>
<show-unused-type-selector-warnings>false</show-unused-type-selector-warnings>
<strict>true</strict>
<use-resource-bundle-metadata>true</use-resource-bundle-metadata>
<verbose-stacktraces>true</verbose-stacktraces>
<warn-array-tostring-changes>false</warn-array-tostring-changes>
<warn-assignment-within-conditional>true</warn-assignment-within-conditional>
<warn-bad-array-cast>true</warn-bad-array-cast>
<warn-bad-bool-assignment>true</warn-bad-bool-assignment>
<warn-bad-date-cast>true</warn-bad-date-cast>
<warn-bad-es3-type-method>true</warn-bad-es3-type-method>
<warn-bad-es3-type-prop>true</warn-bad-es3-type-prop>
<warn-bad-nan-comparison>true</warn-bad-nan-comparison>
<warn-bad-null-assignment>true</warn-bad-null-assignment>
<warn-bad-null-comparison>true</warn-bad-null-comparison>
<warn-bad-undefined-comparison>true</warn-bad-undefined-comparison>
<warn-boolean-constructor-with-no-args>false</warn-boolean-constructor-with-no-args>
<warn-changes-in-resolve>false</warn-changes-in-resolve>
<warn-class-is-sealed>true</warn-class-is-sealed>
<warn-const-not-initialized>true</warn-const-not-initialized>
<warn-constructor-returns-value>false</warn-constructor-returns-value>
<warn-deprecated-event-handler-error>true</warn-deprecated-event-handler-error>
<warn-deprecated-function-error>true</warn-deprecated-function-error>
<warn-deprecated-property-error>true</warn-deprecated-property-error>
<warn-duplicate-argument-names>true</warn-duplicate-argument-names>
<warn-duplicate-variable-def>true</warn-duplicate-variable-def>
<warn-for-var-in-changes>false</warn-for-var-in-changes>
<warn-import-hides-class>true</warn-import-hides-class>
<warn-instance-of-changes>true</warn-instance-of-changes>
<warn-internal-error>true</warn-internal-error>
<warn-level-not-supported>true</warn-level-not-supported>
<warn-missing-namespace-decl>true</warn-missing-namespace-decl>
<warn-negative-uint-literal>true</warn-negative-uint-literal>
<warn-no-constructor>false</warn-no-constructor>
<warn-no-explicit-super-call-in-constructor>false</warn-no-explicit-super-call-in-constructor>
<warn-no-type-decl>true</warn-no-type-decl>
<warn-number-from-string-changes>false</warn-number-from-string-changes>
<warn-scoping-change-in-this>false</warn-scoping-change-in-this>
<warn-slow-text-field-addition>true</warn-slow-text-field-addition>
<warn-unlikely-function-value>true</warn-unlikely-function-value>
<warn-xml-class-has-changed>false</warn-xml-class-has-changed>
</compiler>
<default-background-color>0x000000</default-background-color>
<default-frame-rate>30</default-frame-rate>
<default-script-limits>
<max-recursion-depth>1000</max-recursion-depth>
<max-execution-time>15</max-execution-time>
</default-script-limits>
<default-size>
<width>750</width>
<height>700</height>
</default-size>
<metadata>
<creator>Three Rings Design, Inc.</creator>
<language>EN</language>
<publisher>Three Rings Design, Inc.</publisher>
</metadata>
<runtime-shared-library-path>
<path-element>@flex_sdk_dir@/frameworks/libs/framework.swc</path-element>
<rsl-url>framework_3.2.0.3958.swz</rsl-url>
<policy-file-url></policy-file-url>
<rsl-url>framework_3.2.0.3958.swf</rsl-url>
<policy-file-url></policy-file-url>
</runtime-shared-library-path>
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<target-player>10.0.0</target-player>
<use-network>true</use-network>
</flex-config>
@@ -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);
}
}