Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup tests #656

Merged
merged 8 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading