]> git.proxmox.com Git - rustc.git/blob - library/std/src/sys/sgx/waitqueue/unsafe_list/tests.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / library / std / src / sys / sgx / waitqueue / unsafe_list / tests.rs
1 use super::*;
2 use crate::cell::Cell;
3
4 unsafe fn assert_empty<T>(list: &mut UnsafeList<T>) {
5 assert!(list.pop().is_none(), "assertion failed: list is not empty");
6 }
7
8 #[test]
9 fn init_empty() {
10 unsafe {
11 assert_empty(&mut UnsafeList::<i32>::new());
12 }
13 }
14
15 #[test]
16 fn push_pop() {
17 unsafe {
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);
23 }
24 }
25
26 #[test]
27 fn push_remove() {
28 unsafe {
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);
34 }
35 }
36
37 #[test]
38 fn push_remove_pop() {
39 unsafe {
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);
51
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);
58
59 assert_eq!(list.push(&mut node1), &11);
60 assert_eq!(list.pop().unwrap(), &11);
61 assert_empty(&mut list);
62
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);
68 }
69 }
70
71 #[test]
72 fn complex_pushes_pops() {
73 unsafe {
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);
89 }
90 }
91
92 #[test]
93 fn cell() {
94 unsafe {
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);
102 }
103 }