]>
git.proxmox.com Git - rustc.git/blob - library/std/src/sys/sgx/waitqueue/unsafe_list/tests.rs
4 unsafe fn assert_empty
<T
>(list
: &mut UnsafeList
<T
>) {
5 assert
!(list
.pop().is_none(), "assertion failed: list is not empty");
11 assert_empty(&mut UnsafeList
::<i32>::new());
18 let mut node
= UnsafeListEntry
::new(1234);
19 let mut list
= UnsafeList
::new();
20 assert_eq
!(list
.push(&mut node
), &1234);
21 assert_eq
!(list
.pop().unwrap(), &1234);
22 assert_empty(&mut list
);
29 let mut node
= UnsafeListEntry
::new(1234);
30 let mut list
= UnsafeList
::new();
31 assert_eq
!(list
.push(&mut node
), &1234);
32 list
.remove(&mut node
);
33 assert_empty(&mut list
);
38 fn push_remove_pop() {
40 let mut node1
= UnsafeListEntry
::new(11);
41 let mut node2
= UnsafeListEntry
::new(12);
42 let mut node3
= UnsafeListEntry
::new(13);
43 let mut node4
= UnsafeListEntry
::new(14);
44 let mut node5
= UnsafeListEntry
::new(15);
45 let mut list
= UnsafeList
::new();
46 assert_eq
!(list
.push(&mut node1
), &11);
47 assert_eq
!(list
.push(&mut node2
), &12);
48 assert_eq
!(list
.push(&mut node3
), &13);
49 assert_eq
!(list
.push(&mut node4
), &14);
50 assert_eq
!(list
.push(&mut node5
), &15);
52 list
.remove(&mut node1
);
53 assert_eq
!(list
.pop().unwrap(), &12);
54 list
.remove(&mut node3
);
55 assert_eq
!(list
.pop().unwrap(), &14);
56 list
.remove(&mut node5
);
57 assert_empty(&mut list
);
59 assert_eq
!(list
.push(&mut node1
), &11);
60 assert_eq
!(list
.pop().unwrap(), &11);
61 assert_empty(&mut list
);
63 assert_eq
!(list
.push(&mut node3
), &13);
64 assert_eq
!(list
.push(&mut node4
), &14);
65 list
.remove(&mut node3
);
66 list
.remove(&mut node4
);
67 assert_empty(&mut list
);
72 fn complex_pushes_pops() {
74 let mut node1
= UnsafeListEntry
::new(1234);
75 let mut node2
= UnsafeListEntry
::new(4567);
76 let mut node3
= UnsafeListEntry
::new(9999);
77 let mut node4
= UnsafeListEntry
::new(8642);
78 let mut list
= UnsafeList
::new();
79 list
.push(&mut node1
);
80 list
.push(&mut node2
);
81 assert_eq
!(list
.pop().unwrap(), &1234);
82 list
.push(&mut node3
);
83 assert_eq
!(list
.pop().unwrap(), &4567);
84 assert_eq
!(list
.pop().unwrap(), &9999);
85 assert_empty(&mut list
);
86 list
.push(&mut node4
);
87 assert_eq
!(list
.pop().unwrap(), &8642);
88 assert_empty(&mut list
);
95 let mut node
= UnsafeListEntry
::new(Cell
::new(0));
96 let mut list
= UnsafeList
::new();
97 let noderef
= list
.push(&mut node
);
98 assert_eq
!(noderef
.get(), 0);
99 list
.pop().unwrap().set(1);
100 assert_empty(&mut list
);
101 assert_eq
!(noderef
.get(), 1);