[librsvg: 1/10] Add test about ignoring filter chains with unresolvable URIs




commit 993efd7e6158f63020137ba82a92929cc7e6fe2c
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Apr 28 12:49:18 2021 -0500

    Add test about ignoring filter chains with unresolvable URIs

 tests/Makefile.am    |  1 +
 tests/src/filters.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/src/main.rs    |  3 +++
 3 files changed, 57 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ab03ef33..cedb30f2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,6 +5,7 @@ test_sources =                          \
        src/bugs.rs                     \
        src/compare_surfaces.rs         \
        src/errors.rs                   \
+       src/filters.rs                  \
        src/intrinsic_dimensions.rs     \
        src/loading_crash.rs            \
        src/main.rs                     \
diff --git a/tests/src/filters.rs b/tests/src/filters.rs
new file mode 100644
index 00000000..ac8310ec
--- /dev/null
+++ b/tests/src/filters.rs
@@ -0,0 +1,53 @@
+use cairo;
+
+use crate::reference_utils::{Compare, Evaluate, Reference};
+use crate::utils::{load_svg, render_document, SurfaceSize};
+
+#[test]
+fn invalid_filter_reference_cancels_filter_chain() {
+    // The <rect> has a filter chain with two URLs listed, but the second one doesn't resolve.
+    // The whole filter chain should be ignored.
+    let svg = load_svg(
+        br##"<?xml version="1.0" encoding="UTF-8"?>
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg"; xmlns:xlink="http://www.w3.org/1999/xlink"; width="400" 
height="400">
+  <defs>
+    <filter id="filter">
+      <feColorMatrix type="hueRotate" values="240"/>
+    </filter>
+  </defs>
+
+  <rect x="100" y="100" width="200" height="200" fill="lime" filter="url(#filter) url(#nonexistent)"/>
+</svg>
+"##,
+    ).unwrap();
+
+    let output_surf = render_document(
+        &svg,
+        SurfaceSize(400, 400),
+        |_| (),
+        cairo::Rectangle {
+            x: 0.0,
+            y: 0.0,
+            width: 400.0,
+            height: 400.0,
+        },
+    )
+    .unwrap();
+
+    let reference_surf = cairo::ImageSurface::create(cairo::Format::ARgb32, 400, 400).unwrap();
+
+    {
+        let cr = cairo::Context::new(&reference_surf);
+
+        cr.rectangle(100.0, 100.0, 200.0, 200.0);
+        cr.set_source_rgb(0.0, 1.0, 0.0);
+        cr.fill();
+    }
+
+    Reference::from_surface(reference_surf)
+        .compare(&output_surf)
+        .evaluate(
+            &output_surf,
+            "invalid_filter_reference_cancels_filter_chain",
+        );
+}
diff --git a/tests/src/main.rs b/tests/src/main.rs
index 4041ce40..79a323b0 100644
--- a/tests/src/main.rs
+++ b/tests/src/main.rs
@@ -17,6 +17,9 @@ mod compare_surfaces;
 #[cfg(test)]
 mod errors;
 
+#[cfg(test)]
+mod filters;
+
 #[cfg(test)]
 mod intrinsic_dimensions;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]