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
6TestCase := 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
37let instance = TestCase::new().unwrap();
38assert_eq!(instance.get_text1_foo(), 85 + 4);
39assert_eq!(instance.get_some_prop(), 5);
40instance.set_active_index(1);
41assert_eq!(instance.get_text1_foo(), 3 + 2 * 4);
42assert_eq!(instance.get_some_prop(), 5);
43slint_testing::mock_elapsed_time(75); // 75% the animation
44assert!(instance.get_some_prop() > 1500);
45assert!(instance.get_some_prop() < 1999);
46slint_testing::mock_elapsed_time(30); // more than 100% the animation
47assert_eq!(instance.get_some_prop(), 2000);
48
49instance.set_active_index(2);
50assert_eq!(instance.get_some_prop(), 5);
51assert_eq!(instance.get_text1_foo(), 3 + 2 * 4);
52slint_testing::mock_elapsed_time(290);
53assert!(instance.get_text1_foo() > 70);
54assert!(instance.get_text1_foo() < 87);
55slint_testing::mock_elapsed_time(30);
56assert_eq!(instance.get_text1_foo(), 85 + 4);
57```
58
59
60```cpp
61auto handle = TestCase::create();
62const TestCase &instance = *handle;
63assert_eq(instance.get_text1_foo(), 85 + 4);
64assert_eq(instance.get_some_prop(), 5);
65instance.set_active_index(1);
66assert_eq(instance.get_text1_foo(), 3 + 2 * 4);
67assert_eq(instance.get_some_prop(), 5);
68slint_testing::mock_elapsed_time(75); // 75% the animation
69assert(instance.get_some_prop() > 1500);
70assert(instance.get_some_prop() < 1999);
71slint_testing::mock_elapsed_time(30); // more than 100% the animation
72assert_eq(instance.get_some_prop(), 2000);
73
74instance.set_active_index(2);
75assert_eq(instance.get_some_prop(), 5);
76assert_eq(instance.get_text1_foo(), 3 + 2 * 4);
77slint_testing::mock_elapsed_time(290);
78assert(instance.get_text1_foo() > 70);
79assert(instance.get_text1_foo() < 87);
80slint_testing::mock_elapsed_time(30);
81assert_eq(instance.get_text1_foo(), 85 + 4);
82```
83
84
85```js
86var instance = new slint.TestCase({});
87assert.equal(instance.text1_foo, 85 + 4);
88assert.equal(instance.some_prop, 5);
89instance.active_index = 1;
90assert.equal(instance.text1_foo, 3 + 2 * 4);
91assert.equal(instance.some_prop, 5);
92slintlib.private_api.mock_elapsed_time(75); // 75% the animation
93assert(instance.some_prop > 1500);
94assert(instance.some_prop < 1999);
95slintlib.private_api.mock_elapsed_time(30); // more than 100% the animation
96assert.equal(instance.some_prop, 2000);
97
98instance.active_index = 2;
99assert.equal(instance.some_prop, 5);
100assert.equal(instance.text1_foo, 3 + 2 * 4);
101slintlib.private_api.mock_elapsed_time(290);
102assert(instance.text1_foo > 70);
103assert(instance.text1_foo < 87);
104slintlib.private_api.mock_elapsed_time(30);
105assert.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}