-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1432 from HeroicKatora/issue-1428-tga
Issue 1428 tga
- Loading branch information
Showing
11 changed files
with
122 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::path::PathBuf; | ||
|
||
const BASE_PATH: [&str; 2] = [".", "tests"]; | ||
const IMAGE_DIR: &str = "images"; | ||
const REGRESSION_DIR: &str = "regression"; | ||
|
||
fn process_images<F>(dir: &str, input_decoder: Option<&str>, func: F) | ||
where | ||
F: Fn(PathBuf), | ||
{ | ||
let base: PathBuf = BASE_PATH.iter().collect(); | ||
let decoders = &["tga", "tiff", "png", "gif", "bmp", "ico", "jpg", "hdr", "pbm", "webp"]; | ||
for decoder in decoders { | ||
let mut path = base.clone(); | ||
path.push(dir); | ||
path.push(decoder); | ||
path.push("**"); | ||
path.push( | ||
"*.".to_string() + match input_decoder { | ||
Some(val) => val, | ||
None => decoder, | ||
}, | ||
); | ||
let pattern = &*format!("{}", path.display()); | ||
for path in glob::glob(pattern).unwrap().filter_map(Result::ok) { | ||
func(path) | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn check_regressions() { | ||
process_images(REGRESSION_DIR, None, |path| { | ||
let _ = image::open(path); | ||
}) | ||
} | ||
|
||
/// Check that BMP files with large values could cause OOM issues are rejected. | ||
/// | ||
/// The images are postfixed with `bad_bmp` to not be loaded by the other test. | ||
#[test] | ||
fn bad_bmps() { | ||
let path: PathBuf = BASE_PATH | ||
.iter() | ||
.collect::<PathBuf>() | ||
.join(IMAGE_DIR) | ||
.join("bmp/images") | ||
.join("*.bad_bmp"); | ||
|
||
let pattern = &*format!("{}", path.display()); | ||
for path in glob::glob(pattern).unwrap().filter_map(Result::ok) { | ||
let im = image::open(path); | ||
assert!(im.is_err()); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.