pub extern crate libc;
pub mod mem;
pub mod byte;
pub mod routine;
pub mod arch;
pub use mem::*;
pub use byte::*;
pub use routine::*;
pub use arch::*;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_mem() {
fn test_new() {
let mut mem = Mem::new(5);
match mem.get(2) {
Some(some) => assert_eq!(*some, 0x0),
None => panic!("value of index (1) is 'None'")
};
*match mem.get_mut(3) {
Some(some) => some,
None => panic!("value of index (3) is 'None'")
} = 0x1;
match mem.get(3) {
Some(some) => assert_eq!(*some, 0x1),
None => panic!("value of index (3) is 'None'")
};
assert_eq!(mem.len(), 5);
assert_eq!(mem.clone_into_vec(), vec![0x0, 0x0, 0x0, 0x1, 0x0]);
}
fn test_from() {
let mut mem = Mem::from(vec![0x0, 0x0, 0x0, 0x0, 0x0]);
match mem.get(2) {
Some(some) => assert_eq!(*some, 0x0),
None => panic!("value of index (1) is 'None'")
};
*match mem.get_mut(3) {
Some(some) => some,
None => panic!("value of index (3) is 'None'")
} = 0x1;
match mem.get(3) {
Some(some) => assert_eq!(*some, 0x1),
None => panic!("value of index (3) is 'None'")
};
assert_eq!(mem.len(), 5);
assert_eq!(mem.clone_into_vec(), vec![0x0, 0x0, 0x0, 0x1, 0x0]);
}
test_new();
test_from();
}
#[test]
fn test_routine() {
fn test_new() {
let mut mems: Vec<*mut Mem> = Vec::new();
let mut routine = Routine::new(&mut mems);
routine.push_vec(vec![
SYS_WRITE, stdout(), 'O' as Byte,
SYS_WRITE, stdout(), 'K' as Byte,
SYS_WRITE, stdout(), '\n' as Byte,
SYS_EXIT
]);
match routine.call() {
Some(some) => panic!("{}", some.to_string()),
None => ()
};
assert_eq!(routine.len(), 10);
assert_eq!(routine.clone_into_vec(), vec![
SYS_WRITE, stdout(), 'O' as Byte,
SYS_WRITE, stdout(), 'K' as Byte,
SYS_WRITE, stdout(), '\n' as Byte,
SYS_EXIT
]);
}
fn test_from() {
let mut mems: Vec<*mut Mem> = Vec::new();
let mut routine = Routine::from(vec![
SYS_WRITE, stdout(), 'O' as Byte,
SYS_WRITE, stdout(), 'K' as Byte,
SYS_WRITE, stdout(), '\n' as Byte,
SYS_EXIT
], &mut mems);
match routine.call() {
Some(some) => panic!("{}", some.to_string()),
None => ()
};
assert_eq!(routine.len(), 10);
assert_eq!(routine.clone_into_vec(), vec![
SYS_WRITE, stdout(), 'O' as Byte,
SYS_WRITE, stdout(), 'K' as Byte,
SYS_WRITE, stdout(), '\n' as Byte,
SYS_EXIT
]);
}
test_new();
test_from();
}
}