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 | |
7 | export 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 |
40 | let instance = TestCase::new().unwrap(); |
41 | assert_eq!(instance.get_hello(), 40); |
42 | assert_eq!(instance.get_binding_dep(), 100); |
43 | assert_eq!(instance.get_unset_property(), 0); |
44 | slint_testing::send_mouse_click(&instance, 5., 5.); |
45 | // no time has elapsed yet |
46 | assert_eq!(instance.get_hello(), 40); |
47 | assert_eq!(instance.get_binding_dep(), 100); |
48 | assert_eq!(instance.get_unset_property(), 0); |
49 | |
50 | // Half the animation |
51 | slint_testing::mock_elapsed_time(600); |
52 | assert_eq!(instance.get_hello(), 50); |
53 | assert_eq!(instance.get_binding_dep(), 125); |
54 | assert_eq!(instance.get_unset_property(), 50); |
55 | |
56 | |
57 | |
58 | // Remaining half |
59 | slint_testing::mock_elapsed_time(600); |
60 | assert_eq!(instance.get_hello(), 60); |
61 | assert_eq!(instance.get_binding_dep(), 150); |
62 | assert_eq!(instance.get_unset_property(), 100); |
63 | |
64 | slint_testing::mock_elapsed_time(100); |
65 | assert_eq!(instance.get_hello(), 60); |
66 | assert_eq!(instance.get_binding_dep(), 150); |
67 | |
68 | |
69 | ``` |
70 | |
71 | |
72 | ```cpp |
73 | auto handle = TestCase::create(); |
74 | const TestCase &instance = *handle; |
75 | assert_eq(instance.get_hello(), 40); |
76 | assert_eq(instance.get_binding_dep(), 100); |
77 | assert_eq(instance.get_unset_property(), 0); |
78 | slint_testing::send_mouse_click(&instance, 5., 5.); |
79 | // no time has elapsed yet |
80 | assert_eq(instance.get_hello(), 40); |
81 | assert_eq(instance.get_binding_dep(), 100); |
82 | assert_eq(instance.get_unset_property(), 0); |
83 | |
84 | // Half the animation |
85 | slint_testing::mock_elapsed_time(600); |
86 | assert_eq(instance.get_hello(), 50); |
87 | assert_eq(instance.get_binding_dep(), 125); |
88 | assert_eq(instance.get_unset_property(), 50); |
89 | |
90 | |
91 | // Remaining half |
92 | slint_testing::mock_elapsed_time(600); |
93 | assert_eq(instance.get_hello(), 60); |
94 | assert_eq(instance.get_binding_dep(), 150); |
95 | assert_eq(instance.get_unset_property(), 100); |
96 | |
97 | slint_testing::mock_elapsed_time(100); |
98 | assert_eq(instance.get_hello(), 60); |
99 | assert_eq(instance.get_binding_dep(), 150); |
100 | assert_eq(instance.get_unset_property(), 100); |
101 | ``` |
102 | |
103 | ```js |
104 | var instance = new slint.TestCase({}); |
105 | assert.equal(instance.hello, 40); |
106 | assert.equal(instance.binding_dep, 100); |
107 | assert.equal(instance.unset_property, 0); |
108 | slintlib.private_api.send_mouse_click(instance, 5., 5.); |
109 | // no time has elapsed yet |
110 | assert.equal(instance.hello, 40); |
111 | assert.equal(instance.binding_dep, 100); |
112 | assert.equal(instance.unset_property, 0); |
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 | assert.equal(instance.unset_property, 50); |
119 | // Remaining half |
120 | slintlib.private_api.mock_elapsed_time(600); |
121 | assert.equal(instance.hello, 60); |
122 | assert.equal(instance.binding_dep, 150); |
123 | assert.equal(instance.unset_property, 100); |
124 | slintlib.private_api.mock_elapsed_time(100); |
125 | assert.equal(instance.hello, 60); |
126 | assert.equal(instance.binding_dep, 150); |
127 | assert.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 | } |