author | alfadur |
Fri, 23 Aug 2019 19:26:52 +0300 | |
changeset 15350 | 81037b6052f4 |
parent 14435 | a1613788130d |
permissions | -rw-r--r-- |
14435
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
1 |
use std::io::Read; |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
2 |
use std::path::Path; |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
3 |
|
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
4 |
use physfs::{ PhysFSContext, file }; |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
5 |
|
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
6 |
#[test] |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
7 |
fn read_file_from_directory() { |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
8 |
let con = match PhysFSContext::new() { |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
9 |
Err(e) => panic!(e), |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
10 |
Ok(con) => con |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
11 |
}; |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
12 |
|
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
13 |
assert!(PhysFSContext::is_init()); |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
14 |
|
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
15 |
match con.mount(&Path::new(super::PATH_TO_HERE), "/test/".to_string(), true) { |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
16 |
Err(e) => panic!(e), |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
17 |
_ => () |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
18 |
} |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
19 |
|
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
20 |
let mut file = match file::File::open(&con, "/test/directory/read.txt".to_string(), file::Mode::Read) { |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
21 |
Ok(f) => f, |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
22 |
Err(e) => panic!(e) |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
23 |
}; |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
24 |
|
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
25 |
let buf = &mut [0; 32]; |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
26 |
|
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
27 |
match file.read(buf) { |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
28 |
Err(e) => panic!(e), |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
29 |
_ => () |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
30 |
} |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
31 |
|
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
32 |
let mut contents = String::new(); |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
33 |
for &mut byte in buf { |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
34 |
if byte == 0 { break } |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
35 |
contents.push(byte as char); |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
36 |
} |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
37 |
|
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
38 |
assert!(contents == "Read from me."); |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
39 |
} |
a1613788130d
Adopt physfs-rs lib and adapt it to recent std library, remove global mutex
unc0rr
parents:
diff
changeset
|
40 |