1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/types"# ] |
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<float> p1: 100%; |
7 | property<float> p2: 1%; |
8 | property<float> p3: 5.5%; |
9 | property<float> p4: 10 + 50%; |
10 | } |
11 | |
12 | |
13 | /* |
14 | |
15 | ```cpp |
16 | auto handle = TestCase::create(); |
17 | const TestCase &instance = *handle; |
18 | auto fuzzy_compare = [](float a, float b) { return std::abs(a - b) < 0.00000001; }; |
19 | assert(fuzzy_compare(instance.get_p1(), 1.)); |
20 | assert(fuzzy_compare(instance.get_p2(), 0.01)); |
21 | assert(fuzzy_compare(instance.get_p3(), 0.055)); |
22 | assert(fuzzy_compare(instance.get_p4(), 10.5)); |
23 | // self_test |
24 | assert(!fuzzy_compare(instance.get_p1(), 1.001)); |
25 | ``` |
26 | |
27 | ```rust |
28 | let instance = TestCase::new().unwrap(); |
29 | assert_eq!(instance.get_p1(), 1.); |
30 | assert_eq!(instance.get_p2(), 0.01); |
31 | assert_eq!(instance.get_p3(), 0.055); |
32 | assert_eq!(instance.get_p4(), 10.5); |
33 | |
34 | assert_ne!(instance.get_p3(), 0.0549); |
35 | ``` |
36 | |
37 | ```js |
38 | var instance = new slint.TestCase({}); |
39 | function n(a) { return Math.round(a*1000000) } |
40 | assert.equal(n(instance.p1), n(1.)); |
41 | assert.equal(n(instance.p2), n(0.01)); |
42 | assert.equal(n(instance.p3), n(0.055)); |
43 | assert.equal(n(instance.p4), n(10.5)); |
44 | // self_test |
45 | assert.notEqual(n(instance.p1), n(1.001)); |
46 | |
47 | ``` |
48 | |
49 | */ |
50 | } |
51 | |
52 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
53 | use i_slint_backend_testing as slint_testing; |
54 | slint_testing::init(); |
55 | let instance = TestCase::new().unwrap(); |
56 | assert_eq!(instance.get_p1(), 1.); |
57 | assert_eq!(instance.get_p2(), 0.01); |
58 | assert_eq!(instance.get_p3(), 0.055); |
59 | assert_eq!(instance.get_p4(), 10.5); |
60 | |
61 | assert_ne!(instance.get_p3(), 0.0549); |
62 | Ok(()) |
63 | } |