45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
use pixstrip_core::operations::MetadataConfig;
|
|
use pixstrip_core::operations::metadata::strip_metadata;
|
|
use std::path::Path;
|
|
|
|
fn create_test_jpeg(path: &Path) {
|
|
let img = image::RgbImage::from_fn(100, 80, |x, y| {
|
|
image::Rgb([(x % 256) as u8, (y % 256) as u8, 128])
|
|
});
|
|
img.save_with_format(path, image::ImageFormat::Jpeg).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn strip_all_metadata_produces_file() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let input = dir.path().join("test.jpg");
|
|
let output = dir.path().join("stripped.jpg");
|
|
create_test_jpeg(&input);
|
|
|
|
strip_metadata(&input, &output, &MetadataConfig::StripAll).unwrap();
|
|
assert!(output.exists());
|
|
assert!(std::fs::metadata(&output).unwrap().len() > 0);
|
|
}
|
|
|
|
#[test]
|
|
fn keep_all_metadata_copies_file() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let input = dir.path().join("test.jpg");
|
|
let output = dir.path().join("kept.jpg");
|
|
create_test_jpeg(&input);
|
|
|
|
strip_metadata(&input, &output, &MetadataConfig::KeepAll).unwrap();
|
|
assert!(output.exists());
|
|
}
|
|
|
|
#[test]
|
|
fn privacy_mode_strips_gps() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let input = dir.path().join("test.jpg");
|
|
let output = dir.path().join("privacy.jpg");
|
|
create_test_jpeg(&input);
|
|
|
|
strip_metadata(&input, &output, &MetadataConfig::Privacy).unwrap();
|
|
assert!(output.exists());
|
|
}
|