1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/elements"# ] |
2 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
3 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
4 | |
5 | // FIXME: Skip embedding test on C++ and NodeJS since ComponentFactory is not implemented there! |
6 | //ignore: cpp,js |
7 | |
8 | export component TestCase { |
9 | HorizontalLayout { |
10 | cont := ComponentContainer { } |
11 | } |
12 | in property<component-factory> component-factory <=> cont.component-factory; |
13 | out property<length> pref-height: root.preferred-height; |
14 | } |
15 | |
16 | /* |
17 | |
18 | |
19 | |
20 | ```rust |
21 | |
22 | // Test that it doesn't panic when we have some focus things in the init callback |
23 | use slint::ComponentHandle; |
24 | let inner_instance = std::rc::Rc::<core::cell::RefCell<Option<slint_interpreter::ComponentInstance>>>::default(); |
25 | let inner_instance_clone = inner_instance.clone(); |
26 | let factory = slint::ComponentFactory::new(move |ctx| { |
27 | let mut compiler = slint_interpreter::ComponentCompiler::new(); |
28 | let e = spin_on::spin_on(compiler.build_from_source( |
29 | r#"export component Inner { |
30 | preferred-height: 42px; |
31 | forward-focus: b; |
32 | b := TextInput { |
33 | text: "Hello 🌍"; |
34 | } |
35 | init => { |
36 | b.focus(); |
37 | b.select_all(); |
38 | b.set-selection-offsets(2, 2); |
39 | } |
40 | out property cursor <=> b.cursor_position_byte_offset ; |
41 | }"#.into(), |
42 | std::path::PathBuf::from("embedded.slint"), |
43 | )).unwrap_or_else(|| panic!("compile error {:?}", compiler.diagnostics())); |
44 | |
45 | let inner = e.create_embedded(ctx).unwrap(); |
46 | inner_instance_clone.replace(Some(inner.clone_strong())); |
47 | Some(inner) |
48 | }); |
49 | |
50 | let instance = TestCase::new().unwrap(); |
51 | instance.set_component_factory(factory.clone()); |
52 | assert_eq!(instance.get_pref_height(), 42.); |
53 | let cursor = inner_instance.borrow().as_ref().expect("should have been created").get_property("cursor").unwrap(); |
54 | assert_eq!(cursor, slint_interpreter::Value::from(2.)); |
55 | ``` |
56 | |
57 | |
58 | */ |
59 | } |
60 | |
61 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
62 | use i_slint_backend_testing as slint_testing; |
63 | slint_testing::init(); |
64 | |
65 | // Test that it doesn't panic when we have some focus things in the init callback |
66 | use slint::ComponentHandle; |
67 | let inner_instance = std::rc::Rc::<core::cell::RefCell<Option<slint_interpreter::ComponentInstance>>>::default(); |
68 | let inner_instance_clone = inner_instance.clone(); |
69 | let factory = slint::ComponentFactory::new(move |ctx| { |
70 | let mut compiler = slint_interpreter::ComponentCompiler::new(); |
71 | let e = spin_on::spin_on(compiler.build_from_source( |
72 | r#"export component Inner { |
73 | preferred-height: 42px; |
74 | forward-focus: b; |
75 | b := TextInput { |
76 | text: "Hello 🌍"; |
77 | } |
78 | init => { |
79 | b.focus(); |
80 | b.select_all(); |
81 | b.set-selection-offsets(2, 2); |
82 | } |
83 | out property cursor <=> b.cursor_position_byte_offset ; |
84 | }"# .into(), |
85 | std::path::PathBuf::from("embedded.slint" ), |
86 | )).unwrap_or_else(|| panic!("compile error {:?}" , compiler.diagnostics())); |
87 | |
88 | let inner = e.create_embedded(ctx).unwrap(); |
89 | inner_instance_clone.replace(Some(inner.clone_strong())); |
90 | Some(inner) |
91 | }); |
92 | |
93 | let instance = TestCase::new().unwrap(); |
94 | instance.set_component_factory(factory.clone()); |
95 | assert_eq!(instance.get_pref_height(), 42.); |
96 | let cursor = inner_instance.borrow().as_ref().expect("should have been created" ).get_property("cursor" ).unwrap(); |
97 | assert_eq!(cursor, slint_interpreter::Value::from(2.)); |
98 | Ok(()) |
99 | } |