1#![allow(deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/globals/../../helper_components"#]
2#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/globals"#]
3// Copyright © SixtyFPS GmbH <info@slint.dev>
4// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
5
6//include_path: ../../helper_components
7
8import { StyleMetrics } from "std-widgets.slint";
9import { ExportedGlobal as ReexportedGlobal } from "export_globals.slint";
10
11struct MyStruct := { x:int, y: int, }
12
13global InternalGlobal := {
14 property <int> hello: 42;
15 property <MyStruct> my_struct;
16 pure callback sum(int, int)->int;
17}
18
19export { InternalGlobal as PublicGlobal }
20export { ReexportedGlobal }
21
22TestCase := Rectangle {
23 property <bool> test_global_prop_value: InternalGlobal.hello == 100;
24 property <int> test_call_callback: InternalGlobal.sum(6, 4);
25}
26
27/*
28```rust
29let instance = TestCase::new().unwrap();
30assert!(!instance.get_test_global_prop_value());
31assert_eq!(PublicGlobal::get(&instance).get_hello(), 42);
32instance.global::<PublicGlobal<'_>>().set_hello(100);
33assert!(instance.get_test_global_prop_value());
34
35assert_eq!(ReexportedGlobal::get(&instance).get_foo(), 44);
36
37instance.global::<PublicGlobal<'_>>().on_sum(|a, b| a + b);
38assert_eq!(instance.get_test_call_callback(), 10);
39assert_eq!(instance.global::<PublicGlobal<'_>>().invoke_sum(4, 5), 9);
40```
41
42```cpp
43auto handle = TestCase::create();
44const TestCase &instance = *handle;
45assert(!instance.get_test_global_prop_value());
46assert_eq(instance.global<PublicGlobal>().get_hello(), 42);
47instance.global<PublicGlobal>().set_hello(100);
48assert(instance.get_test_global_prop_value());
49
50assert_eq(instance.global<ReexportedGlobal>().get_foo(), 44);
51
52instance.global<PublicGlobal>().on_sum([](int a, int b) { return a + b; });
53assert_eq(instance.get_test_call_callback(), 10);
54assert_eq(instance.global<PublicGlobal>().invoke_sum(4, 5), 9);
55```
56
57```js
58let instance = new slint.TestCase({});
59assert(!instance.test_global_prop_value);
60assert.equal(instance.PublicGlobal.hello, 42);
61instance.PublicGlobal.hello = 100;
62assert(instance.test_global_prop_value);
63
64assert.equal(instance.ReexportedGlobal.foo, 44);
65instance.PublicGlobal.sum = function(a, b) { return a + b };
66assert.equal(instance.test_call_callback, 10);
67assert.equal(instance.PublicGlobal.sum(4, 5), 9);
68```
69
70*/
71}
72
73#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
74 use i_slint_backend_testing as slint_testing;
75 slint_testing::init();
76 let instance = TestCase::new().unwrap();
77 assert!(!instance.get_test_global_prop_value());
78 assert_eq!(PublicGlobal::get(&instance).get_hello(), 42);
79 instance.global::<PublicGlobal<'_>>().set_hello(100);
80 assert!(instance.get_test_global_prop_value());
81
82 assert_eq!(ReexportedGlobal::get(&instance).get_foo(), 44);
83
84 instance.global::<PublicGlobal<'_>>().on_sum(|a, b| a + b);
85 assert_eq!(instance.get_test_call_callback(), 10);
86 assert_eq!(instance.global::<PublicGlobal<'_>>().invoke_sum(4, 5), 9);
87 Ok(())
88}