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> active_index: 0;
6 property<int> some_prop: 5;
7 text1 := Text {
8 property<int> foo; // this one is not initialized
9 animate foo { duration: 100ms; }
10 }
11
12 states [
13 xxx when active_index == 1 : {
14 text1.foo: 3000;
15 some_prop: 2000;
16 }
17 ]
18
19 animate some_prop { duration: 100ms; }
20
21
22 property<int> text1_foo: text1.foo;
23
24}
25
26
27/*
28
29```rust
30let instance = TestCase::new().unwrap();
31assert_eq!(instance.get_text1_foo(), 0);
32assert_eq!(instance.get_some_prop(), 5);
33instance.set_active_index(1);
34assert_eq!(instance.get_text1_foo(), 0);
35assert_eq!(instance.get_some_prop(), 5);
36slint_testing::mock_elapsed_time(75); // 75% the animation
37assert!(instance.get_some_prop() > 1500);
38assert!(instance.get_some_prop() < 1999);
39assert!(instance.get_text1_foo() > 2000);
40assert!(instance.get_text1_foo() < 2999);
41
42slint_testing::mock_elapsed_time(30); // more than 100% the animation
43assert_eq!(instance.get_text1_foo(), 3000);
44assert_eq!(instance.get_some_prop(), 2000);
45
46instance.set_active_index(2);
47assert_eq!(instance.get_text1_foo(), 3000);
48assert_eq!(instance.get_some_prop(), 2000);
49
50slint_testing::mock_elapsed_time(100);
51assert_eq!(instance.get_text1_foo(), 0);
52assert_eq!(instance.get_some_prop(), 5);
53
54```
55
56
57```cpp
58auto handle = TestCase::create();
59const TestCase &instance = *handle;
60assert_eq(instance.get_text1_foo(), 0);
61assert_eq(instance.get_some_prop(), 5);
62instance.set_active_index(1);
63assert_eq(instance.get_text1_foo(), 0);
64assert_eq(instance.get_some_prop(), 5);
65slint_testing::mock_elapsed_time(75); // 75% the animation
66assert(instance.get_some_prop() > 1500);
67assert(instance.get_some_prop() < 1999);
68assert(instance.get_text1_foo() > 2000);
69assert(instance.get_text1_foo() < 2999);
70
71slint_testing::mock_elapsed_time(30); // more than 100% the animation
72assert_eq(instance.get_text1_foo(), 3000);
73assert_eq(instance.get_some_prop(), 2000);
74
75instance.set_active_index(2);
76assert_eq(instance.get_text1_foo(), 3000);
77assert_eq(instance.get_some_prop(), 2000);
78
79slint_testing::mock_elapsed_time(100);
80assert_eq(instance.get_text1_foo(), 0);
81assert_eq(instance.get_some_prop(), 5);
82```
83
84
85```js
86var instance = new slint.TestCase({});
87assert.equal(instance.text1_foo, 0);
88assert.equal(instance.some_prop, 5);
89instance.active_index = 1;
90assert.equal(instance.text1_foo, 0);
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);
95assert(instance.text1_foo > 2000);
96assert(instance.text1_foo < 2999);
97
98slintlib.private_api.mock_elapsed_time(30); // more than 100% the animation
99assert.equal(instance.text1_foo, 3000);
100assert.equal(instance.some_prop, 2000);
101
102instance.active_index = 2;
103assert.equal(instance.text1_foo, 3000);
104assert.equal(instance.some_prop, 2000);
105
106slintlib.private_api.mock_elapsed_time(100);
107assert.equal(instance.text1_foo, 0);
108assert.equal(instance.some_prop, 5);
109```
110
111*/
112