-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtests.rs
More file actions
68 lines (62 loc) · 1.65 KB
/
Copy pathtests.rs
File metadata and controls
68 lines (62 loc) · 1.65 KB
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
59
60
61
62
63
64
65
66
67
68
#![allow(unused_imports)]
#[cfg(test)]
extern crate core;
use alloc_no_stdlib::Allocator;
use super::HeapAllocator;
#[cfg(feature="stdlib")]
use alloc_no_stdlib::HeapAlloc;
#[cfg(all(feature="unsafe", feature="stdlib"))]
use alloc_no_stdlib::HeapAllocUninitialized;
#[test]
fn heap_test() {
let mut halloc : HeapAllocator<u8> = HeapAllocator::<u8>{default_value: 0};
for _i in 1..10 { // heap test
let mut x = halloc.alloc_cell(100000);
x[0] = 4;
let mut y = halloc.alloc_cell(110000);
y[0] = 5;
let mut z = halloc.alloc_cell(120000);
z[0] = 6;
assert_eq!(y[0], 5);
halloc.free_cell(y);
assert_eq!(x[0], 4);
assert_eq!(x[9], 0);
assert_eq!(z[0], 6);
}
}
#[cfg(all(feature="unsafe", feature="stdlib"))]
#[test]
fn std_unsafe_heap_test() {
let mut halloc = unsafe{HeapAllocUninitialized::<u8>::new()};
for _i in 1..10 { // heap test
let mut x = halloc.alloc_cell(100000);
x[0] = 4;
let mut y = halloc.alloc_cell(110000);
y[0] = 5;
let mut z = halloc.alloc_cell(120000);
z[0] = 6;
assert_eq!(y[0], 5);
halloc.free_cell(y);
assert_eq!(x[0], 4);
assert_eq!(x[9], 0);
assert_eq!(z[0], 6);
}
}
#[cfg(feature="stdlib")]
#[test]
fn std_heap_test() {
let mut halloc = HeapAlloc::<u8>::new(0);
for _i in 1..10 { // heap test
let mut x = halloc.alloc_cell(100000);
x[0] = 4;
let mut y = halloc.alloc_cell(110000);
y[0] = 5;
let mut z = halloc.alloc_cell(120000);
z[0] = 6;
assert_eq!(y[0], 5);
halloc.free_cell(y);
assert_eq!(x[0], 4);
assert_eq!(x[9], 0);
assert_eq!(z[0], 6);
}
}