rust/physfs-rs/tests/directory/mod.rs
changeset 14435 a1613788130d
equal deleted inserted replaced
14434:632dfc73cf83 14435:a1613788130d
       
     1 use std::io::Read;
       
     2 use std::path::Path;
       
     3 
       
     4 use physfs::{ PhysFSContext, file };
       
     5 
       
     6 #[test]
       
     7 fn read_file_from_directory() {
       
     8     let con = match PhysFSContext::new() {
       
     9         Err(e) => panic!(e),
       
    10         Ok(con) => con
       
    11     };
       
    12 
       
    13     assert!(PhysFSContext::is_init());
       
    14 
       
    15     match con.mount(&Path::new(super::PATH_TO_HERE), "/test/".to_string(), true) {
       
    16         Err(e) => panic!(e),
       
    17         _ => ()
       
    18     }
       
    19 
       
    20     let mut file = match file::File::open(&con, "/test/directory/read.txt".to_string(), file::Mode::Read) {
       
    21         Ok(f) => f,
       
    22         Err(e) => panic!(e)
       
    23     };
       
    24 
       
    25     let buf = &mut [0; 32];
       
    26 
       
    27     match file.read(buf) {
       
    28         Err(e) => panic!(e),
       
    29         _ => ()
       
    30     }
       
    31 
       
    32     let mut contents = String::new();
       
    33     for &mut byte in buf {
       
    34         if byte == 0 { break }
       
    35         contents.push(byte as char);
       
    36     }
       
    37 
       
    38     assert!(contents == "Read from me.");
       
    39 }
       
    40