aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2021-07-03 16:13:48 -0700
committeriximeow <me@iximeow.net>2021-07-03 16:13:48 -0700
commit282645e18ac920b2c1051a0bdf3e3236ee5839d6 (patch)
tree46b054c118063c66d422c27bfcd8b7dc199d0b24 /test
parent7e154da8e2bd7b8892bdefe2f71c111c2135b0a3 (diff)
add tests for MemoryAccessSize, consistentify style on docs
Diffstat (limited to 'test')
-rw-r--r--test/long_mode/operand.rs15
-rw-r--r--test/protected_mode/operand.rs14
2 files changed, 27 insertions, 2 deletions
diff --git a/test/long_mode/operand.rs b/test/long_mode/operand.rs
index 77ce256..5a51ef3 100644
--- a/test/long_mode/operand.rs
+++ b/test/long_mode/operand.rs
@@ -1,4 +1,4 @@
-use yaxpeax_x86::long_mode::{Operand, RegSpec};
+use yaxpeax_x86::long_mode::{InstDecoder, MemoryAccessSize, Operand, RegSpec};
#[test]
fn register_widths() {
@@ -12,5 +12,18 @@ fn register_widths() {
#[test]
fn memory_widths() {
+ // the register operand directly doesn't report a size - it comes from the `Instruction` for
+ // which this is an operand.
assert_eq!(Operand::RegDeref(RegSpec::rsp()).width(), None);
+
+ fn mem_size_of(data: &[u8]) -> MemoryAccessSize {
+ let decoder = InstDecoder::default();
+ decoder.decode_slice(data).unwrap().mem_size().unwrap()
+ }
+
+ // and checking the memory size direcly reports correct names
+ assert_eq!(mem_size_of(&[0x32, 0x00]).size_name(), "byte");
+ assert_eq!(mem_size_of(&[0x66, 0x33, 0x00]).size_name(), "word");
+ assert_eq!(mem_size_of(&[0x33, 0x00]).size_name(), "dword");
+ assert_eq!(mem_size_of(&[0x48, 0x33, 0x00]).size_name(), "qword");
}
diff --git a/test/protected_mode/operand.rs b/test/protected_mode/operand.rs
index 028cb8f..b2d3624 100644
--- a/test/protected_mode/operand.rs
+++ b/test/protected_mode/operand.rs
@@ -1,4 +1,4 @@
-use yaxpeax_x86::protected_mode::{Operand, RegSpec};
+use yaxpeax_x86::protected_mode::{InstDecoder, MemoryAccessSize, Operand, RegSpec};
#[test]
fn register_widths() {
@@ -11,5 +11,17 @@ fn register_widths() {
#[test]
fn memory_widths() {
+ // the register operand directly doesn't report a size - it comes from the `Instruction` for
+ // which this is an operand.
assert_eq!(Operand::RegDeref(RegSpec::esp()).width(), None);
+
+ fn mem_size_of(data: &[u8]) -> MemoryAccessSize {
+ let decoder = InstDecoder::default();
+ decoder.decode_slice(data).unwrap().mem_size().unwrap()
+ }
+
+ // and checking the memory size direcly reports correct names
+ assert_eq!(mem_size_of(&[0x32, 0x00]).size_name(), "byte");
+ assert_eq!(mem_size_of(&[0x66, 0x33, 0x00]).size_name(), "word");
+ assert_eq!(mem_size_of(&[0x33, 0x00]).size_name(), "dword");
}