1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-23 05:07:46 +00:00

Add invalid data test for Skeleton

This commit is contained in:
Joshua Goins 2024-04-16 22:07:30 -04:00
parent 4a882d529d
commit 7414d19b57

View file

@ -78,7 +78,7 @@ impl Skeleton {
pub fn from_existing(buffer: ByteSpan) -> Option<Skeleton> { pub fn from_existing(buffer: ByteSpan) -> Option<Skeleton> {
let mut cursor = Cursor::new(buffer); let mut cursor = Cursor::new(buffer);
let sklb = SKLB::read(&mut cursor).unwrap(); let sklb = SKLB::read(&mut cursor).ok()?;
let root = HavokBinaryTagFileReader::read(&sklb.raw_data); let root = HavokBinaryTagFileReader::read(&sklb.raw_data);
let raw_animation_container = root.find_object_by_type("hkaAnimationContainer"); let raw_animation_container = root.find_object_by_type("hkaAnimationContainer");
@ -101,3 +101,21 @@ impl Skeleton {
Some(skeleton) Some(skeleton)
} }
} }
#[cfg(test)]
mod tests {
use std::fs::read;
use std::path::PathBuf;
use super::*;
#[test]
fn test_invalid() {
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
d.push("resources/tests");
d.push("random");
// Feeding it invalid data should not panic
Skeleton::from_existing(&read(d).unwrap());
}
}