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