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
8global MyGlobal := {
9 property <int> hello: 42;
10}
11
12export { MyGlobal }
13export { MyGlobal as GlobalAlias }
14
15TestCase := Rectangle {
16 property <bool> test_global_prop_value: MyGlobal.hello == 100;
17}
18
19/*
20```rust
21let instance = TestCase::new().unwrap();
22assert!(!instance.get_test_global_prop_value());
23assert_eq!(MyGlobal::get(&instance).get_hello(), 42);
24assert_eq!(GlobalAlias::get(&instance).get_hello(), 42);
25instance.global::<MyGlobal<'_>>().set_hello(100);
26assert!(instance.get_test_global_prop_value());
27assert_eq!(MyGlobal::get(&instance).get_hello(), 100);
28assert_eq!(GlobalAlias::get(&instance).get_hello(), 100);
29```
30
31```cpp
32auto handle = TestCase::create();
33const TestCase &instance = *handle;
34assert(!instance.get_test_global_prop_value());
35assert_eq(instance.global<MyGlobal>().get_hello(), 42);
36assert_eq(instance.global<GlobalAlias>().get_hello(), 42);
37instance.global<MyGlobal>().set_hello(100);
38assert(instance.get_test_global_prop_value());
39assert_eq(instance.global<MyGlobal>().get_hello(), 100);
40assert_eq(instance.global<GlobalAlias>().get_hello(), 100);
41
42```
43
44```js
45let instance = new slint.TestCase({});
46assert(!instance.test_global_prop_value);
47assert.equal(instance.MyGlobal.hello, 42);;
48assert.equal(instance.GlobalAlias.hello, 42);;
49instance.MyGlobal.hello = 100;
50assert(instance.test_global_prop_value);
51assert.equal(instance.MyGlobal.hello, 100);
52assert.equal(instance.GlobalAlias.hello, 100);
53```
54
55*/
56}
57
58#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
59 use i_slint_backend_testing as slint_testing;
60 slint_testing::init();
61 let instance = TestCase::new().unwrap();
62 assert!(!instance.get_test_global_prop_value());
63 assert_eq!(MyGlobal::get(&instance).get_hello(), 42);
64 assert_eq!(GlobalAlias::get(&instance).get_hello(), 42);
65 instance.global::<MyGlobal<'_>>().set_hello(100);
66 assert!(instance.get_test_global_prop_value());
67 assert_eq!(MyGlobal::get(&instance).get_hello(), 100);
68 assert_eq!(GlobalAlias::get(&instance).get_hello(), 100);
69 Ok(())
70}