Skip to content

Commit 6b34020

Browse files
author
Serban Iorga
committed
[GuestAddress] add unit tests
add unit tests for BitAnd, BitOr, Default
1 parent 43d86a5 commit 6b34020

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

memory_model/src/guest_address.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ pub trait Address:
5353
/// Get the raw value of the address.
5454
fn raw_value(&self) -> Self::V;
5555

56-
/// Returns the bitwise and of the address with the given mask.
57-
fn mask(&self, mask: Self::V) -> Self::V {
58-
self.raw_value() & mask
59-
}
60-
6156
/// Returns the offset from this address to the given base address.
6257
/// Only use this when `base` is guaranteed not to overflow.
6358
fn unchecked_offset_from(&self, base: Self) -> Self::V {
@@ -195,4 +190,23 @@ mod tests {
195190
assert_eq!(Some(GuestAddress(0x0f)), a.checked_sub(0xf0));
196191
assert!(a.checked_sub(0xffff).is_none());
197192
}
193+
194+
#[test]
195+
fn default() {
196+
assert_eq!(GuestAddress::default(), GuestAddress(0));
197+
}
198+
199+
#[test]
200+
fn and() {
201+
let a = GuestAddress(0x00);
202+
let b = GuestAddress(0xff);
203+
assert_eq!(a & b.raw_value(), a);
204+
}
205+
206+
#[test]
207+
fn or() {
208+
let a = GuestAddress(0x00);
209+
let b = GuestAddress(0xff);
210+
assert_eq!(a | b.raw_value(), b);
211+
}
198212
}

0 commit comments

Comments
 (0)