AMF3 tests, exceptions

This commit is contained in:
Jindra Petřík
2016-07-17 15:48:56 +02:00
parent ec5ca5c3f1
commit f7b3d502cb
39 changed files with 2639 additions and 1545 deletions

View File

@@ -0,0 +1,169 @@
package
{
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;
import flash.utils.Dictionary;
import flash.geom.Point;
import flash.xml.XMLDocument;
import flash.net.registerClassAlias;
/**
* Generating test data file
*/
public class AmfTest extends Sprite
{
private function writeToFile(filename:String,data)
{
var urlStr:String = "file:///"+File.applicationDirectory.nativePath+"/generated/"+filename;
var file:File = new File() ;
file.url = urlStr;
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
var bytes:ByteArray = new ByteArray();
bytes.writeObject(data);
fileStream.writeBytes(bytes, 0, bytes.length);
fileStream.close();
}
public function AmfTest() {
var ar = ["a","b","c"];
var asoc_array = [1,2,3];
asoc_array["key1"] = 5;
asoc_array["key2"] = 6;
var ba:ByteArray = new ByteArray();
ba.writeByte(65);
ba.writeByte(66);
ba.writeByte(67);
var vector_int:Vector.<int> = new <int>[-10,20,-30,40];
var vector_uint:Vector.<uint> = new <uint>[10,20,30,40];
var vector_double:Vector.<Number> = new <Number>[-10.1,20.2,-30.3,40.4];
var vector_string:Vector.<String> = new <String>["x","y","z"];
var vector_point:Vector.<Point> = new <Point>[new Point(10,20),new Point(30,40),new Point(50,60)];
var dict = new Dictionary();
dict["dkey1"] = "TestOne";
dict["dkey2"] = "TestTwo";
var txmldoc:XMLDocument = new XMLDocument("<foo><bar>aa</bar></foo>");
var txml:XML = <foo>
<bar>Hello</bar>
<bar>Hi</bar>
</foo>;
var date = new Date();
var me = {
"01_int":5,
"02_negative-int":-5,
"03_string":"String",
"04_true":true,
"05_false":false,
"06_undefined":undefined,
"07_null":null,
"08_double":5.6,
"09_negative-double":-5.6,
"10_array":ar,
"11_asoc_array": asoc_array,
"12_date":date,
"13_xml":txml,
"14_byteArray":ba,
"15_vectorInt":vector_int,
"16_vectorUInt":vector_uint,
"17_vectorDouble":vector_double,
"18_vectorString":vector_string,
"19_vectorPoint":vector_point,
"20_dictionary":dict,
"21_xmldoc":txmldoc,
"22_ref_string":"String",
"23_ref_array":ar,
"24_ref_date":date,
"25_ref_byteArray":ba,
"26_ref_vectorInt":vector_int,
"27_ref_vectorUInt":vector_uint,
"28_ref_vectorDouble":vector_double,
"29_ref_vectorString":vector_string,
"30_ref_dictionary":dict,
"31_ref_xml":txml,
"32_ref_xmldoc":txmldoc
};
me["33_me"] = me;
writeToFile("all.bin",me);
var custom = new CustomClass();
custom.setVal8(127);
custom.setVal32(-2500);
registerClassAlias("CustomClass", CustomClass);
var cust_obj = {
"member1":5,
"member2":custom,
"member3":27
};
writeToFile("custom.bin",cust_obj);
writeToFile("noserializer_object_dynamic.bin",{
"a":5,
"b":8,
"c":custom,
"d":6,
"e":7,
"f":26
});
writeToFile("noserializer_array_dense.bin",
["a","b",custom,"d","e","f"]
);
var arx = [];
arx["a"] = 1;
arx["b"] = 2;
arx["c"] = custom;
arx["d"] = 4;
arx["e"] = 5;
arx["f"] = 6;
writeToFile("noserializer_array_associative.bin", arx);
writeToFile("noserializer_vector.bin", new <Object>["a","b",custom,"d","e","f"]);
var nsdict = new Dictionary();
nsdict["a"] = "One";
nsdict["b"] = "Two";
nsdict["c"] = custom;
nsdict["d"] = "Three";
nsdict["e"] = "Four";
nsdict["f"] = "Five";
writeToFile("noserializer_dictionary_value.bin", nsdict);
var nsdict2 = new Dictionary();
nsdict2["a"] = "One";
nsdict2["b"] = "Two";
nsdict2[custom] = "Three";
nsdict2["d"] = "Three";
nsdict2["e"] = "Four";
nsdict2["f"] = "Five";
writeToFile("noserializer_dictionary_key.bin", nsdict2);
var objWithCustom:ObjectWithCustom = new ObjectWithCustom("1","2",custom,"4","5","6");
writeToFile("noserializer_object_sealed.bin", objWithCustom);
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,32 @@
package
{
import flash.utils.IExternalizable;
import flash.utils.IDataOutput;
import flash.utils.IDataInput;
public class CustomClass implements IExternalizable
{
private var val8:int;
private var val32:int;
public function CustomClass() { //No constructor parameters allowed
}
public function setVal8(v:int){
this.val8 = v;
}
public function setVal32(v:int){
this.val32 = v;
}
public function writeExternal(output:IDataOutput):void {
output.writeByte(val8);
output.writeInt(val32);
}
public function readExternal(input:IDataInput):void {
this.val8 = input.readByte();
this.val32 = input.readInt();
}
}
}

View File

@@ -0,0 +1,24 @@
package
{
public class ObjectWithCustom
{
public var a:String;
public var b:String;
public var c:CustomClass;
public var d:String;
public var e:String;
public var f:String;
public function ObjectWithCustom(a:String,b:String,c:CustomClass,d:String,e:String,f:String) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
this.f = f;
}
}
}

14
libsrc/ffdec_lib/testdata/amf3/app.xml vendored Normal file
View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://ns.adobe.com/air/application/3.1">
<id>samples.flex.HelloWorld</id>
<versionNumber>1</versionNumber>
<filename>HelloWorld</filename>
<initialWindow>
<content>AmfTest.swf</content>
<visible>true</visible>
<systemChrome>none</systemChrome>
<transparent>true</transparent>
<width>400</width>
<height>200</height>
</initialWindow>
</application>

Binary file not shown.

View File

@@ -0,0 +1,3 @@
member3member1member2
CustomClass<73><7F><EFBFBD><

View File

@@ -0,0 +1,2 @@
fabc
CustomClass<73><7F><EFBFBD><de

View File

@@ -0,0 +1,2 @@
ab

View File

@@ -0,0 +1,3 @@
fabc
CustomClass<73><7F><EFBFBD><de

View File

@@ -0,0 +1,3 @@
ccfadbe
CustomClass<73><7F><EFBFBD><61425

Binary file not shown.

20
libsrc/ffdec_lib/testdata/amf3/run.bat vendored Normal file
View File

@@ -0,0 +1,20 @@
@echo off
set ISDEBUG=false
if "%1" == "debug" goto blockset
goto block2
:blockset
set ISDEBUG=true
:block2
set AIRPATH=c:\air
set COMPILERPATH=%AIRPATH%\bin\amxmlc.bat
if not exist %COMPILERPATH% goto notex
call %COMPILERPATH% -warnings=false -debug=%ISDEBUG% AmfTest.as>NUL
if errorlevel==1 goto failed
goto end
:notex
echo AIR SDK not found. Download and unpack Flex SDK into C:\air directory, then run build again
goto end
:failed
pause
:end
%AIRPATH%\bin\adl.exe app.xml

View File

@@ -0,0 +1,34 @@
package
{
import flash.utils.IExternalizable;
import flash.utils.IDataOutput;
import flash.utils.IDataInput;
public class CustomClass implements IExternalizable
{
private var val8:int;
private var val32:int;
public function CustomClass()
{
}
public function setVal8(v:int){
this.val8 = v;
}
public function setVal32(v:int){
this.val32 = v;
}
public function writeExternal(output:IDataOutput):void {
output.writeByte(val8);
output.writeInt(val32);
}
public function readExternal(input:IDataInput):void {
this.val8 = input.readByte();
this.val32 = input.readInt();
}
}
}