diff --git a/core/src/avm1.rs b/core/src/avm1.rs index b3e3769f3157c..9ec264b9fc1f4 100644 --- a/core/src/avm1.rs +++ b/core/src/avm1.rs @@ -23,9 +23,6 @@ mod runtime; mod scope; mod value; -#[cfg(test)] -mod tests; - pub use activation::{Activation, ActivationIdentifier}; pub use debug::VariableDumper; pub use error::Error; diff --git a/core/src/avm1/debug.rs b/core/src/avm1/debug.rs index 866fa88c84be3..cf0c29270791c 100644 --- a/core/src/avm1/debug.rs +++ b/core/src/avm1/debug.rs @@ -188,124 +188,3 @@ impl<'a> VariableDumper<'a> { self.output.push('\n'); } } - -#[cfg(test)] -mod tests { - use super::*; - use crate::avm1::error::Error; - use crate::avm1::test_utils::with_avm; - use crate::avm1::ScriptObject; - - #[test] - fn dump_undefined() { - with_avm(19, |activation, _root| -> Result<(), Error> { - assert_eq!( - VariableDumper::dump(&Value::Undefined, " ", activation), - "undefined" - ); - Ok(()) - }) - } - - #[test] - fn dump_null() { - with_avm(19, |activation, _root| -> Result<(), Error> { - assert_eq!(VariableDumper::dump(&Value::Null, " ", activation), "null"); - Ok(()) - }) - } - - #[test] - fn dump_bool() { - with_avm(19, |activation, _root| -> Result<(), Error> { - assert_eq!(VariableDumper::dump(&true.into(), " ", activation), "true"); - assert_eq!( - VariableDumper::dump(&false.into(), " ", activation), - "false" - ); - Ok(()) - }) - } - - #[test] - fn dump_number() { - with_avm(19, |activation, _root| -> Result<(), Error> { - assert_eq!(VariableDumper::dump(&1000.into(), " ", activation), "1000"); - assert_eq!( - VariableDumper::dump(&(-0.05).into(), " ", activation), - "-0.05" - ); - Ok(()) - }) - } - - #[test] - fn dump_string() { - with_avm(19, |activation, _root| -> Result<(), Error> { - assert_eq!(VariableDumper::dump(&"".into(), " ", activation), "\"\""); - assert_eq!( - VariableDumper::dump(&"HELLO WORLD".into(), " ", activation), - "\"HELLO WORLD\"" - ); - assert_eq!( - VariableDumper::dump( - &"Escape \"this\" string\nplease! \u{0008}\u{000C}\n\r\t\"\\".into(), - " ", - activation, - ), - "\"Escape \\\"this\\\" string\\nplease! \\b\\f\\n\\r\\t\\\"\\\\\"" - ); - Ok(()) - }) - } - - #[test] - fn dump_empty_object() { - with_avm(19, |activation, _root| -> Result<(), Error> { - let object = ScriptObject::new(activation.strings(), None); - assert_eq!( - VariableDumper::dump(&object.into(), " ", activation), - "[object #0] {}" - ); - Ok(()) - }) - } - - #[test] - fn dump_object() { - with_avm(19, |activation, _root| -> Result<(), Error> { - let object = ScriptObject::new(activation.strings(), None); - let child = ScriptObject::new(activation.strings(), None); - object.set("self", object.into(), activation)?; - object.set("test", "value".into(), activation)?; - object.set("child", child.into(), activation)?; - child.set("parent", object.into(), activation)?; - child.set("age", 6.into(), activation)?; - assert_eq!( - VariableDumper::dump(&object.into(), " ", activation), - "[object #0] {\n child: [object #1] {\n age: 6\n parent: [object #0]\n }\n test: \"value\"\n self: [object #0]\n}", - ); - Ok(()) - }) - } - - #[test] - fn dump_variables() { - with_avm(19, |activation, _root| -> Result<(), Error> { - let object = ScriptObject::new(activation.strings(), None); - let child = ScriptObject::new(activation.strings(), None); - object.set("self", object.into(), activation)?; - object.set("test", "value".into(), activation)?; - object.set("child", child.into(), activation)?; - child.set("parent", object.into(), activation)?; - child.set("age", 6.into(), activation)?; - let mut dumper = VariableDumper::new(" "); - dumper.print_variables("Variables:", "object", &object.into(), activation); - assert_eq!( - dumper.output, - "Variables:\nobject.child = [object #0] {\n age: 6\n parent: [object #1] {\n child: [object #0]\n test: \"value\"\n self: [object #1]\n }\n }\nobject.test = \"value\"\nobject.self = [object #1]\n\n" - ); - Ok(()) - }) - } -} diff --git a/core/src/avm1/globals.rs b/core/src/avm1/globals.rs index 65c6ca7407280..84ee31eb3a856 100644 --- a/core/src/avm1/globals.rs +++ b/core/src/avm1/globals.rs @@ -1026,181 +1026,3 @@ pub fn remove_display_object<'gc>(this: DisplayObject<'gc>, activation: &mut Act } } } - -#[cfg(test)] -#[allow(clippy::unreadable_literal)] -mod tests { - use super::*; - - fn setup<'gc>(activation: &mut Activation<'_, 'gc>) -> Object<'gc> { - create_globals(activation.strings()).1 - } - - test_method!(boolean_function, "Boolean", setup, - [19] => { - [true] => true, - [false] => false, - [10.0] => true, - [-10.0] => true, - [0.0] => false, - [f64::INFINITY] => true, - [f64::NAN] => false, - [""] => false, - ["Hello"] => true, - [" "] => true, - ["0"] => true, - ["1"] => true, - [Value::Undefined] => false, - [Value::Null] => false, - [] => Value::Undefined - }, - [6] => { - [true] => true, - [false] => false, - [10.0] => true, - [-10.0] => true, - [0.0] => false, - [f64::INFINITY] => true, - [f64::NAN] => false, - [""] => false, - ["Hello"] => false, - [" "] => false, - ["0"] => false, - ["1"] => true, - [Value::Undefined] => false, - [Value::Null] => false, - [] => Value::Undefined - } - ); - - test_method!(is_nan_function, "isNaN", setup, - [19] => { - [true] => false, - [false] => false, - [10.0] => false, - [-10.0] => false, - [0.0] => false, - [f64::INFINITY] => false, - [f64::NAN] => true, - [""] => true, - ["Hello"] => true, - [" "] => true, - [" 5 "] => true, - ["0"] => false, - ["1"] => false, - ["Infinity"] => true, - ["100a"] => true, - ["0x10"] => false, - ["0xhello"] => true, - ["0x1999999981ffffff"] => false, - ["0xUIXUIDFKHJDF012345678"] => true, - ["123e-1"] => false, - [] => true - } - ); - - test_method!(is_finite, "isFinite", setup, - [19] => { - [true] => true, - [false] => true, - [10.0] => true, - [-10.0] => true, - [0.0] => true, - [f64::INFINITY] => false, - [f64::NEG_INFINITY] => false, - [f64::NAN] => false, - [""] => false, - ["Hello"] => false, - [" "] => false, - [" 5 "] => false, - ["0"] => true, - ["1"] => true, - ["Infinity"] => false, - ["-Infinity"] => false, - ["100a"] => false, - ["0x10"] => true, - ["0xhello"] => false, - ["0x1999999981ffffff"] => true, - ["0xUIXUIDFKHJDF012345678"] => false, - ["123e-1"] => true, - [Value::Undefined] => false, - [Value::Null] => false, - [] => false - } - ); - - test_method!(number_function, "Number", setup, - [5, 6] => { - [true] => 1.0, - [false] => 0.0, - [10.0] => 10.0, - [-10.0] => -10.0, - ["true"] => f64::NAN, - ["false"] => f64::NAN, - [1.0] => 1.0, - [0.0] => 0.0, - [0.000] => 0.0, - ["0.000"] => 0.0, - ["True"] => f64::NAN, - ["False"] => f64::NAN, - [f64::NAN] => f64::NAN, - [f64::INFINITY] => f64::INFINITY, - [f64::NEG_INFINITY] => f64::NEG_INFINITY, - [" 12"] => 12.0, - [" \t\r\n12"] => 12.0, - ["\u{A0}12"] => f64::NAN, - [" 0x12"] => f64::NAN, - ["01.2"] => 1.2, - [""] => f64::NAN, - ["Hello"] => f64::NAN, - [" "] => f64::NAN, - [" 5 "] => f64::NAN, - ["0"] => 0.0, - ["1"] => 1.0, - ["Infinity"] => f64::NAN, - ["-Infinity"] => f64::NAN, - ["inf"] => f64::NAN, - ["-inf"] => f64::NAN, - ["100a"] => f64::NAN, - ["0xhello"] => f64::NAN, - ["123e-1"] => 12.3, - ["0xUIXUIDFKHJDF012345678"] => f64::NAN, - [] => 0.0 - }, - [5] => { - ["0x12"] => f64::NAN, - ["0x10"] => f64::NAN, - ["0x1999999981ffffff"] => f64::NAN, - ["010"] => 10, - ["-010"] => -10, - ["+010"] => 10, - [" 010"] => 10, - [" -010"] => -10, - [" +010"] => 10, - ["037777777777"] => 37777777777.0, - ["-037777777777"] => -37777777777.0 - }, - [6, 7] => { - ["0x12"] => 18.0, - ["0x10"] => 16.0, - ["-0x10"] => f64::NAN, - ["0x1999999981ffffff"] => -2113929217.0, - ["010"] => 8, - ["-010"] => -8, - ["+010"] => 8, - [" 010"] => 10, - [" -010"] => -10, - [" +010"] => 10, - ["037777777777"] => -1, - ["-037777777777"] => 1 - }, - [5, 6] => { - [Value::Undefined] => 0.0, - [Value::Null] => 0.0 - }, - [7] => { - [Value::Undefined] => f64::NAN, - [Value::Null] => f64::NAN - } - ); -} diff --git a/core/src/avm1/globals/math.rs b/core/src/avm1/globals/math.rs index 6b15d6fd4600d..90698c9494cb3 100644 --- a/core/src/avm1/globals/math.rs +++ b/core/src/avm1/globals/math.rs @@ -329,7 +329,6 @@ mod tests { [f64::NAN] => f64::NAN, [Value::Null] => f64::NAN, [Value::Undefined] => f64::NAN, - ["5"] => f64::NAN, [1.0, 2.0] => 1.0, [3.0, 2.0, 1.0] => 9.0 }, @@ -361,7 +360,6 @@ mod tests { [f64::NAN] => f64::NAN, [Value::Null] => f64::NAN, [Value::Undefined] => f64::NAN, - ["5"] => f64::NAN, [1.0, 2.0] => 2.0, [3.0, 2.0, 1.0] => 3.0 }, @@ -382,7 +380,6 @@ mod tests { [f64::NAN] => f64::NAN, [Value::Null] => f64::NAN, [Value::Undefined] => f64::NAN, - ["5"] => f64::NAN, [1.0, 2.0] => 1.0, [3.0, 2.0, 1.0] => 2.0 }, diff --git a/core/src/avm1/object/script_object.rs b/core/src/avm1/object/script_object.rs index e415fa2cabe3a..94509b065c90c 100644 --- a/core/src/avm1/object/script_object.rs +++ b/core/src/avm1/object/script_object.rs @@ -556,232 +556,3 @@ impl<'gc> TObject<'gc> for ScriptObject<'gc> { self.delete(activation, index_str) } } - -#[cfg(test)] -mod tests { - use super::*; - - use crate::avm1::function::Executable; - use crate::avm1::function::FunctionObject; - - fn with_object(swf_version: u8, test: F) - where - F: for<'a, 'gc> FnOnce(&mut Activation<'_, 'gc>, Object<'gc>), - { - crate::avm1::test_utils::with_avm(swf_version, |activation, _root| { - let object = ScriptObject::new( - &activation.context.strings, - Some(activation.context.avm1.prototypes().object), - ) - .into(); - test(activation, object); - Ok(()) - }) - } - - #[test] - fn test_get_undefined() { - with_object(0, |activation, object| { - assert_eq!( - object.get("not_defined", activation).unwrap(), - Value::Undefined - ); - }) - } - - #[test] - fn test_set_get() { - with_object(0, |activation, object| { - object.raw_script_object().define_value( - activation.gc(), - "forced", - "forced".into(), - Attribute::empty(), - ); - object.set("natural", "natural".into(), activation).unwrap(); - - assert_eq!(object.get("forced", activation).unwrap(), "forced".into()); - assert_eq!(object.get("natural", activation).unwrap(), "natural".into()); - }) - } - - #[test] - fn test_set_readonly() { - with_object(0, |activation, object| { - object.raw_script_object().define_value( - activation.gc(), - "normal", - "initial".into(), - Attribute::empty(), - ); - object.raw_script_object().define_value( - activation.gc(), - "readonly", - "initial".into(), - Attribute::READ_ONLY, - ); - - object.set("normal", "replaced".into(), activation).unwrap(); - object - .set("readonly", "replaced".into(), activation) - .unwrap(); - - assert_eq!(object.get("normal", activation).unwrap(), "replaced".into()); - assert_eq!( - object.get("readonly", activation).unwrap(), - "initial".into() - ); - }) - } - - #[test] - fn test_deletable_not_readonly() { - with_object(0, |activation, object| { - object.raw_script_object().define_value( - activation.gc(), - "test", - "initial".into(), - Attribute::DONT_DELETE, - ); - - assert!(!object.delete(activation, "test".into())); - assert_eq!(object.get("test", activation).unwrap(), "initial".into()); - - object - .raw_script_object() - .set("test", "replaced".into(), activation) - .unwrap(); - - assert!(!object.delete(activation, "test".into())); - assert_eq!(object.get("test", activation).unwrap(), "replaced".into()); - }) - } - - #[test] - fn test_virtual_get() { - with_object(0, |activation, object| { - let getter = FunctionObject::function( - &activation.context.strings, - Executable::Native(|_avm, _this, _args| Ok("Virtual!".into())), - activation.context.avm1.prototypes().function, - activation.context.avm1.prototypes().function, - ); - - object.raw_script_object().add_property( - activation.gc(), - "test".into(), - getter, - None, - Attribute::empty(), - ); - - assert_eq!(object.get("test", activation).unwrap(), "Virtual!".into()); - - // This set should do nothing - object.set("test", "Ignored!".into(), activation).unwrap(); - assert_eq!(object.get("test", activation).unwrap(), "Virtual!".into()); - }) - } - - #[test] - fn test_delete() { - with_object(0, |activation, object| { - let getter = FunctionObject::function( - &activation.context.strings, - Executable::Native(|_avm, _this, _args| Ok("Virtual!".into())), - activation.context.avm1.prototypes().function, - activation.context.avm1.prototypes().function, - ); - - object.raw_script_object().add_property( - activation.gc(), - "virtual".into(), - getter, - None, - Attribute::empty(), - ); - object.raw_script_object().add_property( - activation.gc(), - "virtual_un".into(), - getter, - None, - Attribute::DONT_DELETE, - ); - object.raw_script_object().define_value( - activation.gc(), - "stored", - "Stored!".into(), - Attribute::empty(), - ); - object.raw_script_object().define_value( - activation.gc(), - "stored_un", - "Stored!".into(), - Attribute::DONT_DELETE, - ); - - assert!(object.delete(activation, "virtual".into())); - assert!(!object.delete(activation, "virtual_un".into())); - assert!(object.delete(activation, "stored".into())); - assert!(!object.delete(activation, "stored_un".into())); - assert!(!object.delete(activation, "non_existent".into())); - - assert_eq!(object.get("virtual", activation).unwrap(), Value::Undefined); - assert_eq!( - object.get("virtual_un", activation).unwrap(), - "Virtual!".into() - ); - assert_eq!(object.get("stored", activation).unwrap(), Value::Undefined); - assert_eq!( - object.get("stored_un", activation).unwrap(), - "Stored!".into() - ); - }) - } - - #[test] - fn test_get_keys() { - with_object(0, |activation, object| { - let getter = FunctionObject::function( - &activation.context.strings, - Executable::Native(|_avm, _this, _args| Ok(Value::Null)), - activation.context.avm1.prototypes().function, - activation.context.avm1.prototypes().function, - ); - - object.raw_script_object().define_value( - activation.gc(), - "stored", - Value::Null, - Attribute::empty(), - ); - object.raw_script_object().define_value( - activation.gc(), - "stored_hidden", - Value::Null, - Attribute::DONT_ENUM, - ); - object.raw_script_object().add_property( - activation.gc(), - "virtual".into(), - getter, - None, - Attribute::empty(), - ); - object.raw_script_object().add_property( - activation.gc(), - "virtual_hidden".into(), - getter, - None, - Attribute::DONT_ENUM, - ); - - let keys: Vec<_> = object.get_keys(activation, false); - assert_eq!(keys.len(), 2); - assert!(keys.contains(&"stored".into())); - assert!(!keys.contains(&"stored_hidden".into())); - assert!(keys.contains(&"virtual".into())); - assert!(!keys.contains(&"virtual_hidden".into())); - }) - } -} diff --git a/core/src/avm1/test_utils.rs b/core/src/avm1/test_utils.rs index 1ac0f65770314..adc6e2cf537aa 100644 --- a/core/src/avm1/test_utils.rs +++ b/core/src/avm1/test_utils.rs @@ -38,7 +38,7 @@ macro_rules! test_method { $( for version in &$versions { with_avm(*version, |activation, _root| -> Result<(), Error> { - let name: $crate::string::AvmString<'_> = $name.into(); + let name = crate::string::AvmString::new_utf8(activation.gc(), $name); let object = $object(activation); $( diff --git a/core/src/avm1/tests.rs b/core/src/avm1/tests.rs index d7edfa7af2021..e69de29bb2d1d 100644 --- a/core/src/avm1/tests.rs +++ b/core/src/avm1/tests.rs @@ -1,25 +0,0 @@ -use crate::avm1::error::Error; -use crate::avm1::test_utils::with_avm; -use crate::avm1::TObject; - -#[test] -fn locals_into_form_values() { - with_avm(19, |activation, _this| -> Result<(), Error> { - let my_locals = activation.scope().locals().to_owned(); - my_locals - .set("value1", "string".into(), activation) - .unwrap(); - my_locals.set("value2", 2.into(), activation).unwrap(); - let my_local_values = activation.locals_into_form_values(); - - assert_eq!(my_local_values.len(), 2); - assert_eq!(my_local_values.get("value1"), Some(&"string".to_string())); - assert_eq!(my_local_values.get("value2"), Some(&"2".to_string())); - assert_eq!( - my_local_values.keys().cloned().collect::>(), - vec!["value2".to_string(), "value1".to_string()] - ); - - Ok(()) - }); -} diff --git a/core/src/avm1/value.rs b/core/src/avm1/value.rs index a3ed038218505..8f9d424ff61b7 100644 --- a/core/src/avm1/value.rs +++ b/core/src/avm1/value.rs @@ -1104,70 +1104,6 @@ mod test { }) } - #[test] - - fn wrapping_u16() { - use super::f64_to_wrapping_u16; - assert_eq!(f64_to_wrapping_u16(0.0), 0); - assert_eq!(f64_to_wrapping_u16(1.0), 1); - assert_eq!(f64_to_wrapping_u16(-1.0), 65535); - assert_eq!(f64_to_wrapping_u16(123.1), 123); - assert_eq!(f64_to_wrapping_u16(66535.9), 999); - assert_eq!(f64_to_wrapping_u16(-9980.7), 55556); - assert_eq!(f64_to_wrapping_u16(-196608.0), 0); - assert_eq!(f64_to_wrapping_u16(f64::NAN), 0); - assert_eq!(f64_to_wrapping_u16(f64::INFINITY), 0); - assert_eq!(f64_to_wrapping_u16(f64::NEG_INFINITY), 0); - } - - #[test] - - fn wrapping_i16() { - use super::f64_to_wrapping_i16; - assert_eq!(f64_to_wrapping_i16(0.0), 0); - assert_eq!(f64_to_wrapping_i16(1.0), 1); - assert_eq!(f64_to_wrapping_i16(-1.0), -1); - assert_eq!(f64_to_wrapping_i16(123.1), 123); - assert_eq!(f64_to_wrapping_i16(32768.9), -32768); - assert_eq!(f64_to_wrapping_i16(-32769.9), 32767); - assert_eq!(f64_to_wrapping_i16(-33268.1), 32268); - assert_eq!(f64_to_wrapping_i16(-196608.0), 0); - assert_eq!(f64_to_wrapping_i16(f64::NAN), 0); - assert_eq!(f64_to_wrapping_i16(f64::INFINITY), 0); - assert_eq!(f64_to_wrapping_i16(f64::NEG_INFINITY), 0); - } - - #[test] - fn wrapping_u32() { - use super::f64_to_wrapping_u32; - assert_eq!(f64_to_wrapping_u32(0.0), 0); - assert_eq!(f64_to_wrapping_u32(1.0), 1); - assert_eq!(f64_to_wrapping_u32(-1.0), 4294967295); - assert_eq!(f64_to_wrapping_u32(123.1), 123); - assert_eq!(f64_to_wrapping_u32(4294968295.9), 999); - assert_eq!(f64_to_wrapping_u32(-4289411740.3), 5555556); - assert_eq!(f64_to_wrapping_u32(-12884901888.0), 0); - assert_eq!(f64_to_wrapping_u32(f64::NAN), 0); - assert_eq!(f64_to_wrapping_u32(f64::INFINITY), 0); - assert_eq!(f64_to_wrapping_u32(f64::NEG_INFINITY), 0); - } - - #[test] - fn wrapping_i32() { - use super::f64_to_wrapping_i32; - assert_eq!(f64_to_wrapping_i32(0.0), 0); - assert_eq!(f64_to_wrapping_i32(1.0), 1); - assert_eq!(f64_to_wrapping_i32(-1.0), -1); - assert_eq!(f64_to_wrapping_i32(123.1), 123); - assert_eq!(f64_to_wrapping_i32(4294968295.9), 999); - assert_eq!(f64_to_wrapping_i32(2147484648.3), -2147482648); - assert_eq!(f64_to_wrapping_i32(-8589934591.2), 1); - assert_eq!(f64_to_wrapping_i32(4294966896.1), -400); - assert_eq!(f64_to_wrapping_i32(f64::NAN), 0); - assert_eq!(f64_to_wrapping_i32(f64::INFINITY), 0); - assert_eq!(f64_to_wrapping_i32(f64::NEG_INFINITY), 0); - } - #[test] fn f64_to_string() { use super::f64_to_string as f64_to_avm_string; diff --git a/core/src/ecma_conversions.rs b/core/src/ecma_conversions.rs index c2d52756b6ebc..3caae9710b5da 100644 --- a/core/src/ecma_conversions.rs +++ b/core/src/ecma_conversions.rs @@ -58,10 +58,72 @@ pub fn round_to_even(n: f64) -> i32 { #[cfg(test)] mod test { - use super::round_to_even; + #[test] + fn wrapping_u16() { + use super::f64_to_wrapping_u16; + assert_eq!(f64_to_wrapping_u16(0.0), 0); + assert_eq!(f64_to_wrapping_u16(1.0), 1); + assert_eq!(f64_to_wrapping_u16(-1.0), 65535); + assert_eq!(f64_to_wrapping_u16(123.1), 123); + assert_eq!(f64_to_wrapping_u16(66535.9), 999); + assert_eq!(f64_to_wrapping_u16(-9980.7), 55556); + assert_eq!(f64_to_wrapping_u16(-196608.0), 0); + assert_eq!(f64_to_wrapping_u16(f64::NAN), 0); + assert_eq!(f64_to_wrapping_u16(f64::INFINITY), 0); + assert_eq!(f64_to_wrapping_u16(f64::NEG_INFINITY), 0); + } + + #[test] + + fn wrapping_i16() { + use super::f64_to_wrapping_i16; + assert_eq!(f64_to_wrapping_i16(0.0), 0); + assert_eq!(f64_to_wrapping_i16(1.0), 1); + assert_eq!(f64_to_wrapping_i16(-1.0), -1); + assert_eq!(f64_to_wrapping_i16(123.1), 123); + assert_eq!(f64_to_wrapping_i16(32768.9), -32768); + assert_eq!(f64_to_wrapping_i16(-32769.9), 32767); + assert_eq!(f64_to_wrapping_i16(-33268.1), 32268); + assert_eq!(f64_to_wrapping_i16(-196608.0), 0); + assert_eq!(f64_to_wrapping_i16(f64::NAN), 0); + assert_eq!(f64_to_wrapping_i16(f64::INFINITY), 0); + assert_eq!(f64_to_wrapping_i16(f64::NEG_INFINITY), 0); + } + + #[test] + fn wrapping_u32() { + use super::f64_to_wrapping_u32; + assert_eq!(f64_to_wrapping_u32(0.0), 0); + assert_eq!(f64_to_wrapping_u32(1.0), 1); + assert_eq!(f64_to_wrapping_u32(-1.0), 4294967295); + assert_eq!(f64_to_wrapping_u32(123.1), 123); + assert_eq!(f64_to_wrapping_u32(4294968295.9), 999); + assert_eq!(f64_to_wrapping_u32(-4289411740.3), 5555556); + assert_eq!(f64_to_wrapping_u32(-12884901888.0), 0); + assert_eq!(f64_to_wrapping_u32(f64::NAN), 0); + assert_eq!(f64_to_wrapping_u32(f64::INFINITY), 0); + assert_eq!(f64_to_wrapping_u32(f64::NEG_INFINITY), 0); + } + + #[test] + fn wrapping_i32() { + use super::f64_to_wrapping_i32; + assert_eq!(f64_to_wrapping_i32(0.0), 0); + assert_eq!(f64_to_wrapping_i32(1.0), 1); + assert_eq!(f64_to_wrapping_i32(-1.0), -1); + assert_eq!(f64_to_wrapping_i32(123.1), 123); + assert_eq!(f64_to_wrapping_i32(4294968295.9), 999); + assert_eq!(f64_to_wrapping_i32(2147484648.3), -2147482648); + assert_eq!(f64_to_wrapping_i32(-8589934591.2), 1); + assert_eq!(f64_to_wrapping_i32(4294966896.1), -400); + assert_eq!(f64_to_wrapping_i32(f64::NAN), 0); + assert_eq!(f64_to_wrapping_i32(f64::INFINITY), 0); + assert_eq!(f64_to_wrapping_i32(f64::NEG_INFINITY), 0); + } #[test] fn test_round_to_even() { + use super::round_to_even; assert_eq!(round_to_even(0.0), 0); assert_eq!(round_to_even(2.0), 2); assert_eq!(round_to_even(2.1), 2); diff --git a/tests/tests/swfs/avm1/geturl/output.txt b/tests/tests/swfs/avm1/geturl/output.txt new file mode 100644 index 0000000000000..5d57be0727d30 --- /dev/null +++ b/tests/tests/swfs/avm1/geturl/output.txt @@ -0,0 +1,7 @@ +Navigator::navigate_to_url: + URL: http://www.example.com + Target: _blank + Method: POST + Param: value2=2 + Param: value1=string + Param: $version=LNX 32,0,0,0 diff --git a/tests/tests/swfs/avm1/geturl/test.swf b/tests/tests/swfs/avm1/geturl/test.swf new file mode 100644 index 0000000000000..42138d4757041 Binary files /dev/null and b/tests/tests/swfs/avm1/geturl/test.swf differ diff --git a/tests/tests/swfs/avm1/geturl/test.toml b/tests/tests/swfs/avm1/geturl/test.toml new file mode 100644 index 0000000000000..10c6e791be85f --- /dev/null +++ b/tests/tests/swfs/avm1/geturl/test.toml @@ -0,0 +1,2 @@ +num_frames = 1 +log_fetch = true diff --git a/tests/tests/swfs/avm1/object_properties/output.txt b/tests/tests/swfs/avm1/object_properties/output.txt new file mode 100644 index 0000000000000..6e97f0dcb1c68 --- /dev/null +++ b/tests/tests/swfs/avm1/object_properties/output.txt @@ -0,0 +1,31 @@ +// get_undefined +undefined +// set_get +forced +natural +// set_readonly +replaced +initial +// deletable_not_readonly +false +initial +false +replaced +// virtual_get +Virtual! +Virtual! +// delete +true +false +true +false +false +undefined +Virtual! +undefined +Stored! +// get_keys +true +false +true +false diff --git a/tests/tests/swfs/avm1/object_properties/test.as b/tests/tests/swfs/avm1/object_properties/test.as new file mode 100644 index 0000000000000..3601a23e7fc1d --- /dev/null +++ b/tests/tests/swfs/avm1/object_properties/test.as @@ -0,0 +1,104 @@ +var DONT_ENUM = 1 << 0; +var DONT_DELETE = 1 << 1; +var READ_ONLY = 1 << 2; + +var runObjectTest = function(testName, testFunc) { + trace("// " + testName); + var _loc3_ = {}; + testFunc(_loc3_); +}; + +runObjectTest("get_undefined",function(o) { + trace(o.not_defined); +}); + +runObjectTest("set_get",function(o) { + o.forced = "forced"; + o.natural = "natural"; + trace(o.forced); + trace(o.natural); +}); + +runObjectTest("set_readonly",function(o) { + o.normal = "initial"; + o.readonly = "initial"; + ASSetPropFlags(o, "readonly", READ_ONLY); + o.normal = "replaced"; + o.readonly = "replaced"; + trace(o.normal); + trace(o.readonly); +}); + +runObjectTest("deletable_not_readonly",function(o) { + o.test = "initial"; + ASSetPropFlags(o, "test", DONT_DELETE); + trace(delete o.test); + trace(o.test); + o.test = "replaced"; + trace(delete o.test); + trace(o.test); +}); + +runObjectTest("virtual_get",function(o) { + var getter = function() { + return "Virtual!"; + }; + o.addProperty("test", getter, null); + trace(o.test); + o.test = "Ignored!"; + trace(o.test); +}); + +runObjectTest("delete", function(o) { + var getter = function() { + return "Virtual!"; + }; + o.addProperty("virtual", getter, null); + o.addProperty("virtual_un", getter, null); + ASSetPropFlags(o, "virtual_un", DONT_DELETE); + o.stored = "Stored!"; + o.stored_un = "Stored!"; + ASSetPropFlags(o, "stored_un", DONT_DELETE); + trace(delete o.virtual); + trace(delete o.virtual_un); + trace(delete o.stored); + trace(delete o.stored_un); + trace(delete o.non_existent); + trace(o.virtual); + trace(o.virtual_un); + trace(o.stored); + trace(o.stored_un); +}); + +runObjectTest("get_keys", function(o) { + var getter = function() { + return null; + }; + o.stored = null; + o.stored_hidden = null; + ASSetPropFlags(o, "stored_hidden", DONT_ENUM); + o.addProperty("virtual", getter, null); + o.addProperty("virtual_hidden", getter, null); + ASSetPropFlags(o, "virtual_hidden", DONT_ENUM); + + var list = []; + for (var prop in o) { + list.push(prop); + } + + var listContains = function(element) { + var i = 0; + while (i < list.length) { + if (list[i] == element) { + return true; + } + i ++; + } + return false; + }; + + trace(listContains("stored")); + trace(listContains("stored_hidden")); + trace(listContains("virtual")); + trace(listContains("virtual_hidden")); +}); diff --git a/tests/tests/swfs/avm1/object_properties/test.swf b/tests/tests/swfs/avm1/object_properties/test.swf new file mode 100644 index 0000000000000..4e10391ab0e85 Binary files /dev/null and b/tests/tests/swfs/avm1/object_properties/test.swf differ diff --git a/tests/tests/swfs/avm1/object_properties/test.toml b/tests/tests/swfs/avm1/object_properties/test.toml new file mode 100644 index 0000000000000..dbee897f5863d --- /dev/null +++ b/tests/tests/swfs/avm1/object_properties/test.toml @@ -0,0 +1 @@ +num_frames = 1 diff --git a/tests/tests/swfs/avm1/swf5_global_funcs/output.txt b/tests/tests/swfs/avm1/swf5_global_funcs/output.txt new file mode 100644 index 0000000000000..d2b7f5b834800 --- /dev/null +++ b/tests/tests/swfs/avm1/swf5_global_funcs/output.txt @@ -0,0 +1,232 @@ +NaN +0.9 +-0.9 +-2 +-1 +0.5 +0.1 +-0.5 +-0.1 +0 +3 +2 +1 +Infinity +-Infinity +NaN +NaN +12 +NaN +12 +NaN +-37777777777 +37777777777 +10 +10 +-10 +10 +-10 +37777777777 +NaN +NaN +NaN +NaN +12.3 +NaN +NaN +NaN +NaN +NaN +5 +NaN +NaN +NaN +NaN +NaN +NaN +NaN +NaN +-5 +1 +0 +NaN +NaN +0 +1 +0 +0 +0 +false +true +true +true +true +true +true +true +true +true +true +true +true +false +false +false +false +true +false +true +false +true +true +true +true +true +true +true +true +false +false +false +false +true +false +false +false +false +false +true +false +false +false +false +false +false +false +false +true +true +true +false +false +true +true +true +true +false +true +false +false +false +false +false +false +false +false +false +false +false +false +false +false +true +true +false +true +false +true +false +false +false +false +false +false +false +false +true +true +true +true +false +true +true +true +true +true +false +true +true +true +true +true +true +true +true +false +false +false +true +true +false +false +false +false +true +true +true +true +true +true +true +true +true +true +false +true +true +true +true +true +false +false +true +false +true +false +true +true +true +true +true +true +true +true +false +false +false +false +true +false +false +false +false +false +true +false +false +false +false +false +false +false +false +true +true +false +false +false +false +true +false +false +undefined diff --git a/tests/tests/swfs/avm1/swf5_global_funcs/test.as b/tests/tests/swfs/avm1/swf5_global_funcs/test.as new file mode 100644 index 0000000000000..f8a938f1951a5 --- /dev/null +++ b/tests/tests/swfs/avm1/swf5_global_funcs/test.as @@ -0,0 +1,10 @@ +var funcs = [Boolean, isNaN, isFinite, Number]; +var values = [null, undefined, true, false, "true", "false", "0", "1", "-5", "True", "False", "Infinity", "-Infinity", "NaN", "", " ", "Hello", " 5", " 5 ", "inf", "-inf", "100a", "0xhello", "123e-1", "0xUIXUIDFKHJDF012345678", "0x12", "0x10", "0x1999999981ffffff", "037777777777", "-010", "+010", " -010", " +010", " 010", "037777777777", "-037777777777", "Hello", "\t\r12", "\r12\r", " \t 12", -NaN, NaN, -Infinity, Infinity, 1, 2, 3, 0, -0.1, -0.5, 0.1, 0.5, -1, -2, -0.9, 0.9, {}]; +for (var i in funcs) { + var func = funcs[i]; + for (var j in values) { + var value = values[j]; + trace(func(value)); + } + trace(func()); +} diff --git a/tests/tests/swfs/avm1/swf5_global_funcs/test.swf b/tests/tests/swfs/avm1/swf5_global_funcs/test.swf new file mode 100644 index 0000000000000..428c16a81290d Binary files /dev/null and b/tests/tests/swfs/avm1/swf5_global_funcs/test.swf differ diff --git a/tests/tests/swfs/avm1/swf5_global_funcs/test.toml b/tests/tests/swfs/avm1/swf5_global_funcs/test.toml new file mode 100644 index 0000000000000..dbee897f5863d --- /dev/null +++ b/tests/tests/swfs/avm1/swf5_global_funcs/test.toml @@ -0,0 +1 @@ +num_frames = 1 diff --git a/tests/tests/swfs/avm1/swf6_global_funcs/output.txt b/tests/tests/swfs/avm1/swf6_global_funcs/output.txt new file mode 100644 index 0000000000000..3c0300b221720 --- /dev/null +++ b/tests/tests/swfs/avm1/swf6_global_funcs/output.txt @@ -0,0 +1,232 @@ +NaN +0.9 +-0.9 +-2 +-1 +0.5 +0.1 +-0.5 +-0.1 +0 +3 +2 +1 +Infinity +-Infinity +NaN +NaN +12 +NaN +12 +NaN +1 +-1 +10 +10 +-10 +8 +-8 +-1 +-2113929217 +16 +18 +NaN +12.3 +NaN +NaN +NaN +NaN +NaN +5 +NaN +NaN +NaN +NaN +NaN +NaN +NaN +NaN +-5 +1 +0 +NaN +NaN +0 +1 +0 +0 +0 +false +true +true +true +true +true +true +true +true +true +true +true +true +false +false +false +false +true +false +true +false +true +true +true +true +true +true +true +true +true +true +true +false +true +false +false +false +false +false +true +false +false +false +false +false +false +false +false +true +true +true +false +false +true +true +true +true +false +true +false +false +false +false +false +false +false +false +false +false +false +false +false +false +true +true +false +true +false +true +false +false +false +false +false +false +false +false +false +false +false +true +false +true +true +true +true +true +false +true +true +true +true +true +true +true +true +false +false +false +true +true +false +false +false +false +true +true +true +true +true +true +true +true +true +true +false +true +true +true +true +true +false +false +true +false +true +false +true +true +true +true +true +true +true +true +true +true +true +false +true +false +false +false +false +false +true +false +false +false +false +false +false +false +false +true +true +false +false +false +false +true +false +false +undefined diff --git a/tests/tests/swfs/avm1/swf6_global_funcs/test.as b/tests/tests/swfs/avm1/swf6_global_funcs/test.as new file mode 100644 index 0000000000000..f8a938f1951a5 --- /dev/null +++ b/tests/tests/swfs/avm1/swf6_global_funcs/test.as @@ -0,0 +1,10 @@ +var funcs = [Boolean, isNaN, isFinite, Number]; +var values = [null, undefined, true, false, "true", "false", "0", "1", "-5", "True", "False", "Infinity", "-Infinity", "NaN", "", " ", "Hello", " 5", " 5 ", "inf", "-inf", "100a", "0xhello", "123e-1", "0xUIXUIDFKHJDF012345678", "0x12", "0x10", "0x1999999981ffffff", "037777777777", "-010", "+010", " -010", " +010", " 010", "037777777777", "-037777777777", "Hello", "\t\r12", "\r12\r", " \t 12", -NaN, NaN, -Infinity, Infinity, 1, 2, 3, 0, -0.1, -0.5, 0.1, 0.5, -1, -2, -0.9, 0.9, {}]; +for (var i in funcs) { + var func = funcs[i]; + for (var j in values) { + var value = values[j]; + trace(func(value)); + } + trace(func()); +} diff --git a/tests/tests/swfs/avm1/swf6_global_funcs/test.swf b/tests/tests/swfs/avm1/swf6_global_funcs/test.swf new file mode 100644 index 0000000000000..abf5a55616dc2 Binary files /dev/null and b/tests/tests/swfs/avm1/swf6_global_funcs/test.swf differ diff --git a/tests/tests/swfs/avm1/swf6_global_funcs/test.toml b/tests/tests/swfs/avm1/swf6_global_funcs/test.toml new file mode 100644 index 0000000000000..dbee897f5863d --- /dev/null +++ b/tests/tests/swfs/avm1/swf6_global_funcs/test.toml @@ -0,0 +1 @@ +num_frames = 1 diff --git a/tests/tests/swfs/avm1/swf7_global_funcs/output.txt b/tests/tests/swfs/avm1/swf7_global_funcs/output.txt new file mode 100644 index 0000000000000..d2a6efb6516a2 --- /dev/null +++ b/tests/tests/swfs/avm1/swf7_global_funcs/output.txt @@ -0,0 +1,232 @@ +NaN +0.9 +-0.9 +-2 +-1 +0.5 +0.1 +-0.5 +-0.1 +0 +3 +2 +1 +Infinity +-Infinity +NaN +NaN +12 +NaN +12 +NaN +1 +-1 +10 +10 +-10 +8 +-8 +-1 +-2113929217 +16 +18 +NaN +12.3 +NaN +NaN +NaN +NaN +NaN +5 +NaN +NaN +NaN +NaN +NaN +NaN +NaN +NaN +-5 +1 +0 +NaN +NaN +0 +1 +NaN +NaN +0 +false +true +true +true +true +true +true +true +true +true +true +true +true +false +false +false +false +true +false +true +false +true +true +true +true +true +true +true +true +true +true +true +false +true +false +false +false +false +false +true +false +false +false +false +false +false +false +false +true +true +true +false +false +true +true +false +false +false +true +false +false +false +false +false +false +false +false +false +false +false +false +false +false +true +true +false +true +false +true +false +false +false +false +false +false +false +false +false +false +false +true +false +true +true +true +true +true +false +true +true +true +true +true +true +true +true +false +false +false +true +true +false +false +true +true +true +true +true +true +true +true +true +true +true +true +false +true +true +true +true +true +false +false +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +false +true +true +true +true +true +true +true +true +true +true +false +true +false +false +undefined diff --git a/tests/tests/swfs/avm1/swf7_global_funcs/test.as b/tests/tests/swfs/avm1/swf7_global_funcs/test.as new file mode 100644 index 0000000000000..f8a938f1951a5 --- /dev/null +++ b/tests/tests/swfs/avm1/swf7_global_funcs/test.as @@ -0,0 +1,10 @@ +var funcs = [Boolean, isNaN, isFinite, Number]; +var values = [null, undefined, true, false, "true", "false", "0", "1", "-5", "True", "False", "Infinity", "-Infinity", "NaN", "", " ", "Hello", " 5", " 5 ", "inf", "-inf", "100a", "0xhello", "123e-1", "0xUIXUIDFKHJDF012345678", "0x12", "0x10", "0x1999999981ffffff", "037777777777", "-010", "+010", " -010", " +010", " 010", "037777777777", "-037777777777", "Hello", "\t\r12", "\r12\r", " \t 12", -NaN, NaN, -Infinity, Infinity, 1, 2, 3, 0, -0.1, -0.5, 0.1, 0.5, -1, -2, -0.9, 0.9, {}]; +for (var i in funcs) { + var func = funcs[i]; + for (var j in values) { + var value = values[j]; + trace(func(value)); + } + trace(func()); +} diff --git a/tests/tests/swfs/avm1/swf7_global_funcs/test.swf b/tests/tests/swfs/avm1/swf7_global_funcs/test.swf new file mode 100644 index 0000000000000..eeaea811ba192 Binary files /dev/null and b/tests/tests/swfs/avm1/swf7_global_funcs/test.swf differ diff --git a/tests/tests/swfs/avm1/swf7_global_funcs/test.toml b/tests/tests/swfs/avm1/swf7_global_funcs/test.toml new file mode 100644 index 0000000000000..dbee897f5863d --- /dev/null +++ b/tests/tests/swfs/avm1/swf7_global_funcs/test.toml @@ -0,0 +1 @@ +num_frames = 1