1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/expr"#]
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> toggle: { return false; }
7 property <int> value: {
8 if (toggle) {
9 return 42;
10 }
11 return 100;
12 }
13 property <float> value2: {
14 return 100;
15 }
16
17 in-out property <int> index: -1;
18 public function rust_fn_codegen_bug() -> bool {
19 return index != 0 && index != 1;
20 }
21 in-out property <bool> rust_binding_codegen_bug: {
22 return index != 42 && index != 42;
23 }
24
25 callback test_signal;
26 property <bool> block_signal;
27 property <bool> signal_handled;
28 test_signal => {
29 if (block_signal) {
30 return;
31 }
32 signal_handled = true;
33 }
34
35 property<bool> test: { return value2 == value; return false; }
36}
37/*
38```cpp
39auto handle = TestCase::create();
40const TestCase &instance = *handle;
41assert_eq(instance.get_value(), 100);
42assert(instance.get_test());
43instance.set_toggle(true);
44assert_eq(instance.get_value(), 42);
45
46instance.invoke_test_signal();
47assert(instance.get_signal_handled());
48
49instance.set_signal_handled(false);
50instance.set_block_signal(true);
51instance.invoke_test_signal();
52assert(!instance.get_signal_handled());
53```
54
55```rust
56let instance = TestCase::new().unwrap();
57assert_eq!(instance.get_value(), 100);
58assert!(instance.get_test());
59instance.set_toggle(true);
60assert_eq!(instance.get_value(), 42);
61
62instance.invoke_test_signal();
63assert!(instance.get_signal_handled());
64
65instance.set_signal_handled(false);
66instance.set_block_signal(true);
67instance.invoke_test_signal();
68assert!(!instance.get_signal_handled());
69```
70
71
72```js
73var instance = new slint.TestCase({});
74assert.equal(instance.value, 100);
75assert(instance.test);
76instance.toggle = (true);
77assert.equal(instance.value, 42);
78
79instance.test_signal();
80assert(instance.signal_handled);
81
82instance.signal_handled = (false);
83instance.block_signal = (true);
84instance.test_signal();
85assert(!instance._signal_handled);
86```
87
88*/
89}
90
91#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
92 use i_slint_backend_testing as slint_testing;
93 slint_testing::init();
94 let instance = TestCase::new().unwrap();
95 assert_eq!(instance.get_value(), 100);
96 assert!(instance.get_test());
97 instance.set_toggle(true);
98 assert_eq!(instance.get_value(), 42);
99
100 instance.invoke_test_signal();
101 assert!(instance.get_signal_handled());
102
103 instance.set_signal_handled(false);
104 instance.set_block_signal(true);
105 instance.invoke_test_signal();
106 assert!(!instance.get_signal_handled());
107 Ok(())
108}