1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Pointers in the EVE memory space.

pub mod region;

mod ptr;
mod slice;

#[doc(inline)]
pub use ptr::Ptr;

#[doc(inline)]
pub use slice::Slice;

pub(crate) use region::*;

#[cfg(test)]
mod tests {
    use super::*;
    use crate::models::testing::Exhaustive;
    use crate::models::Model;

    #[test]
    fn test_ptr_eq() {
        assert_eq!(
            <Exhaustive as Model>::MainMem::ptr(1),
            <Exhaustive as Model>::MainMem::ptr(1)
        );
        assert_ne!(
            <Exhaustive as Model>::MainMem::ptr(1),
            <Exhaustive as Model>::MainMem::ptr(2)
        );
        // Addresses from different memory regions on the same model are
        // comparable, but will always return false because the address
        // regions are required to be disjoint within a model.
        assert_ne!(
            <Exhaustive as Model>::MainMem::ptr(1),
            <Exhaustive as Model>::DisplayListMem::ptr(1)
        );
    }

    #[test]
    fn test_ptr_cmp() {
        assert!(<Exhaustive as Model>::MainMem::ptr(1) < <Exhaustive as Model>::MainMem::ptr(2));
        assert!(<Exhaustive as Model>::MainMem::ptr(2) >= <Exhaustive as Model>::MainMem::ptr(2));
        // Addresses from different memory regions on the same model are
        // comparable, and reflect the relative positions of those regions
        // in the memory map. In the case of the "Exhaustive" testing model,
        // MainMem is at lower addresses than DisplayListMem in the memory
        // map.
        assert!(
            <Exhaustive as Model>::MainMem::ptr(1) < <Exhaustive as Model>::DisplayListMem::ptr(1)
        );
        assert!(
            !(<Exhaustive as Model>::MainMem::ptr(1)
                > <Exhaustive as Model>::DisplayListMem::ptr(1))
        );
    }
}