swf: Add tests for errors on incorrect parse

This commit is contained in:
Mike Welsh 2019-10-10 00:41:14 -07:00
parent 3058b88011
commit 93a221aea4
2 changed files with 26 additions and 0 deletions

View File

@ -404,6 +404,19 @@ pub mod tests {
}
}
/// Ensure that we return an error on invalid data.
#[test]
fn read_parse_error() {
let action_bytes = [0xff, 0xff, 0xff, 0x00, 0x00];
let mut reader = Reader::new(&action_bytes[..], 5);
match reader.read_action() {
Err(crate::error::Error::Avm1ParseError { .. }) => (),
result => {
panic!("Expected Avm1ParseError, got {:?}", result);
}
}
}
#[test]
fn read_define_function() {
// Ensure we read a function properly along with the function data.

View File

@ -3136,4 +3136,17 @@ pub mod tests {
assert_eq!(reader.read_tag_list().unwrap(), [Tag::ShowFrame]);
}
}
/// Ensure that we return an error on invalid data.
#[test]
fn read_invalid_tag() {
let tag_bytes = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
let mut reader = Reader::new(&tag_bytes[..], 5);
match reader.read_tag() {
Err(crate::error::Error::SwfParseError { .. }) => (),
result => {
panic!("Expected SwfParseError, got {:?}", result);
}
}
}
}