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 | |
5 | TestCase := 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 |
39 | auto handle = TestCase::create(); |
40 | const TestCase &instance = *handle; |
41 | assert_eq(instance.get_value(), 100); |
42 | assert(instance.get_test()); |
43 | instance.set_toggle(true); |
44 | assert_eq(instance.get_value(), 42); |
45 | |
46 | instance.invoke_test_signal(); |
47 | assert(instance.get_signal_handled()); |
48 | |
49 | instance.set_signal_handled(false); |
50 | instance.set_block_signal(true); |
51 | instance.invoke_test_signal(); |
52 | assert(!instance.get_signal_handled()); |
53 | ``` |
54 | |
55 | ```rust |
56 | let instance = TestCase::new().unwrap(); |
57 | assert_eq!(instance.get_value(), 100); |
58 | assert!(instance.get_test()); |
59 | instance.set_toggle(true); |
60 | assert_eq!(instance.get_value(), 42); |
61 | |
62 | instance.invoke_test_signal(); |
63 | assert!(instance.get_signal_handled()); |
64 | |
65 | instance.set_signal_handled(false); |
66 | instance.set_block_signal(true); |
67 | instance.invoke_test_signal(); |
68 | assert!(!instance.get_signal_handled()); |
69 | ``` |
70 | |
71 | |
72 | ```js |
73 | var instance = new slint.TestCase({}); |
74 | assert.equal(instance.value, 100); |
75 | assert(instance.test); |
76 | instance.toggle = (true); |
77 | assert.equal(instance.value, 42); |
78 | |
79 | instance.test_signal(); |
80 | assert(instance.signal_handled); |
81 | |
82 | instance.signal_handled = (false); |
83 | instance.block_signal = (true); |
84 | instance.test_signal(); |
85 | assert(!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 | } |