1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
3
4//include_path: ../../helper_components
5
6global MyGlobal := {
7 property <int> hello: 42;
8}
9
10export { MyGlobal }
11export { MyGlobal as GlobalAlias }
12
13TestCase := Rectangle {
14 property <bool> test_global_prop_value: MyGlobal.hello == 100;
15}
16
17/*
18```rust
19let instance = TestCase::new().unwrap();
20assert!(!instance.get_test_global_prop_value());
21assert_eq!(MyGlobal::get(&instance).get_hello(), 42);
22assert_eq!(GlobalAlias::get(&instance).get_hello(), 42);
23instance.global::<MyGlobal<'_>>().set_hello(100);
24assert!(instance.get_test_global_prop_value());
25assert_eq!(MyGlobal::get(&instance).get_hello(), 100);
26assert_eq!(GlobalAlias::get(&instance).get_hello(), 100);
27```
28
29```cpp
30auto handle = TestCase::create();
31const TestCase &instance = *handle;
32assert(!instance.get_test_global_prop_value());
33assert_eq(instance.global<MyGlobal>().get_hello(), 42);
34assert_eq(instance.global<GlobalAlias>().get_hello(), 42);
35instance.global<MyGlobal>().set_hello(100);
36assert(instance.get_test_global_prop_value());
37assert_eq(instance.global<MyGlobal>().get_hello(), 100);
38assert_eq(instance.global<GlobalAlias>().get_hello(), 100);
39
40```
41
42```js
43let instance = new slint.TestCase({});
44assert(!instance.test_global_prop_value);
45assert.equal(instance.MyGlobal.hello, 42);;
46assert.equal(instance.GlobalAlias.hello, 42);;
47instance.MyGlobal.hello = 100;
48assert(instance.test_global_prop_value);
49assert.equal(instance.MyGlobal.hello, 100);
50assert.equal(instance.GlobalAlias.hello, 100);
51```
52
53*/
54