Skip to content

Commit

Permalink
Cartridge: added tests for error types
Browse files Browse the repository at this point in the history
  • Loading branch information
Amjad50 committed Aug 20, 2020
1 parent 2849714 commit 7a8194f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions cartridge/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,58 @@
mod cartridge_tests {
use crate::{Cartridge, CartridgeError};

#[test]
fn cartridge_file_not_found() {
let err = Cartridge::from_file("./file/does/not/exists.nes")
.err()
.expect("Should get an error as the cartridge file does not exists");

if let CartridgeError::FileError(file_err) = err {
assert_eq!(file_err.kind(), std::io::ErrorKind::NotFound);
} else {
panic!("Should get file not found error");
}
}

#[test]
fn cartridge_extension_error_file() {
let err = Cartridge::from_file("./file/does/not/exists.notnes")
.err()
.expect("Should get an error as the cartridge has extension error");

if let CartridgeError::ExtensionError = err {
// passed
} else {
panic!("Should get extension error");
}
}

#[test]
fn cartridge_wrong_header() {
let err = Cartridge::from_file("./tests/roms/test_wrong_header.nes")
.err()
.expect("Should get an error as the cartridge has wrong header");

if let CartridgeError::HeaderError = err {
// passed
} else {
panic!("Should get header error");
}
}

#[test]
fn cartridge_large_file() {
let err = Cartridge::from_file("./tests/roms/test_large_file.nes")
.err()
.expect("Should get an error as the cartridge file is larger than expected");

if let CartridgeError::TooLargeFile(exceeded_size) = err {
assert_eq!(exceeded_size, 1);
} else {
panic!("Should get too large file error");
}
}

#[test]
fn test_ines1_cartridge_read() -> Result<(), CartridgeError> {
let cartridge = Cartridge::from_file("./tests/roms/test_creation.nes")?;
Expand Down
Binary file added cartridge/tests/roms/test_large_file.nes
Binary file not shown.
Binary file added cartridge/tests/roms/test_wrong_header.nes
Binary file not shown.

0 comments on commit 7a8194f

Please sign in to comment.