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