1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/crashes"# ] |
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 | // issue #177 |
6 | |
7 | export TestCase := Window { |
8 | width: 100px; |
9 | height: 100px; |
10 | |
11 | callback clicked; |
12 | clicked => { debug("Hello" ); model= []; } |
13 | property <bool> hover: under.has-hover; |
14 | property<[int]> model: [1]; |
15 | VerticalLayout { |
16 | under := TouchArea { |
17 | HorizontalLayout { |
18 | for value in model: TouchArea { |
19 | horizontal-stretch: 5; |
20 | vertical-stretch: 5; |
21 | clicked => { root.clicked(); } |
22 | Rectangle { background: blue; } |
23 | } |
24 | } |
25 | } |
26 | Rectangle { |
27 | horizontal-stretch: 0; |
28 | vertical-stretch: 0; |
29 | background: yellow; |
30 | } |
31 | } |
32 | |
33 | |
34 | } |
35 | |
36 | /* |
37 | |
38 | ```cpp |
39 | auto handle = TestCase::create(); |
40 | const TestCase &instance = *handle; |
41 | auto vec_model = std::make_shared<slint::VectorModel<int>>(std::vector<int>{1, 2}); |
42 | instance.set_model(vec_model); |
43 | instance.on_clicked([vec_model] { vec_model->erase(vec_model->row_count()-1); }); |
44 | slint_testing::send_mouse_click(&instance, 95., 5.); |
45 | assert_eq(instance.get_model()->row_count(), 1); |
46 | assert(instance.get_hover()); |
47 | slint_testing::send_mouse_click(&instance, 95., 5.); |
48 | assert_eq(instance.get_model()->row_count(), 0); |
49 | assert(!instance.get_hover()); |
50 | ``` |
51 | |
52 | ```rust |
53 | use slint::Model; |
54 | let instance = TestCase::new().unwrap(); |
55 | let vec_model = std::rc::Rc::new(slint::VecModel::from(vec![1i32, 2i32])); |
56 | instance.set_model(vec_model.clone().into()); |
57 | instance.on_clicked(move || { vec_model.remove(vec_model.row_count() - 1); }); |
58 | slint_testing::send_mouse_click(&instance, 95., 5.); |
59 | assert_eq!(instance.get_model().row_count(), 1); |
60 | assert!(instance.get_hover()); |
61 | slint_testing::send_mouse_click(&instance, 95., 5.); |
62 | assert_eq!(instance.get_model().row_count(), 0); |
63 | assert!(!instance.get_hover()); |
64 | ``` |
65 | |
66 | ```js |
67 | let model = new slintlib.ArrayModel([1, 2]); |
68 | var instance = new slint.TestCase({ |
69 | clicked: function() { model.pop(); } |
70 | }); |
71 | instance.model = model; |
72 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
73 | assert.equal(instance.model.length, 1); |
74 | assert(instance.hover); |
75 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
76 | assert.equal(instance.model.length, 0); |
77 | assert(!instance.hover); |
78 | ``` |
79 | */ |
80 | } |
81 | |
82 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
83 | use i_slint_backend_testing as slint_testing; |
84 | slint_testing::init(); |
85 | use slint::Model; |
86 | let instance = TestCase::new().unwrap(); |
87 | let vec_model: Rc> = std::rc::Rc::new(slint::VecModel::from(vec![1i32, 2i32])); |
88 | instance.set_model(vec_model.clone().into()); |
89 | instance.on_clicked(move || { vec_model.remove(index:vec_model.row_count() - 1); }); |
90 | slint_testing::send_mouse_click(&instance, x:95., y:5.); |
91 | assert_eq!(instance.get_model().row_count(), 1); |
92 | assert!(instance.get_hover()); |
93 | slint_testing::send_mouse_click(&instance, x:95., y:5.); |
94 | assert_eq!(instance.get_model().row_count(), 0); |
95 | assert!(!instance.get_hover()); |
96 | Ok(()) |
97 | } |