tests: Add stage_object_properties test

This commit is contained in:
Mike Welsh 2019-12-11 20:27:32 -08:00
parent c9864eb557
commit e36dbad7d2
4 changed files with 97 additions and 13 deletions

View File

@ -2,7 +2,7 @@
//!
//! Trace output can be compared with correct output from the official Flash Payer.
use approx::abs_diff_eq;
use approx::assert_abs_diff_eq;
use log::{Metadata, Record};
use ruffle_core::backend::{
audio::NullAudioBackend, navigator::NullNavigatorBackend, render::NullRenderer,
@ -111,19 +111,23 @@ fn test_stage_object_enumerate() -> Result<(), Error> {
#[test]
fn test_stage_object_properties() -> Result<(), Error> {
let trace_log = run_swf("tests/swfs/avm1/stage_object_properties/test.swf", 1)?;
let actual: Vec<f64> = trace_log
.lines()
.map(|s| str::parse::<f64>(s).unwrap())
.collect();
let expected: Vec<f64> =
std::fs::read_to_string("tests/swfs/avm1/stage_object_properties/output.txt")?
.lines()
.map(|s| str::parse::<f64>(s).unwrap())
.collect();
let trace_log = run_swf("tests/swfs/avm1/stage_object_properties/test.swf", 4)?;
let expected_data =
std::fs::read_to_string("tests/swfs/avm1/stage_object_properties/output.txt")?;
assert_eq!(
trace_log.lines().count(),
expected_data.lines().count(),
"# of lines of output didn't match"
);
for (actual, expected) in actual.into_iter().zip(expected.into_iter()) {
abs_diff_eq!(actual, expected, epsilon = 0.0001);
for (actual, expected) in trace_log.lines().zip(expected_data.lines()) {
// If these are numbers, compare using approx_eq.
if let (Ok(actual), Ok(expected)) = (actual.parse::<f64>(), expected.parse::<f64>()) {
// TODO: Lower this epsilon as the accuracy of the properties improves.
assert_abs_diff_eq!(actual, expected, epsilon = 0.5);
} else {
assert_eq!(actual, expected);
}
}
Ok(())
}

View File

@ -0,0 +1,80 @@
Starting properties:
289.25
202.1
805.95
656.75
-162.038711547852
249.484237591759
301.023390825966
100
true
Setting with SetMember...
Final properties:
123
321
673.2
515.45
27
-321
123
50
false
Starting properties:
123
321
673.2
515.45
27
-321
123
50
false
Setting with SetProperty...
Final properties:
100
200
153.3
882
90
345
-123
25
true
Testing ranges...
_x:
_y:
_rotation:
90
180
-179
-180
179
_xscale:
345
_yscale:
-123
_scale:
-123
_alpha:
25
_currentframe:
1
_totalframes:
1
Testing width/height...
370.05
108.1
54.0467504391298
100
200.05
108.1
54.0467504391298
54.05
92.5
200
100
25
92.5
50
24.9966220780976
25

Binary file not shown.

Binary file not shown.