1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/properties"#]
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 4741
6
7export component TestCase inherits Rectangle {
8 width: 120px;
9 height: 120px;
10
11 out property <int> hello: 40;
12 animate hello {
13 duration: 1200ms;
14 }
15 out property <int> unset_property;
16 animate unset_property {
17 duration: 1200ms;
18 }
19 private property<bool> condition: true;
20 out property<int> binding_dep: condition ? 100 : 150;
21 animate binding_dep {
22 duration: 1200ms;
23 }
24
25 in property <bool> c: true;
26 if c : TouchArea {
27 clicked => {
28 debug("CLICKED") ;
29 root.hello = 60;
30 root.condition = false;
31 unset_property = 100;
32 debug("DONE");
33 }
34 }
35}
36
37/*
38
39```rust
40let instance = TestCase::new().unwrap();
41assert_eq!(instance.get_hello(), 40);
42assert_eq!(instance.get_binding_dep(), 100);
43assert_eq!(instance.get_unset_property(), 0);
44slint_testing::send_mouse_click(&instance, 5., 5.);
45// no time has elapsed yet
46assert_eq!(instance.get_hello(), 40);
47assert_eq!(instance.get_binding_dep(), 100);
48assert_eq!(instance.get_unset_property(), 0);
49
50// Half the animation
51slint_testing::mock_elapsed_time(600);
52assert_eq!(instance.get_hello(), 50);
53assert_eq!(instance.get_binding_dep(), 125);
54assert_eq!(instance.get_unset_property(), 50);
55
56
57
58// Remaining half
59slint_testing::mock_elapsed_time(600);
60assert_eq!(instance.get_hello(), 60);
61assert_eq!(instance.get_binding_dep(), 150);
62assert_eq!(instance.get_unset_property(), 100);
63
64slint_testing::mock_elapsed_time(100);
65assert_eq!(instance.get_hello(), 60);
66assert_eq!(instance.get_binding_dep(), 150);
67
68
69```
70
71
72```cpp
73auto handle = TestCase::create();
74const TestCase &instance = *handle;
75assert_eq(instance.get_hello(), 40);
76assert_eq(instance.get_binding_dep(), 100);
77assert_eq(instance.get_unset_property(), 0);
78slint_testing::send_mouse_click(&instance, 5., 5.);
79// no time has elapsed yet
80assert_eq(instance.get_hello(), 40);
81assert_eq(instance.get_binding_dep(), 100);
82assert_eq(instance.get_unset_property(), 0);
83
84// Half the animation
85slint_testing::mock_elapsed_time(600);
86assert_eq(instance.get_hello(), 50);
87assert_eq(instance.get_binding_dep(), 125);
88assert_eq(instance.get_unset_property(), 50);
89
90
91// Remaining half
92slint_testing::mock_elapsed_time(600);
93assert_eq(instance.get_hello(), 60);
94assert_eq(instance.get_binding_dep(), 150);
95assert_eq(instance.get_unset_property(), 100);
96
97slint_testing::mock_elapsed_time(100);
98assert_eq(instance.get_hello(), 60);
99assert_eq(instance.get_binding_dep(), 150);
100assert_eq(instance.get_unset_property(), 100);
101```
102
103```js
104var instance = new slint.TestCase({});
105assert.equal(instance.hello, 40);
106assert.equal(instance.binding_dep, 100);
107assert.equal(instance.unset_property, 0);
108slintlib.private_api.send_mouse_click(instance, 5., 5.);
109// no time has elapsed yet
110assert.equal(instance.hello, 40);
111assert.equal(instance.binding_dep, 100);
112assert.equal(instance.unset_property, 0);
113
114// Half the animation
115slintlib.private_api.mock_elapsed_time(600);
116assert.equal(instance.hello, 50);
117assert.equal(instance.binding_dep, 125);
118assert.equal(instance.unset_property, 50);
119// Remaining half
120slintlib.private_api.mock_elapsed_time(600);
121assert.equal(instance.hello, 60);
122assert.equal(instance.binding_dep, 150);
123assert.equal(instance.unset_property, 100);
124slintlib.private_api.mock_elapsed_time(100);
125assert.equal(instance.hello, 60);
126assert.equal(instance.binding_dep, 150);
127assert.equal(instance.unset_property, 100);
128
129```
130*/
131}
132
133#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
134 use i_slint_backend_testing as slint_testing;
135 slint_testing::init();
136 let instance = TestCase::new().unwrap();
137 assert_eq!(instance.get_hello(), 40);
138 assert_eq!(instance.get_binding_dep(), 100);
139 assert_eq!(instance.get_unset_property(), 0);
140 slint_testing::send_mouse_click(&instance, 5., 5.);
141 // no time has elapsed yet
142 assert_eq!(instance.get_hello(), 40);
143 assert_eq!(instance.get_binding_dep(), 100);
144 assert_eq!(instance.get_unset_property(), 0);
145
146 // Half the animation
147 slint_testing::mock_elapsed_time(600);
148 assert_eq!(instance.get_hello(), 50);
149 assert_eq!(instance.get_binding_dep(), 125);
150 assert_eq!(instance.get_unset_property(), 50);
151
152
153
154 // Remaining half
155 slint_testing::mock_elapsed_time(600);
156 assert_eq!(instance.get_hello(), 60);
157 assert_eq!(instance.get_binding_dep(), 150);
158 assert_eq!(instance.get_unset_property(), 100);
159
160 slint_testing::mock_elapsed_time(100);
161 assert_eq!(instance.get_hello(), 60);
162 assert_eq!(instance.get_binding_dep(), 150);
163
164
165 Ok(())
166}