tests: Add test for reading AMF0 objects
This commit is contained in:
parent
e7a723f250
commit
84a7b3d148
|
@ -479,6 +479,7 @@ swf_tests! {
|
||||||
(as3_get_qualified_class_name, "avm2/get_qualified_class_name", 1),
|
(as3_get_qualified_class_name, "avm2/get_qualified_class_name", 1),
|
||||||
(as3_get_qualified_super_class_name, "avm2/get_qualified_super_class_name", 1),
|
(as3_get_qualified_super_class_name, "avm2/get_qualified_super_class_name", 1),
|
||||||
(as3_bytearray_readobject_amf3, "avm2/bytearray_readobject_amf3", 1),
|
(as3_bytearray_readobject_amf3, "avm2/bytearray_readobject_amf3", 1),
|
||||||
|
(as3_bytearray_readobject_amf0, "avm2/bytearray_readobject_amf0", 1),
|
||||||
(as3_array_constr, "avm2/array_constr", 1),
|
(as3_array_constr, "avm2/array_constr", 1),
|
||||||
(as3_array_access, "avm2/array_access", 1),
|
(as3_array_access, "avm2/array_access", 1),
|
||||||
(as3_array_storage, "avm2/array_storage", 1),
|
(as3_array_storage, "avm2/array_storage", 1),
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package
|
||||||
|
{
|
||||||
|
import flash.utils.ByteArray;
|
||||||
|
public class Test
|
||||||
|
{
|
||||||
|
var TESTS = [
|
||||||
|
[6], // UNDEFINED
|
||||||
|
[5], // NULL
|
||||||
|
[1,0], // FALSE
|
||||||
|
[1,1], // TRUE
|
||||||
|
[0,63,240,0,0,0,0,0,0], // INTEGER
|
||||||
|
[0,63,241,153,153,153,153,153,154], // NUMBER
|
||||||
|
[0,127,240,0,0,0,0,0,0], // INFINITY
|
||||||
|
[0,255,240,0,0,0,0,0,0], // NEG INFINITY
|
||||||
|
[0,255,248,0,0,0,0,0,0], // NAN
|
||||||
|
[2,0,4,116,101,115,116], // STRING
|
||||||
|
[8,0,0,0,2,0,1,48,0,63,240,0,0,0,0,0,0,0,1,49,0,64,0,0,0,0,0,0,0,0,0,9], // DENSE ARRAY
|
||||||
|
[8,0,0,0,9,0,1,48,0,63,240,0,0,0,0,0,0,0,1,49,0,64,0,0,0,0,0,0,0,0,1,56,0,64,8,0,0,0,0,0,0,0,0,9], // ARRAY WITH HOLES
|
||||||
|
[8,0,0,0,2,0,1,48,0,63,240,0,0,0,0,0,0,0,1,49,0,64,0,0,0,0,0,0,0,0,5,104,101,108,108,111,0,64,8,0,0,0,0,0,0,0,0,9], // ARRAY WITH ELEMENTS
|
||||||
|
[8,0,0,0,9,0,1,48,0,63,240,0,0,0,0,0,0,0,1,49,0,64,0,0,0,0,0,0,0,0,1,56,0,64,16,0,0,0,0,0,0,0,5,104,101,108,108,111,0,64,8,0,0,0,0,0,0,0,0,9], // ARRAY WITH HOLES AND ELEMENTS
|
||||||
|
[8,0,0,0,3,0,1,48,8,0,0,0,2,0,1,48,0,63,240,0,0,0,0,0,0,0,1,49,0,64,0,0,0,0,0,0,0,0,0,9,0,1,49,8,0,0,0,2,0,1,48,0,64,8,0,0,0,0,0,0,0,1,49,0,64,16,0,0,0,0,0,0,0,0,9,0,1,50,8,0,0,0,2,0,1,48,0,64,20,0,0,0,0,0,0,0,1,49,8,0,0,0,2,0,1,48,0,64,24,0,0,0,0,0,0,0,1,49,0,64,28,0,0,0,0,0,0,0,0,9,0,0,9,0,0,9], // MULTI DIMENSIONAL ARRAY
|
||||||
|
[3,0,4,116,101,115,116,2,0,5,104,101,108,108,111,0,0,9] // OBJECT
|
||||||
|
];
|
||||||
|
public function testToObject(arr)
|
||||||
|
{
|
||||||
|
var ba = new ByteArray();
|
||||||
|
ba.objectEncoding = "AMF0";
|
||||||
|
for (var i = 0; i < arr.length; i++)
|
||||||
|
{
|
||||||
|
ba.writeByte(arr[i]);
|
||||||
|
}
|
||||||
|
ba.position = 0;
|
||||||
|
return ba.readObject();
|
||||||
|
}
|
||||||
|
public function Test()
|
||||||
|
{
|
||||||
|
for (var i = 0; i < TESTS.length; i++)
|
||||||
|
{
|
||||||
|
var obj = testToObject(TESTS[i]);
|
||||||
|
trace(obj);
|
||||||
|
if (obj is Object)
|
||||||
|
{
|
||||||
|
trace("showing props:");
|
||||||
|
for (var prop in obj)
|
||||||
|
{
|
||||||
|
if (! (prop is int))
|
||||||
|
{
|
||||||
|
trace(prop);
|
||||||
|
trace(obj[prop])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace("done showing props");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
undefined
|
||||||
|
null
|
||||||
|
false
|
||||||
|
showing props:
|
||||||
|
done showing props
|
||||||
|
true
|
||||||
|
showing props:
|
||||||
|
done showing props
|
||||||
|
1
|
||||||
|
showing props:
|
||||||
|
done showing props
|
||||||
|
1.1
|
||||||
|
showing props:
|
||||||
|
done showing props
|
||||||
|
Infinity
|
||||||
|
showing props:
|
||||||
|
done showing props
|
||||||
|
-Infinity
|
||||||
|
showing props:
|
||||||
|
done showing props
|
||||||
|
NaN
|
||||||
|
showing props:
|
||||||
|
done showing props
|
||||||
|
test
|
||||||
|
showing props:
|
||||||
|
done showing props
|
||||||
|
1,2
|
||||||
|
showing props:
|
||||||
|
done showing props
|
||||||
|
1,2,,,,,,,3
|
||||||
|
showing props:
|
||||||
|
done showing props
|
||||||
|
1,2
|
||||||
|
showing props:
|
||||||
|
hello
|
||||||
|
3
|
||||||
|
done showing props
|
||||||
|
1,2,,,,,,,4
|
||||||
|
showing props:
|
||||||
|
hello
|
||||||
|
3
|
||||||
|
done showing props
|
||||||
|
1,2,3,4,5,6,7
|
||||||
|
showing props:
|
||||||
|
done showing props
|
||||||
|
[object Object]
|
||||||
|
showing props:
|
||||||
|
test
|
||||||
|
hello
|
||||||
|
done showing props
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue