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 | export component TestCase { |
6 | in property <int> xx : 1000; |
7 | out property <int> yy: xx * 10; |
8 | animate yy { |
9 | duration: 1s; |
10 | easing: linear; |
11 | } |
12 | } |
13 | |
14 | /* |
15 | |
16 | ```rust |
17 | let instance = TestCase::new().unwrap(); |
18 | instance.set_xx(500); |
19 | // It's the first time we query the value: so no animation |
20 | assert_eq!(instance.get_yy(), 5000); |
21 | instance.set_xx(1000); |
22 | // now it is animated |
23 | slint_testing::mock_elapsed_time(500); |
24 | assert_eq!(instance.get_yy(), 7500); |
25 | instance.set_xx(500); |
26 | slint_testing::mock_elapsed_time(500); |
27 | assert_eq!(instance.get_yy(), 7500 - 2500/2); |
28 | slint_testing::mock_elapsed_time(5000); |
29 | instance.set_xx(1000); |
30 | assert_eq!(instance.get_yy(), 7500 - 2500/2); // even if time has passed, since we reset the xx value, it is as if no time had passed |
31 | slint_testing::mock_elapsed_time(500); |
32 | instance.set_xx(1000); |
33 | slint_testing::mock_elapsed_time(250); |
34 | assert_eq!(instance.get_yy(), 9063); |
35 | slint_testing::mock_elapsed_time(250); |
36 | assert_eq!(instance.get_yy(), 10000); |
37 | ``` |
38 | |
39 | |
40 | */ |
41 | } |
42 | |
43 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
44 | use i_slint_backend_testing as slint_testing; |
45 | slint_testing::init(); |
46 | let instance = TestCase::new().unwrap(); |
47 | instance.set_xx(500); |
48 | // It's the first time we query the value: so no animation |
49 | assert_eq!(instance.get_yy(), 5000); |
50 | instance.set_xx(1000); |
51 | // now it is animated |
52 | slint_testing::mock_elapsed_time(500); |
53 | assert_eq!(instance.get_yy(), 7500); |
54 | instance.set_xx(500); |
55 | slint_testing::mock_elapsed_time(500); |
56 | assert_eq!(instance.get_yy(), 7500 - 2500/2); |
57 | slint_testing::mock_elapsed_time(5000); |
58 | instance.set_xx(1000); |
59 | assert_eq!(instance.get_yy(), 7500 - 2500/2); // even if time has passed, since we reset the xx value, it is as if no time had passed |
60 | slint_testing::mock_elapsed_time(500); |
61 | instance.set_xx(1000); |
62 | slint_testing::mock_elapsed_time(250); |
63 | assert_eq!(instance.get_yy(), 9063); |
64 | slint_testing::mock_elapsed_time(250); |
65 | assert_eq!(instance.get_yy(), 10000); |
66 | Ok(()) |
67 | } |