1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/globals"#]
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
5global Glo := {
6 property <int> hello: 42;
7 pure callback sum(int, int) -> int;
8 pure callback mul(int, int) -> int;
9 pure callback calculate_profit() -> int;
10 calculate_profit() => { return 1000; }
11}
12
13ExtraComp := Rectangle {
14 property<int> five: Glo.sum(3, 2);
15 property<int> six: Glo.mul(3, 2);
16}
17
18
19TestCase := Window {
20 pure callback sum <=> Glo.sum;
21 pure callback mul <=> Glo.mul;
22
23 x := ExtraComp {}
24 property<int> five: x.five;
25 property<int> six: x.six;
26
27 property<int> profit: Glo.calculate-profit();
28
29 //mul(α, β) => { return α * β; }
30 property<bool> test: five == 0 && profit == 1000; // because the callback is not set
31
32}
33
34/*
35```rust
36let instance = TestCase::new().unwrap();
37instance.on_sum(|a, b| a + b);
38instance.on_mul(|a, b| a * b);
39assert_eq!(instance.get_five(), 5);
40assert_eq!(instance.get_six(), 6);
41assert_eq!(instance.get_profit(), 1000);
42```
43
44```cpp
45auto handle = TestCase::create();
46const TestCase &instance = *handle;
47instance.on_sum([](int a, int b) { return a + b; });
48instance.on_mul([](int a, int b) { return a * b; });
49assert_eq(instance.get_five(), 5);
50assert_eq(instance.get_six(), 6);
51assert_eq(instance.get_profit(), 1000);
52```
53
54```js
55let instance = new slint.TestCase({
56 sum: function(a, b) { return a + b; },
57 mul: function(a, b) { return a * b; }
58});
59assert.equal(instance.five, 5);
60assert.equal(instance.six, 6);
61assert.equal(instance.profit, 1000);
62```
63
64*/
65}
66
67#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
68 use i_slint_backend_testing as slint_testing;
69 slint_testing::init();
70 let instance = TestCase::new().unwrap();
71 instance.on_sum(|a, b| a + b);
72 instance.on_mul(|a, b| a * b);
73 assert_eq!(instance.get_five(), 5);
74 assert_eq!(instance.get_six(), 6);
75 assert_eq!(instance.get_profit(), 1000);
76 Ok(())
77}