Skip to content

Instantly share code, notes, and snippets.

@kolen
Created July 23, 2019 17:08
Show Gist options
  • Save kolen/2fd057848dfa0f82dfe58461263d1f62 to your computer and use it in GitHub Desktop.
Save kolen/2fd057848dfa0f82dfe58461263d1f62 to your computer and use it in GitHub Desktop.
Rust Image library test cases for iteration methods on ImageBuffer with zero width and/or height causing 'chunk_size != 0' panic
[package]
name = "image-iter-panic-demo"
version = "0.1.0"
edition = "2018"
[dependencies]
image = { git = "https://github.com/image-rs/image" }
[lib]
path = "lib.rs"
#[cfg(test)]
use image::{ImageBuffer, RgbaImage};
#[cfg(test)]
mod tests_zero_width_zero_height {
use super::*;
fn test_image() -> RgbaImage {
ImageBuffer::new(0, 0)
}
#[test]
fn test_rows_mut() {
let mut image = test_image();
let rows = image.rows_mut();
assert_eq!(rows.count(), 0);
}
#[test]
fn test_pixels_mut() {
let mut image = test_image();
let rows = image.pixels_mut();
assert_eq!(rows.count(), 0);
}
#[test]
fn test_rows() {
let image = test_image();
let rows = image.rows();
assert_eq!(rows.count(), 0);
}
#[test]
fn test_pixels() {
let image = test_image();
let rows = image.pixels();
assert_eq!(rows.count(), 0);
}
}
#[cfg(test)]
mod tests_zero_width_nonzero_height {
use super::*;
fn test_image() -> RgbaImage {
ImageBuffer::new(0, 2)
}
#[test]
fn test_rows_mut() {
let mut image = test_image();
let rows = image.rows_mut();
assert_eq!(rows.count(), 2);
}
#[test]
fn test_pixels_mut() {
let mut image = test_image();
let rows = image.pixels_mut();
assert_eq!(rows.count(), 0);
}
#[test]
fn test_rows() {
let image = test_image();
let rows = image.rows();
assert_eq!(rows.count(), 2);
}
#[test]
fn test_pixels() {
let image = test_image();
let rows = image.pixels();
assert_eq!(rows.count(), 0);
}
}
#[cfg(test)]
mod tests_nonzero_width_zero_height {
use super::*;
fn test_image() -> RgbaImage {
ImageBuffer::new(2, 0)
}
#[test]
fn test_rows_mut() {
let mut image = test_image();
let rows = image.rows_mut();
assert_eq!(rows.count(), 0);
}
#[test]
fn test_pixels_mut() {
let mut image = test_image();
let rows = image.pixels_mut();
assert_eq!(rows.count(), 0);
}
#[test]
fn test_rows() {
let image = test_image();
let rows = image.rows();
assert_eq!(rows.count(), 0);
}
#[test]
fn test_pixels() {
let image = test_image();
let rows = image.pixels();
assert_eq!(rows.count(), 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment