-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathlib.rs
More file actions
47 lines (38 loc) · 1.5 KB
/
lib.rs
File metadata and controls
47 lines (38 loc) · 1.5 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
#![allow(dead_code, unused_variables)]
mod address_space;
mod cacher;
mod data_source;
pub use address_space::{AddressSpace, FlagBuilder};
pub use data_source::{DataSource, FileDataSource};
use std::sync::Arc; // <- will have to make Arc ourselves for #no_std
// TODO: why does rustfmt say this is unused, but if I leave it out, undefined?
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn constructors() {
let _a = AddressSpace::new("my first address space");
let _ds: FileDataSource = FileDataSource::new("Cargo.toml").unwrap(); // a little silly, but why not?
}
// more tests here - add mappings, read data, remove mappings and add more, make sure the
// address space has what we expect in it after each operation
// test if mapping has been added
#[test]
fn test_add_mapping() {
let mut addr_space = AddressSpace::new("Test address space");
let data_source: FileDataSource = FileDataSource::new("Cargo.toml").unwrap();
let offset: usize = 0;
let length: usize = 1;
let read_flags = FlagBuilder::new().toggle_read();
let ds_arc = Arc::new(data_source);
let addr = addr_space
.add_mapping(ds_arc.clone(), offset, length, read_flags)
.unwrap();
assert!(addr != 0);
let addr2 = addr_space
.add_mapping(ds_arc.clone(), address_space::PAGE_SIZE, 0, read_flags)
.unwrap();
assert!(addr2 != 0);
assert!(addr2 != addr);
}
}