use slint::platform::{Platform, PlatformError, WindowAdapter};
use std::cell::Cell;
use std::rc::Rc;
mod without_font {
slint::slint! {
export component WithoutFont inherits Window {
Text {
text: "Hello";
}
}
}
}
mod with_font {
slint::slint! {
import "../../../examples/slide_puzzle/plaster-font/Plaster-Regular.ttf";
export component WithFont inherits Window {
Text {
font-family: "Plaster";
text: "Hello";
}
}
}
}
struct FailingPlatform {
attempts: Cell<u32>,
}
impl Platform for FailingPlatform {
fn create_window_adapter(&self) -> Result<Rc<dyn WindowAdapter>, PlatformError> {
self.attempts.set(self.attempts.get() + 1);
Err(PlatformError::Other(format!(
"cannot create window adapter (attempt {})",
self.attempts.get()
)))
}
}
#[test]
fn window_adapter_creation_error_is_returned() {
slint::platform::set_platform(Box::new(FailingPlatform { attempts: Cell::new(0) })).unwrap();
let Err(PlatformError::Other(message)) = without_font::WithoutFont::new() else {
panic!("expected new() to fail with the platform error");
};
assert_eq!(message, "cannot create window adapter (attempt 1)");
let Err(PlatformError::Other(message)) = with_font::WithFont::new() else {
panic!("expected new() to fail with the platform error");
};
assert_eq!(message, "cannot create window adapter (attempt 2)");
}