add macro tests

This commit is contained in:
Dmitry Belyaev 2022-08-27 23:58:04 +03:00
parent c3bf670f19
commit 1444dd6977
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -129,6 +129,8 @@ impl ApplyPatch for &mut [u8] {
mod tests {
use super::*;
use binnpatch_macro::{binnpat, binnpats, binnvec, binnvecs};
#[test]
fn bytes_from_pattern() {
let src_pattern = "E8 4D F8 FF 83 C4 85 C0 5F 75 32 8B 54 24 48 50 50";
@ -198,4 +200,59 @@ mod tests {
dst_data.as_mut_slice().apply_patch(offset, &replacement);
assert_eq!(dst_data, expected_data);
}
#[test]
fn bytes_from_pattern_macro() {
let pattern = binnpats!("E8 4D F8 FF 83 C4 85 C0 5F 75 32 8B 54 24 48 50 50");
let bytes: Vec<u8> = vec![
0xE8, 0x4D, 0xF8, 0xFF, 0x83, 0xC4, 0x85, 0xC0, 0x5F, 0x75, 0x32, 0x8B, 0x54, 0x24,
0x48, 0x50, 0x50,
];
assert_eq!(bytes, pattern.bytes);
}
#[test]
fn mask_from_pattern_macro() {
let pattern = binnpats!("E8 ?? ?? FF ?? C4 ?? ?? 5F 75 32 ?? 54 24 48 50 50");
let mask: Vec<bool> = vec![
false, true, true, false, true, false, true, true, false, false, false, true, false,
false, false, false, false,
];
assert_eq!(mask, pattern.mask);
}
#[test]
fn binnvec_macro() {
let actual = binnvec!(E8 4D F8 FF 83 C4 85 C0 5F 75 32 8B 54 24 48 50 50);
let expected: Vec<u8> = vec![
0xE8, 0x4D, 0xF8, 0xFF, 0x83, 0xC4, 0x85, 0xC0, 0x5F, 0x75, 0x32, 0x8B, 0x54, 0x24,
0x48, 0x50, 0x50,
];
assert_eq!(expected, actual);
}
#[test]
fn binnvecs_macro() {
let actual = binnvecs!("E8 4D F8 FF 83 C4 85 C0 5F 75 32 8B 54 24 48 50 50");
let expected: Vec<u8> = vec![
0xE8, 0x4D, 0xF8, 0xFF, 0x83, 0xC4, 0x85, 0xC0, 0x5F, 0x75, 0x32, 0x8B, 0x54, 0x24,
0x48, 0x50, 0x50,
];
assert_eq!(expected, actual);
}
#[test]
fn bytes_from_pattern_macro2() {
let pattern = binnpat!(E8 4D F8 FF 83 C4 85 C0 5F 75 32 8B 54 24 48 50 50);
let bytes: Vec<u8> = vec![
0xE8, 0x4D, 0xF8, 0xFF, 0x83, 0xC4, 0x85, 0xC0, 0x5F, 0x75, 0x32, 0x8B, 0x54, 0x24,
0x48, 0x50, 0x50,
];
assert_eq!(bytes, pattern.bytes);
}
#[test]
fn mask_from_pattern_macro2() {
let pattern = binnpat!(E8 ?? ?? FF ?? C4 ?? ?? 5F 75 32 ?? 54 24 48 50 50);
let mask: Vec<bool> = vec![
false, true, true, false, true, false, true, true, false, false, false, true, false,
false, false, false, false,
];
assert_eq!(mask, pattern.mask);
}
}