1 | #![allow (unreachable_pub)] |
2 | //! Mock version of std::fs::OpenOptions; |
3 | use mockall::mock; |
4 | |
5 | use crate::fs::mocks::MockFile; |
6 | #[cfg (unix)] |
7 | use std::os::unix::fs::OpenOptionsExt; |
8 | #[cfg (windows)] |
9 | use std::os::windows::fs::OpenOptionsExt; |
10 | use std::{io, path::Path}; |
11 | |
12 | mock! { |
13 | #[derive(Debug)] |
14 | pub OpenOptions { |
15 | pub fn append(&mut self, append: bool) -> &mut Self; |
16 | pub fn create(&mut self, create: bool) -> &mut Self; |
17 | pub fn create_new(&mut self, create_new: bool) -> &mut Self; |
18 | pub fn open<P: AsRef<Path> + 'static>(&self, path: P) -> io::Result<MockFile>; |
19 | pub fn read(&mut self, read: bool) -> &mut Self; |
20 | pub fn truncate(&mut self, truncate: bool) -> &mut Self; |
21 | pub fn write(&mut self, write: bool) -> &mut Self; |
22 | } |
23 | impl Clone for OpenOptions { |
24 | fn clone(&self) -> Self; |
25 | } |
26 | #[cfg(unix)] |
27 | impl OpenOptionsExt for OpenOptions { |
28 | fn custom_flags(&mut self, flags: i32) -> &mut Self; |
29 | fn mode(&mut self, mode: u32) -> &mut Self; |
30 | } |
31 | #[cfg(windows)] |
32 | impl OpenOptionsExt for OpenOptions { |
33 | fn access_mode(&mut self, access: u32) -> &mut Self; |
34 | fn share_mode(&mut self, val: u32) -> &mut Self; |
35 | fn custom_flags(&mut self, flags: u32) -> &mut Self; |
36 | fn attributes(&mut self, val: u32) -> &mut Self; |
37 | fn security_qos_flags(&mut self, flags: u32) -> &mut Self; |
38 | } |
39 | } |
40 | |