-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathring_buffer.rs
More file actions
34 lines (31 loc) · 944 Bytes
/
Copy pathring_buffer.rs
File metadata and controls
34 lines (31 loc) · 944 Bytes
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
extern crate e2d2;
use e2d2::state::*;
#[test]
fn alloc_test() {
let rb = RingBuffer::new(1).unwrap();
drop(rb);
}
#[test]
fn write_at_offset_test() {
let mut rb = RingBuffer::new(4096).unwrap();
let input = vec![1, 2, 3, 4];
rb.write_at_offset(4095, &input[..]);
let mut output: Vec<_> = (0..input.len()).map(|_| 0).collect();
rb.read_from_offset(4095, &mut output[..]);
for idx in 0..input.len() {
assert_eq!(input[idx], output[idx]);
}
}
#[test]
fn read_write_tail_test() {
let mut rb = RingBuffer::new(4096).unwrap();
let input: Vec<_> = (0..8192).map(|i| (i & 0xff) as u8).collect();
let written = rb.write_at_tail(&input[..]);
assert_eq!(written, 4095);
let mut output: Vec<_> = (0..8192).map(|_| 0).collect();
let read = rb.read_from_head(&mut output[..]);
assert_eq!(read, written);
for idx in 0..read {
assert_eq!(input[idx], output[idx]);
}
}