mod tests_common; use rand::random; use tests_common::*; use ext2::OpenOptions; use std::fs::File; use std::io::{Read, Write}; #[test] fn read() { fn read_of_size(size: usize) { //create a disk of size of the file + a little space for metadata create_disk(size + 1024 * 1024 * 10); mount_disk(); let filename = "/simple_read"; /* WRITE with the std */ let v = { let filename_mounted = DISK_MOUNTED_NAME.to_owned() + "/" + filename; let mut f = File::create(&filename_mounted).expect(&format!( "open on mounted filesystem failed {}", &filename_mounted )); // random bytes to write let v: Vec = (0..(size)).map(|_| random::()).collect(); f.write_all(&v).expect("write on mouted filesystem failed"); v }; umount_disk(); /* READ with the ext2 */ let mut buf = vec![42; size]; let ext2 = new_ext2_instance::(); let mut f = OpenOptions::new() .read(true) .write(true) .create(true) .open(&filename, ext2) .unwrap(); let count = f.read(&mut buf).unwrap(); assert_eq!(count, size); assert_eq!(buf[..], v[..]); } let sizes = &[ 42, DIRECT_MAX_SIZE + 42, SINGLY_MAX_SIZE + 42, DOUBLY_MAX_SIZE + 42, ]; for size in sizes { read_of_size(*size); } }