Cleanup tests (#656)

I've replaced a few tests with synthetic images and removed a number
that I don't believe are relevant anymore.

I've also removed the #553 test without replacement as I don't know how
to synthesise a replacement and the issue is still open anyway.

Going forward I think we should avoid adding any new "issue" tests and
instead synthesise something suitable in one of the other collections.

Closes #655.
This commit is contained in:
andrews05 2024-12-03 08:58:01 +13:00 committed by GitHub
parent 3b7467a5da
commit 8ebb5e6dfd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 90 additions and 260 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 910 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 455 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 42 KiB

View file

@ -12,10 +12,8 @@ use std::{
use indexmap::indexset;
use oxipng::{internal_tests::*, *};
const GRAYSCALE: u8 = 0;
const RGB: u8 = 2;
const INDEXED: u8 = 3;
const RGBA: u8 = 6;
fn get_opts(input: &Path) -> (OutFile, oxipng::Options) {
let mut options = oxipng::Options {
@ -582,7 +580,7 @@ fn fix_errors() {
let png = PngData::new(&input, &opts).unwrap();
assert_eq!(png.raw.ihdr.color_type.png_header_code(), RGBA);
assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
match oxipng::optimize(&InFile::Path(input), &output, &opts) {
@ -600,7 +598,7 @@ fn fix_errors() {
}
};
assert_eq!(png.raw.ihdr.color_type.png_header_code(), GRAYSCALE);
assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::Eight);
// Cannot check if pixels are equal because image crate cannot read corrupt (input) PNGs
@ -688,9 +686,9 @@ fn zopfli_mode() {
input,
&output,
&opts,
INDEXED,
RGB,
BitDepth::Eight,
INDEXED,
RGB,
BitDepth::Eight,
);
}

View file

@ -666,6 +666,17 @@ fn interlaced_small_files() {
);
}
#[test]
fn interlaced_vertical_filters() {
test_it_converts(
"tests/files/interlaced_vertical_filters.png",
RGB,
BitDepth::Eight,
RGB,
BitDepth::Eight,
);
}
#[test]
fn interlaced_odd_width() {
test_it_converts(

View file

@ -386,6 +386,18 @@ fn rgb_8_should_be_palette_8() {
);
}
#[test]
fn rgb_trns_8_should_be_palette_8() {
test_it_converts(
"tests/files/rgb_trns_8_should_be_palette_8.png",
false,
RGB,
BitDepth::Eight,
INDEXED,
BitDepth::Eight,
);
}
#[test]
fn rgb_16_should_be_palette_4() {
test_it_converts(
@ -722,6 +734,18 @@ fn grayscale_alpha_8_should_be_grayscale_8() {
);
}
#[test]
fn grayscale_alpha_8_should_be_palette_8() {
test_it_converts(
"tests/files/grayscale_alpha_8_should_be_palette_8.png",
false,
GRAYSCALE_ALPHA,
BitDepth::Eight,
INDEXED,
BitDepth::Eight,
);
}
#[test]
fn grayscale_16_should_be_grayscale_16() {
test_it_converts(
@ -926,6 +950,18 @@ fn grayscale_alpha_8_should_be_grayscale_trns_1() {
);
}
#[test]
fn grayscale_trns_8_should_be_grayscale_1() {
test_it_converts(
"tests/files/grayscale_trns_8_should_be_grayscale_1.png",
true,
GRAYSCALE,
BitDepth::Eight,
GRAYSCALE,
BitDepth::One,
);
}
#[test]
fn small_files() {
test_it_converts(
@ -1012,6 +1048,45 @@ fn palette_should_be_reduced_with_unused() {
remove_file(output).ok();
}
#[test]
fn palette_should_be_reduced_with_bkgd() {
let input = PathBuf::from("tests/files/palette_should_be_reduced_with_bkgd.png");
let (output, opts) = get_opts(&input);
let png = PngData::new(&input, &opts).unwrap();
assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::One);
assert_eq!(&png.aux_chunks[0].name, b"bKGD");
if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type {
assert_eq!(palette.len(), 3);
}
match oxipng::optimize(&InFile::Path(input), &output, &opts) {
Ok(_) => (),
Err(x) => panic!("{}", x),
};
let output = output.path().unwrap();
assert!(output.exists());
let png = match PngData::new(output, &opts) {
Ok(x) => x,
Err(x) => {
remove_file(output).ok();
panic!("{}", x)
}
};
assert_eq!(png.raw.ihdr.color_type.png_header_code(), INDEXED);
assert_eq!(png.raw.ihdr.bit_depth, BitDepth::One);
assert_ne!(&png.aux_chunks[0].name, b"bKGD");
if let ColorType::Indexed { palette } = &png.raw.ihdr.color_type {
assert_eq!(palette.len(), 2);
}
remove_file(output).ok();
}
#[test]
fn palette_should_be_reduced_with_both() {
let input = PathBuf::from("tests/files/palette_should_be_reduced_with_both.png");

View file

@ -7,7 +7,6 @@ use std::{
use oxipng::{internal_tests::*, *};
const GRAYSCALE: u8 = 0;
const RGB: u8 = 2;
const INDEXED: u8 = 3;
const GRAYSCALE_ALPHA: u8 = 4;
const RGBA: u8 = 6;
@ -75,18 +74,6 @@ fn test_it_converts(
Arc::try_unwrap(png.raw).unwrap()
}
#[test]
fn issue_29() {
test_it_converts(
"tests/files/issue-29.png",
None,
RGB,
BitDepth::Eight,
RGB,
BitDepth::Eight,
);
}
#[test]
fn issue_42() {
let input = "tests/files/issue-42.png";
@ -102,78 +89,6 @@ fn issue_42() {
);
}
#[test]
fn issue_52_01() {
test_it_converts(
"tests/files/issue-52-01.png",
None,
RGBA,
BitDepth::Eight,
INDEXED,
BitDepth::Eight,
);
}
#[test]
fn issue_52_02() {
test_it_converts(
"tests/files/issue-52-02.png",
None,
RGBA,
BitDepth::Eight,
RGBA,
BitDepth::Eight,
);
}
#[test]
fn issue_52_03() {
test_it_converts(
"tests/files/issue-52-03.png",
None,
RGBA,
BitDepth::Eight,
RGBA,
BitDepth::Eight,
);
}
#[test]
fn issue_52_04() {
test_it_converts(
"tests/files/issue-52-04.png",
None,
RGBA,
BitDepth::Eight,
RGB,
BitDepth::Eight,
);
}
#[test]
fn issue_52_05() {
test_it_converts(
"tests/files/issue-52-05.png",
None,
RGBA,
BitDepth::Eight,
RGB,
BitDepth::Eight,
);
}
#[test]
fn issue_52_06() {
test_it_converts(
"tests/files/issue-52-06.png",
None,
RGBA,
BitDepth::Eight,
RGBA,
BitDepth::Eight,
);
}
#[test]
fn issue_56() {
test_it_converts(
@ -222,30 +137,6 @@ fn issue_60() {
);
}
#[test]
fn issue_80() {
test_it_converts(
"tests/files/issue-80.png",
None,
INDEXED,
BitDepth::Two,
INDEXED,
BitDepth::One,
);
}
#[test]
fn issue_82() {
test_it_converts(
"tests/files/issue-82.png",
None,
INDEXED,
BitDepth::Four,
INDEXED,
BitDepth::Eight,
);
}
#[test]
fn issue_89() {
test_it_converts(
@ -258,63 +149,6 @@ fn issue_89() {
);
}
#[test]
fn issue_92_filter_0() {
test_it_converts(
"tests/files/issue-92.png",
None,
GRAYSCALE,
BitDepth::Eight,
GRAYSCALE,
BitDepth::Eight,
);
}
#[test]
fn issue_92_filter_5() {
let input = "tests/files/issue-92.png";
let (_, mut opts) = get_opts(Path::new(input));
opts.filter = [RowFilter::MinSum].iter().cloned().collect();
let output = OutFile::from_path(Path::new(input).with_extension("-f5-out.png"));
test_it_converts(
input,
Some((output, opts)),
GRAYSCALE,
BitDepth::Eight,
GRAYSCALE,
BitDepth::Eight,
);
}
#[test]
fn issue_113() {
let input = "tests/files/issue-113.png";
let (output, mut opts) = get_opts(Path::new(input));
opts.interlace = Some(Interlacing::Adam7);
opts.optimize_alpha = true;
test_it_converts(
input,
Some((output, opts)),
RGBA,
BitDepth::Eight,
GRAYSCALE_ALPHA,
BitDepth::Eight,
);
}
#[test]
fn issue_129() {
test_it_converts(
"tests/files/issue-129.png",
None,
RGB,
BitDepth::Eight,
INDEXED,
BitDepth::Eight,
);
}
#[test]
fn issue_140() {
test_it_converts(
@ -327,42 +161,6 @@ fn issue_140() {
);
}
#[test]
fn issue_141() {
test_it_converts(
"tests/files/issue-141.png",
None,
RGBA,
BitDepth::Eight,
RGB,
BitDepth::Eight,
);
}
#[test]
fn issue_153() {
test_it_converts(
"tests/files/issue-153.png",
None,
RGBA,
BitDepth::Eight,
INDEXED,
BitDepth::Eight,
);
}
#[test]
fn issue_159() {
test_it_converts(
"tests/files/issue-159.png",
None,
INDEXED,
BitDepth::One,
INDEXED,
BitDepth::One,
);
}
#[test]
fn issue_171() {
test_it_converts(
@ -402,55 +200,3 @@ fn issue_182() {
BitDepth::One,
);
}
#[test]
fn issue_195() {
test_it_converts(
"tests/files/issue-195.png",
None,
RGBA,
BitDepth::Eight,
INDEXED,
BitDepth::Eight,
);
}
#[test]
fn issue_426_01() {
test_it_converts(
"tests/files/issue-426-01.png",
None,
GRAYSCALE,
BitDepth::Eight,
GRAYSCALE,
BitDepth::One,
);
}
#[test]
fn issue_426_02() {
test_it_converts(
"tests/files/issue-426-02.png",
None,
GRAYSCALE,
BitDepth::Eight,
GRAYSCALE,
BitDepth::One,
);
}
#[test]
fn issue_553() {
let png = test_it_converts(
"tests/files/issue-553.png",
None,
INDEXED,
BitDepth::Eight,
INDEXED,
BitDepth::Eight,
);
match png.ihdr.color_type {
ColorType::Indexed { palette } => assert_eq!(palette.len(), 256),
_ => unreachable!(),
};
}