diff --git a/druid/src/widget/svg.rs b/druid/src/widget/svg.rs
index 7588c03d6b..adf0b3611c 100644
--- a/druid/src/widget/svg.rs
+++ b/druid/src/widget/svg.rs
@@ -238,3 +238,120 @@ fn color_from_usvg(paint: &usvg::Paint, opacity: usvg::Opacity) -> Color {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn translate() {
+ use crate::tests::harness::Harness;
+
+ let svg_data = SvgData::from_str(
+ "",
+ )
+ .unwrap();
+
+ let svg_widget = Svg::new(svg_data);
+
+ Harness::create_full(
+ true,
+ svg_widget,
+ Size::new(400., 600.),
+ |harness| {
+ harness.send_initial_events();
+ harness.just_layout();
+ harness.paint();
+ },
+ |target| {
+ let raw_pixels = target.into_raw();
+ assert_eq!(raw_pixels.len(), 400 * 600 * 4);
+
+ // being a tall widget with a square image the top and bottom rows will be
+ // the padding collor and the middle rows will not have any padding
+
+ // check that the middle row 400 pix wide is 200 black then 200 wight
+ let expecting: Vec = [
+ vec![41, 41, 41, 255].repeat(200),
+ vec![0, 0, 0, 255].repeat(200),
+ ]
+ .concat();
+ assert_eq!(raw_pixels[400 * 300 * 4..400 * 301 * 4], expecting[..]);
+
+ // check that the hole of the last 100 rows are all the back ground color.
+ let expecting: Vec = vec![41, 41, 41, 255].repeat(400 * 100);
+ assert_eq!(
+ raw_pixels[400 * 600 * 4 - 4 * 400 * 100..400 * 600 * 4],
+ expecting[..]
+ );
+ },
+ )
+ }
+
+ #[test]
+ fn scale() {
+ use crate::tests::harness::Harness;
+
+ let svg_data = SvgData::from_str(
+ "",
+ )
+ .unwrap();
+
+ let svg_widget = Svg::new(svg_data);
+
+ Harness::create_full(
+ true,
+ svg_widget,
+ Size::new(400., 600.),
+ |harness| {
+ harness.send_initial_events();
+ harness.just_layout();
+ harness.paint();
+ },
+ |target| {
+ let raw_pixels = target.into_raw();
+ assert_eq!(raw_pixels.len(), 400 * 600 * 4);
+
+ // being a tall widget with a square image the top and bottom rows will be
+ // the padding collor and the middle rows will not have any padding
+
+ // check that the middle row 400 pix wide is 200 black then 200 wight
+ let expecting: Vec = [
+ vec![41, 41, 41, 255].repeat(200),
+ vec![0, 0, 0, 255].repeat(200),
+ ]
+ .concat();
+ assert_eq!(raw_pixels[400 * 300 * 4..400 * 301 * 4], expecting[..]);
+
+ // check that the hole of the last 100 rows are all the back ground color.
+ let expecting: Vec = vec![41, 41, 41, 255].repeat(400 * 100);
+ assert_eq!(
+ raw_pixels[400 * 600 * 4 - 4 * 400 * 100..400 * 600 * 4],
+ expecting[..]
+ );
+ },
+ )
+ }
+}