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