Skip to content

Commit

Permalink
Remove redundant fn open_sample() definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mindeng committed Jul 13, 2024
1 parent 069eb07 commit 0cd94a2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 40 deletions.
12 changes: 4 additions & 8 deletions src/bbox/ilst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ fn parse_value(type_code: u32, data: &[u8]) -> crate::Result<EntryValue> {

#[cfg(test)]
mod tests {
use std::{fs::File, io::Read, path::Path};
use std::io::Read;

use crate::bbox::travel_while;
use crate::{bbox::travel_while, testkit::open_sample};

use super::*;
use test_case::test_case;

#[test_case("meta.mov")]
fn ilst_box(path: &str) {
let mut f = open_sample(path);
let mut f = open_sample(path).unwrap();
let mut buf = Vec::new();
f.read_to_end(&mut buf).unwrap();

Expand Down Expand Up @@ -168,7 +168,7 @@ mod tests {

#[test_case("embedded-in-heic.mov")]
fn heic_mov_ilst(path: &str) {
let mut f = open_sample(path);
let mut f = open_sample(path).unwrap();
let mut buf = Vec::new();
f.read_to_end(&mut buf).unwrap();

Expand Down Expand Up @@ -205,8 +205,4 @@ IlstItem { size: 28, index: 9, data_len: 20, type_set: 0, type_code: 1, local: 0
IlstItem { size: 48, index: 10, data_len: 40, type_set: 0, type_code: 1, local: 0, value: Text(\"2023-11-02T19:58:34+0800\") }"
);
}

fn open_sample(path: &str) -> File {
File::open(Path::new("./testdata").join(path)).unwrap()
}
}
15 changes: 7 additions & 8 deletions src/bbox/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,19 @@ impl KeyEntry {

#[cfg(test)]
mod tests {
use std::{fs::File, io::Read, path::Path};
use std::io::Read;

use crate::bbox::{travel_while, ParseBox};
use crate::{
bbox::{travel_while, ParseBox},
testkit::open_sample,
};

use super::*;
use test_case::test_case;

#[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);
let mut f = open_sample(path).unwrap();
let mut buf = Vec::new();
f.read_to_end(&mut buf).unwrap();

Expand Down Expand Up @@ -129,7 +132,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);
let mut f = open_sample(path).unwrap();
let mut buf = Vec::new();
f.read_to_end(&mut buf).unwrap();

Expand Down Expand Up @@ -170,8 +173,4 @@ KeyEntry { size: 36, namespace: "mdta", key: "com.apple.quicktime.software" }
KeyEntry { size: 40, namespace: "mdta", key: "com.apple.quicktime.creationdate" }"#,
);
}

fn open_sample(path: &str) -> File {
File::open(Path::new("./testdata").join(path)).unwrap()
}
}
18 changes: 6 additions & 12 deletions src/bbox/mvhd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ impl ParseBody<MvhdBox> for MvhdBox {

#[cfg(test)]
mod tests {
use std::{fs::File, io::Read, path::Path};
use std::io::Read;

use crate::bbox::{travel_while, ParseBox};
use crate::{
bbox::{travel_while, ParseBox},
testkit::open_sample,
};

use super::*;
use chrono::FixedOffset;
Expand All @@ -103,7 +106,7 @@ mod tests {
1063
)]
fn mvhd_box(path: &str, time_utc: &str, time_east8: &str, milliseconds: u32) {
let mut f = open_sample(path);
let mut f = open_sample(path).unwrap();
let mut buf = Vec::new();
f.read_to_end(&mut buf).unwrap();

Expand All @@ -130,13 +133,4 @@ mod tests {
time_east8
);
}

fn open_sample(path: &str) -> File {
let p = Path::new(path);
if p.is_absolute() {
File::open(p).unwrap()
} else {
File::open(Path::new("./testdata").join(p)).unwrap()
}
}
}
15 changes: 3 additions & 12 deletions src/bbox/tkhd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ fn find_video_track(input: &[u8]) -> crate::Result<Option<BoxHolder>> {

#[cfg(test)]
mod tests {
use std::{fs::File, io::Read, path::Path};
use std::io::Read;

use crate::bbox::travel_while;
use crate::{bbox::travel_while, testkit::open_sample};

use super::*;
use test_case::test_case;

#[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);
let mut f = open_sample(path).unwrap();
let mut buf = Vec::new();
f.read_to_end(&mut buf).unwrap();

Expand All @@ -164,13 +164,4 @@ mod tests {
assert_eq!(tkhd.width, width);
assert_eq!(tkhd.height, height);
}

fn open_sample(path: &str) -> File {
let p = Path::new(path);
if p.is_absolute() {
File::open(p).unwrap()
} else {
File::open(Path::new("./testdata").join(p)).unwrap()
}
}
}

0 comments on commit 0cd94a2

Please sign in to comment.