1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/elements/../../../examples/printerdemo/ui/images/"# ] |
2 | #[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/elements"# ] |
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: ../../../examples/printerdemo/ui/images/ |
7 | |
8 | FixedWidthtImage := Image { |
9 | source: @image-url("cat.jpg" ); |
10 | width: 500phx; |
11 | } |
12 | |
13 | TestCase := Rectangle { |
14 | fixed_image := Image { |
15 | width: 50phx; |
16 | height: 50phx; |
17 | } |
18 | fixed_image_contain := Image { |
19 | width: 50phx; |
20 | height: 50phx; |
21 | image-fit: contain; |
22 | } |
23 | |
24 | VerticalLayout { |
25 | image_in_layout := Image { |
26 | } |
27 | image_in_layout_with_explicit_fit := Image { |
28 | image-fit: fill; |
29 | } |
30 | } |
31 | |
32 | image_with_missing_height := FixedWidthtImage { |
33 | property <bool> expected_height_ok: self.height == 750phx; |
34 | } |
35 | |
36 | image_with_missing_width := Image { |
37 | source: @image-url("cat.jpg" ); |
38 | height: 600phx; |
39 | property <bool> expected_width_ok: self.width == 400phx; |
40 | } |
41 | |
42 | image_with_missing_width_clipped := Image { |
43 | source: @image-url("cat.jpg" ); |
44 | height: 600phx; |
45 | source-clip-width: 20; |
46 | source-clip-height: 20; |
47 | property <bool> expected_width_ok: self.width == 600phx; |
48 | } |
49 | |
50 | property <bool> fixed_image_default_image_fit_ok: fixed_image.image-fit == ImageFit.fill; |
51 | property <bool> fixed_image_image_fit_override_ok: fixed_image_contain.image-fit == ImageFit.contain; |
52 | property <bool> image_in_layout_fit_ok: image_in_layout.image-fit == ImageFit.contain; |
53 | property <bool> image_in_layout_custom_fit_ok: image_in_layout_with_explicit_fit.image-fit == ImageFit.fill; |
54 | property <bool> image_with_missing_height_ok <=> image_with_missing_height.expected_height_ok; |
55 | property <bool> image_with_missing_width_ok <=> image_with_missing_width.expected_width_ok; |
56 | property <bool> image_with_missing_width_clipped_ok <=> image_with_missing_width.expected_width_ok; |
57 | |
58 | property <bool> test: fixed_image_default_image_fit_ok && fixed_image_image_fit_override_ok && image_in_layout_fit_ok && image_in_layout_custom_fit_ok && image_with_missing_height_ok && image_with_missing_width_ok && image_with_missing_width_clipped_ok; |
59 | } |
60 | |
61 | /* |
62 | |
63 | ```cpp |
64 | auto handle = TestCase::create(); |
65 | const TestCase &instance = *handle; |
66 | assert(instance.get_fixed_image_default_image_fit_ok()); |
67 | assert(instance.get_fixed_image_image_fit_override_ok()); |
68 | assert(instance.get_image_in_layout_fit_ok()); |
69 | assert(instance.get_image_in_layout_custom_fit_ok()); |
70 | assert(instance.get_image_with_missing_height_ok()); |
71 | assert(instance.get_image_with_missing_width_ok()); |
72 | assert(instance.get_image_with_missing_width_clipped_ok()); |
73 | ``` |
74 | |
75 | |
76 | ```rust |
77 | let instance = TestCase::new().unwrap(); |
78 | assert!(instance.get_fixed_image_default_image_fit_ok()); |
79 | assert!(instance.get_fixed_image_image_fit_override_ok()); |
80 | assert!(instance.get_image_in_layout_fit_ok()); |
81 | assert!(instance.get_image_in_layout_custom_fit_ok()); |
82 | assert!(instance.get_image_with_missing_height_ok()); |
83 | assert!(instance.get_image_with_missing_width_ok()); |
84 | assert!(instance.get_image_with_missing_width_clipped_ok()); |
85 | ``` |
86 | |
87 | ```js |
88 | var instance = new slint.TestCase(); |
89 | assert(instance.fixed_image_default_image_fit_ok); |
90 | assert(instance.fixed_image_image_fit_override_ok); |
91 | assert(instance.image_in_layout_fit_ok); |
92 | assert(instance.image_in_layout_custom_fit_ok); |
93 | assert(instance.image_with_missing_height_ok); |
94 | assert(instance.image_with_missing_width_ok); |
95 | assert(instance.image_with_missing_width_clipped_ok); |
96 | ``` |
97 | |
98 | */ |
99 | } |
100 | |
101 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
102 | use i_slint_backend_testing as slint_testing; |
103 | slint_testing::init(); |
104 | let instance = TestCase::new().unwrap(); |
105 | assert!(instance.get_fixed_image_default_image_fit_ok()); |
106 | assert!(instance.get_fixed_image_image_fit_override_ok()); |
107 | assert!(instance.get_image_in_layout_fit_ok()); |
108 | assert!(instance.get_image_in_layout_custom_fit_ok()); |
109 | assert!(instance.get_image_with_missing_height_ok()); |
110 | assert!(instance.get_image_with_missing_width_ok()); |
111 | assert!(instance.get_image_with_missing_width_clipped_ok()); |
112 | Ok(()) |
113 | } |