Skip to content

Commit

Permalink
tests: Add avm2/filereference_save_and_load test
Browse files Browse the repository at this point in the history
This test ensures that the error 2037 is thrown
when load is called after save.

It's currently a known failure as Ruffle is not as strict as FP
regarding throwing the error 2037.
  • Loading branch information
kjarosh authored and Dinnerbone committed May 7, 2024
1 parent 6ea64c9 commit d852c74
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/tests/swfs/avm2/filereference_save_and_load/Test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package {
import flash.display.Sprite;
public class Test extends Sprite { }
}

import flash.net.FileReference;
import flash.net.FileFilter;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.utils.setTimeout;

var file = new FileReference();

function dump(file) {
try {
trace("file.name: " + file.name);
} catch (e) {
trace("file.name threw: " + e);
}

try {
trace("file.size: " + file.size);
} catch (e) {
trace("file.size threw: " + e);
}

trace("file.data: " + file.data);
trace("");
}

function onopen(e) {
trace("open event");
dump(e.target);
}

function onprogress(e) {
trace("progress event");
trace(e.bytesLoaded + " / " + e.bytesTotal);
dump(e.target);
}

function oncomplete(e) {
trace("complete event");
dump(e.target);

try {
file.load();
} catch(e) {
trace("Error: " + e);
}
}

function onselect(e) {
trace("select event");
dump(e.target);
}

function oncancel(e) {
trace("cancel event");
dump(e.target);
}

file.addEventListener(Event.OPEN, onopen);
file.addEventListener(ProgressEvent.PROGRESS, onprogress);
file.addEventListener(Event.COMPLETE, oncomplete);
file.addEventListener(Event.SELECT, onselect);
file.addEventListener(Event.CANCEL, oncancel);

file.save("Hello, World!", "debug-success.txt");
22 changes: 22 additions & 0 deletions tests/tests/swfs/avm2/filereference_save_and_load/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
select event
file.name: debug-success.txt
file.size: 0
file.data: null

open event
file.name: debug-success.txt
file.size: 0
file.data: null

progress event
13 / 13
file.name: debug-success.txt
file.size: 0
file.data: null

complete event
file.name: debug-success.txt
file.size: 13
file.data: null

Error: Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/tests/swfs/avm2/filereference_save_and_load/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
num_ticks = 1

# FIXME FP is more strict regarding the error 2037
known_failure = true

# this test currently overflows the stack
ignore = true

0 comments on commit d852c74

Please sign in to comment.