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