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
5TestCase := 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
15auto handle = TestCase::create();
16const TestCase &instance = *handle;
17instance.set_condition(true);
18assert_eq(instance.get_test_value(), 1);
19assert_eq(instance.get_test_value2(), 2);
20instance.set_condition(false);
21assert_eq(instance.get_test_value(), 2);
22assert_eq(instance.get_test_value2(), 4);
23instance.set_condition2(true);
24assert_eq(instance.get_test_value2(), 3);
25assert_eq(instance.get_test_value3(), 12.);
26```
27
28
29```rust
30let instance = TestCase::new().unwrap();
31instance.set_condition(true);
32assert_eq!(instance.get_test_value(), 1);
33assert_eq!(instance.get_test_value2(), 2);
34instance.set_condition(false);
35assert_eq!(instance.get_test_value(), 2);
36assert_eq!(instance.get_test_value2(), 4);
37instance.set_condition2(true);
38assert_eq!(instance.get_test_value2(), 3);
39assert_eq!(instance.get_test_value3(), 12.);
40```
41
42```js
43var instance = new slint.TestCase({});
44instance.condition = true;
45assert.equal(instance.test_value, 1);
46assert.equal(instance.test_value2, 2);
47instance.condition = false;
48assert.equal(instance.test_value, 2);
49assert.equal(instance.test_value2, 4);
50instance.condition2 = true;
51assert.equal(instance.test_value2, 3);
52assert.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}