Skip to content

Commit

Permalink
Cleanup tests (#656)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrews05 authored Dec 2, 2024
1 parent 3b7467a commit 8ebb5e6
Show file tree
Hide file tree
Showing 30 changed files with 90 additions and 260 deletions.
Binary file modified tests/files/fix_errors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/files/interlaced_vertical_filters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed tests/files/issue-113.png
Binary file not shown.
Binary file removed tests/files/issue-129.png
Binary file not shown.
Binary file removed tests/files/issue-141.png
Binary file not shown.
Binary file removed tests/files/issue-153.png
Binary file not shown.
Binary file removed tests/files/issue-159.png
Binary file not shown.
Binary file removed tests/files/issue-195.png
Binary file not shown.
Binary file removed tests/files/issue-29.png
Binary file not shown.
Binary file removed tests/files/issue-426-01.png
Binary file not shown.
Binary file removed tests/files/issue-426-02.png
Binary file not shown.
Binary file removed tests/files/issue-52-01.png
Binary file not shown.
Binary file removed tests/files/issue-52-02.png
Binary file not shown.
Binary file removed tests/files/issue-52-03.png
Binary file not shown.
Binary file removed tests/files/issue-52-04.png
Binary file not shown.
Binary file removed tests/files/issue-52-05.png
Binary file not shown.
Binary file removed tests/files/issue-52-06.png
Binary file not shown.
Binary file removed tests/files/issue-553.png
Binary file not shown.
Binary file removed tests/files/issue-80.png
Binary file not shown.
Binary file removed tests/files/issue-82.png
Binary file not shown.
Binary file removed tests/files/issue-92.png
Binary file not shown.
Binary file added tests/files/palette_should_be_reduced_with_bkgd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/files/rgb_trns_8_should_be_palette_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/files/zopfli_mode.png
10 changes: 4 additions & 6 deletions tests/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -688,9 +686,9 @@ fn zopfli_mode() {
input,
&output,
&opts,
INDEXED,
RGB,
BitDepth::Eight,
INDEXED,
RGB,
BitDepth::Eight,
);
}
11 changes: 11 additions & 0 deletions tests/interlaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
75 changes: 75 additions & 0 deletions tests/reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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");
Expand Down
Loading

0 comments on commit 8ebb5e6

Please sign in to comment.