1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/conditional"# ] |
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<bool> condition; |
7 | property<int> test_value: condition ? 1 : 2; |
8 | property<bool> condition2; |
9 | property<int> test_value2: condition ? condition2 ? 1 : 2 : condition2 ? 3 : 4; |
10 | |
11 | property<length> test_value3: false ? 0 : 12phx; |
12 | } |
13 | /* |
14 | ```cpp |
15 | auto handle = TestCase::create(); |
16 | const TestCase &instance = *handle; |
17 | instance.set_condition(true); |
18 | assert_eq(instance.get_test_value(), 1); |
19 | assert_eq(instance.get_test_value2(), 2); |
20 | instance.set_condition(false); |
21 | assert_eq(instance.get_test_value(), 2); |
22 | assert_eq(instance.get_test_value2(), 4); |
23 | instance.set_condition2(true); |
24 | assert_eq(instance.get_test_value2(), 3); |
25 | assert_eq(instance.get_test_value3(), 12.); |
26 | ``` |
27 | |
28 | |
29 | ```rust |
30 | let instance = TestCase::new().unwrap(); |
31 | instance.set_condition(true); |
32 | assert_eq!(instance.get_test_value(), 1); |
33 | assert_eq!(instance.get_test_value2(), 2); |
34 | instance.set_condition(false); |
35 | assert_eq!(instance.get_test_value(), 2); |
36 | assert_eq!(instance.get_test_value2(), 4); |
37 | instance.set_condition2(true); |
38 | assert_eq!(instance.get_test_value2(), 3); |
39 | assert_eq!(instance.get_test_value3(), 12.); |
40 | ``` |
41 | |
42 | ```js |
43 | var instance = new slint.TestCase({}); |
44 | instance.condition = true; |
45 | assert.equal(instance.test_value, 1); |
46 | assert.equal(instance.test_value2, 2); |
47 | instance.condition = false; |
48 | assert.equal(instance.test_value, 2); |
49 | assert.equal(instance.test_value2, 4); |
50 | instance.condition2 = true; |
51 | assert.equal(instance.test_value2, 3); |
52 | assert.equal(instance.test_value3, 12); |
53 | ``` |
54 | */ |
55 | } |
56 | |
57 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
58 | use i_slint_backend_testing as slint_testing; |
59 | slint_testing::init(); |
60 | let instance = TestCase::new().unwrap(); |
61 | instance.set_condition(true); |
62 | assert_eq!(instance.get_test_value(), 1); |
63 | assert_eq!(instance.get_test_value2(), 2); |
64 | instance.set_condition(false); |
65 | assert_eq!(instance.get_test_value(), 2); |
66 | assert_eq!(instance.get_test_value2(), 4); |
67 | instance.set_condition2(true); |
68 | assert_eq!(instance.get_test_value2(), 3); |
69 | assert_eq!(instance.get_test_value3(), 12.); |
70 | Ok(()) |
71 | } |