Skip to main content

ferroui_browser/
win_stubs.rs

1use ferroui_base::platform::IBitmapImpl;
2use ferroui_controls::platform::{IPlatformIconLoader, IWindowIconImpl};
3use std::io;
4use std::rc::Rc;
5
6/// The icon loader of a platform without window icons.
7#[derive(Default)]
8pub struct IconLoaderStub;
9
10struct IconStub;
11
12impl IWindowIconImpl for IconStub {
13    fn save(&self, _output_stream: &mut dyn io::Write) -> io::Result<()> {
14        Ok(())
15    }
16}
17
18impl IPlatformIconLoader for IconLoaderStub {
19    fn load_icon_from_file(&self, _file_name: &str) -> io::Result<Rc<dyn IWindowIconImpl>> {
20        Ok(Rc::new(IconStub))
21    }
22
23    fn load_icon_from_stream(&self, _stream: &mut dyn io::Read) -> io::Result<Rc<dyn IWindowIconImpl>> {
24        Ok(Rc::new(IconStub))
25    }
26
27    fn load_icon_from_bitmap(&self, _bitmap: std::sync::Arc<ferroui_base::platform::SharedBitmapImpl>) -> Rc<dyn IWindowIconImpl> {
28        Rc::new(IconStub)
29    }
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[test]
37    fn every_source_gives_an_icon_that_saves_nothing() {
38        let loader = IconLoaderStub;
39        let mut output = Vec::new();
40
41        loader.load_icon_from_file("icon.ico").unwrap().save(&mut output).unwrap();
42        loader.load_icon_from_stream(&mut io::Cursor::new(vec![1, 2, 3])).unwrap().save(&mut output).unwrap();
43
44        assert!(output.is_empty());
45    }
46}