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
8FixedWidthtImage := Image {
9 source: @image-url("cat.jpg");
10 width: 500phx;
11}
12
13TestCase := 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
64auto handle = TestCase::create();
65const TestCase &instance = *handle;
66assert(instance.get_fixed_image_default_image_fit_ok());
67assert(instance.get_fixed_image_image_fit_override_ok());
68assert(instance.get_image_in_layout_fit_ok());
69assert(instance.get_image_in_layout_custom_fit_ok());
70assert(instance.get_image_with_missing_height_ok());
71assert(instance.get_image_with_missing_width_ok());
72assert(instance.get_image_with_missing_width_clipped_ok());
73```
74
75
76```rust
77let instance = TestCase::new().unwrap();
78assert!(instance.get_fixed_image_default_image_fit_ok());
79assert!(instance.get_fixed_image_image_fit_override_ok());
80assert!(instance.get_image_in_layout_fit_ok());
81assert!(instance.get_image_in_layout_custom_fit_ok());
82assert!(instance.get_image_with_missing_height_ok());
83assert!(instance.get_image_with_missing_width_ok());
84assert!(instance.get_image_with_missing_width_clipped_ok());
85```
86
87```js
88var instance = new slint.TestCase();
89assert(instance.fixed_image_default_image_fit_ok);
90assert(instance.fixed_image_image_fit_override_ok);
91assert(instance.image_in_layout_fit_ok);
92assert(instance.image_in_layout_custom_fit_ok);
93assert(instance.image_with_missing_height_ok);
94assert(instance.image_with_missing_width_ok);
95assert(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}