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 | |
6 | TestCase := Rectangle { |
7 | property<int> top_level: 4; |
8 | property<int> active_index: 0; |
9 | property<int> some_prop: 5; |
10 | text1 := Text { |
11 | property<int> foo: 85 + top_level; |
12 | } |
13 | |
14 | states [ |
15 | xxx when active_index == 1 : { |
16 | text1.foo: 3 + 2 * top_level; |
17 | some_prop: 2000; |
18 | in { |
19 | animate some_prop { duration: 100ms; } |
20 | } |
21 | out { |
22 | animate text1.foo { duration: 300ms; } |
23 | } |
24 | } |
25 | ] |
26 | |
27 | property<int> text1_foo: text1.foo; |
28 | |
29 | } |
30 | |
31 | |
32 | |
33 | |
34 | /* |
35 | |
36 | ```rust |
37 | let instance = TestCase::new().unwrap(); |
38 | assert_eq!(instance.get_text1_foo(), 85 + 4); |
39 | assert_eq!(instance.get_some_prop(), 5); |
40 | instance.set_active_index(1); |
41 | assert_eq!(instance.get_text1_foo(), 3 + 2 * 4); |
42 | assert_eq!(instance.get_some_prop(), 5); |
43 | slint_testing::mock_elapsed_time(75); // 75% the animation |
44 | assert!(instance.get_some_prop() > 1500); |
45 | assert!(instance.get_some_prop() < 1999); |
46 | slint_testing::mock_elapsed_time(30); // more than 100% the animation |
47 | assert_eq!(instance.get_some_prop(), 2000); |
48 | |
49 | instance.set_active_index(2); |
50 | assert_eq!(instance.get_some_prop(), 5); |
51 | assert_eq!(instance.get_text1_foo(), 3 + 2 * 4); |
52 | slint_testing::mock_elapsed_time(290); |
53 | assert!(instance.get_text1_foo() > 70); |
54 | assert!(instance.get_text1_foo() < 87); |
55 | slint_testing::mock_elapsed_time(30); |
56 | assert_eq!(instance.get_text1_foo(), 85 + 4); |
57 | ``` |
58 | |
59 | |
60 | ```cpp |
61 | auto handle = TestCase::create(); |
62 | const TestCase &instance = *handle; |
63 | assert_eq(instance.get_text1_foo(), 85 + 4); |
64 | assert_eq(instance.get_some_prop(), 5); |
65 | instance.set_active_index(1); |
66 | assert_eq(instance.get_text1_foo(), 3 + 2 * 4); |
67 | assert_eq(instance.get_some_prop(), 5); |
68 | slint_testing::mock_elapsed_time(75); // 75% the animation |
69 | assert(instance.get_some_prop() > 1500); |
70 | assert(instance.get_some_prop() < 1999); |
71 | slint_testing::mock_elapsed_time(30); // more than 100% the animation |
72 | assert_eq(instance.get_some_prop(), 2000); |
73 | |
74 | instance.set_active_index(2); |
75 | assert_eq(instance.get_some_prop(), 5); |
76 | assert_eq(instance.get_text1_foo(), 3 + 2 * 4); |
77 | slint_testing::mock_elapsed_time(290); |
78 | assert(instance.get_text1_foo() > 70); |
79 | assert(instance.get_text1_foo() < 87); |
80 | slint_testing::mock_elapsed_time(30); |
81 | assert_eq(instance.get_text1_foo(), 85 + 4); |
82 | ``` |
83 | |
84 | |
85 | ```js |
86 | var instance = new slint.TestCase({}); |
87 | assert.equal(instance.text1_foo, 85 + 4); |
88 | assert.equal(instance.some_prop, 5); |
89 | instance.active_index = 1; |
90 | assert.equal(instance.text1_foo, 3 + 2 * 4); |
91 | assert.equal(instance.some_prop, 5); |
92 | slintlib.private_api.mock_elapsed_time(75); // 75% the animation |
93 | assert(instance.some_prop > 1500); |
94 | assert(instance.some_prop < 1999); |
95 | slintlib.private_api.mock_elapsed_time(30); // more than 100% the animation |
96 | assert.equal(instance.some_prop, 2000); |
97 | |
98 | instance.active_index = 2; |
99 | assert.equal(instance.some_prop, 5); |
100 | assert.equal(instance.text1_foo, 3 + 2 * 4); |
101 | slintlib.private_api.mock_elapsed_time(290); |
102 | assert(instance.text1_foo > 70); |
103 | assert(instance.text1_foo < 87); |
104 | slintlib.private_api.mock_elapsed_time(30); |
105 | assert.equal(instance.text1_foo, 85 + 4); |
106 | ``` |
107 | |
108 | */ |
109 | } |
110 | |
111 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
112 | use i_slint_backend_testing as slint_testing; |
113 | slint_testing::init(); |
114 | let instance = TestCase::new().unwrap(); |
115 | assert_eq!(instance.get_text1_foo(), 85 + 4); |
116 | assert_eq!(instance.get_some_prop(), 5); |
117 | instance.set_active_index(1); |
118 | assert_eq!(instance.get_text1_foo(), 3 + 2 * 4); |
119 | assert_eq!(instance.get_some_prop(), 5); |
120 | slint_testing::mock_elapsed_time(75); // 75% the animation |
121 | assert!(instance.get_some_prop() > 1500); |
122 | assert!(instance.get_some_prop() < 1999); |
123 | slint_testing::mock_elapsed_time(30); // more than 100% the animation |
124 | assert_eq!(instance.get_some_prop(), 2000); |
125 | |
126 | instance.set_active_index(2); |
127 | assert_eq!(instance.get_some_prop(), 5); |
128 | assert_eq!(instance.get_text1_foo(), 3 + 2 * 4); |
129 | slint_testing::mock_elapsed_time(290); |
130 | assert!(instance.get_text1_foo() > 70); |
131 | assert!(instance.get_text1_foo() < 87); |
132 | slint_testing::mock_elapsed_time(30); |
133 | assert_eq!(instance.get_text1_foo(), 85 + 4); |
134 | Ok(()) |
135 | } |