From 1444dd69774ba9674f7aa4d437154bba1fbae823 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sat, 27 Aug 2022 23:58:04 +0300 Subject: [PATCH] add macro tests --- lib/src/lib.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 8322161..c139a77 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -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 = 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 = 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 = 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 = 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 = 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 = vec![ + false, true, true, false, true, false, true, true, false, false, false, true, false, + false, false, false, false, + ]; + assert_eq!(mask, pattern.mask); + } }