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