Skip to content

Commit

Permalink
Move tests out of published package
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Jan 12, 2024
1 parent 12f920f commit 6716478
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 65 deletions.
27 changes: 1 addition & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ homepage = "https://github.com/image-rs/image-gif"
repository = "https://github.com/image-rs/image-gif"
documentation = "https://docs.rs/gif"
edition = "2021"
exclude = [
"tests/crashtest/*",
"tests/samples/*",
"benches/*.gif",
"gif-afl/*",
]
include = ["src/**", "LICENSE-*", "README.md", "benches/*.rs"]

[lib]
bench = false
Expand All @@ -37,26 +32,6 @@ color_quant = ["dep:color_quant"]
# Reservation for a feature turning off std
std = []

[[test]]
name = "check_testimages"
required-features = ["std"]

[[test]]
name = "crashtest"
required-features = ["std"]

[[test]]
name = "decode"
required-features = ["std"]

[[test]]
name = "stall"
required-features = ["std"]

[[test]]
name = "roundtrip"
required-features = ["std"]

[[bench]]
name = "decode"
harness = false
Expand Down
18 changes: 0 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,6 @@ pub mod streaming_decoder {
pub use crate::reader::{StreamingDecoder, OutputBuffer, Decoded, FrameDataType};
}

#[cfg(test)]
#[test]
fn round_trip() {
use std::io::prelude::*;
use std::fs::File;
let mut data = vec![];
File::open("tests/samples/sample_1.gif").unwrap().read_to_end(&mut data).unwrap();
let mut decoder = Decoder::new(&*data).unwrap();
let palette: Vec<u8> = decoder.palette().unwrap().into();
let frame = decoder.read_next_frame().unwrap().unwrap();
let mut data2 = vec![];
{
let mut encoder = Encoder::new(&mut data2, frame.width, frame.height, &palette).unwrap();
encoder.write_frame(frame).unwrap();
}
assert_eq!(&data[..], &data2[..]);
}

macro_rules! insert_as_doc {
{ $content:expr } => {
#[allow(unused_doc_comments)]
Expand Down
22 changes: 1 addition & 21 deletions src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,27 +637,7 @@ impl iter::Iterator for InterlaceIterator {

#[cfg(test)]
mod test {
use std::fs::File;

use super::{Decoder, InterlaceIterator};

#[test]
fn test_simple_indexed() {
let mut decoder = Decoder::new(File::open("tests/samples/sample_1.gif").unwrap()).unwrap();
let frame = decoder.read_next_frame().unwrap().unwrap();
assert_eq!(&*frame.buffer, &[
1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
1, 1, 1, 0, 0, 0, 0, 2, 2, 2,
1, 1, 1, 0, 0, 0, 0, 2, 2, 2,
2, 2, 2, 0, 0, 0, 0, 1, 1, 1,
2, 2, 2, 0, 0, 0, 0, 1, 1, 1,
2, 2, 2, 2, 2, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 1, 1, 1, 1, 1
][..]);
}
use super::InterlaceIterator;

#[test]
fn test_interlace_iterator() {
Expand Down
1 change: 1 addition & 0 deletions tests/check_testimages.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "std")]

use std::collections::HashMap;
use std::fs::File;
Expand Down
2 changes: 2 additions & 0 deletions tests/crashtest.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "std")]

use std::{fs, io};
use gif::DecodeOptions;

Expand Down
21 changes: 21 additions & 0 deletions tests/decode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
#![cfg(feature = "std")]

use gif::{Decoder, DecodeOptions, DisposalMethod, Encoder, Frame};
use std::fs::File;

#[test]
fn test_simple_indexed() {
let mut decoder = Decoder::new(File::open("tests/samples/sample_1.gif").unwrap()).unwrap();
let frame = decoder.read_next_frame().unwrap().unwrap();
assert_eq!(&*frame.buffer, &[
1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
1, 1, 1, 0, 0, 0, 0, 2, 2, 2,
1, 1, 1, 0, 0, 0, 0, 2, 2, 2,
2, 2, 2, 0, 0, 0, 0, 1, 1, 1,
2, 2, 2, 0, 0, 0, 0, 1, 1, 1,
2, 2, 2, 2, 2, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 1, 1, 1, 1, 1
][..]);
}

#[test]
fn frame_consistency_is_configurable() {
Expand Down
19 changes: 19 additions & 0 deletions tests/roundtrip.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
#![cfg(feature = "std")]

use gif::{ColorOutput, Decoder, Encoder, Frame};

#[test]
fn round_trip() {
use std::io::prelude::*;
use std::fs::File;
let mut data = vec![];
File::open("tests/samples/sample_1.gif").unwrap().read_to_end(&mut data).unwrap();
let mut decoder = Decoder::new(&*data).unwrap();
let palette: Vec<u8> = decoder.palette().unwrap().into();
let frame = decoder.read_next_frame().unwrap().unwrap();
let mut data2 = vec![];
{
let mut encoder = Encoder::new(&mut data2, frame.width, frame.height, &palette).unwrap();
encoder.write_frame(frame).unwrap();
}
assert_eq!(&data[..], &data2[..]);
}

#[test]
fn encode_roundtrip() {
const ORIGINAL: &[u8] = include_bytes!("samples/2x2.gif");
Expand Down
2 changes: 2 additions & 0 deletions tests/stall.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(feature = "std")]

use std::{fs, sync::mpsc, thread, time::Duration};

#[test]
Expand Down

0 comments on commit 6716478

Please sign in to comment.