1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
3
4 TestCase := Rectangle {
5 property<int> top_level: 4;
6 property<int> active_index: 0;
7 property<int> some_prop: 5;
8 text1 := Text {
9 property<int> foo: 85 + top_level;
10 }
11
12 states [
13 xxx when active_index == 1 : {
14 text1.foo: 3 + 2 * top_level;
15 some_prop: 2000;
16 }
17 ]
18
19 transitions [
20 in xxx: {
21 animate some_prop { duration: 100ms; }
22 }
23 out xxx: {
24 animate text1.foo { duration: 300ms; }
25 }
26 ]
27
28 property<int> text1_foo: text1.foo;
29
30}
31
32
33/*
34
35```rust
36let instance = TestCase::new().unwrap();
37assert_eq!(instance.get_text1_foo(), 85 + 4);
38assert_eq!(instance.get_some_prop(), 5);
39instance.set_active_index(1);
40assert_eq!(instance.get_text1_foo(), 3 + 2 * 4);
41assert_eq!(instance.get_some_prop(), 5);
42slint_testing::mock_elapsed_time(75); // 75% the animation
43assert!(instance.get_some_prop() > 1500);
44assert!(instance.get_some_prop() < 1999);
45slint_testing::mock_elapsed_time(30); // more than 100% the animation
46assert_eq!(instance.get_some_prop(), 2000);
47
48instance.set_active_index(2);
49assert_eq!(instance.get_some_prop(), 5);
50assert_eq!(instance.get_text1_foo(), 3 + 2 * 4);
51slint_testing::mock_elapsed_time(290);
52assert!(instance.get_text1_foo() > 70);
53assert!(instance.get_text1_foo() < 87);
54slint_testing::mock_elapsed_time(30);
55assert_eq!(instance.get_text1_foo(), 85 + 4);
56```
57
58
59```cpp
60auto handle = TestCase::create();
61const TestCase &instance = *handle;
62assert_eq(instance.get_text1_foo(), 85 + 4);
63assert_eq(instance.get_some_prop(), 5);
64instance.set_active_index(1);
65assert_eq(instance.get_text1_foo(), 3 + 2 * 4);
66assert_eq(instance.get_some_prop(), 5);
67slint_testing::mock_elapsed_time(75); // 75% the animation
68assert(instance.get_some_prop() > 1500);
69assert(instance.get_some_prop() < 1999);
70slint_testing::mock_elapsed_time(30); // more than 100% the animation
71assert_eq(instance.get_some_prop(), 2000);
72
73instance.set_active_index(2);
74assert_eq(instance.get_some_prop(), 5);
75assert_eq(instance.get_text1_foo(), 3 + 2 * 4);
76slint_testing::mock_elapsed_time(290);
77assert(instance.get_text1_foo() > 70);
78assert(instance.get_text1_foo() < 87);
79slint_testing::mock_elapsed_time(30);
80assert_eq(instance.get_text1_foo(), 85 + 4);
81```
82
83
84```js
85var instance = new slint.TestCase({});
86assert.equal(instance.text1_foo, 85 + 4);
87assert.equal(instance.some_prop, 5);
88instance.active_index = 1;
89assert.equal(instance.text1_foo, 3 + 2 * 4);
90assert.equal(instance.some_prop, 5);
91slintlib.private_api.mock_elapsed_time(75); // 75% the animation
92assert(instance.some_prop > 1500);
93assert(instance.some_prop < 1999);
94slintlib.private_api.mock_elapsed_time(30); // more than 100% the animation
95assert.equal(instance.some_prop, 2000);
96
97instance.active_index = 2;
98assert.equal(instance.some_prop, 5);
99assert.equal(instance.text1_foo, 3 + 2 * 4);
100slintlib.private_api.mock_elapsed_time(290);
101assert(instance.text1_foo > 70);
102assert(instance.text1_foo < 87);
103slintlib.private_api.mock_elapsed_time(30);
104assert.equal(instance.text1_foo, 85 + 4);
105```
106
107*/
108