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 | TestCase := 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 |
31 | let instance = TestCase::new().unwrap(); |
32 | assert_eq!(instance.get_hello(), 40); |
33 | assert_eq!(instance.get_binding_dep(), 100); |
34 | instance.set_condition(false); |
35 | instance.set_hello(60); |
36 | // no time has elapsed yet |
37 | assert_eq!(instance.get_hello(), 40); |
38 | assert_eq!(instance.get_binding_dep(), 100); |
39 | |
40 | // Half the animation |
41 | slint_testing::mock_elapsed_time(600); |
42 | assert_eq!(instance.get_hello(), 50); |
43 | assert_eq!(instance.get_binding_dep(), 125); |
44 | |
45 | |
46 | // Remaining half |
47 | slint_testing::mock_elapsed_time(600); |
48 | assert_eq!(instance.get_hello(), 60); |
49 | assert_eq!(instance.get_binding_dep(), 150); |
50 | |
51 | slint_testing::mock_elapsed_time(100); |
52 | assert_eq!(instance.get_hello(), 60); |
53 | assert_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) |
57 | instance.set_condition(true); |
58 | instance.set_hello(30); |
59 | slint_testing::mock_elapsed_time(600); |
60 | assert_eq!(instance.get_hello(), 45); |
61 | assert_eq!(instance.get_binding_dep(), 125); |
62 | |
63 | ``` |
64 | |
65 | |
66 | ```cpp |
67 | auto handle = TestCase::create(); |
68 | const TestCase &instance = *handle; |
69 | assert_eq(instance.get_hello(), 40); |
70 | assert_eq(instance.get_binding_dep(), 100); |
71 | instance.set_condition(false); |
72 | instance.set_hello(60); |
73 | // no time has elapsed yet |
74 | assert_eq(instance.get_hello(), 40); |
75 | assert_eq(instance.get_binding_dep(), 100); |
76 | |
77 | // Half the animation |
78 | slint_testing::mock_elapsed_time(600); |
79 | assert_eq(instance.get_hello(), 50); |
80 | assert_eq(instance.get_binding_dep(), 125); |
81 | |
82 | |
83 | // Remaining half |
84 | slint_testing::mock_elapsed_time(600); |
85 | assert_eq(instance.get_hello(), 60); |
86 | assert_eq(instance.get_binding_dep(), 150); |
87 | |
88 | slint_testing::mock_elapsed_time(100); |
89 | assert_eq(instance.get_hello(), 60); |
90 | assert_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) |
94 | instance.set_condition(true); |
95 | instance.set_hello(30); |
96 | slint_testing::mock_elapsed_time(600); |
97 | assert_eq(instance.get_hello(), 45); |
98 | assert_eq(instance.get_binding_dep(), 125); |
99 | ``` |
100 | |
101 | ```js |
102 | var instance = new slint.TestCase({}); |
103 | assert.equal(instance.hello, 40); |
104 | assert.equal(instance.binding_dep, 100); |
105 | instance.condition = false; |
106 | instance.hello = 60; |
107 | // no time has elapsed yet |
108 | assert.equal(instance.hello, 40); |
109 | assert.equal(instance.binding_dep, 100); |
110 | |
111 | // Half the animation |
112 | slintlib.private_api.mock_elapsed_time(600); |
113 | assert.equal(instance.hello, 50); |
114 | assert.equal(instance.binding_dep, 125); |
115 | // Remaining half |
116 | slintlib.private_api.mock_elapsed_time(600); |
117 | assert.equal(instance.hello, 60); |
118 | assert.equal(instance.binding_dep, 150); |
119 | slintlib.private_api.mock_elapsed_time(100); |
120 | assert.equal(instance.hello, 60); |
121 | assert.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) |
125 | instance.condition = true; |
126 | instance.hello = 30; |
127 | slintlib.private_api.mock_elapsed_time(600); |
128 | assert.equal(instance.hello, 45); |
129 | assert.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 | } |