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