mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 19:04:07 +00:00
Simplify matrix test
This commit is contained in:
parent
8564cf6268
commit
f94e6c460d
1 changed files with 130 additions and 122 deletions
|
@ -82,63 +82,61 @@ mod test {
|
|||
|
||||
static AES_KEY: &str = "lNJbw660IOC+kU7cnVQ1oeqrXyhk4J6UAZrCBbcnp94=";
|
||||
|
||||
macro_rules! matrix_test_read {
|
||||
( ($($version:literal $exp_version:expr),* $(,)?), $compress:tt, $encrypt:tt, $encryptindex:tt ) => {
|
||||
$( mt_compress_read!($version, $exp_version, $compress, $encrypt, $encryptindex); )*
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! mt_compress_read {
|
||||
( $version:literal, $exp_version:expr, ($($compress:literal),* $(,)?), $encrypt:tt, $encryptindex:tt ) => {
|
||||
$( mt_encrypt_read!($version, $exp_version, $compress, $encrypt, $encryptindex); )*
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! mt_encrypt_read {
|
||||
( $version:literal, $exp_version:expr, $compress:literal, ($($encrypt:literal),* $(,)?), $encryptindex:tt ) => {
|
||||
$( mt_encryptindex_read!($version, $exp_version, $compress, $encrypt, $encryptindex); )*
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! mt_encryptindex_read {
|
||||
( $version:literal, $exp_version:expr, $compress:literal, $encrypt:literal, ($($encryptindex:literal),* $(,)?) ) => {
|
||||
$(
|
||||
paste! {
|
||||
#[test]
|
||||
fn [< test_read_version_ $version $compress $encrypt $encryptindex >]() {
|
||||
fn test_read(version: repak::Version, bytes: &[u8]) {
|
||||
use aes::cipher::KeyInit;
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
let key = general_purpose::STANDARD
|
||||
.decode(AES_KEY)
|
||||
.as_ref()
|
||||
.map_err(|_| repak::Error::Base64)
|
||||
.and_then(|bytes| {
|
||||
aes::Aes256::new_from_slice(bytes).map_err(|_| repak::Error::Aes)
|
||||
}).unwrap();
|
||||
.and_then(|bytes| aes::Aes256::new_from_slice(bytes).map_err(|_| repak::Error::Aes))
|
||||
.unwrap();
|
||||
|
||||
|
||||
let mut inner_reader = std::io::Cursor::new(include_bytes!(concat!("packs/pack_", $version, $compress, $encrypt, $encryptindex, ".pak")));
|
||||
let mut inner_reader = std::io::Cursor::new(bytes);
|
||||
let len = inner_reader.seek(SeekFrom::End(0)).unwrap();
|
||||
let mut reader = ReadCounter::new_size(inner_reader, len as usize);
|
||||
|
||||
let pak = repak::PakReader::new_any(&mut reader, Some(key)).unwrap();
|
||||
|
||||
assert_eq!(pak.mount_point(), "../mount/point/root/");
|
||||
assert_eq!(pak.version(), $exp_version);
|
||||
assert_eq!(pak.version(), version);
|
||||
use std::collections::HashSet;
|
||||
let files: HashSet<String> = HashSet::from_iter(pak.files());
|
||||
assert_eq!(files, HashSet::from_iter(vec!["test.txt", "test.png", "zeros.bin", "directory/nested.txt"].into_iter().map(String::from)));
|
||||
assert_eq!(
|
||||
files,
|
||||
HashSet::from_iter(
|
||||
vec!["test.txt", "test.png", "zeros.bin", "directory/nested.txt"]
|
||||
.into_iter()
|
||||
.map(String::from)
|
||||
)
|
||||
);
|
||||
|
||||
for file in files {
|
||||
let mut buf = vec![];
|
||||
let mut writer = std::io::Cursor::new(&mut buf);
|
||||
pak.read_file(&file, &mut reader, &mut writer).unwrap();
|
||||
match file.as_str() {
|
||||
"test.txt" => assert_eq!(buf, include_bytes!("pack/root/test.txt"), "test.txt incorrect contents"),
|
||||
"test.png" => assert_eq!(buf, include_bytes!("pack/root/test.png"), "test.png incorrect contents"),
|
||||
"zeros.bin" => assert_eq!(buf, include_bytes!("pack/root/zeros.bin"), "zeros.bin incorrect contents"),
|
||||
"directory/nested.txt" => assert_eq!(buf, include_bytes!("pack/root/directory/nested.txt"), "nested.txt incorrect contents"),
|
||||
name => panic!("unrecognized file {}", name)
|
||||
"test.txt" => assert_eq!(
|
||||
buf,
|
||||
include_bytes!("pack/root/test.txt"),
|
||||
"test.txt incorrect contents"
|
||||
),
|
||||
"test.png" => assert_eq!(
|
||||
buf,
|
||||
include_bytes!("pack/root/test.png"),
|
||||
"test.png incorrect contents"
|
||||
),
|
||||
"zeros.bin" => assert_eq!(
|
||||
buf,
|
||||
include_bytes!("pack/root/zeros.bin"),
|
||||
"zeros.bin incorrect contents"
|
||||
),
|
||||
"directory/nested.txt" => assert_eq!(
|
||||
buf,
|
||||
include_bytes!("pack/root/directory/nested.txt"),
|
||||
"nested.txt incorrect contents"
|
||||
),
|
||||
name => panic!("unrecognized file {}", name),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,61 +146,19 @@ macro_rules! mt_encryptindex_read {
|
|||
// by UnrealPak are meaningful
|
||||
assert!(r > 0, "every byte has been read at least once");
|
||||
}
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
matrix_test_read!(
|
||||
(
|
||||
"v5" repak::Version::V5,
|
||||
"v7" repak::Version::V7,
|
||||
"v8a" repak::Version::V8A,
|
||||
"v8b" repak::Version::V8B,
|
||||
"v9" repak::Version::V9,
|
||||
"v11" repak::Version::V11,
|
||||
),
|
||||
("", "_compress"),
|
||||
("", "_encrypt"),
|
||||
("", "_encryptindex")
|
||||
);
|
||||
|
||||
macro_rules! matrix_test_write {
|
||||
( ($($version:literal $exp_version:expr),* $(,)?), $compress:tt, $encrypt:tt, $encryptindex:tt ) => {
|
||||
$( mt_compress_write!($version, $exp_version, $compress, $encrypt, $encryptindex); )*
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! mt_compress_write {
|
||||
( $version:literal, $exp_version:expr, ($($compress:literal),* $(,)?), $encrypt:tt, $encryptindex:tt ) => {
|
||||
$( mt_encrypt_write!($version, $exp_version, $compress, $encrypt, $encryptindex); )*
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! mt_encrypt_write {
|
||||
( $version:literal, $exp_version:expr, $compress:literal, ($($encrypt:literal),* $(,)?), $encryptindex:tt ) => {
|
||||
$( mt_encryptindex_write!($version, $exp_version, $compress, $encrypt, $encryptindex); )*
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! mt_encryptindex_write {
|
||||
( $version:literal, $exp_version:expr, $compress:literal, $encrypt:literal, ($($encryptindex:literal),* $(,)?) ) => {
|
||||
$(
|
||||
paste! {
|
||||
#[test]
|
||||
fn [< test_write_version_ $version $compress $encrypt $encryptindex >]() {
|
||||
fn test_write(_version: repak::Version, bytes: &[u8]) {
|
||||
use aes::cipher::KeyInit;
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
let key = general_purpose::STANDARD
|
||||
.decode(AES_KEY)
|
||||
.as_ref()
|
||||
.map_err(|_| repak::Error::Base64)
|
||||
.and_then(|bytes| {
|
||||
aes::Aes256::new_from_slice(bytes).map_err(|_| repak::Error::Aes)
|
||||
}).unwrap();
|
||||
.and_then(|bytes| aes::Aes256::new_from_slice(bytes).map_err(|_| repak::Error::Aes))
|
||||
.unwrap();
|
||||
|
||||
let mut reader = std::io::Cursor::new(include_bytes!(concat!("packs/pack_", $version, $compress, $encrypt, $encryptindex, ".pak")));
|
||||
let mut reader = std::io::Cursor::new(bytes);
|
||||
let pak_reader = repak::PakReader::new_any(&mut reader, Some(key)).unwrap();
|
||||
|
||||
let writer = Cursor::new(vec![]);
|
||||
|
@ -221,14 +177,65 @@ macro_rules! mt_encryptindex_write {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(pak_writer.write_index().unwrap().into_inner(), reader.into_inner());
|
||||
}
|
||||
}
|
||||
)*
|
||||
assert_eq!(
|
||||
pak_writer.write_index().unwrap().into_inner(),
|
||||
reader.into_inner()
|
||||
);
|
||||
}
|
||||
|
||||
macro_rules! matrix_test {
|
||||
( $name:literal, ($($version:literal $exp_version:expr),* $(,)?), $compress:tt, $encrypt:tt, $encryptindex:tt, $body:tt ) => {
|
||||
$( matrix_test_compress!($name, $version, $exp_version, $compress, $encrypt, $encryptindex, $body); )*
|
||||
};
|
||||
}
|
||||
|
||||
matrix_test_write!(
|
||||
macro_rules! matrix_test_compress {
|
||||
( $name:literal, $version:literal, $exp_version:expr, ($($compress:literal),* $(,)?), $encrypt:tt, $encryptindex:tt, $body:tt ) => {
|
||||
$( matrix_test_encrypt!($name, $version, $exp_version, $compress, $encrypt, $encryptindex, $body); )*
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! matrix_test_encrypt {
|
||||
( $name:literal, $version:literal, $exp_version:expr, $compress:literal, ($($encrypt:literal),* $(,)?), $encryptindex:tt, $body:tt ) => {
|
||||
$( matrix_test_encryptindex!($name, $version, $exp_version, $compress, $encrypt, $encryptindex, $body); )*
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! matrix_test_encryptindex {
|
||||
( $name:literal, $version:literal, $exp_version:expr, $compress:literal, $encrypt:literal, ($($encryptindex:literal),* $(,)?), $body:tt ) => {
|
||||
$( matrix_test_body!($name, $version, $exp_version, $compress, $encrypt, $encryptindex, $body); )*
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! matrix_test_body {
|
||||
( $name:literal, $version:literal, $exp_version:expr, $compress:literal, $encrypt:literal, $encryptindex:literal, $body:expr ) => {
|
||||
paste! {
|
||||
#[test]
|
||||
fn [< test_ $name _version_ $version $compress $encrypt $encryptindex >]() {
|
||||
$body($exp_version, include_bytes!(concat!("packs/pack_", $version, $compress, $encrypt, $encryptindex, ".pak")));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
matrix_test!(
|
||||
"read",
|
||||
(
|
||||
"v5" repak::Version::V5,
|
||||
"v7" repak::Version::V7,
|
||||
"v8a" repak::Version::V8A,
|
||||
"v8b" repak::Version::V8B,
|
||||
"v9" repak::Version::V9,
|
||||
"v11" repak::Version::V11,
|
||||
),
|
||||
("", "_compress"),
|
||||
("", "_encrypt"),
|
||||
("", "_encryptindex"),
|
||||
test_read
|
||||
);
|
||||
|
||||
matrix_test!(
|
||||
"write",
|
||||
(
|
||||
"v5" repak::Version::V5,
|
||||
"v7" repak::Version::V7,
|
||||
|
@ -239,5 +246,6 @@ matrix_test_write!(
|
|||
),
|
||||
("", /*"_compress"*/),
|
||||
("", /*"_encrypt"*/),
|
||||
("", /*"_encryptindex"*/)
|
||||
("", /*"_encryptindex"*/),
|
||||
test_write
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue