Skip to content

Commit

Permalink
tests: Add form loader encoding tests
Browse files Browse the repository at this point in the history
Several form loader encoding tests have been added. They test whether
the form loader uses the correct encoding to decode text files with
different SWF versions and settings.
  • Loading branch information
Korne127 committed Jun 19, 2024
1 parent df017bc commit cda78ae
Show file tree
Hide file tree
Showing 23 changed files with 95 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/framework/src/backends/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@ impl SuccessResponse for TestResponse {
Box::pin(async move { Ok(self.body) })
}

fn next_chunk(&mut self) -> OwnedFuture<Option<Vec<u8>>, Error> {
if !self.chunk_gotten {
self.chunk_gotten = true;
let body = self.body.clone();
Box::pin(async move { Ok(Some(body)) })
} else {
Box::pin(async move { Ok(None) })
}
fn text_encoding(&self) -> Option<&'static Encoding> {
None
}

fn status(&self) -> u16 {
Expand All @@ -52,12 +46,18 @@ impl SuccessResponse for TestResponse {
self.redirected
}

fn expected_length(&self) -> Result<Option<u64>, Error> {
Ok(Some(self.body.len() as u64))
fn next_chunk(&mut self) -> OwnedFuture<Option<Vec<u8>>, Error> {
if !self.chunk_gotten {
self.chunk_gotten = true;
let body = self.body.clone();
Box::pin(async move { Ok(Some(body)) })
} else {
Box::pin(async move { Ok(None) })
}
}

fn text_encoding(&self) -> Option<&'static Encoding> {
None
fn expected_length(&self) -> Result<Option<u64>, Error> {
Ok(Some(self.body.len() as u64))
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_1/UTF8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
utf8_var=UTF8: ÄÖÜ ß - 片仮名
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_1/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF8: ÄÖÜ ß - 片仮名
18 changes: 18 additions & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_1/test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SWF Version 6

/*
* This test is the first test out of a series of tests, testing the encoding the form loader uses to decode
* text files.
* This test tests whether a UTF-8 text file loaded in an SWF file with SWF version 6 is decoded as UTF-8.
* Flash decodes invalid UTF-8 characters (such as some characters encoded in ISO Latin-1) differently, and
* as of June 2024, Ruffle doesn't implement this. Therefore, this test only tests a UTF-8 file.
*/

loadVariablesNum("UTF8.txt", 0);

this.onEnterFrame = function() {
if (this.utf8_var != undefined) {
trace(this.utf8_var);
this.onEnterFrame = null;
}
};
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_1/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_frames = 3
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_2/Iso.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
iso_var=Iso Latin-1: ��� �
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_2/Shift Jis.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shift_var=Shift Jis: �Љ���
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_2/UTF8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
utf8_var=UTF8: ÄÖÜ ß - 片仮
3 changes: 3 additions & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_2/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UTF8: ÄÖÜ ß - 片仮
Iso Latin-1: ÄÖÜ ß
Shift Jis: •Ð‰¼–¼
23 changes: 23 additions & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_2/test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SWF Version 5

/*
* This test is the second test out of a series of tests, testing the encoding the form loader uses to decode
* text files.
* This test tests whether text files loaded in an SWF file with SWF version 5 are decoded as Windows-1252.
* Flash decodes these files as Windows-1252 on Windows. On macOS, a different custom encoding is used (with
* the letters with diacritics having the same encoding as in Windows-1252).
*/

// ActionScript code in Frame 1

loadVariablesNum("UTF8.txt", 0);
loadVariablesNum("Iso.txt", 0);
loadVariablesNum("Shift Jis.txt", 0);


// ActionScript code in Frame 3

trace(this.utf8_var);
trace(this.iso_var);
trace(this.shift_var);
stop();
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_2/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_frames = 3
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_3/Iso.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
iso_var=Iso Latin-1: ��� �
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_3/Shift Jis.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shift_var=Shift Jis: �Љ���
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_3/UTF8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
utf8_var=UTF8: ÄÖÜ ß - 片仮名
3 changes: 3 additions & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_3/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UTF8: ÄÖÜ ß - 片仮名
Iso Latin-1: ÄÖÜ ß
Shift Jis: 片仮名
25 changes: 25 additions & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_3/test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SWF Version 6

/*
* This test is the third test out of a series of tests, testing the encoding the form loader uses to decode
* text files.
* This test tests whether text files loaded with System#useCodepage set to true are decoded correctly.
* While Flash uses the system codepage, Ruffle doesn't always have access to it, and it's not reliably the
* correct encoding. Therefore, when System#useCodepage is set to true, text files in different encodings
* should all be decoded correctly.
*/

System.useCodepage = true;

loadVariablesNum("UTF8.txt", 0);
loadVariablesNum("Iso.txt", 0);
loadVariablesNum("Shift Jis.txt", 0);

this.onEnterFrame = function() {
if (this.utf8_var != undefined && this.iso_var != undefined && this.shift_var != undefined) {
trace(this.utf8_var);
trace(this.iso_var);
trace(this.shift_var);
this.onEnterFrame = null;
}
};
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/form_loader_encoding_3/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_frames = 3

0 comments on commit cda78ae

Please sign in to comment.