1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2025-04-15 08:14:15 +00:00

Test: add unit tests for GpsBox

This commit is contained in:
Precision 2025-01-13 13:03:14 +08:00
parent c0043dcb47
commit b8b3a3875e
2 changed files with 43 additions and 2 deletions

View file

@ -99,5 +99,46 @@ impl<W: Write> WriteBox<&mut W> for GpsBox {
#[cfg(test)]
mod tests {
// TODO
use super::*;
use std::io::Cursor;
#[test]
fn test_gps() {
let src_box = GpsBox {
version_and_date: 12345678,
data_blocks: vec![
GpsDataBlockInfo {
offset: 100,
size: 256,
}
],
};
let mut buf = Vec::new();
src_box.write_box(&mut buf).unwrap();
assert_eq!(buf.len(), src_box.box_size() as usize);
let mut reader = Cursor::new(&buf);
let header = BoxHeader::read(&mut reader).unwrap();
assert_eq!(header.name, BoxType::GpsBox);
assert_eq!(src_box.box_size(), header.size);
let dst_box = GpsBox::read_box(&mut reader, header.size).unwrap();
assert_eq!(src_box, dst_box);
}
#[test]
fn test_gps_empty() {
let src_box = GpsBox::default();
let mut buf = Vec::new();
src_box.write_box(&mut buf).unwrap();
assert_eq!(buf.len(), src_box.box_size() as usize);
let mut reader = Cursor::new(&buf);
let header = BoxHeader::read(&mut reader).unwrap();
assert_eq!(header.name, BoxType::GpsBox);
assert_eq!(src_box.box_size(), header.size);
let dst_box = GpsBox::read_box(&mut reader, header.size).unwrap();
assert_eq!(src_box, dst_box);
}
}

View file

@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::io::{Read, Seek};
use std::time::Duration;
use crate::gps::GpsBox;
use crate::meta::MetaBox;
use crate::*;