mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-24 05:27:45 +00:00
Add invalid data test for Texture
This commit is contained in:
parent
17ba7f2389
commit
4b6166f8d0
1 changed files with 19 additions and 1 deletions
20
src/tex.rs
20
src/tex.rs
|
@ -82,7 +82,7 @@ impl Texture {
|
||||||
/// Reads an existing TEX file
|
/// Reads an existing TEX file
|
||||||
pub fn from_existing(buffer: ByteSpan) -> Option<Texture> {
|
pub fn from_existing(buffer: ByteSpan) -> Option<Texture> {
|
||||||
let mut cursor = Cursor::new(buffer);
|
let mut cursor = Cursor::new(buffer);
|
||||||
let header = TexHeader::read(&mut cursor).unwrap();
|
let header = TexHeader::read(&mut cursor).ok()?;
|
||||||
|
|
||||||
// TODO: Adapted from Lumina, but this really can be written better...
|
// TODO: Adapted from Lumina, but this really can be written better...
|
||||||
let mut texture_data_size = vec![0; min(13, header.mip_levels as usize)];
|
let mut texture_data_size = vec![0; min(13, header.mip_levels as usize)];
|
||||||
|
@ -141,3 +141,21 @@ impl Texture {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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
|
||||||
|
Texture::from_existing(&read(d).unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue