1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4import { ListView } from "std-widgets.slint";
5
6export component TestCase {
7 width: 300phx;
8 height: 300phx;
9 in-out property<[int]> model: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];
10
11 function assert(cond: bool, error: string) {
12 if (!cond && root.error == "") {
13 root.error = error;
14 }
15 }
16
17 out property <int> clicked;
18 out property <string> error;
19
20 ListView {
21 viewport-y: -530px;
22 for val[i] in model: TouchArea {
23 height: 100px;
24 clicked => {
25 assert(i == 6, "i = " + i + " ≠ 6");
26 assert(val == 6, "val = " + val + " ≠ 6");
27 val += 100;
28 assert(val == 106, "val = " + val + " ≠ 106");
29 model[i] += 1000;
30 assert(val == 1106, "val = " + val + " ≠ 1106");
31 root.clicked = val;
32 }
33 }
34 }
35
36}
37
38/*
39```rust
40let instance = TestCase::new().unwrap();
41
42slint_testing::send_mouse_click(&instance, 50., 155.);
43assert_eq!(instance.get_error().as_str(), "");
44assert_eq!(instance.get_clicked(), 1106);
45```
46
47```cpp
48auto handle = TestCase::create();
49const TestCase &instance = *handle;
50
51slint_testing::send_mouse_click(&instance, 50., 155.);
52assert_eq(instance.get_error(), "");
53assert_eq(instance.get_clicked(), 1106);
54
55```
56
57
58```js
59var instance = new slint.TestCase({});
60slintlib.private_api.send_mouse_click(instance, 50., 155.);
61
62
63assert.equal(instance.error, "");
64assert.equal(instance.clicked, 1106);
65```
66
67
68*/
69