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
7export 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
39auto handle = TestCase::create();
40const TestCase &instance = *handle;
41auto vec_model = std::make_shared<slint::VectorModel<int>>(std::vector<int>{1, 2});
42instance.set_model(vec_model);
43instance.on_clicked([vec_model] { vec_model->erase(vec_model->row_count()-1); });
44slint_testing::send_mouse_click(&instance, 95., 5.);
45assert_eq(instance.get_model()->row_count(), 1);
46assert(instance.get_hover());
47slint_testing::send_mouse_click(&instance, 95., 5.);
48assert_eq(instance.get_model()->row_count(), 0);
49assert(!instance.get_hover());
50```
51
52```rust
53use slint::Model;
54let instance = TestCase::new().unwrap();
55let vec_model = std::rc::Rc::new(slint::VecModel::from(vec![1i32, 2i32]));
56instance.set_model(vec_model.clone().into());
57instance.on_clicked(move || { vec_model.remove(vec_model.row_count() - 1); });
58slint_testing::send_mouse_click(&instance, 95., 5.);
59assert_eq!(instance.get_model().row_count(), 1);
60assert!(instance.get_hover());
61slint_testing::send_mouse_click(&instance, 95., 5.);
62assert_eq!(instance.get_model().row_count(), 0);
63assert!(!instance.get_hover());
64```
65
66```js
67let model = new slintlib.ArrayModel([1, 2]);
68var instance = new slint.TestCase({
69 clicked: function() { model.pop(); }
70});
71instance.model = model;
72slintlib.private_api.send_mouse_click(instance, 5., 5.);
73assert.equal(instance.model.length, 1);
74assert(instance.hover);
75slintlib.private_api.send_mouse_click(instance, 5., 5.);
76assert.equal(instance.model.length, 0);
77assert(!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}