mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-24 05:27:45 +00:00
Begin writing ZiPatch unit tests
Right now it's only the usual invalid data test we have elsewhere, but this lays the groundwork to add more!
This commit is contained in:
parent
4357e382ab
commit
657005ad53
1 changed files with 39 additions and 1 deletions
38
src/patch.rs
38
src/patch.rs
|
@ -14,6 +14,7 @@ use crate::ByteBuffer;
|
|||
|
||||
use crate::common::{get_platform_string, Platform, Region};
|
||||
use crate::common_file_operations::{get_string_len, read_bool_from, read_string, write_bool_as, write_string};
|
||||
use crate::shpk::ShaderPackage;
|
||||
use crate::sqpack::{read_data_block_patch, write_data_block_patch};
|
||||
|
||||
#[binrw]
|
||||
|
@ -770,3 +771,40 @@ impl ZiPatch {
|
|||
Some(buffer)
|
||||
}
|
||||
}
|
||||
|
||||
// Note that these only deal with fake patch data. To test retail patches, see tests/patching_test.rs
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs::{read, write};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::*;
|
||||
|
||||
// Prepares a temporary data directory to use
|
||||
fn prepare_data_dir() -> String {
|
||||
let mut dir = std::env::temp_dir();
|
||||
dir.push("physis-patch-tests");
|
||||
if dir.exists() {
|
||||
fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
fs::create_dir_all(&dir);
|
||||
|
||||
dir.to_str().unwrap().to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid() {
|
||||
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
d.push("resources/tests");
|
||||
d.push("random");
|
||||
|
||||
let data_dir = prepare_data_dir();
|
||||
|
||||
write(data_dir.clone() + "/test.patch", &read(d).unwrap());
|
||||
|
||||
// Feeding it invalid data should not panic
|
||||
ZiPatch::apply(&data_dir.clone(), &(data_dir + "/test.patch"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue