diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/jpeg-decoder/tests | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/jpeg-decoder/tests')
-rw-r--r-- | vendor/jpeg-decoder/tests/lib.rs | 155 | ||||
-rw-r--r-- | vendor/jpeg-decoder/tests/rayon-0.rs | 16 | ||||
-rw-r--r-- | vendor/jpeg-decoder/tests/rayon-1.rs | 18 | ||||
-rw-r--r-- | vendor/jpeg-decoder/tests/rayon-2.rs | 23 | ||||
-rw-r--r-- | vendor/jpeg-decoder/tests/rayon.rs | 16 |
5 files changed, 228 insertions, 0 deletions
diff --git a/vendor/jpeg-decoder/tests/lib.rs b/vendor/jpeg-decoder/tests/lib.rs new file mode 100644 index 0000000..b6a87c1 --- /dev/null +++ b/vendor/jpeg-decoder/tests/lib.rs @@ -0,0 +1,155 @@ +extern crate jpeg_decoder as jpeg; +extern crate png; +extern crate walkdir; + +use std::path::Path; +use std::fs::File; + +mod common; +mod crashtest; +mod reftest; + +#[test] +#[wasm_bindgen_test::wasm_bindgen_test] +fn included_file() { + const FILE: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/reftest/images/mozilla/jpg-progressive.jpg")); + + let mut data = FILE; + let mut decoder = jpeg::Decoder::new(&mut data); + let ref_data = decoder.decode().unwrap(); + let ref_info = decoder.info().unwrap(); + + let mut data = FILE; + decoder = jpeg::Decoder::new(&mut data); + decoder.read_info().unwrap(); + let info = decoder.info().unwrap(); + let data = decoder.decode().unwrap(); + + assert_eq!(info, decoder.info().unwrap()); + assert_eq!(info, ref_info); + assert_eq!(data, ref_data); +} + +#[test] +fn read_info() { + let path = Path::new("tests").join("reftest").join("images").join("mozilla").join("jpg-progressive.jpg"); + + let mut decoder = jpeg::Decoder::new(File::open(&path).unwrap()); + let ref_data = decoder.decode().unwrap(); + let ref_info = decoder.info().unwrap(); + + decoder = jpeg::Decoder::new(File::open(&path).unwrap()); + decoder.read_info().unwrap(); + let info = decoder.info().unwrap(); + let data = decoder.decode().unwrap(); + + assert_eq!(info, decoder.info().unwrap()); + assert_eq!(info, ref_info); + assert_eq!(data, ref_data); +} + +#[test] +fn read_icc_profile() { + let path = Path::new("tests") + .join("reftest") + .join("images") + .join("mozilla") + .join("jpg-srgb-icc.jpg"); + + let mut decoder = jpeg::Decoder::new(File::open(&path).unwrap()); + decoder.decode().unwrap(); + + let profile = decoder.icc_profile().unwrap(); + // "acsp" is a mandatory string in ICC profile headers. + assert_eq!(&profile[36..40], b"acsp"); +} + +// Test if chunks are concatenated in the correct order +#[test] +fn read_icc_profile_random_order() { + let path = Path::new("tests") + .join("icc") + .join("icc_chunk_order.jpeg"); + + let mut decoder = jpeg::Decoder::new(File::open(&path).unwrap()); + decoder.decode().unwrap(); + + let profile = decoder.icc_profile().unwrap(); + + assert_eq!(profile.len(), 254); + + for i in 1..=254 { + assert_eq!(profile[i - 1], i as u8); + } +} + +// Check if ICC profiles with invalid chunk number 0 are discarded +#[test] +fn read_icc_profile_seq_no_0() { + let path = Path::new("tests") + .join("icc") + .join("icc_chunk_seq_no_0.jpeg"); + + let mut decoder = jpeg::Decoder::new(File::open(&path).unwrap()); + decoder.decode().unwrap(); + + let profile = decoder.icc_profile(); + assert!(profile.is_none()); +} + +// Check if ICC profiles with multiple chunks with the same number are discarded +#[test] +fn read_icc_profile_double_seq_no() { + let path = Path::new("tests") + .join("icc") + .join("icc_chunk_double_seq_no.jpeg"); + + let mut decoder = jpeg::Decoder::new(File::open(&path).unwrap()); + decoder.decode().unwrap(); + + let profile = decoder.icc_profile(); + assert!(profile.is_none()); +} + +// Check if ICC profiles with mismatching number of chunks and total chunk count are discarded +#[test] +fn read_icc_profile_chunk_count_mismatch() { + let path = Path::new("tests") + .join("icc") + .join("icc_chunk_count_mismatch.jpeg"); + + let mut decoder = jpeg::Decoder::new(File::open(&path).unwrap()); + decoder.decode().unwrap(); + + let profile = decoder.icc_profile(); + assert!(profile.is_none()); +} + +// Check if ICC profiles with missing chunk are discarded +#[test] +fn read_icc_profile_missing_chunk() { + let path = Path::new("tests") + .join("icc") + .join("icc_missing_chunk.jpeg"); + + let mut decoder = jpeg::Decoder::new(File::open(&path).unwrap()); + decoder.decode().unwrap(); + + let profile = decoder.icc_profile(); + assert!(profile.is_none()); +} + +#[test] +fn read_exif_data() { + let path = Path::new("tests") + .join("reftest") + .join("images") + .join("ycck.jpg"); + + let mut decoder = jpeg::Decoder::new(File::open(&path).unwrap()); + decoder.decode().unwrap(); + + let exif_data = decoder.exif_data().unwrap(); + // exif data start as a TIFF header + assert_eq!(&exif_data[0..8], b"\x49\x49\x2A\x00\x08\x00\x00\x00"); +} diff --git a/vendor/jpeg-decoder/tests/rayon-0.rs b/vendor/jpeg-decoder/tests/rayon-0.rs new file mode 100644 index 0000000..484816c --- /dev/null +++ b/vendor/jpeg-decoder/tests/rayon-0.rs @@ -0,0 +1,16 @@ +//! Must be a separate test because it modifies the _global_ rayon pool. +use std::{fs::File, path::Path}; +use jpeg_decoder::Decoder; + +#[test] +fn decoding_in_global_pool() { + let path = Path::new("tests").join("reftest").join("images").join("mozilla").join("jpg-progressive.jpg"); + + rayon::ThreadPoolBuilder::new() + .num_threads(1) + .build_global() + .unwrap(); + + let mut decoder = Decoder::new(File::open(&path).unwrap()); + let _ = decoder.decode().unwrap(); +} diff --git a/vendor/jpeg-decoder/tests/rayon-1.rs b/vendor/jpeg-decoder/tests/rayon-1.rs new file mode 100644 index 0000000..e6bd896 --- /dev/null +++ b/vendor/jpeg-decoder/tests/rayon-1.rs @@ -0,0 +1,18 @@ +//! Must be a separate test because it modifies the _global_ rayon pool. +use std::{fs::File, path::Path}; +use jpeg_decoder::Decoder; + +#[test] +fn decoding_in_fetched_global_pool() { + let path = Path::new("tests").join("reftest").join("images").join("mozilla").join("jpg-progressive.jpg"); + + rayon::ThreadPoolBuilder::new() + .num_threads(1) + .build_global() + .unwrap(); + + rayon::scope(|_| { + let mut decoder = Decoder::new(File::open(&path).unwrap()); + let _ = decoder.decode().unwrap(); + }) +} diff --git a/vendor/jpeg-decoder/tests/rayon-2.rs b/vendor/jpeg-decoder/tests/rayon-2.rs new file mode 100644 index 0000000..982f837 --- /dev/null +++ b/vendor/jpeg-decoder/tests/rayon-2.rs @@ -0,0 +1,23 @@ +//! Must be a separate test because it modifies the _global_ rayon pool. +use std::{fs::File, path::Path}; +use jpeg_decoder::Decoder; + +#[test] +fn decoding_in_global_pool() { + let path = Path::new("tests/reftest/images/progressive3.jpg"); + + rayon::ThreadPoolBuilder::new() + .num_threads(2) + .build_global() + .unwrap(); + + let _: Vec<_> = (0..1024) + .map(|_| { + let path = path.clone(); + std::thread::spawn(move || { + let mut decoder = Decoder::new(File::open(&path).unwrap()); + let _ = decoder.decode().unwrap(); + }); + }).collect(); +} + diff --git a/vendor/jpeg-decoder/tests/rayon.rs b/vendor/jpeg-decoder/tests/rayon.rs new file mode 100644 index 0000000..9222a85 --- /dev/null +++ b/vendor/jpeg-decoder/tests/rayon.rs @@ -0,0 +1,16 @@ +use std::{fs::File, path::Path}; +use jpeg_decoder::Decoder; + +#[test] +fn decoding_in_limited_threadpool_does_not_deadlock() { + let path = Path::new("tests").join("reftest").join("images").join("mozilla").join("jpg-progressive.jpg"); + + let pool = rayon::ThreadPoolBuilder::new() + .num_threads(1) + .build() + .unwrap(); + pool.install(|| { + let mut decoder = Decoder::new(File::open(&path).unwrap()); + let _ = decoder.decode().unwrap(); + }); +} |