2022-10-02 15:02:15 +02:00
|
|
|
use std::sync::Once;
|
2021-10-23 17:18:52 +02:00
|
|
|
|
2023-02-25 20:39:52 +01:00
|
|
|
use crate::cleanup::remove_compressed_test_file;
|
|
|
|
|
|
|
|
mod cleanup;
|
|
|
|
|
2021-10-23 17:18:52 +02:00
|
|
|
static INIT: Once = Once::new();
|
|
|
|
|
|
|
|
pub fn initialize(file: &str) {
|
|
|
|
INIT.call_once(|| {
|
2023-02-25 20:39:52 +01:00
|
|
|
remove_compressed_test_file(file);
|
2021-10-23 17:18:52 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compress_20() {
|
|
|
|
let output = "tests/samples/output/compressed_20.webp";
|
|
|
|
initialize(output);
|
2022-02-23 17:50:48 +01:00
|
|
|
let mut params = caesium::initialize_parameters();
|
2021-10-23 17:18:52 +02:00
|
|
|
params.webp.quality = 20;
|
2022-10-02 15:02:15 +02:00
|
|
|
caesium::compress(
|
|
|
|
String::from("tests/samples/uncompressed_家.webp"),
|
|
|
|
String::from(output),
|
2022-11-14 23:00:14 +01:00
|
|
|
¶ms,
|
2022-10-02 15:02:15 +02:00
|
|
|
)
|
2024-01-23 18:51:39 +01:00
|
|
|
.unwrap();
|
2021-10-23 17:18:52 +02:00
|
|
|
assert!(std::path::Path::new(output).exists());
|
2022-10-02 15:02:15 +02:00
|
|
|
assert_eq!(
|
|
|
|
infer::get_from_path(output).unwrap().unwrap().mime_type(),
|
|
|
|
"image/webp"
|
|
|
|
);
|
2023-02-25 20:39:52 +01:00
|
|
|
remove_compressed_test_file(output)
|
2021-10-23 17:18:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compress_50() {
|
|
|
|
let output = "tests/samples/output/compressed_50.webp";
|
|
|
|
initialize(output);
|
2022-02-23 17:50:48 +01:00
|
|
|
let mut params = caesium::initialize_parameters();
|
2021-10-23 17:18:52 +02:00
|
|
|
params.webp.quality = 50;
|
2022-10-02 15:02:15 +02:00
|
|
|
caesium::compress(
|
|
|
|
String::from("tests/samples/uncompressed_家.webp"),
|
|
|
|
String::from(output),
|
2022-11-14 23:00:14 +01:00
|
|
|
¶ms,
|
2022-10-02 15:02:15 +02:00
|
|
|
)
|
2024-01-23 18:51:39 +01:00
|
|
|
.unwrap();
|
2021-10-23 17:18:52 +02:00
|
|
|
assert!(std::path::Path::new(output).exists());
|
2022-10-02 15:02:15 +02:00
|
|
|
assert_eq!(
|
|
|
|
infer::get_from_path(output).unwrap().unwrap().mime_type(),
|
|
|
|
"image/webp"
|
|
|
|
);
|
2023-02-25 20:39:52 +01:00
|
|
|
remove_compressed_test_file(output)
|
2021-10-23 17:18:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compress_80() {
|
|
|
|
let output = "tests/samples/output/compressed_80.webp";
|
|
|
|
initialize(output);
|
2022-02-23 17:50:48 +01:00
|
|
|
let mut params = caesium::initialize_parameters();
|
2021-10-23 17:18:52 +02:00
|
|
|
params.webp.quality = 80;
|
2022-10-02 15:02:15 +02:00
|
|
|
caesium::compress(
|
|
|
|
String::from("tests/samples/uncompressed_家.webp"),
|
|
|
|
String::from(output),
|
2022-11-14 23:00:14 +01:00
|
|
|
¶ms,
|
2022-10-02 15:02:15 +02:00
|
|
|
)
|
2024-01-23 18:51:39 +01:00
|
|
|
.unwrap();
|
2021-10-23 17:18:52 +02:00
|
|
|
assert!(std::path::Path::new(output).exists());
|
2022-10-02 15:02:15 +02:00
|
|
|
assert_eq!(
|
|
|
|
infer::get_from_path(output).unwrap().unwrap().mime_type(),
|
|
|
|
"image/webp"
|
|
|
|
);
|
2023-02-25 20:39:52 +01:00
|
|
|
remove_compressed_test_file(output)
|
2021-10-23 17:18:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compress_100() {
|
|
|
|
let output = "tests/samples/output/compressed_100.webp";
|
|
|
|
initialize(output);
|
2022-02-23 17:50:48 +01:00
|
|
|
let mut params = caesium::initialize_parameters();
|
2021-10-23 17:18:52 +02:00
|
|
|
params.webp.quality = 100;
|
2022-10-02 15:02:15 +02:00
|
|
|
caesium::compress(
|
|
|
|
String::from("tests/samples/uncompressed_家.webp"),
|
|
|
|
String::from(output),
|
2022-11-14 23:00:14 +01:00
|
|
|
¶ms,
|
2022-10-02 15:02:15 +02:00
|
|
|
)
|
2024-01-23 18:51:39 +01:00
|
|
|
.unwrap();
|
2021-10-23 17:18:52 +02:00
|
|
|
assert!(std::path::Path::new(output).exists());
|
2022-10-02 15:02:15 +02:00
|
|
|
assert_eq!(
|
|
|
|
infer::get_from_path(output).unwrap().unwrap().mime_type(),
|
|
|
|
"image/webp"
|
|
|
|
);
|
2023-02-25 20:39:52 +01:00
|
|
|
remove_compressed_test_file(output)
|
2021-10-23 17:18:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn optimize() {
|
|
|
|
let output = "tests/samples/output/optimized.webp";
|
|
|
|
initialize(output);
|
2022-02-23 17:50:48 +01:00
|
|
|
let mut params = caesium::initialize_parameters();
|
2021-10-23 17:18:52 +02:00
|
|
|
params.optimize = true;
|
2022-10-02 15:02:15 +02:00
|
|
|
caesium::compress(
|
|
|
|
String::from("tests/samples/uncompressed_家.webp"),
|
|
|
|
String::from(output),
|
2022-11-14 23:00:14 +01:00
|
|
|
¶ms,
|
2022-10-02 15:02:15 +02:00
|
|
|
)
|
2024-01-23 18:51:39 +01:00
|
|
|
.unwrap();
|
2021-10-23 17:18:52 +02:00
|
|
|
assert!(std::path::Path::new(output).exists());
|
2022-10-02 15:02:15 +02:00
|
|
|
assert_eq!(
|
|
|
|
infer::get_from_path(output).unwrap().unwrap().mime_type(),
|
|
|
|
"image/webp"
|
|
|
|
);
|
2023-02-25 20:39:52 +01:00
|
|
|
remove_compressed_test_file(output)
|
2022-02-12 14:10:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn downscale_compress_80() {
|
|
|
|
let output = "tests/samples/output/downscale_compressed_80.webp";
|
|
|
|
initialize(output);
|
2022-02-23 17:50:48 +01:00
|
|
|
let mut params = caesium::initialize_parameters();
|
2022-02-12 14:10:12 +01:00
|
|
|
params.webp.quality = 80;
|
|
|
|
params.width = 150;
|
|
|
|
params.height = 100;
|
2022-10-02 15:02:15 +02:00
|
|
|
caesium::compress(
|
|
|
|
String::from("tests/samples/uncompressed_家.webp"),
|
|
|
|
String::from(output),
|
2022-11-14 23:00:14 +01:00
|
|
|
¶ms,
|
2022-10-02 15:02:15 +02:00
|
|
|
)
|
2024-01-23 18:51:39 +01:00
|
|
|
.unwrap();
|
2022-02-12 14:10:12 +01:00
|
|
|
assert!(std::path::Path::new(output).exists());
|
2022-10-02 15:02:15 +02:00
|
|
|
assert_eq!(
|
|
|
|
infer::get_from_path(output).unwrap().unwrap().mime_type(),
|
|
|
|
"image/webp"
|
|
|
|
);
|
2022-02-12 14:10:12 +01:00
|
|
|
assert_eq!(image::image_dimensions(output).unwrap(), (150, 100));
|
2023-02-25 20:39:52 +01:00
|
|
|
remove_compressed_test_file(output)
|
2022-02-12 14:10:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn downscale_optimize() {
|
|
|
|
let output = "tests/samples/output/downscale_optimized.webp";
|
|
|
|
initialize(output);
|
2022-02-23 17:50:48 +01:00
|
|
|
let mut params = caesium::initialize_parameters();
|
2022-02-12 14:10:12 +01:00
|
|
|
params.optimize = true;
|
|
|
|
params.width = 150;
|
|
|
|
params.height = 100;
|
2022-10-02 15:02:15 +02:00
|
|
|
caesium::compress(
|
|
|
|
String::from("tests/samples/uncompressed_家.webp"),
|
|
|
|
String::from(output),
|
2022-11-14 23:00:14 +01:00
|
|
|
¶ms,
|
2022-10-02 15:02:15 +02:00
|
|
|
)
|
2024-01-23 18:51:39 +01:00
|
|
|
.unwrap();
|
2022-02-12 14:10:12 +01:00
|
|
|
assert!(std::path::Path::new(output).exists());
|
2022-10-02 15:02:15 +02:00
|
|
|
assert_eq!(
|
|
|
|
infer::get_from_path(output).unwrap().unwrap().mime_type(),
|
|
|
|
"image/webp"
|
|
|
|
);
|
2022-02-12 14:10:12 +01:00
|
|
|
assert_eq!(image::image_dimensions(output).unwrap(), (150, 100));
|
2023-02-25 20:39:52 +01:00
|
|
|
remove_compressed_test_file(output)
|
2021-10-23 17:18:52 +02:00
|
|
|
}
|
2024-08-01 11:51:11 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compress_animated_80() {
|
|
|
|
let output = "tests/samples/output/compressed_animated_80.webp";
|
|
|
|
initialize(output);
|
|
|
|
let mut params = caesium::initialize_parameters();
|
|
|
|
params.webp.quality = 80;
|
|
|
|
caesium::compress(
|
|
|
|
String::from("tests/samples/uncompressed_animated.webp"),
|
|
|
|
String::from(output),
|
|
|
|
¶ms,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
assert!(std::path::Path::new(output).exists());
|
|
|
|
assert_eq!(
|
|
|
|
infer::get_from_path(output).unwrap().unwrap().mime_type(),
|
|
|
|
"image/webp"
|
|
|
|
);
|
|
|
|
remove_compressed_test_file(output)
|
|
|
|
}
|