diff --git a/src/bbox.rs b/src/bbox.rs index f64e76c..ac467de 100644 --- a/src/bbox.rs +++ b/src/bbox.rs @@ -332,9 +332,7 @@ fn parse_cstr(input: &[u8]) -> IResult<&[u8], String> { #[cfg(test)] mod tests { - use std::io::Read; - - use crate::testkit::open_sample; + use crate::testkit::read_sample; use super::*; use nom::error::make_error; @@ -342,9 +340,7 @@ mod tests { #[test_case("exif.heic")] fn travel_heic(path: &str) { - let mut reader = open_sample(path).unwrap(); - let mut buf = Vec::new(); - reader.read_to_end(buf.as_mut()).unwrap(); + let buf = read_sample(path).unwrap(); let mut boxes = Vec::new(); let (remain, bbox) = travel_while(&buf, |bbox| { @@ -389,9 +385,7 @@ mod tests { #[test_case("meta.mov")] fn travel_mov(path: &str) { - let mut reader = open_sample(path).unwrap(); - let mut buf = Vec::new(); - reader.read_to_end(buf.as_mut()).unwrap(); + let buf = read_sample(path).unwrap(); let mut boxes = Vec::new(); let (remain, bbox) = travel_while(&buf, |bbox| { @@ -444,9 +438,7 @@ mod tests { #[test_case("meta.mp4")] fn travel_mp4(path: &str) { - let mut reader = open_sample(path).unwrap(); - let mut buf = Vec::new(); - reader.read_to_end(buf.as_mut()).unwrap(); + let buf = read_sample(path).unwrap(); let mut boxes = Vec::new(); let (remain, bbox) = travel_while(&buf, |bbox| { @@ -531,16 +523,7 @@ mod tests { // atom. #[test_case("meta.mp4")] fn find_android_gps_box(path: &str) { - let mut f = open_sample(path).unwrap(); - let mut buf = Vec::new(); - f.read_to_end(&mut buf).unwrap(); - - // let (_, bbox) = travel_while(&buf, |b| b.box_type() != "moov").unwrap(); - // println!("bbox: {:?}", bbox.header); - // let (_, bbox) = travel_while(bbox.body_data(), |b| b.box_type() != "udta").unwrap(); - // println!("bbox: {:?}", bbox.header); - // let (_, bbox) = travel_while(bbox.body_data(), |b| b.box_type() != "©xyz").unwrap(); - + let buf = read_sample(path).unwrap(); let (_, bbox) = find_box(&buf, "moov/udta/©xyz").unwrap(); let bbox = bbox.unwrap(); // println!("bbox: {:?}", bbox.header); diff --git a/src/bbox/ilst.rs b/src/bbox/ilst.rs index aa59eda..95930e4 100644 --- a/src/bbox/ilst.rs +++ b/src/bbox/ilst.rs @@ -127,19 +127,14 @@ fn parse_value(type_code: u32, data: &[u8]) -> crate::Result { #[cfg(test)] mod tests { - use std::io::Read; - - use crate::{bbox::travel_while, testkit::open_sample}; + use crate::{bbox::travel_while, testkit::read_sample}; use super::*; use test_case::test_case; #[test_case("meta.mov")] fn ilst_box(path: &str) { - let mut f = open_sample(path).unwrap(); - let mut buf = Vec::new(); - f.read_to_end(&mut buf).unwrap(); - + let buf = read_sample(path).unwrap(); let (_, bbox) = travel_while(&buf, |b| b.box_type() != "moov").unwrap(); let bbox = bbox.unwrap(); let (_, bbox) = travel_while(bbox.body_data(), |b| b.box_type() != "meta").unwrap(); @@ -168,10 +163,7 @@ mod tests { #[test_case("embedded-in-heic.mov")] fn heic_mov_ilst(path: &str) { - let mut f = open_sample(path).unwrap(); - let mut buf = Vec::new(); - f.read_to_end(&mut buf).unwrap(); - + let buf = read_sample(path).unwrap(); let (_, moov) = travel_while(&buf, |b| b.box_type() != "moov").unwrap(); let moov = moov.unwrap(); let (_, meta) = travel_while(moov.body_data(), |b| b.box_type() != "meta").unwrap(); diff --git a/src/bbox/keys.rs b/src/bbox/keys.rs index 90d4c39..93378da 100644 --- a/src/bbox/keys.rs +++ b/src/bbox/keys.rs @@ -68,11 +68,9 @@ impl KeyEntry { #[cfg(test)] mod tests { - use std::io::Read; - use crate::{ bbox::{travel_while, ParseBox}, - testkit::open_sample, + testkit::read_sample, }; use super::*; @@ -80,10 +78,7 @@ mod tests { #[test_case("meta.mov", 4133, 0x01b9, 0xc9)] fn keys_box(path: &str, moov_size: u64, meta_size: u64, keys_size: u64) { - let mut f = open_sample(path).unwrap(); - let mut buf = Vec::new(); - f.read_to_end(&mut buf).unwrap(); - + let buf = read_sample(path).unwrap(); let (_, moov) = travel_while(&buf, |b| b.box_type() != "moov").unwrap(); let moov = moov.unwrap(); let (_, meta) = travel_while(moov.body_data(), |b| b.box_type() != "meta").unwrap(); @@ -132,10 +127,7 @@ mod tests { #[test_case("embedded-in-heic.mov", 0x1790, 0x0372, 0x1ce)] fn heic_mov_keys(path: &str, moov_size: u64, meta_size: u64, keys_size: u64) { - let mut f = open_sample(path).unwrap(); - let mut buf = Vec::new(); - f.read_to_end(&mut buf).unwrap(); - + let buf = read_sample(path).unwrap(); let (_, moov) = travel_while(&buf, |b| b.box_type() != "moov").unwrap(); let moov = moov.unwrap(); let (_, meta) = travel_while(moov.body_data(), |b| b.box_type() != "meta").unwrap(); diff --git a/src/bbox/meta.rs b/src/bbox/meta.rs index d8ca959..237a0e3 100644 --- a/src/bbox/meta.rs +++ b/src/bbox/meta.rs @@ -121,20 +121,14 @@ pub struct ItemLocation { #[cfg(test)] mod tests { - use std::io::Read; - - use crate::{bbox::travel_while, testkit::open_sample}; + use crate::{bbox::travel_while, testkit::read_sample}; use super::*; use test_case::test_case; #[test_case("exif.heic", 2618)] fn meta(path: &str, meta_size: usize) { - let mut reader = open_sample(path).unwrap(); - let mut buf = Vec::new(); - reader.read_to_end(buf.as_mut()).unwrap(); - assert_eq!(buf.len() as u64, reader.metadata().unwrap().len()); - + let buf = read_sample(path).unwrap(); let (_, bbox) = travel_while(&buf, |bbox| { // println!("got {}", bbox.header.box_type); bbox.box_type() != "meta" diff --git a/src/bbox/mvhd.rs b/src/bbox/mvhd.rs index 9b081fc..19fc998 100644 --- a/src/bbox/mvhd.rs +++ b/src/bbox/mvhd.rs @@ -82,11 +82,9 @@ impl ParseBody for MvhdBox { #[cfg(test)] mod tests { - use std::io::Read; - use crate::{ bbox::{travel_while, ParseBox}, - testkit::open_sample, + testkit::read_sample, }; use super::*; @@ -106,9 +104,7 @@ mod tests { 1063 )] fn mvhd_box(path: &str, time_utc: &str, time_east8: &str, milliseconds: u32) { - let mut f = open_sample(path).unwrap(); - let mut buf = Vec::new(); - f.read_to_end(&mut buf).unwrap(); + let buf = read_sample(path).unwrap(); let (_, bbox) = travel_while(&buf, |b| b.box_type() != "moov").unwrap(); let bbox = bbox.unwrap(); diff --git a/src/bbox/tkhd.rs b/src/bbox/tkhd.rs index 52891cc..fb91dd7 100644 --- a/src/bbox/tkhd.rs +++ b/src/bbox/tkhd.rs @@ -143,9 +143,7 @@ fn find_video_track(input: &[u8]) -> crate::Result> { #[cfg(test)] mod tests { - use std::io::Read; - - use crate::{bbox::travel_while, testkit::open_sample}; + use crate::{bbox::travel_while, testkit::read_sample}; use super::*; use test_case::test_case; @@ -153,9 +151,7 @@ mod tests { #[test_case("meta.mov", 720, 1280)] #[test_case("meta.mp4", 1920, 1080)] fn tkhd_box(path: &str, width: u32, height: u32) { - let mut f = open_sample(path).unwrap(); - let mut buf = Vec::new(); - f.read_to_end(&mut buf).unwrap(); + let buf = read_sample(path).unwrap(); let (_, bbox) = travel_while(&buf, |b| b.box_type() != "moov").unwrap(); let bbox = bbox.unwrap();