[librsvg: 3/4] Add `test_compare_render_output!` macro for filter ref tests
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/4] Add `test_compare_render_output!` macro for filter ref tests
- Date: Thu, 13 May 2021 16:04:18 +0000 (UTC)
commit 60ec5b659285fe269eaf658e52fff5f28bd34abd
Author: John Ledbetter <john ledbetter gmail com>
Date: Wed May 12 10:41:02 2021 -0400
Add `test_compare_render_output!` macro for filter ref tests
`test_compare_render_output!` takes three arguments:
* The test name, used for defining the test fn and for error output
* The test SVG string
* A reference SVG string to compare against.
This reduces some copy-paste duplication in the filter function tests.
tests/src/filters.rs | 229 ++++++++++++++-------------------------------------
1 file changed, 60 insertions(+), 169 deletions(-)
---
diff --git a/tests/src/filters.rs b/tests/src/filters.rs
index 61e89927..c283c74e 100644
--- a/tests/src/filters.rs
+++ b/tests/src/filters.rs
@@ -3,6 +3,45 @@ use cairo;
use crate::reference_utils::{Compare, Evaluate, Reference};
use crate::utils::{load_svg, render_document, SurfaceSize};
+macro_rules! test_compare_render_output {
+ ($test_name:ident, $test:expr, $reference:expr $(,)?) => {
+ #[test]
+ fn $test_name() {
+ let svg = load_svg($test).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 = load_svg($reference).unwrap();
+ let reference_surf = render_document(
+ &reference,
+ SurfaceSize(400, 400),
+ |_| (),
+ cairo::Rectangle {
+ x: 0.0,
+ y: 0.0,
+ width: 400.0,
+ height: 400.0,
+ },
+ )
+ .unwrap();
+
+ Reference::from_surface(reference_surf.into_image_surface().unwrap())
+ .compare(&output_surf)
+ .evaluate(&output_surf, stringify!($test_name));
+ }
+ };
+}
+
#[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.
@@ -99,33 +138,14 @@ fn non_filter_reference_cancels_filter_chain() {
.evaluate(&output_surf, "non_filter_reference_cancels_filter_chain");
}
-#[test]
-fn blur_filter_func() {
- // Create an element with a filter function, and compare it to the
- // supposed equivalent using the <filter> element.
- let svg = load_svg(
- br##"<?xml version="1.0" encoding="UTF-8"?>
+test_compare_render_output!(
+ blur_filter_func,
+ 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">
<rect x="100" y="100" width="200" height="200" fill="lime" filter="blur(5)"/>
</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 = load_svg(
- br##"<?xml version="1.0" encoding="UTF-8"?>
+ 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">
@@ -136,54 +156,17 @@ fn blur_filter_func() {
<rect x="100" y="100" width="200" height="200" fill="lime" filter="url(#filter)"/>
</svg>
"##,
- ).unwrap();
-
- let reference_surf = render_document(
- &reference,
- SurfaceSize(400, 400),
- |_| (),
- cairo::Rectangle {
- x: 0.0,
- y: 0.0,
- width: 400.0,
- height: 400.0,
- },
- )
- .unwrap();
-
- Reference::from_surface(reference_surf.into_image_surface().unwrap())
- .compare(&output_surf)
- .evaluate(&output_surf, "blur_filter_func");
-}
+);
-#[test]
-fn opacity_filter_func() {
- // Create an element with a filter function, and compare it to the
- // supposed equivalent using the <filter> element.
- let svg = load_svg(
- br##"<?xml version="1.0" encoding="UTF-8"?>
+test_compare_render_output!(
+opacity_filter_func,
+ 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">
<rect x="100" y="100" width="200" height="200" fill="red"/>
<rect x="100" y="100" width="200" height="200" fill="lime" filter="opacity(0.75)"/>
</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 = load_svg(
- br##"<?xml version="1.0" encoding="UTF-8"?>
+ 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">
@@ -196,54 +179,17 @@ fn opacity_filter_func() {
<rect x="100" y="100" width="200" height="200" fill="red"/>
<rect x="100" y="100" width="200" height="200" fill="lime" filter="url(#filter)"/>
</svg>
-"##,
- ).unwrap();
+"##
+);
- let reference_surf = render_document(
- &reference,
- SurfaceSize(400, 400),
- |_| (),
- cairo::Rectangle {
- x: 0.0,
- y: 0.0,
- width: 400.0,
- height: 400.0,
- },
- )
- .unwrap();
-
- Reference::from_surface(reference_surf.into_image_surface().unwrap())
- .compare(&output_surf)
- .evaluate(&output_surf, "opacity_filter_func");
-}
-
-#[test]
-fn saturate_filter_func() {
- // Create an element with a filter function, and compare it to the
- // supposed equivalent using the <filter> element.
- let svg = load_svg(
- br##"<?xml version="1.0" encoding="UTF-8"?>
+test_compare_render_output!(
+ saturate_filter_func,
+ 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">
<rect x="100" y="100" width="200" height="200" fill="lime" filter="saturate(0.75)"/>
</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 = load_svg(
- br##"<?xml version="1.0" encoding="UTF-8"?>
+ 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">
@@ -254,53 +200,16 @@ fn saturate_filter_func() {
<rect x="100" y="100" width="200" height="200" fill="lime" filter="url(#filter)"/>
</svg>
"##,
- ).unwrap();
-
- let reference_surf = render_document(
- &reference,
- SurfaceSize(400, 400),
- |_| (),
- cairo::Rectangle {
- x: 0.0,
- y: 0.0,
- width: 400.0,
- height: 400.0,
- },
- )
- .unwrap();
-
- Reference::from_surface(reference_surf.into_image_surface().unwrap())
- .compare(&output_surf)
- .evaluate(&output_surf, "saturate_filter_func");
-}
+);
-#[test]
-fn sepia_filter_func() {
- // Create an element with a filter function, and compare it to the
- // supposed equivalent using the <filter> element.
- let svg = load_svg(
- br##"<?xml version="1.0" encoding="UTF-8"?>
+test_compare_render_output!(
+ sepia_filter_func,
+ 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">
<rect x="100" y="100" width="200" height="200" fill="lime" filter="sepia(0.75)"/>
</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 = load_svg(
- br##"<?xml version="1.0" encoding="UTF-8"?>
+ 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">
@@ -315,22 +224,4 @@ fn sepia_filter_func() {
<rect x="100" y="100" width="200" height="200" fill="lime" filter="url(#filter)"/>
</svg>
"##,
- ).unwrap();
-
- let reference_surf = render_document(
- &reference,
- SurfaceSize(400, 400),
- |_| (),
- cairo::Rectangle {
- x: 0.0,
- y: 0.0,
- width: 400.0,
- height: 400.0,
- },
- )
- .unwrap();
-
- Reference::from_surface(reference_surf.into_image_surface().unwrap())
- .compare(&output_surf)
- .evaluate(&output_surf, "sepia_filter_func");
-}
+);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]