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