2022-01-24 16:21:05 +01:00
|
|
|
use libcaesium;
|
2021-10-23 17:18:52 +02:00
|
|
|
use std::sync::Once;
|
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
static INIT: Once = Once::new();
|
|
|
|
|
|
|
|
pub fn initialize(file: &str) {
|
|
|
|
INIT.call_once(|| {
|
|
|
|
if fs::metadata(file).is_ok() {
|
|
|
|
fs::remove_file(file).unwrap();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn cleanup(file: &str) {
|
|
|
|
if fs::metadata(file).is_ok() {
|
|
|
|
fs::remove_file(file).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn standard_compress_png() {
|
|
|
|
let output = "tests/samples/output/compressed.png";
|
|
|
|
initialize(output);
|
2022-01-24 16:21:05 +01:00
|
|
|
libcaesium::compress(String::from("tests/samples/uncompressed_드림캐쳐.png"),
|
2021-10-23 17:18:52 +02:00
|
|
|
String::from(output),
|
2022-01-24 16:21:05 +01:00
|
|
|
libcaesium::initialize_parameters())
|
2021-10-23 17:18:52 +02:00
|
|
|
.unwrap();
|
|
|
|
assert!(std::path::Path::new(output).exists());
|
|
|
|
cleanup(output)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn standard_compress_png_with_optimize_flag() {
|
|
|
|
let output = "tests/samples/output/compressed_max.png";
|
|
|
|
initialize(output);
|
2022-01-24 16:21:05 +01:00
|
|
|
let mut params = libcaesium::initialize_parameters();
|
2021-10-23 17:18:52 +02:00
|
|
|
params.optimize = true;
|
2022-01-24 16:21:05 +01:00
|
|
|
libcaesium::compress(String::from("tests/samples/uncompressed_드림캐쳐.png"),
|
2021-10-23 17:18:52 +02:00
|
|
|
String::from(output),
|
|
|
|
params)
|
|
|
|
.unwrap();
|
|
|
|
assert!(std::path::Path::new(output).exists());
|
|
|
|
cleanup(output)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn zopfli_compress_png() {
|
|
|
|
let output = "tests/samples/output/optimized.png";
|
|
|
|
initialize(output);
|
2022-01-24 16:21:05 +01:00
|
|
|
let mut params = libcaesium::initialize_parameters();
|
2021-10-23 17:18:52 +02:00
|
|
|
params.png.level = 3;
|
|
|
|
params.optimize = true;
|
|
|
|
params.png.force_zopfli = true;
|
2022-01-24 16:21:05 +01:00
|
|
|
libcaesium::compress(String::from("tests/samples/uncompressed_드림캐쳐.png"),
|
2021-10-23 17:18:52 +02:00
|
|
|
String::from(output),
|
|
|
|
params)
|
|
|
|
.unwrap();
|
|
|
|
assert!(std::path::Path::new(output).exists());
|
|
|
|
cleanup(output)
|
|
|
|
}
|