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